[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] popup menus cleanup
From: |
Vaclav Slavik |
Subject: |
Re: [lmi] popup menus cleanup |
Date: |
Tue, 06 Jul 2010 16:43:24 +0200 |
On Tue, 2010-07-06 at 10:43 +0000, Greg Chicares wrote:
> But AFAICT this menu lives on the heap, with or without the patch, so
> heap vs. stack doesn't seem to be the problem. I figured that we have
> this menu on the heap already, inside the menubar object, so why not
> just use it for the popup?
In practical terms, because if you do, it fails:
../src/common/menucmn.cpp(540): assert "!IsAttached()" failed in
SetInvokingWindow(): menus attached to menu bar can't have
invoking window
But it makes sense even without that assert: a submenu is owned by its
parent menu (here, by the menu bar) and once owned, it shouldn't be
taken out of the parent menu and used independently, without
disassociating it from the parent first.
A menu like a window in this respect: windows and menus form a treethe
hierarchy, where all objects expect the root (in wx, that's
wxTopLevelWindow) have exactly one parent. A menu attached to a menubar
has the menubar as its parent; a popup menu has the window it pops on as
its parent. By re-using the same menu instance, you're asking it to have
two parents for a little while.
Regards,
Vaclav