summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-06-22 09:06:31 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-06-22 09:10:54 +0200
commitf403cecdaedf263f11081c91bed62640362a3a3e (patch)
tree3c143b9b0073d3d500822650d1b813fb238f577e /libreofficekit
parent7b08304b55cf2284a3c583426c60baef618ba206 (diff)
gtktiledviewer: do HTML copying if possible
Change-Id: I24e7b18442cb08814a73dd33b368b368039a11e4
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx37
1 files changed, 35 insertions, 2 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 7d4960d520d9..575588ea8bcb 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -125,16 +125,49 @@ static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
}
}
+/// Our GtkClipboardGetFunc implementation for HTML.
+static void htmlGetFunc(GtkClipboard* /*pClipboard*/, GtkSelectionData* pSelectionData, guint /*info*/, gpointer pUserData)
+{
+ GdkAtom aAtom(gdk_atom_intern("text/html", false));
+ const gchar* pSelection = static_cast<const gchar*>(pUserData);
+ gtk_selection_data_set(pSelectionData, aAtom, 8, reinterpret_cast<const guchar *>(pSelection), strlen(pSelection));
+}
+
+/// Our GtkClipboardClearFunc implementation for HTML.
+static void htmlClearFunc(GtkClipboard* /*pClipboard*/, gpointer pData)
+{
+ g_free(pData);
+}
+
+/// Same as gtk_clipboard_set_text(), but sets HTML.
+static void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection)
+{
+ GtkTargetList* pList = gtk_target_list_new(0, 0);
+ GdkAtom aAtom(gdk_atom_intern("text/html", false));
+ gtk_target_list_add(pList, aAtom, 0, 0);
+ gint nTargets = 0;
+ GtkTargetEntry* pTargets = gtk_target_table_new_from_list(pList, &nTargets);
+
+ gtk_clipboard_set_with_data(pClipboard, pTargets, nTargets, htmlGetFunc, htmlClearFunc, g_strdup(pSelection));
+
+ gtk_target_table_free(pTargets, nTargets);
+ gtk_target_list_unref(pList);
+}
+
/// Handler for the copy button: write clipboard.
static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/)
{
LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
char* pUsedFormat = 0;
- char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", &pUsedFormat);
+ char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/html", &pUsedFormat);
GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pDocView), GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_text(pClipboard, pSelection, -1);
+ std::string aUsedFormat(pUsedFormat);
+ if (aUsedFormat == "text/plain;charset=utf-8")
+ gtk_clipboard_set_text(pClipboard, pSelection, -1);
+ else
+ clipboardSetHtml(pClipboard, pSelection);
free(pSelection);
free(pUsedFormat);