source: Docking/CoolDocking/UCDCommon.pas

Last change on this file was 437, checked in by chronos, 12 years ago
  • Fixed: Better switching tabbed controls.
File size: 5.5 KB
Line 
1unit UCDCommon;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Forms, Controls, Contnrs, ExtCtrls, ComCtrls;
9
10type
11 TCDStyleType = (dsList, dsTabs, dsPopupTabs, dsPopupList);
12 TCDHideType = (dhtPermanent, dhtTemporal);
13 TCDDirection = (ddNone, ddHorizontal, ddVertical);
14 THeaderPos = (hpAuto, hpLeft, hpTop, hpRight, hpBottom);
15
16 TCDMasterBase = class;
17 TCDClientBase = class;
18
19 { TCDManagerBase }
20
21 TCDManagerBase = class(TDockManager)
22 private
23 FMaster: TCDMasterBase;
24 procedure SetMaster(const AValue: TCDMasterBase);
25 public
26 property Master: TCDMasterBase read FMaster write SetMaster;
27 end;
28
29 TCDConjoinFormBase = class(TForm)
30 public
31 constructor Create(TheOwner: TComponent); override;
32 end;
33
34 TCDCustomizeBase = class(TComponent)
35 private
36 FMaster: TCDMasterBase;
37 procedure SetMaster(const AValue: TCDMasterBase);
38 published
39 property Master: TCDMasterBase read FMaster write SetMaster;
40 end;
41
42 { TCDMasterBase }
43
44 TCDMasterBase = class(TComponent)
45 private
46 FCoolDockCustomize: TCDCustomizeBase;
47 FClients: TObjectList; // TList<TCoolDockClientBase>
48 function GetClient(Index: Integer): TCDClientBase;
49 procedure SetCustomize(const AValue: TCDCustomizeBase);
50 public
51 constructor Create(AOwner: TComponent); override;
52 destructor Destroy; override;
53 procedure RegisterClient(Client: TCDClientBase);
54 procedure UnRegisterClient(Client: TCDClientBase);
55 property Clients[Index: Integer]: TCDClientBase read GetClient;
56 published
57 property Customize: TCDCustomizeBase read FCoolDockCustomize
58 write SetCustomize;
59 end;
60
61 { TCDClientBase }
62
63 TCDClientBase = class(TComponent)
64 private
65 FMaster: TCDMasterBase;
66 FPanel: TPanel;
67 procedure SetMaster(const AValue: TCDMasterBase);
68 protected
69 procedure SetPanel(const AValue: TPanel); virtual;
70 published
71 property Master: TCDMasterBase read FMaster
72 write SetMaster;
73 property Panel: TPanel read FPanel
74 write SetPanel;
75 end;
76
77function GetUniqueName(BaseName: string): string;
78function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
79procedure DebugLog(Text: string); inline;
80
81implementation
82
83var
84 UniqueNameCounter: Integer;
85
86procedure DebugLog(Text: string); inline;
87begin
88 {$IFDEF DEBUG_COOLDOCK}
89 WriteLn(FormatDateTime('hh:nn:ss.zzz', Time) + ' ' + Text);
90 {$ENDIF}
91end;
92
93function GetUniqueName(BaseName: string): string;
94begin
95 Result := BaseName + IntToStr(UniqueNameCounter);
96 Inc(UniqueNameCounter);
97end;
98
99function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
100begin
101 case HeaderPos of
102 hpBottom: Result := tpBottom;
103 hpLeft: Result := tpLeft;
104 hpTop: Result := tpTop;
105 hpRight: Result := tpRight;
106 hpAuto: Result := tpTop;
107 end;
108end;
109
110{ TCDManagerBase }
111
112procedure TCDManagerBase.SetMaster(const AValue: TCDMasterBase);
113begin
114 if FMaster = AValue then Exit;
115 FMaster := AValue;
116end;
117
118{ TCDClientBase }
119
120procedure TCDClientBase.SetMaster(const AValue: TCDMasterBase);
121var
122 FOldMaster: TCDMasterBase;
123begin
124 if FMaster = AValue then Exit;
125 FOldMaster := FMaster;
126 FMaster := AValue;
127 if Assigned(FOldMaster) then
128 FOldMaster.UnregisterClient(Self);
129 if Assigned(FMaster) then begin
130 FMaster.RegisterClient(Self);
131 if not (csDesigning in ComponentState) then begin
132 if Assigned(TWinControl(Owner).DockManager) then
133 TCDManagerBase(TWinControl(Owner).DockManager).Master := FMaster;
134 if Assigned(FPanel) then
135 TCDManagerBase(FPanel.DockManager).Master := FMaster;
136 end;
137 end;
138end;
139
140procedure TCDClientBase.SetPanel(const AValue: TPanel);
141begin
142 if FPanel = AValue then exit;
143 if Assigned(FPanel) then FPanel.DockSite := False;
144 FPanel := AValue;
145end;
146
147{ TCDConjoinFormBase }
148
149constructor TCDConjoinFormBase.Create(TheOwner: TComponent);
150begin
151 inherited Create(TheOwner);
152end;
153
154procedure TCDCustomizeBase.SetMaster(const AValue: TCDMasterBase);
155var
156 OldMaster: TCDMasterBase;
157begin
158 if FMaster = AValue then Exit;
159 OldMaster := FMaster;
160 FMaster := AValue;
161 if Assigned(AValue) then begin
162 FMaster.Customize := Self;
163 end else begin
164 OldMaster.Customize := nil;
165 end;
166end;
167
168procedure TCDMasterBase.SetCustomize(const AValue: TCDCustomizeBase
169 );
170var
171 OldCustomize: TCDCustomizeBase;
172begin
173 if FCoolDockCustomize = AValue then Exit;
174 OldCustomize := FCoolDockCustomize;
175 FCoolDockCustomize := AValue;
176 if Assigned(AValue) then begin
177 FCoolDockCustomize.Master := Self;
178 end else begin
179 OldCustomize.Master := nil;
180 end;
181end;
182
183constructor TCDMasterBase.Create(AOwner: TComponent);
184begin
185 inherited;
186 FClients := TObjectList.Create;
187 FClients.OwnsObjects := False;
188end;
189
190destructor TCDMasterBase.Destroy;
191var
192 I: Integer;
193begin
194 for I := FClients.Count - 1 downto 0 do
195 TCDClientBase(FClients[I]).Master := nil;
196 FClients.Free;
197 inherited Destroy;
198end;
199
200procedure TCDMasterBase.RegisterClient(Client: TCDClientBase);
201begin
202 if Assigned(Client) then
203 if FClients.IndexOf(Client) = -1 then begin
204 FClients.Add(Client);
205 Client.Master := Self;
206 end;
207end;
208
209procedure TCDMasterBase.UnRegisterClient(Client: TCDClientBase);
210begin
211 if Assigned(Client) then begin
212 Client.Master := nil;
213 FClients.Remove(Client);
214 end;
215end;
216
217function TCDMasterBase.GetClient(Index: Integer): TCDClientBase;
218begin
219 Result := TCDClientBase(FClients[Index]);
220end;
221
222initialization
223
224UniqueNameCounter := 1;
225
226end.
227
Note: See TracBrowser for help on using the repository browser.