Beginner question about wxMenuBar Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
renaud.s
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Feb 22, 2006 9:23 pm
Location: Belgium
Contact:

Beginner question about wxMenuBar

Post by renaud.s » Wed Feb 22, 2006 10:19 pm

Hi all,

I'm beginner in wxWidgets and I'm currently trying to write a application using a wxMDIParentFrame and a few wxMDIChild. I would like to keep (nearly) the same menu bar for the parent as for the child. The childs would simply add a single menu. Because there will be several different 'kind' of child, I would like to avoid re-building the menu bar every time.
So my idea is too build a 'main' menu bar in the parent frame then 'catch' it in child, then add (with wxMenuBar::Insert) the special's child menu and finaly assign the newly created menu bar to the child window.
So I was thinking to create a similar function as wxFrame::getMenuBar (not avaible for wxMIDParentFrame) but I would prefare getting a copy of the menu object instead of a pointer on it. Just to avoid a modification of the parent's menu by the child.
The problem is that wxMenu and wxMenuBar doesn't have a copy constructor or it is private.
First question: is there a reason why there is no copy constructor avalaible for wxMenu and wxMenuBar ?
Second question: is there a reason why there is getMenuBar() for wxMDIParentFrame ?
Third question: any suggestion ? :-)


Many thanks

PS: just get the 'cross-platfrom gui programming with wxwidgets' book a few days ago, excellent book, I really recommand it to all wxBeginner !

Renaud

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Thu Feb 23, 2006 4:25 am

Most wxWindow and derivatives do not have a copy constructor because the copy constructor wouldn't be able to resolve what the new parent should be (most wxWindow and derivative instances typically have a parent).

wxMDIParentFrame has GetMenuBar() because it is part of wxFrame (which wxMDIParentFrame dervies from). Why wouldn't it have GetMenuBar()?

What I would do is make a public createMenuBar() member of your wxMDIParentFrame which returns a newly allocated wxMenuBar as a pointer with all the appropriate wxMenus and wxMenuItems added in. Call that when creating the parent frame's menubar then, in the child frame, also call it to make a new wxMenuBar with an identical structure then make your customizations to it. Naturally, if you have dynamically added/altered menus or menu items that wouldn't work perfectly. You could, of course, use wxMenuBar::GetMenu() along with wxMenuBar::GetMenuCount() and manually go through the menubar to create your duplicate but I view that is a last resort, personally.

renaud.s
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Feb 22, 2006 9:23 pm
Location: Belgium
Contact:

Thanks

Post by renaud.s » Thu Feb 23, 2006 8:26 am

Indead wxMDIParentFrame is derived from wxFrame and so has a GetMenuBar() member function... sorry I must have missed something somewhere.... :?

I'll try out your suggestion.

Many thanks for your answer

Post Reply