Blame SOURCES/0234-gtktiledviwer-try-to-paste-as-html-then-as-plain-tex.patch

135360
From cd8468af6c005d3ba1f11eff0fdc04344a282c31 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Mon, 26 Oct 2015 14:25:26 +0100
135360
Subject: [PATCH 234/398] gtktiledviwer: try to paste as html, then as plain
135360
 text
135360
135360
Change-Id: I8e1c93fd36fb903c0625b29f9f73825438c9e113
135360
(cherry picked from commit 080bd44f0b0300075ff18d377f31deebbc4009ed)
135360
---
135360
 desktop/source/lib/lokclipboard.cxx                |  2 +-
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 28 ++++++++++++++++++++++
135360
 2 files changed, 29 insertions(+), 1 deletion(-)
135360
135360
diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
135360
index 50d570577e27..376bcd72d238 100644
135360
--- a/desktop/source/lib/lokclipboard.cxx
135360
+++ b/desktop/source/lib/lokclipboard.cxx
135360
@@ -43,7 +43,7 @@ throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeExc
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
+        aRet <<= OUString(pText, m_aSequence.getLength(), RTL_TEXTENCODING_UTF8);
135360
     }
135360
     else
135360
         aRet <<= m_aSequence;
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index b0ea03ee6796..72afd52131ad 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -15,6 +15,7 @@
135360
 #include <iostream>
135360
 
135360
 #include <boost/property_tree/json_parser.hpp>
135360
+#include <boost/optional.hpp>
135360
 #include <gdk/gdkkeysyms.h>
135360
 
135360
 #define LOK_USE_UNSTABLE_API
135360
@@ -287,6 +288,33 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
135360
     LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
135360
 
135360
     GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD);
135360
+
135360
+    GdkAtom* pTargets;
135360
+    gint nTargets;
135360
+    boost::optional<GdkAtom> oTarget;
135360
+    if (gtk_clipboard_wait_for_targets(pClipboard, &pTargets, &nTargets))
135360
+    {
135360
+        for (gint i = 0; i < nTargets; ++i)
135360
+        {
135360
+            gchar* pName = gdk_atom_name(pTargets[i]);
135360
+            if (std::string(pName) == "text/html")
135360
+                oTarget = pTargets[i];
135360
+            g_free(pName);
135360
+        }
135360
+        g_free(pTargets);
135360
+    }
135360
+
135360
+    if (oTarget)
135360
+    {
135360
+        GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget);
135360
+        gint nLength;
135360
+        const guchar* pData = gtk_selection_data_get_data_with_length(pSelectionData, &nLength);
135360
+        bool bSuccess = pDocument->pClass->paste(pDocument, "text/html", reinterpret_cast<const char*>(pData), nLength);
135360
+        gtk_selection_data_free(pSelectionData);
135360
+        if (bSuccess)
135360
+            return;
135360
+    }
135360
+
135360
     gchar* pText = gtk_clipboard_wait_for_text(pClipboard);
135360
     if (pText)
135360
         pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", pText, strlen(pText));
135360
-- 
135360
2.12.0
135360