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