The menubar dynamic sizing patch broke any app which adds an empty
menubar and populates it later. Since this is (or at least was) a valid way to use wxMenuBar before that, we need to recalculate the size whenever it might change. (We probably need to do it anyway for this to be completely useful). This patch isn't the cleanest or most efficient way to do that, but it's a minimal change on a new feature that at least restores compatibility. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17417 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -96,8 +96,14 @@ protected:
|
||||
virtual void DoGetClientSize( int *width, int *height ) const;
|
||||
|
||||
#if wxUSE_MENUS_NATIVE
|
||||
|
||||
virtual void DetachMenuBar();
|
||||
virtual void AttachMenuBar(wxMenuBar *menubar);
|
||||
|
||||
public:
|
||||
// Menu size is dynamic now, call this whenever it might change.
|
||||
void UpdateMenuBarSize();
|
||||
|
||||
#endif // wxUSE_MENUS_NATIVE
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxFrame)
|
||||
|
@@ -96,8 +96,14 @@ protected:
|
||||
virtual void DoGetClientSize( int *width, int *height ) const;
|
||||
|
||||
#if wxUSE_MENUS_NATIVE
|
||||
|
||||
virtual void DetachMenuBar();
|
||||
virtual void AttachMenuBar(wxMenuBar *menubar);
|
||||
|
||||
public:
|
||||
// Menu size is dynamic now, call this whenever it might change.
|
||||
void UpdateMenuBarSize();
|
||||
|
||||
#endif // wxUSE_MENUS_NATIVE
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxFrame)
|
||||
|
@@ -579,19 +579,31 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
|
||||
|
||||
m_frameMenuBar->Show( TRUE );
|
||||
|
||||
GtkRequisition req;
|
||||
req.width = 2;
|
||||
req.height = 2;
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
|
||||
(m_frameMenuBar->m_widget, &req );
|
||||
m_menuBarHeight = req.height;
|
||||
UpdateMenuBarSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_menuBarHeight = 2;
|
||||
GtkUpdateSize(); // resize window in OnInternalIdle
|
||||
}
|
||||
}
|
||||
|
||||
void wxFrame::UpdateMenuBarSize()
|
||||
{
|
||||
wxASSERT_MSG( m_frameMenuBar, _T("Updating non existant menubar?") );
|
||||
|
||||
GtkRequisition req;
|
||||
|
||||
req.width = 2;
|
||||
req.height = 2;
|
||||
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
|
||||
(m_frameMenuBar->m_widget, &req );
|
||||
|
||||
m_menuBarHeight = req.height;
|
||||
|
||||
// resize window in OnInternalIdle
|
||||
|
||||
GtkUpdateSize();
|
||||
}
|
||||
|
||||
|
@@ -387,8 +387,21 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title)
|
||||
// m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
|
||||
// adding menu later on.
|
||||
if (m_invokingWindow)
|
||||
{
|
||||
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
|
||||
|
||||
// OPTIMISE ME: we should probably cache this, or pass it
|
||||
// directly, but for now this is a minimal
|
||||
// change to validate the new dynamic sizing.
|
||||
// see (and refactor :) similar code in Remove
|
||||
// below.
|
||||
|
||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
||||
|
||||
if( frame )
|
||||
frame->UpdateMenuBarSize();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -452,6 +465,16 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
||||
printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) );
|
||||
*/
|
||||
|
||||
if (m_invokingWindow)
|
||||
{
|
||||
// OPTIMISE ME: see comment in GtkAppend
|
||||
|
||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
||||
|
||||
if( frame )
|
||||
frame->UpdateMenuBarSize();
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
@@ -579,19 +579,31 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
|
||||
|
||||
m_frameMenuBar->Show( TRUE );
|
||||
|
||||
GtkRequisition req;
|
||||
req.width = 2;
|
||||
req.height = 2;
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
|
||||
(m_frameMenuBar->m_widget, &req );
|
||||
m_menuBarHeight = req.height;
|
||||
UpdateMenuBarSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_menuBarHeight = 2;
|
||||
GtkUpdateSize(); // resize window in OnInternalIdle
|
||||
}
|
||||
}
|
||||
|
||||
void wxFrame::UpdateMenuBarSize()
|
||||
{
|
||||
wxASSERT_MSG( m_frameMenuBar, _T("Updating non existant menubar?") );
|
||||
|
||||
GtkRequisition req;
|
||||
|
||||
req.width = 2;
|
||||
req.height = 2;
|
||||
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
|
||||
(m_frameMenuBar->m_widget, &req );
|
||||
|
||||
m_menuBarHeight = req.height;
|
||||
|
||||
// resize window in OnInternalIdle
|
||||
|
||||
GtkUpdateSize();
|
||||
}
|
||||
|
||||
|
@@ -387,8 +387,21 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title)
|
||||
// m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
|
||||
// adding menu later on.
|
||||
if (m_invokingWindow)
|
||||
{
|
||||
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
|
||||
|
||||
// OPTIMISE ME: we should probably cache this, or pass it
|
||||
// directly, but for now this is a minimal
|
||||
// change to validate the new dynamic sizing.
|
||||
// see (and refactor :) similar code in Remove
|
||||
// below.
|
||||
|
||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
||||
|
||||
if( frame )
|
||||
frame->UpdateMenuBarSize();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -452,6 +465,16 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
||||
printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) );
|
||||
*/
|
||||
|
||||
if (m_invokingWindow)
|
||||
{
|
||||
// OPTIMISE ME: see comment in GtkAppend
|
||||
|
||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
||||
|
||||
if( frame )
|
||||
frame->UpdateMenuBarSize();
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user