summaryrefslogtreecommitdiff
path: root/plugins/Chess4Net/DialogUnit.pas
blob: 921d630dba1e85a7711a86f1a6f24d2f38b6d617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
unit DialogUnit;

interface

uses
  Forms, Dialogs, Controls, Classes, Windows,
  ModalForm;

type
  TDialogForm = class(TModalForm)
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ButtonClick(Sender: TObject);
  private
    m_ModID: TModalFormID;
    msgDlg: TForm;
    function GetCaption: TCaption;
    procedure SetCaption(capt: TCaption);
  protected
    function GetHandle: hWnd; override;
    function GetEnabled_: boolean; override;
    procedure SetEnabled_(flag: boolean); override;
    function GetLeft_: integer; override;
    procedure SetLeft_(x: integer); override;
    function GetTop_: integer; override;
    procedure SetTop_(y: integer); override;
    function GetModalID: TModalFormID; override;
  public
    constructor Create(frmOwner: TForm; const wstrMsg: WideString;
      DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; modID: TModalFormID = mfNone;
      msgDlgHandler: TModalFormHandler = nil; bStayOnTopIfNoOwner: boolean = FALSE); overload;
    constructor Create(dlgOwner: TDialogs; const wstrMsg: WideString;
      DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; modID: TModalFormID;
      msgDlgHandler: TModalFormHandler; bStayOnTopIfNoOwner: boolean = FALSE); overload;
    destructor Destroy; override;

    procedure Show; override;
    procedure Close; override;
    function ShowModal: integer; reintroduce;
    procedure SetFocus; override;

    property Caption: TCaption read GetCaption write SetCaption;
  end;

implementation

uses
  StdCtrls, SysUtils, MessageDialogUnit;

constructor TDialogForm.Create(frmOwner: TForm; const wstrMsg: WideString;
  DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; modID: TModalFormID = mfNone;
  msgDlgHandler: TModalFormHandler = nil; bStayOnTopIfNoOwner: boolean = FALSE);
var
  i: integer;
begin
  inherited CreateNew(frmOwner);

  m_ModID := modID;
  RHandler := msgDlgHandler;

  msgDlg := MessageDialogUnit.CreateMessageDialog(frmOwner, wstrMsg, DlgType, Buttons,
    bStayOnTopIfNoOwner);
  // msgDlg.FormStyle := frmOwner.FormStyle;
  msgDlg.OnShow := FormShow;
  msgDlg.OnClose := FormClose;

  for i := 0 to (msgDlg.ComponentCount - 1) do
  begin
    if (msgDlg.Components[i] is TButton) then
      TButton(msgDlg.Components[i]).OnClick := ButtonClick;
  end;
end;


constructor TDialogForm.Create(dlgOwner: TDialogs; const wstrMsg: WideString;
  DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; modID: TModalFormID;
  msgDlgHandler: TModalFormHandler; bStayOnTopIfNoOwner: boolean = FALSE);
begin
  self.dlgOwner := dlgOwner;
  Create((dlgOwner.Owner as TForm), wstrMsg, DlgType, Buttons, modID, msgDlgHandler, bStayOnTopIfNoOwner);
end;


procedure TDialogForm.FormShow(Sender: TObject);
begin
  inherited FormShow(msgDlg);
end;


procedure TDialogForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(dlgOwner) then
    dlgOwner.UnsetShowing(self);
  if (fsModal in msgDlg.FormState) then
    exit;
  if (Assigned(RHandler)) then
    RHandler(TModalForm(msgDlg), GetModalID);
//  Action := caFree;
  Release;
end;


procedure TDialogForm.Show;
begin
  msgDlg.Show;
end;


procedure TDialogForm.Close;
begin
  msgDlg.Close;
end;


function TDialogForm.ShowModal: integer;
begin
  Result := msgDlg.ShowModal;
end;

procedure TDialogForm.ButtonClick(Sender: TObject);
begin
  if not (fsModal in msgDlg.FormState) then
    msgDlg.Close;
end;

destructor TDialogForm.Destroy;
begin
  msgDlg.Release;
  inherited;
end;

function TDialogForm.GetCaption: TCaption;
begin
  Result := msgDlg.Caption;
end;

procedure TDialogForm.SetCaption(capt: TCaption);
begin
  msgDlg.Caption := capt;
end;

function TDialogForm.GetHandle: hWnd;
begin
  Result := msgDlg.Handle;
end;


function TDialogForm.GetEnabled_: boolean;
begin
  Result := msgDlg.Enabled;
end;


procedure TDialogForm.SetEnabled_(flag: boolean);
begin
  msgDlg.Enabled := flag;
end;


procedure TDialogForm.SetFocus;
begin
  msgDlg.SetFocus;
  msgDlg.Show;
end;


function TDialogForm.GetLeft_: integer;
begin
  Result := msgDlg.Left;
end;


procedure TDialogForm.SetLeft_(x: integer);
begin
  msgDlg.Left := x;
end;


function TDialogForm.GetTop_: integer;
begin
  Result := msgDlg.Top;
end;


procedure TDialogForm.SetTop_(y: integer);
begin
  msgDlg.Top := y;
end;


function TDialogForm.GetModalID: TModalFormID;
begin
  Result := m_ModID;
end;

end.