source: trunk/Packages/CoolDocking/UCDCommon.pas

Last change on this file was 73, checked in by chronos, 12 years ago
  • Modified: Packages are now stored as uncomporessed and are linked with relative path to project.
File size: 5.3 KB
Line 
1unit UCDCommon;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Forms, Controls, Contnrs, StdCtrls, 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 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
76function GetUniqueName(BaseName: string): string;
77function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
78
79implementation
80
81var
82 UniqueNameCounter: Integer;
83
84function GetUniqueName(BaseName: string): string;
85begin
86 Result := BaseName + IntToStr(UniqueNameCounter);
87 Inc(UniqueNameCounter);
88end;
89
90function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
91begin
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;
99end;
100
101{ TCDManagerBase }
102
103procedure TCDManagerBase.SetMaster(const AValue: TCDMasterBase);
104begin
105 if FMaster = AValue then Exit;
106 FMaster := AValue;
107end;
108
109{ TCDClientBase }
110
111procedure TCDClientBase.SetMaster(const AValue: TCDMasterBase);
112var
113 FOldMaster: TCDMasterBase;
114begin
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;
129end;
130
131procedure TCDClientBase.SetPanel(const AValue: TPanel);
132begin
133 if FPanel = AValue then exit;
134 if Assigned(FPanel) then FPanel.DockSite := False;
135 FPanel := AValue;
136end;
137
138{ TCDConjoinFormBase }
139
140constructor TCDConjoinFormBase.Create(TheOwner: TComponent);
141begin
142 inherited Create(TheOwner);
143end;
144
145procedure TCDCustomizeBase.SetMaster(const AValue: TCDMasterBase);
146var
147 OldMaster: TCDMasterBase;
148begin
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;
157end;
158
159procedure TCDMasterBase.SetCustomize(const AValue: TCDCustomizeBase
160 );
161var
162 OldCustomize: TCDCustomizeBase;
163begin
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;
172end;
173
174constructor TCDMasterBase.Create(AOwner: TComponent);
175begin
176 inherited;
177 FClients := TObjectList.Create;
178 FClients.OwnsObjects := False;
179end;
180
181destructor TCDMasterBase.Destroy;
182var
183 I: Integer;
184begin
185 for I := FClients.Count - 1 downto 0 do
186 TCDClientBase(FClients[I]).Master := nil;
187 FClients.Free;
188 inherited Destroy;
189end;
190
191procedure TCDMasterBase.RegisterClient(Client: TCDClientBase);
192begin
193 if Assigned(Client) then
194 if FClients.IndexOf(Client) = -1 then begin
195 FClients.Add(Client);
196 Client.Master := Self;
197 end;
198end;
199
200procedure TCDMasterBase.UnRegisterClient(Client: TCDClientBase);
201begin
202 if Assigned(Client) then begin
203 Client.Master := nil;
204 FClients.Remove(Client);
205 end;
206end;
207
208function TCDMasterBase.GetClient(Index: Integer): TCDClientBase;
209begin
210 Result := TCDClientBase(FClients[Index]);
211end;
212
213initialization
214
215UniqueNameCounter := 1;
216
217end.
218
Note: See TracBrowser for help on using the repository browser.