3

这个问题上,我一直在尝试捕获 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;floaty=-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标准的艺术提供者对象,修改为捕获窗格状态,但这感觉就像是一把大锤来破解坚果。我还可以捕获关闭事件并更改返回的透视字符串,因此未设置“关闭”位,但这也不是特别优雅。

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

4

2 回答 2

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;
    }
}
于 2016-01-17T20:20:35.003 回答
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>

于 2016-01-17T21:11:45.693 回答