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
|
{
fpGUI - Free Pascal GUI Library
Menu 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}
{
All menu and menu item implementations
}
{$IFDEF read_interface}
{ TMenuItem }
TMenuItem = class(TCustomPanel)
private
FHotKeyDef: string;
FSeparator: boolean;
protected
procedure Paint(Canvas: TFCanvas); override;
function ProcessEvent(Event: TEventObj): Boolean; override;
public
constructor Create(const pText: string; pOwner: TComponent); overload;
published
property Separator: boolean read FSeparator write FSeparator;
property HotKeyDef: string read FHotKeyDef write FHotKeyDef;
property Text;
property Visible;
property Enabled;
end;
{ TMenuBar }
TMenuBar = class(TCustomBoxLayout)
private
protected
public
constructor Create(AOwner: TComponent); override;
function AddMenu(const pTitle: string): TMenuItem;
function AddMenu(const pTitle: string; const pHotKeyDef: string; pHandlerProc: TNotifyEvent): TMenuItem;
published
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
{ TMenuItem }
procedure TMenuItem.Paint(Canvas: TFCanvas);
begin
if (wsClicked in WidgetState) or (wsMouseInside in WidgetState) then
FBevelStyle := bsLowered
else
FBevelStyle := bsPlain;
inherited Paint(Canvas);
end;
function TMenuItem.ProcessEvent(Event: TEventObj): Boolean;
begin
{$IFDEF DEBUG}
if Event.InheritsFrom(TMouseEnterEventObj) then
writeln(Format('MouseEnter for %s:%s', [Text, Classname]))
else if Event.InheritsFrom(TMouseLeaveEventObj) then
writeln(Format('MouseLeave for %s:%s', [Text, Classname]));
{$ENDIF}
if Event.InheritsFrom(TMouseEnterEventObj) then
begin
Include(WidgetState, wsMouseInside);
Redraw;
result := True;
end
else if Event.InheritsFrom(TMouseLeaveEventObj) then
begin
Exclude(WidgetState, wsMouseInside);
Redraw;
result := True;
end
else
result := inherited ProcessEvent(Event);
end;
constructor TMenuItem.Create(const pText: string; pOwner: TComponent);
begin
inherited Create(pText, pOwner);
WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
FBevelStyle := bsPlain;
end;
constructor TMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
FCanExpandHeight := False;
Spacing := 0;
end;
function TMenuBar.AddMenu(const pTitle: string): TMenuItem;
begin
Result := TMenuItem.Create(pTitle, self);
InsertChild(Result);
end;
function TMenuBar.AddMenu(const pTitle: string; const pHotKeyDef: string;
pHandlerProc: TNotifyEvent): TMenuItem;
begin
Result := AddMenu(pTitle);
if pTitle <> '-' then
begin
Result.Text := pTitle;
Result.HotKeyDef := pHotKeyDef;
Result.OnClick := pHandlerProc;
end
else
Result.Separator := True;
end;
{$ENDIF read_implementation}
|