From 86f504ee014d17172267f14742b8edd5789cbbc6 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 15 Mar 2016 20:44:50 +0000 Subject: Related: tdf#98637 make this a tractable problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just too hard, it would all be much easier if the ActionGroup existed right from the start of the entire process. So smuggle in to the ctor the toplevel frame that the menubar will be inserted into so we can use its ActionGroup from the start. That would suggest that we could then just keep the hierarchy in sync as it is created rather than finding opportune moments to update /generate it. Change-Id: I550f94a994210423ab9cea1986e643056cb5bd29 Reviewed-on: https://gerrit.libreoffice.org/23287 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- vcl/unx/gtk/gtkinst.cxx | 19 +++++++++++++++++-- vcl/unx/gtk/gtksalmenu.cxx | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'vcl/unx') diff --git a/vcl/unx/gtk/gtkinst.cxx b/vcl/unx/gtk/gtkinst.cxx index a37102e0f30f..eacc457b1350 100644 --- a/vcl/unx/gtk/gtkinst.cxx +++ b/vcl/unx/gtk/gtkinst.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -347,10 +348,24 @@ SalBitmap* GtkInstance::CreateSalBitmap() #ifdef ENABLE_GMENU_INTEGRATION -SalMenu* GtkInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu ) +SalMenu* GtkInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu, SystemWindow* pAssociatedSystemWindow ) { EnsureInit(); - GtkSalMenu* pSalMenu = new GtkSalMenu( bMenuBar ); + + GtkSalFrame *pFrame = pAssociatedSystemWindow ? dynamic_cast(pAssociatedSystemWindow->ImplGetFrame()) + : nullptr; + + GActionGroup* pActionGroup; + if (pFrame) + { + GtkWidget* pWidget = pFrame->getWindow(); + GdkWindow* gdkWindow = gtk_widget_get_window( pWidget ); + pActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) ); + } + else + pActionGroup = nullptr; + + GtkSalMenu* pSalMenu = new GtkSalMenu(bMenuBar, pActionGroup); pSalMenu->SetMenu( pVCLMenu ); return pSalMenu; } diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 204415564b96..0378b49f45e0 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -456,16 +456,26 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& rRec * GtkSalMenu */ -GtkSalMenu::GtkSalMenu( bool bMenuBar ) : +GtkSalMenu::GtkSalMenu( bool bMenuBar, GActionGroup *pActionGroup ) : mbMenuBar( bMenuBar ), mpMenuBarWidget( nullptr ), mpCloseButton( nullptr ), mpVCLMenu( nullptr ), mpParentSalMenu( nullptr ), mpFrame( nullptr ), - mpMenuModel( nullptr ), - mpActionGroup( nullptr ) + mpActionGroup(pActionGroup) { + if (bMenuBar) + mpMenuModel = G_MENU_MODEL(g_lo_menu_new()); + else + mpMenuModel = nullptr; + + GLOActionGroup* pLOActionGroup = G_LO_ACTION_GROUP( mpActionGroup ); + if (pLOActionGroup) + { + g_lo_action_group_clear(pLOActionGroup); + g_lo_action_group_set_top_menu(pLOActionGroup, static_cast(this)); + } } void GtkSalMenu::SetMenuModel(GMenuModel* pMenuModel) @@ -664,22 +674,12 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame) GdkWindow* gdkWindow = gtk_widget_get_window( pWidget ); GLOMenu* pMenuModel = G_LO_MENU( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) ); - GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) ); - SAL_INFO("vcl.unity", "Found menu model: " << pMenuModel << " and action group: " << pActionGroup); + SAL_INFO("vcl.unity", "Found menu model: " << pMenuModel); if ( pMenuModel ) { if ( g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 ) g_lo_menu_remove( pMenuModel, 0 ); - - mpMenuModel = G_MENU_MODEL( g_lo_menu_new() ); - } - - if ( pActionGroup ) - { - g_lo_action_group_clear( pActionGroup ); - g_lo_action_group_set_top_menu(pActionGroup, static_cast(this)); - mpActionGroup = G_ACTION_GROUP( pActionGroup ); } // Generate the main menu structure. -- cgit