Blame SOURCES/0054-gtktiledviewer-do-HTML-copying-if-possible.patch

135360
From 25bb8e0fa54097cc0197e5883b0b95b648d75452 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Mon, 22 Jun 2015 09:06:31 +0200
135360
Subject: [PATCH 054/398] gtktiledviewer: do HTML copying if possible
135360
135360
(cherry picked from commit f403cecdaedf263f11081c91bed62640362a3a3e)
135360
135360
Change-Id: I24e7b18442cb08814a73dd33b368b368039a11e4
135360
---
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 38 ++++++++++++++++++++--
135360
 1 file changed, 36 insertions(+), 2 deletions(-)
135360
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index 9496ba5ea180..57556616d803 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -125,15 +125,49 @@ static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
135360
     }
135360
 }
135360
 
135360
+/// Our GtkClipboardGetFunc implementation for HTML.
135360
+static void htmlGetFunc(GtkClipboard* /*pClipboard*/, GtkSelectionData* pSelectionData, guint /*info*/, gpointer pUserData)
135360
+{
135360
+    GdkAtom aAtom(gdk_atom_intern("text/html", false));
135360
+    const gchar* pSelection = static_cast<const gchar*>(pUserData);
135360
+    gtk_selection_data_set(pSelectionData, aAtom, 8, reinterpret_cast<const guchar *>(pSelection), strlen(pSelection));
135360
+}
135360
+
135360
+/// Our GtkClipboardClearFunc implementation for HTML.
135360
+static void htmlClearFunc(GtkClipboard* /*pClipboard*/, gpointer pData)
135360
+{
135360
+    g_free(pData);
135360
+}
135360
+
135360
+/// Same as gtk_clipboard_set_text(), but sets HTML.
135360
+static void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection)
135360
+{
135360
+    GtkTargetList* pList = gtk_target_list_new(0, 0);
135360
+    GdkAtom aAtom(gdk_atom_intern("text/html", false));
135360
+    gtk_target_list_add(pList, aAtom, 0, 0);
135360
+    gint nTargets = 0;
135360
+    GtkTargetEntry* pTargets = gtk_target_table_new_from_list(pList, &nTargets);
135360
+
135360
+    gtk_clipboard_set_with_data(pClipboard, pTargets, nTargets, htmlGetFunc, htmlClearFunc, g_strdup(pSelection));
135360
+
135360
+    gtk_target_table_free(pTargets, nTargets);
135360
+    gtk_target_list_unref(pList);
135360
+}
135360
+
135360
 /// Handler for the copy button: write clipboard.
135360
 static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/)
135360
 {
135360
     LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
135360
     LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
135360
-    char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8");
135360
+    char* pUsedFormat = 0;
135360
+    char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/html", &pUsedFormat);
135360
 
135360
     GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pDocView), GDK_SELECTION_CLIPBOARD);
135360
-    gtk_clipboard_set_text(pClipboard, pSelection, -1);
135360
+    std::string aUsedFormat(pUsedFormat);
135360
+    if (aUsedFormat == "text/plain;charset=utf-8")
135360
+        gtk_clipboard_set_text(pClipboard, pSelection, -1);
135360
+    else
135360
+        clipboardSetHtml(pClipboard, pSelection);
135360
 
135360
     free(pSelection);
135360
 }
135360
-- 
135360
2.12.0
135360