Changeset 359 for Docking/CoolDocking/Managers/UCDManagerRegions.pas
- Timestamp:
- May 4, 2012, 12:27:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/Managers/UCDManagerRegions.pas
r355 r359 15 15 16 16 TCDManagerRegionsItem = class(TCDManagerItem) 17 private 18 public 17 19 PanelHeader: TCDPanelHeader; 18 20 Splitter: TSplitter; 19 Align: TAlign;20 21 procedure VisibleChange(Sender: TObject); override; 21 22 procedure Paint(Sender: TObject); override; 23 procedure PanelResize(Sender: TObject); 22 24 constructor Create; 23 25 destructor Destroy; override; 24 26 procedure SetControl(const AValue: TWinControl); override; 27 procedure SetCenter; 25 28 end; 26 29 … … 30 33 private 31 34 FDockItems: TObjectList; // TList<TCDManagerRegionsItem> 35 FLastVisibleItemsCount: Integer; 32 36 function GetHeaderPos: THeaderPos; override; 33 37 procedure SetHeaderPos(const AValue: THeaderPos); override; 34 38 function GetDirection(InsertAt: TAlign): TCDDirection; 39 procedure ResizePanels; 40 procedure ClearItemsAlignment; 41 procedure UpdateItemsAlignment; 42 function PanelsVisible: Integer; 43 protected 44 FDockDirection: TCDDirection; 35 45 public 36 FDockDirection: TCDDirection;37 46 //Panels: TObjectList; // TObjectList<TCDStyleRegionsPanel> 38 47 function FindControlInPanels(Control: TControl): TCDManagerItem; override; … … 59 68 { TCDManagerRegionsItem } 60 69 70 procedure TCDManagerRegionsItem.SetCenter; 71 begin 72 TCDManagerRegions(Manager).ClearItemsAlignment; 73 PanelHeader.Align := alClient; 74 Manager.Update; 75 end; 76 61 77 procedure TCDManagerRegionsItem.VisibleChange(Sender: TObject); 62 78 begin … … 66 82 // TCDManagerRegionsItem(DockItems[DockItems.IndexOf(FindControlInPanels(TControl(Sender)))]).HideType := dhtPermanent; 67 83 //end; 84 PanelHeader.Visible := Control.Visible; 68 85 Update; 69 86 … … 91 108 end; 92 109 110 procedure TCDManagerRegionsItem.PanelResize(Sender: TObject); 111 begin 112 TCDManagerRegions(Manager).ResizePanels; 113 end; 114 93 115 constructor TCDManagerRegionsItem.Create; 94 116 begin … … 97 119 PanelHeader.Header.OnMouseDown := DockPanelMouseDown; 98 120 PanelHeader.Header.Icon.OnMouseDown := DockPanelMouseDown; 121 PanelHeader.OnResize := PanelResize; 99 122 100 123 Splitter := TSplitter.Create(nil); … … 113 136 Splitter.Parent := nil; 114 137 Splitter.Free; 115 Control.Parent := nil;138 if Assigned(Control) then Control.Parent := nil; 116 139 inherited Destroy; 117 140 end; … … 153 176 end; 154 177 178 procedure TCDManagerRegions.ResizePanels; 179 var 180 I: Integer; 181 CenterPanelSize: TPoint; 182 Zoom: Real; 183 const 184 MinSize = 30; 185 begin 186 I := 0; 187 while (I < DockItems.Count) and 188 (TCDManagerRegionsItem(DockItems[I]).PanelHeader.Align <> alClient) do 189 Inc(I); 190 if I < DockItems.Count then begin 191 CenterPanelSize.X := TCDManagerRegionsItem(DockItems[I]).PanelHeader.Width; 192 CenterPanelSize.Y := TCDManagerRegionsItem(DockItems[I]).PanelHeader.Height; 193 end else Exit; 194 if (CenterPanelSize.X < MinSize) and (FDockDirection = ddHorizontal) then begin 195 Zoom := CenterPanelSize.X / MinSize; 196 for I := 0 to DockItems.Count - 1 do 197 with TCDManagerRegionsItem(DockItems[I]).PanelHeader do 198 if Align <> alClient then Width := Round(Width * Zoom); 199 end; 200 if (CenterPanelSize.Y < MinSize) and (FDockDirection = ddVertical) then begin 201 Zoom := CenterPanelSize.Y / MinSize; 202 for I := 0 to DockItems.Count - 1 do 203 with TCDManagerRegionsItem(DockItems[I]).PanelHeader do 204 if Align <> alClient then Height := Round(Height * Zoom); 205 end; 206 end; 207 208 procedure TCDManagerRegions.ClearItemsAlignment; 209 var 210 I: Integer; 211 begin 212 for I := 0 to FDockItems.Count - 1 do 213 with TCDManagerRegionsItem(FDockItems[I]) do begin 214 PanelHeader.Align := alNone; 215 Splitter.Align := alNone; 216 end; 217 end; 218 219 procedure TCDManagerRegions.UpdateItemsAlignment; 220 var 221 I: Integer; 222 ClientPanelIndex: Integer; 223 begin 224 // Find alClient panel item index 225 I := 0; 226 while (I < FDockItems.Count) and 227 (TCDManagerRegionsItem(FDockItems[I]).PanelHeader.Align <> alClient) do Inc(I); 228 if I < FDockItems.Count then ClientPanelIndex := I 229 else ClientPanelIndex := FDockItems.Count div 2; 230 231 // Normalize alignment 232 for I := 0 to FDockItems.Count - 1 do 233 with TCDManagerRegionsItem(FDockItems[I]) do begin 234 if FDockDirection = ddHorizontal then begin 235 if I < ClientPanelIndex then PanelHeader.Align := alLeft 236 else if I = ClientPanelIndex then PanelHeader.Align := alClient 237 else if I > ClientPanelIndex then PanelHeader.Align := alRight; 238 end; 239 if FDockDirection = ddVertical then begin 240 if I < ClientPanelIndex then PanelHeader.Align := alTop 241 else if I = ClientPanelIndex then PanelHeader.Align := alClient 242 else if I > ClientPanelIndex then PanelHeader.Align := alBottom; 243 end; 244 end; 245 end; 246 247 function TCDManagerRegions.PanelsVisible: Integer; 248 var 249 I: Integer; 250 begin 251 Result := 0; 252 for I := 0 to FDockItems.Count - 1 do 253 with TCDManagerRegionsItem(FDockItems[I]) do begin 254 if PanelHeader.Visible then Inc(Result); 255 end; 256 end; 257 155 258 function TCDManagerRegions.FindControlInPanels(Control: TControl 156 259 ): TCDManagerItem; … … 172 275 NewItem := TCDManagerRegionsItem.Create; 173 276 with NewItem do begin 277 PanelHeader.DockItem := NewItem; 174 278 PanelHeader.Parent := Self.DockSite; 175 279 Manager := Self; … … 184 288 185 289 NewItem.PanelHeader.Parent := DockSite; 186 187 if DockItems.Count = 0 then NewItem.Align := alClient188 else NewItem.Align := InsertAt;189 290 190 291 NewItem.Control := TWinControl(Control); … … 302 403 var 303 404 I: Integer; 304 SplitterLeft: Integer; 305 SplitterTop: Integer; 306 BaseAlign: TAlign; 405 PositionLeft: Integer; 406 PositionTop: Integer; 307 407 VisibleControlsCount: Integer; 408 const 409 MinSize = 30; 308 410 begin 309 411 inherited; 310 412 if FUpdateCount = 0 then begin 311 413 DebugLog('TCDManagerRegions.UpdateClientSize'); 312 VisibleControlsCount := DockSite.VisibleDockClientCount;414 VisibleControlsCount := PanelsVisible; 313 415 if DockSite is TForm then begin 314 DockSiteVisible := VisibleControlsCount > 0;416 //DockSiteVisible := VisibleControlsCount > 0; 315 417 end; 316 418 if VisibleControlsCount = 0 then VisibleControlsCount := 1; 317 419 420 PositionLeft := 0; 421 PositionTop := 0; 422 UpdateItemsAlignment; 318 423 for I := 0 to DockItems.Count - 1 do 319 424 with TCDManagerRegionsItem(DockItems[I]) do 320 425 begin 321 PanelHeader.Left := SplitterLeft; 322 PanelHeader.Top := SplitterTop; 323 PanelHeader.Height := Self.DockSite.Height div 324 VisibleControlsCount; 325 PanelHeader.Width := Self.DockSite.Width div 326 VisibleControlsCount; 426 PanelHeader.Left := PositionLeft; 427 PanelHeader.Top := PositionTop; 428 if (FLastVisibleItemsCount <> VisibleControlsCount) then begin 429 PanelHeader.Height := Self.DockSite.Height div 430 VisibleControlsCount; 431 PanelHeader.Width := Self.DockSite.Width div 432 VisibleControlsCount; 433 end; 434 if PanelHeader.Height < MinSize then PanelHeader.Height := MinSize; 435 if PanelHeader.Width < MinSize then PanelHeader.Width := MinSize; 436 327 437 if Assigned(TWinControl(Control).DockManager) then 328 438 PanelHeader.Header.Visible := TCDManager(TWinControl(Control).DockManager).HeaderVisible; 329 439 PanelHeader.Visible := Control.Visible; 330 440 Paint(Self); 331 if FDockDirection = ddHorizontal then 332 BaseAlign := alLeft else BaseAlign := alTop; 333 334 if I < Trunc((DockItems.Count - 1) / 2) then BaseAlign := BaseAlign 335 else if I = Trunc((DockItems.Count - 1) / 2) then BaseAlign := alClient 336 else if I > Trunc((DockItems.Count - 1) / 2) then begin 337 if BaseAlign = alTop then BaseAlign := alBottom 338 else if BaseAlign = alLeft then BaseAlign := alRight; 339 end; 340 PanelHeader.Align := BaseAlign; 341 342 Splitter.Align := BaseAlign; 343 SplitterLeft := PanelHeader.Left; 344 SplitterTop := PanelHeader.Top; 345 Splitter.Left := SplitterLeft; 346 Splitter.Top := SplitterTop; 441 442 //PositionLeft := PanelHeader.Left; 443 //PositionTop := PanelHeader.Top; 444 if PanelHeader.Align = alLeft then Splitter.Left := PositionLeft + PanelHeader.Width + 1; 445 if PanelHeader.Align = alRight then Splitter.Left := PositionLeft - 1; 446 if PanelHeader.Align = alTop then Splitter.Top := PositionTop + PanelHeader.Height + 1; 447 if PanelHeader.Align = alBottom then Splitter.Top := PositionTop - 1; 448 Splitter.Align := PanelHeader.Align; 347 449 Splitter.Parent := Self.DockSite; 348 Splitter.Visible := I <> (Trunc(DockItems.Count - 1) / 2); 349 Inc(SplitterLeft, Splitter.Width); 350 Inc(SplitterTop, Splitter.Height); 450 Splitter.Visible := PanelHeader.Visible and (PanelHeader.Align <> alClient); 451 Splitter.Width := 3; 452 Splitter.Height := 3; 453 Inc(PositionLeft, Splitter.Width + PanelHeader.Width); 454 Inc(PositionTop, Splitter.Height + PanelHeader.Height); 351 455 352 456 Paint(Self); 353 PanelHeader.Align := BaseAlign; 354 end; 457 //PanelHeader.Align := BaseAlign; 458 end; 459 FLastVisibleItemsCount := VisibleControlsCount; 355 460 end; 356 461 end; … … 362 467 inherited; 363 468 //if DockSite.Visible <> AValue then 469 if DockItems.Count > 0 then 364 470 try 365 471 BeginUpdate;
Note:
See TracChangeset
for help on using the changeset viewer.