1 | unit UCDCommon;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Forms, Controls, Contnrs, StdCtrls, 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 | constructor Create(TheOwner: TComponent); override;
|
---|
31 | end;
|
---|
32 |
|
---|
33 | TCDCustomizeBase = class(TComponent)
|
---|
34 | private
|
---|
35 | FMaster: TCDMasterBase;
|
---|
36 | procedure SetMaster(const AValue: TCDMasterBase);
|
---|
37 | published
|
---|
38 | property Master: TCDMasterBase read FMaster write SetMaster;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | { TCDMasterBase }
|
---|
42 |
|
---|
43 | TCDMasterBase = class(TComponent)
|
---|
44 | private
|
---|
45 | FCoolDockCustomize: TCDCustomizeBase;
|
---|
46 | FClients: TObjectList; // TList<TCoolDockClientBase>
|
---|
47 | function GetClient(Index: Integer): TCDClientBase;
|
---|
48 | procedure SetCustomize(const AValue: TCDCustomizeBase);
|
---|
49 | public
|
---|
50 | constructor Create(AOwner: TComponent); override;
|
---|
51 | destructor Destroy; override;
|
---|
52 | procedure RegisterClient(Client: TCDClientBase);
|
---|
53 | procedure UnRegisterClient(Client: TCDClientBase);
|
---|
54 | property Clients[Index: Integer]: TCDClientBase read GetClient;
|
---|
55 | published
|
---|
56 | property Customize: TCDCustomizeBase read FCoolDockCustomize
|
---|
57 | write SetCustomize;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | { TCDClientBase }
|
---|
61 |
|
---|
62 | TCDClientBase = class(TComponent)
|
---|
63 | private
|
---|
64 | FMaster: TCDMasterBase;
|
---|
65 | FPanel: TPanel;
|
---|
66 | procedure SetMaster(const AValue: TCDMasterBase);
|
---|
67 | public
|
---|
68 | procedure SetPanel(const AValue: TPanel); virtual;
|
---|
69 | published
|
---|
70 | property Master: TCDMasterBase read FMaster
|
---|
71 | write SetMaster;
|
---|
72 | property Panel: TPanel read FPanel
|
---|
73 | write SetPanel;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | function GetUniqueName(BaseName: string): string;
|
---|
77 | function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
|
---|
78 |
|
---|
79 | implementation
|
---|
80 |
|
---|
81 | var
|
---|
82 | UniqueNameCounter: Integer;
|
---|
83 |
|
---|
84 | function GetUniqueName(BaseName: string): string;
|
---|
85 | begin
|
---|
86 | Result := BaseName + IntToStr(UniqueNameCounter);
|
---|
87 | Inc(UniqueNameCounter);
|
---|
88 | end;
|
---|
89 |
|
---|
90 | function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
|
---|
91 | begin
|
---|
92 | case HeaderPos of
|
---|
93 | hpBottom: Result := tpBottom;
|
---|
94 | hpLeft: Result := tpLeft;
|
---|
95 | hpTop: Result := tpTop;
|
---|
96 | hpRight: Result := tpRight;
|
---|
97 | hpAuto: Result := tpTop;
|
---|
98 | end;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | { TCDManagerBase }
|
---|
102 |
|
---|
103 | procedure TCDManagerBase.SetMaster(const AValue: TCDMasterBase);
|
---|
104 | begin
|
---|
105 | if FMaster = AValue then Exit;
|
---|
106 | FMaster := AValue;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | { TCDClientBase }
|
---|
110 |
|
---|
111 | procedure TCDClientBase.SetMaster(const AValue: TCDMasterBase);
|
---|
112 | var
|
---|
113 | FOldMaster: TCDMasterBase;
|
---|
114 | begin
|
---|
115 | if FMaster = AValue then Exit;
|
---|
116 | FOldMaster := FMaster;
|
---|
117 | FMaster := AValue;
|
---|
118 | if Assigned(FOldMaster) then
|
---|
119 | FOldMaster.UnregisterClient(Self);
|
---|
120 | if Assigned(FMaster) then begin
|
---|
121 | FMaster.RegisterClient(Self);
|
---|
122 | if not (csDesigning in ComponentState) then begin
|
---|
123 | if Assigned(TWinControl(Owner).DockManager) then
|
---|
124 | TCDManagerBase(TWinControl(Owner).DockManager).Master := FMaster;
|
---|
125 | if Assigned(FPanel) then
|
---|
126 | TCDManagerBase(FPanel.DockManager).Master := FMaster;
|
---|
127 | end;
|
---|
128 | end;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TCDClientBase.SetPanel(const AValue: TPanel);
|
---|
132 | begin
|
---|
133 | if FPanel = AValue then exit;
|
---|
134 | if Assigned(FPanel) then FPanel.DockSite := False;
|
---|
135 | FPanel := AValue;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | { TCDConjoinFormBase }
|
---|
139 |
|
---|
140 | constructor TCDConjoinFormBase.Create(TheOwner: TComponent);
|
---|
141 | begin
|
---|
142 | inherited Create(TheOwner);
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TCDCustomizeBase.SetMaster(const AValue: TCDMasterBase);
|
---|
146 | var
|
---|
147 | OldMaster: TCDMasterBase;
|
---|
148 | begin
|
---|
149 | if FMaster = AValue then Exit;
|
---|
150 | OldMaster := FMaster;
|
---|
151 | FMaster := AValue;
|
---|
152 | if Assigned(AValue) then begin
|
---|
153 | FMaster.Customize := Self;
|
---|
154 | end else begin
|
---|
155 | OldMaster.Customize := nil;
|
---|
156 | end;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TCDMasterBase.SetCustomize(const AValue: TCDCustomizeBase
|
---|
160 | );
|
---|
161 | var
|
---|
162 | OldCustomize: TCDCustomizeBase;
|
---|
163 | begin
|
---|
164 | if FCoolDockCustomize = AValue then Exit;
|
---|
165 | OldCustomize := FCoolDockCustomize;
|
---|
166 | FCoolDockCustomize := AValue;
|
---|
167 | if Assigned(AValue) then begin
|
---|
168 | FCoolDockCustomize.Master := Self;
|
---|
169 | end else begin
|
---|
170 | OldCustomize.Master := nil;
|
---|
171 | end;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | constructor TCDMasterBase.Create(AOwner: TComponent);
|
---|
175 | begin
|
---|
176 | inherited;
|
---|
177 | FClients := TObjectList.Create;
|
---|
178 | FClients.OwnsObjects := False;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | destructor TCDMasterBase.Destroy;
|
---|
182 | var
|
---|
183 | I: Integer;
|
---|
184 | begin
|
---|
185 | for I := FClients.Count - 1 downto 0 do
|
---|
186 | TCDClientBase(FClients[I]).Master := nil;
|
---|
187 | FClients.Free;
|
---|
188 | inherited Destroy;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | procedure TCDMasterBase.RegisterClient(Client: TCDClientBase);
|
---|
192 | begin
|
---|
193 | if Assigned(Client) then
|
---|
194 | if FClients.IndexOf(Client) = -1 then begin
|
---|
195 | FClients.Add(Client);
|
---|
196 | Client.Master := Self;
|
---|
197 | end;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TCDMasterBase.UnRegisterClient(Client: TCDClientBase);
|
---|
201 | begin
|
---|
202 | if Assigned(Client) then begin
|
---|
203 | Client.Master := nil;
|
---|
204 | FClients.Remove(Client);
|
---|
205 | end;
|
---|
206 | end;
|
---|
207 |
|
---|
208 | function TCDMasterBase.GetClient(Index: Integer): TCDClientBase;
|
---|
209 | begin
|
---|
210 | Result := TCDClientBase(FClients[Index]);
|
---|
211 | end;
|
---|
212 |
|
---|
213 | initialization
|
---|
214 |
|
---|
215 | UniqueNameCounter := 1;
|
---|
216 |
|
---|
217 | end.
|
---|
218 |
|
---|