mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-23 04:51:44 +00:00
7609645970
2005-04-09 Michael Natterer <mitch@gimp.org> Implement dragging and dropping in any GdkPixbuf supported format. Fixes bug #172794 and bug #172795. * app/core/gimplayer.[ch] (gimp_layer_new_from_region): new function which contains all stuff that was in gimp_layer_new_from_tiles(). (gimp_layer_new_from_tiles): use above function. (gimp_layer_new_from_pixbuf): new function. * app/widgets/Makefile.am * app/widgets/gimppixbuf.[ch]: new files containing GdkPixbuf utility functions for clipboard and DnD. * app/widgets/gimpselectiondata.[ch]: removed gimp_selection_data_set,get_pixbuf(), GTK+ provides the same API. Also removed GdkAtom parameters all over the place because it's always the same as selection_data->target. * app/widgets/gimpclipboard.c: use the new pixbuf utility functions and gtk_selection_data_set,get_pixbuf(). * app/widgets/widgets-enums.h * app/widgets/gimpdnd.[ch]: removed never-implemented GIMP_DND_TYPE_PNG and added a generic GIMP_DND_TYPE_PIXBUF instead. Added API to drag and drop GdkPixbufs which transparently converts from/to and GdkPixbuf-supported image format. Removed passing around of GdkAtoms, since they were always the same as selection_data->target. * app/widgets/gimpdnd-xds.[ch]: follow GdkAtom parameter removal. * app/widgets/gimpcontainertreeview.[ch]: added virtual function GimpContainerTreeView::drop_pixbuf(). * app/widgets/gimpcontainertreeview-dnd.c: dispatch drop_pixbuf(). * app/widgets/gimplayertreeview.c: implement drop_pixbuf(). * app/widgets/gimpdrawabletreeview.c: allow to drag all drawables as pixbufs. * app/display/gimpdisplayshell-dnd.c: allow dropping of pixbufs.
176 lines
4.7 KiB
C
176 lines
4.7 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
*
|
|
* gimpdnd-xds.c
|
|
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
|
|
*
|
|
* Saving Files via Drag-and-Drop:
|
|
* The Direct Save Protocol for the X Window System
|
|
*
|
|
* http://www.newplanetsoftware.com/xds/
|
|
* http://rox.sourceforge.net/xds.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "widgets-types.h"
|
|
|
|
#include "core/gimp.h"
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "file/file-save.h"
|
|
#include "file/file-utils.h"
|
|
|
|
#include "gimpdnd-xds.h"
|
|
#include "gimpfiledialog.h"
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
#ifdef DEBUG_DND
|
|
#define D(stmnt) stmnt
|
|
#else
|
|
#define D(stmnt)
|
|
#endif
|
|
|
|
|
|
#define MAX_URI_LEN 4096
|
|
|
|
|
|
void
|
|
gimp_dnd_xds_source_set (GdkDragContext *context,
|
|
GimpImage *image)
|
|
{
|
|
GdkAtom property;
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
|
|
|
|
D (g_printerr ("\ngimp_dnd_xds_source_set\n"));
|
|
|
|
property = gdk_atom_intern ("XdndDirectSave0", FALSE);
|
|
|
|
if (image)
|
|
{
|
|
GdkAtom type = gdk_atom_intern ("text/plain", FALSE);
|
|
gchar *filename = gimp_image_get_filename (image);
|
|
gchar *basename;
|
|
|
|
if (filename)
|
|
{
|
|
basename = g_path_get_basename (filename);
|
|
}
|
|
else
|
|
{
|
|
gchar *tmp = g_strconcat (_("Untitled"), ".xcf", NULL);
|
|
basename = g_filename_from_utf8 (tmp, -1, NULL, NULL, NULL);
|
|
g_free (tmp);
|
|
}
|
|
|
|
|
|
gdk_property_change (context->source_window,
|
|
property, type, 8, GDK_PROP_MODE_REPLACE,
|
|
basename, basename ? strlen (basename) : 0);
|
|
|
|
g_free (basename);
|
|
g_free (filename);
|
|
}
|
|
else
|
|
{
|
|
gdk_property_delete (context->source_window, property);
|
|
}
|
|
}
|
|
|
|
void
|
|
gimp_dnd_xds_save_image (GdkDragContext *context,
|
|
GimpImage *image,
|
|
GtkSelectionData *selection)
|
|
{
|
|
PlugInProcDef *proc;
|
|
GdkAtom property = gdk_atom_intern ("XdndDirectSave0", FALSE);
|
|
GdkAtom type = gdk_atom_intern ("text/plain", FALSE);
|
|
gint length;
|
|
guchar *data;
|
|
gchar *uri;
|
|
GError *error = NULL;
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
D (g_printerr ("\ngimp_dnd_xds_save_image\n"));
|
|
|
|
if (! gdk_property_get (context->source_window, property, type,
|
|
0, MAX_URI_LEN, FALSE,
|
|
NULL, NULL, &length, &data))
|
|
return;
|
|
|
|
|
|
uri = g_strndup ((const gchar *) data, length);
|
|
g_free (data);
|
|
|
|
proc = file_utils_find_proc (image->gimp->save_procs, uri);
|
|
|
|
if (proc)
|
|
{
|
|
gchar *filename = file_utils_filename_from_uri (uri);
|
|
|
|
/* FIXME: shouldn't overwrite non-local files w/o confirmation */
|
|
|
|
if (! filename ||
|
|
! g_file_test (filename, G_FILE_TEST_EXISTS) ||
|
|
gimp_file_overwrite_dialog (NULL, uri))
|
|
{
|
|
if (file_save (image, gimp_get_user_context (image->gimp), NULL,
|
|
uri, proc, GIMP_RUN_INTERACTIVE, FALSE,
|
|
&error) == GIMP_PDB_SUCCESS)
|
|
{
|
|
gtk_selection_data_set (selection, selection->target, 8, "S", 1);
|
|
}
|
|
else
|
|
{
|
|
gtk_selection_data_set (selection, selection->target, 8, "E", 1);
|
|
|
|
if (error)
|
|
{
|
|
gchar *filename = file_utils_uri_to_utf8_filename (uri);
|
|
|
|
g_message (_("Saving '%s' failed:\n\n%s"),
|
|
filename, error->message);
|
|
|
|
g_free (filename);
|
|
g_error_free (error);
|
|
}
|
|
}
|
|
}
|
|
|
|
g_free (filename);
|
|
}
|
|
else
|
|
{
|
|
gtk_selection_data_set (selection, selection->target, 8, "E", 1);
|
|
|
|
g_message (_("The given filename does not have any known "
|
|
"file extension."));
|
|
}
|
|
|
|
g_free (uri);
|
|
}
|