Changeset 6 for DockManagement
- Timestamp:
- Dec 9, 2011, 7:22:16 AM (13 years ago)
- Location:
- DockManagement
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DockManagement/Demo/UMainForm.dfm
r5 r6 3 3 Top = 0 4 4 Caption = 'DockManagement demo' 5 ClientHeight = 2026 ClientWidth = 3985 ClientHeight = 372 6 ClientWidth = 540 7 7 Color = clBtnFace 8 8 Font.Charset = DEFAULT_CHARSET -
DockManagement/Demo/UMainForm.pas
r5 r6 4 4 5 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,7 Vcl. Controls, Vcl.Forms, Vcl.Dialogs, UDockForm, Vcl.Menus, UDockManagement;6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, 7 Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UDockForm, Vcl.Menus, UDockManagement, Generics.Collections; 8 8 9 9 type … … 18 18 private 19 19 RegistryKey: string; 20 function NewDockForm: TDockForm; 20 21 public 22 Forms: TObjectList<TForm>; 21 23 FormCounter: Integer; 22 24 BaseDockPanel: TDBaseDockPanel; … … 38 40 procedure TMainForm.FormCreate(Sender: TObject); 39 41 begin 42 Forms := TObjectList<TForm>.Create; 40 43 CustomDockManager := TDDockManager.Create(Self); 41 44 CustomDockManager.RegistryKey := RegistryKey; … … 54 57 BaseDockPanel.Free; 55 58 CustomDockManager.Free; 59 Forms.Free; 56 60 end; 57 61 58 62 procedure TMainForm.FormShow(Sender: TObject); 63 var 64 I: Integer; 59 65 begin 60 66 // Init dock init list … … 68 74 end; 69 75 //CustomDockManager.LoadFromRegistry 76 for I := 0 to 5 do begin 77 Forms.Add(NewDockForm); 78 end; 79 end; 80 81 function TMainForm.NewDockForm: TDockForm; 82 begin 83 Inc(FormCounter); 84 Result := TDockForm.Create(MainForm); 85 Result.Memo1.Text := 'Form ' + IntToStr(FormCounter); 86 Result.Memo1.Align := alClient; 87 Result.Caption := 'Form ' + IntToStr(FormCounter); 88 Result.Show; 89 CustomDockManager.RegisterDockForm(Result, 200, 200, Result.Name, True); 70 90 end; 71 91 72 92 procedure TMainForm.Newform1Click(Sender: TObject); 73 var74 NewForm: TDockForm;75 93 begin 76 Inc(FormCounter); 77 NewForm := TDockForm.Create(MainForm); 78 NewForm.Caption := 'Form ' + IntToStr(FormCounter); 79 NewForm.Show; 80 CustomDockManager.RegisterDockForm(NewForm, 200, 200, NewForm.Name, True); 94 Forms.Add(NewDockForm); 81 95 end; 82 96 -
DockManagement/UDockManagement.pas
r5 r6 11 11 const 12 12 RegistryRootKey = HKEY_CURRENT_USER; 13 UseConjoinForm: Boolean = True; 14 UseTabbedDock: Boolean = True; 13 15 14 16 type … … 27 29 procedure DoClose(var Action: TCloseAction); override; 28 30 procedure DoShow; override; 31 procedure DockDrop(Source: TDragDockObject; X, Y: Integer); override; 32 procedure DoDockOver(Source: TDragDockObject; X, Y: Integer; 33 State: TDragState; var Accept: Boolean); override; 29 34 public 30 35 constructor Create(AOwner: TComponent); override; … … 79 84 end; 80 85 86 TDConjoinPanel = class(TDDockPanel) 87 protected 88 function DoUnDock(NewTarget: TWinControl; Client: TControl): Boolean; override; 89 end; 90 91 TDConjoinForm = class(TCustomForm) 92 Panel: TDConjoinPanel; 93 constructor Create(AOwner: TComponent); override; 94 constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override; 95 end; 96 97 TDTabForm = class(TCustomForm) 98 Panel: TPanel; 99 TabSet: TDockTabSet; 100 constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override; 101 end; 102 81 103 82 104 implementation … … 84 106 uses Registry; 85 107 108 function GetDockRect(X, Y, Width, Height: Integer; Align: TAlign): TRect; 109 const 110 Border = 0.1; 111 FrameWidth = 30; 112 var 113 CenterRectagle: TRect; 114 begin 115 CenterRectagle := Rect(Round(Width * Border), Round(Height * Border), 116 Width - Round(Width * Border), Height - Round(Height * Border)); 117 118 if (Height > 0) and (Width > 0) then begin 119 if (X > CenterRectagle.Left) and (Y > CenterRectagle.Top) and 120 (X < CenterRectagle.Right) and (Y < CenterRectagle.Bottom) then begin 121 Result.TopLeft := CenterRectagle.TopLeft; 122 Result.BottomRight := CenterRectagle.BottomRight; 123 end else 124 if (X < CenterRectagle.Left) and (Round(Y * (Width / Height)) > X) and 125 (Round(Y * (Width / Height)) < (Width - X)) then begin 126 Result.TopLeft := Point(0, 0); 127 Result.BottomRight := Point(Width div 2, Height); 128 end else 129 if (Y < CenterRectagle.Top) and (Round(X * (Height / Width)) > Y) and 130 (Round(X * (Height / Width)) < (Height - Y)) then begin 131 Result.TopLeft := Point(0, 0); 132 Result.BottomRight := Point(Width, Height div 2); 133 end else 134 if (X > CenterRectagle.Right) and (Round(Y * (Width / Height)) > (Width - X)) and 135 (Round(Y * (Width / Height)) < X) then begin 136 Result.TopLeft := Point(Width div 2, 0); 137 Result.BottomRight := Point(Width, Height); 138 end else 139 if (Y > CenterRectagle.Bottom) and (Round(X * (Height / Width)) > (Height - Y)) and 140 (Round(X * (Height / Width)) < Y) then begin 141 Result.TopLeft := Point(0, Height div 2); 142 Result.BottomRight := Point(Width, Height); 143 end else 144 Accept := False; 145 end; 146 147 case Align of 148 alLeft: if Width < FrameWidth then begin 149 Result.TopLeft := Point(0, 0); 150 Result.BottomRight := Point(FrameWidth, Height); 151 end; 152 alTop: if Height < FrameWidth then begin 153 Result.TopLeft := Point(0, 0); 154 Result.BottomRight := Point(Width, FrameWidth); 155 end; 156 alRight: if Width < FrameWidth then begin 157 Result.TopLeft := Point(-FrameWidth, 0); 158 Result.BottomRight := Point(Width, Height); 159 end; 160 alBottom: if Height < FrameWidth then begin 161 Result.TopLeft := Point(0, -FrameWidth); 162 Result.BottomRight := Point(Width, Height); 163 end; 164 end; 165 end; 86 166 87 167 { TDDockManager } … … 360 440 begin 361 441 inherited; 362 DockSite := True; 442 if UseConjoinForm then begin 443 DockSite := True; 444 UseDockManager := True; 445 end; 363 446 DragKind := dkDock; 364 447 DragMode := dmAutomatic; … … 439 522 end; 440 523 524 procedure TDDockForm.DockDrop(Source: TDragDockObject; X, Y: Integer); 525 var 526 NewConjoin: TDConjoinForm; 527 begin 528 inherited; 529 if not UseConjoinForm then Exit; 530 NewConjoin := TDConjoinForm.CreateNew(nil); 531 NewConjoin.Show; 532 NewConjoin.Caption := 'Conjoin'; 533 Source.Control.ManualDock(NewConjoin.Panel, nil, alTop); 534 Self.ManualDock(NewConjoin.Panel, nil, alTop); 535 // if Parent is TDBaseDockPanel then 536 // with TDBaseDockPanel(Parent) do 537 // DockPanelCloseForm(nil, Self, dpaDock); 538 end; 539 441 540 procedure TDDockForm.DoClose(var Action: TCloseAction); 442 541 begin … … 449 548 end; 450 549 451 procedure TDDockForm.DoShow; 452 begin 453 inherited; 454 if Parent is TDDockPanel then 455 with TDDockPanel(Parent) do 456 if Parent is TDBaseDockPanel then 457 with TDBaseDockPanel(Parent) do 458 DockPanelCloseForm(Self, TDDockPanel(Self.Parent), dpaShow); 459 end; 460 461 procedure TDDockPanel.DockDrop(Source: TDragDockObject; X, Y: Integer); 462 begin 463 inherited; 464 if Parent is TDBaseDockPanel then 465 with TDBaseDockPanel(Parent) do 466 DockPanelCloseForm(nil, Self, dpaDock); 467 end; 468 469 procedure TDDockPanel.DoDockOver(Source: TDragDockObject; X, Y: Integer; 550 procedure TDDockForm.DoDockOver(Source: TDragDockObject; X, Y: Integer; 470 551 State: TDragState; var Accept: Boolean); 471 552 const … … 477 558 begin 478 559 inherited; 560 if not UseConjoinForm then Exit; 479 561 Accept := Source.Control is TDDockForm; 480 562 if Accept then … … 531 613 end; 532 614 Source.DockRect := DockRectangle; 615 end; 616 end; 617 618 procedure TDDockForm.DoShow; 619 begin 620 inherited; 621 if Parent is TDDockPanel then 622 with TDDockPanel(Parent) do 623 if Parent is TDBaseDockPanel then 624 with TDBaseDockPanel(Parent) do 625 DockPanelCloseForm(Self, TDDockPanel(Self.Parent), dpaShow); 626 end; 627 628 procedure TDDockPanel.DockDrop(Source: TDragDockObject; X, Y: Integer); 629 begin 630 inherited; 631 if Parent is TDBaseDockPanel then 632 with TDBaseDockPanel(Parent) do 633 DockPanelCloseForm(nil, Self, dpaDock); 634 end; 635 636 procedure TDDockPanel.DoDockOver(Source: TDragDockObject; X, Y: Integer; 637 State: TDragState; var Accept: Boolean); 638 begin 639 inherited; 640 Accept := Source.Control is TDDockForm; 641 if Accept then 642 begin 643 Source.DockRect := GetDockRect(X, Y, Width, Height); 644 Source.DockRect.TopLeft := ClientToScreen(Source.DockRect.TopLeft); 645 Source.DockRect.BottomRight := ClientToScreen(Source.DockRect.BottomRight); 533 646 end; 534 647 end; … … 706 819 end; 707 820 821 { TDConjoinForm } 822 823 constructor TDConjoinForm.Create(AOwner: TComponent); 824 begin 825 inherited; 826 end; 827 828 constructor TDConjoinForm.CreateNew(AOwner: TComponent; Dummy: Integer); 829 begin 830 inherited; 831 Panel := TDConjoinPanel.Create(Self); 832 Panel.Align := alClient; 833 Panel.BevelOuter := bvNone; 834 Panel.BevelInner := bvNone; 835 Panel.Caption := ''; 836 Panel.Parent := Self; 837 Panel.Visible := True; 838 Panel.DockSite := True; 839 Panel.UseDockManager := True; 840 //Panel.DragKind := dkDock; 841 //Panel.DragMode := dmAutomatic; 842 DragMode := dmAutomatic; 843 DragKind := dkDock; 844 end; 845 846 { TDConjoinPanel } 847 848 function TDConjoinPanel.DoUnDock(NewTarget: TWinControl; 849 Client: TControl): Boolean; 850 var 851 VisibleDockClientCount: Integer; 852 I: Integer; 853 begin 854 inherited; 855 856 VisibleDockClientCount := 0; 857 for I := 0 to DockClientCount - 1 do 858 if DockClients[I].Visible then Inc(VisibleDockClientCount); 859 860 if VisibleDockClientCount <= 2 then begin 861 Parent.Free; 862 end; 863 end; 864 865 { TDTabForm } 866 867 constructor TDTabForm.CreateNew(AOwner: TComponent; Dummy: Integer); 868 begin 869 inherited; 870 Panel := TDConjoinPanel.Create(Self); 871 Panel.Align := alClient; 872 Panel.BevelOuter := bvNone; 873 Panel.BevelInner := bvNone; 874 Panel.Caption := ''; 875 Panel.Parent := Self; 876 Panel.Visible := True; 877 Panel.DockSite := True; 878 Panel.UseDockManager := True; 879 //Panel.DragKind := dkDock; 880 //Panel.DragMode := dmAutomatic; 881 DragMode := dmAutomatic; 882 DragKind := dkDock; 883 TabSet := TDockTabSet.Create(Self); 884 TabSet.Parent := Self; 885 TabSet.Align := alBottom; 886 TabSet.Visible := True; 887 end; 888 708 889 end.
Note:
See TracChangeset
for help on using the changeset viewer.