1 | unit UCDManagerRegions;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Controls, ExtCtrls, StdCtrls, Forms,
|
---|
9 | Graphics, Contnrs, Buttons, UCDCommon, UCDManager,
|
---|
10 | LCLType, LMessages;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TCDManagerRegionsItem }
|
---|
15 |
|
---|
16 | TCDManagerRegionsItem = class(TCDManagerItem)
|
---|
17 | PanelHeader: TCDPanelHeader;
|
---|
18 | Splitter: TSplitter;
|
---|
19 | procedure VisibleChange(Sender: TObject); override;
|
---|
20 | procedure Paint(Sender: TObject); override;
|
---|
21 | constructor Create;
|
---|
22 | destructor Destroy; override;
|
---|
23 | procedure SetControl(const AValue: TWinControl); override;
|
---|
24 | end;
|
---|
25 |
|
---|
26 | { TCDManagerRegions }
|
---|
27 |
|
---|
28 | TCDManagerRegions = class(TCDManager)
|
---|
29 | private
|
---|
30 | FDockItems: TObjectList; // TList<TCDManagerRegionsItem>
|
---|
31 | function GetHeaderPos: THeaderPos; override;
|
---|
32 | procedure SetHeaderPos(const AValue: THeaderPos); override;
|
---|
33 | function GetDirection(InsertAt: TAlign): TCDDirection;
|
---|
34 | public
|
---|
35 | FDockDirection: TCDDirection;
|
---|
36 | //Panels: TObjectList; // TObjectList<TCDStyleRegionsPanel>
|
---|
37 | function FindControlInPanels(Control: TControl): TCDManagerItem; override;
|
---|
38 | procedure InsertControlNoUpdate(Control: TControl; InsertAt: TAlign);
|
---|
39 | procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;
|
---|
40 | DropCtl: TControl); override;
|
---|
41 | procedure RemoveControl(Control: TControl); override;
|
---|
42 | constructor Create(ADockSite: TWinControl);
|
---|
43 | destructor Destroy; override;
|
---|
44 | procedure PaintSite(DC: HDC); override;
|
---|
45 | procedure UpdateClientSize; override;
|
---|
46 | procedure SetVisible(const AValue: Boolean); override;
|
---|
47 | procedure ChangeVisible(Control: TWinControl; Visible: Boolean);
|
---|
48 | property DockDirection: TCDDirection read FDockDirection
|
---|
49 | write FDockDirection;
|
---|
50 | property DockItems: TObjectList read FDockItems write FDockItems;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | implementation
|
---|
54 |
|
---|
55 | uses
|
---|
56 | UCDClient, UCDConjoinForm;
|
---|
57 |
|
---|
58 | { TCDManagerRegionsItem }
|
---|
59 |
|
---|
60 | procedure TCDManagerRegionsItem.VisibleChange(Sender: TObject);
|
---|
61 | begin
|
---|
62 | inherited VisibleChange(Sender);
|
---|
63 | with TCDManagerRegions(Manager) do begin
|
---|
64 | //if TControl(Sender).Visible then begin
|
---|
65 | // TCDManagerRegionsItem(DockItems[DockItems.IndexOf(FindControlInPanels(TControl(Sender)))]).HideType := dhtPermanent;
|
---|
66 | //end;
|
---|
67 | UpdateClientSize;
|
---|
68 | end;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TCDManagerRegionsItem.Paint(Sender: TObject);
|
---|
72 | var
|
---|
73 | I: Integer;
|
---|
74 | R: TRect;
|
---|
75 | begin
|
---|
76 | inherited Paint(Sender);
|
---|
77 | with PanelHeader do
|
---|
78 | if not (csDesigning in ComponentState) then
|
---|
79 | if Assigned(Control) then begin
|
---|
80 | //R := Control.ClientRect;
|
---|
81 | //Canvas.FillRect(R);
|
---|
82 | if Visible then begin
|
---|
83 | Header.Invalidate;
|
---|
84 | end;
|
---|
85 | end;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | constructor TCDManagerRegionsItem.Create;
|
---|
89 | begin
|
---|
90 | PanelHeader := TCDPanelHeader.Create(nil);
|
---|
91 | // PanelHeader.Header.ManagerItem := Self;
|
---|
92 | PanelHeader.Header.OnMouseDown := DockPanelMouseDown;
|
---|
93 | PanelHeader.Header.Icon.OnMouseDown := DockPanelMouseDown;
|
---|
94 |
|
---|
95 | Splitter := TSplitter.Create(nil);
|
---|
96 | with Splitter do begin
|
---|
97 | Width := 3;
|
---|
98 | Height := 3;
|
---|
99 | //Parent := Panel;
|
---|
100 | //Color := clRed;
|
---|
101 | end;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | destructor TCDManagerRegionsItem.Destroy;
|
---|
105 | begin
|
---|
106 | PanelHeader.Parent := nil;
|
---|
107 | PanelHeader.Free;
|
---|
108 | Splitter.Parent := nil;
|
---|
109 | Splitter.Free;
|
---|
110 | Control.Parent := nil;
|
---|
111 | inherited Destroy;
|
---|
112 | end;
|
---|
113 |
|
---|
114 | procedure TCDManagerRegionsItem.SetControl(const AValue: TWinControl);
|
---|
115 | begin
|
---|
116 | inherited SetControl(AValue);
|
---|
117 | PanelHeader.Header.Control := AValue;
|
---|
118 | end;
|
---|
119 |
|
---|
120 |
|
---|
121 | { TCDManagerRegions }
|
---|
122 |
|
---|
123 | function TCDManagerRegions.GetHeaderPos: THeaderPos;
|
---|
124 | begin
|
---|
125 | Result := inherited;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TCDManagerRegions.SetHeaderPos(const AValue: THeaderPos);
|
---|
129 | begin
|
---|
130 | inherited SetHeaderPos(AValue);
|
---|
131 | if Assigned(DockSite.Parent) then
|
---|
132 | TCDManager(DockSite.Parent.DockManager).UpdateClientSize;
|
---|
133 | (* case AValue of
|
---|
134 | hpBottom, hpTop: FDockDirection := ddVertical;
|
---|
135 | hpLeft, hpRight: FDockDirection := ddHorizontal;
|
---|
136 | end;*)
|
---|
137 | end;
|
---|
138 |
|
---|
139 | function TCDManagerRegions.GetDirection(InsertAt: TAlign): TCDDirection;
|
---|
140 | begin
|
---|
141 | Result := ddHorizontal;
|
---|
142 | if (InsertAt = alTop) or (InsertAt = alBottom) then
|
---|
143 | Result := ddVertical
|
---|
144 | else
|
---|
145 | if (InsertAt = alLeft) or (InsertAt = alRight) then
|
---|
146 | Result := ddHorizontal
|
---|
147 | else;
|
---|
148 | end;
|
---|
149 |
|
---|
150 | function TCDManagerRegions.FindControlInPanels(Control: TControl
|
---|
151 | ): TCDManagerItem;
|
---|
152 | var
|
---|
153 | I: Integer;
|
---|
154 | begin
|
---|
155 | I := 0;
|
---|
156 | while (I < FDockItems.Count) and
|
---|
157 | (TCDManagerItem(FDockItems[I]).Control <> Control) do Inc(I);
|
---|
158 | if I < FDockItems.Count then Result := TCDManagerItem(FDockItems[I])
|
---|
159 | else Result := nil;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TCDManagerRegions.InsertControlNoUpdate(Control: TControl;
|
---|
163 | InsertAt: TAlign);
|
---|
164 | var
|
---|
165 | NewItem: TCDManagerRegionsItem;
|
---|
166 | begin
|
---|
167 | NewItem := TCDManagerRegionsItem.Create;
|
---|
168 | with NewItem do begin
|
---|
169 | PanelHeader.Parent := Self.DockSite;
|
---|
170 | Manager := Self;
|
---|
171 | if DockStyle = dsList then Visible := True;
|
---|
172 | PanelHeader.Header.PopupMenu := Self.PopupMenu;
|
---|
173 | end;
|
---|
174 | if (Control is TForm) and Assigned((Control as TForm).Icon) then begin
|
---|
175 | NewItem.PanelHeader.Header.Icon.Picture.Assign((Control as TForm).Icon);
|
---|
176 | NewItem.PanelHeader.Header.Icon.Width := NewItem.PanelHeader.Header.Icon.Picture.Bitmap.Width;
|
---|
177 | NewItem.PanelHeader.Header.Icon.Height := NewItem.PanelHeader.Header.Icon.Picture.Bitmap.Height;
|
---|
178 | end;
|
---|
179 |
|
---|
180 | NewItem.PanelHeader.Parent := DockSite;
|
---|
181 |
|
---|
182 | NewItem.Control := TWinControl(Control);
|
---|
183 | Control.AddHandlerOnVisibleChanged(NewItem.VisibleChange);
|
---|
184 | Control.AddHandlerOnVisibleChanging(NewItem.VisibleChanging);
|
---|
185 | Control.Parent := NewItem.PanelHeader.ControlPanel;
|
---|
186 | Control.Align := alClient;
|
---|
187 | if (InsertAt = alTop) or (InsertAt = alLeft) then
|
---|
188 | DockItems.Insert(0, NewItem)
|
---|
189 | else DockItems.Add(NewItem);
|
---|
190 | end;
|
---|
191 |
|
---|
192 | procedure TCDManagerRegions.InsertControlPanel(Control: TControl; InsertAt: TAlign;
|
---|
193 | DropCtl: TControl);
|
---|
194 | var
|
---|
195 | NewItem: TCDManagerRegionsItem;
|
---|
196 | I: Integer;
|
---|
197 | NewDirection: TCDDirection;
|
---|
198 | NewConjoinDockForm: TCDConjoinForm;
|
---|
199 | NewDockSite: TWinControl;
|
---|
200 | begin
|
---|
201 | inherited;
|
---|
202 | begin
|
---|
203 | if DockSite.DockClientCount <= 2 then FDockDirection := GetDirection(InsertAt)
|
---|
204 | else
|
---|
205 | if (DockSite.DockClientCount > 2) then begin
|
---|
206 | NewDirection := GetDirection(InsertAt);
|
---|
207 | if (NewDirection <> FDockDirection) then begin
|
---|
208 | // Direction change, create conjoin form
|
---|
209 | NewConjoinDockForm := CreateConjoinForm;
|
---|
210 | try
|
---|
211 | FreeParentIfEmpty := False;
|
---|
212 | for I := DockSite.DockClientCount - 1 downto 0 do begin
|
---|
213 | DockSite.DockClients[I].ManualDock(NewConjoinDockForm);
|
---|
214 | end;
|
---|
215 | finally
|
---|
216 | FreeParentIfEmpty := True;
|
---|
217 | end;
|
---|
218 | NewConjoinDockForm.ManualDock(DockSite);
|
---|
219 | Control.ManualDock(DockSite, nil, InsertAt);
|
---|
220 | NewConjoinDockForm.UpdateCaption;
|
---|
221 | UpdateClientSize;
|
---|
222 | Exit;
|
---|
223 | end;
|
---|
224 | end;
|
---|
225 | InsertControlNoUpdate(Control, InsertAt);
|
---|
226 | end;
|
---|
227 | UpdateClientSize;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TCDManagerRegions.RemoveControl(Control: TControl);
|
---|
231 | var
|
---|
232 | ManagerItem: TCDManagerItem;
|
---|
233 | ClientCount: Integer;
|
---|
234 | begin
|
---|
235 | ManagerItem := FindControlInPanels(Control);
|
---|
236 | if Assigned(ManagerItem) then begin
|
---|
237 | Control.RemoveHandlerOnVisibleChanged(ManagerItem.VisibleChange);
|
---|
238 | Control.RemoveHandlerOnVisibleChanging(ManagerItem.VisibleChanging);
|
---|
239 | end;
|
---|
240 |
|
---|
241 | DockItems.Remove(ManagerItem);
|
---|
242 | ClientCount := DockItems.Count;
|
---|
243 |
|
---|
244 | //if TCDManager(Manager).DockSite.DockClientCount = 2 then FDockDirection := ddNone;
|
---|
245 | if FreeParentIfEmpty and (ClientCount = 1) then begin
|
---|
246 | // Last removed control => Free parent if it is TCDConjoinForm
|
---|
247 | if Self.DockSite is TCDConjoinForm then
|
---|
248 | with TCDConjoinForm(Self.DockSite) do begin
|
---|
249 | if Assigned(Parent) then begin
|
---|
250 | TCDManagerItem(DockItems[0]).Control.ManualDock(HostDockSite);
|
---|
251 | end else TCDManagerItem(DockItems[0]).Control.ManualFloat(Rect(Left, Top, Left + Width, Top + Height));
|
---|
252 | ManualFloat(Rect(Left, Top, Left + Width, Top + Height));
|
---|
253 | inherited RemoveControl(Control);
|
---|
254 | Free;
|
---|
255 | Exit;
|
---|
256 | end;
|
---|
257 | end;
|
---|
258 | inherited RemoveControl(Control);
|
---|
259 | if ClientCount > 1 then UpdateClientSize;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | constructor TCDManagerRegions.Create(ADockSite: TWinControl);
|
---|
263 | var
|
---|
264 | I: Integer;
|
---|
265 | NewItem: TCDManagerRegionsItem;
|
---|
266 | begin
|
---|
267 | inherited;
|
---|
268 | FDockStyle := dsList;
|
---|
269 | FDockItems := TObjectList.Create;
|
---|
270 |
|
---|
271 | for I := 0 to ADockSite.DockClientCount - 1 do
|
---|
272 | InsertControlNoUpdate(ADockSite.DockClients[I], alLeft);
|
---|
273 | UpdateClientSize;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | destructor TCDManagerRegions.Destroy;
|
---|
277 | begin
|
---|
278 | FDockItems.Free;
|
---|
279 | inherited Destroy;
|
---|
280 | end;
|
---|
281 |
|
---|
282 | procedure TCDManagerRegions.PaintSite(DC: HDC);
|
---|
283 | var
|
---|
284 | I: Integer;
|
---|
285 | begin
|
---|
286 | inherited PaintSite(DC);
|
---|
287 | for I := 0 to FDockItems.Count - 1 do
|
---|
288 | with TCDManagerRegionsItem(FDockItems[I]) do begin
|
---|
289 | PanelHeader.Invalidate;
|
---|
290 | end;
|
---|
291 | end;
|
---|
292 |
|
---|
293 | procedure TCDManagerRegions.UpdateClientSize;
|
---|
294 | var
|
---|
295 | I: Integer;
|
---|
296 | SplitterLeft: Integer;
|
---|
297 | SplitterTop: Integer;
|
---|
298 | BaseAlign: TAlign;
|
---|
299 | VisibleControlsCount: Integer;
|
---|
300 | begin
|
---|
301 | inherited UpdateClientSize;
|
---|
302 | if FDockDirection = ddHorizontal then
|
---|
303 | BaseAlign := alLeft else BaseAlign := alTop;
|
---|
304 |
|
---|
305 | SplitterLeft := 0;
|
---|
306 | SplitterTop := 0;
|
---|
307 | VisibleControlsCount := DockSite.VisibleDockClientCount;
|
---|
308 | if DockSite is TForm then
|
---|
309 | DockSite.Visible := VisibleControlsCount > 0;
|
---|
310 | if VisibleControlsCount = 0 then VisibleControlsCount := 1;
|
---|
311 |
|
---|
312 | for I := 0 to DockItems.Count - 1 do
|
---|
313 | with TCDManagerRegionsItem(DockItems[I]) do
|
---|
314 | begin
|
---|
315 | PanelHeader.Left := SplitterLeft;
|
---|
316 | PanelHeader.Top := SplitterTop;
|
---|
317 | PanelHeader.Height := Self.DockSite.Height div
|
---|
318 | VisibleControlsCount;
|
---|
319 | PanelHeader.Width := Self.DockSite.Width div
|
---|
320 | VisibleControlsCount;
|
---|
321 | if Assigned(TWinControl(Control).DockManager) then
|
---|
322 | PanelHeader.Header.Visible := TCDManager(TWinControl(Control).DockManager).HeaderVisible;
|
---|
323 | PanelHeader.Visible := Control.Visible;
|
---|
324 | Paint(Self);
|
---|
325 | if I < (DockItems.Count - 1) then PanelHeader.Align := BaseAlign
|
---|
326 | else PanelHeader.Align := alClient;
|
---|
327 |
|
---|
328 | Inc(SplitterLeft, PanelHeader.Width);
|
---|
329 | Inc(SplitterTop, PanelHeader.Height);
|
---|
330 | Splitter.Left := SplitterLeft;
|
---|
331 | Splitter.Top := SplitterTop;
|
---|
332 | Splitter.Parent := Self.DockSite;
|
---|
333 | Splitter.Align := BaseAlign;
|
---|
334 | Splitter.Visible := I < (DockItems.Count - 1);
|
---|
335 | Inc(SplitterLeft, Splitter.Width);
|
---|
336 | Inc(SplitterTop, Splitter.Height);
|
---|
337 |
|
---|
338 | Paint(Self);
|
---|
339 | if I < (DockItems.Count - 1) then begin
|
---|
340 | if DockDirection = ddHorizontal then PanelHeader.Align := alLeft
|
---|
341 | else PanelHeader.Align := alTop;
|
---|
342 | end else PanelHeader.Align := alClient;
|
---|
343 | end;
|
---|
344 | end;
|
---|
345 |
|
---|
346 | procedure TCDManagerRegions.SetVisible(const AValue: Boolean);
|
---|
347 | var
|
---|
348 | I: Integer;
|
---|
349 | begin
|
---|
350 | inherited;
|
---|
351 | for I := 0 to DockItems.Count - 1 do
|
---|
352 | with TCDManagerRegionsItem(DockItems[I]) do begin
|
---|
353 | if AValue and (not Control.Visible) and (Control.Tag = Integer(dhtTemporal)) then begin
|
---|
354 | Control.Show;
|
---|
355 | Control.Tag := Integer(dhtPermanent);
|
---|
356 | end else
|
---|
357 | if not AValue then begin
|
---|
358 | Control.Tag := Integer(dhtTemporal);
|
---|
359 | Control.Hide;
|
---|
360 | end;
|
---|
361 | end;
|
---|
362 | //ClientAreaPanel.Show;
|
---|
363 | end;
|
---|
364 |
|
---|
365 | procedure TCDManagerRegions.ChangeVisible(Control: TWinControl;
|
---|
366 | Visible: Boolean);
|
---|
367 | begin
|
---|
368 | inherited;
|
---|
369 | end;
|
---|
370 |
|
---|
371 | end.
|
---|
372 |
|
---|