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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
{
This demonstrates the usage of ICommand and ICommandHolder. They work
similar to Delphi's TAction classes
}
unit frm_main;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_button,
fpg_memo, fpg_menu, fpg_label, fpg_trackbar;
type
TMainForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: MainForm}
btnAdd: TfpgButton;
memName1: TfpgMemo;
btnQuit: TfpgButton;
MainMenu: TfpgMenuBar;
mnuFile: TfpgPopupMenu;
btnShowBorderless: TfpgButton;
btnShowSplash: TfpgButton;
Label1: TfpgLabel;
{@VFD_HEAD_END: MainForm}
public
procedure AfterCreate; override;
end;
TBorderLessForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: BorderLessForm}
btnClose: TfpgButton;
Label1: TfpgLabel;
TrackBar1: TfpgTrackBar;
{@VFD_HEAD_END: BorderLessForm}
public
constructor Create(AOwner: TComponent); override;
procedure AfterCreate; override;
class procedure Execute;
end;
{@VFD_NEWFORM_DECL}
implementation
uses
commands;
{@VFD_NEWFORM_IMPL}
{ TBorderLessForm }
constructor TBorderLessForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Include(FWindowAttributes, waBorderLess); // borderless and steals focus like a normal form
end;
procedure TBorderLessForm.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: BorderLessForm}
Name := 'BorderLessForm';
SetPosition(321, 549, 323, 133);
WindowTitle := 'BorderLessForm';
Hint := '';
WindowPosition := wpOneThirdDown;
btnClose := TfpgButton.Create(self);
with btnClose do
begin
Name := 'btnClose';
SetPosition(232, 100, 80, 24);
Text := 'Close';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
ModalResult := mrOK;
TabOrder := 1;
end;
Label1 := TfpgLabel.Create(self);
with Label1 do
begin
Name := 'Label1';
SetPosition(8, 32, 304, 16);
FontDesc := '#Label2';
Hint := '';
Layout := tlCenter;
Text := 'Look Mom, no borders!';
end;
TrackBar1 := TfpgTrackBar.Create(self);
with TrackBar1 do
begin
Name := 'TrackBar1';
SetPosition(72, 60, 148, 30);
Hint := '';
TabOrder := 3;
end;
{@VFD_BODY_END: BorderLessForm}
{%endregion}
end;
class procedure TBorderLessForm.Execute;
var
frm: TBorderLessForm;
begin
frm := TBorderLessForm.Create(nil);
try
frm.ShowModal;
finally
frm.Free;
end;
end;
{ TMainForm }
procedure TMainForm.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: MainForm}
Name := 'MainForm';
SetPosition(293, 236, 416, 273);
WindowTitle := 'Command Interface Test';
Hint := '';
WindowPosition := wpScreenCenter;
btnAdd := TfpgButton.Create(self);
with btnAdd do
begin
Name := 'btnAdd';
SetPosition(260, 28, 148, 24);
Text := 'Add Text to Memo';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 1;
end;
memName1 := TfpgMemo.Create(self);
with memName1 do
begin
Name := 'memName1';
SetPosition(8, 28, 236, 236);
Hint := '';
Lines.Add('');
FontDesc := '#Edit1';
TabOrder := 2;
end;
btnQuit := TfpgButton.Create(self);
with btnQuit do
begin
Name := 'btnQuit';
SetPosition(332, 240, 75, 24);
Text := 'Quit';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 3;
end;
MainMenu := TfpgMenuBar.Create(self);
with MainMenu do
begin
Name := 'MainMenu';
SetPosition(0, 0, 416, 24);
Anchors := [anLeft,anRight,anTop];
end;
mnuFile := TfpgPopupMenu.Create(self);
with mnuFile do
begin
Name := 'mnuFile';
SetPosition(44, 72, 120, 20);
AddMenuItem('Quit', '', nil);
end;
btnShowBorderless := TfpgButton.Create(self);
with btnShowBorderless do
begin
Name := 'btnShowBorderless';
SetPosition(260, 56, 148, 24);
Text := 'Show Borderless Form';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 6;
end;
btnShowSplash := TfpgButton.Create(self);
with btnShowSplash do
begin
Name := 'btnShowSplash';
SetPosition(260, 84, 148, 24);
Text := 'Show Splash Screen';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 7;
end;
Label1 := TfpgLabel.Create(self);
with Label1 do
begin
Name := 'Label1';
SetPosition(252, 120, 156, 116);
FontDesc := '#Label1';
Hint := '';
Text := 'Note the difference between a borderless form and a splash screen (wtPopup) form. wtPopup doesn''t steal focus (eg: hint window)';
WrapText := True;
end;
{@VFD_BODY_END: MainForm}
{%endregion}
MainMenu.AddMenuItem('File', nil).SubMenu := mnuFile;
{ Instantiate the Command classes. By setting a Command it
take preference over OnClick event handlers and is handled
automatically for you. No need to declare a OnClick event handler. }
btnAdd.SetCommand(TAddCommand.Create(memName1));
btnQuit.SetCommand(TExitCommand.Create);
btnShowBorderless.SetCommand(TShowBorderlessForm.Create);
btnShowSplash.SetCommand(TShowSplashCommand.Create);
// The menu item File|Quit shares the command of btnQuit
mnuFile.MenuItemByName('Quit').SetCommand(btnQuit.GetCommand);
end;
end.
|