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
|
program menutest;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,
fpgfx,
gui_form,
gui_menu;
type
TMainForm = class(TfpgForm)
private
FMenuBar: TfpgMenuBar;
FFileSubMenu: TfpgPopupMenu;
FEditSubMenu: TfpgPopupMenu;
FEditSelectSubMenu: TfpgPopupMenu;
FHelpSubMenu: TfpgPopupMenu;
procedure miExitClicked(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
end;
{ TMainForm }
procedure TMainForm.miExitClicked(Sender: TObject);
begin
Close;
end;
constructor TMainForm.Create(AOwner: TComponent);
var
mi: TfpgMenuItem;
begin
inherited Create(AOwner);
WindowTitle := 'Menu Test';
WindowPosition := wpUser;
SetPosition(100, 100, 400, 200);
// Create top level sub-menus
FFileSubMenu := TfpgPopupMenu.Create(self);
FFileSubMenu.AddMenuItem('&Open', 'Ctrl-O', nil);
FFileSubMenu.AddMenuItem('&Save', 'Ctrl-S', nil);
FFileSubMenu.AddMenuItem('S&ave As', 'Ctrl+Shift+S', nil);
FFileSubMenu.AddMenuItem('-', '', nil);
FFileSubMenu.AddMenuItem('Save && Reload', '', nil);
FFileSubMenu.AddMenuItem('-', '', nil);
FFileSubMenu.AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
FEditSubMenu := TfpgPopupMenu.Create(self);
FEditSubMenu.AddMenuItem('&Cut', 'Ctrl-X', nil);
FEditSubMenu.AddMenuItem('C&opy', 'Ctrl-C', nil);
FEditSubMenu.AddMenuItem('&Paste', 'Ctrl-V', nil);
FEditSubMenu.AddMenuItem('-', '', nil);
FEditSubMenu.AddMenuItem('&Spell check', 'F4', nil).Enabled := False;
FEditSelectSubMenu := TfpgPopupMenu.Create(self);
FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
FEditSelectSubMenu.AddMenuItem('Select All', '', nil);
FEditSelectSubMenu.AddMenuItem('Select Word', '', nil);
FEditSelectSubMenu.AddMenuItem('Select Line', '', nil);
FHelpSubMenu := TfpgPopupMenu.Create(self);
FHelpSubMenu.AddMenuItem('&About', 'F12', nil);
FHelpSubMenu.AddMenuItem('Test Russian text -> Òåñò', '', nil);
// Create main menu bar
FMenuBar := TfpgMenuBar.Create(self);
FMenuBar.SetPosition(0, 0, Width, FMenuBar.Height);
FMenuBar.AddMenuItem('&File', nil).SubMenu := FFileSubMenu;
FMenuBar.AddMenuItem('&Edit', nil).SubMenu := FEditSubMenu;
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;
end;
begin
MainProc;
end.
|