gimp/app/widgets/gimptoolbox-dnd.c

215 lines
6.6 KiB
C
Raw Normal View History

/* 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"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimp-edit.h"
#include "core/gimpbuffer.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
#include "core/gimptoolinfo.h"
#include "file/file-open.h"
#include "file/file-utils.h"
#include "gimpdnd.h"
#include "gimptoolbox.h"
#include "gimptoolbox-dnd.h"
#include "gimp-intl.h"
/* local function prototypes */
static void gimp_toolbox_drop_uri_list (GtkWidget *widget,
GList *uri_list,
gpointer data);
static void gimp_toolbox_drop_drawable (GtkWidget *widget,
GimpViewable *viewable,
gpointer data);
static void gimp_toolbox_drop_tool (GtkWidget *widget,
GimpViewable *viewable,
gpointer data);
static void gimp_toolbox_drop_buffer (GtkWidget *widget,
GimpViewable *viewable,
gpointer data);
/* public functions */
void
gimp_toolbox_dnd_init (GimpToolbox *toolbox)
{
GimpDock *dock;
g_return_if_fail (GIMP_IS_TOOLBOX (toolbox));
dock = GIMP_DOCK (toolbox);
gimp_dnd_uri_list_dest_add (GTK_WIDGET (toolbox),
gimp_toolbox_drop_uri_list,
dock->context);
gimp_dnd_uri_list_dest_add (toolbox->tool_wbox,
gimp_toolbox_drop_uri_list,
dock->context);
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_LAYER,
gimp_toolbox_drop_drawable,
dock->context);
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_LAYER_MASK,
gimp_toolbox_drop_drawable,
dock->context);
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_CHANNEL,
gimp_toolbox_drop_drawable,
dock->context);
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_TOOL_INFO,
gimp_toolbox_drop_tool,
dock->context);
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_BUFFER,
gimp_toolbox_drop_buffer,
dock->context);
}
/* private functions */
static void
gimp_toolbox_drop_uri_list (GtkWidget *widget,
GList *uri_list,
gpointer data)
{
GimpContext *context = GIMP_CONTEXT (data);
GList *list;
for (list = uri_list; list; list = g_list_next (list))
{
const gchar *uri = list->data;
GimpImage *gimage;
GimpPDBStatusType status;
GError *error = NULL;
Redid the whole internal progress stuff: don't pass around 2004-08-10 Michael Natterer <mitch@gimp.org> Redid the whole internal progress stuff: don't pass around progress_callback and progress_data; instead, provide a pointer to a GimpProgressInterface which can be implemented by a variety of backends. Addresses (but not yet fixes) bugs #6010, #97266 and #135185. * app/display/Makefile.am * app/display/gimpprogress.[ch]: removed the old progress hack. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpprogress.[ch]: implement GimpProgressInterface. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpprogressdialog.[ch]: the standalone progress dialog as widget implementing GimpProgressInterface. * app/display/gimpdisplay.c * app/display/gimpstatusbar.[ch] * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpthumbbox.[ch]: added GimpProgressInterface implementation to these classes. * app/core/gimp-gui.[ch] * app/gui/gui-vtable.c: replaced the old progress vtable entries by two new to create and destroy a GimpProgressDialog in case no other progress is available. * app/pdb/procedural_db.[ch] * app/plug-in/plug-in-run.[ch] * tools/pdbgen/app.pl: pass a GimpProgress to all PDB wrappers and all plug-ins. * app/plug-in/plug-in.[ch] * app/plug-in/plug-ins.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in-progress.c: handle the case there the plug-in was crated with a progress as well as the case where it wasn't. * app/app_procs.c * app/batch.c * app/xcf/xcf.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/widgets/gimphelp.c * app/widgets/gimpbrushselect.c * app/widgets/gimpfontselect.c * app/widgets/gimpgradientselect.c * app/widgets/gimppaletteselect.c * app/widgets/gimppatternselect.c: changed accordingly. * app/core/gimpimagefile.[ch] * app/display/gimpdisplayshell-dnd.c * app/gui/file-open-dialog.c * app/gui/file-open-location-dialog.c * app/gui/file-save-dialog.c * app/widgets/gimplayertreeview.c * app/widgets/gimptoolbox-dnd.c: pass a GimpProgress to all file related functions. Embed the progress in the file dialog where possible. * app/core/gimpdrawable-blend.[ch] * app/core/gimpdrawable-transform.[ch] * app/core/gimpimage-convert.[ch] * app/core/gimpimage-flip.[ch] * app/core/gimpimage-resize.[ch] * app/core/gimpimage-rotate.[ch] * app/core/gimpimage-scale.[ch] * app/core/gimpitem-linked.[ch] * app/core/gimpitem.[ch] * app/core/gimpchannel.c * app/core/gimpdrawable.c * app/core/gimplayer.c * app/core/gimpselection.c * app/vectors/gimpvectors.c: replaced callback/data by GimpProgress. * app/tools/gimpblendtool.c * app/tools/gimptransformtool.c * app/gui/convert-dialog.c * app/actions/documents-commands.c * app/actions/file-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/plug-in-commands.c * app/actions/vectors-commands.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb: changed callers accordingly. * app/pdb/*_cmds.c: regenerated.
2004-08-11 02:47:21 +08:00
gimage = file_open_with_display (context->gimp, context, NULL,
uri, &status, &error);
if (! gimage && 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);
}
}
}
static void
gimp_toolbox_drop_drawable (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
GimpDrawable *drawable;
GimpItem *item;
GimpImage *gimage;
GimpImage *new_image;
GimpLayer *new_layer;
GType new_type;
gint width, height;
gint off_x, off_y;
gint bytes;
GimpImageBaseType type;
drawable = GIMP_DRAWABLE (viewable);
item = GIMP_ITEM (viewable);
gimage = gimp_item_get_image (item);
width = gimp_item_width (item);
height = gimp_item_height (item);
bytes = gimp_drawable_bytes (drawable);
type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable));
new_image = gimp_create_image (gimage->gimp, width, height, type, FALSE);
gimp_image_undo_disable (new_image);
if (type == GIMP_INDEXED)
gimp_image_set_colormap (new_image,
gimp_image_get_colormap (gimage),
gimp_image_get_colormap_size (gimage),
FALSE);
gimp_image_set_resolution (new_image,
gimage->xresolution, gimage->yresolution);
gimp_image_set_unit (new_image, gimage->unit);
if (GIMP_IS_LAYER (drawable))
new_type = G_TYPE_FROM_INSTANCE (drawable);
else
new_type = GIMP_TYPE_LAYER;
new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (drawable), new_image,
new_type, FALSE));
gimp_object_set_name (GIMP_OBJECT (new_layer),
gimp_object_get_name (GIMP_OBJECT (drawable)));
gimp_item_offsets (GIMP_ITEM (new_layer), &off_x, &off_y);
gimp_item_translate (GIMP_ITEM (new_layer), -off_x, -off_y, FALSE);
gimp_image_add_layer (new_image, new_layer, 0);
gimp_image_undo_enable (new_image);
tools/pdbgen/pdb/image.pdb app/pdb/image_cmds.c reverted changes I did to 2004-06-01 Sven Neumann <sven@gimp.org> * tools/pdbgen/pdb/image.pdb * app/pdb/image_cmds.c * app/core/gimpimage.[ch]: reverted changes I did to the image unit earlier. As in 2.0, it will continue to not accept pixels. This makes the PDB API and the XCF format compatible again and fixes bug #142961 (and to some extent bug #137704). * app/core/Makefile.am * app/core/gimpimage-unit.[ch]: removed these files. The convenience accessors defined here aren't commonly used any longer. * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell.[ch]: added a unit parameter to gimp_display_new(). Made "unit" and "scale" properties of GimpDisplayShell. * app/actions/image-commands.c * app/actions/images-commands.c * app/actions/layers-commands.c * app/actions/select-commands.c * app/actions/view-commands.c * app/core/gimp-edit.c * app/core/gimp.[ch] * app/core/gimptemplate.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-title.c * app/display/gimpstatusbar.c * app/file/file-open.c * app/gui/gui-vtable.c * app/gui/info-window.c * app/gui/offset-dialog.c * app/gui/resize-dialog.[ch] * app/pdb/display_cmds.c * app/tools/gimpcroptool.c * app/tools/gimpmeasuretool.c * app/tools/gimppainttool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/vectors/gimpvectors-export.c * app/widgets/gimptoolbox-dnd.c * tools/pdbgen/pdb/display.pdb: changed accordingly. Use the display unit where the image unit was used before.
2004-06-02 06:04:20 +08:00
gimp_create_display (gimage->gimp, new_image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (new_image);
}
static void
gimp_toolbox_drop_tool (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
GimpContext *context = GIMP_CONTEXT (data);
gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable));
}
static void
gimp_toolbox_drop_buffer (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
GimpContext *context = GIMP_CONTEXT (data);
if (context->gimp->busy)
return;
gimp_edit_paste_as_new (context->gimp, NULL, GIMP_BUFFER (viewable));
}