Blame SOURCES/0001-Resolves-fdo-48835-application-menu-for-LibreOffice.patch

2135ec
From 931fc46eb8e09a9b16232fd58a222a47d28c5ea1 Mon Sep 17 00:00:00 2001
2135ec
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
2135ec
Date: Thu, 18 Jul 2013 17:19:46 +0100
2135ec
Subject: [PATCH] Resolves: fdo#48835 application menu for LibreOffice
2135ec
2135ec
(cherry picked from commit c6d4c18c7ccf047bdb0ca1b65d8f63efa5d8422f)
2135ec
2135ec
Change-Id: I623f029722b71dde6e60f289c7339a96e2dfbf8e
2135ec
---
2135ec
 vcl/inc/unx/gtk/gtkframe.hxx       |   2 +
2135ec
 vcl/unx/gtk/window/gtksalframe.cxx | 149 +++++++++++++++++++++++++++++++++++--
2135ec
 2 files changed, 144 insertions(+), 7 deletions(-)
2135ec
2135ec
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
2135ec
index c3ea919..cce16ab 100644
2135ec
--- a/vcl/inc/unx/gtk/gtkframe.hxx
2135ec
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
2135ec
@@ -309,7 +309,9 @@ public:
2135ec
     GtkSalFrame( SystemParentData* pSysData );
2135ec
 
2135ec
     guint                           m_nMenuExportId;
2135ec
+    guint                           m_nAppMenuExportId;
2135ec
     guint                           m_nActionGroupExportId;
2135ec
+    guint                           m_nAppActionGroupExportId;
2135ec
     guint                           m_nHudAwarenessId;
2135ec
 
2135ec
     // dispatches an event, returns true if dispatched
2135ec
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx
2135ec
index 0f53e93..a3e648a 100644
2135ec
--- a/vcl/unx/gtk/window/gtksalframe.cxx
2135ec
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
2135ec
@@ -21,6 +21,7 @@
2135ec
 #include <unx/gtk/gtkdata.hxx>
2135ec
 #include <unx/gtk/gtkinst.hxx>
2135ec
 #include <unx/gtk/gtkgdi.hxx>
2135ec
+#include <vcl/help.hxx>
2135ec
 #include <vcl/keycodes.hxx>
2135ec
 #include <vcl/layout.hxx>
2135ec
 #include <unx/wmadaptor.hxx>
2135ec
@@ -65,11 +66,17 @@
2135ec
 #  include <cstdio>
2135ec
 #endif
2135ec
 
2135ec
+#include <comphelper/processfactory.hxx>
2135ec
+#include <comphelper/sequenceashashmap.hxx>
2135ec
 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
2135ec
 #include <com/sun/star/accessibility/AccessibleRole.hpp>
2135ec
 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
2135ec
 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
2135ec
 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
2135ec
+#include <com/sun/star/frame/Desktop.hpp>
2135ec
+#include <com/sun/star/frame/ModuleManager.hpp>
2135ec
+#include <com/sun/star/frame/XFrame.hpp>
2135ec
+#include <com/sun/star/util/URLTransformer.hpp>
2135ec
 
2135ec
 #if GTK_CHECK_VERSION(3,0,0)
2135ec
 #  include <gdk/gdkkeysyms-compat.h>
2135ec
@@ -534,6 +541,71 @@ static void hud_activated( gboolean hud_active, gpointer user_data )
2135ec
     }
2135ec
 }
2135ec
 
2135ec
+static void activate_uno(GSimpleAction *action, GVariant*, gpointer)
2135ec
+{
2135ec
+    uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
2135ec
+
2135ec
+    uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create( xContext );
2135ec
+
2135ec
+    uno::Reference < css::frame::XFrame > xFrame(xDesktop->getActiveFrame());
2135ec
+    if (!xFrame.is())
2135ec
+        xFrame = uno::Reference < css::frame::XFrame >(xDesktop, uno::UNO_QUERY);
2135ec
+
2135ec
+    if (!xFrame.is())
2135ec
+        return;
2135ec
+
2135ec
+    uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, uno::UNO_QUERY);
2135ec
+    if (!xDispatchProvider.is())
2135ec
+        return;
2135ec
+
2135ec
+    gchar *strval = NULL;
2135ec
+    g_object_get(action, "name", &strval, NULL);
2135ec
+    if (!strval)
2135ec
+        return;
2135ec
+
2135ec
+    if (strcmp(strval, "New") == 0)
2135ec
+    {
2135ec
+        uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
2135ec
+        OUString aModuleId(xModuleManager->identify(xFrame));
2135ec
+        if (aModuleId.isEmpty())
2135ec
+            return;
2135ec
+
2135ec
+        comphelper::SequenceAsHashMap lModuleDescription(xModuleManager->getByName(aModuleId));
2135ec
+        OUString sFactoryService;
2135ec
+        lModuleDescription[OUString("ooSetupFactoryEmptyDocumentURL")] >>= sFactoryService;
2135ec
+        if (sFactoryService.isEmpty())
2135ec
+            return;
2135ec
+
2135ec
+        uno::Sequence < css::beans::PropertyValue > args(0);
2135ec
+        xDesktop->loadComponentFromURL(sFactoryService, OUString("_blank"), 0, args);
2135ec
+        return;
2135ec
+    }
2135ec
+
2135ec
+    OUString sCommand(".uno:");
2135ec
+    sCommand += OUString(strval, strlen(strval), RTL_TEXTENCODING_UTF8);
2135ec
+    g_free(strval);
2135ec
+
2135ec
+    css::util::URL aCommand;
2135ec
+    aCommand.Complete = sCommand;
2135ec
+    uno::Reference< css::util::XURLTransformer > xParser = css::util::URLTransformer::create(xContext);
2135ec
+    xParser->parseStrict(aCommand);
2135ec
+
2135ec
+    uno::Reference< css::frame::XDispatch > xDisp = xDispatchProvider->queryDispatch(aCommand, OUString(), 0);
2135ec
+
2135ec
+    if (!xDisp.is())
2135ec
+        return;
2135ec
+
2135ec
+    xDisp->dispatch(aCommand, css::uno::Sequence< css::beans::PropertyValue >());
2135ec
+}
2135ec
+
2135ec
+static GActionEntry app_entries[] = {
2135ec
+  { "OptionsTreeDialog", activate_uno, NULL, NULL, NULL, {0} },
2135ec
+  { "About", activate_uno, NULL, NULL, NULL, {0} },
2135ec
+  { "HelpIndex", activate_uno, NULL, NULL, NULL, {0} },
2135ec
+  { "Quit", activate_uno, NULL, NULL, NULL, {0} },
2135ec
+  { "New", activate_uno, NULL, NULL, NULL, {0} }
2135ec
+};
2135ec
+
2135ec
 gboolean ensure_dbus_setup( gpointer data )
2135ec
 {
2135ec
     GtkSalFrame* pSalFrame = reinterpret_cast< GtkSalFrame* >( data );
2135ec
@@ -553,29 +625,86 @@ gboolean ensure_dbus_setup( gpointer data )
2135ec
 
2135ec
         // Generate menu paths.
2135ec
         XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow );
2135ec
-        gchar* aDBusPath = g_strdup_printf("/window/%lu", windowId);
2135ec
-        gchar* aDBusWindowPath = g_strdup_printf( "/window/%lu", windowId );
2135ec
-        gchar* aDBusMenubarPath = g_strdup_printf( "/window/%lu/menus/menubar", windowId );
2135ec
+        gchar* aDBusWindowPath = g_strdup_printf( "/org/libreoffice/window/%lu", windowId );
2135ec
+        gchar* aDBusMenubarPath = g_strdup_printf( "/org/libreoffice/window/%lu/menus/menubar", windowId );
2135ec
 
2135ec
         // Set window properties.
2135ec
         g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", pMenuModel, ObjectDestroyedNotify );
2135ec
         g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", pActionGroup, ObjectDestroyedNotify );
2135ec
 
2135ec
+        gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APPLICATION_ID", "org.libreoffice" );
2135ec
         gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
2135ec
-        gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "" );
2135ec
+        gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "/org/libreoffice" );
2135ec
         gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath );
2135ec
         gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath );
2135ec
+        gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APP_MENU_OBJECT_PATH", "/org/libreoffice/menus/appmenu" );
2135ec
 
2135ec
         // Publish the menu model and the action group.
2135ec
         SAL_INFO("vcl.unity", "exporting menu model at " << pMenuModel << " for window " << windowId);
2135ec
         pSalFrame->m_nMenuExportId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pMenuModel, NULL);
2135ec
         SAL_INFO("vcl.unity", "exporting action group at " << pActionGroup << " for window " << windowId);
2135ec
-        pSalFrame->m_nActionGroupExportId = g_dbus_connection_export_action_group( pSessionBus, aDBusPath, pActionGroup, NULL);
2135ec
+        pSalFrame->m_nActionGroupExportId = g_dbus_connection_export_action_group( pSessionBus, aDBusWindowPath, pActionGroup, NULL);
2135ec
         pSalFrame->m_nHudAwarenessId = hud_awareness_register( pSessionBus, aDBusMenubarPath, hud_activated, pSalFrame, NULL, NULL );
2135ec
 
2135ec
-        g_free( aDBusPath );
2135ec
-        g_free( aDBusWindowPath );
2135ec
+        //app menu, to-do translations, block normal menus when active, honor use appmenu settings
2135ec
+        ResMgr* pMgr = ImplGetResMgr();
2135ec
+        if( pMgr )
2135ec
+        {
2135ec
+            GMenu *menu = g_menu_new ();
2135ec
+            GMenuItem* item;
2135ec
+
2135ec
+            GMenu *firstsubmenu = g_menu_new ();
2135ec
+
2135ec
+            OString sNew(OUStringToOString(ResId(SV_BUTTONTEXT_NEW, *pMgr).toString(),
2135ec
+                RTL_TEXTENCODING_UTF8).replaceFirst("~", "_"));
2135ec
+
2135ec
+            item = g_menu_item_new(sNew.getStr(), "app.New");
2135ec
+            g_menu_append_item( firstsubmenu, item );
2135ec
+
2135ec
+            g_menu_append_section( menu, NULL, G_MENU_MODEL(firstsubmenu));
2135ec
+
2135ec
+            GMenu *secondsubmenu = g_menu_new ();
2135ec
+
2135ec
+            OString sPreferences(OUStringToOString(ResId(SV_STDTEXT_PREFERENCES, *pMgr).toString(),
2135ec
+                RTL_TEXTENCODING_UTF8).replaceFirst("~", "_"));
2135ec
+
2135ec
+            item = g_menu_item_new(sPreferences.getStr(), "app.OptionsTreeDialog");
2135ec
+            g_menu_append_item( secondsubmenu, item );
2135ec
+
2135ec
+            g_menu_append_section( menu, NULL, G_MENU_MODEL(secondsubmenu));
2135ec
+            GMenu *thirdsubmenu = g_menu_new ();
2135ec
+
2135ec
+            OString sHelp(OUStringToOString(ResId(SV_BUTTONTEXT_HELP, *pMgr).toString(),
2135ec
+                RTL_TEXTENCODING_UTF8).replaceFirst("~", "_"));
2135ec
+
2135ec
+            item = g_menu_item_new(sHelp.getStr(), "app.HelpIndex");
2135ec
+            g_menu_append_item( thirdsubmenu, item );
2135ec
+
2135ec
+            OString sAbout(OUStringToOString(ResId(SV_STDTEXT_ABOUT, *pMgr).toString(),
2135ec
+                RTL_TEXTENCODING_UTF8).replaceFirst("~", "_"));
2135ec
+
2135ec
+            item = g_menu_item_new(sAbout.getStr(), "app.About");
2135ec
+            g_menu_append_item( thirdsubmenu, item );
2135ec
+
2135ec
+            OString sQuit(OUStringToOString(ResId(SV_MENU_MAC_QUITAPP, *pMgr).toString(),
2135ec
+                RTL_TEXTENCODING_UTF8).replaceFirst("~", "_"));
2135ec
+
2135ec
+            item = g_menu_item_new(sQuit.getStr(), "app.Quit");
2135ec
+            g_menu_append_item( thirdsubmenu, item );
2135ec
+            g_menu_append_section( menu, NULL, G_MENU_MODEL(thirdsubmenu));
2135ec
+
2135ec
+            GSimpleActionGroup *group = g_simple_action_group_new ();
2135ec
+            g_simple_action_group_add_entries (group, app_entries, G_N_ELEMENTS (app_entries), NULL);
2135ec
+            GActionGroup* pAppActionGroup = G_ACTION_GROUP(group);
2135ec
+
2135ec
+            pSalFrame->m_nAppActionGroupExportId = g_dbus_connection_export_action_group( pSessionBus, "/org/libreoffice", pAppActionGroup, NULL);
2135ec
+            g_object_unref(pAppActionGroup);
2135ec
+            pSalFrame->m_nAppMenuExportId = g_dbus_connection_export_menu_model (pSessionBus, "/org/libreoffice/menus/appmenu", G_MENU_MODEL (menu), NULL);
2135ec
+            g_object_unref(menu);
2135ec
+        }
2135ec
+
2135ec
         g_free( aDBusMenubarPath );
2135ec
+        g_free( aDBusWindowPath );
2135ec
     }
2135ec
 
2135ec
     return FALSE;
2135ec
@@ -707,8 +836,12 @@ GtkSalFrame::~GtkSalFrame()
2135ec
                     hud_awareness_unregister( pSessionBus, m_nHudAwarenessId );
2135ec
                 if ( m_nMenuExportId )
2135ec
                     g_dbus_connection_unexport_menu_model( pSessionBus, m_nMenuExportId );
2135ec
+                if ( m_nAppMenuExportId )
2135ec
+                    g_dbus_connection_unexport_menu_model( pSessionBus, m_nAppMenuExportId );
2135ec
                 if ( m_nActionGroupExportId )
2135ec
                     g_dbus_connection_unexport_action_group( pSessionBus, m_nActionGroupExportId );
2135ec
+                if ( m_nAppActionGroupExportId )
2135ec
+                    g_dbus_connection_unexport_action_group( pSessionBus, m_nAppActionGroupExportId );
2135ec
             }
2135ec
 #endif
2135ec
             gtk_widget_destroy( m_pWindow );
2135ec
@@ -828,7 +961,9 @@ void GtkSalFrame::InitCommon()
2135ec
     m_pSalMenu          = NULL;
2135ec
     m_nWatcherId        = 0;
2135ec
     m_nMenuExportId     = 0;
2135ec
+    m_nAppMenuExportId  = 0;
2135ec
     m_nActionGroupExportId = 0;
2135ec
+    m_nAppActionGroupExportId = 0;
2135ec
     m_nHudAwarenessId   = 0;
2135ec
 
2135ec
     gtk_widget_set_app_paintable( m_pWindow, TRUE );
2135ec
-- 
2135ec
1.8.3.1
2135ec