[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Load{Menu,Tool}Bar difference in XRC

From: Vadim Zeitlin
Subject: [lmi] Load{Menu,Tool}Bar difference in XRC
Date: Fri, 8 Aug 2008 00:56:19 +0200

 Hello again,

 This mail is about the question raised by the following comment

// WX !! It seems odd that LoadMenuBar has two signatures, the simpler
// of which requires no 'parent' argument, while LoadToolBar does not.

in main_wx.cpp. This refers to the fact that wxXmlResource has the
following methods for menu loading

    wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name);
    wxMenuBar *LoadMenuBar(const wxString& name)
      { return LoadMenuBar(NULL, name); }

but only

    wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);

for loading the toolbars.

 The reason for the above discrepancy is that a menu bar is not a window
and in particular not a child window and so doesn't need a parent window to
be created. It may use the parent window and attach itself to it
automatically but it doesn't require it. But a toolbar is just a normal
child window and so must have a valid top level parent window in order to
be created -- this is why there is no LoadToolBar() overload without parent
and, moreover, there can't be such an overload.

 So the comment above can be just removed. OTOH this still leaves an
unpleasant asymmetry between LoadMenuBar(name) call just above and
LoadToolBar(frame_, name) call below. One way of resolving it would be to
use LoadToolBar(frame_, name) for the menu as well -- and I don't see any
reason why we shouldn't do it like this. We'd simply call AdjustMenus() on
the menu bar already attached to the frame instead of doing it before
attaching it but nothing needs to be changed otherwise. I.e. the change
would be to just replace

-    frame_->SetMenuBar(AdjustMenus(menu_bar));


+    AdjustMenus(menu_bar);

Notice that SetMenuBar() becomes unnecessary and that SetToolBar() is
unnecessary already as LoadToolBar() calls it already. So the full patch I
propose is

--- main_wx.cpp 2008-08-07 21:00:19 +0000
+++ main_wx.cpp 2008-08-07 22:55:26 +0000
@@ -486,7 +486,7 @@

 void Skeleton::InitMenuBar()
-    wxMenuBar* menu_bar = wxXmlResource::Get()->LoadMenuBar("main_menu");
+    wxMenuBar* menu_bar = wxXmlResource::Get()->LoadMenuBar(frame_, 
         fatal_error() << "Unable to create menubar." << LMI_FLUSH;
@@ -495,12 +495,9 @@
-    frame_->SetMenuBar(AdjustMenus(menu_bar));
+    AdjustMenus(menu_bar);

-// WX !! It seems odd that LoadMenuBar has two signatures, the simpler
-// of which requires no 'parent' argument, while LoadToolBar does not.
 void Skeleton::InitToolBar()
     wxToolBar* tool_bar = wxXmlResource::Get()->LoadToolBar(frame_, "toolbar");
@@ -508,7 +505,6 @@
         fatal_error() << "Unable to create toolbar." << LMI_FLUSH;
-    frame_->SetToolBar(tool_bar);

 void Skeleton::UponAbout(wxCommandEvent&)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]