summaryrefslogtreecommitdiff
path: root/examples/gui/menutest/menutest.lpr
blob: 1db064fbf29a1599fc89bcea95e4725dade0369a (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
program menutest;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  fpg_main,
  fpg_form,
  fpg_menu,
  fpg_edit;

type
  TMainForm = class(TfpgForm)
  private
    FMenuBar: TfpgMenuBar;
    FFileSubMenu: TfpgPopupMenu;
    FEditSubMenu: TfpgPopupMenu;
    FEditSelectSubMenu: TfpgPopupMenu;
    FHelpSubMenu: TfpgPopupMenu;
    edit1: TfpgEdit;
    procedure   miExitClicked(Sender: TObject);
    procedure   miMenuItemSelected(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;


{ TMainForm }

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

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

constructor TMainForm.Create(AOwner: TComponent);
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', @miMenuItemSelected);
  FFileSubMenu.AddMenuItem('&Save', 'Ctrl-S', @miMenuItemSelected);
  FFileSubMenu.AddMenuItem('S&ave As', 'Ctrl+Shift+S', @miMenuItemSelected);
  FFileSubMenu.AddMenuItem('-', '', nil);
  FFileSubMenu.AddMenuItem('Save && Reload', '', @miMenuItemSelected);
  FFileSubMenu.AddMenuItem('-', '', nil);
  FFileSubMenu.AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);

  FEditSubMenu := TfpgPopupMenu.Create(self);
  FEditSubMenu.AddMenuItem('&Cut', 'Ctrl-X', @miMenuItemSelected);
  FEditSubMenu.AddMenuItem('C&opy', 'Ctrl-C', @miMenuItemSelected);
  FEditSubMenu.AddMenuItem('&Paste', 'Ctrl-V', @miMenuItemSelected);
  FEditSubMenu.AddMenuItem('-', '', nil);
  FEditSubMenu.AddMenuItem('&Spell check', 'F4', @miMenuItemSelected).Enabled := False;
  FEditSelectSubMenu := TfpgPopupMenu.Create(self);
  FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
    FEditSelectSubMenu.AddMenuItem('Select All', '', @miMenuItemSelected);
    FEditSelectSubMenu.AddMenuItem('Select Word', '', @miMenuItemSelected);
    FEditSelectSubMenu.AddMenuItem('Select Line', '', @miMenuItemSelected);

  FHelpSubMenu := TfpgPopupMenu.Create(self);
  FHelpSubMenu.AddMenuItem('&About', 'F12', @miMenuItemSelected);
  FHelpSubMenu.AddMenuItem('Test Russian text -> Òåñò', '', @miMenuItemSelected);

  // Create main menu bar
  FMenuBar := CreateMenuBar(self);
  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;

  edit1 := TfpgEdit.Create(self);
  edit1.SetPosition(10, 70, 100, 24);
end;


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

begin
  MainProc;
end.