1 | unit UCDCommon;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Forms, Controls, Contnrs, ExtCtrls, ComCtrls;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
77 | function GetUniqueName(BaseName: string): string;
|
---|
78 | function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
|
---|
79 | procedure DebugLog(Text: string); inline;
|
---|
80 |
|
---|
81 | implementation
|
---|
82 |
|
---|
83 | var
|
---|
84 | UniqueNameCounter: Integer;
|
---|
85 |
|
---|
86 | procedure DebugLog(Text: string); inline;
|
---|
87 | begin
|
---|
88 | {$IFDEF DEBUG_COOLDOCK}
|
---|
89 | WriteLn(FormatDateTime('hh:nn:ss.zzz', Time) + ' ' + Text);
|
---|
90 | {$ENDIF}
|
---|
91 | end;
|
---|
92 |
|
---|
93 | function GetUniqueName(BaseName: string): string;
|
---|
94 | begin
|
---|
95 | Result := BaseName + IntToStr(UniqueNameCounter);
|
---|
96 | Inc(UniqueNameCounter);
|
---|
97 | end;
|
---|
98 |
|
---|
99 | function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
|
---|
100 | begin
|
---|
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;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | { TCDManagerBase }
|
---|
111 |
|
---|
112 | procedure TCDManagerBase.SetMaster(const AValue: TCDMasterBase);
|
---|
113 | begin
|
---|
114 | if FMaster = AValue then Exit;
|
---|
115 | FMaster := AValue;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | { TCDClientBase }
|
---|
119 |
|
---|
120 | procedure TCDClientBase.SetMaster(const AValue: TCDMasterBase);
|
---|
121 | var
|
---|
122 | FOldMaster: TCDMasterBase;
|
---|
123 | begin
|
---|
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;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | procedure TCDClientBase.SetPanel(const AValue: TPanel);
|
---|
141 | begin
|
---|
142 | if FPanel = AValue then exit;
|
---|
143 | if Assigned(FPanel) then FPanel.DockSite := False;
|
---|
144 | FPanel := AValue;
|
---|
145 | end;
|
---|
146 |
|
---|
147 | { TCDConjoinFormBase }
|
---|
148 |
|
---|
149 | constructor TCDConjoinFormBase.Create(TheOwner: TComponent);
|
---|
150 | begin
|
---|
151 | inherited Create(TheOwner);
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TCDCustomizeBase.SetMaster(const AValue: TCDMasterBase);
|
---|
155 | var
|
---|
156 | OldMaster: TCDMasterBase;
|
---|
157 | begin
|
---|
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;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TCDMasterBase.SetCustomize(const AValue: TCDCustomizeBase
|
---|
169 | );
|
---|
170 | var
|
---|
171 | OldCustomize: TCDCustomizeBase;
|
---|
172 | begin
|
---|
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;
|
---|
181 | end;
|
---|
182 |
|
---|
183 | constructor TCDMasterBase.Create(AOwner: TComponent);
|
---|
184 | begin
|
---|
185 | inherited;
|
---|
186 | FClients := TObjectList.Create;
|
---|
187 | FClients.OwnsObjects := False;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | destructor TCDMasterBase.Destroy;
|
---|
191 | var
|
---|
192 | I: Integer;
|
---|
193 | begin
|
---|
194 | for I := FClients.Count - 1 downto 0 do
|
---|
195 | TCDClientBase(FClients[I]).Master := nil;
|
---|
196 | FClients.Free;
|
---|
197 | inherited Destroy;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TCDMasterBase.RegisterClient(Client: TCDClientBase);
|
---|
201 | begin
|
---|
202 | if Assigned(Client) then
|
---|
203 | if FClients.IndexOf(Client) = -1 then begin
|
---|
204 | FClients.Add(Client);
|
---|
205 | Client.Master := Self;
|
---|
206 | end;
|
---|
207 | end;
|
---|
208 |
|
---|
209 | procedure TCDMasterBase.UnRegisterClient(Client: TCDClientBase);
|
---|
210 | begin
|
---|
211 | if Assigned(Client) then begin
|
---|
212 | Client.Master := nil;
|
---|
213 | FClients.Remove(Client);
|
---|
214 | end;
|
---|
215 | end;
|
---|
216 |
|
---|
217 | function TCDMasterBase.GetClient(Index: Integer): TCDClientBase;
|
---|
218 | begin
|
---|
219 | Result := TCDClientBase(FClients[Index]);
|
---|
220 | end;
|
---|
221 |
|
---|
222 | initialization
|
---|
223 |
|
---|
224 | UniqueNameCounter := 1;
|
---|
225 |
|
---|
226 | end.
|
---|
227 |
|
---|