kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

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

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