[Libreoffice-commits] core.git: 2 commits - vcl/inc vcl/unx

Caolán McNamara caolanm at redhat.com
Fri May 6 14:49:25 UTC 2016


 vcl/inc/unx/gtk/gtkframe.hxx   |    3 --
 vcl/inc/unx/gtk/gtksalmenu.hxx |   10 ++++++--
 vcl/unx/gtk/gloactiongroup.cxx |   13 ----------
 vcl/unx/gtk/gtksalframe.cxx    |   17 -------------
 vcl/unx/gtk/gtksalmenu.cxx     |   51 ++++++++++++++++++++++++++++++++---------
 vcl/unx/gtk3/gtk3gtkframe.cxx  |   17 -------------
 6 files changed, 49 insertions(+), 62 deletions(-)

New commits:
commit d20e08a3ab819ac24f7ea49a98b4dd3683120857
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri May 6 15:14:38 2016 +0100

    Resolves: tdf#98636 if the menubar hierarchy has been changed
    
    then update the whole thing by re-calling SetFrame
    
    Change-Id: Ib16006a76ca04dc104232a056c43fda2b5b24074

diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index a5dc414..11ed51f 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -20,6 +20,7 @@
 
 #include <unx/salmenu.h>
 #include <unx/gtk/gtkframe.hxx>
+#include <vcl/idle.hxx>
 
 #if ENABLE_DBUS && ENABLE_GIO && \
     (GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 36)
@@ -42,8 +43,10 @@ class GtkSalMenu : public SalMenu
 {
 private:
     std::vector< GtkSalMenuItem* >  maItems;
+    Idle                            maUpdateMenuBarIdle;
 
     bool                            mbMenuBar;
+    bool                            mbNeedsUpdate;
     GtkWidget*                      mpMenuBarWidget;
     GtkWidget*                      mpCloseButton;
     Menu*                           mpVCLMenu;
@@ -57,6 +60,8 @@ private:
     void                        ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries);
     void                        ActivateAllSubmenus(Menu* pMenuBar);
 
+    DECL_LINK_TYPED(MenuBarHierarchyChangeHandler, Idle*, void);
+
 public:
     GtkSalMenu( bool bMenuBar );
     virtual ~GtkSalMenu();
@@ -104,8 +109,9 @@ public:
     bool                        PrepUpdate();
     virtual void                Update() override;  // Update this menu only.
     // Update full menu hierarchy from this menu.
-    void                        UpdateFull () { ActivateAllSubmenus(mpVCLMenu); }
+    void                        UpdateFull () { if (mbNeedsUpdate) ActivateAllSubmenus(mpVCLMenu); }
     GtkSalMenu*                 GetTopLevel();
+    void                        SetNeedsUpdate();
 
     void CreateMenuBarWidget();
     void DestroyMenuBarWidget();
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index fc3092a..b6deecf 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -182,6 +182,13 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
     if( !PrepUpdate() )
         return;
 
+    if (mbNeedsUpdate)
+    {
+        mbNeedsUpdate = false;
+        if (mbMenuBar)
+            maUpdateMenuBarIdle.Stop();
+    }
+
     Menu* pVCLMenu = mpVCLMenu;
     GLOMenu* pLOMenu = G_LO_MENU( mpMenuModel );
     GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( mpActionGroup );
@@ -409,6 +416,7 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& rRec
 
 GtkSalMenu::GtkSalMenu( bool bMenuBar ) :
     mbMenuBar( bMenuBar ),
+    mbNeedsUpdate( false ),
     mpMenuBarWidget( nullptr ),
     mpCloseButton( nullptr ),
     mpVCLMenu( nullptr ),
@@ -417,6 +425,32 @@ GtkSalMenu::GtkSalMenu( bool bMenuBar ) :
     mpMenuModel( nullptr ),
     mpActionGroup( nullptr )
 {
+    //typically this only gets called after the menu has been customized on the
+    //next idle slot, in the normal case of a new menubar SetFrame is called
+    //directly long before this idle would get called.
+    maUpdateMenuBarIdle.SetPriority(SchedulerPriority::HIGHEST);
+    maUpdateMenuBarIdle.SetIdleHdl(LINK(this, GtkSalMenu, MenuBarHierarchyChangeHandler));
+    maUpdateMenuBarIdle.SetDebugName("Native Gtk Menu Update Idle");
+}
+
+IMPL_LINK_NOARG_TYPED(GtkSalMenu, MenuBarHierarchyChangeHandler, Idle *, void)
+{
+    SAL_WARN_IF(!mpFrame, "vcl.gtk", "MenuBar layout changed, but no frame for some reason!");
+    if (!mpFrame)
+        return;
+    SetFrame(mpFrame);
+}
+
+void GtkSalMenu::SetNeedsUpdate()
+{
+    GtkSalMenu* pMenu = this;
+    while (pMenu && !pMenu->mbNeedsUpdate)
+    {
+        pMenu->mbNeedsUpdate = true;
+        if (mbMenuBar)
+            maUpdateMenuBarIdle.Start();
+        pMenu = pMenu->mpParentSalMenu;
+    }
 }
 
 void GtkSalMenu::SetMenuModel(GMenuModel* pMenuModel)
@@ -460,12 +494,15 @@ void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
         maItems.insert( maItems.begin() + nPos, pItem );
 
     pItem->mpParentMenu = this;
+
+    SetNeedsUpdate();
 }
 
 void GtkSalMenu::RemoveItem( unsigned nPos )
 {
     SolarMutexGuard aGuard;
     maItems.erase( maItems.begin() + nPos );
+    SetNeedsUpdate();
 }
 
 void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned )
@@ -479,6 +516,8 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig
 
     pGtkSubMenu->mpParentSalMenu = this;
     pItem->mpSubMenu = pGtkSubMenu;
+
+    SetNeedsUpdate();
 }
 
 #if GTK_CHECK_VERSION(3,0,0)
commit b41a5e899bcb567595f489fab37cbebcc5efacc0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri May 6 13:57:04 2016 +0100

    reroute UpdateFull through ActivateAllSubmenus
    
    Change-Id: I8689abacbfc970a9124bb97a3962bcfb0df9c67d

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 4739c77..45ea636 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -229,10 +229,7 @@ class GtkSalFrame : public SalFrame
     SalMenu*                        m_pSalMenu;
 
 #if ENABLE_DBUS && ENABLE_GIO
-    public:
-    void EnsureDbusMenuSynced();
     private:
-    SalMenu*                        m_pLastSyncedDbusMenu;
     friend void ensure_dbus_setup(GdkWindow* gdkWindow, GtkSalFrame* pSalFrame);
     friend void on_registrar_available (GDBusConnection*, const gchar*, const gchar*, gpointer);
     friend void on_registrar_unavailable (GDBusConnection*, const gchar*, gpointer);
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 359ac5d..a5dc414 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -97,14 +97,14 @@ public:
     void                        NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck );
     void                        NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, const OUString& rKeyName );
 
-    void                        ActivateAllSubmenus() { ActivateAllSubmenus(mpVCLMenu); }
     static void                 DispatchCommand(const gchar* pMenuCommand);
     static void                 Activate(const gchar* pMenuCommand);
     static void                 Deactivate(const gchar* pMenuCommand);
     void                        EnableUnity(bool bEnable);
     bool                        PrepUpdate();
     virtual void                Update() override;  // Update this menu only.
-    void                        UpdateFull();       // Update full menu hierarchy from this menu.
+    // Update full menu hierarchy from this menu.
+    void                        UpdateFull () { ActivateAllSubmenus(mpVCLMenu); }
     GtkSalMenu*                 GetTopLevel();
 
     void CreateMenuBarWidget();
diff --git a/vcl/unx/gtk/gloactiongroup.cxx b/vcl/unx/gtk/gloactiongroup.cxx
index 663f1bb..00b0ccc 100644
--- a/vcl/unx/gtk/gloactiongroup.cxx
+++ b/vcl/unx/gtk/gloactiongroup.cxx
@@ -149,18 +149,7 @@ g_lo_action_group_query_action (GActionGroup        *group,
 {
     //SAL_INFO("vcl.unity", "g_lo_action_group_query_action on " << group);
     GLOActionGroup *lo_group = G_LO_ACTION_GROUP (group);
-    GLOAction* action;
-
-    if (enabled)
-    {
-        GtkSalFrame* pFrame = lo_group->priv->frame;
-        if (pFrame) {
-            pFrame->EnsureDbusMenuSynced();
-        }
-    }
-
-    // note: EnsureDbusMenuSynced could have deleted the action!
-    action = G_LO_ACTION (g_hash_table_lookup (lo_group->priv->table, action_name));
+    GLOAction* action = G_LO_ACTION (g_hash_table_lookup (lo_group->priv->table, action_name));
 
     if (action == nullptr)
         return FALSE;
diff --git a/vcl/unx/gtk/gtksalframe.cxx b/vcl/unx/gtk/gtksalframe.cxx
index ff40971..4a95275 100644
--- a/vcl/unx/gtk/gtksalframe.cxx
+++ b/vcl/unx/gtk/gtksalframe.cxx
@@ -438,9 +438,6 @@ GtkSalFrame::GtkSalFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
     m_bDefaultPos       = true;
     m_bDefaultSize      = ( (nStyle & SalFrameStyleFlags::SIZEABLE) && ! pParent );
     m_bWindowIsGtkPlug  = false;
-#if ENABLE_DBUS && ENABLE_GIO
-    m_pLastSyncedDbusMenu = nullptr;
-#endif
     Init( pParent, nStyle );
 }
 
@@ -454,9 +451,6 @@ GtkSalFrame::GtkSalFrame( SystemParentData* pSysData )
     GetGenericData()->ErrorTrapPush();
     m_bDefaultPos       = true;
     m_bDefaultSize      = true;
-#if ENABLE_DBUS && ENABLE_GIO
-    m_pLastSyncedDbusMenu = nullptr;
-#endif
     Init( pSysData );
 }
 
@@ -494,17 +488,6 @@ static void ObjectDestroyedNotify( gpointer data )
     }
 }
 
-#if ENABLE_DBUS && ENABLE_GIO
-void GtkSalFrame::EnsureDbusMenuSynced()
-{
-    GtkSalMenu* pSalMenu = static_cast<GtkSalMenu*>(GetMenu());
-    if(m_pLastSyncedDbusMenu != pSalMenu) {
-        m_pLastSyncedDbusMenu = pSalMenu;
-        static_cast<GtkSalMenu*>(pSalMenu)->ActivateAllSubmenus();
-    }
-}
-#endif
-
 static void hud_activated( gboolean hud_active, gpointer user_data )
 {
     if ( hud_active )
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index f199f74..fc3092a 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -314,16 +314,6 @@ void GtkSalMenu::Update()
     ImplUpdate(false, !pMenu->mbMenuBar);
 }
 
-void GtkSalMenu::UpdateFull()
-{
-    //find out if top level is a menubar or not, if not, then its a popup menu
-    //hierarchy and in those we hide (most) disabled entries
-    const GtkSalMenu* pMenu = this;
-    while (pMenu->mpParentSalMenu)
-        pMenu = pMenu->mpParentSalMenu;
-    ImplUpdate(true, !pMenu->mbMenuBar);
-}
-
 #if GTK_CHECK_VERSION(3,0,0)
 static void MenuPositionFunc(GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data)
 {
@@ -375,7 +365,7 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& rRec
     mpActionGroup = G_ACTION_GROUP(pActionGroup);
     mpMenuModel = G_MENU_MODEL(g_lo_menu_new());
     // Generate the main menu structure, populates mpMenuModel
-    ActivateAllSubmenus();
+    UpdateFull();
 
     GtkWidget *pWidget = gtk_menu_new_from_model(mpMenuModel);
     gtk_menu_attach_to_widget(GTK_MENU(pWidget), mpFrame->getMouseEventWidget(), nullptr);
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 9f0dcfb..d716a5c 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -465,9 +465,6 @@ GtkSalFrame::GtkSalFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
     m_bDefaultPos       = true;
     m_bDefaultSize      = ( (nStyle & SalFrameStyleFlags::SIZEABLE) && ! pParent );
     m_bWindowIsGtkPlug  = false;
-#if ENABLE_DBUS && ENABLE_GIO
-    m_pLastSyncedDbusMenu = nullptr;
-#endif
     Init( pParent, nStyle );
 }
 
@@ -481,9 +478,6 @@ GtkSalFrame::GtkSalFrame( SystemParentData* pSysData )
     GetGenericData()->ErrorTrapPush();
     m_bDefaultPos       = true;
     m_bDefaultSize      = true;
-#if ENABLE_DBUS && ENABLE_GIO
-    m_pLastSyncedDbusMenu = nullptr;
-#endif
     Init( pSysData );
 }
 
@@ -498,17 +492,6 @@ static void ObjectDestroyedNotify( gpointer data )
     }
 }
 
-#if ENABLE_DBUS && ENABLE_GIO
-void GtkSalFrame::EnsureDbusMenuSynced()
-{
-    GtkSalMenu* pSalMenu = static_cast<GtkSalMenu*>(GetMenu());
-    if(m_pLastSyncedDbusMenu != pSalMenu) {
-        m_pLastSyncedDbusMenu = pSalMenu;
-        static_cast<GtkSalMenu*>(pSalMenu)->ActivateAllSubmenus();
-    }
-}
-#endif
-
 static void hud_activated( gboolean hud_active, gpointer user_data )
 {
     if ( hud_active )


More information about the Libreoffice-commits mailing list