Recent

Author Topic: [AnchorDocking] Event on form being docked & preventing form layout saved & more  (Read 889 times)

Skotty

  • New Member
  • *
  • Posts: 13
There's three problems I have to solve with AnchorDocking:

1: A form being docked shall get an event about this happening

I have a form with an OpenGL context which needs to always re-initialize this context once it was docked/undocked. For this I obviously must get some kind of message/event on when it was docked/undocked.
As this can be happening anywhere in the program (arbitrary dockable forms) I was thinking the default "OnDockDrop" event on any TAnchorDockHostSite would be not a good option. But is there actually any better?


2: Prevening a specific form being saved in the layout config

Writing the anchor docking layout saves it for every form. I however do have one dockable form that I want to exclude from this. Is there any proper way to do this, other than somewhat the outputted config file?


3: Main form should have static caption

When docking any other forms into my main form, it does adjust the caption. However I want this to stay on my manually set caption. What is the right approach to do this?
« Last Edit: May 25, 2020, 10:58:06 pm by Skotty »

Skotty

  • New Member
  • *
  • Posts: 13
Alright, I have taken the time to delve further into the unfortunately not so well documented code and did the following for each point:

1:
I made a new class inheriting from TAnchorDockHostSite and extended the SetParent method to fire events through the control hierarchy.

Code: Pascal  [Select][+][-]
  1. type
  2.   TALEEditorDockHostSite = class(TAnchorDockHostSite)
  3.   protected
  4.     FOnParentChange: TNotifyEvent;
  5.     FOnParentChanged: TNotifyEvent;
  6.     procedure SetParent(NewParent: TWinControl); override;
  7.     procedure NotifyParentChange(Source: TComponent);
  8.     procedure NotifyParentChanged(Source: TComponent);
  9.   public
  10.     property OnParentChange: TNotifyEvent read FOnParentChange write FOnParentChange;
  11.     property OnParentChanged: TNotifyEvent read FOnParentChanged write FOnParentChanged;
  12.   end;      
  13.  
  14. procedure TALEEditorDockHostSite.SetParent(NewParent: TWinControl);
  15. begin
  16.   NotifyParentChange(Self);
  17.   inherited SetParent(NewParent);
  18.   NotifyParentChanged(Self);
  19. end;
  20.  
  21. procedure TALEEditorDockHostSite.NotifyParentChange(Source: TComponent);
  22. var
  23.   Index: ValSInt;
  24. begin
  25.   if Assigned(FOnParentChange) then
  26.     FOnParentChange(Source);
  27.  
  28.   for Index := 0 to ControlCount - 1 do
  29.     if Controls[Index] is TALEEditorDockHostSite then
  30.       (Controls[Index] as TALEEditorDockHostSite).NotifyParentChange(Source);
  31. end;
  32.  
  33. procedure TALEEditorDockHostSite.NotifyParentChanged(Source: TComponent);
  34. var
  35.   Index: ValSInt;
  36. begin
  37.   if Assigned(FOnParentChanged) then
  38.     FOnParentChanged(Source);
  39.  
  40.   for Index := 0 to ControlCount - 1 do
  41.     if Controls[Index] is TALEEditorDockHostSite then
  42.       (Controls[Index] as TALEEditorDockHostSite).NotifyParentChanged(Source);
  43. end;  
  44.  

After that I told DockMaster in my app's initialization to instanciate this class instead of the default TAnchorDockHostSite:
Code: Pascal  [Select][+][-]
  1. DockMaster.SiteClass := TALEEditorDockHostSite;
  2.  


2:
Yet to be solved. Will edit once I have it. Probably similar to the above solution.


3:

Instead of making my entire main for a dock site via MakeDockSite I instead switched over to give it a dedicated docking area and made this the dock site instead via MakeDockPanel.
That is from the minidewithdockpanel example files. It also prevents resizing problems when closing docket forms (some other forms may become almost entirely hidden, confusing for the end-user).

 

TinyPortal © 2005-2018