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
|
{
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
function ProcessEvent(pEvent: 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(TBinWidget)
private
protected
procedure Paint(Canvas: TFCanvas); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function AddMenu(const pTitle: string): TMenuItem;
function AddMenu(const pTitle: string; const pHotKeyDef: string; pHandlerProc: TNotifyEvent): TMenuItem;
published
// FLayout: TBoxLayout;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
{ TMenuItem }
function TMenuItem.ProcessEvent(pEvent: TEventObj): Boolean;
begin
if pEvent.InheritsFrom(TMouseMoveEventObj) then
Writeln('MenuItem ' + Text
+ ' X=' + IntToStr(TMouseMoveEventObj(pEvent).Position.X)
+ ',Y=' + IntToStr(TMouseMoveEventObj(pEvent).Position.Y));
Result := inherited ProcessEvent(pEvent);
end;
constructor TMenuItem.Create(const pText: string; pOwner: TComponent);
begin
inherited Create(pText, pOwner);
FBevelStyle := bsPlain;
end;
procedure TMenuBar.Paint(Canvas: TFCanvas);
{var
i: integer; }
begin
// inherited Paint(Canvas);
Style.DrawWindowBackground(Canvas, ClientRect);
// FLayout.Paint(Canvas);
{
for i := 1 to VisibleCount do
begin
DrawColumn(Canvas, i, i = FFocusItem);
end;
Style.DrawSeparator(
Canvas,
Rect(0, ClientRect.Bottom - 4, ClientRect.Right, ClientRect.Bottom),
Horizontal);
}
end;
constructor TMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
FCanExpandWidth := True;
{
FLayout := TBoxLayout.Create(nil);
FLayout.Spacing := 0;
FLayout.BorderSpacing := 6;
FLayout.HorzAlign := horzLeft;
InsertChild(FLayout);
}
end;
destructor TMenuBar.Destroy;
begin
// RemoveChild(FLayout);
// FLayout.Free;
inherited Destroy;
end;
function TMenuBar.AddMenu(const pTitle: string): TMenuItem;
begin
Result := TMenuItem.Create(pTitle, self);
// FLayout.InsertChild(Result);
end;
function TMenuBar.AddMenu(const pTitle: string; const pHotKeyDef: string;
pHandlerProc: TNotifyEvent): TMenuItem;
begin
Result := TMenuItem.Create(self);
if pTitle <> '-' then
begin
Result.Text := pTitle;
Result.HotKeyDef := pHotKeyDef;
Result.OnClick := pHandlerProc;
end
else
begin
Result.Separator := True;
end;
// FLayout.InsertChild(Result);
end;
{$ENDIF read_implementation}
|