-
Notifications
You must be signed in to change notification settings - Fork 1
/
unitformforoptionsbasic.pas
186 lines (147 loc) · 4.45 KB
/
unitformforoptionsbasic.pas
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
unit UnitFormForOptionsBasic;
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, CommonFunctionsLCL, UnitCommon, Forms, ButtonPanel,
LazMethodList, Controls;
type
TFormForOptionsBasic = class(TCustomForm, IFormAddCloseQuery)
private
CloseQueryList: TMethodList;
MainControl: TControl;
BP: TButtonPanel;
Panel1: TCustomControl;
FFixConstraints: Boolean;
procedure AfterShow(Data: PtrInt);
protected
procedure DoShow; override;
public
const
DefaultPanelButtons = [TPanelButton.pbOK, TPanelButton.pbCancel];
//DefaultPanelButtonsWithHelp: TPanelButtons = [TPanelButton.pbOK, TPanelButton.pbCancel, TPanelButton.pbHelp];
public
constructor CreateForControl(AOwner: TComponent; C: TControl;
AFixConstraints: Boolean; Buttons: TPanelButtons = DefaultPanelButtons);
destructor Destroy; override;
function CloseQuery: Boolean; override;
procedure RemoveAllHandlersOfObject(AnObject: TObject); override;
procedure AddCloseQuery(C: TCloseQueryEvent);
end;
implementation
{ TFormForOptionsBasic }
function TFormForOptionsBasic.CloseQuery: Boolean;
var
I: Integer;
begin
Result := inherited CloseQuery;
if Assigned(CloseQueryList) then begin
I := 0;
while Result and (I < CloseQueryList.Count) do begin
TCloseQueryEvent(CloseQueryList[I])(Self, Result);
Inc(I);
end;
end;
end;
procedure TFormForOptionsBasic.RemoveAllHandlersOfObject(AnObject: TObject);
begin
inherited RemoveAllHandlersOfObject(AnObject);
if Assigned(CloseQueryList) then begin
CloseQueryList.RemoveAllMethodsOfObject(AnObject);
if CloseQueryList.Count = 0 then
FreeAndNil(CloseQueryList);
end;
end;
procedure TFormForOptionsBasic.AfterShow(Data: PtrInt);
begin
Self.AutoSize := False;
if Data > 0 then begin
Self.AutoSize := True;
TCommonFunctionsLCL.AdjustFormPos(Self);
Application.QueueAsyncCall(@AfterShow, Data - 1);
end else begin
DisableAlign;
try
Panel1.AutoSize := False;
MainControl.AnchorParallel(akLeft, 0, Panel1);
if Assigned(BP) then begin
BP.Anchors := BP.Anchors - [akTop];
BP.AnchorParallel(akBottom, 0, Panel1);
MainControl.AnchorToNeighbour(akBottom, 0, BP);
end else begin
MainControl.AnchorParallel(akBottom, 0, Panel1);
end;
Panel1.AnchorParallel(akRight, 0, Self);
Panel1.AnchorParallel(akBottom, 0, Self);
if FFixConstraints then begin
Constraints.MinHeight := Height;
Constraints.MinWidth := Width;
end;
finally
EnableAlign;
end;
end;
end;
procedure TFormForOptionsBasic.DoShow;
begin
inherited DoShow;
AfterShow(2);
end;
constructor TFormForOptionsBasic.CreateForControl(AOwner: TComponent;
C: TControl; AFixConstraints: Boolean; Buttons: TPanelButtons);
begin
if C = nil then
Abort;
inherited CreateNew(AOwner, 0);
Name := TCommonFunctions.GlobalObjectNameGenerator(Self);
FFixConstraints := AFixConstraints;
//BorderStyle := bsSingle;
BorderIcons := BorderIcons - [TBorderIcon.biMaximize, TBorderIcon.biMinimize];
BP := nil;
MainControl := C;
Caption := C.Caption;
Panel1 := TCustomControl.Create(Self);
Panel1.Name := TCommonFunctions.GlobalObjectNameGenerator(Panel1);
Panel1.Caption := '';
Panel1.Anchors := [];
Panel1.AnchorParallel(akLeft, 0, Self);
Panel1.AnchorParallel(akTop, 0, Self);
C.Anchors := [];
C.AnchorParallel(akRight, 0, Panel1);
C.AnchorParallel(akTop, 0, Panel1);
if Buttons <> [] then begin
BP := TButtonPanel.Create(Panel1);
BP.Name := TCommonFunctions.GlobalObjectNameGenerator(BP);
BP.Align := alNone;
BP.Anchors := [];
BP.ShowBevel := False;
BP.ShowButtons := Buttons;
BP.AnchorParallel(akRight, 0, Panel1);
BP.AnchorToNeighbour(akTop, 0, C);
BP.BorderSpacing.Around := 6;
BP.Parent := Panel1;
end;
C.Parent := Panel1;
CloseQueryList := nil;
Panel1.AutoSize := True;
if C is TWinControl then
TWinControl(C).TabOrder := 0;
Panel1.Parent := Self;
end;
destructor TFormForOptionsBasic.Destroy;
begin
FreeAndNil(CloseQueryList);
inherited Destroy;
end;
procedure TFormForOptionsBasic.AddCloseQuery(C: TCloseQueryEvent);
begin
if Assigned(C) then begin
if CloseQueryList = nil then begin
CloseQueryList := TMethodList.Create;
end;
CloseQueryList.Add(TMethod(C));
end;
end;
end.