1 | unit UCDManager;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UCDCommon, Controls, Contnrs, Dialogs,
|
---|
9 | UCDPopupMenu, LCLType, LCLIntf, LMessages, Graphics, Buttons,
|
---|
10 | UCDConjoinForm, Menus, ExtCtrls, Forms;
|
---|
11 |
|
---|
12 | const
|
---|
13 | GrabberSize = 22;
|
---|
14 |
|
---|
15 | type
|
---|
16 | TCDManager = class;
|
---|
17 | TCDManagerItem = class;
|
---|
18 |
|
---|
19 | TCDPanelForm = class(TForm)
|
---|
20 | Panel: TPanel;
|
---|
21 | end;
|
---|
22 |
|
---|
23 | { TCDHeaderButton }
|
---|
24 |
|
---|
25 | TCDHeaderButton = class
|
---|
26 | Icon: TImage;
|
---|
27 | Visible: Boolean;
|
---|
28 | constructor Create;
|
---|
29 | destructor Destroy; override;
|
---|
30 | end;
|
---|
31 |
|
---|
32 | { TCDHeader }
|
---|
33 |
|
---|
34 | TCDHeader = class(TPanel)
|
---|
35 | private
|
---|
36 | MyFont: hFont;
|
---|
37 | procedure CloseButtonClick(Sender: TObject);
|
---|
38 | procedure PaintExecute(Sender: TObject);
|
---|
39 | procedure RearrangeButtons;
|
---|
40 | public
|
---|
41 | Buttons: TObjectList; // TList<TCDHeaderButton>
|
---|
42 | Icon: TImage;
|
---|
43 | Control: TControl;
|
---|
44 | constructor Create(TheOwner: TComponent); override;
|
---|
45 | destructor Destroy; override;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | { TCDPanelHeader }
|
---|
49 |
|
---|
50 | TCDPanelHeader = class(TPanel)
|
---|
51 | private
|
---|
52 | FHeaderPos: THeaderPos;
|
---|
53 | function GetHeaderVisible: Boolean;
|
---|
54 | procedure SetHeaderPos(const AValue: THeaderPos);
|
---|
55 | procedure SetHeaderVisible(const AValue: Boolean);
|
---|
56 | public
|
---|
57 | Header: TCDHeader;
|
---|
58 | ControlPanel: TPanel;
|
---|
59 | DockItem: TCDManagerItem;
|
---|
60 | property HeaderPos: THeaderPos read FHeaderPos write SetHeaderPos;
|
---|
61 | property HeaderVisible: Boolean read GetHeaderVisible write SetHeaderVisible;
|
---|
62 | constructor Create(TheOwner: TComponent); override;
|
---|
63 | destructor Destroy; override;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | { TCDManagerItem }
|
---|
67 |
|
---|
68 | TCDManagerItem = class
|
---|
69 | private
|
---|
70 | FControl: TWinControl;
|
---|
71 | procedure ResizeExecute(Sender: TObject);
|
---|
72 | public
|
---|
73 | Manager: TCDManager;
|
---|
74 | procedure SetControl(const AValue: TWinControl); virtual;
|
---|
75 | procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
76 | Shift: TShiftState; X, Y: Integer);
|
---|
77 | procedure Paint(Sender: TObject); virtual;
|
---|
78 | procedure VisibleChange(Sender: TObject); virtual;
|
---|
79 | procedure VisibleChanging(Sender: TObject); virtual;
|
---|
80 | constructor Create; virtual;
|
---|
81 | destructor Destroy; override;
|
---|
82 | property Control: TWinControl read FControl write SetControl;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | { TCDManager }
|
---|
86 |
|
---|
87 | TCDManager = class(TCDManagerBase)
|
---|
88 | protected
|
---|
89 | FUpdateCount: Integer;
|
---|
90 | FDockStyle: TCDStyleType;
|
---|
91 | procedure SetHeaderPos(const AValue: THeaderPos); virtual;
|
---|
92 | private
|
---|
93 | FDockSite: TWinControl;
|
---|
94 | FDockSiteVisible: Boolean;
|
---|
95 | FHeaderPos: THeaderPos;
|
---|
96 | FHeaderVisible: Boolean;
|
---|
97 | FOnDockSiteHide: TNotifyEvent;
|
---|
98 | FOnDockSiteShow: TNotifyEvent;
|
---|
99 | function GetDockSite: TWinControl;
|
---|
100 | function GetMoveDuration: Integer;
|
---|
101 | procedure SetDockSiteVisible(AValue: Boolean); virtual;
|
---|
102 | procedure SetDockStyle(const AValue: TCDStyleType);
|
---|
103 | procedure SetHeaderVisible(const AValue: Boolean);
|
---|
104 | procedure SetMoveDuration(const AValue: Integer);
|
---|
105 | procedure CloseHandler(Sender: TObject; var CloseAction: TCloseAction);
|
---|
106 | protected
|
---|
107 | procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;
|
---|
108 | DropCtl: TControl); virtual;
|
---|
109 | function GetHeaderPos: THeaderPos; virtual;
|
---|
110 | function FindControlInPanels(Control: TControl): TCDManagerItem; virtual;
|
---|
111 | public
|
---|
112 | Locked: Boolean;
|
---|
113 | PopupMenu: TCDPopupMenu;
|
---|
114 | FreeParentIfEmpty: Boolean; // Free or not parent conjoin forms
|
---|
115 | procedure SetVisible(const AValue: Boolean); virtual;
|
---|
116 | constructor Create(ADockSite: TWinControl); override;
|
---|
117 | destructor Destroy; override;
|
---|
118 | procedure Update; virtual;
|
---|
119 | procedure Switch(Index: Integer); virtual;
|
---|
120 | procedure ChangeVisible(Control: TWinControl; Visible: Boolean); virtual;
|
---|
121 | procedure Assign(Source: TPersistent); override;
|
---|
122 | procedure BringToFront; virtual;
|
---|
123 |
|
---|
124 | // Inherited from TDockManager
|
---|
125 | procedure BeginUpdate; override;
|
---|
126 | procedure EndUpdate; override;
|
---|
127 | procedure GetControlBounds(Control: TControl;
|
---|
128 | out AControlBounds: TRect); override;
|
---|
129 | function GetDockEdge(ADockObject: TDragDockObject): boolean; override;
|
---|
130 | procedure InsertControl(ADockObject: TDragDockObject); override; overload;
|
---|
131 | procedure InsertControl(Control: TControl; InsertAt: TAlign;
|
---|
132 | DropCtl: TControl); override; overload;
|
---|
133 | procedure LoadFromStream(Stream: TStream); override;
|
---|
134 | procedure PaintSite(DC: HDC); override;
|
---|
135 | procedure MessageHandler(Sender: TControl; var Message: TLMessage); override;
|
---|
136 | procedure PositionDockRect(ADockObject: TDragDockObject); override; overload;
|
---|
137 | procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign;
|
---|
138 | var DockRect: TRect); override; overload;
|
---|
139 | procedure RemoveControl(Control: TControl); override;
|
---|
140 | procedure ResetBounds(Force: Boolean); override;
|
---|
141 | procedure SaveToStream(Stream: TStream); override;
|
---|
142 | procedure SetReplacingControl(Control: TControl); override;
|
---|
143 | function AutoFreeByControl: Boolean; override;
|
---|
144 |
|
---|
145 | function CreateConjoinForm: TCDConjoinForm;
|
---|
146 | function CreateDockableForm: TCDPanelForm;
|
---|
147 | property DockStyle: TCDStyleType read FDockStyle write SetDockStyle;
|
---|
148 | property MoveDuration: Integer read GetMoveDuration write SetMoveDuration;
|
---|
149 | property DockSite: TWinControl read GetDockSite;
|
---|
150 | property HeaderPos: THeaderPos read GetHeaderPos write SetHeaderPos;
|
---|
151 | property HeaderVisible: Boolean read FHeaderVisible write SetHeaderVisible;
|
---|
152 | property Visible: Boolean write SetVisible;
|
---|
153 | property DockSiteVisible: Boolean read FDockSiteVisible write SetDockSiteVisible;
|
---|
154 | property OnDockSiteHide: TNotifyEvent read FOnDockSiteHide write FOnDockSiteHide;
|
---|
155 | property OnDockSiteShow: TNotifyEvent read FOnDockSiteShow write FOnDockSiteShow;
|
---|
156 | end;
|
---|
157 |
|
---|
158 |
|
---|
159 | implementation
|
---|
160 |
|
---|
161 | uses
|
---|
162 | UCDManagerRegions, UCDManagerTabs, UCDManagerRegionsPopup, UCDManagerTabsPopup,
|
---|
163 | UCDResource, UCDClient;
|
---|
164 |
|
---|
165 | function CreateRotatedFont(F: TFont; Angle: Integer): Integer;
|
---|
166 | var
|
---|
167 | LF: TLogFont;
|
---|
168 | begin
|
---|
169 | FillChar(LF, SizeOf(LF), #0);
|
---|
170 | with LF do begin
|
---|
171 | lfHeight := F.Height;
|
---|
172 | lfWidth := 0;
|
---|
173 | lfEscapement := Angle * 10;
|
---|
174 | lfOrientation := 0;
|
---|
175 | if fsBold in F.Style then
|
---|
176 | lfWeight := FW_BOLD
|
---|
177 | else
|
---|
178 | lfWeight := FW_NORMAL;
|
---|
179 | lfItalic := Byte(fsItalic in F.Style);
|
---|
180 | lfUnderline := Byte(fsUnderline in F.Style);
|
---|
181 | lfStrikeOut := Byte(fsStrikeOut in F.Style);
|
---|
182 | lfCharSet := DEFAULT_CHARSET;
|
---|
183 | StrPCopy(lfFaceName, F.Name);
|
---|
184 | lfQuality := DEFAULT_QUALITY;
|
---|
185 | {everything else as default}
|
---|
186 | lfOutPrecision := OUT_DEFAULT_PRECIS;
|
---|
187 | lfClipPrecision := CLIP_DEFAULT_PRECIS;
|
---|
188 | case F.Pitch of
|
---|
189 | fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
|
---|
190 | fpFixed: lfPitchAndFamily := FIXED_PITCH;
|
---|
191 | else
|
---|
192 | lfPitchAndFamily := DEFAULT_PITCH;
|
---|
193 | end;
|
---|
194 | end;
|
---|
195 | Result := CreateFontIndirect(LF);
|
---|
196 | end;
|
---|
197 |
|
---|
198 | { TCDHeaderButton }
|
---|
199 |
|
---|
200 | constructor TCDHeaderButton.Create;
|
---|
201 | begin
|
---|
202 | inherited;
|
---|
203 | Icon := TImage.Create(nil);
|
---|
204 | end;
|
---|
205 |
|
---|
206 | destructor TCDHeaderButton.Destroy;
|
---|
207 | begin
|
---|
208 | Icon.Free;
|
---|
209 | inherited Destroy;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | { TCDPanelHeader }
|
---|
213 |
|
---|
214 | procedure TCDPanelHeader.SetHeaderPos(const AValue: THeaderPos);
|
---|
215 | begin
|
---|
216 | if FHeaderPos=AValue then exit;
|
---|
217 | FHeaderPos:=AValue;
|
---|
218 |
|
---|
219 | //Paint(Self);
|
---|
220 | end;
|
---|
221 |
|
---|
222 | function TCDPanelHeader.GetHeaderVisible: Boolean;
|
---|
223 | begin
|
---|
224 | Result := Header.Visible;
|
---|
225 | end;
|
---|
226 |
|
---|
227 | procedure TCDPanelHeader.SetHeaderVisible(const AValue: Boolean);
|
---|
228 | begin
|
---|
229 | Header.Visible := AValue;
|
---|
230 | end;
|
---|
231 |
|
---|
232 | constructor TCDPanelHeader.Create(TheOwner: TComponent);
|
---|
233 | begin
|
---|
234 | inherited;
|
---|
235 | //Paint.OnPaint := Paint;
|
---|
236 | // Header.Shape.OnMouseDown := DockPanelMouseDown;
|
---|
237 | // Header.Title.OnMouseDown := DockPanelMouseDown;
|
---|
238 | HeaderPos := hpTop;
|
---|
239 | Constraints.MinHeight := GrabberSize;
|
---|
240 | Align := alClient;
|
---|
241 |
|
---|
242 | ControlPanel := TPanel.Create(Self);
|
---|
243 | with ControlPanel do begin
|
---|
244 | Parent := Self;
|
---|
245 | Visible := True;
|
---|
246 | DockSite := True;
|
---|
247 | UseDockManager := True;
|
---|
248 | Align := alClient;
|
---|
249 | BevelInner := bvNone;
|
---|
250 | BevelOuter := bvNone;
|
---|
251 | //Color := clGreen;
|
---|
252 | end;
|
---|
253 | Header := TCDHeader.Create(Self);
|
---|
254 | with Header do begin
|
---|
255 | Parent := Self;
|
---|
256 | Visible := True;
|
---|
257 | Align := alTop;
|
---|
258 | Height := GrabberSize;
|
---|
259 | //ManagerItem := Self;
|
---|
260 | end;
|
---|
261 | //OnResize := ResizeExecute;
|
---|
262 | BevelInner := bvNone;
|
---|
263 | BevelOuter := bvNone;
|
---|
264 | HeaderVisible := True;
|
---|
265 | end;
|
---|
266 |
|
---|
267 | destructor TCDPanelHeader.Destroy;
|
---|
268 | begin
|
---|
269 | inherited Destroy;
|
---|
270 | end;
|
---|
271 |
|
---|
272 | { TCDManagerItem }
|
---|
273 |
|
---|
274 | procedure TCDManagerItem.Paint(Sender: TObject);
|
---|
275 | begin
|
---|
276 | end;
|
---|
277 |
|
---|
278 | constructor TCDManagerItem.Create;
|
---|
279 | begin
|
---|
280 |
|
---|
281 | end;
|
---|
282 |
|
---|
283 | procedure TCDManagerItem.ResizeExecute(Sender: TObject);
|
---|
284 | begin
|
---|
285 | (* if Assigned(Control) then begin
|
---|
286 | Control.Top := GrabberSize;
|
---|
287 | Control.Left := 0;
|
---|
288 | Control.Width := Width;
|
---|
289 | Control.Height := Height - GrabberSize;
|
---|
290 | //Control.SetBounds(0, GrabberSize, Width - Control.Left,
|
---|
291 | // Height - Control.Top);
|
---|
292 | end;*)
|
---|
293 | end;
|
---|
294 |
|
---|
295 | procedure TCDManagerItem.SetControl(const AValue: TWinControl);
|
---|
296 | begin
|
---|
297 | if FControl = AValue then Exit;
|
---|
298 | FControl := AValue;
|
---|
299 | end;
|
---|
300 |
|
---|
301 | procedure TCDManagerItem.DockPanelMouseDown(Sender: TObject;
|
---|
302 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
303 | begin
|
---|
304 | if Control is TForm then begin
|
---|
305 | TForm(Control).SetFocus;
|
---|
306 | Paint(Self);
|
---|
307 | end;
|
---|
308 | if (Button = mbLeft) then begin
|
---|
309 | //(Control as TWinControl).DockSite := False;
|
---|
310 | //ClientAreaPanel.DockSite := False;
|
---|
311 | if not Manager.Locked then begin
|
---|
312 | (Control as TWinControl).BeginDrag(False, 10);
|
---|
313 | DragManager.DragStart(Control, False, 1);
|
---|
314 | end;
|
---|
315 | end;
|
---|
316 | end;
|
---|
317 |
|
---|
318 | destructor TCDManagerItem.Destroy;
|
---|
319 | begin
|
---|
320 | if Assigned(Control) then
|
---|
321 | Control.RemoveHandlerOnVisibleChanged(VisibleChange);
|
---|
322 | inherited Destroy;
|
---|
323 | end;
|
---|
324 |
|
---|
325 | procedure TCDManagerItem.VisibleChange(Sender: TObject);
|
---|
326 | begin
|
---|
327 | end;
|
---|
328 |
|
---|
329 | procedure TCDManagerItem.VisibleChanging(Sender: TObject);
|
---|
330 | begin
|
---|
331 |
|
---|
332 | end;
|
---|
333 |
|
---|
334 | { TCDManager }
|
---|
335 |
|
---|
336 | function TCDManager.FindControlInPanels(Control: TControl
|
---|
337 | ): TCDManagerItem;
|
---|
338 | begin
|
---|
339 | Result := nil;
|
---|
340 | end;
|
---|
341 |
|
---|
342 | function TCDManager.GetDockSite: TWinControl;
|
---|
343 | begin
|
---|
344 | Result := FDockSite;
|
---|
345 | end;
|
---|
346 |
|
---|
347 | function TCDManager.GetHeaderPos: THeaderPos;
|
---|
348 | begin
|
---|
349 | Result := FHeaderPos;
|
---|
350 | end;
|
---|
351 |
|
---|
352 | procedure TCDManager.BringToFront;
|
---|
353 | begin
|
---|
354 | //DockSiteVisible := True;
|
---|
355 | DockSite.Show;
|
---|
356 | DockSite.BringToFront;
|
---|
357 | if Assigned(DockSite.Parent) then begin
|
---|
358 | if Assigned(DockSite.Parent.DockManager)
|
---|
359 | and (DockSite.Parent.DockManager is TCDManager) then
|
---|
360 | TCDManager(DockSite.Parent.DockManager).BringToFront
|
---|
361 | else DockSite.Parent.BringToFront;
|
---|
362 | end;
|
---|
363 | end;
|
---|
364 |
|
---|
365 | function TCDManager.GetMoveDuration: Integer;
|
---|
366 | begin
|
---|
367 | Result := 0;
|
---|
368 | end;
|
---|
369 |
|
---|
370 | procedure TCDManager.SetDockSiteVisible(AValue: Boolean);
|
---|
371 | begin
|
---|
372 | if FDockSiteVisible = AValue then Exit;
|
---|
373 | FDockSiteVisible := AValue;
|
---|
374 | SetVisible(FDockSiteVisible);
|
---|
375 | if Assigned(FOnDockSiteHide) and (not FDockSiteVisible) then
|
---|
376 | FOnDockSiteHide(Self);
|
---|
377 | if Assigned(FOnDockSiteShow) and FDockSiteVisible then
|
---|
378 | FOnDockSiteShow(Self);
|
---|
379 | end;
|
---|
380 |
|
---|
381 | constructor TCDManager.Create(ADockSite: TWinControl);
|
---|
382 | begin
|
---|
383 | inherited Create(ADockSite);
|
---|
384 |
|
---|
385 | FDockSite := ADockSite;
|
---|
386 |
|
---|
387 | FreeParentIfEmpty := True;
|
---|
388 |
|
---|
389 | FDockStyle := dsList; // dsNone
|
---|
390 | FHeaderVisible := True;
|
---|
391 | PopupMenu := TCDPopupMenu.Create(Self);
|
---|
392 | PopupMenu.Parent := ADockSite;
|
---|
393 | if ADockSite is TForm then
|
---|
394 | TForm(ADockSite).AddHandlerClose(CloseHandler);
|
---|
395 | end;
|
---|
396 |
|
---|
397 | destructor TCDManager.Destroy;
|
---|
398 | begin
|
---|
399 | if FDockSite is TForm then
|
---|
400 | TForm(FDockSite).RemoveHandlerClose(CloseHandler);
|
---|
401 | PopupMenu.Free;
|
---|
402 | inherited Destroy;
|
---|
403 | end;
|
---|
404 |
|
---|
405 | procedure TCDManager.BeginUpdate;
|
---|
406 | begin
|
---|
407 | Inc(FUpdateCount);
|
---|
408 | end;
|
---|
409 |
|
---|
410 | procedure TCDManager.EndUpdate;
|
---|
411 | begin
|
---|
412 | if FUpdateCount > 0 then Dec(FUpdateCount);
|
---|
413 | if FUpdateCount = 0 then Update;
|
---|
414 | end;
|
---|
415 |
|
---|
416 | procedure TCDManager.GetControlBounds(Control: TControl; out
|
---|
417 | AControlBounds: TRect);
|
---|
418 | begin
|
---|
419 | end;
|
---|
420 |
|
---|
421 | function TCDManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
|
---|
422 | begin
|
---|
423 | Result := inherited GetDockEdge(ADockObject);
|
---|
424 | end;
|
---|
425 |
|
---|
426 | procedure TCDManager.InsertControl(ADockObject: TDragDockObject);
|
---|
427 | begin
|
---|
428 | inherited InsertControl(ADockObject);
|
---|
429 | end;
|
---|
430 |
|
---|
431 | procedure TCDManager.InsertControlPanel(Control: TControl; InsertAt: TAlign;
|
---|
432 | DropCtl: TControl);
|
---|
433 | begin
|
---|
434 | end;
|
---|
435 |
|
---|
436 | procedure TCDManager.InsertControl(Control: TControl; InsertAt: TAlign;
|
---|
437 | DropCtl: TControl);
|
---|
438 | var
|
---|
439 | NewSplitter: TSplitter;
|
---|
440 | NewDockPanel: TCDManagerItem;
|
---|
441 | NewPanel: TPanel;
|
---|
442 | I: Integer;
|
---|
443 | NewConjoinDockForm: TCDConjoinForm;
|
---|
444 | NewDockSite: TWinControl;
|
---|
445 | NewForm: TForm;
|
---|
446 | begin
|
---|
447 | if (FDockSite is TForm) and (not (FDockSite is TCDConjoinForm)) then begin
|
---|
448 | if (not Assigned(FDockSite.Parent)) then begin
|
---|
449 | // Create conjointed form
|
---|
450 | NewConjoinDockForm := CreateConjoinForm;
|
---|
451 | FDockSite.ManualDock(NewConjoinDockForm);
|
---|
452 | Control.ManualDock(NewConjoinDockForm, nil, InsertAt);
|
---|
453 | NewConjoinDockForm.UpdateCaption;
|
---|
454 | end else begin
|
---|
455 | NewConjoinDockForm := CreateConjoinForm;
|
---|
456 | NewDockSite := FDockSite.HostDockSite;
|
---|
457 | // FDockSite.ManualFloat(FDockSite.BoundsRect);
|
---|
458 | NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);
|
---|
459 | FDockSite.ManualDock(NewConjoinDockForm);
|
---|
460 | Control.ManualDock(NewConjoinDockForm, nil, InsertAt);
|
---|
461 | NewConjoinDockForm.UpdateCaption;
|
---|
462 | end;
|
---|
463 | end else
|
---|
464 | if (FDockSite is TCDConjoinForm) or (FDockSite is TPanel) then begin
|
---|
465 | InsertControlPanel(Control, InsertAt, DropCtl);
|
---|
466 | end;
|
---|
467 | if FDockSite is TCDConjoinForm then
|
---|
468 | TCDConjoinForm(FDockSite).UpdateCaption;
|
---|
469 |
|
---|
470 | // FDockPanel.Invalidate;
|
---|
471 | //inherited;
|
---|
472 | end;
|
---|
473 |
|
---|
474 | procedure TCDManager.LoadFromStream(Stream: TStream);
|
---|
475 | begin
|
---|
476 | end;
|
---|
477 |
|
---|
478 | procedure TCDManager.PaintSite(DC: HDC);
|
---|
479 | begin
|
---|
480 | end;
|
---|
481 |
|
---|
482 | procedure TCDManager.MessageHandler(Sender: TControl;
|
---|
483 | var Message: TLMessage);
|
---|
484 | begin
|
---|
485 | inherited MessageHandler(Sender, Message);
|
---|
486 | end;
|
---|
487 |
|
---|
488 | procedure TCDManager.PositionDockRect(ADockObject: TDragDockObject);
|
---|
489 | begin
|
---|
490 | inherited PositionDockRect(ADockObject);
|
---|
491 | end;
|
---|
492 |
|
---|
493 | procedure TCDManager.PositionDockRect(Client, DropCtl: TControl;
|
---|
494 | DropAlign: TAlign; var DockRect: TRect);
|
---|
495 | begin
|
---|
496 | case DropAlign of
|
---|
497 | alNone: begin
|
---|
498 | DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);
|
---|
499 | end;
|
---|
500 | alRight: begin
|
---|
501 | DockRect := Rect(FDockSite.ClientWidth div 2, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);
|
---|
502 | end;
|
---|
503 | alLeft: begin
|
---|
504 | DockRect := Rect(0, 0, FDockSite.ClientWidth div 2, FDockSite.ClientHeight);
|
---|
505 | end;
|
---|
506 | alTop: begin
|
---|
507 | DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight div 2);
|
---|
508 | end;
|
---|
509 | alBottom: begin
|
---|
510 | DockRect := Rect(0, FDockSite.ClientHeight div 2, FDockSite.ClientWidth, FDockSite.ClientHeight);
|
---|
511 | end;
|
---|
512 | end;
|
---|
513 | DockRect.TopLeft := FDockSite.ClientToScreen(DockRect.TopLeft);
|
---|
514 | DockRect.BottomRight := FDockSite.ClientToScreen(DockRect.BottomRight);
|
---|
515 | end;
|
---|
516 |
|
---|
517 | procedure TCDManager.RemoveControl(Control: TControl);
|
---|
518 | begin
|
---|
519 | if FDockSite is TCDConjoinForm then
|
---|
520 | TCDConjoinForm(FDockSite).UpdateCaption;
|
---|
521 | end;
|
---|
522 |
|
---|
523 | procedure TCDManager.ResetBounds(Force: Boolean);
|
---|
524 | begin
|
---|
525 | end;
|
---|
526 |
|
---|
527 | procedure TCDManager.SaveToStream(Stream: TStream);
|
---|
528 | begin
|
---|
529 | end;
|
---|
530 |
|
---|
531 | procedure TCDManager.SetReplacingControl(Control: TControl);
|
---|
532 | begin
|
---|
533 | inherited SetReplacingControl(Control);
|
---|
534 | end;
|
---|
535 |
|
---|
536 | function TCDManager.AutoFreeByControl: Boolean;
|
---|
537 | begin
|
---|
538 | Result := inherited AutoFreeByControl;
|
---|
539 | end;
|
---|
540 |
|
---|
541 | function TCDManager.CreateConjoinForm: TCDConjoinForm;
|
---|
542 | var
|
---|
543 | NewDockSite: TWinControl;
|
---|
544 | NewConjoinDockForm: TCDConjoinForm;
|
---|
545 | begin
|
---|
546 | NewConjoinDockForm := TCDConjoinForm.Create(Application);
|
---|
547 | NewConjoinDockForm.Name := GetUniqueName('ConjoinForm');
|
---|
548 | NewConjoinDockForm.Visible := False;
|
---|
549 | NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;
|
---|
550 | NewConjoinDockForm.CoolDockClient.Master := Self.Master;
|
---|
551 | NewDockSite := FDockSite.HostDockSite;
|
---|
552 | // FDockSite.ManualFloat(FDockSite.BoundsRect);
|
---|
553 | //NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);
|
---|
554 | Result := NewConjoinDockForm;
|
---|
555 | end;
|
---|
556 |
|
---|
557 | function TCDManager.CreateDockableForm: TCDPanelForm;
|
---|
558 | var
|
---|
559 | NewClient: TCDClient;
|
---|
560 | begin
|
---|
561 | Application.CreateForm(TCDPanelForm, Result);
|
---|
562 | Result.Name := GetUniqueName('DockForm');
|
---|
563 | NewClient := TCDClient.Create(Result);
|
---|
564 | Result.Panel := TPanel.Create(Result);
|
---|
565 | Result.Panel.Parent := Result;
|
---|
566 | //Result.Panel.Visible := True;
|
---|
567 | Result.Panel.BevelInner := bvNone;
|
---|
568 | Result.Panel.BevelOuter := bvNone;
|
---|
569 | NewClient.Panel := Result.Panel;
|
---|
570 | NewClient.Master := Self.Master;
|
---|
571 | NewClient.Dockable := False;
|
---|
572 | end;
|
---|
573 |
|
---|
574 | procedure TCDManager.SetDockStyle(const AValue: TCDStyleType);
|
---|
575 | var
|
---|
576 | NewManager: TCDManager;
|
---|
577 | begin
|
---|
578 | if FDockStyle <> AValue then begin
|
---|
579 | FDockStyle := AValue;
|
---|
580 | if AValue = dsTabs then begin
|
---|
581 | NewManager := TCDManagerTabs.Create(FDockSite);
|
---|
582 | end else
|
---|
583 | if AValue = dsList then begin
|
---|
584 | NewManager := TCDManagerRegions.Create(FDockSite);
|
---|
585 | end else
|
---|
586 | if AValue = dsPopupList then begin
|
---|
587 | NewManager := TCDManagerPopupRegions.Create(FDockSite);
|
---|
588 | end else
|
---|
589 | if AValue = dsPopupTabs then begin
|
---|
590 | NewManager := TCDManagerTabsPopup.Create(FDockSite);
|
---|
591 | end;
|
---|
592 | if DockSite.DockManager is TCDManager then
|
---|
593 | NewManager.Assign(TCDManager(DockSite.DockManager));
|
---|
594 | DockSite.DockManager := NewManager;
|
---|
595 | NewManager.Update;
|
---|
596 | end;
|
---|
597 | end;
|
---|
598 |
|
---|
599 | procedure TCDManager.SetHeaderVisible(const AValue: Boolean);
|
---|
600 | begin
|
---|
601 | if FHeaderVisible = AValue then Exit;
|
---|
602 | FHeaderVisible := AValue;
|
---|
603 | if Assigned(DockSite.HostDockSite) then
|
---|
604 | TCDManager(DockSite.HostDockSite.DockManager).Update;
|
---|
605 | end;
|
---|
606 |
|
---|
607 | procedure TCDManager.SetHeaderPos(const AValue: THeaderPos);
|
---|
608 | begin
|
---|
609 | FHeaderPos := AValue;
|
---|
610 | end;
|
---|
611 |
|
---|
612 | procedure TCDManager.SetMoveDuration(const AValue: Integer);
|
---|
613 | begin
|
---|
614 | end;
|
---|
615 |
|
---|
616 | procedure TCDManager.CloseHandler(Sender: TObject; var CloseAction: TCloseAction
|
---|
617 | );
|
---|
618 | begin
|
---|
619 | //DockSite.Visible := False;
|
---|
620 | //SetVisible(FDockSite.Visible);
|
---|
621 | end;
|
---|
622 |
|
---|
623 | procedure TCDManager.SetVisible(const AValue: Boolean);
|
---|
624 | begin
|
---|
625 | end;
|
---|
626 |
|
---|
627 | procedure TCDManager.Update;
|
---|
628 | begin
|
---|
629 | end;
|
---|
630 |
|
---|
631 | procedure TCDManager.Switch(Index: Integer);
|
---|
632 | begin
|
---|
633 |
|
---|
634 | end;
|
---|
635 |
|
---|
636 | procedure TCDManager.ChangeVisible(Control: TWinControl; Visible: Boolean);
|
---|
637 | begin
|
---|
638 |
|
---|
639 | end;
|
---|
640 |
|
---|
641 | procedure TCDManager.Assign(Source: TPersistent);
|
---|
642 | begin
|
---|
643 | if Source is TCDManager then begin
|
---|
644 | FDockStyle := TCDManager(Source).FDockStyle;
|
---|
645 | FDockSite := TCDManager(Source).FDockSite;
|
---|
646 | end else inherited;
|
---|
647 | end;
|
---|
648 |
|
---|
649 | { TCDHeader }
|
---|
650 |
|
---|
651 | constructor TCDHeader.Create(TheOwner: TComponent);
|
---|
652 | var
|
---|
653 | NewButton: TCDHeaderButton;
|
---|
654 | begin
|
---|
655 | inherited Create(TheOwner);
|
---|
656 | OnPaint := PaintExecute;
|
---|
657 | //MyFont := CreateRotatedFont(Canvas.Font, 90);
|
---|
658 |
|
---|
659 | Buttons := TObjectList.Create;
|
---|
660 |
|
---|
661 | NewButton := TCDHeaderButton.Create;
|
---|
662 | with NewButton do begin
|
---|
663 | DataModule2.ImageList1.GetBitmap(0, Icon.Picture.Bitmap);
|
---|
664 | Icon.Parent := Self;
|
---|
665 | Icon.OnClick := CloseButtonClick;
|
---|
666 | Visible := True;
|
---|
667 | end;
|
---|
668 | Buttons.Add(NewButton);
|
---|
669 | NewButton := TCDHeaderButton.Create;
|
---|
670 | with NewButton do begin
|
---|
671 | DataModule2.ImageList1.GetBitmap(1, Icon.Picture.Bitmap);
|
---|
672 | Icon.Parent := Self;
|
---|
673 | Icon.OnClick := nil;
|
---|
674 | Visible := False;
|
---|
675 | end;
|
---|
676 | Buttons.Add(NewButton);
|
---|
677 | NewButton := TCDHeaderButton.Create;
|
---|
678 | with NewButton do begin
|
---|
679 | DataModule2.ImageList1.GetBitmap(2, Icon.Picture.Bitmap);
|
---|
680 | Icon.Parent := Self;
|
---|
681 | Icon.OnClick := nil;
|
---|
682 | Visible := False;
|
---|
683 | end;
|
---|
684 | Buttons.Add(NewButton);
|
---|
685 | RearrangeButtons;
|
---|
686 |
|
---|
687 | Icon := TImage.Create(Self);
|
---|
688 | with Icon do begin
|
---|
689 | Parent := Self;
|
---|
690 | Left := 4;
|
---|
691 | Top := 2;
|
---|
692 | Visible := True;
|
---|
693 | end;
|
---|
694 |
|
---|
695 | BevelInner := bvNone;
|
---|
696 | BevelOuter := bvNone;
|
---|
697 | end;
|
---|
698 |
|
---|
699 | destructor TCDHeader.Destroy;
|
---|
700 | begin
|
---|
701 | Buttons.Free;
|
---|
702 | inherited Destroy;
|
---|
703 | end;
|
---|
704 |
|
---|
705 | procedure TCDHeader.PaintExecute(Sender: TObject);
|
---|
706 | const
|
---|
707 | Corner: Integer = 2;
|
---|
708 | Border: Integer = 1;
|
---|
709 | BorderColor: TColor = $B9C3C6;
|
---|
710 | TopColor: TColor = $CFD6D9;
|
---|
711 | BottomColor: TColor = $DAE0E1;
|
---|
712 | var
|
---|
713 | Points: array of TPoint;
|
---|
714 | TitleLeft: Integer;
|
---|
715 | TitleMaxWidth: Integer;
|
---|
716 | I: Integer;
|
---|
717 | Title: string;
|
---|
718 | R: TRect;
|
---|
719 | begin
|
---|
720 | if Assigned(Control) and Assigned(TWinControl(Control).DockManager) then
|
---|
721 | with TCDManager(TWinControl(Control).DockManager) do
|
---|
722 | case HeaderPos of
|
---|
723 | hpLeft: begin
|
---|
724 | Align := alLeft;
|
---|
725 | Width := GrabberSize;
|
---|
726 | end;
|
---|
727 | hpTop, hpAuto: begin
|
---|
728 | Align := alTop;
|
---|
729 | Height := GrabberSize;
|
---|
730 | end;
|
---|
731 | hpRight: begin
|
---|
732 | Align := alRight;
|
---|
733 | Width := GrabberSize;
|
---|
734 | end;
|
---|
735 | hpBottom: begin
|
---|
736 | Align := alBottom;
|
---|
737 | Height := GrabberSize;
|
---|
738 | end;
|
---|
739 | end;
|
---|
740 |
|
---|
741 | if Assigned(Control) then
|
---|
742 | if (Control as TWinControl).Focused then
|
---|
743 | Canvas.Font.Style := Canvas.Font.Style + [fsBold]
|
---|
744 | else Canvas.Font.Style := Canvas.Font.Style - [fsBold];
|
---|
745 |
|
---|
746 | RearrangeButtons;
|
---|
747 |
|
---|
748 | with Canvas do begin
|
---|
749 | GradientFill(Rect(Border, Border, Width - Border,
|
---|
750 | Height - Border), TopColor, BottomColor, gdVertical);
|
---|
751 | Brush.Color := clBtnFace;
|
---|
752 | Brush.Style := bsSolid;
|
---|
753 | Pen.Color := clBtnFace;
|
---|
754 | Pen.Style := psSolid;
|
---|
755 | SetLength(Points, 3);
|
---|
756 | Points[0] := Point(Border, Border);
|
---|
757 | Points[1] := Point(Border, Border + Corner);
|
---|
758 | Points[2] := Point(Border + Corner, Border);
|
---|
759 | Polygon(Points);
|
---|
760 | Points[0] := Point(Width - 1 - Border, Border);
|
---|
761 | Points[1] := Point(Width - 1 - Border, Border + Corner);
|
---|
762 | Points[2] := Point(Width - 1 - Border - Corner, Border);
|
---|
763 | Polygon(Points);
|
---|
764 | Points[0] := Point(Border, Height - 1 - Border);
|
---|
765 | Points[1] := Point(Border, Height - 1 - Border - Corner);
|
---|
766 | Points[2] := Point(Border + Corner, Height - 1 - Border);
|
---|
767 | Polygon(Points);
|
---|
768 | Points[0] := Point(Width - 1 - Border, Height - 1 - Border);
|
---|
769 | Points[1] := Point(Width - 1 - Border, Height - 1 - Border - Corner);
|
---|
770 | Points[2] := Point(Width - 1 - Border - Corner, Height - 1 - Border);
|
---|
771 | Polygon(Points);
|
---|
772 |
|
---|
773 | SetLength(Points, 9);
|
---|
774 | Points[0] := Point(Border, Border + Corner);
|
---|
775 | Points[1] := Point(Border + Corner, Border);
|
---|
776 | Points[2] := Point(Width - 1 - Border - Corner, Border);
|
---|
777 | Points[3] := Point(Width - 1 - Border, Border + Corner);
|
---|
778 | Points[4] := Point(Width - 1 - Border, Height - 1 - Border - Corner);
|
---|
779 | Points[5] := Point(Width - 1 - Border - Corner, Height - 1 - Border);
|
---|
780 | Points[6] := Point(Border + Corner, Height - 1 - Border);
|
---|
781 | Points[7] := Point(Border, Height - 1 - Border - Corner);
|
---|
782 | Points[8] := Point(Border, Border + Corner);
|
---|
783 | Pen.Color := BorderColor;
|
---|
784 | Polyline(Points);
|
---|
785 |
|
---|
786 | Canvas.Brush.Style := bsClear;
|
---|
787 | TitleMaxWidth := Self.Width - 6;
|
---|
788 | for I := 0 to Buttons.Count - 1 do
|
---|
789 | if TCDHeaderButton(Buttons[I]).Visible then
|
---|
790 | Dec(TitleMaxWidth, TCDHeaderButton(Buttons[I]).Icon.Width + 2);
|
---|
791 | if Icon.Picture.Width > 0 then begin
|
---|
792 | TitleLeft := 8 + Icon.Picture.Width;
|
---|
793 | Dec(TitleMaxWidth, Icon.Picture.Width + 2)
|
---|
794 | end else TitleLeft := 6;
|
---|
795 |
|
---|
796 | //SelectObject(Canvas.Handle, MyFont);
|
---|
797 | if Assigned(Control) then
|
---|
798 | Title := Control.Caption else Title := '';
|
---|
799 | if (TextWidth(Title) > TitleMaxWidth) then begin
|
---|
800 | while (Length(Title) > 0) and (TextWidth(Title + '...') > TitleMaxWidth) do begin
|
---|
801 | Delete(Title, Length(Title), 1);
|
---|
802 | end;
|
---|
803 | Title := Title + '...';
|
---|
804 | end;
|
---|
805 |
|
---|
806 | R := Rect(TitleLeft, 4, TitleLeft + TitleMaxWidth, 4 + TextHeight(Title));
|
---|
807 | TextRect(R, TitleLeft, 4, Title);
|
---|
808 | end;
|
---|
809 | end;
|
---|
810 |
|
---|
811 | procedure TCDHeader.RearrangeButtons;
|
---|
812 | const
|
---|
813 | Separation: Integer = 4;
|
---|
814 | var
|
---|
815 | LeftPos: Integer;
|
---|
816 | I: Integer;
|
---|
817 | begin
|
---|
818 | LeftPos := Self.Width;
|
---|
819 | for I := 0 to Buttons.Count - 1 do
|
---|
820 | with TCDHeaderButton(Buttons[I]) do
|
---|
821 | if Visible then begin
|
---|
822 | Icon.Anchors := [akRight, akTop];
|
---|
823 | //Icon.Picture.Bitmap.SetSize(16, 16);
|
---|
824 | Icon.Width := Icon.Picture.Bitmap.Width;
|
---|
825 | Icon.Height := Icon.Picture.Bitmap.Height;
|
---|
826 | LeftPos := LeftPos - Icon.Width - Separation;
|
---|
827 | Icon.Left := LeftPos;
|
---|
828 | Icon.Top := (GrabberSize - Icon.Height) div 2;
|
---|
829 |
|
---|
830 | //ShowMessage(IntToStr(Icon.Width) + ' ' + InttoStr(Icon.Height));
|
---|
831 | Icon.Visible := True;
|
---|
832 | end else Icon.Visible := False;
|
---|
833 | end;
|
---|
834 |
|
---|
835 | procedure TCDHeader.CloseButtonClick(Sender: TObject);
|
---|
836 | begin
|
---|
837 | if Assigned(Control) then
|
---|
838 | Control.Hide;
|
---|
839 | end;
|
---|
840 |
|
---|
841 | end.
|
---|
842 |
|
---|