在wxPHP中是否有AUI窗格移动(或停靠)事件?

时间:2016-01-16 15:03:48

标签: php wxwidgets wxphp

On this question我一直在尝试捕获AUI窗格配置,以便在关闭任何窗格时可以恢复它。对于wxPHP而言,文档有些限制,对于wxWidgets来说,上游是有限的,所以我很感觉我的方式。

我已经意识到SavePaneInfo将帮助我捕获窗格的状态 - 它会输出一个透视字符串,它表示给定时刻窗格的位置和选项。因此,我需要做的就是在窗格更改并更新其内部表示时进行捕获。

为了感兴趣,透视图如下:

  

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;轻飘= -1; floatw = -1; floath = -1

然而,捕获移动/停靠事件并不是微不足道的。我可以看到六个与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

我已经能够捕获恢复和关闭事件,并且find_manager似乎没有做任何事情。我在这个窗口试过了wxEVT_ANY,它似乎也没有抓到任何东西。我也在个别窗格上试过它,但无济于事(据我所知,没有任何东西可以调用):

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

上游库wxWidgets的文档提到了这个事件:

EVT_AUI_PANE_ACTIVATED

然而,这似乎没有在wxPHP中实现 - 这就是我想要的吗?它听起来不太正确,但是如果我可以在没有常数的情况下访问它,我肯定会尝试它。

我想我可以将wxAuiManager::SetArtProvider与标准的艺术品提供者对象一起使用,进行修改以捕捉窗格状态,但这感觉就像是一个破解坚果的大锤。我还可以捕获close事件并更改返回的透视字符串,这样就不会设置'closed'位,但这也不是特别优雅。

我想做的事情感觉非常微不足道,并且与wxWidgets的其他部分保持一致,但事实并非如此。有什么建议可以尝试吗?

2 个答案:

答案 0 :(得分:2)

我有一个解决方案。我本来希望从wxAuiManagerEvent检测哪个窗格正在关闭,这样我只需在关闭时记录窗格的透视字符串。然而,这似乎不可能:

  • $event->GetEventObject()的引用为NULL - 可能是wxPHP错误;
  • $event->GetPane()返回的窗格没有用于读取窗格名称的属性或方法。

因此,无论何时关闭一个窗格,我都采用了保存所有透视字符串的方法。

我发现透视字符串包含一些表示窗格的关闭状态,因此在存储这些字符串时,我确保未设置此位。重新组合透视字符串并不是最优雅的东西,但它起作用,并且比取消停靠和重新锁定要好得多(参见原始帖子中的链接问题)。

这是一些代码循环遍历我的窗格,获取透视字符串,取消设置已关闭的标志并将透视保存在窗口列表中:

public function onPaneClose(wxAuiManagerEvent $event)
{
    for($i = 0; $i <= 7; $i++)
    {
        $pi = $this->getPaneInfoByIndex($i);
        $persp = $this->getManagedWindow()->getAuiManager()->SavePaneInfo($pi);

        // Split perspective string into pieces, get the second one (state)
        $items = explode(';', $persp);
        $state = $items[2];

        // Decode the bitfield within
        $stateItems = explode('=', $state);
        $stateBitfield = (int) $stateItems[1];

        // Set up bitmask to ignore closed state
        $bitMask = (-1 ^ 2);

        // Reset the perspective string minus the closed state bit
        $replacementBitfield = $stateBitfield & $bitMask;
        $items[2] = "state=" . $replacementBitfield;
        $newPersp = implode(';', $items);

        // Finally save the perspective
        $this->windowSaves[$i] = $newPersp;
    }
}

答案 1 :(得分:0)

我找到了另一个解决方案,我认为我中度偏好。事实证明 可以从wxAuiPaneInfo对象获取窗格名称 - 透视图包含它!这允许我简化算法 - 我只是将名称转换为序数,然后单独保存窗格透视图。

由于窗格关闭事件总是在关闭之前触发(即当它们仍然是否可以被否决时),因此它们不会设置关闭位,所以很高兴我不必修改它。这是我的新事件处理程序:

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;
    }
}

我刚刚在符合auiPane<index>命名格式的透视字符串上使用了正则表达式。