diff --git a/include/wx/gtk/frame.h b/include/wx/gtk/frame.h index 6f04f1546a..d4ec4bc940 100644 --- a/include/wx/gtk/frame.h +++ b/include/wx/gtk/frame.h @@ -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) diff --git a/include/wx/gtk1/frame.h b/include/wx/gtk1/frame.h index 6f04f1546a..d4ec4bc940 100644 --- a/include/wx/gtk1/frame.h +++ b/include/wx/gtk1/frame.h @@ -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) diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 2df0917868..641fe09094 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -578,20 +578,32 @@ 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 - // resize window in OnInternalIdle GtkUpdateSize(); } diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 886522158e..24b1885cee 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -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; } diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index 2df0917868..641fe09094 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -578,20 +578,32 @@ 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 - // resize window in OnInternalIdle GtkUpdateSize(); } diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 886522158e..24b1885cee 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -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; }