135360
From cb62457c638e4bd4d951bcf664040326c840824c Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Mon, 26 Oct 2015 14:20:26 +0100
135360
Subject: [PATCH 233/398] lok clipboard: support rich text paste
135360
135360
Change-Id: Ida5028969782be792b32b952d3adba0c30dd8bae
135360
(cherry picked from commit faa316e670414363dcfb6db6001fdb209f4a48c1)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  3 +++
135360
 desktop/source/lib/lokclipboard.cxx         | 11 ++++++++---
135360
 desktop/source/lib/lokclipboard.hxx         |  2 +-
135360
 3 files changed, 12 insertions(+), 4 deletions(-)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 12831318dde3..d4135b66d1d8 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -338,7 +338,10 @@ void DesktopLOKTest::testPasteWriter()
135360
     CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText));
135360
     free(pText);
135360
 
135360
+    // textt/plain should be rejected.
135360
     CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
135360
+    // Writer is expected to support text/html.
135360
+    CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/html", aText.getStr(), aText.getLength()));
135360
 
135360
     comphelper::LibreOfficeKit::setActive(false);
135360
 }
135360
diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
135360
index a81902b15b6b..50d570577e27 100644
135360
--- a/desktop/source/lib/lokclipboard.cxx
135360
+++ b/desktop/source/lib/lokclipboard.cxx
135360
@@ -32,7 +32,7 @@ OUString SAL_CALL LOKClipboard::getName() throw (uno::RuntimeException, std::exc
135360
 
135360
 LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, size_t nSize)
135360
     : m_aMimeType(pMimeType),
135360
-      m_aText(pData, nSize)
135360
+      m_aSequence(reinterpret_cast<const sal_Int8*>(pData), nSize)
135360
 {
135360
 }
135360
 
135360
@@ -40,8 +40,13 @@ uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavo
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
+    if (rFlavor.DataType == cppu::UnoType<OUString>::get())
135360
+    {
135360
+        sal_Char* pText = reinterpret_cast<sal_Char*>(m_aSequence.getArray());
135360
+        aRet <<= OUString(pText, rtl_str_getLength(pText), RTL_TEXTENCODING_UTF8);
135360
+    }
135360
+    else
135360
+        aRet <<= m_aSequence;
135360
     return aRet;
135360
 }
135360
 
135360
diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx
135360
index b982e1c734ee..a0ab6451e0c0 100644
135360
--- a/desktop/source/lib/lokclipboard.hxx
135360
+++ b/desktop/source/lib/lokclipboard.hxx
135360
@@ -35,7 +35,7 @@ public:
135360
 class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
135360
 {
135360
     OString m_aMimeType;
135360
-    OString m_aText;
135360
+    css::uno::Sequence<sal_Int8> m_aSequence;
135360
 
135360
     /// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported().
135360
     std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector();
135360
-- 
135360
2.12.0
135360