Changeset 187 for Docking/CoolDocking/UCoolDocking.pas
- Timestamp:
- Mar 11, 2011, 8:41:52 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/UCoolDocking.pas
r186 r187 13 13 DateUtils, UCoolDockStyleTabs, UCoolDockStyleRegions, UCoolDockStylePopupTabs, 14 14 UCoolDockStylePopupRegions, UCoolDockStyle, UCoolDockClientPanel, 15 UCoolDockPopupMenu ;15 UCoolDockPopupMenu, UCoolDockManager; 16 16 17 17 const … … 19 19 20 20 type 21 TCoolDockManager = class;22 21 TCoolDockClient = class; 23 22 TCoolDockMaster = class; 24 25 { TCoolDockConjoinForm }26 27 TCoolDockConjoinForm = class(TCoolDockConjoinFormBase)28 public29 CoolDockClient: TCoolDockClient;30 procedure FormShow(Sender : TObject);31 procedure FormHide(Sender : TObject);32 constructor Create(TheOwner: TComponent); override;33 destructor Destroy; override;34 private35 procedure SetName(const NewName: TComponentName); override;36 end;37 38 39 { TCoolDockPanels }40 41 // TCoolDockPanels = TObjectList<TCoolDockClientPanel>42 TCoolDockPanels = class(TObjectList)43 destructor Destroy; override;44 end;45 46 { TCoolDockManager }47 48 TCoolDockManager = class(TCoolDockManagerBase)49 private50 FMaster: TCoolDockMaster;51 FDockStyle: TDockStyle;52 FDockSite: TWinControl;53 FDockPanels: TCoolDockPanels;54 function GetDockSite: TWinControl;55 function GetHeaderPos: THeaderPos;56 function GetMoveDuration: Integer;57 procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;58 DropCtl: TControl);59 procedure SetDockStyle(const AValue: TDockStyle);60 procedure SetHeaderPos(const AValue: THeaderPos);61 procedure SetMaster(const AValue: TCoolDockMaster);62 procedure SetMoveDuration(const AValue: Integer);63 procedure SetVisible(const AValue: Boolean);64 procedure UpdateClientSize;65 public66 DockStyleHandler: TCoolDockStyle;67 PopupMenu: TCoolDockPopupMenu;68 constructor Create(ADockSite: TWinControl); override;69 destructor Destroy; override;70 71 // Inherited from TDockManager72 procedure BeginUpdate; override;73 procedure EndUpdate; override;74 procedure GetControlBounds(Control: TControl;75 out AControlBounds: TRect); override;76 function GetDockEdge(ADockObject: TDragDockObject): boolean; override;77 procedure InsertControl(ADockObject: TDragDockObject); override; overload;78 procedure InsertControl(Control: TControl; InsertAt: TAlign;79 DropCtl: TControl); override; overload;80 procedure LoadFromStream(Stream: TStream); override;81 procedure PaintSite(DC: HDC); override;82 procedure MessageHandler(Sender: TControl; var Message: TLMessage); override;83 procedure PositionDockRect(ADockObject: TDragDockObject); override; overload;84 procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign;85 var DockRect: TRect); override; overload;86 procedure RemoveControl(Control: TControl); override;87 procedure ResetBounds(Force: Boolean); override;88 procedure SaveToStream(Stream: TStream); override;89 procedure SetReplacingControl(Control: TControl); override;90 function AutoFreeByControl: Boolean; override;91 92 function FindControlInPanels(Control: TControl): TCoolDockClientPanel;93 function CreateContainer(InsertAt: TAlign): TCoolDockConjoinForm;94 property DockPanels: TCoolDockPanels read FDockPanels write FDockPanels;95 property DockStyle: TDockStyle read FDockStyle write SetDockStyle;96 property MoveDuration: Integer read GetMoveDuration write SetMoveDuration;97 property Master: TCoolDockMaster read FMaster write SetMaster;98 property DockSite: TWinControl read GetDockSite;99 property HeaderPos: THeaderPos read GetHeaderPos write SetHeaderPos;100 property Visible: Boolean write SetVisible;101 end;102 23 103 24 { TCoolDockMaster } … … 110 31 FShowIcons: Boolean; 111 32 FTabsEnabled: Boolean; 112 FClients: TObjectList;113 function GetClient(Index: Integer): TCoolDockClient;114 33 procedure SetShowIcons(const AValue: Boolean); 115 34 procedure SetTabsEnabled(const AValue: Boolean); … … 117 36 constructor Create(AOwner: TComponent); override; 118 37 destructor Destroy; override; 119 procedure RegisterClient(Client: TCoolDockClient);120 procedure UnRegisterClient(Client: TCoolDockClient);121 property Clients[Index: Integer]: TCoolDockClient read GetClient;122 38 published 123 39 property TabsEnabled: Boolean read FTabsEnabled write SetTabsEnabled; … … 132 48 end; 133 49 134 TCoolDockClient = class(TCo mponent)50 TCoolDockClient = class(TCoolDockClientBase) 135 51 private 136 52 FDockable: Boolean; 137 53 FFloatable: Boolean; 138 FMaster: TCoolDockMaster;139 FPanel: TPanel;140 54 procedure SetDockable(const AValue: Boolean); 141 55 procedure SetFloatable(const AValue: Boolean); 142 procedure SetMaster(const AValue: TCoolDockMaster);143 procedure SetPanel(const AValue: TPanel);144 56 public 145 57 constructor Create(AOwner: TComponent); override; … … 150 62 property Floatable: Boolean read FFloatable 151 63 write SetFloatable default True; 152 property Master: TCoolDockMaster read FMaster153 write SetMaster;154 property Panel: TPanel read FPanel155 write SetPanel;156 64 end; 157 65 … … 171 79 end; 172 80 173 function GetUniqueName(BaseName: string): string;174 var175 I: Integer;176 begin177 I := 1;178 while Assigned(FindGlobalComponent(BaseName + IntToStr(I))) do Inc(I);179 Result := BaseName + IntToStr(I);180 end;181 182 { TCoolDockPanels }183 184 destructor TCoolDockPanels.Destroy;185 var186 Temp: Integer;187 begin188 Temp := Count;189 inherited Destroy;190 end;191 192 193 { TCoolDockManager }194 195 function TCoolDockManager.FindControlInPanels(Control: TControl196 ): TCoolDockClientPanel;197 var198 I: Integer;199 begin200 I := 0;201 while (I < FDockPanels.Count) and202 (TCoolDockClientPanel(FDockPanels[I]).Control <> Control) do Inc(I);203 if I < FDockPanels.Count then Result := TCoolDockClientPanel(FDockPanels[I])204 else Result := nil;205 end;206 207 function TCoolDockManager.GetDockSite: TWinControl;208 begin209 Result := FDockSite;210 end;211 212 function TCoolDockManager.GetHeaderPos: THeaderPos;213 begin214 215 end;216 217 function TCoolDockManager.GetMoveDuration: Integer;218 begin219 220 end;221 222 constructor TCoolDockManager.Create(ADockSite: TWinControl);223 var224 NewMenuItem: TMenuItem;225 NewMenuItem2: TMenuItem;226 begin227 inherited Create(ADockSite);228 FDockSite := ADockSite;229 FDockPanels := TCoolDockPanels.Create;230 231 FDockStyle := dsTabs; // To initialize style value have to be different232 DockStyle := dsList;233 PopupMenu := TCoolDockPopupMenu.Create(Self);234 PopupMenu.Parent := ADockSite;235 end;236 237 destructor TCoolDockManager.Destroy;238 begin239 PopupMenu.Free;240 DockStyleHandler.Free;241 FDockPanels.Free;242 inherited Destroy;243 end;244 245 procedure TCoolDockManager.BeginUpdate;246 begin247 inherited BeginUpdate;248 end;249 250 procedure TCoolDockManager.EndUpdate;251 begin252 inherited EndUpdate;253 end;254 255 procedure TCoolDockManager.GetControlBounds(Control: TControl; out256 AControlBounds: TRect);257 begin258 end;259 260 function TCoolDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;261 begin262 Result := inherited GetDockEdge(ADockObject);263 end;264 265 procedure TCoolDockManager.InsertControl(ADockObject: TDragDockObject);266 begin267 inherited InsertControl(ADockObject);268 end;269 270 procedure TCoolDockManager.InsertControlPanel(Control: TControl; InsertAt: TAlign;271 DropCtl: TControl);272 begin273 DockStyleHandler.InsertControl(Control, InsertAt);274 end;275 276 procedure TCoolDockManager.InsertControl(Control: TControl; InsertAt: TAlign;277 DropCtl: TControl);278 var279 NewSplitter: TSplitter;280 NewDockPanel: TCoolDockClientPanel;281 NewPanel: TPanel;282 I: Integer;283 NewConjoinDockForm: TCoolDockConjoinForm;284 NewDockSite: TWinControl;285 NewForm: TForm;286 begin287 if (FDockSite is TForm) and (not (FDockSite is TCoolDockConjoinForm)) then begin288 if (not Assigned(FDockSite.Parent)) then begin289 // Create conjointed form290 NewConjoinDockForm := CreateContainer(InsertAt);291 FDockSite.ManualDock(NewConjoinDockForm);292 Control.ManualDock(NewConjoinDockForm, nil, InsertAt);293 end else begin294 NewConjoinDockForm := CreateContainer(InsertAt);295 NewDockSite := FDockSite.HostDockSite;296 // FDockSite.ManualFloat(FDockSite.BoundsRect);297 NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);298 FDockSite.ManualDock(NewConjoinDockForm);299 Control.ManualDock(NewConjoinDockForm, nil, InsertAt);300 end;301 end else302 if (FDockSite is TCoolDockConjoinForm) or (FDockSite is TPanel) or (FDockSite is TCoolDockClientPanel) then begin303 InsertControlPanel(Control, InsertAt, DropCtl);304 end;305 306 // FDockPanel.Invalidate;307 //inherited;308 end;309 310 procedure TCoolDockManager.LoadFromStream(Stream: TStream);311 begin312 end;313 314 procedure TCoolDockManager.PaintSite(DC: HDC);315 var316 Canvas: TControlCanvas;317 Control: TControl;318 I: Integer;319 R: TRect;320 begin321 for I := 0 to FDockPanels.Count - 1 do322 with TCoolDockClientPanel(FDockPanels[I]) do begin323 Invalidate;324 end;325 end;326 327 procedure TCoolDockManager.MessageHandler(Sender: TControl;328 var Message: TLMessage);329 begin330 inherited MessageHandler(Sender, Message);331 end;332 333 procedure TCoolDockManager.PositionDockRect(ADockObject: TDragDockObject);334 begin335 inherited PositionDockRect(ADockObject);336 end;337 338 procedure TCoolDockManager.PositionDockRect(Client, DropCtl: TControl;339 DropAlign: TAlign; var DockRect: TRect);340 begin341 case DropAlign of342 alNone: begin343 DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);344 end;345 alRight: begin346 DockRect := Rect(FDockSite.ClientWidth div 2, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);347 end;348 alLeft: begin349 DockRect := Rect(0, 0, FDockSite.ClientWidth div 2, FDockSite.ClientHeight);350 end;351 alTop: begin352 DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight div 2);353 end;354 alBottom: begin355 DockRect := Rect(0, FDockSite.ClientHeight div 2, FDockSite.ClientWidth, FDockSite.ClientHeight);356 end;357 end;358 DockRect.TopLeft := FDockSite.ClientToScreen(DockRect.TopLeft);359 DockRect.BottomRight := FDockSite.ClientToScreen(DockRect.BottomRight);360 end;361 362 procedure TCoolDockManager.RemoveControl(Control: TControl);363 var364 ClientPanel: TCoolDockClientPanel;365 begin366 DockStyleHandler.RemoveControl(Control);367 //inherited;368 (* if Control.HostDockSite = Self.FDockSite then begin369 ClientPanel := FindControlInPanels(Control);370 371 //if Assigned(ClientPanel) then ClientPanel.Splitter.Free;372 //Control.RemoveHandlerOnVisibleChanged(ClientPanel.VisibleChange);373 FDockPanels.Remove(ClientPanel);374 DockStyleHandler.RemoveControl(Control);375 UpdateClientSize;376 //FDockSite.Invalidate;377 //if (FDockSite is TCoolDockConjoinForm) and (FDockSite.DockClientCount = 1) then378 // FDockSite.Free;379 DockStyle := DockStyle;380 end;381 *)382 end;383 384 procedure TCoolDockManager.ResetBounds(Force: Boolean);385 var386 I: Integer;387 Control: TControl;388 R: TRect;389 begin390 end;391 392 procedure TCoolDockManager.SaveToStream(Stream: TStream);393 begin394 end;395 396 procedure TCoolDockManager.SetReplacingControl(Control: TControl);397 begin398 inherited SetReplacingControl(Control);399 end;400 401 function TCoolDockManager.AutoFreeByControl: Boolean;402 begin403 Result := inherited AutoFreeByControl;404 end;405 406 function TCoolDockManager.CreateContainer(InsertAt: TAlign): TCoolDockConjoinForm;407 var408 NewDockSite: TWinControl;409 NewConjoinDockForm: TCoolDockConjoinForm;410 begin411 NewConjoinDockForm := TCoolDockConjoinForm.Create(Application);412 NewConjoinDockForm.Name := GetUniqueName('ConjoinForm');413 NewConjoinDockForm.Visible := True;414 NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;415 NewConjoinDockForm.CoolDockClient.Master := Self.Master;416 NewDockSite := FDockSite.HostDockSite;417 // FDockSite.ManualFloat(FDockSite.BoundsRect);418 //NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);419 Result := NewConjoinDockForm;420 end;421 422 procedure TCoolDockManager.SetDockStyle(const AValue: TDockStyle);423 var424 I: Integer;425 begin426 if FDockStyle <> AValue then begin427 FDockStyle := AValue;428 FreeAndNil(DockStyleHandler);429 if AValue = dsTabs then begin430 DockStyleHandler := TCoolDockStyleTabs.Create(Self);431 TCoolDockStyleTabs(DockStyleHandler).TabControlChange(Self);432 end else433 if AValue = dsList then begin434 DockStyleHandler := TCoolDockStyleRegions.Create(Self);435 end else436 if AValue = dsPopupList then begin437 DockStyleHandler := TCoolDockStylePopupRegions.Create(Self);438 end else439 if AValue = dsPopupTabs then begin440 DockStyleHandler := TCoolDockStylePopupTabs.Create(Self);441 end;442 end;443 UpdateClientSize;444 end;445 446 procedure TCoolDockManager.SetHeaderPos(const AValue: THeaderPos);447 begin448 449 end;450 451 procedure TCoolDockManager.SetMaster(const AValue: TCoolDockMaster);452 begin453 if FMaster = AValue then Exit;454 FMaster := AValue;455 end;456 457 procedure TCoolDockManager.SetMoveDuration(const AValue: Integer);458 begin459 end;460 461 procedure TCoolDockManager.SetVisible(const AValue: Boolean);462 var463 I: Integer;464 begin465 DockStyleHandler.Visible := AValue;466 // for I := 0 to DockPanels.Count - 1 do467 // TCoolDockClientPanel(DockPanels[I]).Visible := AValue;468 end;469 470 procedure TCoolDockManager.UpdateClientSize;471 begin472 DockStyleHandler.UpdateClientSize;473 end;474 475 { TCoolDockConjoinForm }476 477 procedure TCoolDockConjoinForm.FormShow(Sender: TObject);478 begin479 TCoolDockManager(DockManager).Visible := True;480 end;481 482 procedure TCoolDockConjoinForm.FormHide(Sender: TObject);483 var484 I: Integer;485 begin486 TCoolDockManager(DockManager).Visible := False;487 // Hide all docked childs488 with TCoolDockManager(DockManager) do489 for I := 0 to DockPanels.Count - 1 do490 if Assigned(TCoolDockClientPanel(DockPanels[I]).Control) then begin491 TCoolDockClientPanel(DockPanels[I]).Control.Tag := Integer(dhtTemporal);492 TCoolDockClientPanel(DockPanels[I]).Control.Hide;493 end;494 end;495 496 constructor TCoolDockConjoinForm.Create(TheOwner: TComponent);497 begin498 inherited CreateNew(TheOwner);499 CoolDockClient := TCoolDockClient.Create(Self);500 with CoolDockClient do begin501 end;502 OnShow := FormShow;503 OnHide := FormHide;504 end;505 506 destructor TCoolDockConjoinForm.Destroy;507 begin508 inherited;509 end;510 511 procedure TCoolDockConjoinForm.SetName(const NewName: TComponentName);512 begin513 inherited SetName(NewName);514 CoolDockClient.Name := Name + 'CoolDockClient';515 end;516 81 517 82 { TCoolDockMaster } … … 521 86 if FTabsEnabled = AValue then Exit; 522 87 FTabsEnabled := AValue; 523 end;524 525 function TCoolDockMaster.GetClient(Index: Integer): TCoolDockClient;526 begin527 Result := TCoolDockClient(FClients[Index]);528 88 end; 529 89 … … 537 97 begin 538 98 inherited Create(AOwner); 539 FClients := TObjectList.Create;540 FClients.OwnsObjects := False;541 99 end; 542 100 … … 546 104 begin 547 105 // Assigning nil to Client Master property cause unregistring client from list 548 for I := FClients.Count - 1 downto 0 do549 TCoolDockClient(FClients[I]).Master := nil;550 FClients.Free;551 106 Customize := nil; 552 107 inherited Destroy; 553 108 end; 554 109 555 procedure TCoolDockMaster.RegisterClient(Client: TCoolDockClient);556 begin557 if Assigned(Client) then558 if FClients.IndexOf(Client) = -1 then begin559 FClients.Add(Client);560 Client.Master := Self;561 end;562 end;563 564 procedure TCoolDockMaster.UnRegisterClient(Client: TCoolDockClient);565 begin566 if Assigned(Client) then begin567 Client.Master := nil;568 FClients.Remove(Client);569 end;570 end;571 110 572 111 { TCoolDockClient } 573 574 procedure TCoolDockClient.SetMaster(const AValue: TCoolDockMaster);575 var576 FOldMaster: TCoolDockMaster;577 begin578 if FMaster = AValue then Exit;579 FOldMaster := FMaster;580 FMaster := AValue;581 if Assigned(FOldMaster) then582 FOldMaster.UnregisterClient(Self);583 if Assigned(FMaster) then begin584 FMaster.RegisterClient(Self);585 if not (csDesigning in ComponentState) then begin586 if Assigned(TWinControl(Owner).DockManager) then587 TCoolDockManager(TWinControl(Owner).DockManager).Master := FMaster;588 if Assigned(Panel) then589 TCoolDockManager(Panel.DockManager).Master := FMaster;590 end;591 end;592 end;593 112 594 113 procedure TCoolDockClient.SetDockable(const AValue: Boolean); … … 640 159 end; 641 160 642 procedure TCoolDockClient.SetPanel(const AValue: TPanel);643 var644 OldPanel: TPanel;645 begin646 if FPanel = AValue then exit;647 OldPanel := FPanel;648 FPanel := AValue;649 if not (csDesigning in ComponentState) then begin650 if Assigned(FPanel) then651 with FPanel do begin652 DockSite := True;653 UseDockManager := True;654 DockManager := TCoolDockManager.Create(FPanel);655 end else begin656 OldPanel.DockSite := False;657 end;658 end;659 end;660 661 initialization662 663 RegisterClass(TCoolDockConjoinForm);664 665 finalization666 667 UnRegisterClass(TCoolDockConjoinForm);668 669 161 670 162 end.
Note:
See TracChangeset
for help on using the changeset viewer.