Changeset 48 for DockManager/Lazarus/UCustomDockManager.pas
- Timestamp:
- Sep 17, 2010, 3:34:31 PM (14 years ago)
- Location:
- DockManager/Lazarus
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DockManager/Lazarus
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
DockManager/Lazarus/UCustomDockManager.pas
r47 r48 2 2 3 3 {$mode delphi}{$H+} 4 5 // Date: 2010-09-17 4 6 5 7 interface … … 7 9 uses 8 10 Classes, SysUtils, Controls, LCLType, LMessages, Graphics, StdCtrls, 9 Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs ;11 Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs, Menus, FileUtil; 10 12 11 13 const 12 GrabberSize = 18;14 GrabberSize = 22; 13 15 14 16 type 15 17 TDockDirection = (ddNone, ddHorizontal, ddVertical); 18 THeaderPos = (hpAuto, hpLeft, hpTop, hpRight, hpBottom); 16 19 17 20 TCustomDockManager = class; … … 53 56 TCustomDockManager = class(TDockManager) 54 57 private 58 PopupMenu1: TPopupMenu; 55 59 FDockStyle: TDockStyle; 56 60 TabControl: TTabControl; … … 64 68 procedure UpdateClientSize; 65 69 procedure TabControlChange(Sender: TObject); 70 procedure PopupMenuListClick(Sender: TObject); 71 procedure PopupMenuTabsClick(Sender: TObject); 66 72 public 67 73 constructor Create(ADockSite: TWinControl); override; … … 87 93 function AutoFreeByControl: Boolean; override; 88 94 89 function CreateContainer : TConjoinDockForm;95 function CreateContainer(InsertAt: TAlign): TConjoinDockForm; 90 96 property DockStyle: TDockStyle read FDockStyle write SetDockStyle; 91 97 end; 92 98 99 { TCustomDockMaster } 100 101 TCustomDockMaster = class(TComponent) 102 private 103 FDefaultHeaderPos: THeaderPos; 104 FTabsEnabled: Boolean; 105 procedure SetTabsEnabled(const AValue: Boolean); 106 public 107 procedure SaveLayoutToStream(Stream: TStream); 108 procedure LoadLayoutFromStream(Stream: TStream); 109 procedure SaveLayoutToFile(FileName: string); 110 procedure LoadLayoutFromFile(FileName: string); 111 published 112 property TabsEnabled: Boolean read FTabsEnabled write SetTabsEnabled; 113 property DefaultHeaderPos: THeaderPos read FDefaultHeaderPos 114 write FDefaultHeaderPos; 115 end; 116 117 procedure Register; 118 93 119 implementation 120 121 procedure Register; 122 begin 123 RegisterComponents('CustomDocking', [TCustomDockMaster]); 124 end; 125 94 126 95 127 { TCustomDockManager } … … 108 140 109 141 constructor TCustomDockManager.Create(ADockSite: TWinControl); 110 begin 142 var 143 NewMenuItem: TMenuItem; 144 begin 145 inherited Create(ADockSite); 111 146 FDockSite := ADockSite; 112 147 FDockPanels := TObjectList.Create; 148 PopupMenu1 := TPopupMenu.Create(FDockSite); 149 NewMenuItem := TMenuItem.Create(PopupMenu1); 150 NewMenuItem.Caption := 'List'; 151 PopupMenu1.Items.Add(NewMenuItem); 152 NewMenuItem.OnClick := PopupMenuListClick; 153 NewMenuItem := TMenuItem.Create(PopupMenu1); 154 NewMenuItem.Caption := 'Tabs'; 155 NewMenuItem.OnClick := PopupMenuTabsClick; 156 PopupMenu1.Items.Add(NewMenuItem); 113 157 TabControl := TTabControl.Create(FDockSite); 114 158 with TabControl do begin … … 118 162 Height := 24; 119 163 OnChange := TabControlChange; 120 end;121 inherited Create(ADockSite);164 PopupMenu := PopupMenu1; 165 end; 122 166 end; 123 167 … … 156 200 DropCtl: TControl); 157 201 var 158 NewSplitter: TSplitter;159 202 NewPanel: TDockClientPanel; 160 203 I: Integer; … … 171 214 //end; 172 215 if FDockSite.DockClientCount > 1 then begin 173 NewSplitter := TSplitter.Create(nil); 174 NewSplitter.Parent := FDockSite; 175 NewSplitter.Visible := True; 176 NewSplitter.Color := clRed; 177 with NewSplitter do 178 if FDockDirection = ddVertical then begin 179 Align := alTop; 180 Top := FDockSite.Height; 181 end else 182 if FDockDirection = ddHorizontal then begin 183 Align := alLeft; 184 Left := FDockSite.Width; 216 with TDockClientPanel(FDockPanels.Last).Splitter do begin 217 Parent := FDockSite; 218 Visible := True; 219 if FDockDirection = ddVertical then begin 220 Align := alTop; 221 Top := FDockSite.Height; 222 end else 223 if FDockDirection = ddHorizontal then begin 224 Align := alLeft; 225 Left := FDockSite.Width; 226 end; 185 227 end; 186 228 … … 194 236 NewPanel := TDockClientPanel.Create(nil); 195 237 with NewPanel do begin 196 Splitter := NewSplitter;197 238 Parent := FDockSite; 198 239 OwnerDockManager := Self; 199 240 if DockStyle = dsList then Visible := True; 200 241 Align := alClient; 242 PopupMenu := PopupMenu1; 201 243 end; 202 244 203 245 if DockStyle = dsTabs then begin 204 TabControl.Tabs.Add(Control. Name);246 TabControl.Tabs.Add(Control.Caption); 205 247 TabControlChange(Self); 206 248 end; … … 342 384 end; 343 385 344 function TCustomDockManager.CreateContainer : TConjoinDockForm;386 function TCustomDockManager.CreateContainer(InsertAt: TAlign): TConjoinDockForm; 345 387 var 346 388 NewDockSite: TWinControl; … … 354 396 NewDockSite := FDockSite.HostDockSite; 355 397 // FDockSite.ManualFloat(FDockSite.BoundsRect); 356 NewConjoinDockForm.ManualDock(NewDockSite );398 NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt); 357 399 Result := NewConjoinDockForm; 358 400 end; … … 367 409 TabControl.Tabs.Clear; 368 410 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; 411 TabControl.Tabs.Add(TDockClientPanel(FDockPanels[I]).Control.Caption); 412 if Assigned(TDockClientPanel(FDockPanels[I]).Splitter) then 413 TDockClientPanel(FDockPanels[I]).Splitter.Visible := False; 371 414 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False; 372 415 TDockClientPanel(FDockPanels[I]).Visible := False; … … 378 421 TabControl.Tabs.Clear; 379 422 for I := 0 to FDockPanels.Count - 1 do begin 380 TDockClientPanel(FDockPanels[I]).Splitter.Visible := True; 423 if Assigned(TDockClientPanel(FDockPanels[I]).Splitter) then 424 TDockClientPanel(FDockPanels[I]).Splitter.Visible := True; 381 425 TDockClientPanel(FDockPanels[I]).Visible := True; 382 426 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TDockClientPanel(FDockPanels[I]); 427 TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := True; 383 428 end; 384 429 end; … … 416 461 end; 417 462 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; 463 with TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel do begin 464 Parent := FDockSite; 465 Visible := True; 466 UpdateClientSize; 467 end; 420 468 // TDockClientPanel(FDockPanels[TabControl.TabIndex]).Visible := True; 421 469 end; 470 end; 471 472 procedure TCustomDockManager.PopupMenuTabsClick(Sender: TObject); 473 begin 474 DockStyle := dsTabs; 475 end; 476 477 procedure TCustomDockManager.PopupMenuListClick(Sender: TObject); 478 begin 479 DockStyle := dsList; 422 480 end; 423 481 … … 439 497 Caption := 'X'; 440 498 Font.Size := 6; 441 Width := 14;442 Height := 14;499 Width := GrabberSize - 4; 500 Height := GrabberSize - 4; 443 501 Visible := False; 444 502 OnClick := CloseButtonClick; … … 459 517 //Color := clGreen; 460 518 end; 519 Splitter := TSplitter.Create(Self); 520 with Splitter do begin 521 //Color := clRed; 522 end; 461 523 OnPaint := DockPanelPaint; 462 524 OnMouseDown := DockPanelMouseDown; … … 483 545 else Font.Style := Font.Style - [fsBold]; 484 546 Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1); 485 TextOut(6, 2, AControl.Caption);547 TextOut(6, 4, AControl.Caption); 486 548 487 549 CloseButton.Left := AControl.Width - CloseButton.Width - 2; … … 526 588 begin 527 589 if Control is TForm then begin 528 TForm(Control).SetFocus;590 //TForm(Control).SetFocus; 529 591 DockPanelPaint(Self); 530 592 end; … … 545 607 UseDockManager := True; 546 608 Align := alClient; 609 // Color := clYellow; 547 610 end; 548 611 DragKind := dkDock; … … 550 613 end; 551 614 615 { TCustomDockMaster } 616 617 procedure TCustomDockMaster.SetTabsEnabled(const AValue: Boolean); 618 begin 619 if FTabsEnabled=AValue then exit; 620 FTabsEnabled:=AValue; 621 end; 622 623 procedure TCustomDockMaster.SaveLayoutToStream(Stream: TStream); 624 begin 625 626 end; 627 628 procedure TCustomDockMaster.LoadLayoutFromStream(Stream: TStream); 629 begin 630 631 end; 632 633 procedure TCustomDockMaster.SaveLayoutToFile(FileName: string); 634 var 635 LayoutFile: TFileStream; 636 begin 637 if FileExistsUTF8(FileName) then 638 LayoutFile := TFileStream.Create(FileName, fmOpenReadWrite) 639 else LayoutFile := TFileStream.Create(FileName, fmCreate); 640 try 641 SaveLayoutToStream(LayoutFile); 642 finally 643 Free; 644 end; 645 end; 646 647 procedure TCustomDockMaster.LoadLayoutFromFile(FileName: string); 648 var 649 LayoutFile: TFileStream; 650 begin 651 LayoutFile := TFileStream.Create(FileName, fmOpenRead); 652 try 653 LoadLayoutFromStream(LayoutFile); 654 finally 655 Free; 656 end; 657 end; 658 552 659 initialization 553 660 DefaultDockManagerClass := TCustomDockManager;
Note:
See TracChangeset
for help on using the changeset viewer.