[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - comphelper/Library_comphelper.mk comphelper/source desktop/source include/comphelper include/LibreOfficeKit libreofficekit/qa libreofficekit/source vcl/source

Jan Holesovsky kendy at collabora.com
Thu Mar 12 07:02:20 PDT 2015


 comphelper/Library_comphelper.mk                    |    1 
 comphelper/source/misc/dispatchcommand.cxx          |   64 ++++++++++++++++++++
 desktop/source/lib/init.cxx                         |   14 ++++
 include/LibreOfficeKit/LibreOfficeKit.h             |    4 +
 include/LibreOfficeKit/LibreOfficeKit.hxx           |   10 +++
 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    3 
 include/comphelper/dispatchcommand.hxx              |   31 +++++++++
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   15 ++++
 libreofficekit/source/gtk/lokdocview.cxx            |    5 +
 vcl/source/control/button.cxx                       |   33 ----------
 10 files changed, 149 insertions(+), 31 deletions(-)

New commits:
commit 0f91f16748570e20dd122f66a2b51834bc438225
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Mar 12 14:59:59 2015 +0100

    LOK: Implement posting of .uno: commands.
    
    Implements also Bold button as an example in the gtktiledviewer.
    
    Change-Id: I3b07d51165f28534aadbb4673f964ec10d5fc6ef

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index e1e0cb2..40b05b5 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -26,6 +26,7 @@
 #include <rtl/strbuf.hxx>
 #include <rtl/bootstrap.hxx>
 #include <cppuhelper/bootstrap.hxx>
+#include <comphelper/dispatchcommand.hxx>
 #include <comphelper/processfactory.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -212,6 +213,8 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
                                 int nX,
                                 int nY,
                                 int nCount);
+static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
+                               const char* pCommand);
 static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
                                   int nType,
                                   int nX,
@@ -250,6 +253,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
             m_pDocumentClass->registerCallback = doc_registerCallback;
             m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
             m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
+            m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
             m_pDocumentClass->setTextSelection = doc_setTextSelection;
             m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
             m_pDocumentClass->resetSelection = doc_resetSelection;
@@ -722,6 +726,16 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* /*pThis*/, int nType, int n
 #endif
 }
 
+static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand)
+{
+    OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
+
+    if (!comphelper::dispatchCommand(aCommand))
+    {
+        gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
+    }
+}
+
 static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount)
 {
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 07a2a2c..ee217ed 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -133,6 +133,10 @@ struct _LibreOfficeKitDocumentClass
                          int nX,
                          int nY,
                          int nCount);
+  /// @see lok::Document::postUnoCommand
+  void (*postUnoCommand)(LibreOfficeKitDocument* pThis,
+                         const char* pCommand);
+
   /// @see lok::Document::setTextSelection
   void (*setTextSelection)(LibreOfficeKitDocument* pThis,
                          int nType,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index c19aa50..1d7d709 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -131,6 +131,16 @@ public:
     }
 
     /**
+     * Posts an UNO command to the document.
+     *
+     * @param pCommand uno command to be posted to the document, like ".uno:Bold"
+     */
+    inline void postUnoCommand(const char* pCommand)
+    {
+        mpDoc->pClass->postUnoCommand(mpDoc, pCommand);
+    }
+
+    /**
      * Sets the start or end of a text selection.
      *
      * @param nType @see LibreOfficeKitSetTextSelectionType
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 77e9118..f088f49 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -121,6 +121,9 @@ void            lok_docview_set_edit        (LOKDocView* pDocView,
                                              gboolean bEdit);
 /// Gets if the viewer is actually an editor or not.
 gboolean        lok_docview_get_edit        (LOKDocView* pDocView);
+
+/// Posts the .uno: command to the LibreOfficeKit.
+void            lok_docview_post_command    (LOKDocView* pDocView, const char* pCommand);
 #ifdef __cplusplus
 }
 #endif
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 32a107e..92ffdd4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -35,6 +35,7 @@ static int help()
 
 static GtkWidget* pDocView;
 static GtkToolItem* pEnableEditing;
+static GtkToolItem* pBold;
 static GtkWidget* pDocViewQuad;
 static GtkWidget* pVBox;
 // GtkComboBox requires gtk 2.24 or later
@@ -124,6 +125,14 @@ static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pD
         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
 }
 
+/// User clicked on the 'Bold' button -> inform LOKDocView.
+void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+{
+    LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+
+    lok_docview_post_command(pLOKDocView, ".uno:Bold");
+}
+
 void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
 {
     if ( pDocView )
@@ -364,6 +373,12 @@ int main( int argc, char* argv[] )
     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
     g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), NULL);
 
+    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
+    pBold = gtk_toggle_tool_button_new();
+    gtk_tool_button_set_label(GTK_TOOL_BUTTON(pBold), "Bold");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pBold, -1);
+    g_signal_connect(G_OBJECT(pBold), "toggled", G_CALLBACK(toggleBold), NULL);
+
     gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
 
     // Docview
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 8349256..e3fd1cb 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -971,4 +971,9 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
     return pDocView->m_bEdit;
 }
 
+SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand)
+{
+    pDocView->pDocument->pClass->postUnoCommand(pDocView->pDocument, pCommand);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit c07efa8eb16434b063c948f316d45b1316b857f6
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Mar 12 14:04:31 2015 +0100

    Factor out the .uno: command dispatching to a separate function / file.
    
    Change-Id: I8486933d57d42992e66be7f17443320cfc2ad629

diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index 7a263c9..e36fe31 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -82,6 +82,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
     comphelper/source/misc/componentmodule \
     comphelper/source/misc/configuration \
     comphelper/source/misc/configurationhelper \
+    comphelper/source/misc/dispatchcommand \
     comphelper/source/misc/docpasswordhelper \
     comphelper/source/misc/docpasswordrequest \
     comphelper/source/misc/documentinfo \
diff --git a/comphelper/source/misc/dispatchcommand.cxx b/comphelper/source/misc/dispatchcommand.cxx
new file mode 100644
index 0000000..dd43523
--- /dev/null
+++ b/comphelper/source/misc/dispatchcommand.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <comphelper/dispatchcommand.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/URLTransformer.hpp>
+
+using namespace css;
+
+namespace comphelper {
+
+bool dispatchCommand(const OUString& rCommand)
+{
+    // Target where we will execute the .uno: command
+    uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+    uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
+
+    uno::Reference<frame::XFrame> xFrame(xDesktop->getActiveFrame());
+    if (!xFrame.is())
+        xFrame = uno::Reference<frame::XFrame>(xDesktop, uno::UNO_QUERY);
+
+    uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, uno::UNO_QUERY);
+    if (!xDispatchProvider.is())
+        return false;
+
+    util::URL aCommandURL;
+    aCommandURL.Complete = rCommand;
+    uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext);
+    xParser->parseStrict(aCommandURL);
+
+    uno::Reference<frame::XDispatch> xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0);
+    if (!xDisp.is())
+        return false;
+
+    // And do the work...
+    xDisp->dispatch(aCommandURL, uno::Sequence<beans::PropertyValue>());
+
+    return true;
+}
+
+} // namespace comphelper
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/dispatchcommand.hxx b/include/comphelper/dispatchcommand.hxx
new file mode 100644
index 0000000..7289dd7
--- /dev/null
+++ b/include/comphelper/dispatchcommand.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_COMPHELPER_DISPATCHCOMMAND_HXX
+#define INCLUDED_COMPHELPER_DISPATCHCOMMAND_HXX
+
+#include <comphelper/comphelperdllapi.h>
+#include <rtl/ustring.hxx>
+
+namespace comphelper
+{
+
+/** Dispatch the given UNO command in the active frame.
+
+    @param rCommand the command to dispatch, like ".uno:Bold".
+
+    @return true on success.
+*/
+COMPHELPER_DLLPUBLIC bool dispatchCommand(const OUString& rCommand);
+
+}
+
+#endif // INCLUDED_COMPHELPER_DISPATCHCOMMAND_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index be4b464..ec9b9a0 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -41,13 +41,7 @@
 #include <window.h>
 #include <controldata.hxx>
 
-#include <comphelper/processfactory.hxx>
-
-#include <com/sun/star/frame/Desktop.hpp>
-#include <com/sun/star/frame/XDispatch.hpp>
-#include <com/sun/star/frame/XDispatchProvider.hpp>
-#include <com/sun/star/util/URL.hpp>
-#include <com/sun/star/util/URLTransformer.hpp>
+#include <comphelper/dispatchcommand.hxx>
 
 using namespace css;
 
@@ -605,35 +599,12 @@ sal_IntPtr Button::dispatchCommandHandler(void *, void *pCaller)
     if (pButton == NULL)
         return 0;
 
-    // Target where we will execute the .uno: command
-    uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
-    uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
-
-    uno::Reference<frame::XFrame> xFrame(xDesktop->getActiveFrame());
-    if (!xFrame.is())
-        xFrame = uno::Reference<frame::XFrame>(xDesktop, uno::UNO_QUERY);
-
-    uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, uno::UNO_QUERY);
-    if (!xDispatchProvider.is())
+    if (!comphelper::dispatchCommand(pButton->maCommand))
         return 0;
 
-    util::URL aCommandURL;
-    aCommandURL.Complete = pButton->maCommand;
-    uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext);
-    xParser->parseStrict(aCommandURL);
-
-    uno::Reference<frame::XDispatch> xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0);
-    if (!xDisp.is())
-        return 0;
-
-    // And do the work...
-    xDisp->dispatch(aCommandURL, uno::Sequence<beans::PropertyValue>());
-
     return 1;
 }
 
-
-
 void PushButton::ImplInitPushButtonData()
 {
     mpWindowImpl->mbPushButton    = true;


More information about the Libreoffice-commits mailing list