2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-06-06 15:14:47 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-06-06 15:14:47 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-06 15:14:47 +00: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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-06-06 15:14:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2004-12-24 19:11:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-06-06 15:14:47 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-06-06 15:14:47 +00: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 14:47:45 +01:00
|
|
|
#include "core/gimpimage-new.h"
|
2010-02-08 11:11:33 +01:00
|
|
|
#include "core/gimpimage-undo.h"
|
2003-06-06 15:14:47 +00:00
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#include "core/gimplayermask.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
2004-06-02 17:35:55 +00:00
|
|
|
#include "file/file-open.h"
|
|
|
|
|
2003-06-06 15:14:47 +00:00
|
|
|
#include "gimpdnd.h"
|
|
|
|
#include "gimptoolbox.h"
|
|
|
|
#include "gimptoolbox-dnd.h"
|
2014-05-02 20:20:46 +02:00
|
|
|
#include "gimpwidgets-utils.h"
|
2003-06-06 15:14:47 +00:00
|
|
|
|
2004-06-02 17:35:55 +00:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2003-06-06 15:14:47 +00:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2005-01-15 17:17:33 +00: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-24 22:22:24 +00:00
|
|
|
static void gimp_toolbox_drop_pixbuf (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gpointer data);
|
2003-06-06 15:14:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2010-11-20 15:18:09 +01:00
|
|
|
gimp_toolbox_dnd_init (GimpToolbox *toolbox,
|
|
|
|
GtkWidget *vbox)
|
2003-06-06 15:14:47 +00:00
|
|
|
{
|
2009-12-05 21:20:18 +01:00
|
|
|
GimpContext *context = NULL;
|
2003-06-06 15:14:47 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_TOOLBOX (toolbox));
|
2010-11-20 15:18:09 +01:00
|
|
|
g_return_if_fail (GTK_IS_BOX (vbox));
|
2003-06-06 15:14:47 +00:00
|
|
|
|
2009-12-05 21:20:18 +01:00
|
|
|
context = gimp_toolbox_get_context (toolbox);
|
2003-06-06 15:14:47 +00:00
|
|
|
|
2019-09-21 17:10:46 +00:00
|
|
|
/* Before calling any dnd helper functions, setup the drag
|
2010-01-22 20:48:34 +01:00
|
|
|
* 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 15:18:09 +01:00
|
|
|
gtk_drag_dest_set (vbox,
|
2010-01-22 20:48:34 +01:00
|
|
|
0, NULL, 0,
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
|
2013-01-09 00:28:30 +01: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 15:18:09 +01:00
|
|
|
gimp_dnd_component_dest_add (vbox,
|
2005-01-15 17:17:33 +00:00
|
|
|
gimp_toolbox_drop_component,
|
2009-12-05 21:20:18 +01:00
|
|
|
context);
|
2013-01-09 00:28:30 +01:00
|
|
|
gimp_dnd_uri_list_dest_add (vbox,
|
|
|
|
gimp_toolbox_drop_uri_list,
|
|
|
|
context);
|
2010-11-20 15:18:09 +01:00
|
|
|
gimp_dnd_pixbuf_dest_add (vbox,
|
2005-05-24 22:22:24 +00:00
|
|
|
gimp_toolbox_drop_pixbuf,
|
2009-12-05 21:20:18 +01:00
|
|
|
context);
|
2003-06-06 15:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2004-06-02 17:35:55 +00:00
|
|
|
static void
|
2004-06-30 14:47:23 +00:00
|
|
|
gimp_toolbox_drop_uri_list (GtkWidget *widget,
|
2004-12-31 14:36:30 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2004-06-30 14:47:23 +00:00
|
|
|
GList *uri_list,
|
|
|
|
gpointer data)
|
2004-06-02 17:35:55 +00:00
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GList *list;
|
|
|
|
|
2005-05-24 22:22:24 +00:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2004-06-30 14:47:23 +00:00
|
|
|
for (list = uri_list; list; list = g_list_next (list))
|
2004-06-02 17:35:55 +00:00
|
|
|
{
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file = g_file_new_for_uri (list->data);
|
2004-06-02 17:35:55 +00:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2022-10-11 23:19:18 +02:00
|
|
|
file_open_with_display (context->gimp, context, NULL,
|
|
|
|
file, FALSE,
|
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)),
|
|
|
|
&status, &error);
|
2004-06-02 17:35:55 +00:00
|
|
|
|
2022-10-11 23:19:18 +02:00
|
|
|
if (status != GIMP_PDB_CANCEL && status != GIMP_PDB_SUCCESS)
|
2004-06-02 17:35:55 +00:00
|
|
|
{
|
2022-10-11 23:19:18 +02:00
|
|
|
/* file_open_image() took care of always having a filled error when
|
|
|
|
* the status is neither CANCEL nor SUCCESS (and to transform a
|
|
|
|
* wrongful success without a returned image into an EXECUTION_ERROR).
|
|
|
|
*
|
|
|
|
* In some case, we may also have a SUCCESS without an image, when the
|
|
|
|
* file procedure is a `generic_file_proc` (e.g. for a .gex extension
|
|
|
|
* file). So we should not rely on having a returned image or not.
|
|
|
|
* Once again, sanitizing the returned status is handled by
|
|
|
|
* file_open_image().
|
|
|
|
*/
|
2007-05-21 16:32:52 +00:00
|
|
|
gimp_message (context->gimp, G_OBJECT (widget), GIMP_MESSAGE_ERROR,
|
2006-10-09 18:49:15 +00:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
2014-07-07 00:46:25 +02:00
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2004-06-02 17:35:55 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2014-07-07 00:46:25 +02:00
|
|
|
|
|
|
|
g_object_unref (file);
|
2004-06-02 17:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 15:14:47 +00:00
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_drawable (GtkWidget *widget,
|
2004-12-31 14:36:30 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 15:14:47 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2010-02-08 14:47:45 +01:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GimpImage *new_image;
|
2003-06-06 15:14:47 +00:00
|
|
|
|
2005-05-24 22:22:24 +00:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 14:47:45 +01:00
|
|
|
new_image = gimp_image_new_from_drawable (context->gimp,
|
|
|
|
GIMP_DRAWABLE (viewable));
|
2014-05-02 20:20:46 +02:00
|
|
|
gimp_create_display (context->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)));
|
2003-12-09 15:09:57 +00:00
|
|
|
g_object_unref (new_image);
|
2003-06-06 15:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_tool (GtkWidget *widget,
|
2004-12-31 14:36:30 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 15:14:47 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
|
2005-05-24 22:22:24 +00:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2003-06-06 15:14:47 +00:00
|
|
|
gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_buffer (GtkWidget *widget,
|
2004-12-31 14:36:30 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2003-06-06 15:14:47 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
2005-09-02 22:50:06 +00:00
|
|
|
GimpImage *image;
|
2003-06-06 15:14:47 +00:00
|
|
|
|
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2017-05-01 18:36:33 +02:00
|
|
|
image = gimp_image_new_from_buffer (context->gimp,
|
2010-02-08 15:19:03 +01:00
|
|
|
GIMP_BUFFER (viewable));
|
2014-05-02 20:20:46 +02:00
|
|
|
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)));
|
2010-02-08 15:19:03 +01:00
|
|
|
g_object_unref (image);
|
2003-06-06 15:14:47 +00:00
|
|
|
}
|
2005-01-15 17:17:33 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_component (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannelType component,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-24 22:22:24 +00:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
2005-01-15 17:17:33 +00:00
|
|
|
GimpImage *new_image;
|
|
|
|
|
2005-05-24 22:22:24 +00:00
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 14:47:45 +01:00
|
|
|
new_image = gimp_image_new_from_component (context->gimp,
|
|
|
|
image, component);
|
2014-05-02 20:20:46 +02:00
|
|
|
gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)));
|
2005-01-15 17:17:33 +00:00
|
|
|
g_object_unref (new_image);
|
|
|
|
}
|
2005-05-24 22:22:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_toolbox_drop_pixbuf (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-25 09:54:05 +00:00
|
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
GimpImage *new_image;
|
2005-05-24 22:22:24 +00:00
|
|
|
|
|
|
|
if (context->gimp->busy)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 14:47:45 +01:00
|
|
|
new_image = gimp_image_new_from_pixbuf (context->gimp, pixbuf,
|
|
|
|
_("Dropped Buffer"));
|
2014-05-02 20:20:46 +02:00
|
|
|
gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)));
|
2005-05-24 22:22:24 +00:00
|
|
|
g_object_unref (new_image);
|
|
|
|
}
|