OnDock (C++)

From RAD Studio Code Examples
Jump to: navigation, search


The following example is taken from the docking demo. It shows how to set permissions to dock dockable objects onto a docking site.


void __fastcall TMainForm::LeftDockPanelDockDrop(TObject *Sender,
      TDragDockObject *Source, int X, int Y)
  //OnDockDrop gets called after the client has actually docked,
  //so you have to check for DockClientCount = 1 before making 
  //the dock panel visible.
  TPanel *panel = dynamic_cast<TPanel *>(Sender);
  if (panel->DockClientCount == 1)
	ShowDockPanel(panel, True, NULL);
  //Make DockManager repaint its clients.

void __fastcall TMainForm::LeftDockPanelDockOver(TObject *Sender,
	  TDragDockObject *Source, int X, int Y, TDragState State, bool &Accept)
  Accept = (dynamic_cast<TDockableForm*>(Source->Control) != NULL);
  if (Accept)
    // Modify the DockRect to preview the dock area.
    Types::TPoint TopLeft = LeftDockPanel->ClientToScreen(Point(0, 0));
	Types::TPoint BottomRight = LeftDockPanel->ClientToScreen(
	  Point(this->ClientWidth/3, LeftDockPanel->Height));
	Source->DockRect = Types::TRect(TopLeft, BottomRight);

void __fastcall TMainForm::LeftDockPanelUnDock(TObject *Sender,
	  TControl *Client, TWinControl *NewTarget, bool &Allow)
  //OnUnDock gets called before the client is undocked, in order to optionally
  //disallow the undock. DockClientCount is never 0 when called from this event.
  TPanel *panel = dynamic_cast<TPanel *>(Sender);
  if (panel->DockClientCount == 1)
	ShowDockPanel(panel, False, NULL);

void __fastcall TMainForm::LeftDockPanelGetSiteInfo(TObject *Sender,
	  TControl *DockClient, TRect &InfluenceRect, TPoint &MousePos,
	  bool &CanDock)
  //If CanDock is True, the panel does not automatically draw the preview rectangle.
  CanDock = DockClient->ClassNameIs("TDockableForm");
  if (!CanDock)
     ShowMessage(L"GetSiteInfo CanDock went bad!");


Personal tools