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