* * *

Author Topic: DesignerMediator in any unit  (Read 663 times)

x2nie

  • Sr. Member
  • ****
  • Posts: 451
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
DesignerMediator in any unit
« on: September 10, 2016, 08:26:41 am »
I am developing a new WYSIWYG editor for components that are not inherited from TWinControl nor TControl.
It is fine (can resize, move, change property via Object Inspector and also drop a new component from Components Palette),
until I found that is not all Lazarus's feature worked properly for non-LCL componets.
For example: the Paste command always places copied component at root ( its should placed inside the current selected component)
, and drag-drop within Component Tree also disallowed.


AFAIK, the problem is because my component-editor rely only at TDesignerMediator, but TDesignerMediator was not involved on every Lazarus activities.


What I want is let TDesignerMediator decide what should going right when Lazarus is editing a non-LCL components.
For example, there is no chance to involve TDesignerMediator in \lazarus_trunk\components\identf\componenttreeview.pas line:403 :
Code: Pascal  [Select]
  1. procedure TComponentTreeView.DragOver(Source: TObject; X, Y: Integer;
  2.   State: TDragState; var Accept: Boolean);
  3. var
  4. ...
  5. begin
  6.  
  7.  
  8.   AcceptContainer := False;
  9.   AcceptControl := True;
  10. ..
  11.   if Assigned(ParentNode) and Assigned(ParentNode.Data) then
  12.   begin
  13.     AnObject := TObject(ParentNode.Data);
  14.     if (AnObject is TWinControl) then
  15.     begin
  16.       if ControlAcceptsStreamableChildComponent(TWinControl(AControl),
  17.          TComponentClass(AnObject.ClassType),aLookupRoot)
  18.       then begin
  19.         AContainer := TPersistent(AnObject);
  20.         //DebugLn(['TComponentTreeView.DragOver AContainer=',DbgSName(AContainer)]);
  21.         AcceptContainer := True;
  22.       end;
  23.     end
  24.     else
  25.     if (AnObject is TCollection) then
  26.     begin
  27.       // it is allowed to move container items inside the container
  28.       AContainer := TPersistent(AnObject);
  29.       AcceptContainer := True;
  30.     end;
  31.   end;
  32.  
  33.  
  34.   if AcceptContainer then
  35.   begin
  36.     Node := GetFirstMultiSelected;
  37.     while Assigned(Node) and AcceptControl do
  38.     begin
  39.       AnObject := TObject(Node.Data);
  40.       // don't allow to move ancestor components
  41.       if (AnObject is TComponent) and
  42.          (csAncestor in TComponent(AnObject).ComponentState) then break;
  43.       if (AnObject is TControl) then
  44.       begin
  45.         if AnObject = AContainer then break;
  46.         if not (AContainer is TWinControl) then break;
  47.         // check if new parent allows this control class
  48.         if not TWinControl(AContainer).CheckChildClassAllowed(AnObject.ClassType, False) then
  49.           break;
  50.         // check if one of the parent of the container is the control itself
  51.         if AControl.IsParentOf(TWinControl(AContainer)) then break;
  52.         // do not move children of a restricted parent to another parent
  53.         // e.g. TPage of TPageControl
  54.         if (AControl.Parent <> nil) and (AControl.Parent <> AContainer) and
  55.             (not (csAcceptsControls in AControl.Parent.ControlStyle)) then
  56.           break;
  57.       end
  58.       else
  59.       if (AnObject is TCollectionItem) then
  60.       begin
  61.         if AnObject = AContainer then break;
  62.         if not (AContainer is TCollection) then
  63.           break;
  64.         if TCollectionItem(AnObject).Collection <> TCollection(AContainer) then
  65.           break;
  66.       end;
  67.       Node := Node.GetNextMultiSelected;
  68.     end;
  69.     AcceptControl := (Node = nil);
  70.   end;
  71.  
  72.  
  73.   Accept := AcceptContainer and AcceptControl;
  74.   inherited DragOver(Source, X, Y, State, Accept);
  75.  
  76.  
  77.   Accept := AcceptContainer and AcceptControl and ((OnDragOver=nil) or Accept);
  78. end;


See? there is no chance for non-TControl to decide what should go right.
There are many other sample that is similar situation in several different folder (\ide, \components\identf, \designer, )


So, my question is : How to involve/call/access the DesignerMediator "at any unit" (I mean there are different folders)? .




I guess it will start with current selected component, but really have no idea. Thanks You
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus