Ignore:
Timestamp:
Mar 11, 2011, 8:41:52 AM (14 years ago)
Author:
george
Message:
  • Modified: Classes TCoolDockConjoinForm and TCoolDockManager separated to own units.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCoolDocking.pas

    r186 r187  
    1313  DateUtils, UCoolDockStyleTabs, UCoolDockStyleRegions, UCoolDockStylePopupTabs,
    1414  UCoolDockStylePopupRegions, UCoolDockStyle, UCoolDockClientPanel,
    15   UCoolDockPopupMenu;
     15  UCoolDockPopupMenu, UCoolDockManager;
    1616
    1717const
     
    1919
    2020type
    21   TCoolDockManager = class;
    2221  TCoolDockClient = class;
    2322  TCoolDockMaster = class;
    24 
    25   { TCoolDockConjoinForm }
    26 
    27   TCoolDockConjoinForm = class(TCoolDockConjoinFormBase)
    28   public
    29     CoolDockClient: TCoolDockClient;
    30     procedure FormShow(Sender : TObject);
    31     procedure FormHide(Sender : TObject);
    32     constructor Create(TheOwner: TComponent); override;
    33     destructor Destroy; override;
    34   private
    35     procedure SetName(const NewName: TComponentName); override;
    36   end;
    37 
    38 
    39   { TCoolDockPanels }
    40 
    41   // TCoolDockPanels = TObjectList<TCoolDockClientPanel>
    42   TCoolDockPanels = class(TObjectList)
    43     destructor Destroy; override;
    44   end;
    45 
    46   { TCoolDockManager }
    47 
    48   TCoolDockManager = class(TCoolDockManagerBase)
    49   private
    50     FMaster: TCoolDockMaster;
    51     FDockStyle: TDockStyle;
    52     FDockSite: TWinControl;
    53     FDockPanels: TCoolDockPanels;
    54     function GetDockSite: TWinControl;
    55     function GetHeaderPos: THeaderPos;
    56     function GetMoveDuration: Integer;
    57     procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;
    58       DropCtl: TControl);
    59     procedure SetDockStyle(const AValue: TDockStyle);
    60     procedure SetHeaderPos(const AValue: THeaderPos);
    61     procedure SetMaster(const AValue: TCoolDockMaster);
    62     procedure SetMoveDuration(const AValue: Integer);
    63     procedure SetVisible(const AValue: Boolean);
    64     procedure UpdateClientSize;
    65   public
    66     DockStyleHandler: TCoolDockStyle;
    67     PopupMenu: TCoolDockPopupMenu;
    68     constructor Create(ADockSite: TWinControl); override;
    69     destructor Destroy; override;
    70 
    71     // Inherited from TDockManager
    72     procedure BeginUpdate; override;
    73     procedure EndUpdate; override;
    74     procedure GetControlBounds(Control: TControl;
    75       out AControlBounds: TRect); override;
    76     function GetDockEdge(ADockObject: TDragDockObject): boolean; override;
    77     procedure InsertControl(ADockObject: TDragDockObject); override; overload;
    78     procedure InsertControl(Control: TControl; InsertAt: TAlign;
    79       DropCtl: TControl); override; overload;
    80     procedure LoadFromStream(Stream: TStream); override;
    81     procedure PaintSite(DC: HDC); override;
    82     procedure MessageHandler(Sender: TControl; var Message: TLMessage); override;
    83     procedure PositionDockRect(ADockObject: TDragDockObject); override; overload;
    84     procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign;
    85       var DockRect: TRect); override; overload;
    86     procedure RemoveControl(Control: TControl); override;
    87     procedure ResetBounds(Force: Boolean); override;
    88     procedure SaveToStream(Stream: TStream); override;
    89     procedure SetReplacingControl(Control: TControl); override;
    90     function AutoFreeByControl: Boolean; override;
    91 
    92     function FindControlInPanels(Control: TControl): TCoolDockClientPanel;
    93     function CreateContainer(InsertAt: TAlign): TCoolDockConjoinForm;
    94     property DockPanels: TCoolDockPanels read FDockPanels write FDockPanels;
    95     property DockStyle: TDockStyle read FDockStyle write SetDockStyle;
    96     property MoveDuration: Integer read GetMoveDuration write SetMoveDuration;
    97     property Master: TCoolDockMaster read FMaster write SetMaster;
    98     property DockSite: TWinControl read GetDockSite;
    99     property HeaderPos: THeaderPos read GetHeaderPos write SetHeaderPos;
    100     property Visible: Boolean write SetVisible;
    101   end;
    10223
    10324  { TCoolDockMaster }
     
    11031    FShowIcons: Boolean;
    11132    FTabsEnabled: Boolean;
    112     FClients: TObjectList;
    113     function GetClient(Index: Integer): TCoolDockClient;
    11433    procedure SetShowIcons(const AValue: Boolean);
    11534    procedure SetTabsEnabled(const AValue: Boolean);
     
    11736    constructor Create(AOwner: TComponent); override;
    11837    destructor Destroy; override;
    119     procedure RegisterClient(Client: TCoolDockClient);
    120     procedure UnRegisterClient(Client: TCoolDockClient);
    121     property Clients[Index: Integer]: TCoolDockClient read GetClient;
    12238  published
    12339    property TabsEnabled: Boolean read FTabsEnabled write SetTabsEnabled;
     
    13248  end;
    13349
    134   TCoolDockClient = class(TComponent)
     50  TCoolDockClient = class(TCoolDockClientBase)
    13551  private
    13652    FDockable: Boolean;
    13753    FFloatable: Boolean;
    138     FMaster: TCoolDockMaster;
    139     FPanel: TPanel;
    14054    procedure SetDockable(const AValue: Boolean);
    14155    procedure SetFloatable(const AValue: Boolean);
    142     procedure SetMaster(const AValue: TCoolDockMaster);
    143     procedure SetPanel(const AValue: TPanel);
    14456  public
    14557    constructor Create(AOwner: TComponent); override;
     
    15062    property Floatable: Boolean read FFloatable
    15163      write SetFloatable default True;
    152     property Master: TCoolDockMaster read FMaster
    153       write SetMaster;
    154     property Panel: TPanel read FPanel
    155       write SetPanel;
    15664  end;
    15765
     
    17179end;
    17280
    173 function GetUniqueName(BaseName: string): string;
    174 var
    175   I: Integer;
    176 begin
    177   I := 1;
    178   while Assigned(FindGlobalComponent(BaseName + IntToStr(I))) do Inc(I);
    179   Result := BaseName + IntToStr(I);
    180 end;
    181 
    182 { TCoolDockPanels }
    183 
    184 destructor TCoolDockPanels.Destroy;
    185 var
    186   Temp: Integer;
    187 begin
    188   Temp := Count;
    189   inherited Destroy;
    190 end;
    191 
    192 
    193 { TCoolDockManager }
    194 
    195 function TCoolDockManager.FindControlInPanels(Control: TControl
    196   ): TCoolDockClientPanel;
    197 var
    198   I: Integer;
    199 begin
    200   I := 0;
    201   while (I < FDockPanels.Count) and
    202     (TCoolDockClientPanel(FDockPanels[I]).Control <> Control) do Inc(I);
    203   if I < FDockPanels.Count then Result := TCoolDockClientPanel(FDockPanels[I])
    204     else Result := nil;
    205 end;
    206 
    207 function TCoolDockManager.GetDockSite: TWinControl;
    208 begin
    209   Result := FDockSite;
    210 end;
    211 
    212 function TCoolDockManager.GetHeaderPos: THeaderPos;
    213 begin
    214 
    215 end;
    216 
    217 function TCoolDockManager.GetMoveDuration: Integer;
    218 begin
    219 
    220 end;
    221 
    222 constructor TCoolDockManager.Create(ADockSite: TWinControl);
    223 var
    224   NewMenuItem: TMenuItem;
    225   NewMenuItem2: TMenuItem;
    226 begin
    227   inherited Create(ADockSite);
    228   FDockSite := ADockSite;
    229   FDockPanels := TCoolDockPanels.Create;
    230 
    231   FDockStyle := dsTabs; // To initialize style value have to be different
    232   DockStyle := dsList;
    233   PopupMenu := TCoolDockPopupMenu.Create(Self);
    234   PopupMenu.Parent := ADockSite;
    235 end;
    236 
    237 destructor TCoolDockManager.Destroy;
    238 begin
    239   PopupMenu.Free;
    240   DockStyleHandler.Free;
    241   FDockPanels.Free;
    242   inherited Destroy;
    243 end;
    244 
    245 procedure TCoolDockManager.BeginUpdate;
    246 begin
    247   inherited BeginUpdate;
    248 end;
    249 
    250 procedure TCoolDockManager.EndUpdate;
    251 begin
    252   inherited EndUpdate;
    253 end;
    254 
    255 procedure TCoolDockManager.GetControlBounds(Control: TControl; out
    256   AControlBounds: TRect);
    257 begin
    258 end;
    259 
    260 function TCoolDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
    261 begin
    262   Result := inherited GetDockEdge(ADockObject);
    263 end;
    264 
    265 procedure TCoolDockManager.InsertControl(ADockObject: TDragDockObject);
    266 begin
    267   inherited InsertControl(ADockObject);
    268 end;
    269 
    270 procedure TCoolDockManager.InsertControlPanel(Control: TControl; InsertAt: TAlign;
    271   DropCtl: TControl);
    272 begin
    273   DockStyleHandler.InsertControl(Control, InsertAt);
    274 end;
    275 
    276 procedure TCoolDockManager.InsertControl(Control: TControl; InsertAt: TAlign;
    277   DropCtl: TControl);
    278 var
    279   NewSplitter: TSplitter;
    280   NewDockPanel: TCoolDockClientPanel;
    281   NewPanel: TPanel;
    282   I: Integer;
    283   NewConjoinDockForm: TCoolDockConjoinForm;
    284   NewDockSite: TWinControl;
    285   NewForm: TForm;
    286 begin
    287   if (FDockSite is TForm) and (not (FDockSite is TCoolDockConjoinForm)) then begin
    288     if (not Assigned(FDockSite.Parent)) then begin
    289       // Create conjointed form
    290       NewConjoinDockForm := CreateContainer(InsertAt);
    291       FDockSite.ManualDock(NewConjoinDockForm);
    292       Control.ManualDock(NewConjoinDockForm, nil, InsertAt);
    293     end else begin
    294       NewConjoinDockForm := CreateContainer(InsertAt);
    295       NewDockSite := FDockSite.HostDockSite;
    296 //      FDockSite.ManualFloat(FDockSite.BoundsRect);
    297       NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);
    298       FDockSite.ManualDock(NewConjoinDockForm);
    299       Control.ManualDock(NewConjoinDockForm, nil, InsertAt);
    300     end;
    301   end else
    302   if (FDockSite is TCoolDockConjoinForm) or (FDockSite is TPanel) or (FDockSite is TCoolDockClientPanel) then begin
    303     InsertControlPanel(Control, InsertAt, DropCtl);
    304   end;
    305 
    306 //  FDockPanel.Invalidate;
    307   //inherited;
    308 end;
    309 
    310 procedure TCoolDockManager.LoadFromStream(Stream: TStream);
    311 begin
    312 end;
    313 
    314 procedure TCoolDockManager.PaintSite(DC: HDC);
    315 var
    316   Canvas: TControlCanvas;
    317   Control: TControl;
    318   I: Integer;
    319   R: TRect;
    320 begin
    321   for I := 0 to FDockPanels.Count - 1 do
    322     with TCoolDockClientPanel(FDockPanels[I]) do begin
    323       Invalidate;
    324     end;
    325 end;
    326 
    327 procedure TCoolDockManager.MessageHandler(Sender: TControl;
    328   var Message: TLMessage);
    329 begin
    330   inherited MessageHandler(Sender, Message);
    331 end;
    332 
    333 procedure TCoolDockManager.PositionDockRect(ADockObject: TDragDockObject);
    334 begin
    335   inherited PositionDockRect(ADockObject);
    336 end;
    337 
    338 procedure TCoolDockManager.PositionDockRect(Client, DropCtl: TControl;
    339   DropAlign: TAlign; var DockRect: TRect);
    340 begin
    341   case DropAlign of
    342     alNone: begin
    343       DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);
    344     end;
    345     alRight: begin
    346       DockRect := Rect(FDockSite.ClientWidth div 2, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);
    347     end;
    348     alLeft: begin
    349       DockRect := Rect(0, 0, FDockSite.ClientWidth div 2, FDockSite.ClientHeight);
    350     end;
    351     alTop: begin
    352       DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight div 2);
    353     end;
    354     alBottom: begin
    355       DockRect := Rect(0, FDockSite.ClientHeight div 2, FDockSite.ClientWidth, FDockSite.ClientHeight);
    356     end;
    357   end;
    358   DockRect.TopLeft := FDockSite.ClientToScreen(DockRect.TopLeft);
    359   DockRect.BottomRight := FDockSite.ClientToScreen(DockRect.BottomRight);
    360 end;
    361 
    362 procedure TCoolDockManager.RemoveControl(Control: TControl);
    363 var
    364   ClientPanel: TCoolDockClientPanel;
    365 begin
    366   DockStyleHandler.RemoveControl(Control);
    367   //inherited;
    368 (*  if Control.HostDockSite = Self.FDockSite then begin
    369     ClientPanel := FindControlInPanels(Control);
    370 
    371     //if Assigned(ClientPanel) then ClientPanel.Splitter.Free;
    372     //Control.RemoveHandlerOnVisibleChanged(ClientPanel.VisibleChange);
    373     FDockPanels.Remove(ClientPanel);
    374     DockStyleHandler.RemoveControl(Control);
    375     UpdateClientSize;
    376     //FDockSite.Invalidate;
    377     //if (FDockSite is TCoolDockConjoinForm) and (FDockSite.DockClientCount = 1) then
    378     //  FDockSite.Free;
    379     DockStyle := DockStyle;
    380   end;
    381   *)
    382 end;
    383 
    384 procedure TCoolDockManager.ResetBounds(Force: Boolean);
    385 var
    386   I: Integer;
    387   Control: TControl;
    388   R: TRect;
    389 begin
    390 end;
    391 
    392 procedure TCoolDockManager.SaveToStream(Stream: TStream);
    393 begin
    394 end;
    395 
    396 procedure TCoolDockManager.SetReplacingControl(Control: TControl);
    397 begin
    398   inherited SetReplacingControl(Control);
    399 end;
    400 
    401 function TCoolDockManager.AutoFreeByControl: Boolean;
    402 begin
    403   Result := inherited AutoFreeByControl;
    404 end;
    405 
    406 function TCoolDockManager.CreateContainer(InsertAt: TAlign): TCoolDockConjoinForm;
    407 var
    408   NewDockSite: TWinControl;
    409   NewConjoinDockForm: TCoolDockConjoinForm;
    410 begin
    411   NewConjoinDockForm := TCoolDockConjoinForm.Create(Application);
    412   NewConjoinDockForm.Name := GetUniqueName('ConjoinForm');
    413   NewConjoinDockForm.Visible := True;
    414   NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;
    415   NewConjoinDockForm.CoolDockClient.Master := Self.Master;
    416   NewDockSite := FDockSite.HostDockSite;
    417   // FDockSite.ManualFloat(FDockSite.BoundsRect);
    418   //NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);
    419   Result := NewConjoinDockForm;
    420 end;
    421 
    422 procedure TCoolDockManager.SetDockStyle(const AValue: TDockStyle);
    423 var
    424   I: Integer;
    425 begin
    426   if FDockStyle <> AValue then begin
    427     FDockStyle := AValue;
    428     FreeAndNil(DockStyleHandler);
    429     if AValue = dsTabs then begin
    430       DockStyleHandler := TCoolDockStyleTabs.Create(Self);
    431       TCoolDockStyleTabs(DockStyleHandler).TabControlChange(Self);
    432     end else
    433     if AValue = dsList then begin
    434       DockStyleHandler := TCoolDockStyleRegions.Create(Self);
    435     end else
    436     if AValue = dsPopupList then begin
    437       DockStyleHandler := TCoolDockStylePopupRegions.Create(Self);
    438     end else
    439     if AValue = dsPopupTabs then begin
    440       DockStyleHandler := TCoolDockStylePopupTabs.Create(Self);
    441     end;
    442   end;
    443   UpdateClientSize;
    444 end;
    445 
    446 procedure TCoolDockManager.SetHeaderPos(const AValue: THeaderPos);
    447 begin
    448 
    449 end;
    450 
    451 procedure TCoolDockManager.SetMaster(const AValue: TCoolDockMaster);
    452 begin
    453   if FMaster = AValue then Exit;
    454   FMaster := AValue;
    455 end;
    456 
    457 procedure TCoolDockManager.SetMoveDuration(const AValue: Integer);
    458 begin
    459 end;
    460 
    461 procedure TCoolDockManager.SetVisible(const AValue: Boolean);
    462 var
    463   I: Integer;
    464 begin
    465   DockStyleHandler.Visible := AValue;
    466 //  for I := 0 to DockPanels.Count - 1 do
    467 //    TCoolDockClientPanel(DockPanels[I]).Visible := AValue;
    468 end;
    469 
    470 procedure TCoolDockManager.UpdateClientSize;
    471 begin
    472   DockStyleHandler.UpdateClientSize;
    473 end;
    474 
    475 { TCoolDockConjoinForm }
    476 
    477 procedure TCoolDockConjoinForm.FormShow(Sender: TObject);
    478 begin
    479   TCoolDockManager(DockManager).Visible := True;
    480 end;
    481 
    482 procedure TCoolDockConjoinForm.FormHide(Sender: TObject);
    483 var
    484   I: Integer;
    485 begin
    486   TCoolDockManager(DockManager).Visible := False;
    487   // Hide all docked childs
    488   with TCoolDockManager(DockManager) do
    489   for I := 0 to DockPanels.Count - 1 do
    490     if Assigned(TCoolDockClientPanel(DockPanels[I]).Control) then begin
    491       TCoolDockClientPanel(DockPanels[I]).Control.Tag := Integer(dhtTemporal);
    492       TCoolDockClientPanel(DockPanels[I]).Control.Hide;
    493     end;
    494 end;
    495 
    496 constructor TCoolDockConjoinForm.Create(TheOwner: TComponent);
    497 begin
    498   inherited CreateNew(TheOwner);
    499   CoolDockClient := TCoolDockClient.Create(Self);
    500   with CoolDockClient do begin
    501   end;
    502   OnShow := FormShow;
    503   OnHide := FormHide;
    504 end;
    505 
    506 destructor TCoolDockConjoinForm.Destroy;
    507 begin
    508   inherited;
    509 end;
    510 
    511 procedure TCoolDockConjoinForm.SetName(const NewName: TComponentName);
    512 begin
    513   inherited SetName(NewName);
    514   CoolDockClient.Name := Name + 'CoolDockClient';
    515 end;
    51681
    51782{ TCoolDockMaster }
     
    52186  if FTabsEnabled = AValue then Exit;
    52287  FTabsEnabled := AValue;
    523 end;
    524 
    525 function TCoolDockMaster.GetClient(Index: Integer): TCoolDockClient;
    526 begin
    527   Result := TCoolDockClient(FClients[Index]);
    52888end;
    52989
     
    53797begin
    53898  inherited Create(AOwner);
    539   FClients := TObjectList.Create;
    540   FClients.OwnsObjects := False;
    54199end;
    542100
     
    546104begin
    547105  // Assigning nil to Client Master property cause unregistring client from list
    548   for I := FClients.Count - 1 downto 0 do
    549     TCoolDockClient(FClients[I]).Master := nil;
    550   FClients.Free;
    551106  Customize := nil;
    552107  inherited Destroy;
    553108end;
    554109
    555 procedure TCoolDockMaster.RegisterClient(Client: TCoolDockClient);
    556 begin
    557   if Assigned(Client) then
    558     if FClients.IndexOf(Client) = -1 then begin
    559       FClients.Add(Client);
    560       Client.Master := Self;
    561     end;
    562 end;
    563 
    564 procedure TCoolDockMaster.UnRegisterClient(Client: TCoolDockClient);
    565 begin
    566   if Assigned(Client) then begin
    567     Client.Master := nil;
    568     FClients.Remove(Client);
    569   end;
    570 end;
    571110
    572111{ TCoolDockClient }
    573 
    574 procedure TCoolDockClient.SetMaster(const AValue: TCoolDockMaster);
    575 var
    576   FOldMaster: TCoolDockMaster;
    577 begin
    578   if FMaster = AValue then Exit;
    579   FOldMaster := FMaster;
    580   FMaster := AValue;
    581   if Assigned(FOldMaster) then
    582     FOldMaster.UnregisterClient(Self);
    583   if Assigned(FMaster) then begin
    584     FMaster.RegisterClient(Self);
    585     if not (csDesigning in ComponentState) then begin
    586       if Assigned(TWinControl(Owner).DockManager) then
    587         TCoolDockManager(TWinControl(Owner).DockManager).Master := FMaster;
    588       if Assigned(Panel) then
    589         TCoolDockManager(Panel.DockManager).Master := FMaster;
    590     end;
    591   end;
    592 end;
    593112
    594113procedure TCoolDockClient.SetDockable(const AValue: Boolean);
     
    640159end;
    641160
    642 procedure TCoolDockClient.SetPanel(const AValue: TPanel);
    643 var
    644   OldPanel: TPanel;
    645 begin
    646   if FPanel = AValue then exit;
    647   OldPanel := FPanel;
    648   FPanel := AValue;
    649   if not (csDesigning in ComponentState) then begin
    650     if Assigned(FPanel) then
    651     with FPanel do begin
    652       DockSite := True;
    653       UseDockManager := True;
    654       DockManager := TCoolDockManager.Create(FPanel);
    655     end else begin
    656       OldPanel.DockSite := False;
    657     end;
    658   end;
    659 end;
    660 
    661 initialization
    662 
    663 RegisterClass(TCoolDockConjoinForm);
    664 
    665 finalization
    666 
    667 UnRegisterClass(TCoolDockConjoinForm);
    668 
    669161
    670162end.
Note: See TracChangeset for help on using the changeset viewer.