source: trunk/Packages/CoolDocking/Managers/UCDManagerRegions.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: 11.1 KB
Line 
1unit UCDManagerRegions;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Controls, ExtCtrls, StdCtrls, Forms,
9 Graphics, Contnrs, Buttons, UCDCommon, UCDManager,
10 LCLType, LMessages;
11
12type
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
53implementation
54
55uses
56 UCDClient, UCDConjoinForm;
57
58{ TCDManagerRegionsItem }
59
60procedure TCDManagerRegionsItem.VisibleChange(Sender: TObject);
61begin
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;
69end;
70
71procedure TCDManagerRegionsItem.Paint(Sender: TObject);
72var
73 I: Integer;
74 R: TRect;
75begin
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;
86end;
87
88constructor TCDManagerRegionsItem.Create;
89begin
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;
102end;
103
104destructor TCDManagerRegionsItem.Destroy;
105begin
106 PanelHeader.Parent := nil;
107 PanelHeader.Free;
108 Splitter.Parent := nil;
109 Splitter.Free;
110 Control.Parent := nil;
111 inherited Destroy;
112end;
113
114procedure TCDManagerRegionsItem.SetControl(const AValue: TWinControl);
115begin
116 inherited SetControl(AValue);
117 PanelHeader.Header.Control := AValue;
118end;
119
120
121{ TCDManagerRegions }
122
123function TCDManagerRegions.GetHeaderPos: THeaderPos;
124begin
125 Result := inherited;
126end;
127
128procedure TCDManagerRegions.SetHeaderPos(const AValue: THeaderPos);
129begin
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;*)
137end;
138
139function TCDManagerRegions.GetDirection(InsertAt: TAlign): TCDDirection;
140begin
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;
148end;
149
150function TCDManagerRegions.FindControlInPanels(Control: TControl
151 ): TCDManagerItem;
152var
153 I: Integer;
154begin
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;
160end;
161
162procedure TCDManagerRegions.InsertControlNoUpdate(Control: TControl;
163 InsertAt: TAlign);
164var
165 NewItem: TCDManagerRegionsItem;
166begin
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);
190end;
191
192procedure TCDManagerRegions.InsertControlPanel(Control: TControl; InsertAt: TAlign;
193 DropCtl: TControl);
194var
195 NewItem: TCDManagerRegionsItem;
196 I: Integer;
197 NewDirection: TCDDirection;
198 NewConjoinDockForm: TCDConjoinForm;
199 NewDockSite: TWinControl;
200begin
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;
228end;
229
230procedure TCDManagerRegions.RemoveControl(Control: TControl);
231var
232 ManagerItem: TCDManagerItem;
233 ClientCount: Integer;
234begin
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;
260end;
261
262constructor TCDManagerRegions.Create(ADockSite: TWinControl);
263var
264 I: Integer;
265 NewItem: TCDManagerRegionsItem;
266begin
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;
274end;
275
276destructor TCDManagerRegions.Destroy;
277begin
278 FDockItems.Free;
279 inherited Destroy;
280end;
281
282procedure TCDManagerRegions.PaintSite(DC: HDC);
283var
284 I: Integer;
285begin
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;
291end;
292
293procedure TCDManagerRegions.UpdateClientSize;
294var
295 I: Integer;
296 SplitterLeft: Integer;
297 SplitterTop: Integer;
298 BaseAlign: TAlign;
299 VisibleControlsCount: Integer;
300begin
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;
344end;
345
346procedure TCDManagerRegions.SetVisible(const AValue: Boolean);
347var
348 I: Integer;
349begin
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;
363end;
364
365procedure TCDManagerRegions.ChangeVisible(Control: TWinControl;
366 Visible: Boolean);
367begin
368 inherited;
369end;
370
371end.
372
Note: See TracBrowser for help on using the repository browser.