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

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCoolDockCommon.pas

    r183 r187  
    66
    77uses
    8   Classes, SysUtils, Forms, Controls;
     8  Classes, SysUtils, Forms, Controls, Contnrs, StdCtrls, ExtCtrls, ComCtrls;
    99
    1010type
     
    1414
    1515  TCoolDockMasterBase = class;
     16  TCoolDockClientBase = class;
     17
     18  { TCoolDockManagerBase }
    1619
    1720  TCoolDockManagerBase = class(TDockManager)
     21  private
     22    FMaster: TCoolDockMasterBase;
     23    procedure SetMaster(const AValue: TCoolDockMasterBase);
     24  public
     25    property Master: TCoolDockMasterBase read FMaster write SetMaster;
    1826  end;
    1927
     
    3038  end;
    3139
     40  { TCoolDockMasterBase }
     41
    3242  TCoolDockMasterBase = class(TComponent)
    3343  private
    3444    FCoolDockCustomize: TCoolDockCustomizeBase;
     45    FClients: TObjectList; // TList<TCoolDockClientBase>
     46    function GetClient(Index: Integer): TCoolDockClientBase;
    3547    procedure SetCustomize(const AValue: TCoolDockCustomizeBase);
     48  public
     49    constructor Create(AOwner: TComponent); override;
     50    destructor Destroy; override;
     51    procedure RegisterClient(Client: TCoolDockClientBase);
     52    procedure UnRegisterClient(Client: TCoolDockClientBase);
     53    property Clients[Index: Integer]: TCoolDockClientBase read GetClient;
    3654  published
    3755    property Customize: TCoolDockCustomizeBase read FCoolDockCustomize
     
    3957  end;
    4058
     59  { TCoolDockClientBase }
     60
     61  TCoolDockClientBase = class(TComponent)
     62  private
     63    FMaster: TCoolDockMasterBase;
     64    FPanel: TPanel;
     65    procedure SetMaster(const AValue: TCoolDockMasterBase);
     66    procedure SetPanel(const AValue: TPanel);
     67  published
     68    property Master: TCoolDockMasterBase read FMaster
     69      write SetMaster;
     70    property Panel: TPanel read FPanel
     71      write SetPanel;
     72  end;
     73
     74function GetUniqueName(BaseName: string): string;
     75
    4176implementation
     77
     78function GetUniqueName(BaseName: string): string;
     79var
     80  I: Integer;
     81begin
     82  I := 1;
     83  while Assigned(FindGlobalComponent(BaseName + IntToStr(I))) do Inc(I);
     84  Result := BaseName + IntToStr(I);
     85end;
     86
     87
     88{ TCoolDockManagerBase }
     89
     90procedure TCoolDockManagerBase.SetMaster(const AValue: TCoolDockMasterBase);
     91begin
     92  if FMaster = AValue then Exit;
     93  FMaster := AValue;
     94end;
     95
     96{ TCoolDockClientBase }
     97
     98procedure TCoolDockClientBase.SetMaster(const AValue: TCoolDockMasterBase);
     99var
     100  FOldMaster: TCoolDockMasterBase;
     101begin
     102  if FMaster = AValue then Exit;
     103  FOldMaster := FMaster;
     104  FMaster := AValue;
     105  if Assigned(FOldMaster) then
     106    FOldMaster.UnregisterClient(Self);
     107  if Assigned(FMaster) then begin
     108    FMaster.RegisterClient(Self);
     109    if not (csDesigning in ComponentState) then begin
     110      if Assigned(TWinControl(Owner).DockManager) then
     111        TCoolDockManagerBase(TWinControl(Owner).DockManager).Master := FMaster;
     112      if Assigned(FPanel) then
     113        TCoolDockManagerBase(FPanel.DockManager).Master := FMaster;
     114    end;
     115  end;
     116end;
     117
     118procedure TCoolDockClientBase.SetPanel(const AValue: TPanel);
     119var
     120  OldPanel: TPanel;
     121begin
     122  if FPanel = AValue then exit;
     123  OldPanel := FPanel;
     124  FPanel := AValue;
     125  if not (csDesigning in ComponentState) then begin
     126    if Assigned(FPanel) then
     127    with FPanel do begin
     128      DockSite := True;
     129      UseDockManager := True;
     130      //DockManager := TCoolDockManager.Create(FPanel);
     131    end else begin
     132      OldPanel.DockSite := False;
     133    end;
     134  end;
     135end;
    42136
    43137{ TCoolDockConjoinFormBase }
     
    77171end;
    78172
     173constructor TCoolDockMasterBase.Create(AOwner: TComponent);
     174begin
     175  inherited;
     176  FClients := TObjectList.Create;
     177  FClients.OwnsObjects := False;
     178end;
     179
     180destructor TCoolDockMasterBase.Destroy;
     181var
     182  I: Integer;
     183begin
     184  for I := FClients.Count - 1 downto 0 do
     185    TCoolDockClientBase(FClients[I]).Master := nil;
     186  FClients.Free;
     187  inherited Destroy;
     188end;
     189
     190procedure TCoolDockMasterBase.RegisterClient(Client: TCoolDockClientBase);
     191begin
     192  if Assigned(Client) then
     193    if FClients.IndexOf(Client) = -1 then begin
     194      FClients.Add(Client);
     195      Client.Master := Self;
     196    end;
     197end;
     198
     199procedure TCoolDockMasterBase.UnRegisterClient(Client: TCoolDockClientBase);
     200begin
     201  if Assigned(Client) then begin
     202    Client.Master := nil;
     203    FClients.Remove(Client);
     204  end;
     205end;
     206
     207function TCoolDockMasterBase.GetClient(Index: Integer): TCoolDockClientBase;
     208begin
     209  Result := TCoolDockClientBase(FClients[Index]);
     210end;
     211
     212
     213
    79214
    80215end.
Note: See TracChangeset for help on using the changeset viewer.