Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close button appears on my docked control after redocking

I have a paint box which I want the user to be able to undock and move around. So I set its DragKind to dkDock and its DragMode to dmAutomatic, and put it inside a panel with DockSite set to True. I'm experiencing a rather odd behavior when I dock the paint box after having undocked it to a floating form. The close button of the floating form appears inside the panel. I've attached two screenshots. One from the original state, and one after docking the paint box again. What am I missing?

Original State:

Before undocking

After docking:

After docking


UPDATE After using TLama's solution, here's the result.

After Docking ; Using new dock manager

like image 600
iMan Biglari Avatar asked Jan 14 '13 08:01

iMan Biglari


2 Answers

You're not missing anything. That's how the default dock manager implementation works. It just wants to have grabber with the close button available on dock site, which uses it. What you can do, is implement your own dock manager and override its AdjustDockRect method, which controls the size of docking zone and where is in default dock manager implementation made a space for grabber with close button. If you don't want that grabber, just keep the size of dock zone rectangle as it was passed to the method, in size of the whole dock site. In other words, do nothing in that method override.

That's for the functional part of the grabber, but except that you need to intercept hardcoded drawing of it. To do so, you need to override the PaintDockFrame event method and like before, do just nothing there.

Here's a code sample:

type
  TNoGrabDockManager = class(TDockTree)
  protected
    procedure AdjustDockRect(Control: TControl; var ARect: TRect); override;
    procedure PaintDockFrame(Canvas: TCanvas; Control: TControl;
      const ARect: TRect); override;
  end;

implementation

{ TNoGrabDockManager }

procedure TNoGrabDockManager.AdjustDockRect(Control: TControl; var ARect: TRect);
begin
  // here you can make space for a grabber by shifting top or left position
  // of the ARect parameter, which is by default set to the whole dock site
  // bounds size, so if you do nothing here, there will be no grabber
end;

procedure TNoGrabDockManager.PaintDockFrame(Canvas: TCanvas; Control: TControl;
  const ARect: TRect);
begin
  // in this event method, the grabber with that close button are drawn, so
  // as in case of disabling grabber functionality do precisely nothing for
  // drawing it here, that will make it visually disappear
end;

Here's how to use such custom dock manager (see below for note about UseDockManager property):

procedure TForm1.FormCreate(Sender: TObject);
begin
  Panel1.DockManager := TNoGrabDockManager.Create(Panel1);
  Panel1.UseDockManager := True;
end;

Important

As few sources suggest, you should set the UseDockManager property of your dock panel to False at design time. I don't know why, but from quick tests I've made, some of the event methods of the custom dock manager were not fired when I didn't have set that property at design time (the AdjustDockRect event method worked properly even without doing so, but I wouldn't personally rely on it).

like image 84
TLama Avatar answered Oct 02 '22 09:10

TLama


Rather than using a panel as the dock target, use a TPageControl and hide the tab from the generated tab sheet. Since a page control normally has visible tabs, the delete handle is not displayed. Unfortunately, when you hide a tab sheet's tab, the sheet itself is also hidden. So you must save and restore it by adding the following OnDockDrop event:

procedure TForm2.PageControl1DockDrop(Sender: TObject; Source: TDragDockObject;
  X, Y: Integer);
var
  ix: Integer;
begin
  ix := PageControl1.ActivePageIndex;
  PageControl1.ActivePage.TabVisible := false;
  PageControl1.ActivePageIndex := ix;
end;
like image 26
SteveC Avatar answered Oct 02 '22 07:10

SteveC