diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-10-26 14:25:26 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-10-26 15:39:52 +0100 |
commit | 080bd44f0b0300075ff18d377f31deebbc4009ed (patch) | |
tree | 872b3e5c87d4d348440c45290542a791274096c0 /libreofficekit | |
parent | faa316e670414363dcfb6db6001fdb209f4a48c1 (diff) |
gtktiledviwer: try to paste as html, then as plain text
Change-Id: I8e1c93fd36fb903c0625b29f9f73825438c9e113
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index f7c4d5c8d743..8b81c73fbec2 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 @@ -288,6 +289,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)); |