From ccb3d6e7ea5fc01ed5233b20ef950aa00e65e80a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 21 Jan 2016 15:12:23 +0100 Subject: [PATCH] gtktiledviewer: support pasting PNG images Change-Id: Ifaf96dee8b6554282f6a19ac6d6e0d14318aa1f4 --- .../qa/gtktiledviewer/gtktiledviewer.cxx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 1bc65292671d..c6dbc7d42e60 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -601,25 +601,43 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/) GdkAtom* pTargets; gint nTargets; - boost::optional oTarget; + std::map aTargets; 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]; + aTargets[pName] = pTargets[i]; g_free(pName); } g_free(pTargets); } + boost::optional oTarget; + std::string aTargetName; + + std::vector aPreferredNames = + { + std::string("image/png"), + std::string("text/html") + }; + for (const std::string& rName : aPreferredNames) + { + std::map::iterator it = aTargets.find(rName); + if (it != aTargets.end()) + { + aTargetName = it->first; + oTarget = it->second; + break; + } + } + 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 = lok_doc_view_paste(pLOKDocView, "text/html", reinterpret_cast(pData), nLength); + bool bSuccess = lok_doc_view_paste(pLOKDocView, aTargetName.c_str(), reinterpret_cast(pData), nLength); gtk_selection_data_free(pSelectionData); if (bSuccess) return;