Blob Blame History Raw
From cb62457c638e4bd4d951bcf664040326c840824c Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Mon, 26 Oct 2015 14:20:26 +0100
Subject: [PATCH 233/398] lok clipboard: support rich text paste

Change-Id: Ida5028969782be792b32b952d3adba0c30dd8bae
(cherry picked from commit faa316e670414363dcfb6db6001fdb209f4a48c1)
---
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  3 +++
 desktop/source/lib/lokclipboard.cxx         | 11 ++++++++---
 desktop/source/lib/lokclipboard.hxx         |  2 +-
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 12831318dde3..d4135b66d1d8 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -338,7 +338,10 @@ void DesktopLOKTest::testPasteWriter()
     CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText));
     free(pText);
 
+    // textt/plain should be rejected.
     CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
+    // Writer is expected to support text/html.
+    CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/html", aText.getStr(), aText.getLength()));
 
     comphelper::LibreOfficeKit::setActive(false);
 }
diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
index a81902b15b6b..50d570577e27 100644
--- a/desktop/source/lib/lokclipboard.cxx
+++ b/desktop/source/lib/lokclipboard.cxx
@@ -32,7 +32,7 @@ OUString SAL_CALL LOKClipboard::getName() throw (uno::RuntimeException, std::exc
 
 LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, size_t nSize)
     : m_aMimeType(pMimeType),
-      m_aText(pData, nSize)
+      m_aSequence(reinterpret_cast<const sal_Int8*>(pData), nSize)
 {
 }
 
@@ -40,8 +40,13 @@ uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavo
 throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException, std::exception)
 {
     uno::Any aRet;
-    if (m_aMimeType == "text/plain;charset=utf-8" && rFlavor.MimeType == "text/plain;charset=utf-16")
-        aRet <<= OStringToOUString(m_aText, RTL_TEXTENCODING_UTF8);
+    if (rFlavor.DataType == cppu::UnoType<OUString>::get())
+    {
+        sal_Char* pText = reinterpret_cast<sal_Char*>(m_aSequence.getArray());
+        aRet <<= OUString(pText, rtl_str_getLength(pText), RTL_TEXTENCODING_UTF8);
+    }
+    else
+        aRet <<= m_aSequence;
     return aRet;
 }
 
diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx
index b982e1c734ee..a0ab6451e0c0 100644
--- a/desktop/source/lib/lokclipboard.hxx
+++ b/desktop/source/lib/lokclipboard.hxx
@@ -35,7 +35,7 @@ public:
 class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
 {
     OString m_aMimeType;
-    OString m_aText;
+    css::uno::Sequence<sal_Int8> m_aSequence;
 
     /// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported().
     std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector();
-- 
2.12.0