-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuBar.pas
executable file
·126 lines (109 loc) · 3.29 KB
/
MenuBar.pas
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
{*******************************************************}
{ }
{ Implements a TToolbar descendant that has a Menu to }
{ make IDE like Toolbar menus very easy. This works }
{ only in Delphi 4.0 or above }
{ }
{ Copyright (c) 1995,98 Inprise Corporation }
{ }
{-------------------------------------------------------}
{ * Minor bug when Menu remove notification }
{ isn't handled - fixed by Akzhan Abdulin (c) 1998 }
{ + Menu ShortCuts handling added (c) 2000 }
{*******************************************************}
unit MenuBar;
interface
uses
Windows, Messages, Classes, Controls, ComCtrls, Menus;
type
TMenuBar = class(TToolBar)
private
FMenu: TMainMenu;
procedure SetMenu(const Value: TMainMenu);
function HandleAppKeyDown(var Message: TWMKey): Boolean;
procedure CMDialogKey(var Message: TWMKey); message CM_DIALOGKEY;
protected
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
public
constructor Create(AOwner: TComponent); override;
published
property Flat default True;
property ShowCaptions default True;
property EdgeBorders default [];
property Menu: TMainMenu read FMenu write SetMenu;
end;
procedure Register;
implementation
uses
SysUtils, Forms;
procedure Register;
begin
RegisterComponents('Samples', [TMenuBar]);
end;
{ TMenuBar }
procedure TMenuBar.CMDialogKey(var Message: TWMKey);
begin
if not HandleAppKeyDown(Message) then Inherited;
end;
constructor TMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Flat := True;
ShowCaptions := True;
EdgeBorders := [];
ControlStyle := [csCaptureMouse, csClickEvents,
csDoubleClicks, csMenuEvents, csSetCaption];
end;
procedure TMenuBar.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
end;
function TMenuBar.HandleAppKeyDown(var Message: TWMKey): Boolean;
begin
if Assigned(Menu) and Menu.IsShortCut(Message) then
begin
Message.Result := 1;
Result := True;
end
else
Result := False;
end;
procedure TMenuBar.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (AComponent = FMenu) and (Operation = opRemove) then
begin
SetMenu(nil);
end;
Inherited;
end;
procedure TMenuBar.SetMenu(const Value: TMainMenu);
var
i: Integer;
Button: TToolButton;
begin
if FMenu = Value then exit;
if ButtonCount > 0 then
for i := Pred(ButtonCount) downto 0 do
Buttons[i].Free;
FMenu := Value;
if not Assigned(FMenu) then exit;
for i := ButtonCount to Pred(FMenu.Items.Count) do
begin
Button := TToolButton.Create(Self);
try
Button.AutoSize := True;
Button.Grouped := True;
Button.Parent := Self;
Buttons[i].MenuItem := FMenu.Items[i];
except
Button.Free;
raise;
end;
end;
{ Copy attributes from each menu item }
for i := 0 to Pred(FMenu.Items.Count) do
Buttons[i].MenuItem := FMenu.Items[i];
end;
end.