]> git.saurik.com Git - wxWidgets.git/commitdiff
Now allow SetMenuBar to be called several times.
authorJulian Smart <julian@anthemion.co.uk>
Tue, 30 Nov 1999 12:21:06 +0000 (12:21 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 30 Nov 1999 12:21:06 +0000 (12:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4771 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/frame.cpp
src/msw/menu.cpp

index aa75762ebc54e6ad1072eaa888fbd8680157d6b1..0472a949b6944a2867fecffcb541ce84694b1cf4 100644 (file)
@@ -407,6 +407,38 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
         return;
     }
 
+    m_frameMenuBar = NULL;
+
+    // Can set a menubar several times.
+    // TODO: how to prevent a memory leak if you have a currently-unattached
+    // menubar? wxWindows assumes that the frame will delete the menu (otherwise
+    // there are problems for MDI).
+    if (menu_bar->GetHMenu())
+    {
+        m_hMenu = menu_bar->GetHMenu();
+    }
+    else
+    {
+        menu_bar->Detach();
+
+        m_hMenu = menu_bar->Create();
+
+        if ( !m_hMenu )
+            return;
+    }
+
+    InternalSetMenuBar();
+
+    m_frameMenuBar = menu_bar;
+    menu_bar->Attach(this);
+
+#if 0 // Old code that assumes only one call of SetMenuBar per frame.
+    if (!menu_bar)
+    {
+        DetachMenuBar();
+        return;
+    }
+
     wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
 
     if (m_frameMenuBar)
@@ -421,6 +453,7 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
 
     m_frameMenuBar = menu_bar;
     menu_bar->Attach(this);
+#endif
 }
 
 void wxFrame::InternalSetMenuBar()
index dc9f5dfba612bc45e0efd185ea5228aad63c1781..7b85d299277d252f4988addeed3cab503a6b8bd2 100644 (file)
@@ -532,7 +532,7 @@ wxMenuBar::~wxMenuBar()
 
 void wxMenuBar::Refresh()
 {
-    wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
+    wxCHECK_RET( IsAttached(), wxT("can't refresh unattached menubar") );
 
     DrawMenuBar(GetHwndOf(m_menuBarFrame));
 }
@@ -819,7 +819,7 @@ void wxMenuBar::RebuildAccelTable()
 
 void wxMenuBar::Attach(wxFrame *frame)
 {
-    wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
+//    wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
 
     m_menuBarFrame = frame;