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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 18 11:39:48 PDT 2012


 vcl/inc/unx/gtk/glomenu.h         |    4 +
 vcl/inc/unx/gtk/gtksalmenu.hxx    |    3 -
 vcl/unx/gtk/window/glomenu.cxx    |   67 +++++++++++++++++------------
 vcl/unx/gtk/window/gtkframe.cxx   |   39 +++++------------
 vcl/unx/gtk/window/gtksalmenu.cxx |   86 ++++++++++++++++++--------------------
 5 files changed, 101 insertions(+), 98 deletions(-)

New commits:
commit 58aa567b30853f52661f8365d091f16fac0f7fff
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date:   Thu Oct 18 19:35:02 2012 +0100

    Removed the declaration of FlushConnection method in GtkSalFrame.
    
    Change-Id: I22262dd1655405ca9707a69bc036c900940d7df0

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 2f1817e..93b043d 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -312,7 +312,6 @@ public:
 
     guint                           m_nMenuExportId;
     guint                           m_nActionGroupExportId;
-    void FlushConnection();
 
     // dispatches an event, returns true if dispatched
     // and false else; if true was returned the event should
commit 9a5f6298b9d19d55e4d508877cd623110bcd0cfe
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date:   Thu Oct 18 19:31:16 2012 +0100

    Fixed menu visibility and cleaned up some code.
    
    Change-Id: Ibda3c5d6f50d12041065f28ddd41eab57ae9560e

diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx
index 9f65f37..756779a 100644
--- a/vcl/unx/gtk/window/gloactiongroup.cxx
+++ b/vcl/unx/gtk/window/gloactiongroup.cxx
@@ -255,8 +255,6 @@ g_lo_action_group_activate (GActionGroup *group,
 {
     GTK_YIELD_GRAB();
 
-    printf("%s\n", __FUNCTION__);
-
     GLOActionGroup *lo_group = G_LO_ACTION_GROUP (group);
     GtkSalFrame *pFrame = lo_group->priv->frame;
 
diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx
index cc84889..e804ff9 100644
--- a/vcl/unx/gtk/window/glomenu.cxx
+++ b/vcl/unx/gtk/window/glomenu.cxx
@@ -100,12 +100,10 @@ g_lo_menu_is_mutable (GMenuModel*)
 static gint
 g_lo_menu_get_n_items (GMenuModel *model)
 {
-    //printf("[%p] %s\n", model, __FUNCTION__);
     g_return_val_if_fail (model != NULL, 0);
     GLOMenu *menu = G_LO_MENU (model);
     g_return_val_if_fail (menu->items != NULL, 0);
 
-    //printf("[%p] %s - length: %d\n", model, __FUNCTION__, menu->items->len);
     return menu->items->len;
 }
 
@@ -113,7 +111,6 @@ gint
 g_lo_menu_get_n_items_from_section (GLOMenu *menu,
                                     gint     section)
 {
-    //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, section);
     g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, 0);
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
@@ -124,7 +121,6 @@ g_lo_menu_get_n_items_from_section (GLOMenu *menu,
 
     g_object_unref (model);
 
-    //printf("[%p] %s - section: %d - length: %d\n", menu, __FUNCTION__, section, length);
     return length;
 }
 
@@ -134,9 +130,7 @@ g_lo_menu_get_item_attributes (GMenuModel  *model,
                                GHashTable **table)
 {
     GLOMenu *menu = G_LO_MENU (model);
-
     *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).attributes);
-    //printf("[%p] %s - position: %d - table: %p - *table: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL));
 }
 
 static void
@@ -145,9 +139,7 @@ g_lo_menu_get_item_links (GMenuModel  *model,
                           GHashTable **table)
 {
     GLOMenu *menu = G_LO_MENU (model);
-
     *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).links);
-    //printf("[%p] %s - position: %d - table: %p - *table: %p - items: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL), ((menu) ? menu->items : NULL));
 }
 
 void
@@ -164,7 +156,6 @@ g_lo_menu_insert_in_section (GLOMenu     *menu,
                              gint         position,
                              const gchar *label)
 {
-    //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -189,7 +180,6 @@ g_lo_menu_set_attribute_value (GLOMenu     *menu,
                                const gchar *attribute,
                                GVariant    *value)
 {
-    //printf("[%p] %s - position: %d - attribute: %s - value: %p\n", menu, __FUNCTION__, position, attribute, value);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (attribute != NULL);
     g_return_if_fail (valid_attribute_name (attribute));
@@ -212,7 +202,6 @@ g_lo_menu_get_attribute_value_from_item_in_section (GLOMenu            *menu,
                                                     const gchar        *attribute,
                                                     const GVariantType *type)
 {
-    //printf("[%p] %s - section: %d - position: %d - attribute: %s - type: %p\n", menu, __FUNCTION__, section, position, attribute, type);
     GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section));
 
     g_return_val_if_fail (model != NULL, NULL);
@@ -232,7 +221,6 @@ g_lo_menu_set_label (GLOMenu     *menu,
                      gint         position,
                      const gchar *label)
 {
-    //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GVariant *value;
@@ -251,19 +239,16 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu     *menu,
                                         gint         position,
                                         const gchar *label)
 {
-    //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
-
     g_lo_menu_set_label (model, position, label);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
 }
@@ -273,7 +258,6 @@ g_lo_menu_get_label_from_item_in_section (GLOMenu *menu,
                                           gint     section,
                                           gint     position)
 {
-    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *label_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -299,7 +283,6 @@ g_lo_menu_set_action_and_target_value (GLOMenu     *menu,
                                        const gchar *action,
                                        GVariant    *target_value)
 {
-    //printf("[%p] %s - position: %d - action: %s - target value: %p\n", menu, __FUNCTION__, position, action, target_value);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GVariant *action_value;
@@ -327,7 +310,6 @@ g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu     *menu,
                                                           const gchar *command,
                                                           GVariant    *target_value)
 {
-    //printf("[%p] %s - section: %d - position: %d - command: %s - target value: %p\n", menu, __FUNCTION__, section, position, command, target_value);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
@@ -345,15 +327,12 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu     *menu,
                                               gint         position,
                                               const gchar *accelerator)
 {
-    //printf("[%p] %s - section: %d - position: %d - accelerator: %s\n", menu, __FUNCTION__, section, position, accelerator);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
-
     GVariant *value;
 
     if (accelerator != NULL)
@@ -364,7 +343,7 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_ACCELERATOR, value);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
 }
@@ -374,7 +353,6 @@ g_lo_menu_get_accelerator_from_item_in_section (GLOMenu *menu,
                                                 gint     section,
                                                 gint     position)
 {
-    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *accel_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -400,15 +378,12 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
                                           gint         position,
                                           const gchar *command)
 {
-    //printf("[%p] %s - section: %d - position: %d - command: %s\n", menu, __FUNCTION__, section, position, command);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
-
     GVariant *value;
 
     if (command != NULL)
@@ -419,7 +394,7 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_COMMAND, value);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
 }
@@ -429,7 +404,6 @@ g_lo_menu_get_command_from_item_in_section (GLOMenu *menu,
                                             gint     section,
                                             gint     position)
 {
-    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *command_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -455,7 +429,6 @@ g_lo_menu_set_link (GLOMenu     *menu,
                     const gchar *link,
                     GMenuModel  *model)
 {
-    //printf("[%p] %s - position: %d - link: %s - model: %p\n", menu, __FUNCTION__, position, link, model);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (link != NULL);
     g_return_if_fail (valid_attribute_name (link));
@@ -463,8 +436,6 @@ g_lo_menu_set_link (GLOMenu     *menu,
     if (position < 0 || position >= (gint) menu->items->len)
         position = menu->items->len - 1;
 
-//    printf ("%s - position: %d\n", __FUNCTION__, position);
-
     struct item menu_item = g_array_index (menu->items, struct item, position);
 
     if (model != NULL)
@@ -479,7 +450,6 @@ g_lo_menu_insert_section (GLOMenu     *menu,
                           const gchar *label,
                           GMenuModel  *section)
 {
-    //printf("[%p] %s - position: %d - label: %s - section: %p\n", menu, __FUNCTION__, position, label, section);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     if (position < 0 || position > (gint) menu->items->len)
@@ -502,7 +472,6 @@ g_lo_menu_new_section (GLOMenu     *menu,
                        gint         position,
                        const gchar *label)
 {
-    //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label);
     GMenuModel *section = G_MENU_MODEL (g_lo_menu_new());
 
     g_lo_menu_insert_section (menu, position, label, section);
@@ -514,7 +483,6 @@ GLOMenu *
 g_lo_menu_get_section (GLOMenu *menu,
                        gint section)
 {
-    //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, section);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     return G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
@@ -532,19 +500,18 @@ g_lo_menu_new_submenu_in_item_in_section (GLOMenu *menu,
     GLOMenu* model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
-    g_return_if_fail (0 <= position && position < model->items->len);
-
-    struct item menu_item = g_array_index (model->items, struct item, position);
 
-    GMenuModel* submenu = G_MENU_MODEL (g_lo_menu_new());
+    if (0 <= position && position < (gint) model->items->len) {
+        GMenuModel* submenu = G_MENU_MODEL (g_lo_menu_new());
 
-    g_lo_menu_set_link (model, position, G_MENU_LINK_SUBMENU, submenu);
+        g_lo_menu_set_link (model, position, G_MENU_LINK_SUBMENU, submenu);
 
-    g_object_unref (submenu);
+        g_object_unref (submenu);
 
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+        g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
-    g_object_unref (model);
+        g_object_unref (model);
+    }
 }
 
 
@@ -554,7 +521,6 @@ g_lo_menu_set_submenu_to_item_in_section (GLOMenu    *menu,
                                           gint        position,
                                           GMenuModel *submenu)
 {
-    printf("[%p] %s (begin) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -568,7 +534,6 @@ g_lo_menu_set_submenu_to_item_in_section (GLOMenu    *menu,
     g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
-    printf("[%p] %s (end) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu);
 }
 
 GLOMenu *
@@ -576,7 +541,6 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu,
                                             gint     section,
                                             gint     position)
 {
-    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
     g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, NULL);
 
@@ -587,10 +551,9 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu,
     GLOMenu *submenu = NULL;
 
     if (0 <= position && position < (gint) model->items->len)
-
-    submenu = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
-                      ->get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU));
-    //submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU);
+        submenu = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
+                ->get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU));
+        //submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU);
 
     g_object_unref (model);
 
@@ -603,15 +566,12 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu     *menu,
                                                  gint         position,
                                                  const gchar *action)
 {
-    //printf("[%p] %s - section: %d - position: %d - action: %s\n", menu, __FUNCTION__, section, position, action);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section));
 
     g_return_if_fail (model != NULL);
 
-    g_menu_model_items_changed (model, position, 1, 0);
-
     GVariant *value;
 
     if (action != NULL)
@@ -622,7 +582,7 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (G_LO_MENU (model), position, G_LO_MENU_ATTRIBUTE_SUBMENU_ACTION, value);
 
     // Notify the update.
-    g_menu_model_items_changed (model, position, 0, 1);
+    g_menu_model_items_changed (model, position, 1, 1);
 
     g_object_unref (model);
 }
@@ -640,7 +600,6 @@ void
 g_lo_menu_remove (GLOMenu *menu,
                   gint     position)
 {
-    //printf("[%p] %s - position: %d\n", menu, __FUNCTION__, position);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= position && position < (gint) menu->items->len);
 
@@ -654,7 +613,6 @@ g_lo_menu_remove_from_section (GLOMenu *menu,
                                gint     section,
                                gint     position)
 {
-    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -670,7 +628,6 @@ g_lo_menu_remove_from_section (GLOMenu *menu,
 static void
 g_lo_menu_finalize (GObject *object)
 {
-    //printf("[%p] %s\n", object, __FUNCTION__);
     GLOMenu *menu = G_LO_MENU (object);
     struct item *items;
     gint n_items;
diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx
index fcc2576..f307a11 100644
--- a/vcl/unx/gtk/window/gtkframe.cxx
+++ b/vcl/unx/gtk/window/gtkframe.cxx
@@ -580,8 +580,8 @@ void on_registrar_available( GDBusConnection * /*connection*/,
     if ( pSalMenu != NULL )
     {
         GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu);
-        //pGtkSalMenu->UpdateNativeMenu();
         pGtkSalMenu->Display( sal_True );
+        pGtkSalMenu->UpdateNativeMenu();
     }
 }
 
@@ -594,24 +594,17 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/,
 
     SAL_INFO("vcl.unity", "on_registrar_unavailable");
 
-    pSessionBus = NULL;
+    //pSessionBus = NULL;
     GtkSalFrame* pSalFrame = reinterpret_cast< GtkSalFrame* >( user_data );
 
     SalMenu* pSalMenu = pSalFrame->GetMenu();
 
     if ( pSalMenu ) {
         GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu );
-//        pGtkSalMenu->DisconnectFrame();
         pGtkSalMenu->Display( sal_False );
     }
 }
 
-void GtkSalFrame::FlushConnection()
-{
-    if (pSessionBus)
-        g_dbus_connection_flush_sync( pSessionBus, NULL, NULL );
-}
-
 void GtkSalFrame::EnsureAppMenuWatch()
 {
     if ( !m_nWatcherId )
@@ -635,7 +628,7 @@ void GtkSalFrame::EnsureAppMenuWatch()
                                                        NULL );
     }
 
-    ensure_dbus_setup( this );
+    //ensure_dbus_setup( this );
 }
 
 GtkSalFrame::~GtkSalFrame()
@@ -683,8 +676,6 @@ GtkSalFrame::~GtkSalFrame()
         SolarMutexGuard aGuard;
         if(m_nWatcherId)
             g_bus_unwatch_name(m_nWatcherId);
-//        if(m_pSalMenu)
-//            static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame();
         if( m_pWindow )
         {
             g_object_set_data( G_OBJECT( m_pWindow ), "SalFrame", NULL );
@@ -693,16 +684,8 @@ GtkSalFrame::~GtkSalFrame()
             {
                 if(m_nMenuExportId)
                     g_dbus_connection_unexport_menu_model(pSessionBus, m_nMenuExportId);
-                //GLOMenu* pMenuModel = G_LO_MENU(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-menubar" ));
-                //if(pMenuModel)
-                //g_lo_menu_remove(pMenuModel,0);
-                //g_object_unref( pMenuModel );
                 if(m_nActionGroupExportId)
                     g_dbus_connection_unexport_action_group(pSessionBus, m_nActionGroupExportId);
-                //GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-action-group" ));
-                //if(pActionGroup)
-                //g_lo_action_group_clear( pActionGroup );
-                //g_object_unref( pActionGroup );
             }
             gtk_widget_destroy( m_pWindow );
         }
@@ -1132,8 +1115,8 @@ void GtkSalFrame::Init( SalFrame* pParent, sal_uLong nStyle )
     if( eWinType == GTK_WINDOW_TOPLEVEL )
     {
         // Enable DBus native menu if available.
-//        ensure_dbus_setup( this );
-        EnsureAppMenuWatch();
+        ensure_dbus_setup( this );
+        //EnsureAppMenuWatch();
 
         guint32 nUserTime = 0;
         if( (nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION|SAL_FRAME_STYLE_TOOLWINDOW)) == 0 )
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index 3c6ee28..8c48873 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -152,34 +152,14 @@ bool GtkSalMenu::PrepUpdate()
     const GtkSalFrame* pFrame = GetFrame();
     if (pFrame)
     {
-//        const GObject* pWindow = G_OBJECT(gtk_widget_get_window( GTK_WIDGET(pFrame->getWindow()) ));
-//        if(!pWindow)
-//        {
-//            SAL_INFO("vcl.unity", "not updating menu model, I have no frame " << mpMenuModel);
-//            return false;
-//        }
-//
-//        // the root menu does not have its own model and has to use the one owned by the frame
-//        if(mbMenuBar)
-//        {
-//            mpMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( pWindow ), "g-lo-menubar" ) );
-//            mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( pWindow ), "g-lo-action-group" ) );
-//
-//            if(!mpMenuModel || !mpActionGroup)
-//                return false;
-//        }
-//
-//        SAL_INFO("vcl.unity", "updating menu model" << mpMenuModel);
         GtkSalFrame* pNonConstFrame = ( GtkSalFrame* ) pFrame;
         GtkSalMenu* pSalMenu = ((GtkSalMenu*) this);
 
         if ( !pNonConstFrame->GetMenu() )
             pNonConstFrame->SetMenu( pSalMenu );
 
-        if ( /*!bMenuVisibility ||*/ !mpMenuModel || !mpActionGroup )
-            return false;
-
-        return true;
+        if ( bMenuVisibility && mpMenuModel && mpActionGroup )
+            return true;
     }
 
     return false;
@@ -366,9 +346,8 @@ void GtkSalMenu::UpdateNativeMenu()
         {
             NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, itemBits, FALSE, TRUE );
             pNewCommandList = g_list_append( pNewCommandList, g_strdup( aNativeCommand ) );
-//
+
             GLOMenu* pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
-//            printf("%s (begin) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel);
 
             if ( pSubMenuModel == NULL )
             {
@@ -379,7 +358,6 @@ void GtkSalMenu::UpdateNativeMenu()
             }
 
             g_object_unref( pSubMenuModel );
-//            printf("%s (end) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel);
 
             pSubmenu->SetMenuModel( G_MENU_MODEL( pSubMenuModel ) );
             pSubmenu->SetActionGroup( G_ACTION_GROUP( pActionGroup ) );
@@ -388,9 +366,6 @@ void GtkSalMenu::UpdateNativeMenu()
             pSubmenu->GetMenu()->Deactivate();
 
             pSubmenu->UpdateNativeMenu();
-
-            //pSubmenu->SetMenuModel( NULL );
-            //pSubmenu->SetActionGroup( NULL );
         }
 
         g_free( aNativeCommand );
@@ -423,8 +398,6 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
     mpMenuModel( NULL ),
     mpActionGroup( NULL )
 {
-    if (mbMenuBar)
-        printf("[%p] %s\n", this, __FUNCTION__);
 }
 
 GtkSalMenu::~GtkSalMenu()
@@ -434,23 +407,11 @@ GtkSalMenu::~GtkSalMenu()
 
     if ( mbMenuBar == sal_True )
     {
-        printf("[%p] %s\n", this, __FUNCTION__);
-        //if ( mpFrame )
-        //    ((GtkSalFrame*) mpFrame)->SetMenu( NULL );
-
         if ( mpMenuModel )
         {
-            g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 );
+//            g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 );
             g_object_unref( mpMenuModel );
         }
-
-        //if ( mpActionGroup )
-        //{
-            //g_lo_action_group_clear( G_LO_ACTION_GROUP( mpActionGroup ) );
-            //g_object_unref( mpActionGroup );
-        //}
-        //if ( mpFrame )
-        //    ((GtkSalFrame*) mpFrame)->FlushConnection();
     }
 
     maItems.clear();
@@ -458,8 +419,7 @@ GtkSalMenu::~GtkSalMenu()
 
 sal_Bool GtkSalMenu::VisibleMenuBar()
 {
-    //return bMenuVisibility;
-    return sal_False;
+    return bMenuVisibility;
 }
 
 void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
@@ -509,13 +469,12 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
     // actiongroup
     mpOldSalMenu = static_cast< GtkSalMenu* >( pFrameNonConst->GetMenu() );
     pFrameNonConst->SetMenu( this );
+    pFrameNonConst->EnsureAppMenuWatch();
 
     // Clean menu model and action group if needed.
     GtkWidget* pWidget = pFrameNonConst->getWindow();
     GdkWindow* gdkWindow = gtk_widget_get_window( pWidget );
 
-    printf("[%p] %s - window: %p\n", this, __FUNCTION__, gdkWindow);
-
     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" ) );
 
@@ -524,10 +483,7 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
         if ( g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 )
             g_lo_menu_remove( pMenuModel, 0 );
 
-        //g_lo_menu_new_section( pMenuModel, 0, NULL );
-        //mpMenuModel = G_MENU_MODEL( g_lo_menu_get_section( pMenuModel, 0 ) );
         mpMenuModel = G_MENU_MODEL( g_lo_menu_new() );
-        //g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel );
     }
 
     if ( pActionGroup )
@@ -536,15 +492,11 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
         mpActionGroup = G_ACTION_GROUP( pActionGroup );
     }
 
-    //pFrameNonConst->FlushConnection();
-
     // Generate the main menu structure.
-    UpdateNativeMenu();
-    g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel );
-
-    //pFrameNonConst->FlushConnection();
+    if (bMenuVisibility)
+        UpdateNativeMenu();
 
-    printf("[%p] %s - frame: %p - menu export id: %d - action group export id: %d\n", this, __FUNCTION__, pFrame, pFrameNonConst->m_nMenuExportId, pFrameNonConst->m_nActionGroupExportId);
+    g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel );
 }
 
 const GtkSalFrame* GtkSalMenu::GetFrame() const
@@ -737,8 +689,6 @@ void GtkSalMenu::DispatchCommand( gint itemId, const gchar *aCommand )
     if ( mbMenuBar != TRUE )
         return;
 
-    printf("[%p] %s - item id: %d - command: %s\n", this, __FUNCTION__, itemId, aCommand);
-
     GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( (gchar*) aCommand, FALSE );
     Menu* pSubMenu = ( pSalSubMenu != NULL ) ? pSalSubMenu->GetMenu() : NULL;
 
@@ -758,7 +708,6 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand )
         MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );
         pMenuBar->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu );
         pSalSubMenu->UpdateNativeMenu();
-        //((GtkSalFrame*) mpFrame)->FlushConnection();
     }
 }
 
@@ -775,16 +724,6 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand )
     }
 }
 
-//void GtkSalMenu::DisconnectFrame()
-//{
-//    if( mbMenuBar == sal_True )
-//    {
-//        mpMenuModel = NULL;
-//        mpActionGroup = NULL;
-//        mpFrame = NULL;
-//    }
-//}
-
 void GtkSalMenu::Display( sal_Bool bVisible )
 {
     if ( mbMenuBar == sal_False || mpVCLMenu == NULL )
commit 0b56c4a0d12fa58cdf72ab5037b3749aca3458b1
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date:   Wed Oct 17 20:06:11 2012 +0100

    Chart menu works now.
    
    Change-Id: I95861a5af8b9c72c74840868d0530d5855b87785

diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h
index 4c7c3e5..a1a615b 100644
--- a/vcl/inc/unx/gtk/glomenu.h
+++ b/vcl/inc/unx/gtk/glomenu.h
@@ -125,6 +125,10 @@ void        g_lo_menu_set_submenu_to_item_in_section                    (GLOMenu
                                                                          gint         position,
                                                                          GMenuModel  *submenu);
 
+void        g_lo_menu_new_submenu_in_item_in_section                    (GLOMenu     *menu,
+                                                                         gint         section,
+                                                                         gint         position);
+
 GLOMenu *   g_lo_menu_get_submenu_from_item_in_section                  (GLOMenu     *menu,
                                                                          gint         section,
                                                                          gint         position);
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 93b043d..2f1817e 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -312,6 +312,7 @@ public:
 
     guint                           m_nMenuExportId;
     guint                           m_nActionGroupExportId;
+    void FlushConnection();
 
     // dispatches an event, returns true if dispatched
     // and false else; if true was returned the event should
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 6e7084b..46ba215 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -45,6 +45,7 @@ private:
 
     sal_Bool                        mbMenuBar;
     Menu*                           mpVCLMenu;
+    GtkSalMenu*                     mpOldSalMenu;
     GtkSalMenu*                     mpParentSalMenu;
     const GtkSalFrame*              mpFrame;
 
@@ -102,7 +103,7 @@ public:
     void                        DispatchCommand( gint itemId, const gchar* aCommand );
     void                        Activate( const gchar* aMenuCommand );
     void                        Deactivate( const gchar* aMenuCommand );
-    void                        DisconnectFrame();
+//    void                        DisconnectFrame();
     void                        Display( sal_Bool bVisible );
     void UpdateNativeMenu();
 //    void UpdateNativeSubMenu();
diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx
index 756779a..9f65f37 100644
--- a/vcl/unx/gtk/window/gloactiongroup.cxx
+++ b/vcl/unx/gtk/window/gloactiongroup.cxx
@@ -255,6 +255,8 @@ g_lo_action_group_activate (GActionGroup *group,
 {
     GTK_YIELD_GRAB();
 
+    printf("%s\n", __FUNCTION__);
+
     GLOActionGroup *lo_group = G_LO_ACTION_GROUP (group);
     GtkSalFrame *pFrame = lo_group->priv->frame;
 
diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx
index 2ecf23a..cc84889 100644
--- a/vcl/unx/gtk/window/glomenu.cxx
+++ b/vcl/unx/gtk/window/glomenu.cxx
@@ -91,7 +91,7 @@ valid_attribute_name (const gchar *name)
  */
 
 static gboolean
-g_lo_menu_is_mutable (GMenuModel *model)
+g_lo_menu_is_mutable (GMenuModel*)
 {
     // Menu is always mutable.
     return TRUE;
@@ -100,8 +100,12 @@ g_lo_menu_is_mutable (GMenuModel *model)
 static gint
 g_lo_menu_get_n_items (GMenuModel *model)
 {
+    //printf("[%p] %s\n", model, __FUNCTION__);
+    g_return_val_if_fail (model != NULL, 0);
     GLOMenu *menu = G_LO_MENU (model);
+    g_return_val_if_fail (menu->items != NULL, 0);
 
+    //printf("[%p] %s - length: %d\n", model, __FUNCTION__, menu->items->len);
     return menu->items->len;
 }
 
@@ -109,16 +113,18 @@ gint
 g_lo_menu_get_n_items_from_section (GLOMenu *menu,
                                     gint     section)
 {
-    g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, -1);
+    //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, section);
+    g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, 0);
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
-    g_return_val_if_fail (model != NULL, -1);
+    g_return_val_if_fail (model != NULL, 0);
 
     gint length = model->items->len;
 
     g_object_unref (model);
 
+    //printf("[%p] %s - section: %d - length: %d\n", menu, __FUNCTION__, section, length);
     return length;
 }
 
@@ -130,6 +136,7 @@ g_lo_menu_get_item_attributes (GMenuModel  *model,
     GLOMenu *menu = G_LO_MENU (model);
 
     *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).attributes);
+    //printf("[%p] %s - position: %d - table: %p - *table: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL));
 }
 
 static void
@@ -140,6 +147,7 @@ g_lo_menu_get_item_links (GMenuModel  *model,
     GLOMenu *menu = G_LO_MENU (model);
 
     *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).links);
+    //printf("[%p] %s - position: %d - table: %p - *table: %p - items: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL), ((menu) ? menu->items : NULL));
 }
 
 void
@@ -147,20 +155,7 @@ g_lo_menu_insert (GLOMenu     *menu,
                   gint         position,
                   const gchar *label)
 {
-    g_return_if_fail (G_IS_LO_MENU (menu));
-
-    if (position < 0 || position > (gint) menu->items->len)
-        position = menu->items->len;
-
-    struct item menu_item;
-
-    g_lo_menu_struct_item_init(&menu_item);
-
-    g_array_insert_val (menu->items, position, menu_item);
-
-    g_lo_menu_set_label (menu, position, label);
-
-    g_menu_model_items_changed (G_MENU_MODEL (menu), position, 0, 1);
+    g_lo_menu_insert_section (menu, position, label, NULL);
 }
 
 void
@@ -169,6 +164,7 @@ g_lo_menu_insert_in_section (GLOMenu     *menu,
                              gint         position,
                              const gchar *label)
 {
+    //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -193,6 +189,7 @@ g_lo_menu_set_attribute_value (GLOMenu     *menu,
                                const gchar *attribute,
                                GVariant    *value)
 {
+    //printf("[%p] %s - position: %d - attribute: %s - value: %p\n", menu, __FUNCTION__, position, attribute, value);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (attribute != NULL);
     g_return_if_fail (valid_attribute_name (attribute));
@@ -215,6 +212,7 @@ g_lo_menu_get_attribute_value_from_item_in_section (GLOMenu            *menu,
                                                     const gchar        *attribute,
                                                     const GVariantType *type)
 {
+    //printf("[%p] %s - section: %d - position: %d - attribute: %s - type: %p\n", menu, __FUNCTION__, section, position, attribute, type);
     GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section));
 
     g_return_val_if_fail (model != NULL, NULL);
@@ -234,6 +232,7 @@ g_lo_menu_set_label (GLOMenu     *menu,
                      gint         position,
                      const gchar *label)
 {
+    //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GVariant *value;
@@ -252,16 +251,19 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu     *menu,
                                         gint         position,
                                         const gchar *label)
 {
+    //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
+
     g_lo_menu_set_label (model, position, label);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
 
     g_object_unref (model);
 }
@@ -271,6 +273,7 @@ g_lo_menu_get_label_from_item_in_section (GLOMenu *menu,
                                           gint     section,
                                           gint     position)
 {
+    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *label_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -296,6 +299,7 @@ g_lo_menu_set_action_and_target_value (GLOMenu     *menu,
                                        const gchar *action,
                                        GVariant    *target_value)
 {
+    //printf("[%p] %s - position: %d - action: %s - target value: %p\n", menu, __FUNCTION__, position, action, target_value);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GVariant *action_value;
@@ -323,6 +327,7 @@ g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu     *menu,
                                                           const gchar *command,
                                                           GVariant    *target_value)
 {
+    //printf("[%p] %s - section: %d - position: %d - command: %s - target value: %p\n", menu, __FUNCTION__, section, position, command, target_value);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
@@ -340,12 +345,15 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu     *menu,
                                               gint         position,
                                               const gchar *accelerator)
 {
+    //printf("[%p] %s - section: %d - position: %d - accelerator: %s\n", menu, __FUNCTION__, section, position, accelerator);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
+
     GVariant *value;
 
     if (accelerator != NULL)
@@ -356,7 +364,7 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_ACCELERATOR, value);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
 
     g_object_unref (model);
 }
@@ -366,6 +374,7 @@ g_lo_menu_get_accelerator_from_item_in_section (GLOMenu *menu,
                                                 gint     section,
                                                 gint     position)
 {
+    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *accel_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -391,12 +400,15 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
                                           gint         position,
                                           const gchar *command)
 {
+    //printf("[%p] %s - section: %d - position: %d - command: %s\n", menu, __FUNCTION__, section, position, command);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GLOMenu *model = g_lo_menu_get_section (menu, section);
 
     g_return_if_fail (model != NULL);
 
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0);
+
     GVariant *value;
 
     if (command != NULL)
@@ -407,7 +419,7 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_COMMAND, value);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1);
 
     g_object_unref (model);
 }
@@ -417,6 +429,7 @@ g_lo_menu_get_command_from_item_in_section (GLOMenu *menu,
                                             gint     section,
                                             gint     position)
 {
+    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     GVariant *command_value = g_lo_menu_get_attribute_value_from_item_in_section (menu,
@@ -442,6 +455,7 @@ g_lo_menu_set_link (GLOMenu     *menu,
                     const gchar *link,
                     GMenuModel  *model)
 {
+    //printf("[%p] %s - position: %d - link: %s - model: %p\n", menu, __FUNCTION__, position, link, model);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (link != NULL);
     g_return_if_fail (valid_attribute_name (link));
@@ -449,6 +463,8 @@ g_lo_menu_set_link (GLOMenu     *menu,
     if (position < 0 || position >= (gint) menu->items->len)
         position = menu->items->len - 1;
 
+//    printf ("%s - position: %d\n", __FUNCTION__, position);
+
     struct item menu_item = g_array_index (menu->items, struct item, position);
 
     if (model != NULL)
@@ -463,6 +479,7 @@ g_lo_menu_insert_section (GLOMenu     *menu,
                           const gchar *label,
                           GMenuModel  *section)
 {
+    //printf("[%p] %s - position: %d - label: %s - section: %p\n", menu, __FUNCTION__, position, label, section);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     if (position < 0 || position > (gint) menu->items->len)
@@ -470,7 +487,7 @@ g_lo_menu_insert_section (GLOMenu     *menu,
 
     struct item menu_item;
 
-    g_lo_menu_struct_item_init (&menu_item);
+    g_lo_menu_struct_item_init(&menu_item);
 
     g_array_insert_val (menu->items, position, menu_item);
 
@@ -485,19 +502,19 @@ g_lo_menu_new_section (GLOMenu     *menu,
                        gint         position,
                        const gchar *label)
 {
+    //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label);
     GMenuModel *section = G_MENU_MODEL (g_lo_menu_new());
 
     g_lo_menu_insert_section (menu, position, label, section);
 
-//    g_object_unref (section);
+    g_object_unref (section);
 }
 
-
-
 GLOMenu *
 g_lo_menu_get_section (GLOMenu *menu,
                        gint section)
 {
+    //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, section);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
 
     return G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
@@ -505,11 +522,39 @@ g_lo_menu_get_section (GLOMenu *menu,
 }
 
 void
+g_lo_menu_new_submenu_in_item_in_section (GLOMenu *menu,
+                                          gint     section,
+                                          gint     position)
+{
+    g_return_if_fail (G_IS_LO_MENU (menu));
+    g_return_if_fail (0 <= section && section < (gint) menu->items->len);
+
+    GLOMenu* model = g_lo_menu_get_section (menu, section);
+
+    g_return_if_fail (model != NULL);
+    g_return_if_fail (0 <= position && position < model->items->len);
+
+    struct item menu_item = g_array_index (model->items, struct item, position);
+
+    GMenuModel* submenu = G_MENU_MODEL (g_lo_menu_new());
+
+    g_lo_menu_set_link (model, position, G_MENU_LINK_SUBMENU, submenu);
+
+    g_object_unref (submenu);
+
+    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+
+    g_object_unref (model);
+}
+
+
+void
 g_lo_menu_set_submenu_to_item_in_section (GLOMenu    *menu,
                                           gint        section,
                                           gint        position,
                                           GMenuModel *submenu)
 {
+    printf("[%p] %s (begin) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -523,6 +568,7 @@ g_lo_menu_set_submenu_to_item_in_section (GLOMenu    *menu,
     g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
+    printf("[%p] %s (end) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu);
 }
 
 GLOMenu *
@@ -530,6 +576,7 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu,
                                             gint     section,
                                             gint     position)
 {
+    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_val_if_fail (G_IS_LO_MENU (menu), NULL);
     g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, NULL);
 
@@ -537,14 +584,17 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu,
 
     g_return_val_if_fail (model != NULL, NULL);
 
-    GMenuModel *submenu = NULL;
+    GLOMenu *submenu = NULL;
 
     if (0 <= position && position < (gint) model->items->len)
-        submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU);
+
+    submenu = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class)
+                      ->get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU));
+    //submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU);
 
     g_object_unref (model);
 
-    return G_LO_MENU (submenu);
+    return submenu;
 }
 
 void
@@ -553,12 +603,15 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu     *menu,
                                                  gint         position,
                                                  const gchar *action)
 {
+    //printf("[%p] %s - section: %d - position: %d - action: %s\n", menu, __FUNCTION__, section, position, action);
     g_return_if_fail (G_IS_LO_MENU (menu));
 
     GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section));
 
     g_return_if_fail (model != NULL);
 
+    g_menu_model_items_changed (model, position, 1, 0);
+
     GVariant *value;
 
     if (action != NULL)
@@ -569,7 +622,7 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (G_LO_MENU (model), position, G_LO_MENU_ATTRIBUTE_SUBMENU_ACTION, value);
 
     // Notify the update.
-    g_menu_model_items_changed (model, position, 1, 1);
+    g_menu_model_items_changed (model, position, 0, 1);
 
     g_object_unref (model);
 }
@@ -587,12 +640,13 @@ void
 g_lo_menu_remove (GLOMenu *menu,
                   gint     position)
 {
+    //printf("[%p] %s - position: %d\n", menu, __FUNCTION__, position);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= position && position < (gint) menu->items->len);
 
-    g_menu_model_items_changed (G_MENU_MODEL (menu), position, 1, 0);
     g_lo_menu_clear_item (&g_array_index (menu->items, struct item, position));
     g_array_remove_index (menu->items, position);
+    g_menu_model_items_changed (G_MENU_MODEL (menu), position, 1, 0);
 }
 
 void
@@ -600,6 +654,7 @@ g_lo_menu_remove_from_section (GLOMenu *menu,
                                gint     section,
                                gint     position)
 {
+    //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position);
     g_return_if_fail (G_IS_LO_MENU (menu));
     g_return_if_fail (0 <= section && section < (gint) menu->items->len);
 
@@ -615,6 +670,7 @@ g_lo_menu_remove_from_section (GLOMenu *menu,
 static void
 g_lo_menu_finalize (GObject *object)
 {
+    //printf("[%p] %s\n", object, __FUNCTION__);
     GLOMenu *menu = G_LO_MENU (object);
     struct item *items;
     gint n_items;
diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx
index ab8b9c1..fcc2576 100644
--- a/vcl/unx/gtk/window/gtkframe.cxx
+++ b/vcl/unx/gtk/window/gtkframe.cxx
@@ -580,7 +580,7 @@ void on_registrar_available( GDBusConnection * /*connection*/,
     if ( pSalMenu != NULL )
     {
         GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu);
-        pGtkSalMenu->UpdateNativeMenu();
+        //pGtkSalMenu->UpdateNativeMenu();
         pGtkSalMenu->Display( sal_True );
     }
 }
@@ -601,11 +601,17 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/,
 
     if ( pSalMenu ) {
         GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu );
-        pGtkSalMenu->DisconnectFrame();
+//        pGtkSalMenu->DisconnectFrame();
         pGtkSalMenu->Display( sal_False );
     }
 }
 
+void GtkSalFrame::FlushConnection()
+{
+    if (pSessionBus)
+        g_dbus_connection_flush_sync( pSessionBus, NULL, NULL );
+}
+
 void GtkSalFrame::EnsureAppMenuWatch()
 {
     if ( !m_nWatcherId )
@@ -677,28 +683,26 @@ GtkSalFrame::~GtkSalFrame()
         SolarMutexGuard aGuard;
         if(m_nWatcherId)
             g_bus_unwatch_name(m_nWatcherId);
-        if(m_pSalMenu)
-            static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame();
+//        if(m_pSalMenu)
+//            static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame();
         if( m_pWindow )
         {
             g_object_set_data( G_OBJECT( m_pWindow ), "SalFrame", NULL );
-            if(m_nMenuExportId)
+
+            if ( pSessionBus )
             {
-                if(pSessionBus)
+                if(m_nMenuExportId)
                     g_dbus_connection_unexport_menu_model(pSessionBus, m_nMenuExportId);
-                GLOMenu* pMenuModel = G_LO_MENU(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-menubar" ));
-                if(pMenuModel)
-                    //g_lo_menu_remove(pMenuModel,0);
-                    g_object_unref( pMenuModel );
-            }
-            if(m_nActionGroupExportId)
-            {
-                if(pSessionBus)
+                //GLOMenu* pMenuModel = G_LO_MENU(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-menubar" ));
+                //if(pMenuModel)
+                //g_lo_menu_remove(pMenuModel,0);
+                //g_object_unref( pMenuModel );
+                if(m_nActionGroupExportId)
                     g_dbus_connection_unexport_action_group(pSessionBus, m_nActionGroupExportId);
-                GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-action-group" ));
-                if(pActionGroup)
-                    //g_lo_action_group_clear( pActionGroup );
-                    g_object_unref( pActionGroup );
+                //GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-action-group" ));
+                //if(pActionGroup)
+                //g_lo_action_group_clear( pActionGroup );
+                //g_object_unref( pActionGroup );
             }
             gtk_widget_destroy( m_pWindow );
         }
@@ -1471,10 +1475,10 @@ void GtkSalFrame::SetIcon( sal_uInt16 nIcon )
 
 void GtkSalFrame::SetMenu( SalMenu* pSalMenu )
 {
-    if(m_pSalMenu)
-    {
-        static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame();
-    }
+//    if(m_pSalMenu)
+//    {
+//        static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame();
+//    }
     m_pSalMenu = pSalMenu;
 }
 
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index b9d9325..3c6ee28 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -152,25 +152,33 @@ bool GtkSalMenu::PrepUpdate()
     const GtkSalFrame* pFrame = GetFrame();
     if (pFrame)
     {
-        const GObject* pWindow = G_OBJECT(gtk_widget_get_window( GTK_WIDGET(pFrame->getWindow()) ));
-        if(!pWindow)
-        {
-            SAL_INFO("vcl.unity", "not updating menu model, I have no frame " << mpMenuModel);
+//        const GObject* pWindow = G_OBJECT(gtk_widget_get_window( GTK_WIDGET(pFrame->getWindow()) ));
+//        if(!pWindow)
+//        {
+//            SAL_INFO("vcl.unity", "not updating menu model, I have no frame " << mpMenuModel);
+//            return false;
+//        }
+//
+//        // the root menu does not have its own model and has to use the one owned by the frame
+//        if(mbMenuBar)
+//        {
+//            mpMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( pWindow ), "g-lo-menubar" ) );
+//            mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( pWindow ), "g-lo-action-group" ) );
+//
+//            if(!mpMenuModel || !mpActionGroup)
+//                return false;
+//        }
+//
+//        SAL_INFO("vcl.unity", "updating menu model" << mpMenuModel);
+        GtkSalFrame* pNonConstFrame = ( GtkSalFrame* ) pFrame;
+        GtkSalMenu* pSalMenu = ((GtkSalMenu*) this);
+
+        if ( !pNonConstFrame->GetMenu() )
+            pNonConstFrame->SetMenu( pSalMenu );
+
+        if ( /*!bMenuVisibility ||*/ !mpMenuModel || !mpActionGroup )
             return false;
-        }
-    
-        // the root menu does not have its own model and has to use the one owned by the frame
-        if(mbMenuBar)
-        {
-            mpMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( pWindow ), "g-lo-menubar" ) );
-            mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( pWindow ), "g-lo-action-group" ) );
-        
-            if(!mpMenuModel || !mpActionGroup)
-                return false;
-        } 
-        
-        SAL_INFO("vcl.unity", "updating menu model" << mpMenuModel);
-        
+
         return true;
     }
 
@@ -256,6 +264,7 @@ void RemoveUnusedCommands( GLOActionGroup* pActionGroup, GList* pOldCommandList,
 void GtkSalMenu::UpdateNativeMenu()
 {
     SolarMutexGuard aGuard;
+    //GTK_YIELD_GRAB();
 
     if( !PrepUpdate() )
         return;
@@ -357,16 +366,20 @@ void GtkSalMenu::UpdateNativeMenu()
         {
             NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, itemBits, FALSE, TRUE );
             pNewCommandList = g_list_append( pNewCommandList, g_strdup( aNativeCommand ) );
-
+//
             GLOMenu* pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
+//            printf("%s (begin) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel);
 
             if ( pSubMenuModel == NULL )
             {
-                pSubMenuModel = g_lo_menu_new();
-                g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, G_MENU_MODEL( pSubMenuModel ) );
+                //pSubMenuModel = g_lo_menu_new();
+                //g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, G_MENU_MODEL( pSubMenuModel ) );
+                g_lo_menu_new_submenu_in_item_in_section( pLOMenu, nSection, nItemPos );
+                pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
             }
 
             g_object_unref( pSubMenuModel );
+//            printf("%s (end) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel);
 
             pSubmenu->SetMenuModel( G_MENU_MODEL( pSubMenuModel ) );
             pSubmenu->SetActionGroup( G_ACTION_GROUP( pActionGroup ) );
@@ -375,11 +388,10 @@ void GtkSalMenu::UpdateNativeMenu()
             pSubmenu->GetMenu()->Deactivate();
 
             pSubmenu->UpdateNativeMenu();
+
+            //pSubmenu->SetMenuModel( NULL );
+            //pSubmenu->SetActionGroup( NULL );
         }
-//        else if (pSubMenuModel)
-//        {
-//            g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, NULL );
-//        };
 
         g_free( aNativeCommand );
 
@@ -405,26 +417,49 @@ void GtkSalMenu::UpdateNativeMenu()
 GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
     mbMenuBar( bMenuBar ),
     mpVCLMenu( NULL ),
+    mpOldSalMenu( NULL ),
     mpParentSalMenu( NULL ),
     mpFrame( NULL ),
     mpMenuModel( NULL ),
     mpActionGroup( NULL )
 {
+    if (mbMenuBar)
+        printf("[%p] %s\n", this, __FUNCTION__);
 }
 
 GtkSalMenu::~GtkSalMenu()
 {
     SolarMutexGuard aGuard;
+    //GTK_YIELD_GRAB();
+
     if ( mbMenuBar == sal_True )
-        if ( mpFrame )
-            ((GtkSalFrame*) mpFrame)->SetMenu( NULL );
+    {
+        printf("[%p] %s\n", this, __FUNCTION__);
+        //if ( mpFrame )
+        //    ((GtkSalFrame*) mpFrame)->SetMenu( NULL );
+
+        if ( mpMenuModel )
+        {
+            g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 );
+            g_object_unref( mpMenuModel );
+        }
+
+        //if ( mpActionGroup )
+        //{
+            //g_lo_action_group_clear( G_LO_ACTION_GROUP( mpActionGroup ) );
+            //g_object_unref( mpActionGroup );
+        //}
+        //if ( mpFrame )
+        //    ((GtkSalFrame*) mpFrame)->FlushConnection();
+    }
 
     maItems.clear();
 }
 
 sal_Bool GtkSalMenu::VisibleMenuBar()
 {
-    return bMenuVisibility;
+    //return bMenuVisibility;
+    return sal_False;
 }
 
 void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
@@ -462,6 +497,8 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig
 void GtkSalMenu::SetFrame( const SalFrame* pFrame )
 {
     SolarMutexGuard aGuard;
+    GTK_YIELD_GRAB();
+
     assert(mbMenuBar);
     SAL_INFO("vcl.unity", "GtkSalMenu set to frame");
     mpFrame = static_cast< const GtkSalFrame* >( pFrame );
@@ -470,25 +507,44 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
     // if we had a menu on the GtkSalMenu we have to free it as we generate a
     // full menu anyway and we might need to reuse an existing model and
     // actiongroup
+    mpOldSalMenu = static_cast< GtkSalMenu* >( pFrameNonConst->GetMenu() );
     pFrameNonConst->SetMenu( this );
-    mpFrame = static_cast< const GtkSalFrame* >( pFrame );
 
     // Clean menu model and action group if needed.
-//    GObject* pWindow = G_OBJECT( pFrameNonConst->getWindow() );
     GtkWidget* pWidget = pFrameNonConst->getWindow();
     GdkWindow* gdkWindow = gtk_widget_get_window( pWidget );
 
+    printf("[%p] %s - window: %p\n", this, __FUNCTION__, gdkWindow);
+
     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" ) );
 
-    if ( pMenuModel && g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 )
-        g_lo_menu_remove( pMenuModel, 0 );
+    if ( pMenuModel )
+    {
+        if ( g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 )
+            g_lo_menu_remove( pMenuModel, 0 );
+
+        //g_lo_menu_new_section( pMenuModel, 0, NULL );
+        //mpMenuModel = G_MENU_MODEL( g_lo_menu_get_section( pMenuModel, 0 ) );
+        mpMenuModel = G_MENU_MODEL( g_lo_menu_new() );
+        //g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel );
+    }
 
     if ( pActionGroup )
+    {
         g_lo_action_group_clear( pActionGroup );
+        mpActionGroup = G_ACTION_GROUP( pActionGroup );
+    }
+
+    //pFrameNonConst->FlushConnection();
 
     // Generate the main menu structure.
     UpdateNativeMenu();
+    g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel );
+
+    //pFrameNonConst->FlushConnection();
+
+    printf("[%p] %s - frame: %p - menu export id: %d - action group export id: %d\n", this, __FUNCTION__, pFrame, pFrameNonConst->m_nMenuExportId, pFrameNonConst->m_nActionGroupExportId);
 }
 
 const GtkSalFrame* GtkSalMenu::GetFrame() const
@@ -503,7 +559,7 @@ const GtkSalFrame* GtkSalMenu::GetFrame() const
 void GtkSalMenu::NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck )
 {
     SolarMutexGuard aGuard;
-    
+
     if ( mpActionGroup == NULL )
         return;
 
@@ -681,6 +737,8 @@ void GtkSalMenu::DispatchCommand( gint itemId, const gchar *aCommand )
     if ( mbMenuBar != TRUE )
         return;
 
+    printf("[%p] %s - item id: %d - command: %s\n", this, __FUNCTION__, itemId, aCommand);
+
     GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( (gchar*) aCommand, FALSE );
     Menu* pSubMenu = ( pSalSubMenu != NULL ) ? pSalSubMenu->GetMenu() : NULL;
 
@@ -700,6 +758,7 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand )
         MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );
         pMenuBar->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu );
         pSalSubMenu->UpdateNativeMenu();
+        //((GtkSalFrame*) mpFrame)->FlushConnection();
     }
 }
 
@@ -716,15 +775,15 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand )
     }
 }
 
-void GtkSalMenu::DisconnectFrame()
-{
-    if( mbMenuBar == sal_True )
-    {
-        mpMenuModel = NULL;
-        mpActionGroup = NULL;
-        mpFrame = NULL;
-    }
-}
+//void GtkSalMenu::DisconnectFrame()
+//{
+//    if( mbMenuBar == sal_True )
+//    {
+//        mpMenuModel = NULL;
+//        mpActionGroup = NULL;
+//        mpFrame = NULL;
+//    }
+//}
 
 void GtkSalMenu::Display( sal_Bool bVisible )
 {


More information about the Libreoffice-commits mailing list