Search code examples
phpwxwidgetswxphp

Is there a AUI pane move (or dock) event in wxPHP?


On this question I have been attempting to capture a AUI pane configuration so that it can be restored if any panes have been closed. The docs are somewhat limited for wxPHP, and upstream for wxWidgets, so I am largely feeling my way around.

I have realised that SavePaneInfo will help me capture the state of a pane - it outputs a perspective string that represents the position and options for a pane at a given moment. All I need to do therefore is to capture when the pane changes and update my internal representation of it.

For the sake of interest, a perspective looks like this:

name=auiPane3;caption=Caption 3;state=2099196;dir=3;layer=0;row=0;pos=1;prop=100000;bestw=90;besth=25;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1

However, capturing a move/dock event is not proving to be trivial. I can see six events connected with AUI:

wxEVT_AUI_FIND_MANAGER
wxEVT_AUI_PANE_BUTTON
wxEVT_AUI_PANE_CLOSE
wxEVT_AUI_PANE_MAXIMISE
wxEVT_AUI_PANE_RESTORE
wxEVT_AUI_PANE_RENDER

I have been able to capture the restore and close events, and the find_manager doesn't seem to do anything. I've tried wxEVT_ANY on this window, which also does not seem to capture anything. I've also tried it on individual panes too, to no avail (nothing is called as far as I can tell):

$managedWindow->getWindowByIndex(0)->Connect(wxEVT_ANY, array($this, "onAny"));

The docs for the upstream library wxWidgets mention this event:

EVT_AUI_PANE_ACTIVATED

However that does not seem to be implemented in wxPHP - is that what I want? It does not quite sound right, but if I can access it without the constant I would certainly try it.

I guess I could use wxAuiManager::SetArtProvider with the standard art provider object, modified to capture pane state, but that feels like a sledgehammer to crack a nut. I could also capture the close event and change the perspective string returned so the 'closed' bit is not set, but that too is not particularly elegant.

What I want to do feels really trivial, and would be in keeping with other parts of wxWidgets, but it is not so. Any suggestions for things to try?


Solution

  • I've found another solution, which I think I moderately prefer. It turns out it is possible to get the pane name from the wxAuiPaneInfo object - the perspective contains it! This allows me to simplify the algorithm - I just convert the name to an ordinal, and then save pane perspectives individually.

    Since pane close events are always triggered before the close (i.e. when they are still vetoable) they will not have the close bit set, and so happily I do not have to modify that. Here's my new event handler:

    public function onPaneClose(wxAuiManagerEvent $event)
    {
        // In the absence of being able to read the pane name from a paneinfo
        // method, we can parse it out from the perpective string
        $info = $event->GetPane();
        $persp = $this->getManagedWindow()->getAuiManager()->SavePaneInfo($info);
    
        // Fish out the number, which represents the pane ordinal
        $matches = [];
        preg_match('#name=auiPane(\d+)#', $persp, $matches);
        if ($matches)
        {
            $index = $matches[1];
            $this->windowSaves[$index] = $persp;
        }
    }
    

    I've just used a regex on the perspective string that matches my naming format of auiPane<index>.