wxPHP 中是否有 AUI 窗格移动(或停靠)事件? [英] Is there a AUI pane move (or dock) event in wxPHP?
问题描述
关于这个问题我一直在尝试捕获 AUI 窗格配置,以便在任何窗格关闭时可以恢复它.wxPHP 的文档有些限制,wxWidgets 的上游文档有些限制,所以我在很大程度上感觉自己的方式.
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.
我意识到 SavePaneInfo
将帮助我捕获窗格的状态 - 它输出一个 透视字符串,表示给定时刻窗格的位置和选项.因此,我需要做的就是捕捉窗格何时发生变化并更新我对它的内部表示.
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
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 相关的事件:
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
我已经能够捕获恢复和关闭事件,而 find_manager 似乎没有做任何事情.我已经在这个窗口上尝试了 wxEVT_ANY
,它似乎也没有捕捉到任何东西.我也在个别窗格上尝试过,但无济于事(据我所知,没有任何东西被调用):
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"));
上游库 wxWidgets 的文档提到了这个事件:
The docs for the upstream library wxWidgets mention this event:
EVT_AUI_PANE_ACTIVATED
然而,这似乎并没有在 wxPHP 中实现——这是我想要的吗?这听起来不太正确,但如果我可以在没有常量的情况下访问它,我当然会尝试.
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.
我想我可以将 wxAuiManager::SetArtProvider
与标准的艺术提供者对象一起使用,修改为捕获窗格状态,但这感觉就像一把大锤敲碎了坚果.我还可以捕获关闭事件并更改返回的透视字符串,因此未设置关闭"位,但这也不是特别优雅.
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.
我想做的事情感觉真的很琐碎,并且会与 wxWidgets 的其他部分保持一致,但事实并非如此.有什么可以尝试的建议吗?
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?
推荐答案
我找到了另一个解决方案,我认为我比较喜欢.结果证明可以从wxAuiPaneInfo
对象中获取窗格名称——透视图包含它!这让我可以简化算法 - 我只是将名称转换为序数,然后单独保存窗格透视图.
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;
}
}
我刚刚在透视字符串上使用了一个正则表达式,它与我的 auiPane
命名格式相匹配.
I've just used a regex on the perspective string that matches my naming format of auiPane<index>
.
这篇关于wxPHP 中是否有 AUI 窗格移动(或停靠)事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!