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
|
{
fpGUI - Free Pascal GUI Library
Dialogs class declarations
Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
{%mainunit fpgui.pp}
{$IFDEF read_interface}
TCustomStandardDialog = class(TCustomForm)
private
procedure StdBtnClicked(Sender: TObject);
protected
FButtons: TMsgDlgButtons;
MainLayout, BtnLayout: TBoxLayout;
Separator: TSeparator;
function ProcessEvent(Event: TEventObj): Boolean; override;
function DistributeEvent(Event: TEventObj): Boolean; override;
procedure CalcSizes; override;
procedure Resized; override;
procedure SetButtons(AButtons: TMsgDlgButtons);
property Buttons: TMsgDlgButtons read FButtons write SetButtons default [mbOk, mbCancel];
public
constructor Create(AOwner: TComponent); override;
end;
TStandardDialog = class(TCustomStandardDialog)
published
property Text;
property OnCreate;
property Buttons;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
// ===================================================================
// TCustomStandardDialog
// ===================================================================
// public methods
constructor TCustomStandardDialog.Create(AOwner: TComponent);
function AddBtn(const AText: String; ADefault: Boolean): TButton;
begin
Result := TButton.Create(Self);
Result.Text := AText;
// Result.Default := ADefault;
Result.OnClick := @StdBtnClicked;
Result.Parent := BtnLayout;
end;
begin
inherited Create(AOwner);
FButtons := [mbOk, mbCancel];
FBorderWidth := 4;
MainLayout := TBoxLayout.Create(Self);
MainLayout.Orientation := Vertical;
MainLayout.SetEmbeddedParent(Self);
Separator := TSeparator.Create(Self);
Separator.Parent := MainLayout;
BtnLayout := TBoxLayout.Create(Self);
BtnLayout.Orientation := Horizontal;
BtnLayout.HorzAlign := horzRight;
BtnLayout.VertAlign := vertCenter;
BtnLayout.CanExpandHeight := False;
BtnLayout.Parent := MainLayout;
if mbYes in FButtons then AddBtn(mbText_Yes, False);
if mbNo in FButtons then AddBtn(mbText_No, False);
if mbOk in FButtons then AddBtn(mbText_OK, True);
if mbCancel in FButtons then AddBtn(mbText_Cancel, False);
if mbApply in FButtons then AddBtn(mbText_Apply, False);
if mbAbort in FButtons then AddBtn(mbText_Abort, False);
if mbRetry in FButtons then AddBtn(mbText_Retry, False);
if mbIgnore in FButtons then AddBtn(mbText_Ignore, False);
if mbAll in FButtons then AddBtn(mbText_All, False);
if mbNoToAll in FButtons then AddBtn(mbText_NoToAll, False);
if mbYesToAll in FButtons then AddBtn(mbText_YesToAll, False);
if mbHelp in FButtons then AddBtn(mbText_Help, False);
end;
// protected methods
function TCustomStandardDialog.ProcessEvent(Event: TEventObj): Boolean;
begin
Result := MainLayout.ProcessEvent(Event) or inherited ProcessEvent(Event);
end;
function TCustomStandardDialog.DistributeEvent(Event: TEventObj): Boolean;
begin
Result := Event.SendToChild(MainLayout) or inherited DistributeEvent(Event);
end;
procedure TCustomStandardDialog.CalcSizes;
begin
if Assigned(Child) then
begin
FMinSize := Child.MinSize + 2 * BorderWidth;
FDefSize := Child.DefSize + 2 * BorderWidth;
FMaxSize.cx := Min(InfiniteSize, Child.MaxSize.cx + 2 * BorderWidth);
FMaxSize.cy := Min(InfiniteSize, Child.MaxSize.cy + 2 * BorderWidth);
end;
FMinSize.cx := Max(MinSize.cx, MainLayout.MinSize.cx + 2 * BorderWidth);
Inc(FMinSize.cy, MainLayout.DefSize.cy + BorderWidth);
FDefSize.cx := Max(DefSize.cx, MainLayout.DefSize.cx + 2 * BorderWidth);
FDefSize.cy := Min(InfiniteSize, DefSize.cy);
FMaxSize.cx := Min(MaxSize.cx, MainLayout.MaxSize.cx + 2 * BorderWidth);
FMaxSize.cy := Min(InfiniteSize, MaxSize.cy + MainLayout.DefSize.cy);
end;
procedure TCustomStandardDialog.Resized;
begin
if Assigned(Child) then
Child.SetBounds(Point(BorderWidth, BorderWidth),
gfxBase.Size(Width - 2 * BorderWidth,
Height - MainLayout.DefSize.cy - 2 * BorderWidth));
MainLayout.SetBounds(
Point(BorderWidth, Height - MainLayout.DefSize.cy - BorderWidth),
gfxBase.Size(Width - 2 * BorderWidth, MainLayout.DefSize.cy - BorderWidth));
end;
procedure TCustomStandardDialog.SetButtons(AButtons: TMsgDlgButtons);
begin
FButtons := AButtons;
end;
procedure TCustomStandardDialog.StdBtnClicked(Sender: TObject);
begin
Close;
end;
{$ENDIF read_implementation}
|