Changeset 47 for DockManager/Lazarus/UCustomDockManager.pas
- Timestamp:
- Sep 17, 2010, 12:55:46 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DockManager/Lazarus/UCustomDockManager.pas
r46 r47 7 7 uses 8 8 Classes, SysUtils, Controls, LCLType, LMessages, Graphics, StdCtrls, 9 Buttons, ExtCtrls, Contnrs, Forms ;9 Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs; 10 10 11 11 const … … 24 24 end; 25 25 26 TDockStyle = (dsList, dsTabs); 27 26 28 { TDockClientPanel } 27 29 28 30 TDockClientPanel = class(TPanel) 31 private 32 FShowHeader: Boolean; 33 procedure SetShowHeader(const AValue: Boolean); 34 public 29 35 OwnerDockManager: TCustomDockManager; 30 36 CloseButton: TSpeedButton; … … 40 46 procedure CloseButtonClick(Sender: TObject); 41 47 procedure ResizeExecute(Sender: TObject); 48 property ShowHeader: Boolean read FShowHeader write SetShowHeader; 42 49 end; 43 50 … … 46 53 TCustomDockManager = class(TDockManager) 47 54 private 55 FDockStyle: TDockStyle; 56 TabControl: TTabControl; 48 57 FDockDirection: TDockDirection; 49 58 FDockSite: TWinControl; … … 52 61 procedure InsertControlPanel(Control: TControl; InsertAt: TAlign; 53 62 DropCtl: TControl); 63 procedure SetDockStyle(const AValue: TDockStyle); 64 procedure UpdateClientSize; 65 procedure TabControlChange(Sender: TObject); 54 66 public 55 67 constructor Create(ADockSite: TWinControl); override; … … 74 86 procedure SetReplacingControl(Control: TControl); override; 75 87 function AutoFreeByControl: Boolean; override; 88 89 function CreateContainer: TConjoinDockForm; 90 property DockStyle: TDockStyle read FDockStyle write SetDockStyle; 76 91 end; 77 92 … … 96 111 FDockSite := ADockSite; 97 112 FDockPanels := TObjectList.Create; 113 TabControl := TTabControl.Create(FDockSite); 114 with TabControl do begin 115 Parent := FDockSite; 116 Visible := False; 117 Align := alTop; 118 Height := 24; 119 OnChange := TabControlChange; 120 end; 98 121 inherited Create(ADockSite); 99 122 end; … … 174 197 Parent := FDockSite; 175 198 OwnerDockManager := Self; 176 Visible := True;199 if DockStyle = dsList then Visible := True; 177 200 Align := alClient; 201 end; 202 203 if DockStyle = dsTabs then begin 204 TabControl.Tabs.Add(Control.Name); 205 TabControlChange(Self); 178 206 end; 179 207 NewPanel.Control := Control; … … 181 209 Control.Align := alClient; 182 210 FDockPanels.Add(NewPanel); 183 184 for I := 0 to FDockPanels.Count - 1 do begin 185 TDockClientPanel(FDockPanels[I]).Height := FDockSite.Height div 186 FDockSite.DockClientCount; 187 TDockClientPanel(FDockPanels[I]).Width := FDockSite.Width div 188 FDockSite.DockClientCount; 189 end; 211 UpdateClientSize; 190 212 end; 191 213 … … 198 220 I: Integer; 199 221 NewConjoinDockForm: TConjoinDockForm; 222 NewDockSite: TWinControl; 223 NewForm: TForm; 200 224 begin 201 225 if (FDockSite is TForm) then begin … … 205 229 NewConjoinDockForm.Visible := True; 206 230 NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect; 207 Control.ManualDock(NewConjoinDockForm.Panel);208 231 FDockSite.ManualDock(NewConjoinDockForm.Panel); 232 Control.ManualDock(NewConjoinDockForm.Panel, nil, InsertAt); 209 233 end else begin 210 Control.ManualDock(FDockSite.Parent); 234 NewConjoinDockForm := TConjoinDockForm.Create(nil); 235 NewConjoinDockForm.Visible := True; 236 NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect; 237 NewConjoinDockForm.DragMode := dmAutomatic; 238 NewConjoinDockForm.DragKind := dkDock; 239 NewDockSite := FDockSite.HostDockSite; 240 // FDockSite.ManualFloat(FDockSite.BoundsRect); 241 NewConjoinDockForm.ManualDock(NewDockSite); 242 FDockSite.ManualDock(NewConjoinDockForm.Panel); 243 Control.ManualDock(NewConjoinDockForm.Panel, nil, InsertAt); 211 244 end; 212 245 end else … … 282 315 if FDockSite.DockClientCount = 2 then FDockDirection := ddNone; 283 316 //FDockSite.Invalidate; 317 //if (FDockSite is TConjoinDockForm) and (FDockSite.DockClientCount = 1) then 318 // FDockSite.Free; 284 319 end; 285 320 end; … … 307 342 end; 308 343 344 function TCustomDockManager.CreateContainer: TConjoinDockForm; 345 var 346 NewDockSite: TWinControl; 347 NewConjoinDockForm: TConjoinDockForm; 348 begin 349 NewConjoinDockForm := TConjoinDockForm.Create(nil); 350 NewConjoinDockForm.Visible := True; 351 NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect; 352 NewConjoinDockForm.DragMode := dmAutomatic; 353 NewConjoinDockForm.DragKind := dkDock; 354 NewDockSite := FDockSite.HostDockSite; 355 // FDockSite.ManualFloat(FDockSite.BoundsRect); 356 NewConjoinDockForm.ManualDock(NewDockSite); 357 Result := NewConjoinDockForm; 358 end; 359 360 procedure TCustomDockManager.SetDockStyle(const AValue: TDockStyle); 361 var 362 I: Integer; 363 begin 364 FDockStyle := AValue; 365 if AValue = dsTabs then begin 366 TabControl.Visible := True; 367 TabControl.Tabs.Clear; 368 for I := 0 to FDockPanels.Count - 1 do begin 369 TabControl.Tabs.Add(TDockClientPanel(FDockPanels[I]).Control.Name); 370 TDockClientPanel(FDockPanels[I]).Splitter.Visible := False; 371 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False; 372 TDockClientPanel(FDockPanels[I]).Visible := False; 373 end; 374 TabControlChange(Self); 375 end else 376 if AValue = dsList then begin 377 TabControl.Visible := False; 378 TabControl.Tabs.Clear; 379 for I := 0 to FDockPanels.Count - 1 do begin 380 TDockClientPanel(FDockPanels[I]).Splitter.Visible := True; 381 TDockClientPanel(FDockPanels[I]).Visible := True; 382 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TDockClientPanel(FDockPanels[I]); 383 end; 384 end; 385 UpdateClientSize; 386 end; 387 388 procedure TCustomDockManager.UpdateClientSize; 389 var 390 I: Integer; 391 begin 392 if DockStyle = dsList then begin 393 for I := 0 to FDockPanels.Count - 1 do begin 394 TDockClientPanel(FDockPanels[I]).Height := FDockSite.Height div 395 FDockSite.DockClientCount; 396 TDockClientPanel(FDockPanels[I]).Width := FDockSite.Width div 397 FDockSite.DockClientCount; 398 //TDockClientPanel(FDockPanels[I]).DockPanelPaint(Self); 399 end; 400 end else 401 if DockStyle = dsTabs then begin 402 for I := 0 to FDockPanels.Count - 1 do begin 403 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Width := FDockSite.Width; 404 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Height := FDockSite.Height - TabControl.Height; 405 //TDockClientPanel(FDockPanels[I]).DockPanelPaint(Self); 406 end; 407 end; 408 end; 409 410 procedure TCustomDockManager.TabControlChange(Sender: TObject); 411 var 412 I: Integer; 413 begin 414 for I := 0 to FDockPanels.Count - 1 do begin 415 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False; 416 end; 417 if (TabControl.TabIndex <> -1) and (FDockPanels.Count > TabControl.TabIndex) then begin 418 TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel.Parent := FDockSite; 419 TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel.Visible := True; 420 // TDockClientPanel(FDockPanels[TabControl.TabIndex]).Visible := True; 421 end; 422 end; 423 309 424 { TDockClientPanel } 425 426 procedure TDockClientPanel.SetShowHeader(const AValue: Boolean); 427 begin 428 if FShowHeader=AValue then exit; 429 FShowHeader := AValue; 430 DockPanelPaint(Self); 431 end; 310 432 311 433 constructor TDockClientPanel.Create(TheOwner: TComponent); … … 319 441 Width := 14; 320 442 Height := 14; 321 Visible := True;443 Visible := False; 322 444 OnClick := CloseButtonClick; 323 445 end; … … 331 453 Top := GrabberSize; 332 454 Width := Self.Width; 333 Height := Self.Height ;455 Height := Self.Height - GrabberSize; 334 456 Anchors := [akTop, akBottom, akLeft, akRight]; 335 457 BevelInner := bvNone; 336 458 BevelOuter := bvNone; 459 //Color := clGreen; 337 460 end; 338 461 OnPaint := DockPanelPaint; … … 341 464 BevelInner := bvNone; 342 465 BevelOuter := bvNone; 466 ShowHeader := True; 343 467 end; 344 468 … … 386 510 R: TRect; 387 511 begin 388 R := Control.ClientRect; 389 Canvas.FillRect(R); 390 DrawGrabber(Canvas, Control); 512 if Assigned(Control) then begin 513 R := Control.ClientRect; 514 Canvas.FillRect(R); 515 CloseButton.Visible := ShowHeader; 516 if ShowHeader then begin 517 if ClientAreaPanel.DockClientCount = 0 then 518 DrawGrabber(Canvas, Control) else 519 DrawGrabber(Canvas, ClientAreaPanel); 520 end; 521 end; 391 522 end; 392 523 … … 394 525 Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 395 526 begin 396 if (Button=mbLeft) then begin 527 if Control is TForm then begin 528 TForm(Control).SetFocus; 529 DockPanelPaint(Self); 530 end; 531 if (Button = mbLeft) then begin 397 532 DragManager.DragStart(Control, False, 1); 398 533 end;
Note:
See TracChangeset
for help on using the changeset viewer.