source: trunk/Packages/CoolDocking/UCDPopupMenu.pas

Last change on this file was 73, checked in by chronos, 12 years ago
  • Modified: Packages are now stored as uncomporessed and are linked with relative path to project.
File size: 11.0 KB
Line 
1unit UCDPopupMenu;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Menus, Forms, Controls, Dialogs,
9 ExtCtrls, ComCtrls, UCDCommon;
10
11type
12
13 { TCDPopupMenu }
14
15 TCDPopupMenu = class(TPopupMenu)
16 private
17 procedure PopupExecute(Sender: TObject);
18 procedure PopupMenuHeaderVisibleClick(Sender: TObject);
19 public
20 Manager: TCDManagerBase;
21 PositionMenu: TMenuItem;
22 StyleMenu: TMenuItem;
23 LockedMenu: TMenuItem;
24 HeaderVisibleMenu: TMenuItem;
25 constructor Create(AManager: TCDManagerBase);
26 procedure UncheckMenuGroup(Item: TMenuItem);
27 procedure PopupMenuListClick(Sender: TObject);
28 procedure PopupMenuTabsClick(Sender: TObject);
29 procedure PopupMenuPopupListClick(Sender: TObject);
30 procedure PopupMenuPopupTabsClick(Sender: TObject);
31 procedure PopupMenuCloseClick(Sender: TObject);
32 procedure PopupMenuRenameClick(Sender: TObject);
33 procedure PopupMenuPositionAutoClick(Sender: TObject);
34 procedure PopupMenuPositionLeftClick(Sender: TObject);
35 procedure PopupMenuPositionRightClick(Sender: TObject);
36 procedure PopupMenuPositionTopClick(Sender: TObject);
37 procedure PopupMenuPositionBottomClick(Sender: TObject);
38 procedure PopupMenuUndockClick(Sender: TObject);
39 procedure PopupMenuCustomizeClick(Sender: TObject);
40 procedure PopupMenuLockedClick(Sender: TObject);
41 end;
42
43implementation
44
45uses
46 UCDClient, UCDManagerTabs, UCDCustomize, UCDManager;
47
48resourcestring
49 SDockStyle = 'Style';
50 SDockList = 'List';
51 SDockTabs = 'Tabs';
52 SDockPopupList = 'Popup list';
53 SDockPopupTabs = 'Popup tabs';
54 SCloseForm = 'Close';
55 SRenameForm = 'Rename';
56 SPosition = 'Position';
57 SPositionAuto = 'Auto';
58 SPositionTop = 'Top';
59 SPositionLeft = 'Left';
60 SPositionRight = 'Right';
61 SPositionBottom = 'Bottom';
62 SUndock = 'Undock';
63 SCustomize = 'Customize...';
64 SEnterNewWindowName = 'Enter new window name';
65 SRenameWindow = 'Rename window';
66 SLocked = 'Locked';
67 SHeaderVisible = 'Header visible';
68
69{ TCDPopupMenu }
70
71procedure TCDPopupMenu.UncheckMenuGroup(Item: TMenuItem);
72var
73 I: Integer;
74begin
75 for I := 0 to Item.Count - 1 do
76 Item.Items[I].Checked := False;
77end;
78
79procedure TCDPopupMenu.PopupExecute(Sender: TObject);
80begin
81 UncheckMenuGroup(StyleMenu);
82 StyleMenu.Items[Integer(TCDManager(Manager).DockStyle)].Checked := True;
83 UncheckMenuGroup(PositionMenu);
84 PositionMenu.Items[Integer(TCDManager(Manager).HeaderPos)].Checked := True;;
85 LockedMenu.Checked := TCDManager(Manager).Locked;
86 HeaderVisibleMenu.Checked := TCDManager(Manager).HeaderVisible;
87end;
88
89constructor TCDPopupMenu.Create(AManager: TCDManagerBase);
90var
91 NewMenuItem: TMenuItem;
92 NewMenuItem2: TMenuItem;
93 I: Integer;
94begin
95 inherited Create(nil);
96 Manager := AManager;
97
98 Name := GetUniqueName(TCDManager(AManager).DockSite.Name + 'PopupMenu');
99 OnPopup := PopupExecute;
100
101 StyleMenu := TMenuItem.Create(Self);
102 StyleMenu.Caption := SDockStyle;
103 Items.Add(StyleMenu);
104
105 NewMenuItem2 := TMenuItem.Create(StyleMenu);
106 NewMenuItem2.Caption := SDockList;
107 NewMenuItem2.OnClick := PopupMenuListClick;
108 StyleMenu.Add(NewMenuItem2);
109
110 NewMenuItem2 := TMenuItem.Create(StyleMenu);
111 NewMenuItem2.Caption := SDockTabs;
112 NewMenuItem2.OnClick := PopupMenuTabsClick;
113 StyleMenu.Add(NewMenuItem2);
114
115 NewMenuItem2 := TMenuItem.Create(StyleMenu);
116 NewMenuItem2.Caption := SDockPopupTabs;
117 NewMenuItem2.OnClick := PopupMenuPopupTabsClick;
118 StyleMenu.Add(NewMenuItem2);
119
120 NewMenuItem2 := TMenuItem.Create(StyleMenu);
121 NewMenuItem2.Caption := SDockPopupList;
122 NewMenuItem2.OnClick := PopupMenuPopupListClick;
123 StyleMenu.Add(NewMenuItem2);
124
125 PositionMenu := TMenuItem.Create(Self);
126 PositionMenu.Caption := SPosition;
127 Items.Add(PositionMenu);
128
129 NewMenuItem2 := TMenuItem.Create(PositionMenu);
130 NewMenuItem2.Caption := SPositionAuto;
131 NewMenuItem2.OnClick := PopupMenuPositionAutoClick;
132 PositionMenu.Add(NewMenuItem2);
133
134 NewMenuItem2 := TMenuItem.Create(PositionMenu);
135 NewMenuItem2.Caption := SPositionLeft;
136 NewMenuItem2.OnClick := PopupMenuPositionLeftClick;
137 PositionMenu.Add(NewMenuItem2);
138
139 NewMenuItem2 := TMenuItem.Create(PositionMenu);
140 NewMenuItem2.Caption := SPositionTop;
141 NewMenuItem2.OnClick := PopupMenuPositionTopClick;
142 PositionMenu.Add(NewMenuItem2);
143
144 NewMenuItem2 := TMenuItem.Create(PositionMenu);
145 NewMenuItem2.Caption := SPositionRight;
146 NewMenuItem2.OnClick := PopupMenuPositionRightClick;
147 PositionMenu.Add(NewMenuItem2);
148
149 NewMenuItem2 := TMenuItem.Create(PositionMenu);
150 NewMenuItem2.Caption := SPositionBottom;
151 NewMenuItem2.OnClick := PopupMenuPositionBottomClick;
152 PositionMenu.Add(NewMenuItem2);
153
154 NewMenuItem := TMenuItem.Create(Self);
155 NewMenuItem.Caption := SCloseForm;
156 NewMenuItem.OnClick := PopupMenuCloseClick;
157 Items.Add(NewMenuItem);
158
159 NewMenuItem := TMenuItem.Create(Self);
160 NewMenuItem.Caption := SRenameForm;
161 NewMenuItem.OnClick := PopupMenuRenameClick;
162 Items.Add(NewMenuItem);
163
164 NewMenuItem := TMenuItem.Create(Self);
165 NewMenuItem.Caption := SUndock;
166 NewMenuItem.OnClick := PopupMenuUndockClick;
167 Items.Add(NewMenuItem);
168
169 NewMenuItem := TMenuItem.Create(Self);
170 NewMenuItem.Caption := SCustomize;
171 NewMenuItem.OnClick := PopupMenuCustomizeClick;
172 Items.Add(NewMenuItem);
173
174 LockedMenu := TMenuItem.Create(Self);
175 LockedMenu.Caption := SLocked;
176 LockedMenu.OnClick := PopupMenuLockedClick;
177 Items.Add(LockedMenu);
178
179 HeaderVisibleMenu := TMenuItem.Create(Self);
180 HeaderVisibleMenu.Caption := SHeaderVisible;
181 HeaderVisibleMenu.OnClick := PopupMenuHeaderVisibleClick;
182 Items.Add(HeaderVisibleMenu);
183end;
184
185procedure TCDPopupMenu.PopupMenuTabsClick(Sender: TObject);
186begin
187 TCDManager(Manager).DockStyle := dsTabs;
188end;
189
190procedure TCDPopupMenu.PopupMenuPopupListClick(Sender: TObject);
191begin
192 TCDManager(Manager).DockStyle := dsPopupList;
193end;
194
195procedure TCDPopupMenu.PopupMenuPopupTabsClick(Sender: TObject);
196begin
197 TCDManager(Manager).DockStyle := dsPopupTabs;
198end;
199
200procedure TCDPopupMenu.PopupMenuCloseClick(Sender: TObject);
201var
202 Control: TControl;
203begin
204 if PopupComponent is TPageControl then
205 with TPageControl(PopupComponent) do begin
206 TForm(TCDManagerTabsItem(TCDManagerTabs(Manager).DockItems[TabIndex]).Control).Close;
207 end;
208 if PopupComponent is TCDHeader then
209 with TCDHeader(PopupComponent) do begin
210 TForm(Control).Close;
211 end;
212end;
213
214procedure TCDPopupMenu.PopupMenuRenameClick(Sender: TObject);
215var
216 Value: string;
217begin
218 //ShowMessage(PopupComponent.ClassName);
219 if PopupComponent is TPageControl then
220 with TPageControl(PopupComponent) do begin
221 Value := TCDManagerTabsItem(TCDManagerTabs(Manager).DockItems[TabIndex]).Control.Caption;
222 if InputQuery(SRenameWindow, SEnterNewWindowName, False, Value) then begin
223 TCDManagerTabsItem(TCDManagerTabs(Manager).DockItems[TabIndex]).Control.Caption := Value;
224 Pages[TabIndex].Caption := Value;
225 end;
226 end;
227 if PopupComponent is TCDHeader then
228 with TCDHeader(PopupComponent) do begin
229 Value := Control.Caption;
230 if InputQuery(SRenameWindow, SEnterNewWindowName, False, Value) then begin
231 Control.Caption := Value;
232 Invalidate;
233 end;
234 end;
235end;
236
237procedure TCDPopupMenu.PopupMenuPositionAutoClick(Sender: TObject);
238begin
239 if PopupComponent is TPageControl then
240 with TPageControl(PopupComponent) do begin
241 TCDManagerTabs(Manager).HeaderPos := hpAuto;
242 end else
243 if PopupComponent is TCDHeader then
244 with TCDHeader(PopupComponent) do begin
245 TCDManager(TWinControl(Control).DockManager).HeaderPos := hpTop;
246 Invalidate;
247 end;
248end;
249
250procedure TCDPopupMenu.PopupMenuPositionLeftClick(Sender: TObject);
251begin
252 if PopupComponent is TPageControl then
253 with TPageControl(PopupComponent) do begin
254 TCDManagerTabs(Manager).HeaderPos := hpLeft;
255 end else
256 if PopupComponent is TCDHeader then
257 with TCDHeader(PopupComponent) do begin
258 TCDManager(TWinControl(Control).DockManager).HeaderPos := hpLeft;
259 Invalidate;
260 end;
261end;
262
263procedure TCDPopupMenu.PopupMenuPositionRightClick(Sender: TObject);
264begin
265 if PopupComponent is TPageControl then
266 with TPageControl(PopupComponent) do begin
267 TCDManagerTabs(Manager).HeaderPos := hpRight;
268 end else
269 if PopupComponent is TCDHeader then
270 with TCDHeader(PopupComponent) do begin
271 TCDManager(TWinControl(Control).DockManager).HeaderPos := hpRight;
272 Invalidate;
273 end;
274end;
275
276procedure TCDPopupMenu.PopupMenuPositionTopClick(Sender: TObject);
277begin
278 if PopupComponent is TPageControl then
279 with TPageControl(PopupComponent) do begin
280 TCDManagerTabs(Manager).HeaderPos := hpTop;
281 end else
282 if PopupComponent is TCDHeader then
283 with TCDHeader(PopupComponent) do begin
284 TCDManager(TWinControl(Control).DockManager).HeaderPos := hpTop;
285 Invalidate;
286 end;
287end;
288
289procedure TCDPopupMenu.PopupMenuPositionBottomClick(Sender: TObject);
290begin
291 if PopupComponent is TPageControl then
292 with TPageControl(PopupComponent) do begin
293 TCDManagerTabs(Manager).HeaderPos := hpBottom;
294 end else
295 if PopupComponent is TCDHeader then
296 with TCDHeader(PopupComponent) do begin
297 TCDManager(TWinControl(Control).DockManager).HeaderPos := hpBottom;
298 Invalidate;
299 end;
300end;
301
302procedure TCDPopupMenu.PopupMenuUndockClick(Sender: TObject);
303var
304 UndockControl: TControl;
305begin
306 if PopupComponent is TPageControl then
307 with TPageControl(PopupComponent) do begin
308 UndockControl := TCDManagerTabsItem(TCDManagerTabs(Manager).DockItems[TabIndex]).Control;
309 end else
310 if PopupComponent is TCDHeader then
311 with TCDHeader(PopupComponent) do begin
312 UndockControl := Control;
313 end else UndockControl := nil;
314 if Assigned(UndockControl) then
315 UndockControl.ManualFloat(UndockControl.BoundsRect);
316end;
317
318procedure TCDPopupMenu.PopupMenuCustomizeClick(Sender: TObject);
319begin
320 with TCDManager(Manager) do
321 if Assigned(Master) and
322 Assigned(Master.Customize) then
323 TCDCustomize(Master.Customize).Execute;
324end;
325
326procedure TCDPopupMenu.PopupMenuLockedClick(Sender: TObject);
327begin
328 if PopupComponent is TPageControl then
329 with TPageControl(PopupComponent) do begin
330 TCDManagerTabs(Manager).Locked := not TCDManagerTabs(Manager).Locked;
331 end else
332 if PopupComponent is TCDHeader then
333 with TCDHeader(PopupComponent) do begin
334 TCDManagerTabs(Manager).Locked := not TCDManagerTabs(Manager).Locked;
335 end;
336end;
337
338procedure TCDPopupMenu.PopupMenuHeaderVisibleClick(Sender: TObject);
339begin
340 if PopupComponent is TPageControl then
341 with TPageControl(PopupComponent) do begin
342 TCDManagerTabs(Manager).HeaderVisible := not TCDManagerTabs(Manager).HeaderVisible;
343 end else
344 if PopupComponent is TCDHeader then
345 with TCDHeader(PopupComponent) do begin
346 TCDManagerTabs(Manager).HeaderVisible := not TCDManagerTabs(Manager).HeaderVisible;
347 end;
348end;
349
350procedure TCDPopupMenu.PopupMenuListClick(Sender: TObject);
351begin
352 TCDManager(Manager).DockStyle := dsList;
353end;
354
355
356end.
357
Note: See TracBrowser for help on using the repository browser.