From 065de61268db77ee2424fdba219a25baaece0265 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 30 Nov 1999 12:21:06 +0000 Subject: [PATCH] Now allow SetMenuBar to be called several times. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4771 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/frame.cpp | 33 +++++++++++++++++++++++++++++++++ src/msw/menu.cpp | 4 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index aa75762ebc..0472a949b6 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -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() diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index dc9f5dfba6..7b85d29927 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -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; -- 2.45.2