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
This commit is contained in:
@@ -407,6 +407,38 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
|
|||||||
return;
|
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") );
|
wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
|
||||||
|
|
||||||
if (m_frameMenuBar)
|
if (m_frameMenuBar)
|
||||||
@@ -421,6 +453,7 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
|
|||||||
|
|
||||||
m_frameMenuBar = menu_bar;
|
m_frameMenuBar = menu_bar;
|
||||||
menu_bar->Attach(this);
|
menu_bar->Attach(this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFrame::InternalSetMenuBar()
|
void wxFrame::InternalSetMenuBar()
|
||||||
|
@@ -532,7 +532,7 @@ wxMenuBar::~wxMenuBar()
|
|||||||
|
|
||||||
void wxMenuBar::Refresh()
|
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));
|
DrawMenuBar(GetHwndOf(m_menuBarFrame));
|
||||||
}
|
}
|
||||||
@@ -819,7 +819,7 @@ void wxMenuBar::RebuildAccelTable()
|
|||||||
|
|
||||||
void wxMenuBar::Attach(wxFrame *frame)
|
void wxMenuBar::Attach(wxFrame *frame)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
|
// wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
|
||||||
|
|
||||||
m_menuBarFrame = frame;
|
m_menuBarFrame = frame;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user