Changeset 6 for DockManagement


Ignore:
Timestamp:
Dec 9, 2011, 7:22:16 AM (13 years ago)
Author:
chronos
Message:
  • Added: Some basic functionality for conjoined form support.
Location:
DockManagement
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • DockManagement/Demo/UMainForm.dfm

    r5 r6  
    33  Top = 0
    44  Caption = 'DockManagement demo'
    5   ClientHeight = 202
    6   ClientWidth = 398
     5  ClientHeight = 372
     6  ClientWidth = 540
    77  Color = clBtnFace
    88  Font.Charset = DEFAULT_CHARSET
  • DockManagement/Demo/UMainForm.pas

    r5 r6  
    44
    55uses
    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;
    88
    99type
     
    1818  private
    1919    RegistryKey: string;
     20    function NewDockForm: TDockForm;
    2021  public
     22    Forms: TObjectList<TForm>;
    2123    FormCounter: Integer;
    2224    BaseDockPanel: TDBaseDockPanel;
     
    3840procedure TMainForm.FormCreate(Sender: TObject);
    3941begin
     42  Forms := TObjectList<TForm>.Create;
    4043  CustomDockManager := TDDockManager.Create(Self);
    4144  CustomDockManager.RegistryKey := RegistryKey;
     
    5457  BaseDockPanel.Free;
    5558  CustomDockManager.Free;
     59  Forms.Free;
    5660end;
    5761
    5862procedure TMainForm.FormShow(Sender: TObject);
     63var
     64  I: Integer;
    5965begin
    6066 // Init dock init list
     
    6874  end;
    6975  //CustomDockManager.LoadFromRegistry
     76  for I := 0 to 5 do begin
     77    Forms.Add(NewDockForm);
     78  end;
     79end;
     80
     81function TMainForm.NewDockForm: TDockForm;
     82begin
     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);
    7090end;
    7191
    7292procedure TMainForm.Newform1Click(Sender: TObject);
    73 var
    74   NewForm: TDockForm;
    7593begin
    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);
    8195end;
    8296
  • DockManagement/UDockManagement.pas

    r5 r6  
    1111const
    1212  RegistryRootKey = HKEY_CURRENT_USER;
     13  UseConjoinForm: Boolean = True;
     14  UseTabbedDock: Boolean = True;
    1315
    1416type
     
    2729    procedure DoClose(var Action: TCloseAction); override;
    2830    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;
    2934  public
    3035    constructor Create(AOwner: TComponent); override;
     
    7984  end;
    8085
     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
    81103
    82104implementation
     
    84106uses Registry;
    85107
     108function GetDockRect(X, Y, Width, Height: Integer; Align: TAlign): TRect;
     109const
     110  Border = 0.1;
     111  FrameWidth = 30;
     112var
     113  CenterRectagle: TRect;
     114begin
     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;
     165end;
    86166
    87167{ TDDockManager }
     
    360440begin
    361441  inherited;
    362   DockSite := True;
     442  if UseConjoinForm then begin
     443    DockSite := True;
     444    UseDockManager := True;
     445  end;
    363446  DragKind := dkDock;
    364447  DragMode := dmAutomatic;
     
    439522end;
    440523
     524procedure TDDockForm.DockDrop(Source: TDragDockObject; X, Y: Integer);
     525var
     526  NewConjoin: TDConjoinForm;
     527begin
     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);
     538end;
     539
    441540procedure TDDockForm.DoClose(var Action: TCloseAction);
    442541begin
     
    449548end;
    450549
    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;
     550procedure TDDockForm.DoDockOver(Source: TDragDockObject; X, Y: Integer;
    470551  State: TDragState; var Accept: Boolean);
    471552const
     
    477558begin
    478559  inherited;
     560  if not UseConjoinForm then Exit;
    479561  Accept := Source.Control is TDDockForm;
    480562  if Accept then
     
    531613    end;
    532614    Source.DockRect := DockRectangle;
     615  end;
     616end;
     617
     618procedure TDDockForm.DoShow;
     619begin
     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);
     626end;
     627
     628procedure TDDockPanel.DockDrop(Source: TDragDockObject; X, Y: Integer);
     629begin
     630  inherited;
     631  if Parent is TDBaseDockPanel then
     632    with TDBaseDockPanel(Parent) do
     633      DockPanelCloseForm(nil, Self, dpaDock);
     634end;
     635
     636procedure TDDockPanel.DoDockOver(Source: TDragDockObject; X, Y: Integer;
     637  State: TDragState; var Accept: Boolean);
     638begin
     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);
    533646  end;
    534647end;
     
    706819end;
    707820
     821{ TDConjoinForm }
     822
     823constructor TDConjoinForm.Create(AOwner: TComponent);
     824begin
     825  inherited;
     826end;
     827
     828constructor TDConjoinForm.CreateNew(AOwner: TComponent; Dummy: Integer);
     829begin
     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;
     844end;
     845
     846{ TDConjoinPanel }
     847
     848function TDConjoinPanel.DoUnDock(NewTarget: TWinControl;
     849  Client: TControl): Boolean;
     850var
     851  VisibleDockClientCount: Integer;
     852  I: Integer;
     853begin
     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;
     863end;
     864
     865{ TDTabForm }
     866
     867constructor TDTabForm.CreateNew(AOwner: TComponent; Dummy: Integer);
     868begin
     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;
     887end;
     888
    708889end.
Note: See TracChangeset for help on using the changeset viewer.