summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-01-21 15:12:23 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-01-21 15:38:43 +0100
commitccb3d6e7ea5fc01ed5233b20ef950aa00e65e80a (patch)
treee8b26b3c85353f67fef1512dd49fa0bc41a1b086 /libreofficekit
parent2af991dc232bbf96557dc5efe5bd2ce9b6b99f9b (diff)
gtktiledviewer: support pasting PNG images
Change-Id: Ifaf96dee8b6554282f6a19ac6d6e0d14318aa1f4
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx26
1 files 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<GdkAtom> oTarget;
+ std::map<std::string, GdkAtom> 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<GdkAtom> oTarget;
+ std::string aTargetName;
+
+ std::vector<std::string> aPreferredNames =
+ {
+ std::string("image/png"),
+ std::string("text/html")
+ };
+ for (const std::string& rName : aPreferredNames)
+ {
+ std::map<std::string, GdkAtom>::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<const char*>(pData), nLength);
+ bool bSuccess = lok_doc_view_paste(pLOKDocView, aTargetName.c_str(), reinterpret_cast<const char*>(pData), nLength);
gtk_selection_data_free(pSelectionData);
if (bSuccess)
return;