diff options
-rw-r--r-- | vcl/unx/gtk/window/gloactiongroup.cxx | 1 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtksalmenu.cxx | 65 |
2 files changed, 58 insertions, 8 deletions
diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx index 51bf2f0b48f6..a409015c7ac5 100644 --- a/vcl/unx/gtk/window/gloactiongroup.cxx +++ b/vcl/unx/gtk/window/gloactiongroup.cxx @@ -244,7 +244,6 @@ g_lo_action_group_set_action_enabled (GLOActionGroup *group, const gchar *action_name, gboolean enabled) { - cout << __FUNCTION__ << " - " << action_name << endl; g_return_if_fail (G_IS_LO_ACTION_GROUP (group)); g_action_group_action_enabled_changed(G_ACTION_GROUP(group), diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index a82dbe22d4df..d682fbef2d36 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -48,13 +48,17 @@ void updateNativeMenu( GtkSalMenu* pMenu ) { // Force updating of native menu labels. pMenu->SetItemText( i, pSalMenuItem, aText ); - if ( pSalMenuItem->mpSubMenu && pSalMenuItem->mpSubMenu->GetMenu() ) { - pSalMenuItem->mpSubMenu->GetMenu()->Activate(); - updateNativeMenu( pSalMenuItem->mpSubMenu ); - - // FIXME: Using Deactivate() let the menu to update itself correctly, but generates - // duplicated popup menus. -// pSalMenuItem->mpSubMenu->GetMenu()->Deactivate(); + KeyCode nAccelKey = pSalMenuItem->mpVCLMenu->GetAccelKey( pSalMenuItem->mnId ); + pMenu->SetAccelerator( i, pSalMenuItem, nAccelKey, nAccelKey.GetName( pMenu->GetFrame()->GetWindow() ) ); + + if ( isSpecialSubmenu( rtl::OUString::createFromAscii( pSalMenuItem->maCommand ) ) == FALSE ) { + if ( pSalMenuItem->mpSubMenu && pSalMenuItem->mpSubMenu->GetMenu() ) { + pSalMenuItem->mpSubMenu->GetMenu()->Activate(); + // FIXME: Using Deactivate() let the menu to update itself correctly, but generates + // duplicated popup menus. + pSalMenuItem->mpSubMenu->GetMenu()->Deactivate(); + updateNativeMenu( pSalMenuItem->mpSubMenu ); + } } } } @@ -112,6 +116,30 @@ GActionGroup* GetActionGroupFromMenubar( GtkSalMenu *pMenu ) return ( pSalMenu ) ? pSalMenu->GetActionGroup() : NULL; } +rtl::OUString GetGtkKeyName( rtl::OUString keyName ) +{ + rtl::OUString aGtkKeyName(""); + + sal_Int32 nIndex = 0; + + do + { + rtl::OUString token = keyName.getToken( 0, '+', nIndex ); + + if ( token == "Ctrl" ) { + aGtkKeyName += "<Control>"; + } else if ( token == "Alt" ) { + aGtkKeyName += "<Alt>"; + } else if ( token == "Shift" ) { + aGtkKeyName += "<Shift>"; + } else { + aGtkKeyName += token; + } + } while ( nIndex >= 0 ); + + return aGtkKeyName; +} + /* * GtkSalMenu */ @@ -432,6 +460,29 @@ void GtkSalMenu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const I void GtkSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const rtl::OUString& rKeyName ) { + GtkSalMenuItem *pGtkSalMenuItem = static_cast< GtkSalMenuItem* >( pSalMenuItem ); + + if ( rKeyName.isEmpty() ) + return; + + rtl::OString aAccelerator = rtl::OUStringToOString( GetGtkKeyName( rKeyName ), RTL_TEXTENCODING_UTF8 ); + + GVariant* aCurrentAccel = g_menu_model_get_item_attribute_value( pGtkSalMenuItem->mpParentSection, pGtkSalMenuItem->mnPos, "accel", G_VARIANT_TYPE_STRING ); + + sal_Bool bSetAccel = sal_True; + + if ( aCurrentAccel ) { + if ( g_strcmp0( g_variant_get_string( aCurrentAccel, NULL ), aAccelerator.getStr() ) == 0 ) { + bSetAccel = sal_False; + } + } + + if ( bSetAccel == sal_True ) { + g_lo_menu_item_set_attribute_value( pGtkSalMenuItem->mpMenuItem, "accel", g_variant_new_string( aAccelerator.getStr() ) ); + + g_lo_menu_remove( G_LO_MENU( pGtkSalMenuItem->mpParentSection), pGtkSalMenuItem->mnPos ); + g_lo_menu_insert_item( G_LO_MENU( pGtkSalMenuItem->mpParentSection ), pGtkSalMenuItem->mnPos, pGtkSalMenuItem->mpMenuItem ); + } } void GtkSalMenu::SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& aCommandStr ) |