summaryrefslogtreecommitdiff
path: root/vcl/unx/gtk
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-08-26 23:53:56 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:44 +0100
commit1475c67cc5552e9fa9a8e613eb7a034e489cf0d3 (patch)
tree5114eb7e08f81a68d03df2b48688ba94f03a572e /vcl/unx/gtk
parent3411a8a23a1cda4fecaaf3dd2b3e83082b6419d0 (diff)
Added code for accelerators and special items.
Change-Id: Ibd62c4655d671e2920dea5140df8f481c2892fbb
Diffstat (limited to 'vcl/unx/gtk')
-rw-r--r--vcl/unx/gtk/window/gloactiongroup.cxx18
-rw-r--r--vcl/unx/gtk/window/glomenu.cxx26
-rw-r--r--vcl/unx/gtk/window/gtksalmenu.cxx114
3 files changed, 84 insertions, 74 deletions
diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx
index 443c628c8c7b..1a0e88fbd107 100644
--- a/vcl/unx/gtk/window/gloactiongroup.cxx
+++ b/vcl/unx/gtk/window/gloactiongroup.cxx
@@ -70,7 +70,7 @@ static void
g_lo_action_init (GLOAction *action)
{
action->item = NULL;
- action->enabled = FALSE;
+ action->enabled = TRUE;
action->parameter_type = NULL;
action->state_type = NULL;
action->state_hint = NULL;
@@ -84,25 +84,17 @@ g_lo_action_finalize (GObject *object)
action->item = NULL;
- if (action->parameter_type) {
+ if (action->parameter_type)
g_variant_type_free (action->parameter_type);
- action->parameter_type = NULL;
- }
- if (action->state_type) {
+ if (action->state_type)
g_variant_type_free (action->state_type);
- action->state_type = NULL;
- }
- if (action->state_hint) {
+ if (action->state_hint)
g_variant_unref (action->state_hint);
- action->state_hint = NULL;
- }
- if (action->state) {
+ if (action->state)
g_variant_unref (action->state);
- action->state = NULL;
- }
G_OBJECT_CLASS (g_lo_action_parent_class)->finalize (object);
}
diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx
index e4122d5a4d49..77be47139cc7 100644
--- a/vcl/unx/gtk/window/glomenu.cxx
+++ b/vcl/unx/gtk/window/glomenu.cxx
@@ -299,6 +299,32 @@ g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu *menu,
}
void
+g_lo_menu_set_accelerator_to_item_in_section (GLOMenu *menu,
+ gint section,
+ gint position,
+ const gchar *accelerator)
+{
+ g_return_if_fail (G_IS_LO_MENU (menu));
+
+ GMenuModel *model = G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
+ ->get_item_link (G_MENU_MODEL (menu), section, G_MENU_LINK_SECTION);
+
+ g_return_if_fail (model != NULL);
+
+ GVariant *value;
+
+ if (accelerator != NULL)
+ value = g_variant_new_string (accelerator);
+ else
+ value = NULL;
+
+ g_lo_menu_set_attribute_value (G_LO_MENU (model), position, "accel", value);
+
+ // Notify the update.
+ g_menu_model_items_changed (model, position, 1, 1);
+}
+
+void
g_lo_menu_set_link (GLOMenu *menu,
gint position,
const gchar *link,
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index 507849ca41aa..c79bbb8ae67f 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -79,8 +79,8 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu ) {
pMenu->SetItemCommand( i, pSalMenuItem, aCommand );
pMenu->SetItemText( i, pSalMenuItem, aText );
pMenu->EnableItem( i, itemEnabled );
-// pMenu->SetAccelerator( i, pSalMenuItem, nAccelKey, nAccelKey.GetName( pMenu->GetFrame()->GetWindow() ) );
-// pMenu->CheckItem( i, itemChecked );
+ pMenu->SetAccelerator( i, pSalMenuItem, nAccelKey, nAccelKey.GetName( pMenu->GetFrame()->GetWindow() ) );
+ pMenu->CheckItem( i, itemChecked );
GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu;
@@ -144,29 +144,30 @@ GActionGroup* GetActionGroupFromMenubar( GtkSalMenu *pMenu )
return ( pSalMenu ) ? pSalMenu->GetActionGroup() : NULL;
}
-//rtl::OUString GetGtkKeyName( rtl::OUString keyName )
-//{
-// rtl::OUString aGtkKeyName("");
+// FIXME: Check for missing keys. Maybe translating keycodes would be safer...
+rtl::OUString GetGtkKeyName( rtl::OUString keyName )
+{
+ rtl::OUString aGtkKeyName("");
-// sal_Int32 nIndex = 0;
+ 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 );
+ 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;
-//}
+ return aGtkKeyName;
+}
//GVariant* GetRadionButtonHints( GtkSalMenuItem *pSalMenuItem )
//{
@@ -248,10 +249,6 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
mpMenuModel( NULL ),
mpActionGroup( NULL )
{
- if (bMenuBar) {
-// mpActionGroup = G_ACTION_GROUP( g_lo_action_group_new() );
- }
-
mpMenuModel = G_MENU_MODEL( g_lo_menu_new() );
g_lo_menu_new_section( G_LO_MENU( mpMenuModel ), 0, NULL);
}
@@ -264,12 +261,7 @@ GtkSalMenu::~GtkSalMenu()
if ( mbMenuBar ) {
g_source_remove_by_user_data( this );
-
-// GLOMenu* pMainMenu = G_LO_MENU( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) );
-
g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 );
-// g_lo_menu_remove( pMainMenu, 0 );
-// mpMenuModel = NULL;
} else {
g_object_unref( mpMenuModel );
}
@@ -389,11 +381,6 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
GDBusConnection* pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
if(!pSessionBus) puts ("Failed to get DBus session connection");
- gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
- gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "" );
- gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath );
- gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath );
-
// Publish the menu.
if ( aDBusMenubarPath ) {
sal_uInt16 menubarId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, G_MENU_MODEL( pMainMenu ), NULL);
@@ -405,6 +392,13 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
if(!actionGroupId) puts("Failed to export action group");
}
+ // Set window properties.
+ gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
+ gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "" );
+ gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath );
+ gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath );
+
+
g_free( aDBusPath );
g_free( aDBusWindowPath );
g_free( aDBusMenubarPath );
@@ -492,7 +486,7 @@ void GtkSalMenu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rt
GtkSalMenuItem* pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem );
- // FIXME: It would be better retrieving the label from the menu itself, but this currently crashes the app.
+ // FIXME: It would be better retrieving the label from the menu itself, but it currently crashes the app.
if ( pItem->maLabel && g_strcmp0( pItem->maLabel, aConvertedText.getStr() ) == 0 )
bSetLabel = sal_False;
@@ -511,34 +505,28 @@ void GtkSalMenu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const I
void GtkSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const rtl::OUString& rKeyName )
{
-// GtkSalMenuItem *pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem );
+ GtkSalMenuItem *pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem );
-// if ( rKeyName.isEmpty() )
-// return;
+ if ( rKeyName.isEmpty() )
+ return;
-// rtl::OString aAccelerator = rtl::OUStringToOString( GetGtkKeyName( rKeyName ), RTL_TEXTENCODING_UTF8 );
+ rtl::OString aAccelerator = rtl::OUStringToOString( GetGtkKeyName( rKeyName ), RTL_TEXTENCODING_UTF8 );
-// unsigned nSection, nItemPos;
-// GetInsertionData( nPos, &nSection, &nItemPos );
+ unsigned nSection, nItemPos;
+ GetItemSectionAndPosition( nPos, &nSection, &nItemPos );
-// GLOMenu* pSection = G_LO_MENU( maSections[ nSection ] );
+ sal_Bool bSetAccel = sal_True;
-// GVariant* aCurrentAccel = g_menu_model_get_item_attribute_value( G_MENU_MODEL( pSection ), nItemPos, "accel", G_VARIANT_TYPE_STRING );
+ if ( pItem->maAccel && g_strcmp0( pItem->maAccel, aAccelerator.getStr() ) == 0 )
+ bSetAccel = sal_False;
-// sal_Bool bSetAccel = sal_True;
+ if ( bSetAccel == sal_True ) {
+ if (pItem->maAccel)
+ g_free( pItem->maAccel );
-// 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( pItem->mpMenuItem, "accel", g_variant_new_string( aAccelerator.getStr() ) );
-
-// g_lo_menu_remove( pSection, nItemPos );
-// g_lo_menu_insert_item( pSection, nItemPos, pItem );
-// }
+ pItem->maAccel = g_strdup( aAccelerator.getStr() );
+ g_lo_menu_set_accelerator_to_item_in_section ( G_LO_MENU( mpMenuModel ), nSection, nItemPos, pItem->maAccel );
+ }
}
void GtkSalMenu::SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& aCommandStr )
@@ -624,11 +612,12 @@ GtkSalMenuItem::GtkSalMenuItem( const SalItemParams* pItemData ) :
mnId( pItemData->nId ),
mnBits( pItemData->nBits ),
mnType( pItemData->eType ),
- maCommand( NULL ),
- maLabel( NULL ),
mpVCLMenu( pItemData->pMenu ),
mpParentMenu( NULL ),
- mpSubMenu( NULL )
+ mpSubMenu( NULL ),
+ maCommand( NULL ),
+ maLabel( NULL ),
+ maAccel( NULL )
{
}
@@ -639,6 +628,9 @@ GtkSalMenuItem::~GtkSalMenuItem()
if ( maLabel )
g_free( maLabel );
+
+ if ( maAccel )
+ g_free( maAccel );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */