2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-06-06 23:14:47 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-06-06 23:14:47 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-06 23:14:47 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-06 23:14:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2004-12-25 03:11:30 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-06-06 23:14:47 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-06-06 23:14:47 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpbuffer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
2010-02-08 21:47:45 +08:00
|
|
|
#include "core/gimpimage-new.h"
|
2010-02-08 18:11:33 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2003-06-06 23:14:47 +08:00
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#include "core/gimplayermask.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
2004-06-03 01:35:55 +08:00
|
|
|
#include "file/file-open.h"
|
|
|
|
|
2003-06-06 23:14:47 +08:00
|
|
|
#include "gimpdnd.h"
|
|
|
|
#include "gimptoolbox.h"
|
|
|
|
#include "gimptoolbox-dnd.h"
|
2014-05-03 02:20:46 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2003-06-06 23:14:47 +08:00
|
|
|
|
2004-06-03 01:35:55 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2003-06-06 23:14:47 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2005-01-16 01:17:33 +08:00
|
|
|
static void gimp_toolbox_drop_uri_list (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GList *uri_list,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_toolbox_drop_drawable (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_toolbox_drop_tool (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_toolbox_drop_buffer (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_toolbox_drop_component (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannelType component,
|
|
|
|
gpointer data);
|
2005-05-25 06:22:24 +08:00
|
|
|
static void gimp_toolbox_drop_pixbuf (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gpointer data);
|
2003-06-06 23:14:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2010-11-20 22:18:09 +08:00
|
|
|
gimp_toolbox_dnd_init (GimpToolbox *toolbox,
|
|
|
|
GtkWidget *vbox)
|
2003-06-06 23:14:47 +08:00
|
|
|
{
|
2009-12-06 04:20:18 +08:00
|
|
|
GimpContext *context = NULL;
|
2003-06-06 23:14:47 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_TOOLBOX (toolbox));
|
2010-11-20 22:18:09 +08:00
|
|
|
g_return_if_fail (GTK_IS_BOX (vbox));
|
2003-06-06 23:14:47 +08:00
|
|
|
|
2009-12-06 04:20:18 +08:00
|
|
|
context = gimp_toolbox_get_context (toolbox);
|
2003-06-06 23:14:47 +08:00
|
|
|
|
2010-01-23 03:48:34 +08:00
|
|
|
/* Before caling any dnd helper functions, setup the drag
|
|
|
|
* destination manually since we want to handle all drag events
|
|
|
|
* manually, otherwise we would not be able to give the drag handler
|
|
|
|
* a chance to handle drag events
|
|
|
|
*/
|
2010-11-20 22:18:09 +08:00
|
|
|
gtk_drag_dest_set (vbox,
|
2010-01-23 03:48:34 +08:00
|
|
|
0, NULL, 0,
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
|
2013-01-09 07:28:30 +08:00
|
|
|
gimp_dnd_viewable_dest_add (vbox,
|
|
|
|
GIMP_TYPE_LAYER,
|
|
|
|
gimp_toolbox_drop_drawable,
|
|
|
|
context);
|
|
|
|
gimp_dnd_viewable_dest_add (vbox,
|
|
|
|
GIMP_TYPE_LAYER_MASK,
|
|
|
|
gimp_toolbox_drop_drawable,
|
|
|
|
context);
|
|
|
|
gimp_dnd_viewable_dest_add (vbox,
|
|
|
|
GIMP_TYPE_CHANNEL,
|
|
|
|
gimp_toolbox_drop_drawable,
|
|
|
|
context);
|
|
|
|
gimp_dnd_viewable_dest_add (vbox,
|
|
|
|
GIMP_TYPE_TOOL_INFO,
|
|
|
|
gimp_toolbox_drop_tool,
|
|
|
|
context);
|
|
|
|
gimp_dnd_viewable_dest_add (vbox,
|
|
|
|
GIMP_TYPE_BUFFER,
|
|
|
|
gimp_toolbox_drop_buffer,
|
|
|
|
context);
|
2010-11-20 22:18:09 +08:00
|
|
|
gimp_dnd_component_dest_add (vbox,
|
2005-01-16 01:17:33 +08:00
|
|
|
gimp_toolbox_drop_component,
|
2009-12-06 04:20:18 +08:00
|
|
|
context);
|
2013-01-09 07:28:30 +08:00
|
|
|
gimp_dnd_uri_list_dest_add (vbox,
|
|
|
|
gimp_toolbox_drop_uri_list,
|
|
|
|
context);
|
2010-11-20 22:18:09 +08:00
|
|
|
gimp_dnd_pixbuf_dest_add (vbox,
|
2005-05-25 06:22:24 +08:00
|
|
|
gimp_toolbox_drop_pixbuf,
|
2009-12-06 04:20:18 +08:00
|
|
|
context);
|
2003-06-06 23:14:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2004-06-03 01:35:55 +08:00
|
|
|
static void
|
2004-06-30 22:47:23 +08:00
|
|
|
gimp_toolbox_drop_uri_list (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2004-06-30 22:47:23 +08:00
|
|
|
GList *uri_list,
|
|
|
|
gpointer data)
|
2004-06-03 01:35:55 +08:00
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GList *list;
|
|
|
|
|
2005-05-25 06:22:24 +08:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2004-06-30 22:47:23 +08:00
|
|
|
for (list = uri_list; list; list = g_list_next (list))
|
2004-06-03 01:35:55 +08:00
|
|
|
{
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file = g_file_new_for_uri (list->data);
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2004-06-03 01:35:55 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = file_open_with_display (context->gimp, context, NULL,
|
2014-07-07 06:46:25 +08:00
|
|
|
file, FALSE,
|
2014-05-03 02:20:46 +08:00
|
|
|
G_OBJECT (gtk_widget_get_screen (widget)),
|
|
|
|
gimp_widget_get_monitor (widget),
|
|
|
|
&status, &error);
|
2004-06-03 01:35:55 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! image && status != GIMP_PDB_CANCEL)
|
2004-06-03 01:35:55 +08:00
|
|
|
{
|
2007-05-22 00:32:52 +08:00
|
|
|
gimp_message (context->gimp, G_OBJECT (widget), GIMP_MESSAGE_ERROR,
|
2006-10-10 02:49:15 +08:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
2014-07-07 06:46:25 +08:00
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2004-06-03 01:35:55 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2014-07-07 06:46:25 +08:00
|
|
|
|
|
|
|
g_object_unref (file);
|
2004-06-03 01:35:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 23:14:47 +08:00
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_drawable (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 23:14:47 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2010-02-08 21:47:45 +08:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GimpImage *new_image;
|
2003-06-06 23:14:47 +08:00
|
|
|
|
2005-05-25 06:22:24 +08:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
new_image = gimp_image_new_from_drawable (context->gimp,
|
|
|
|
GIMP_DRAWABLE (viewable));
|
2014-05-03 02:20:46 +08:00
|
|
|
gimp_create_display (context->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
|
|
|
G_OBJECT (gtk_widget_get_screen (widget)),
|
|
|
|
gimp_widget_get_monitor (widget));
|
2003-12-09 23:09:57 +08:00
|
|
|
g_object_unref (new_image);
|
2003-06-06 23:14:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_tool (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 23:14:47 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
|
2005-05-25 06:22:24 +08:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2003-06-06 23:14:47 +08:00
|
|
|
gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_buffer (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 23:14:47 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
2005-09-03 06:50:06 +08:00
|
|
|
GimpImage *image;
|
2003-06-06 23:14:47 +08:00
|
|
|
|
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
image = gimp_image_new_from_buffer (context->gimp,
|
2010-02-08 22:19:03 +08:00
|
|
|
GIMP_BUFFER (viewable));
|
2014-05-03 02:20:46 +08:00
|
|
|
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
|
|
|
|
G_OBJECT (gtk_widget_get_screen (widget)),
|
|
|
|
gimp_widget_get_monitor (widget));
|
2010-02-08 22:19:03 +08:00
|
|
|
g_object_unref (image);
|
2003-06-06 23:14:47 +08:00
|
|
|
}
|
2005-01-16 01:17:33 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_component (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannelType component,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-25 06:22:24 +08:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
2005-01-16 01:17:33 +08:00
|
|
|
GimpImage *new_image;
|
|
|
|
|
2005-05-25 06:22:24 +08:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
new_image = gimp_image_new_from_component (context->gimp,
|
|
|
|
image, component);
|
2014-05-03 02:20:46 +08:00
|
|
|
gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
|
|
|
G_OBJECT (gtk_widget_get_screen (widget)),
|
|
|
|
gimp_widget_get_monitor (widget));
|
2005-01-16 01:17:33 +08:00
|
|
|
g_object_unref (new_image);
|
|
|
|
}
|
2005-05-25 06:22:24 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_pixbuf (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-25 17:54:05 +08:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GimpImage *new_image;
|
2005-05-25 06:22:24 +08:00
|
|
|
|
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
new_image = gimp_image_new_from_pixbuf (context->gimp, pixbuf,
|
|
|
|
_("Dropped Buffer"));
|
2014-05-03 02:20:46 +08:00
|
|
|
gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
|
|
|
G_OBJECT (gtk_widget_get_screen (widget)),
|
|
|
|
gimp_widget_get_monitor (widget));
|
2005-05-25 06:22:24 +08:00
|
|
|
g_object_unref (new_image);
|
|
|
|
}
|