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

Maxim Monastirsky momonasmon at gmail.com
Sat Sep 24 21:21:11 UTC 2016


 framework/source/uielement/menubarmanager.cxx |    1 
 vcl/inc/unx/gtk/gtksalmenu.hxx                |    1 
 vcl/unx/gtk/gtksalmenu.cxx                    |   49 ++++++++++++++++++++++++--
 3 files changed, 49 insertions(+), 2 deletions(-)

New commits:
commit a05b67585249b895a70e7fae89dc177e3aeaf57a
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Sat Sep 24 23:47:04 2016 +0300

    tdf#102266 Try to keep HUD up to date
    
    Recent HUD versions don't seem to support the activation
    callback, so we have to update menus in the background.
    
    (regression of 15436c009e756dd4c94046f9849ad5a186454af8)
    
    TODO: Is this manual iteration in GtkSalMenu::SetItemText
    worth it, or maybe simply calling Update() will be good
    enough, too?
    
    Change-Id: I7f08c3518e1767915d84036cdce7f678961595ef

diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx
index a7ed572..c387d2a 100644
--- a/framework/source/uielement/menubarmanager.cxx
+++ b/framework/source/uielement/menubarmanager.cxx
@@ -890,6 +890,7 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool )
                                 if ( !bPopupMenu )
                                 {
                                     xMenuItemDispatch->addStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
+                                    // For the menubar, we have to keep status listening to support Ubuntu's HUD.
                                     if ( !m_bHasMenuBar )
                                         xMenuItemDispatch->removeStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
                                 }
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 460a0e5..cbb7d2c 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -45,6 +45,7 @@ private:
     std::vector< GtkSalMenuItem* >  maItems;
     Idle                            maUpdateMenuBarIdle;
 
+    bool                            mbInActivateCallback;
     bool                            mbMenuBar;
     bool                            mbNeedsUpdate;
     bool                            mbReturnFocusToDocument;
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index be68eff..9e4547b 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -417,6 +417,7 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& rRec
  */
 
 GtkSalMenu::GtkSalMenu( bool bMenuBar ) :
+    mbInActivateCallback( false ),
     mbMenuBar( bMenuBar ),
     mbNeedsUpdate( false ),
     mbReturnFocusToDocument( false ),
@@ -1049,7 +1050,9 @@ void GtkSalMenu::ActivateAllSubmenus(Menu* pMenuBar)
     {
         if ( pSalItem->mpSubMenu != nullptr )
         {
+            pSalItem->mpSubMenu->mbInActivateCallback = true;
             pMenuBar->HandleMenuActivateEvent(pSalItem->mpSubMenu->GetMenu());
+            pSalItem->mpSubMenu->mbInActivateCallback = false;
             pSalItem->mpSubMenu->ActivateAllSubmenus(pMenuBar);
             pSalItem->mpSubMenu->Update();
             pMenuBar->HandleMenuDeActivateEvent(pSalItem->mpSubMenu->GetMenu());
@@ -1077,7 +1080,11 @@ void GtkSalMenu::Activate(const gchar* pCommand)
     GtkSalMenu* pTopLevel = pSalMenu->GetTopLevel();
     Menu* pVclMenu = pSalMenu->GetMenu();
     Menu* pVclSubMenu = pVclMenu->GetPopupMenu(aMenuAndId.second);
+    GtkSalMenu* pSubMenu = pSalMenu->GetItemAtPos(pVclMenu->GetItemPos(aMenuAndId.second))->mpSubMenu;
+
+    pSubMenu->mbInActivateCallback = true;
     pTopLevel->GetMenu()->HandleMenuActivateEvent(pVclSubMenu);
+    pSubMenu->mbInActivateCallback = false;
     pVclSubMenu->UpdateNativeMenu();
 }
 
@@ -1123,19 +1130,57 @@ void GtkSalMenu::CheckItem( unsigned, bool )
 {
 }
 
-void GtkSalMenu::EnableItem( unsigned, bool )
+void GtkSalMenu::EnableItem( unsigned nPos, bool bEnable )
 {
+    SolarMutexGuard aGuard;
+    if ( bUnityMode && !mbInActivateCallback && !mbNeedsUpdate && GetTopLevel()->mbMenuBar && ( nPos < maItems.size() ) )
+    {
+        gchar* pCommand = GetCommandForItem( GetItemAtPos( nPos ) );
+        NativeSetEnableItem( pCommand, bEnable );
+        g_free( pCommand );
+    }
 }
 
 void GtkSalMenu::ShowItem( unsigned nPos, bool bShow )
 {
     SolarMutexGuard aGuard;
     if ( nPos < maItems.size() )
+    {
         maItems[ nPos ]->mbVisible = bShow;
+        if ( bUnityMode && !mbInActivateCallback && !mbNeedsUpdate && GetTopLevel()->mbMenuBar )
+            Update();
+    }
 }
 
-void GtkSalMenu::SetItemText( unsigned, SalMenuItem*, const OUString& )
+void GtkSalMenu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const OUString& rText )
 {
+    SolarMutexGuard aGuard;
+    if ( bUnityMode && !mbInActivateCallback && !mbNeedsUpdate && GetTopLevel()->mbMenuBar && ( nPos < maItems.size() ) )
+    {
+        gchar* pCommand = GetCommandForItem( static_cast< GtkSalMenuItem* >( pSalMenuItem ) );
+
+        gint nSectionsCount = g_menu_model_get_n_items( mpMenuModel );
+        for ( gint nSection = 0; nSection < nSectionsCount; ++nSection )
+        {
+            gint nItemsCount = g_lo_menu_get_n_items_from_section( G_LO_MENU( mpMenuModel ), nSection );
+            for ( gint nItem = 0; nItem < nItemsCount; ++nItem )
+            {
+                gchar* pCommandFromModel = g_lo_menu_get_command_from_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItem );
+
+                if ( !g_strcmp0( pCommandFromModel, pCommand ) )
+                {
+                    NativeSetItemText( nSection, nItem, rText );
+                    g_free( pCommandFromModel );
+                    g_free( pCommand );
+                    return;
+                }
+
+                g_free( pCommandFromModel );
+            }
+        }
+
+        g_free( pCommand );
+    }
 }
 
 void GtkSalMenu::SetItemImage( unsigned, SalMenuItem*, const Image& )


More information about the Libreoffice-commits mailing list