1 | unit UDockManagement;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Forms, Classes, Types, Windows, Messages, SysUtils, Variants, Graphics,
|
---|
7 | Controls, Dialogs, Menus, StdCtrls, ExtCtrls, ComCtrls, XPMan, Grids,
|
---|
8 | FindFile, Math, Tabs, DockTabSet, ToolWin, ImgList, ActnList, URegistry;
|
---|
9 |
|
---|
10 | const
|
---|
11 | RegistryRootKey = HKEY_CURRENT_USER;
|
---|
12 |
|
---|
13 | type
|
---|
14 | TDockFormInitState = class
|
---|
15 | DockSite: string;
|
---|
16 | Width: Integer;
|
---|
17 | Height: Integer;
|
---|
18 | Form: TForm;
|
---|
19 | Visible: Boolean;
|
---|
20 | end;
|
---|
21 |
|
---|
22 | TDockPanelAction = (dpaUndock, dpaDock, dpaClose, dpaShow);
|
---|
23 |
|
---|
24 | TDDockForm = class(TForm)
|
---|
25 | protected
|
---|
26 | procedure DoClose(var Action: TCloseAction); override;
|
---|
27 | procedure DoShow; override;
|
---|
28 | public
|
---|
29 | FormInitStateList: TList;
|
---|
30 | constructor Create(AOwner: TComponent); override;
|
---|
31 | end;
|
---|
32 |
|
---|
33 | TDDockPanel = class(TPanel)
|
---|
34 | procedure DoDockOver(Source: TDragDockObject; X, Y: Integer;
|
---|
35 | State: TDragState; var Accept: Boolean); override;
|
---|
36 | procedure DockDrop(Source: TDragDockObject; X, Y: Integer); override;
|
---|
37 | function DoUnDock(NewTarget: TWinControl; Client: TControl): Boolean; override;
|
---|
38 | end;
|
---|
39 |
|
---|
40 | TDDockTabSet = class(TDockTabSet)
|
---|
41 | procedure DockDrop(Source: TDragDockObject; X, Y: Integer); override;
|
---|
42 | private
|
---|
43 | procedure TabRemoved(Sender: TObject);
|
---|
44 | property OnTabRemoved;
|
---|
45 | public
|
---|
46 | constructor Create(AOwner: TComponent); override;
|
---|
47 | end;
|
---|
48 |
|
---|
49 | TDBaseDockPanel = class(TPanel)
|
---|
50 | PanelCenter: TDDockPanel;
|
---|
51 | PanelLeft: TDDockPanel;
|
---|
52 | PanelTop: TDDockPanel;
|
---|
53 | PanelRight: TDDockPanel;
|
---|
54 | PanelBottom: TDDockPanel;
|
---|
55 | DockTabSetLeft: TDDockTabSet;
|
---|
56 | DockTabSetTop: TDDockTabSet;
|
---|
57 | DockTabSetRight: TDDockTabSet;
|
---|
58 | DockTabSetBottom: TDDockTabSet;
|
---|
59 | SplitterLeft: TSplitter;
|
---|
60 | SplitterTop: TSplitter;
|
---|
61 | SplitterRight: TSplitter;
|
---|
62 | SplitterBottom: TSplitter;
|
---|
63 | public
|
---|
64 | DockPanelWidth: Integer;
|
---|
65 | procedure DockPanelCloseForm(Source: TForm; Panel: TPanel; Action: TDockPanelAction);
|
---|
66 | constructor Create(AOwner: TComponent); override;
|
---|
67 | end;
|
---|
68 |
|
---|
69 | TDDockManager = class
|
---|
70 | BaseDockPanel: TDBaseDockPanel;
|
---|
71 | RegistryKey: string;
|
---|
72 | DockFormList: TList;
|
---|
73 | DockFormInitStateList: TList;
|
---|
74 | Owner: TComponent;
|
---|
75 | procedure SaveToRegistry;
|
---|
76 | procedure LoadFromRegistry;
|
---|
77 | procedure RegisterDockForm(AForm: TForm; InitWidth, InitHeight: Integer; InitDockSite: string; InitVisible: Boolean);
|
---|
78 | constructor Create(AOwner: TComponent);
|
---|
79 | destructor Destroy; override;
|
---|
80 | end;
|
---|
81 |
|
---|
82 |
|
---|
83 | implementation
|
---|
84 |
|
---|
85 | uses Registry;
|
---|
86 |
|
---|
87 |
|
---|
88 | { TDDockManager }
|
---|
89 |
|
---|
90 | procedure TDDockManager.RegisterDockForm(AForm: TForm; InitWidth, InitHeight: Integer; InitDockSite: string; InitVisible: Boolean);
|
---|
91 | begin
|
---|
92 | with TDockFormInitState(DockFormInitStateList[DockFormInitStateList.Add(TDockFormInitState.Create)]) do begin
|
---|
93 | DockSite := InitDockSite;
|
---|
94 | Visible := InitVisible;
|
---|
95 | Width := InitWidth;
|
---|
96 | Height := InitHeight;
|
---|
97 | Form := AForm;
|
---|
98 | Owner.InsertComponent(Form);
|
---|
99 | end;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | procedure TDDockManager.SaveToRegistry;
|
---|
103 | var
|
---|
104 | I: Integer;
|
---|
105 | DockData: TMemoryStream;
|
---|
106 | Buffer: array of Byte;
|
---|
107 | begin
|
---|
108 | with TRegistryEx.Create do
|
---|
109 | try
|
---|
110 | RootKey := RegistryRootKey;
|
---|
111 | for I := 0 to DockFormInitStateList.Count - 1 do
|
---|
112 | with TDockFormInitState(DockFormInitStateList[I]).Form do begin
|
---|
113 | OpenKey(RegistryKey + '\Dock\' + Name, True);
|
---|
114 | WriteBool('Visible', Visible);
|
---|
115 | WriteInteger('LRDockWidth', LRDockWidth);
|
---|
116 | WriteInteger('TBDockHeight', TBDockHeight);
|
---|
117 | WriteInteger('UndockWidth', UndockWidth);
|
---|
118 | WriteInteger('UndockHeight', UndockHeight);
|
---|
119 | WriteInteger('Width', Width);
|
---|
120 | WriteInteger('Height', Height);
|
---|
121 | WriteInteger('Top', Top);
|
---|
122 | WriteInteger('Left', Left);
|
---|
123 | WriteInteger('Orientation', Integer(DockOrientation));
|
---|
124 | WriteBool('Docked', not Floating);
|
---|
125 | if not Floating then WriteString('TargetDockSite', HostDockSite.Name);
|
---|
126 | WriteInteger('Align', Integer(alLeft));
|
---|
127 | end;
|
---|
128 | OpenKey(RegistryKey + '\Dock', True);
|
---|
129 | if BaseDockPanel.PanelTop.Height = 0 then WriteInteger('PanelTopHeight', BaseDockPanel.PanelTop.Tag)
|
---|
130 | else WriteInteger('PanelTopHeight', BaseDockPanel.PanelTop.Height);
|
---|
131 | if BaseDockPanel.PanelLeft.Width = 0 then WriteInteger('PanelLeftWidth', BaseDockPanel.PanelLeft.Tag)
|
---|
132 | else WriteInteger('PanelLeftWidth', BaseDockPanel.PanelLeft.Width);
|
---|
133 | if BaseDockPanel.PanelRight.Width = 0 then WriteInteger('PanelRightWidth', BaseDockPanel.PanelRight.Tag)
|
---|
134 | else WriteInteger('PanelRightWidth', BaseDockPanel.PanelRight.Width);
|
---|
135 | if BaseDockPanel.PanelBottom.Height = 0 then WriteInteger('PanelBottomHeight', BaseDockPanel.PanelBottom.Tag)
|
---|
136 | else WriteInteger('PanelBottomHeight', BaseDockPanel.PanelBottom.Height);
|
---|
137 |
|
---|
138 | with BaseDockPanel do begin
|
---|
139 | DockData := TMemoryStream.Create;
|
---|
140 | PanelTop.DockManager.SaveToStream(DockData);
|
---|
141 | SetLength(Buffer, DockData.Size);
|
---|
142 | DockData.Position := 0;
|
---|
143 | DockData.Read(Buffer[0], Length(Buffer));
|
---|
144 | WriteBinaryData('PanelTopDockZone', Buffer[0], Length(Buffer));
|
---|
145 |
|
---|
146 | DockData.Clear;
|
---|
147 | PanelLeft.DockManager.SaveToStream(DockData);
|
---|
148 | SetLength(Buffer, DockData.Size);
|
---|
149 | DockData.Position := 0;
|
---|
150 | DockData.Read(Buffer[0], Length(Buffer));
|
---|
151 | WriteBinaryData('PanelLeftDockZone', Buffer[0], Length(Buffer));
|
---|
152 |
|
---|
153 | DockData.Clear;
|
---|
154 | Panelright.DockManager.SaveToStream(DockData);
|
---|
155 | SetLength(Buffer, DockData.Size);
|
---|
156 | DockData.Position := 0;
|
---|
157 | DockData.Read(Buffer[0], Length(Buffer));
|
---|
158 | WriteBinaryData('PanelRightDockZone', Buffer[0], Length(Buffer));
|
---|
159 |
|
---|
160 | DockData.Clear;
|
---|
161 | PanelBottom.DockManager.SaveToStream(DockData);
|
---|
162 | SetLength(Buffer, DockData.Size);
|
---|
163 | DockData.Position := 0;
|
---|
164 | DockData.Read(Buffer[0], Length(Buffer));
|
---|
165 | WriteBinaryData('PanelBottomDockZone', Buffer[0], Length(Buffer));
|
---|
166 |
|
---|
167 | DockData.Clear;
|
---|
168 | PanelCenter.DockManager.SaveToStream(DockData);
|
---|
169 | SetLength(Buffer, DockData.Size);
|
---|
170 | DockData.Position := 0;
|
---|
171 | DockData.Read(Buffer[0], Length(Buffer));
|
---|
172 | WriteBinaryData('PanelCenterDockZone', Buffer[0], Length(Buffer));
|
---|
173 |
|
---|
174 | DockData.Free;
|
---|
175 | end;
|
---|
176 | finally
|
---|
177 | Free;
|
---|
178 | end;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | constructor TDDockManager.Create(AOwner: TComponent);
|
---|
182 | begin
|
---|
183 | DockFormInitStateList := TList.Create;
|
---|
184 | DockFormList := TList.Create;
|
---|
185 | Owner := AOwner;
|
---|
186 | end;
|
---|
187 |
|
---|
188 | destructor TDDockManager.Destroy;
|
---|
189 | var
|
---|
190 | I: Integer;
|
---|
191 | begin
|
---|
192 | inherited;
|
---|
193 | DockFormList.Destroy;
|
---|
194 | for I := 0 to DockFormInitStateList.Count - 1 do
|
---|
195 | TDockFormInitState(DockFormInitStateList[I]).Destroy;
|
---|
196 | DockFormInitStateList.Destroy;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TDDockManager.LoadFromRegistry;
|
---|
200 | const
|
---|
201 | ReadBufferSite = 100000;
|
---|
202 | var
|
---|
203 | I: Integer;
|
---|
204 | DockData: TMemoryStream;
|
---|
205 | Buffer: array of Byte;
|
---|
206 | begin
|
---|
207 | with TRegistryEx.Create do
|
---|
208 | try
|
---|
209 | RootKey := RegistryRootKey;
|
---|
210 | OpenKey(RegistryKey + '\Dock', True);
|
---|
211 |
|
---|
212 | with BaseDockPanel do begin
|
---|
213 | PanelTop.Tag := ReadIntegerWithDefault('PanelTopHeight', PanelTop.Tag);
|
---|
214 | if PanelTop.Tag > Height then PanelTop.Tag := Height div 2;
|
---|
215 | if PanelTop.Tag = 0 then PanelTop.Tag := 10;
|
---|
216 |
|
---|
217 | PanelLeft.Tag := ReadIntegerWithDefault('PanelLeftWidth', PanelLeft.Tag);
|
---|
218 | if PanelLeft.Tag > Width then PanelLeft.Tag := Width div 2;
|
---|
219 | if PanelLeft.Tag = 0 then PanelLeft.Tag := 10;
|
---|
220 |
|
---|
221 | PanelRight.Tag := ReadIntegerWithDefault('PanelRightWidth', PanelRight.Tag);
|
---|
222 | if PanelRight.Tag > Width then PanelRight.Tag := Width div 2;
|
---|
223 | if PanelRight.Tag = 0 then PanelRight.Tag := 10;
|
---|
224 |
|
---|
225 | PanelBottom.Tag := ReadIntegerWithDefault('PanelBottomHeight', PanelBottom.Tag);
|
---|
226 | if PanelBottom.Tag > Height then PanelBottom.Tag := Height div 2;
|
---|
227 | if PanelBottom.Tag = 0 then PanelBottom.Tag := 10;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | for I := 0 to DockFormInitStateList.Count - 1 do
|
---|
231 | with TDockFormInitState(DockFormInitStateList[I]) do begin
|
---|
232 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
233 | Form.DockOrientation := TDockOrientation(ReadIntegerWithDefault('Orientation', 0));
|
---|
234 | Form.TBDockHeight := ReadIntegerWithDefault('TBDockHeight', Height);
|
---|
235 | Form.LRDockWidth := ReadIntegerWithDefault('LRDockWidth', Width);
|
---|
236 | Form.UndockHeight := ReadIntegerWithDefault('UndockHeight', Height);
|
---|
237 | Form.UndockWidth := ReadIntegerWithDefault('UndockWidth', Width);
|
---|
238 | Form.Width := ReadIntegerWithDefault('Width', Width);
|
---|
239 | Form.Height := ReadIntegerWithDefault('Height', Height);
|
---|
240 | Form.Top := ReadIntegerWithDefault('Top', (Screen.Width - Width) div 2);
|
---|
241 | Form.Left := ReadIntegerWithDefault('Left', (Screen.Width - Width) div 2);
|
---|
242 | if ReadBoolWithDefault('Docked', True) then begin
|
---|
243 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'DockTabSetLeft' then begin
|
---|
244 | Visible := True;
|
---|
245 | Form.Visible := True;
|
---|
246 | BaseDockPanel.DockTabSetLeft.Visible := True;
|
---|
247 | Form.ManualDock(BaseDockPanel.DockTabSetLeft, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
248 | end;
|
---|
249 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'DockTabSetTop' then begin
|
---|
250 | Visible := True;
|
---|
251 | Form.Visible := True;
|
---|
252 | BaseDockPanel.DockTabSetTop.Visible := True;
|
---|
253 | Form.ManualDock(BaseDockPanel.DockTabSetTop, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
254 | end;
|
---|
255 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'DockTabSetRight' then begin
|
---|
256 | Visible := True;
|
---|
257 | Form.Visible := True;
|
---|
258 | BaseDockPanel.DockTabSetRight.Visible := True;
|
---|
259 | Form.ManualDock(BaseDockPanel.DockTabSetRight, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
260 | end;
|
---|
261 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'DockTabSetBottom' then begin
|
---|
262 | Visible := True;
|
---|
263 | Form.Visible := True;
|
---|
264 | BaseDockPanel.DockTabSetBottom.Visible := True;
|
---|
265 | Form.ManualDock(BaseDockPanel.DockTabSetBottom, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
266 | end;
|
---|
267 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'PanelTop' then begin
|
---|
268 | OpenKey(RegistryKey + '\Dock', True);
|
---|
269 | if not ValueExists('PanelTopDockZone') then Form.ManualDock(BaseDockPanel.PanelTop, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
270 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
271 | Form.Visible := ReadBoolWithDefault('Visible', Visible);
|
---|
272 | end;
|
---|
273 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'PanelLeft' then begin
|
---|
274 | OpenKey(RegistryKey + '\Dock', True);
|
---|
275 | if not ValueExists('PanelLeftDockZone') then Form.ManualDock(BaseDockPanel.PanelLeft, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
276 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
277 | Form.Visible := ReadBoolWithDefault('Visible', Visible);
|
---|
278 | end;
|
---|
279 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'PanelRight' then begin
|
---|
280 | OpenKey(RegistryKey + '\Dock', True);
|
---|
281 | if not ValueExists('PanelRightDockZone') then Form.ManualDock(BaseDockPanel.PanelRight, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
282 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
283 | Form.Visible := ReadBoolWithDefault('Visible', Visible);
|
---|
284 | end;
|
---|
285 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'PanelBottom' then begin
|
---|
286 | OpenKey(RegistryKey + '\Dock', True);
|
---|
287 | if not ValueExists('PanelBottomDockZone') then Form.ManualDock(BaseDockPanel.PanelBottom, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
288 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
289 | Form.Visible := ReadBoolWithDefault('Visible', Visible);
|
---|
290 | end;
|
---|
291 | if ReadStringWithDefault('TargetDockSite', DockSite) = 'PanelCenter' then begin
|
---|
292 | OpenKey(RegistryKey + '\Dock', True);
|
---|
293 | if not ValueExists('PanelCenterDockZone') then Form.ManualDock(BaseDockPanel.PanelCenter, Form, TAlign(ReadIntegerWithDefault('Align', 0)));
|
---|
294 | OpenKey(RegistryKey + '\Dock\' + Form.Name, True);
|
---|
295 | Form.Visible := ReadBoolWithDefault('Visible', Visible);
|
---|
296 | end;
|
---|
297 | end;
|
---|
298 | end;
|
---|
299 |
|
---|
300 | OpenKey(RegistryKey + '\Dock', True);
|
---|
301 | with BaseDockPanel do begin
|
---|
302 | DockData := TMemoryStream.Create;
|
---|
303 | if ValueExists('PanelTopDockZone') then begin
|
---|
304 | SetLength(Buffer, ReadBufferSite);
|
---|
305 | SetLength(Buffer, ReadBinaryData('PanelTopDockZone', Buffer[0], Length(Buffer)));
|
---|
306 | DockData.Clear;
|
---|
307 | DockData.Write(Buffer[0], Length(Buffer));
|
---|
308 | DockData.Position := 0;
|
---|
309 | PanelTop.DockManager.LoadFromStream(DockData);
|
---|
310 | end;
|
---|
311 | if ValueExists('PanelLeftDockZone') then begin
|
---|
312 | SetLength(Buffer, ReadBufferSite);
|
---|
313 | SetLength(Buffer, ReadBinaryData('PanelLeftDockZone', Buffer[0], Length(Buffer)));
|
---|
314 | DockData.Clear;
|
---|
315 | DockData.Write(Buffer[0], Length(Buffer));
|
---|
316 | DockData.Position := 0;
|
---|
317 | PanelLeft.DockManager.LoadFromStream(DockData);
|
---|
318 | //DockTree(PanelLeft.DockManager).
|
---|
319 | end;
|
---|
320 | if ValueExists('PanelRightDockZone') then begin
|
---|
321 | SetLength(Buffer, ReadBufferSite);
|
---|
322 | SetLength(Buffer, ReadBinaryData('PanelRightDockZone', Buffer[0], Length(Buffer)));
|
---|
323 | DockData.Clear;
|
---|
324 | DockData.Write(Buffer[0], Length(Buffer));
|
---|
325 | DockData.Position := 0;
|
---|
326 | PanelRight.DockManager.LoadFromStream(DockData);
|
---|
327 | end;
|
---|
328 | if ValueExists('PanelBottomDockZone') then begin
|
---|
329 | SetLength(Buffer, ReadBufferSite);
|
---|
330 | SetLength(Buffer, ReadBinaryData('PanelBottomDockZone', Buffer[0], Length(Buffer)));
|
---|
331 | DockData.Clear;
|
---|
332 | DockData.Write(Buffer[0], Length(Buffer));
|
---|
333 | DockData.Position := 0;
|
---|
334 | PanelBottom.DockManager.LoadFromStream(DockData);
|
---|
335 | end;
|
---|
336 | if ValueExists('PanelCenterDockZone') then begin
|
---|
337 | SetLength(Buffer, ReadBufferSite);
|
---|
338 | SetLength(Buffer, ReadBinaryData('PanelCenterDockZone', Buffer[0], Length(Buffer)));
|
---|
339 | DockData.Clear;
|
---|
340 | DockData.Write(Buffer[0], Length(Buffer));
|
---|
341 | DockData.Position := 0;
|
---|
342 | PanelCenter.DockManager.LoadFromStream(DockData);
|
---|
343 | end;
|
---|
344 | DockData.Free;
|
---|
345 | end;
|
---|
346 |
|
---|
347 | finally
|
---|
348 | Free;
|
---|
349 | end;
|
---|
350 | end;
|
---|
351 |
|
---|
352 |
|
---|
353 | { TDDockForm }
|
---|
354 |
|
---|
355 | constructor TDDockForm.Create(AOwner: TComponent);
|
---|
356 | begin
|
---|
357 | inherited;
|
---|
358 | DragKind := dkDock;
|
---|
359 | DragMode := dmAutomatic;
|
---|
360 | FormStyle := fsStayOnTop;
|
---|
361 | end;
|
---|
362 |
|
---|
363 | procedure TDBaseDockPanel.DockPanelCloseForm(Source: TForm; Panel: TPanel;
|
---|
364 | Action: TDockPanelAction);
|
---|
365 | var
|
---|
366 | I: Integer;
|
---|
367 | VisibleDockClientCount: Integer;
|
---|
368 | begin
|
---|
369 | if not Assigned(Panel) then Exit;
|
---|
370 |
|
---|
371 | VisibleDockClientCount := 0;
|
---|
372 | for I := 0 to Panel.DockClientCount - 1 do
|
---|
373 | if Panel.DockClients[I].Visible then Inc(VisibleDockClientCount);
|
---|
374 |
|
---|
375 | if ((Action = dpaClose) and (VisibleDockClientCount = 0)) or
|
---|
376 | ((Action = dpaUndock) and (VisibleDockClientCount = 1)) then
|
---|
377 | begin
|
---|
378 | if Panel = PanelLeft then begin
|
---|
379 | PanelLeft.Tag := PanelLeft.Width;
|
---|
380 | PanelLeft.Width := DockPanelWidth;
|
---|
381 | SplitterLeft.Visible := False;
|
---|
382 | end else
|
---|
383 | if Panel = PanelRight then begin
|
---|
384 | PanelRight.Tag := PanelRight.Width;
|
---|
385 | PanelRight.Width := DockPanelWidth;
|
---|
386 | SplitterRight.Visible := False;
|
---|
387 | end;
|
---|
388 | if Panel = PanelTop then begin
|
---|
389 | PanelTop.Tag := PanelTop.Height;
|
---|
390 | PanelTop.Height := DockPanelWidth;
|
---|
391 | SplitterTop.Visible := False;
|
---|
392 | end;
|
---|
393 | if Panel = PanelBottom then begin
|
---|
394 | PanelBottom.Tag := PanelBottom.Height;
|
---|
395 | PanelBottom.Height := DockPanelWidth;
|
---|
396 | SplitterBottom.Visible := False;
|
---|
397 | end;
|
---|
398 | end else
|
---|
399 | if Assigned(Source) then begin
|
---|
400 | if Panel = PanelLeft then begin
|
---|
401 | if PanelLeft.Width <= DockPanelWidth then
|
---|
402 | PanelLeft.Width := PanelLeft.Tag;
|
---|
403 | SplitterLeft.Visible := True;
|
---|
404 | SplitterLeft.Left := 0;
|
---|
405 | PanelLeft.Left := 0;
|
---|
406 | DockTabSetLeft.Left := 0;
|
---|
407 | end else
|
---|
408 | if Panel = PanelRight then begin
|
---|
409 | if PanelRight.Width <= DockPanelWidth then begin
|
---|
410 | PanelRight.Width := PanelRight.Tag;
|
---|
411 | PanelRight.Left := Width - PanelRight.Width;
|
---|
412 | end;
|
---|
413 | SplitterRight.Visible := True;
|
---|
414 | SplitterRight.Left := Width;
|
---|
415 | PanelRight.Left := Width;
|
---|
416 | DockTabSetRight.Left := Width;
|
---|
417 | end else
|
---|
418 | if Panel = PanelTop then begin
|
---|
419 | if PanelTop.Height <= DockPanelWidth then
|
---|
420 | PanelTop.Height := PanelTop.Tag;
|
---|
421 | SplitterTop.Visible := True;
|
---|
422 | SplitterTop.Top := 0;
|
---|
423 | PanelTop.Top := 0;
|
---|
424 | DockTabSetTop.Top := 0;
|
---|
425 | end;
|
---|
426 | if Panel = PanelBottom then begin
|
---|
427 | if PanelBottom.Height <= DockPanelWidth then
|
---|
428 | PanelBottom.Height := PanelBottom.Tag;
|
---|
429 | SplitterBottom.Visible := True;
|
---|
430 | SplitterBottom.Top := Height;
|
---|
431 | PanelBottom.Top := Height;
|
---|
432 | DockTabSetBottom.Top := Height;
|
---|
433 | end;
|
---|
434 | end;
|
---|
435 | end;
|
---|
436 |
|
---|
437 | procedure TDDockForm.DoClose(var Action: TCloseAction);
|
---|
438 | begin
|
---|
439 | inherited;
|
---|
440 | if Parent is TDDockPanel then
|
---|
441 | with TDDockPanel(Parent) do
|
---|
442 | if Parent is TDBaseDockPanel then
|
---|
443 | with TDBaseDockPanel(Parent) do
|
---|
444 | DockPanelCloseForm(Self, TDDockPanel(Self.Parent), dpaClose);
|
---|
445 | end;
|
---|
446 |
|
---|
447 | procedure TDDockForm.DoShow;
|
---|
448 | begin
|
---|
449 | inherited;
|
---|
450 | if Parent is TDDockPanel then
|
---|
451 | with TDDockPanel(Parent) do
|
---|
452 | if Parent is TDBaseDockPanel then
|
---|
453 | with TDBaseDockPanel(Parent) do
|
---|
454 | DockPanelCloseForm(Self, TDDockPanel(Self.Parent), dpaShow);
|
---|
455 | end;
|
---|
456 |
|
---|
457 | procedure TDDockPanel.DockDrop(Source: TDragDockObject; X, Y: Integer);
|
---|
458 | begin
|
---|
459 | inherited;
|
---|
460 | if Parent is TDBaseDockPanel then
|
---|
461 | with TDBaseDockPanel(Parent) do
|
---|
462 | DockPanelCloseForm(nil, Self, dpaDock);
|
---|
463 | end;
|
---|
464 |
|
---|
465 | procedure TDDockPanel.DoDockOver(Source: TDragDockObject; X, Y: Integer;
|
---|
466 | State: TDragState; var Accept: Boolean);
|
---|
467 | const
|
---|
468 | Border = 0.1;
|
---|
469 | FrameWidth = 30;
|
---|
470 | var
|
---|
471 | DockRectangle: TRect;
|
---|
472 | CenterRectagle: TRect;
|
---|
473 | begin
|
---|
474 | inherited;
|
---|
475 | Accept := Source.Control is TDDockForm;
|
---|
476 | if Accept then
|
---|
477 | begin
|
---|
478 | CenterRectagle := Rect(Round(Width * Border), Round(Height * Border),
|
---|
479 | Width - Round(Width * Border), Height - Round(Height * Border));
|
---|
480 |
|
---|
481 | if (Height > 0) and (Width > 0) then begin
|
---|
482 | if (X > CenterRectagle.Left) and (Y > CenterRectagle.Top) and
|
---|
483 | (X < CenterRectagle.Right) and (Y < CenterRectagle.Bottom) then begin
|
---|
484 | DockRectangle.TopLeft := ClientToScreen(CenterRectagle.TopLeft);
|
---|
485 | DockRectangle.BottomRight := ClientToScreen(CenterRectagle.BottomRight);
|
---|
486 | end else
|
---|
487 | if (X < CenterRectagle.Left) and (Round(Y * (Width / Height)) > X) and
|
---|
488 | (Round(Y * (Width / Height)) < (Width - X)) then begin
|
---|
489 | DockRectangle.TopLeft := ClientToScreen(Point(0, 0));
|
---|
490 | DockRectangle.BottomRight := ClientToScreen(Point(Width div 2, Height));
|
---|
491 | end else
|
---|
492 | if (Y < CenterRectagle.Top) and (Round(X * (Height / Width)) > Y) and
|
---|
493 | (Round(X * (Height / Width)) < (Height - Y)) then begin
|
---|
494 | DockRectangle.TopLeft := ClientToScreen(Point(0, 0));
|
---|
495 | DockRectangle.BottomRight := ClientToScreen(Point(Width, Height div 2));
|
---|
496 | end else
|
---|
497 | if (X > CenterRectagle.Right) and (Round(Y * (Width / Height)) > (Width - X)) and
|
---|
498 | (Round(Y * (Width / Height)) < X) then begin
|
---|
499 | DockRectangle.TopLeft := ClientToScreen(Point(Width div 2, 0));
|
---|
500 | DockRectangle.BottomRight := ClientToScreen(Point(Width, Height));
|
---|
501 | end else
|
---|
502 | if (Y > CenterRectagle.Bottom) and (Round(X * (Height / Width)) > (Height - Y)) and
|
---|
503 | (Round(X * (Height / Width)) < Y) then begin
|
---|
504 | DockRectangle.TopLeft := ClientToScreen(Point(0, Height div 2));
|
---|
505 | DockRectangle.BottomRight := ClientToScreen(Point(Width, Height));
|
---|
506 | end else
|
---|
507 | Accept := False;
|
---|
508 | end;
|
---|
509 |
|
---|
510 | case Align of
|
---|
511 | alLeft: if Width < FrameWidth then begin
|
---|
512 | DockRectangle.TopLeft := ClientToScreen(Point(0, 0));
|
---|
513 | DockRectangle.BottomRight := ClientToScreen(Point(FrameWidth, Height));
|
---|
514 | end;
|
---|
515 | alTop: if Height < FrameWidth then begin
|
---|
516 | DockRectangle.TopLeft := ClientToScreen(Point(0, 0));
|
---|
517 | DockRectangle.BottomRight := ClientToScreen(Point(Width, FrameWidth));
|
---|
518 | end;
|
---|
519 | alRight: if Width < FrameWidth then begin
|
---|
520 | DockRectangle.TopLeft := ClientToScreen(Point(-FrameWidth, 0));
|
---|
521 | DockRectangle.BottomRight := ClientToScreen(Point(Width, Height));
|
---|
522 | end;
|
---|
523 | alBottom: if Height < FrameWidth then begin
|
---|
524 | DockRectangle.TopLeft := ClientToScreen(Point(0, -FrameWidth));
|
---|
525 | DockRectangle.BottomRight := ClientToScreen(Point(Width, Height));
|
---|
526 | end;
|
---|
527 | end;
|
---|
528 | Source.DockRect := DockRectangle;
|
---|
529 | end;
|
---|
530 | end;
|
---|
531 |
|
---|
532 | function TDDockPanel.DoUnDock(NewTarget: TWinControl;
|
---|
533 | Client: TControl): Boolean;
|
---|
534 | begin
|
---|
535 | Result := inherited DoUnDock(NewTarget, Client);
|
---|
536 | if Parent is TDBaseDockPanel then
|
---|
537 | with TDBaseDockPanel(Parent) do
|
---|
538 | DockPanelCloseForm(nil, Self, dpaUnDock);
|
---|
539 | end;
|
---|
540 |
|
---|
541 | { TDDockTabSet }
|
---|
542 |
|
---|
543 | constructor TDDockTabSet.Create(AOwner: TComponent);
|
---|
544 | begin
|
---|
545 | inherited;
|
---|
546 | OnTabRemoved := TabRemoved;
|
---|
547 | end;
|
---|
548 |
|
---|
549 | procedure TDDockTabSet.DockDrop(Source: TDragDockObject; X, Y: Integer);
|
---|
550 | begin
|
---|
551 | inherited;
|
---|
552 | Visible := True;
|
---|
553 | end;
|
---|
554 |
|
---|
555 | procedure TDDockTabSet.TabRemoved(Sender: TObject);
|
---|
556 | begin
|
---|
557 | inherited;
|
---|
558 | Visible := Tabs.Count > 0;
|
---|
559 | end;
|
---|
560 |
|
---|
561 | { TDBaseDockPanel }
|
---|
562 |
|
---|
563 | constructor TDBaseDockPanel.Create(AOwner: TComponent);
|
---|
564 | begin
|
---|
565 | inherited;
|
---|
566 |
|
---|
567 | PanelCenter := TDDockPanel.Create(Owner);
|
---|
568 | with PanelCenter do begin
|
---|
569 | Align := alClient;
|
---|
570 | AutoSize := True;
|
---|
571 | DockSite := True;
|
---|
572 | Parent := Self;
|
---|
573 | Name := 'PanelCenter';
|
---|
574 | Caption := '';
|
---|
575 | end;
|
---|
576 |
|
---|
577 | PanelLeft := TDDockPanel.Create(Owner);
|
---|
578 | with PanelLeft do begin
|
---|
579 | DockSite := True;
|
---|
580 | Align := alLeft;
|
---|
581 | Parent := Self;
|
---|
582 | Name := 'PanelLeft';
|
---|
583 | Caption := '';
|
---|
584 | Width := 0;
|
---|
585 | end;
|
---|
586 | DockTabSetLeft := TDDockTabSet.Create(Owner);
|
---|
587 | with DockTabSetLeft do begin
|
---|
588 | Align := alLeft;
|
---|
589 | Style := tsModernTabs;
|
---|
590 | TabPosition := tpLeft;
|
---|
591 | DestinationDockSite := PanelLeft;
|
---|
592 | Visible := False;
|
---|
593 | DockSite := False;
|
---|
594 | ShrinkToFit := True;
|
---|
595 | Parent := Self;
|
---|
596 | Name := 'DockTabSetLeft';
|
---|
597 | Caption := '';
|
---|
598 | Width := 24;
|
---|
599 | end;
|
---|
600 | PanelLeft.Left := DockTabSetLeft.Width;
|
---|
601 | SplitterLeft := TSplitter.Create(Owner);
|
---|
602 | with SplitterLeft do begin
|
---|
603 | Align := alLeft;
|
---|
604 | Parent := Self;
|
---|
605 | Name := 'SplitterLeft';
|
---|
606 | Visible := False;
|
---|
607 | end;
|
---|
608 |
|
---|
609 | PanelRight := TDDockPanel.Create(Owner);
|
---|
610 | with PanelRight do begin
|
---|
611 | DockSite := True;
|
---|
612 | Align := alRight;
|
---|
613 | Parent := Self;
|
---|
614 | Name := 'PanelRight';
|
---|
615 | Caption := '';
|
---|
616 | Width := 0;
|
---|
617 | end;
|
---|
618 | DockTabSetRight := TDDockTabSet.Create(Owner);
|
---|
619 | with DockTabSetRight do begin
|
---|
620 | Align := alRight;
|
---|
621 | Style := tsModernTabs;
|
---|
622 | TabPosition := tpRight;
|
---|
623 | DestinationDockSite := PanelRight;
|
---|
624 | Visible := False;
|
---|
625 | DockSite := False;
|
---|
626 | ShrinkToFit := True;
|
---|
627 | Parent := Self;
|
---|
628 | Name := 'DockTabSetRight';
|
---|
629 | Caption := '';
|
---|
630 | Width := 24;
|
---|
631 | end;
|
---|
632 | SplitterRight := TSplitter.Create(Owner);
|
---|
633 | with SplitterRight do begin
|
---|
634 | Align := alRight;
|
---|
635 | Parent := Self;
|
---|
636 | Visible := False;
|
---|
637 | Name := 'SplitterRight';
|
---|
638 | end;
|
---|
639 |
|
---|
640 | PanelTop := TDDockPanel.Create(Owner);
|
---|
641 | with PanelTop do begin
|
---|
642 | DockSite := True;
|
---|
643 | Align := alTop;
|
---|
644 | Parent := Self;
|
---|
645 | Name := 'PanelTop';
|
---|
646 | Caption := '';
|
---|
647 | Height := 0;
|
---|
648 | end;
|
---|
649 | DockTabSetTop := TDDockTabSet.Create(Owner);
|
---|
650 | with DockTabSetTop do begin
|
---|
651 | Align := alTop;
|
---|
652 | Style := tsModernTabs;
|
---|
653 | TabPosition := tpTop;
|
---|
654 | DestinationDockSite := PanelTop;
|
---|
655 | Visible := False;
|
---|
656 | DockSite := False;
|
---|
657 | ShrinkToFit := True;
|
---|
658 | Parent := Self;
|
---|
659 | Name := 'DockTabSetTop';
|
---|
660 | Caption := '';
|
---|
661 | Height := 24;
|
---|
662 | end;
|
---|
663 | PanelTop.Top := DockTabSetTop.Height;
|
---|
664 | SplitterTop := TSplitter.Create(Owner);
|
---|
665 | with SplitterTop do begin
|
---|
666 | Align := alTop;
|
---|
667 | Parent := Self;
|
---|
668 | Name := 'SplitterTop';
|
---|
669 | Visible := False;
|
---|
670 | end;
|
---|
671 |
|
---|
672 | PanelBottom := TDDockPanel.Create(Owner);
|
---|
673 | with PanelBottom do begin
|
---|
674 | DockSite := True;
|
---|
675 | Parent := Self;
|
---|
676 | Name := 'PanelBottom';
|
---|
677 | Caption := '';
|
---|
678 | Height := 0;
|
---|
679 | Align := alBottom;
|
---|
680 | end;
|
---|
681 | DockTabSetBottom := TDDockTabSet.Create(Owner);
|
---|
682 | with DockTabSetBottom do begin
|
---|
683 | Style := tsModernTabs;
|
---|
684 | TabPosition := tpBottom;
|
---|
685 | DestinationDockSite := PanelBottom;
|
---|
686 | Visible := False;
|
---|
687 | DockSite := False;
|
---|
688 | ShrinkToFit := True;
|
---|
689 | Parent := Self;
|
---|
690 | Name := 'DockTabSetBottom';
|
---|
691 | Caption := '';
|
---|
692 | Align := alBottom;
|
---|
693 | Height := 24;
|
---|
694 | end;
|
---|
695 | SplitterBottom := TSplitter.Create(Owner);
|
---|
696 | with SplitterBottom do begin
|
---|
697 | Name := 'SplitterBottom';
|
---|
698 | Parent := Self;
|
---|
699 | Visible := False;
|
---|
700 | Align := alBottom;
|
---|
701 | end;
|
---|
702 | end;
|
---|
703 |
|
---|
704 | end.
|
---|