kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0225-LOK-add-Document-paste.patch

135360
From 89ad7ba2b6f480c20d332bc3c171045afe21e23b Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Thu, 22 Oct 2015 11:26:13 +0200
135360
Subject: [PATCH 225/398] LOK: add Document::paste()
135360
135360
Change-Id: I34998229e7f5cac4c62c859861783be3c161f9bf
135360
(cherry picked from commit 6552767aa5ed61215eb64dac0cc026a5f7a9aad1)
135360
---
135360
 desktop/Library_sofficeapp.mk             |  2 +
135360
 desktop/source/lib/init.cxx               | 38 ++++++++++++++
135360
 desktop/source/lib/lokclipboard.cxx       | 83 +++++++++++++++++++++++++++++++
135360
 desktop/source/lib/lokclipboard.hxx       | 58 +++++++++++++++++++++
135360
 include/LibreOfficeKit/LibreOfficeKit.h   |  6 +++
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx | 12 +++++
135360
 6 files changed, 199 insertions(+)
135360
 create mode 100644 desktop/source/lib/lokclipboard.cxx
135360
 create mode 100644 desktop/source/lib/lokclipboard.hxx
135360
135360
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
135360
index 2e3acb79b3c6..fb73cfa78f4b 100644
135360
--- a/desktop/Library_sofficeapp.mk
135360
+++ b/desktop/Library_sofficeapp.mk
135360
@@ -122,6 +122,7 @@ ifneq ($(filter $(OS),ANDROID IOS),)
135360
 $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
135360
 	desktop/source/lib/init \
135360
 	desktop/source/lib/lokinteractionhandler \
135360
+	desktop/source/lib/lokclipboard \
135360
 	$(if $(filter $(OS),ANDROID), \
135360
 		desktop/source/lib/lokandroid) \
135360
 ))
135360
@@ -130,6 +131,7 @@ ifeq ($(GUIBASE),unx)
135360
 $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
135360
 	desktop/source/lib/init \
135360
 	desktop/source/lib/lokinteractionhandler \
135360
+	desktop/source/lib/lokclipboard \
135360
 ))
135360
 endif
135360
 endif
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 01fe099ccbe9..0459176c24a0 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -43,6 +43,7 @@
135360
 #include <com/sun/star/ucb/XContentProvider.hpp>
135360
 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
135360
 #include <com/sun/star/util/URLTransformer.hpp>
135360
+#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
135360
 
135360
 #include <editeng/fontitem.hxx>
135360
 #include <editeng/flstitem.hxx>
135360
@@ -78,6 +79,7 @@
135360
 #include "../../inc/lib/init.hxx"
135360
 
135360
 #include "lokinteractionhandler.hxx"
135360
+#include <lokclipboard.hxx>
135360
 
135360
 using namespace css;
135360
 using namespace vcl;
135360
@@ -246,6 +248,10 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
135360
 static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
135360
                                   const char* pMimeType,
135360
                                   char** pUsedMimeType);
135360
+static bool doc_paste(LibreOfficeKitDocument* pThis,
135360
+                      const char* pMimeType,
135360
+                      const char* pData,
135360
+                      size_t nSize);
135360
 static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
135360
                                   int nType,
135360
                                   int nX,
135360
@@ -286,6 +292,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
135360
         m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
135360
         m_pDocumentClass->setTextSelection = doc_setTextSelection;
135360
         m_pDocumentClass->getTextSelection = doc_getTextSelection;
135360
+        m_pDocumentClass->paste = doc_paste;
135360
         m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
135360
         m_pDocumentClass->resetSelection = doc_resetSelection;
135360
         m_pDocumentClass->getCommandValues = doc_getCommandValues;
135360
@@ -989,6 +996,37 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
135360
     return pMemory;
135360
 }
135360
 
135360
+static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, const char* pData, size_t nSize)
135360
+{
135360
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
+    if (!pDoc)
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
135360
+        return false;
135360
+    }
135360
+
135360
+    uno::Reference<datatransfer::XTransferable> xTransferable(new LOKTransferable(pMimeType, pData, nSize));
135360
+    uno::Reference<datatransfer::clipboard::XClipboard> xClipboard(new LOKClipboard());
135360
+    xClipboard->setContents(xTransferable, uno::Reference<datatransfer::clipboard::XClipboardOwner>());
135360
+    vcl::Window* pWindow = pDoc->getWindow();
135360
+    if (!pWindow)
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Document did not provide a window";
135360
+        return false;
135360
+    }
135360
+
135360
+    pWindow->SetClipboard(xClipboard);
135360
+    OUString aCommand(".uno:Paste");
135360
+    uno::Sequence<beans::PropertyValue> aPropertyValues;
135360
+    if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
135360
+        return false;
135360
+    }
135360
+
135360
+    return true;
135360
+}
135360
+
135360
 static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
135360
 {
135360
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
135360
new file mode 100644
135360
index 000000000000..a81902b15b6b
135360
--- /dev/null
135360
+++ b/desktop/source/lib/lokclipboard.cxx
135360
@@ -0,0 +1,83 @@
135360
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
135360
+/*
135360
+ * This file is part of the LibreOffice project.
135360
+ *
135360
+ * This Source Code Form is subject to the terms of the Mozilla Public
135360
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
135360
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
135360
+ */
135360
+
135360
+#include <lokclipboard.hxx>
135360
+#include <comphelper/sequence.hxx>
135360
+
135360
+using namespace com::sun::star;
135360
+
135360
+uno::Reference<datatransfer::XTransferable> SAL_CALL LOKClipboard::getContents()
135360
+throw (uno::RuntimeException, std::exception)
135360
+{
135360
+    return m_xTransferable;
135360
+}
135360
+
135360
+void SAL_CALL LOKClipboard::setContents(const uno::Reference<datatransfer::XTransferable>& xTransferable,
135360
+                                        const uno::Reference<datatransfer::clipboard::XClipboardOwner>& /*xClipboardOwner*/)
135360
+throw (uno::RuntimeException, std::exception)
135360
+{
135360
+    m_xTransferable = xTransferable;
135360
+}
135360
+
135360
+OUString SAL_CALL LOKClipboard::getName() throw (uno::RuntimeException, std::exception)
135360
+{
135360
+    return OUString();
135360
+}
135360
+
135360
+LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, size_t nSize)
135360
+    : m_aMimeType(pMimeType),
135360
+      m_aText(pData, nSize)
135360
+{
135360
+}
135360
+
135360
+uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
135360
+throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException, std::exception)
135360
+{
135360
+    uno::Any aRet;
135360
+    if (m_aMimeType == "text/plain;charset=utf-8" && rFlavor.MimeType == "text/plain;charset=utf-16")
135360
+        aRet <<= OStringToOUString(m_aText, RTL_TEXTENCODING_UTF8);
135360
+    return aRet;
135360
+}
135360
+
135360
+std::vector<datatransfer::DataFlavor> LOKTransferable::getTransferDataFlavorsAsVector()
135360
+{
135360
+    std::vector<datatransfer::DataFlavor> aRet;
135360
+    datatransfer::DataFlavor aFlavor;
135360
+    aFlavor.MimeType = OUString::fromUtf8(m_aMimeType.getStr());
135360
+    aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
135360
+
135360
+    sal_Int32 nIndex(0);
135360
+    if (m_aMimeType.getToken(0, ';', nIndex) == "text/plain")
135360
+    {
135360
+        if (m_aMimeType.getToken(0, ';', nIndex) != "charset=utf-16")
135360
+            aFlavor.MimeType = "text/plain;charset=utf-16";
135360
+        aFlavor.DataType = cppu::UnoType<OUString>::get();
135360
+    }
135360
+    aRet.push_back(aFlavor);
135360
+
135360
+    return aRet;
135360
+}
135360
+
135360
+uno::Sequence<datatransfer::DataFlavor> SAL_CALL LOKTransferable::getTransferDataFlavors()
135360
+throw(uno::RuntimeException, std::exception)
135360
+{
135360
+    return comphelper::containerToSequence(getTransferDataFlavorsAsVector());
135360
+}
135360
+
135360
+sal_Bool SAL_CALL LOKTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
135360
+throw(uno::RuntimeException, std::exception)
135360
+{
135360
+    const std::vector<datatransfer::DataFlavor> aFlavors = getTransferDataFlavorsAsVector();
135360
+    return std::find_if(aFlavors.begin(), aFlavors.end(), [&rFlavor](const datatransfer::DataFlavor& i)
135360
+    {
135360
+        return i.MimeType == rFlavor.MimeType && i.DataType == rFlavor.DataType;
135360
+    }) != aFlavors.end();
135360
+}
135360
+
135360
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx
135360
new file mode 100644
135360
index 000000000000..b982e1c734ee
135360
--- /dev/null
135360
+++ b/desktop/source/lib/lokclipboard.hxx
135360
@@ -0,0 +1,58 @@
135360
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
135360
+/*
135360
+ * This file is part of the LibreOffice project.
135360
+ *
135360
+ * This Source Code Form is subject to the terms of the Mozilla Public
135360
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
135360
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
135360
+ */
135360
+
135360
+#ifndef INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
135360
+#define INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
135360
+
135360
+#include <vector>
135360
+
135360
+#include <cppuhelper/implbase.hxx>
135360
+#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
135360
+
135360
+/// A clipboard implementation for LibreOfficeKit.
135360
+class LOKClipboard : public cppu::WeakImplHelper<css::datatransfer::clipboard::XClipboard>
135360
+{
135360
+    css::uno::Reference<css::datatransfer::XTransferable> m_xTransferable;
135360
+
135360
+public:
135360
+    virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents()
135360
+    throw(css::uno::RuntimeException, std::exception) override;
135360
+
135360
+    virtual void SAL_CALL setContents(const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
135360
+                                      const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
135360
+    throw(css::uno::RuntimeException, std::exception) override;
135360
+
135360
+    virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) override;
135360
+};
135360
+
135360
+/// Represents the contents of LOKClipboard.
135360
+class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
135360
+{
135360
+    OString m_aMimeType;
135360
+    OString m_aText;
135360
+
135360
+    /// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported().
135360
+    std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector();
135360
+
135360
+public:
135360
+    LOKTransferable(const char* pMimeType, const char* pData, size_t nSize);
135360
+
135360
+    virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor)
135360
+    throw(css::datatransfer::UnsupportedFlavorException, css::io::IOException, css::uno::RuntimeException, std::exception) override;
135360
+
135360
+    virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors()
135360
+    throw(css::uno::RuntimeException, std::exception) override;
135360
+
135360
+    virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor)
135360
+    throw(css::uno::RuntimeException, std::exception) override;
135360
+};
135360
+
135360
+#endif
135360
+
135360
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
135360
index 83dcc9803d8a..d83717b4a809 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -157,6 +157,12 @@ struct _LibreOfficeKitDocumentClass
135360
                                const char* pMimeType,
135360
                                char** pUsedMimeType);
135360
 
135360
+    /// @see lok::Document::paste().
135360
+    bool (*paste) (LibreOfficeKitDocument* pThis,
135360
+                   const char* pMimeType,
135360
+                   const char* pData,
135360
+                   size_t nSize);
135360
+
135360
     /// @see lok::Document::setGraphicSelection
135360
     void (*setGraphicSelection) (LibreOfficeKitDocument* pThis,
135360
                                  int nType,
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
index e9167c510110..db7807d999ea 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -247,6 +247,18 @@ public:
135360
     }
135360
 
135360
     /**
135360
+     * Pastes content at the current cursor position.
135360
+     *
135360
+     * @param pMimeType format of pData, for example text/plain;charset=utf-8.
135360
+     * @param pData the actual data to be pasted.
135360
+     * @return if the supplied data was pasted successfully.
135360
+     */
135360
+    inline bool paste(const char* pMimeType, const char* pData, size_t nSize)
135360
+    {
135360
+        return mpDoc->pClass->paste(mpDoc, pMimeType, pData, nSize);
135360
+    }
135360
+
135360
+    /**
135360
      * Adjusts the graphic selection.
135360
      *
135360
      * @param nType @see LibreOfficeKitSetGraphicSelectionType
135360
-- 
135360
2.12.0
135360