summaryrefslogtreecommitdiff
path: root/vcl/unx/gtk
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-08-20 14:22:30 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:43 +0100
commit7a22cf8f880944aace65e81f56dd988dec5d0269 (patch)
tree74cfe729f299cfa24f2a194418756c6c2d9b57ff /vcl/unx/gtk
parent25db814902b123a3d5e4708f0da3daf606f7537d (diff)
Accelerator string is now set, but not displayed.
Change-Id: I8b1f83df1d121b1d6e126b9f10772a90f26d0efd
Diffstat (limited to 'vcl/unx/gtk')
-rw-r--r--vcl/unx/gtk/window/gloactiongroup.cxx1
-rw-r--r--vcl/unx/gtk/window/gtksalmenu.cxx65
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 )