Reputation: 5938
In this [ http://wiki.wxwidgets.org/WxMenu#PopUp-menus ] example wxMenu
is a local variable.
It is then passed by pointer to PopupMenu
, now I always assume that when I give something a menu by pointer it'll delete it for me (much like panels and frames), there's no mention of a copy constructor in http://docs.wxwidgets.org/trunk/classwx_menu.html and even so what if it was subclassed? (so by deduction it does not copy)
Reading: http://docs.wxwidgets.org/trunk/classwx_window.html#a8f715d238cf74a845488b0e2645e98df also states that the PopupMenu
function doesn't return until the menu has been dismissed, it'd be silly if this blocked the entire GUI,
So my question is this:
Why doesn't PopupMenu
take a reference? wx is old, older than some of the things now standard in C++ (RTTI and some memory structures now provided by the STL for example) but references came to be because of operator overloading, inspired by Algol68 (source, "The design and evolution of C++") which is older than the early 90s, which is when I believe wxWidgets came to be.
What constraints are there while the popup menu is open? I'd like to learn more about wx's internals, so if anyone can point me towards some resources that'd be superb! A lot of what I know about wx has been deduced from how it acts. I was happy initially with this magical black box that did GUIs for me, but I am so curious as to how it actually works _(I've read the books: "Cross platform GUI programming in wxWidgets" and "wxPython" - these don't cover it)
In the famous layers of wx diagrams there's the wxWidgets API
then below that the wxWidgets Port
then all the various platform specific stuff, I'd like to know more about how they work/interact.
[diagram: page 44 within this PDF, page 8 in the book: http://ptgmedia.pearsoncmg.com/images/0131473816/downloads/0131473816_book.pdf ]
Upvotes: 0
Views: 108
Reputation: 22753
The different questions are rather unrelated. PopupMenu()
takes a pointer mostly for historical reasons (all wxWidgets functions typically take pointers to any window or menu objects). But the newer GetPopupMenuSelectionFromUser() takes a reference. Yet both of them are modal, in the sense that they don't return control until the menu is dismissed. Internally, popup menus run their own event loop which is, moreover, inside the native GUI toolkit (this is definitely the case under Windows) and not wx itself, but this shouldn't really matter.
In any case, PopupMenu()
does not take ownership of the passed in pointer. This allows you to use it like this:
void Foo() {
wxMenu menu;
menu.Append(...);
window->PopupMenu(&menu);
}
But, again, for most of the cases you can just use GetPopupMenuSelectionFromUser()
which is even more convenient.
Upvotes: 1