1 | unit UCDPopupMenu;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Menus, Forms, Controls, Dialogs,
|
---|
9 | ExtCtrls, ComCtrls, UCDCommon;
|
---|
10 |
|
---|
11 | type
|
---|
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 |
|
---|
43 | implementation
|
---|
44 |
|
---|
45 | uses
|
---|
46 | UCDClient, UCDManagerTabs, UCDCustomize, UCDManager;
|
---|
47 |
|
---|
48 | resourcestring
|
---|
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 |
|
---|
71 | procedure TCDPopupMenu.UncheckMenuGroup(Item: TMenuItem);
|
---|
72 | var
|
---|
73 | I: Integer;
|
---|
74 | begin
|
---|
75 | for I := 0 to Item.Count - 1 do
|
---|
76 | Item.Items[I].Checked := False;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TCDPopupMenu.PopupExecute(Sender: TObject);
|
---|
80 | begin
|
---|
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;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | constructor TCDPopupMenu.Create(AManager: TCDManagerBase);
|
---|
90 | var
|
---|
91 | NewMenuItem: TMenuItem;
|
---|
92 | NewMenuItem2: TMenuItem;
|
---|
93 | I: Integer;
|
---|
94 | begin
|
---|
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);
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TCDPopupMenu.PopupMenuTabsClick(Sender: TObject);
|
---|
186 | begin
|
---|
187 | TCDManager(Manager).DockStyle := dsTabs;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | procedure TCDPopupMenu.PopupMenuPopupListClick(Sender: TObject);
|
---|
191 | begin
|
---|
192 | TCDManager(Manager).DockStyle := dsPopupList;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure TCDPopupMenu.PopupMenuPopupTabsClick(Sender: TObject);
|
---|
196 | begin
|
---|
197 | TCDManager(Manager).DockStyle := dsPopupTabs;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TCDPopupMenu.PopupMenuCloseClick(Sender: TObject);
|
---|
201 | var
|
---|
202 | Control: TControl;
|
---|
203 | begin
|
---|
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;
|
---|
212 | end;
|
---|
213 |
|
---|
214 | procedure TCDPopupMenu.PopupMenuRenameClick(Sender: TObject);
|
---|
215 | var
|
---|
216 | Value: string;
|
---|
217 | begin
|
---|
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;
|
---|
235 | end;
|
---|
236 |
|
---|
237 | procedure TCDPopupMenu.PopupMenuPositionAutoClick(Sender: TObject);
|
---|
238 | begin
|
---|
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;
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TCDPopupMenu.PopupMenuPositionLeftClick(Sender: TObject);
|
---|
251 | begin
|
---|
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;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | procedure TCDPopupMenu.PopupMenuPositionRightClick(Sender: TObject);
|
---|
264 | begin
|
---|
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;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | procedure TCDPopupMenu.PopupMenuPositionTopClick(Sender: TObject);
|
---|
277 | begin
|
---|
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;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TCDPopupMenu.PopupMenuPositionBottomClick(Sender: TObject);
|
---|
290 | begin
|
---|
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;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure TCDPopupMenu.PopupMenuUndockClick(Sender: TObject);
|
---|
303 | var
|
---|
304 | UndockControl: TControl;
|
---|
305 | begin
|
---|
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);
|
---|
316 | end;
|
---|
317 |
|
---|
318 | procedure TCDPopupMenu.PopupMenuCustomizeClick(Sender: TObject);
|
---|
319 | begin
|
---|
320 | with TCDManager(Manager) do
|
---|
321 | if Assigned(Master) and
|
---|
322 | Assigned(Master.Customize) then
|
---|
323 | TCDCustomize(Master.Customize).Execute;
|
---|
324 | end;
|
---|
325 |
|
---|
326 | procedure TCDPopupMenu.PopupMenuLockedClick(Sender: TObject);
|
---|
327 | begin
|
---|
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;
|
---|
336 | end;
|
---|
337 |
|
---|
338 | procedure TCDPopupMenu.PopupMenuHeaderVisibleClick(Sender: TObject);
|
---|
339 | begin
|
---|
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;
|
---|
348 | end;
|
---|
349 |
|
---|
350 | procedure TCDPopupMenu.PopupMenuListClick(Sender: TObject);
|
---|
351 | begin
|
---|
352 | TCDManager(Manager).DockStyle := dsList;
|
---|
353 | end;
|
---|
354 |
|
---|
355 |
|
---|
356 | end.
|
---|
357 |
|
---|