Changeset 194 for Docking/CoolDocking/UCDManager.pas
- Timestamp:
- Mar 11, 2011, 1:00:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/UCDManager.pas
r193 r194 1 1 unit UCDManager; 2 2 3 {$mode objfpc}{$H+}3 {$mode Delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, UCDCommon, Controls, Contnrs, UCDClientPanel,9 UCDPopupMenu, LCLType, LMessages, Graphics, 8 Classes, SysUtils, UCDCommon, Controls, Contnrs, 9 UCDPopupMenu, LCLType, LMessages, Graphics, Buttons, 10 10 UCDConjoinForm, Menus, StdCtrls, ExtCtrls, Forms; 11 11 12 const 13 GrabberSize = 22; 14 12 15 type 13 { TCoolDockPanels } 14 15 // TCoolDockPanels = TObjectList<TCDClientPanel> 16 TCDPanels = class(TObjectList) 16 THeaderPos = (hpAuto, hpLeft, hpTop, hpRight, hpBottom); 17 18 TCDManager = class; 19 TCDManagerItem = class; 20 21 TCDHeader = class(TPanel) 22 private 23 procedure CloseButtonClick(Sender: TObject); 24 procedure DrawGrabber(Canvas: TCanvas; AControl: TControl); 25 public 26 CloseButton: TSpeedButton; 27 Title: TLabel; 28 Icon: TImage; 29 ManagerItem: TCDManagerItem; 30 Shape: TShape; 31 constructor Create(TheOwner: TComponent); override; 17 32 destructor Destroy; override; 33 end; 34 35 { TCDManagerItem } 36 37 TCDManagerItem = class 38 private 39 FHeaderPos: THeaderPos; 40 FShowHeader: Boolean; 41 procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton; 42 Shift: TShiftState; X, Y: Integer); 43 procedure ResizeExecute(Sender: TObject); 44 procedure SetHeaderPos(const AValue: THeaderPos); 45 public 46 Header: TCDHeader; 47 Control: TControl; 48 Manager: TCDManager; 49 procedure Paint(Sender: TObject); virtual; 50 procedure VisibleChange(Sender: TObject); virtual; 51 constructor Create; 52 destructor Destroy; override; 53 property ShowHeader: Boolean read FShowHeader write FShowHeader; 54 property HeaderPos: THeaderPos read FHeaderPos write SetHeaderPos; 18 55 end; 19 56 … … 23 60 private 24 61 FDockSite: TWinControl; 25 FDockPanels: TCDPanels;26 62 function GetDockSite: TWinControl; 27 63 function GetHeaderPos: THeaderPos; … … 65 101 function AutoFreeByControl: Boolean; override; 66 102 67 function FindControlInPanels(Control: TControl): TCD ClientPanel;103 function FindControlInPanels(Control: TControl): TCDManagerItem; virtual; 68 104 function CreateContainer(InsertAt: TAlign): TCDConjoinForm; 69 property DockPanels: TCDPanels read FDockPanels write FDockPanels;70 105 property DockStyle: TCDStyleType read FDockStyle write SetDockStyle; 71 106 property MoveDuration: Integer read GetMoveDuration write SetMoveDuration; … … 81 116 UCDManagerRegions, UCDManagerTabs, UCDManagerRegionsPopup, UCDManagerTabsPopup; 82 117 118 { TCDManagerItem } 119 120 procedure TCDManagerItem.SetHeaderPos(const AValue: THeaderPos); 121 begin 122 if FHeaderPos=AValue then exit; 123 FHeaderPos:=AValue; 124 Paint(Self); 125 end; 126 127 procedure TCDManagerItem.Paint(Sender: TObject); 128 var 129 I: Integer; 130 R: TRect; 131 begin 132 (* if not (csDesigning in ComponentState) then 133 if Assigned(Control) then begin 134 R := Control.ClientRect; 135 Canvas.FillRect(R); 136 Header.Visible := ShowHeader; 137 if ShowHeader then begin 138 if ClientAreaPanel.DockClientCount = 0 then 139 Header.DrawGrabber(Canvas, Control) else 140 Header.DrawGrabber(Canvas, ClientAreaPanel); 141 end; 142 end;*) 143 end; 144 145 constructor TCDManagerItem.Create; 146 begin 147 //Paint.OnPaint := Paint; 148 Header.Shape.OnMouseDown := DockPanelMouseDown; 149 Header.Title.OnMouseDown := DockPanelMouseDown; 150 //OnResize := ResizeExecute; 151 //BevelInner := bvNone; 152 //BevelOuter := bvNone; 153 HeaderPos := hpTop; 154 155 ShowHeader := True; 156 Header := TCDHeader.Create(nil); 157 with Header do begin 158 Parent := nil; 159 Visible := ShowHeader; 160 Align := alTop; 161 Height := GrabberSize; 162 ManagerItem := Self; 163 end; 164 end; 165 166 procedure TCDManagerItem.ResizeExecute(Sender: TObject); 167 begin 168 (* if Assigned(Control) then begin 169 Control.Top := GrabberSize; 170 Control.Left := 0; 171 Control.Width := Width; 172 Control.Height := Height - GrabberSize; 173 //Control.SetBounds(0, GrabberSize, Width - Control.Left, 174 // Height - Control.Top); 175 end;*) 176 end; 177 178 procedure TCDManagerItem.DockPanelMouseDown(Sender: TObject; 179 Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 180 begin 181 if Control is TForm then begin 182 //TForm(Control).SetFocus; 183 Paint(Self); 184 end; 185 if (Button = mbLeft) then begin 186 //(Control as TWinControl).DockSite := False; 187 //ClientAreaPanel.DockSite := False; 188 //(Control as TWinControl).BeginDrag(False, 10); 189 //DragManager.DragStart(Control, False, 1); 190 end; 191 end; 192 193 destructor TCDManagerItem.Destroy; 194 begin 195 if Assigned(Control) then 196 Control.RemoveHandlerOnVisibleChanged(VisibleChange); 197 inherited Destroy; 198 end; 199 200 procedure TCDManagerItem.VisibleChange(Sender: TObject); 201 var 202 ControlVisible: Boolean; 203 Temp: TControl; 204 Temp2: TControl; 205 begin 206 { Temp := TControl(Sender); 207 if Assigned(Control) then 208 begin 209 ControlVisible := TControl(Sender).Visible; 210 (*if Assigned(ClientAreaPanel) then 211 ClientAreaPanel.Visible := ControlVisible; 212 if Assigned(Splitter) then 213 Splitter.Visible := ControlVisible; 214 *) 215 // if Assigned(TCDManager(OwnerDockManager).DockStyleHandler) then 216 if Assigned(Manager) then 217 with TCDManager(Manager) do 218 begin 219 //UpdateClientSize; 220 if ControlVisible then 221 Switch(DockItems.IndexOf(FindControlInPanels(TControl(Sender)))); 222 if not (Control is TWinControl) then raise Exception.Create('Not TWinControl'); 223 if not Assigned(Control) then raise Exception.Create('Control not assigned'); 224 ChangeVisible(TWinControl(Control), ControlVisible); 225 // Show parent control 226 Temp := TControl(Sender).HostDockSite; 227 228 if ControlVisible then 229 TControl(Sender).HostDockSite.Visible := ControlVisible; 230 end; 231 if csDestroying in Control.ComponentState then Control := nil; 232 end;} 233 end; 234 83 235 { TCDManager } 84 236 85 237 function TCDManager.FindControlInPanels(Control: TControl 86 ): TCDClientPanel; 87 var 88 I: Integer; 89 begin 90 I := 0; 91 while (I < FDockPanels.Count) and 92 (TCDClientPanel(FDockPanels[I]).Control <> Control) do Inc(I); 93 if I < FDockPanels.Count then Result := TCDClientPanel(FDockPanels[I]) 94 else Result := nil; 238 ): TCDManagerItem; 239 begin 240 Result := nil; 95 241 end; 96 242 … … 118 264 119 265 FDockSite := ADockSite; 120 FDockPanels := TCDPanels.Create;121 266 122 267 FDockStyle := dsList; // dsNone … … 128 273 begin 129 274 PopupMenu.Free; 130 FDockPanels.Free;131 275 inherited Destroy; 132 276 end; … … 171 315 var 172 316 NewSplitter: TSplitter; 173 NewDockPanel: TCD ClientPanel;317 NewDockPanel: TCDManagerItem; 174 318 NewPanel: TPanel; 175 319 I: Integer; … … 193 337 end; 194 338 end else 195 if (FDockSite is TCDConjoinForm) or (FDockSite is TPanel) or (FDockSite is TCDClientPanel)then begin339 if (FDockSite is TCDConjoinForm) or (FDockSite is TPanel) then begin 196 340 InsertControlPanel(Control, InsertAt, DropCtl); 197 341 end; … … 206 350 207 351 procedure TCDManager.PaintSite(DC: HDC); 208 var 209 Canvas: TControlCanvas; 210 Control: TControl; 211 I: Integer; 212 R: TRect; 213 begin 214 for I := 0 to FDockPanels.Count - 1 do 215 with TCDClientPanel(FDockPanels[I]) do begin 216 Invalidate; 217 end; 352 begin 218 353 end; 219 354 … … 254 389 255 390 procedure TCDManager.RemoveControl(Control: TControl); 256 var257 ClientPanel: TCDClientPanel;391 //var 392 // ClientPanel: TCDClientPanel; 258 393 begin 259 394 //DockStyleHandler.RemoveControl(Control); … … 322 457 if AValue = dsTabs then begin 323 458 NewManager := TCDManagerTabs.Create(FDockSite); 324 TCDManagerTabs(Self).TabControlChange(Self);459 //TCDManagerTabs(Self).TabControlChange(Self); 325 460 end else 326 461 if AValue = dsList then begin … … 328 463 end else 329 464 if AValue = dsPopupList then begin 330 NewManager := TCD StylePopupRegions.Create(FDockSite);465 NewManager := TCDManagerPopupRegions.Create(FDockSite); 331 466 end else 332 467 if AValue = dsPopupTabs then begin … … 336 471 NewManager.Assign(TCDManager(DockSite.DockManager)); 337 472 DockSite.DockManager := NewManager; 338 end;339 UpdateClientSize;473 NewManager.UpdateClientSize; 474 end; 340 475 end; 341 476 … … 379 514 end; 380 515 381 { TCDPanels } 382 383 destructor TCDPanels.Destroy; 384 var 385 Temp: Integer; 386 begin 387 Temp := Count; 516 { TCDHeader } 517 518 constructor TCDHeader.Create(TheOwner: TComponent); 519 begin 520 inherited Create(TheOwner); 521 Shape := TShape.Create(Self); 522 with Shape do begin 523 Parent := Self; 524 Anchors := [akRight, akBottom, akLeft, akTop]; 525 Left := 1; 526 Top := 1; 527 Width := Self.Width - 2; 528 Height := Self.Height - 2; 529 Brush.Style := bsClear; 530 end; 531 Title := TLabel.Create(Self); 532 with Title do begin 533 Parent := Self; 534 Visible := True; 535 Top := 4; 536 Left := 6; 537 BevelInner := bvNone; 538 BevelOuter := bvNone; 539 end; 540 CloseButton := TSpeedButton.Create(Self); 541 with CloseButton do begin 542 Parent := Self; 543 Caption := 'X'; 544 Font.Size := 6; 545 Width := GrabberSize - 8; 546 Height := GrabberSize - 8; 547 Anchors := [akRight, akTop]; 548 Left := Self.Width - Width - 4; 549 Top := 4; 550 Visible := True; 551 OnClick := CloseButtonClick; 552 end; 553 Icon := TImage.Create(Self); 554 with Icon do begin 555 Parent := Self; 556 Left := 4; 557 Top := 2; 558 Visible := True; 559 end; 560 end; 561 562 destructor TCDHeader.Destroy; 563 begin 388 564 inherited Destroy; 389 565 end; 390 566 567 procedure TCDHeader.DrawGrabber(Canvas: TCanvas; AControl: TControl); 568 begin 569 with Canvas do begin 570 Brush.Color := clBtnFace; 571 Pen.Color := clBlack; 572 //FillRect(0, 0, AControl.Width, GrabberSize); 573 574 if (AControl as TWinControl).Focused then 575 Title.Font.Style := Font.Style + [fsBold] 576 else Title.Font.Style := Font.Style - [fsBold]; 577 Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1); 578 if Icon.Picture.Width > 0 then Title.Left := 8 + Icon.Picture.Width 579 else Title.Left := 6; 580 Title.Caption := AControl.Caption; 581 end; 582 end; 583 584 procedure TCDHeader.CloseButtonClick(Sender: TObject); 585 begin 586 ManagerItem.Control.Hide; 587 end; 588 391 589 392 590
Note:
See TracChangeset
for help on using the changeset viewer.