summaryrefslogtreecommitdiff
path: root/examples/gui/menutest/menutest.lpr
blob: e4d40cf05a404997abe6fc9bf493f51d9d4dfcc3 (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
program menutest;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  fpg_base,
  fpg_main,
  fpg_form,
  fpg_menu,
  fpg_edit,
  fpg_panel,
  fpg_button,
  fpg_dialogs,
  fpg_memo;

type
  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    FMenuBar: TfpgMenuBar;
    StatusBar: TfpgPanel;
    Toolbar: TfpgBevel;
    btnQuit: TfpgButton;
    btnSave: TfpgButton;
    btnOpen: TfpgButton;
    btnAbout: TfpgButton;
    edit1: TfpgEdit;
    Memo1: TfpgMemo;
    FFileSubMenu: TfpgPopupMenu;
    FEditSubMenu: TfpgPopupMenu;
    FEditSelectSubMenu: TfpgPopupMenu;
    FViewSubMenu: TfpgPopupMenu;
    FHelpSubMenu: TfpgPopupMenu;
    {@VFD_HEAD_END: MainForm}
    procedure   miExitClicked(Sender: TObject);
    procedure   miMenuItemSelected(Sender: TObject);
    procedure   miMenuItemChecked(Sender: TObject);
    procedure   miToolBarChecked(Sender: TObject);
    procedure   miStatusBarChecked(Sender: TObject);
    procedure   btnAboutClicked(Sender: TObject);
    procedure   Log(const AText: TfpgString);
  public
    procedure   AfterCreate; override;
  end;


{ TMainForm }

procedure TMainForm.miExitClicked(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.miMenuItemSelected(Sender: TObject);
begin
  if Sender is TfpgMenuItem then
    Log('Menu clicked: ' + TfpgMenuItem(Sender).Text);
end;

procedure TMainForm.miMenuItemChecked(Sender: TObject);
begin
  TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
  Log('Check Menu item toggled');
end;

procedure TMainForm.miToolBarChecked(Sender: TObject);
begin
  TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
  ToolBar.Visible := not ToolBar.Visible;
  Log('Check Menu for Toolbar toggled');
end;

procedure TMainForm.miStatusBarChecked(Sender: TObject);
begin
  TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
  StatusBar.Visible := not StatusBar.Visible;
  Log('Check Menu for Statusbar toggled');
end;

procedure TMainForm.btnAboutClicked(Sender: TObject);
begin
  TfpgMessageDialog.AboutFPGui;
end;

procedure TMainForm.Log(const AText: TfpgString);
begin
  Memo1.Lines.Add(AText);
end;

procedure TMainForm.AfterCreate;
begin
  {%region 'Auto-generated GUI code' -fold}
  {@VFD_BODY_BEGIN: MainForm}
  Name := 'MainForm';
  SetPosition(316, 169, 400, 200);
  WindowTitle := 'Menu Test';
  Hint := '';
  WindowPosition := wpOneThirdDown;

  FMenuBar := TfpgMenuBar.Create(self);
  with FMenuBar do
  begin
    Name := 'FMenuBar';
    SetPosition(0, 0, 400, 24);
    Anchors := [anLeft,anRight,anTop];
  end;

  StatusBar := TfpgPanel.Create(self);
  with StatusBar do
  begin
    Name := 'StatusBar';
    SetPosition(0, 176, 400, 24);
    Anchors := [anLeft,anRight,anBottom];
    Alignment := taLeftJustify;
    FontDesc := '#Label1';
    Hint := '';
    Style := bsLowered;
    Text := 'This is the status bar...';
  end;

  Toolbar := TfpgBevel.Create(self);
  with Toolbar do
  begin
    Name := 'Toolbar';
    SetPosition(0, 24, 400, 29);
    Anchors := [anLeft,anRight,anTop];
    Hint := '';
    Shape := bsBottomLine;
  end;

  btnQuit := TfpgButton.Create(Toolbar);
  with btnQuit do
  begin
    Name := 'btnQuit';
    SetPosition(4, 2, 24, 24);
    Text := '';
    Embedded := True;
    FontDesc := '#Label1';
    Hint := '';
    ImageMargin := -1;
    ImageName := 'stdimg.quit';
    ImageSpacing := 0;
    TabOrder := 1;
    OnClick := @miExitClicked;
  end;

  btnSave := TfpgButton.Create(Toolbar);
  with btnSave do
  begin
    Name := 'btnSave';
    SetPosition(56, 2, 24, 24);
    Text := '';
    Embedded := True;
    FontDesc := '#Label1';
    Hint := '';
    ImageMargin := -1;
    ImageName := 'stdimg.save';
    ImageSpacing := 0;
    TabOrder := 2;
  end;

  btnOpen := TfpgButton.Create(Toolbar);
  with btnOpen do
  begin
    Name := 'btnOpen';
    SetPosition(32, 2, 24, 24);
    Text := '';
    Embedded := True;
    FontDesc := '#Label1';
    Hint := '';
    ImageMargin := -1;
    ImageName := 'stdimg.open';
    ImageSpacing := 0;
    TabOrder := 3;
  end;

  btnAbout := TfpgButton.Create(Toolbar);
  with btnAbout do
  begin
    Name := 'btnAbout';
    SetPosition(84, 2, 24, 24);
    Text := '';
    Embedded := True;
    FontDesc := '#Label1';
    Hint := '';
    ImageMargin := -1;
    ImageName := 'stdimg.help';
    ImageSpacing := 0;
    TabOrder := 4;
    OnClick := @btnAboutClicked;
  end;

  edit1 := TfpgEdit.Create(self);
  with edit1 do
  begin
    Name := 'edit1';
    SetPosition(8, 62, 100, 24);
    ExtraHint := '';
    Hint := '';
    TabOrder := 6;
    Text := '';
    FontDesc := '#Edit1';
  end;

  Memo1 := TfpgMemo.Create(self);
  with Memo1 do
  begin
    Name := 'Memo1';
    SetPosition(124, 60, 268, 108);
    Anchors := [anLeft,anRight,anTop,anBottom];
    Hint := '';
    Lines.Add('<= Text Edit has a popup menu too.');
    FontDesc := '#Edit1';
    TabOrder := 10;
  end;

  FFileSubMenu := TfpgPopupMenu.Create(self);
  with FFileSubMenu do
  begin
    Name := 'FFileSubMenu';
    SetPosition(264, 60, 120, 20);
    AddMenuItem('&Open', 'Ctrl-O', @miMenuItemSelected);
    AddMenuItem('&Save', 'Ctrl-S', @miMenuItemSelected);
    AddMenuItem('S&ave As', 'Ctrl+Shift+S', @miMenuItemSelected);
    AddMenuItem('-', '', nil);
    AddMenuItem('Save && Reload', '', @miMenuItemSelected);
    AddMenuItem('-', '', nil);
    AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
  end;

  FEditSubMenu := TfpgPopupMenu.Create(self);
  with FEditSubMenu do
  begin
    Name := 'FEditSubMenu';
    SetPosition(264, 80, 120, 20);
    AddMenuItem('&Cut', 'Ctrl-X', @miMenuItemSelected);
    AddMenuItem('C&opy', 'Ctrl-C', @miMenuItemSelected);
    AddMenuItem('&Paste', 'Ctrl-V', @miMenuItemSelected);
    AddMenuItem('-', '', nil);
    AddMenuItem('&Spell check', 'F4', @miMenuItemSelected).Enabled := False;
  end;

  FEditSelectSubMenu := TfpgPopupMenu.Create(self);
  with FEditSelectSubMenu do
  begin
    Name := 'FEditSelectSubMenu';
    SetPosition(264, 100, 120, 20);
    AddMenuItem('Select All', '', @miMenuItemSelected);
    AddMenuItem('Select Word', '', @miMenuItemSelected);
    AddMenuItem('Select Line', '', @miMenuItemSelected);
    FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
  end;

  FViewSubMenu := TfpgPopupMenu.Create(self);
  with FViewSubMenu do
  begin
    Name := 'FViewSubMenu';
    SetPosition(264, 120, 120, 20);
    AddMenuItem('Full Screen', '', @miMenuItemChecked);
    AddMenuItem('Tool Bar', '', @miToolBarChecked).Checked := True;
    AddMenuItem('Status Bar', '', @miStatusBarChecked).Checked := True;
    AddMenuItem('Line Numbers', '', @miMenuItemChecked);
  end;

  FHelpSubMenu := TfpgPopupMenu.Create(self);
  with FHelpSubMenu do
  begin
    Name := 'FHelpSubMenu';
    SetPosition(264, 140, 120, 20);
    AddMenuItem('&About', 'F12', @btnAboutClicked);
    AddMenuItem('Test Russian text -> Òåñò', '', @miMenuItemSelected);
  end;

  {@VFD_BODY_END: MainForm}
  {%endregion}

  // Attach sub menus to main menu bar
  FMenuBar.AddMenuItem('&File', nil).SubMenu := FFileSubMenu;
  FMenuBar.AddMenuItem('&Edit', nil).SubMenu := FEditSubMenu;
  FMenuBar.AddMenuItem('&View', nil).SubMenu := FViewSubMenu;
  FMenuBar.AddMenuItem('&Windows', nil);
  FMenuBar.AddMenuItem('&Disabled', nil).Enabled := False;
  FMenuBar.AddMenuItem('&Help', nil).SubMenu := FHelpSubMenu;
end;


procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  frm.Show;
  fpgApplication.Run;
  frm.Free;
end;

begin
  MainProc;
end.