[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - desktop/qa desktop/source include/LibreOfficeKit

Szymon Kłos (via logerrit) logerrit at kemper.freedesktop.org
Tue Oct 15 14:00:18 UTC 2019


 desktop/qa/desktop_lib/test_desktop_lib.cxx |    4 +-
 desktop/source/lib/init.cxx                 |   45 +++++++++++++++++++++++++++-
 include/LibreOfficeKit/LibreOfficeKit.h     |    5 +++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   11 ++++++
 4 files changed, 63 insertions(+), 2 deletions(-)

New commits:
commit f8c79e52842e5f0837de0382f530e0cc44e15e32
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Oct 11 08:53:14 2019 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Oct 15 15:59:03 2019 +0200

    jsdialogs: handle dialog events
    
    Change-Id: Icc092cd5b06168d9de8ebed891fc03491865dbad
    Reviewed-on: https://gerrit.libreoffice.org/80833
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 92f275784fc9..760831fabb4d 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2753,10 +2753,12 @@ void DesktopLOKTest::testABI()
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(53), offsetof(struct _LibreOfficeKitDocumentClass, setClipboard));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(54), offsetof(struct _LibreOfficeKitDocumentClass, getSelectionType));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(55), offsetof(struct _LibreOfficeKitDocumentClass, removeTextContext));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(56), offsetof(struct _LibreOfficeKitDocumentClass, sendDialogEvent));
+
 
     // Extending is fine, update this, and add new assert for the offsetof the
     // new method
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(56), sizeof(struct _LibreOfficeKitDocumentClass));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(57), sizeof(struct _LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a9c7fd897808..253adffceb77 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -147,6 +147,7 @@
 #include <i18nlangtag/languagetag.hxx>
 #include <vcl/builder.hxx>
 #include <vcl/abstdlg.hxx>
+#include <vcl/uitest/uiobject.hxx>
 
 #include <app.hxx>
 
@@ -768,7 +769,9 @@ static void doc_removeTextContext(LibreOfficeKitDocument* pThis,
                                   unsigned nLOKWindowId,
                                   int nCharBefore,
                                   int nCharAfter);
-
+static void doc_sendDialogEvent(LibreOfficeKitDocument* pThis,
+                               unsigned nLOKWindowId,
+                               const char* pArguments);
 static void doc_postWindowKeyEvent(LibreOfficeKitDocument* pThis,
                                    unsigned nLOKWindowId,
                                    int nType,
@@ -942,6 +945,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->postWindowKeyEvent = doc_postWindowKeyEvent;
         m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
         m_pDocumentClass->postWindowMouseEvent = doc_postWindowMouseEvent;
+        m_pDocumentClass->sendDialogEvent = doc_sendDialogEvent;
         m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
         m_pDocumentClass->setTextSelection = doc_setTextSelection;
         m_pDocumentClass->getTextSelection = doc_getTextSelection;
@@ -3256,6 +3260,45 @@ public:
     virtual void SAL_CALL disposing(const css::lang::EventObject&) override {}
 };
 
+static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWindowId, const char* pArguments)
+{
+    SolarMutexGuard aGuard;
+
+    char* pCopy = strdup(pArguments);
+    if (!pCopy) {
+        SetLastExceptionMsg("String copying error.");
+        return;
+    }
+
+    char* pIdChar = strtok(pCopy, " ");
+
+    if (!pIdChar) {
+        SetLastExceptionMsg("Error parsing the command.");
+        return;
+    }
+
+    OUString sId = OUString::createFromAscii(pIdChar);
+    free(pCopy);
+
+    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nWindowId);
+    if (!pWindow)
+    {
+        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+        return;
+    }
+    else
+    {
+        OUString sAction("CLICK");
+        WindowUIObject aUIObject(pWindow);
+        std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(sId));
+        if (pUIWindow)
+            pUIWindow->execute(sAction, StringMap());
+
+        // force resend
+        pWindow->Resize();
+    }
+}
+
 static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
 {
     comphelper::ProfileZone aZone("doc_postUnoCommand");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 6060b015be01..29d834969ad6 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -414,6 +414,11 @@ struct _LibreOfficeKitDocumentClass
                                int nBefore,
                                int nAfter);
 
+    /// @see lok::Document::sendDialogEvent
+    void (*sendDialogEvent) (LibreOfficeKitDocument* pThis,
+                            unsigned nLOKWindowId,
+                            const char* pArguments);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index ed64d6447fe6..8c8453086c63 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -303,6 +303,17 @@ public:
     }
 
     /**
+     * Posts a dialog event for the window with given id
+     *
+     * @param nWindowId id of the window to notify
+     * @param pArguments arguments of the event.
+     */
+    void sendDialogEvent(unsigned nWindowId, const char* pArguments = NULL)
+    {
+        mpDoc->pClass->sendDialogEvent(mpDoc, nWindowId, pArguments);
+    }
+
+    /**
      * Posts a UNO command to the document.
      *
      * Example argument string:


More information about the Libreoffice-commits mailing list