From 292cc8c93e347d14c4b27015bd6048110819cafc Mon Sep 17 00:00:00 2001 From: Ron Lee Date: Tue, 1 Oct 2002 15:13:44 +0000 Subject: [PATCH] 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 --- include/wx/gtk/frame.h | 6 ++++++ include/wx/gtk1/frame.h | 6 ++++++ src/gtk/frame.cpp | 28 ++++++++++++++++++++-------- src/gtk/menu.cpp | 23 +++++++++++++++++++++++ src/gtk1/frame.cpp | 28 ++++++++++++++++++++-------- src/gtk1/menu.cpp | 23 +++++++++++++++++++++++ 6 files changed, 98 insertions(+), 16 deletions(-) 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; }