开发者

Difference between UnPin and Close UnPinned

开发者 https://www.devze.com 2023-02-19 07:09 出处:网络
When the user clicks \'x\' on a Pinned Form OnClose is called. When the user clicks \'x\' on an Unpinned Form OnHide is called

When the user clicks 'x' on a Pinned Form OnClose is called.

When the user clicks 'x' on an Unpinned Form OnHide is called

When the user clicks 'UnPin' on a Pinned Form OnHide is called.

I'm trying to synchronise the visible forms with a menu system but I don't know how to determine the difference in the OnHide event between when the user clicks 'x' and when the user clicks 'UnPin'. I want to intercept the 'x' and call Close instead.

Difference between UnPin and Close UnPinned

Each child is a descendant of TManagerPanel which in turn is a descendant of TForm with the border style set to bsSizeToolWin, Drag Kind set to dkDock and Drag Mode is dmAutomatic.

type
    TPanelManager = class(TForm)
    ...
    private
    ...        
        Panels: TManagerPanelList;
        Settings: TSettings; //User Settings
    ...
end;
...

function TPanelManager.InitChild(ChildClass: TManagerPanelClass): TManagerPanel;
var
    Child: TManagerPanel;
begin
    Child := ChildClass.Create(Self);
    Child.Connection := MSConnectio开发者_运维知识库n1;
    Child.Settings := Settings;
    Child.Styles := Styles;
    ...
    Child.OnPanelClosed := PanelClosed;
    Child.OnPercentChanged := PercentChanged;
    ...
    Child.OnPanelHide := PanelHide;
    Child.Font := Font;
    Child.Initialise;
    Child.ManualDock(DockTarget);
    Panels.AddPanel(Child);
    Result := Child;
end;

procedure TPanelManager.PanelClosed(Sender: TObject; var Action: TCloseAction);
var
    MenuItem: TMenuItem;
    Child: TManagerPanel;
begin
    if Sender is TManagerPanel then
    begin
        Child := TManagerPanel(Sender);
        Action := caFree;
        MenuItem := MenuItemFromChild(Child);
        MenuItem.Checked := False;
        Settings[RemoveAmpersand(MenuItem.Caption)] := MenuItem.Checked;
        Panels.Remove(Child);
    end;
end;

EDIT: What I mean by a "Pinned" Form: A docked form with the pin set such that it always visible.

Difference between UnPin and Close UnPinned

What I mean by a "UnPinned" Form: A docked form with the pin released such that a tab appears in a dock tab set and the form appears when the tab is selected.

Difference between UnPin and Close UnPinned

Difference between UnPin and Close UnPinned

Delphi Version is 2007


it seems that pinning and unpinning a docked form changes it's parent between a TTabDockPanel and the TPanel I'm docking it to.

Adding an OnHide method to the Demo Dock Form...

procedure TfrmDock.FormHide(Sender: TObject);
begin
  if Assigned(Self.Parent) then
      ShowMessage(Self.Parent.ClassName)
  else 
      ShowMessage('No Parent');
end;

I can now distinguish between "Floating", "Docked,Pinned" and "Docked, Unpinned" when the form gets hidden.

EDIT I've found a better way of doing this

procedure TfrmDock.FormHide(Sender: TObject);
begin
    if Assigned(Parent) then
    begin
        if Not (csDocking in ControlState) then //This was the original test above
        begin
            if Parent is TTabDockPanel then // This is now a safety check
            begin
                if TTabDockPanel(Parent).AnimateSpeed = 1 then //Additional Test
                    //form is closing
                else
                    //form is hiding (Unpinned focused changed)
            end;
        end
        else 
            //form is being unpinned.
    end;
end;

In DockCaptionMouseUp the Animation Speed is set to 1 so that the panel appears to close (Hides really fast). The same happens for "Unpinning" but control state changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消