summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/Chess4Net/DialogUnit.pas
blob: a8eeeb006e2ec261ca141534f3cf45c29e2e4cc9 (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
////////////////////////////////////////////////////////////////////////////////
// All code below is exclusively owned by author of Chess4Net - Pavel Perminov
// (packpaul@mail.ru, packpaul1@gmail.com).
// Any changes, modifications, borrowing and adaptation are a subject for
// explicit permition from the owner.

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;
    m_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;
    function RGetModalResult: TModalResult; override;
    procedure RSetModalResult(Value: TModalResult); override;

    property MsgDlg: TForm read m_MsgDlg;
  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;

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

  for i := 0 to (m_MsgDlg.ComponentCount - 1) do
  begin
    if (m_MsgDlg.Components[i] is TButton) then
      TButton(m_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(m_MsgDlg);
end;


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


procedure TDialogForm.Show;
begin
  m_MsgDlg.Show;
end;


procedure TDialogForm.Close;
begin
  m_MsgDlg.Close;
end;


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

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

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

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

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

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


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


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


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


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


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


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


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


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

function TDialogForm.RGetModalResult: TModalResult;
begin
  Result := m_MsgDlg.ModalResult;
end;


procedure TDialogForm.RSetModalResult(Value: TModalResult);
begin
  m_MsgDlg.ModalResult := Value;
end;

end.