[Libreoffice-commits] .: Branch 'feature/unitymenus' - vcl/inc vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Aug 26 15:56:27 PDT 2012


 vcl/inc/unx/gtk/glomenu.h             |    5 +
 vcl/inc/unx/gtk/gtksalmenu.hxx        |    7 +-
 vcl/unx/gtk/window/gloactiongroup.cxx |   18 +----
 vcl/unx/gtk/window/glomenu.cxx        |   26 +++++++
 vcl/unx/gtk/window/gtksalmenu.cxx     |  114 +++++++++++++++-------------------
 5 files changed, 94 insertions(+), 76 deletions(-)

New commits:
commit 21ac6ddb95d0e51a2ffe5ed85ca470fa663428bf
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date:   Sun Aug 26 23:53:56 2012 +0100

    Added code for accelerators and special items.
    
    Change-Id: Ibd62c4655d671e2920dea5140df8f481c2892fbb

diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h
index 9c4801f..21c048f 100644
--- a/vcl/inc/unx/gtk/glomenu.h
+++ b/vcl/inc/unx/gtk/glomenu.h
@@ -97,6 +97,11 @@ void        g_lo_menu_set_action_and_target_value_to_item_in_section    (GLOMenu
                                                                          const gchar *command,
                                                                          GVariant    *target_value);
 
+void        g_lo_menu_set_accelerator_to_item_in_section                (GLOMenu     *menu,
+                                                                         gint         section,
+                                                                         gint         position,
+                                                                         const gchar *accelerator);
+
 void        g_lo_menu_set_submenu_to_item_in_section                    (GLOMenu     *menu,
                                                                          gint         section,
                                                                          gint         position,
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 0e21313..324b430 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -93,11 +93,14 @@ public:
     sal_uInt16          mnId;               // Item ID
     MenuItemBits        mnBits;             // Item bits
     MenuItemType        mnType;             // Item type
-    gchar*              maCommand;          // Item command
-    gchar*              maLabel;            // Item label
     Menu*               mpVCLMenu;          // VCL Menu into which this MenuItem is inserted
     GtkSalMenu*         mpParentMenu;       // The menu in which this menu item is inserted
     GtkSalMenu*         mpSubMenu;          // Sub menu of this item (if defined)
+
+    // FIXME: Most of this info should be retrieved from the GMenuModel, but doing that crashes the application at the moment.
+    gchar*              maCommand;          // Item command
+    gchar*              maLabel;            // Item label
+    gchar*              maAccel;            // Item accelerator
 };
 
 #endif // GTKSALMENU_HXX
diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx
index 443c628..1a0e88f 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 e4122d5..77be471 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 507849c..c79bbb8 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: */


More information about the Libreoffice-commits mailing list