gtktiledviewer: support pasting PNG images

Change-Id: Ifaf96dee8b6554282f6a19ac6d6e0d14318aa1f4
This commit is contained in:
Miklos Vajna 2016-01-21 15:12:23 +01:00
parent 2af991dc23
commit ccb3d6e7ea

View File

@ -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;