2001-11-08 19:14:51 +00:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2004-12-24 19:11:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "display-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2003-09-15 17:26:28 +00:00
|
|
|
#include "core/gimp-edit.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
#include "core/gimpbuffer.h"
|
2004-06-01 23:14:28 +00:00
|
|
|
#include "core/gimpcontainer.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpdrawable-bucket-fill.h"
|
|
|
|
#include "core/gimpimage.h"
|
2004-06-01 23:14:28 +00:00
|
|
|
#include "core/gimpimage-merge.h"
|
2003-02-13 11:23:50 +00:00
|
|
|
#include "core/gimpimage-undo.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#include "core/gimppattern.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-06-01 23:14:28 +00:00
|
|
|
#include "file/file-open.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2004-02-11 21:42:22 +00:00
|
|
|
#include "text/gimptext.h"
|
|
|
|
#include "text/gimptextlayer.h"
|
|
|
|
|
2003-05-18 14:47:07 +00:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-12-21 22:09:03 +00:00
|
|
|
#include "vectors/gimpvectors-import.h"
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
#include "gimpdisplay.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
|
|
|
#include "gimpdisplayshell-dnd.h"
|
2004-01-15 14:36:43 +00:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-06-29 13:34:16 +00:00
|
|
|
|
2004-03-10 15:10:34 +00:00
|
|
|
/* #define DEBUG_DND */
|
|
|
|
|
|
|
|
#ifdef DEBUG_DND
|
|
|
|
#define D(stmnt) stmnt
|
|
|
|
#else
|
|
|
|
#define D(stmnt)
|
|
|
|
#endif
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_shell_drop_drawable (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-01-15 14:36:43 +00:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
|
|
|
GType new_type;
|
|
|
|
GimpItem *new_item;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop drawable on canvas\n"));
|
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
if (gimage->gimp->busy)
|
2001-11-08 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
if (GIMP_IS_LAYER (viewable))
|
|
|
|
new_type = G_TYPE_FROM_INSTANCE (viewable);
|
|
|
|
else
|
|
|
|
new_type = GIMP_TYPE_LAYER;
|
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
new_item = gimp_item_convert (GIMP_ITEM (viewable), gimage, new_type, TRUE);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
if (new_item)
|
|
|
|
{
|
|
|
|
GimpLayer *new_layer;
|
2004-01-15 14:36:43 +00:00
|
|
|
gint x, y, width, height;
|
2003-08-27 17:21:49 +00:00
|
|
|
gint off_x, off_y;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
new_layer = GIMP_LAYER (new_item);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
2003-08-27 17:21:49 +00:00
|
|
|
_("Drop New Layer"));
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
|
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
gimp_item_offsets (new_item, &off_x, &off_y);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
|
|
|
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_image_add_layer (gimage, new_layer, -1);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2003-08-27 17:21:49 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_image_flush (gimage);
|
2003-08-27 17:21:49 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_context_set_display (gimp_get_user_context (gimage->gimp),
|
|
|
|
shell->gdisp);
|
2003-08-27 17:21:49 +00:00
|
|
|
}
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2003-05-18 14:47:07 +00:00
|
|
|
void
|
|
|
|
gimp_display_shell_drop_vectors (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-01-27 11:30:54 +00:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
|
|
|
GimpItem *new_item;
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop vectors on canvas\n"));
|
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
if (gimage->gimp->busy)
|
2003-05-18 14:47:07 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
new_item = gimp_item_convert (GIMP_ITEM (viewable), gimage,
|
2003-08-27 17:21:49 +00:00
|
|
|
G_TYPE_FROM_INSTANCE (viewable), TRUE);
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2003-08-27 17:21:49 +00:00
|
|
|
if (new_item)
|
|
|
|
{
|
2004-01-27 11:30:54 +00:00
|
|
|
GimpVectors *new_vectors = GIMP_VECTORS (new_item);
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
2003-08-27 17:21:49 +00:00
|
|
|
_("Drop New Path"));
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_image_add_vectors (gimage, new_vectors, -1);
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_image_flush (gimage);
|
2003-05-18 14:47:07 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_context_set_display (gimp_get_user_context (gimage->gimp),
|
|
|
|
shell->gdisp);
|
2003-08-27 17:21:49 +00:00
|
|
|
}
|
2003-05-18 14:47:07 +00:00
|
|
|
}
|
|
|
|
|
2003-12-21 22:09:03 +00:00
|
|
|
void
|
|
|
|
gimp_display_shell_drop_svg (GtkWidget *widget,
|
2004-07-02 14:08:15 +00:00
|
|
|
const guchar *svg_data,
|
2004-06-30 11:57:17 +00:00
|
|
|
gsize svg_data_len,
|
2003-12-21 22:09:03 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2004-01-27 11:30:54 +00:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
|
|
|
GError *error = NULL;
|
2003-12-21 22:09:03 +00:00
|
|
|
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop SVG on canvas\n"));
|
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
if (gimage->gimp->busy)
|
2003-12-21 22:09:03 +00:00
|
|
|
return;
|
|
|
|
|
2004-07-02 14:08:15 +00:00
|
|
|
if (! gimp_vectors_import_buffer (gimage,
|
|
|
|
(const gchar *) svg_data, svg_data_len,
|
2004-06-29 13:34:16 +00:00
|
|
|
TRUE, TRUE, -1, &error))
|
2003-12-21 22:09:03 +00:00
|
|
|
{
|
|
|
|
g_message (error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_image_flush (gimage);
|
2003-12-21 22:09:03 +00:00
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_context_set_display (gimp_get_user_context (gimage->gimp),
|
|
|
|
shell->gdisp);
|
2003-12-21 22:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
static void
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_display_shell_bucket_fill (GimpDisplayShell *shell,
|
2002-03-18 11:07:34 +00:00
|
|
|
GimpBucketFillMode fill_mode,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpPattern *pattern)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2004-01-27 11:30:54 +00:00
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
2001-11-08 19:14:51 +00:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
if (gimage->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawable = gimp_image_active_drawable (gimage);
|
|
|
|
|
|
|
|
if (! drawable)
|
|
|
|
return;
|
|
|
|
|
2004-02-11 21:42:22 +00:00
|
|
|
/* FIXME: there should be a virtual method for this that the
|
2004-03-13 15:07:33 +00:00
|
|
|
* GimpTextLayer can override.
|
|
|
|
*/
|
|
|
|
if (color && gimp_drawable_is_text_layer (drawable))
|
2004-02-11 21:42:22 +00:00
|
|
|
{
|
2004-03-19 22:12:18 +00:00
|
|
|
gimp_text_layer_set (GIMP_TEXT_LAYER (drawable), NULL,
|
|
|
|
"color", color,
|
|
|
|
NULL);
|
2004-02-11 21:42:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_drawable_bucket_fill_full (drawable,
|
|
|
|
fill_mode,
|
|
|
|
GIMP_NORMAL_MODE, GIMP_OPACITY_OPAQUE,
|
|
|
|
FALSE, /* no seed fill */
|
|
|
|
FALSE, 0.0, FALSE, /* fill params */
|
|
|
|
0.0, 0.0, /* ignored */
|
|
|
|
color, pattern);
|
|
|
|
}
|
2004-01-27 11:30:54 +00:00
|
|
|
|
2004-03-18 15:27:23 +00:00
|
|
|
gimp_image_flush (gimage);
|
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_context_set_display (gimp_get_user_context (gimage->gimp),
|
|
|
|
shell->gdisp);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_shell_drop_pattern (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop pattern on canvas\n"));
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
if (GIMP_IS_PATTERN (viewable))
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_display_shell_bucket_fill (GIMP_DISPLAY_SHELL (data),
|
|
|
|
GIMP_PATTERN_BUCKET_FILL,
|
2004-01-15 14:36:43 +00:00
|
|
|
NULL, GIMP_PATTERN (viewable));
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_shell_drop_color (GtkWidget *widget,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop color on canvas\n"));
|
|
|
|
|
2004-01-27 11:30:54 +00:00
|
|
|
gimp_display_shell_bucket_fill (GIMP_DISPLAY_SHELL (data),
|
|
|
|
GIMP_FG_BUCKET_FILL,
|
2004-01-15 14:36:43 +00:00
|
|
|
color, NULL);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_shell_drop_buffer (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-01-15 14:36:43 +00:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
|
|
|
GimpBuffer *buffer;
|
|
|
|
gint x, y, width, height;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-06-29 13:34:16 +00:00
|
|
|
D (g_print ("drop buffer on canvas\n"));
|
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
if (gimage->gimp->busy)
|
2001-11-08 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
buffer = GIMP_BUFFER (viewable);
|
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
/* FIXME: popup a menu for selecting "Paste Into" */
|
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_edit_paste (gimage, gimp_image_active_drawable (gimage),
|
|
|
|
buffer, FALSE,
|
|
|
|
x, y, width, height);
|
|
|
|
|
|
|
|
gimp_image_flush (gimage);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-01-15 14:36:43 +00:00
|
|
|
gimp_context_set_display (gimp_get_user_context (gimage->gimp),
|
|
|
|
shell->gdisp);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
2004-06-01 23:14:28 +00:00
|
|
|
|
|
|
|
void
|
2004-06-30 14:47:23 +00:00
|
|
|
gimp_display_shell_drop_uri_list (GtkWidget *widget,
|
|
|
|
GList *uri_list,
|
|
|
|
gpointer data)
|
2004-06-01 23:14:28 +00:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
2004-07-04 21:27:09 +00:00
|
|
|
GimpImage *gimage = shell->gdisp->gimage;
|
2004-06-01 23:14:28 +00:00
|
|
|
GimpContext *context;
|
|
|
|
GList *list;
|
|
|
|
|
2004-06-30 14:47:23 +00:00
|
|
|
D (g_print ("drop uri list on canvas\n"));
|
2004-06-29 13:34:16 +00:00
|
|
|
|
2004-06-01 23:14:28 +00:00
|
|
|
context = gimp_get_user_context (gimage->gimp);
|
|
|
|
|
2004-06-30 14:47:23 +00:00
|
|
|
for (list = uri_list; list; list = g_list_next (list))
|
2004-06-01 23:14:28 +00:00
|
|
|
{
|
2004-06-02 17:35:55 +00:00
|
|
|
const gchar *uri = list->data;
|
2004-06-28 21:42:19 +00:00
|
|
|
GimpLayer *new_layer;
|
2004-06-01 23:14:28 +00:00
|
|
|
GimpPDBStatusType status;
|
2004-06-02 17:35:55 +00:00
|
|
|
GError *error = NULL;
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-08-10 18:47:21 +00:00
|
|
|
new_layer = file_open_layer (gimage->gimp, context,
|
|
|
|
GIMP_PROGRESS (shell->statusbar),
|
|
|
|
gimage, uri,
|
2004-06-28 21:42:19 +00:00
|
|
|
&status, &error);
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
if (new_layer)
|
2004-06-01 23:14:28 +00:00
|
|
|
{
|
2004-06-28 21:42:19 +00:00
|
|
|
GimpItem *new_item = GIMP_ITEM (new_layer);
|
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
|
|
|
gint off_x, off_y;
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
gimp_display_shell_untransform_viewport (shell, &x, &y,
|
|
|
|
&width, &height);
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
gimp_item_offsets (new_item, &off_x, &off_y);
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
|
|
|
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
2004-06-01 23:14:28 +00:00
|
|
|
|
2004-06-28 21:42:19 +00:00
|
|
|
gimp_image_add_layer (gimage, new_layer, -1);
|
2004-06-01 23:14:28 +00:00
|
|
|
}
|
2004-06-02 17:35:55 +00:00
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
|
|
|
gchar *filename = file_utils_uri_to_utf8_filename (uri);
|
|
|
|
|
|
|
|
g_message (_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2004-06-01 23:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_flush (gimage);
|
|
|
|
|
|
|
|
gimp_context_set_display (context, shell->gdisp);
|
|
|
|
}
|