app/display/gimpdisplayshell.c app/display/gimpdisplayshell-dnd.[ch]

2005-01-15  Michael Natterer  <mitch@gimp.org>

	* app/display/gimpdisplayshell.c
	* app/display/gimpdisplayshell-dnd.[ch]
	* app/widgets/gimptoolbox-dnd.c: enabled dropping of components
	to the display and the toolbox. Addresses bug #158483.
This commit is contained in:
Michael Natterer
2005-01-15 17:17:33 +00:00
committed by Michael Natterer
parent d0a78f3bdb
commit 7f74bdc941
5 changed files with 221 additions and 84 deletions

View File

@ -1,3 +1,10 @@
2005-01-15 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplayshell.c
* app/display/gimpdisplayshell-dnd.[ch]
* app/widgets/gimptoolbox-dnd.c: enabled dropping of components
to the display and the toolbox. Addresses bug #158483.
2005-01-15 Michael Natterer <mitch@gimp.org>
* app/core/gimpchannel.c (gimp_channel_new*): don't require a

View File

@ -22,14 +22,16 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "display-types.h"
#include "core/gimp.h"
#include "core/gimp-edit.h"
#include "core/gimpbuffer.h"
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-bucket-fill.h"
#include "core/gimpimage.h"
#include "core/gimpimage-merge.h"
@ -357,3 +359,65 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
gimp_context_set_display (context, shell->gdisp);
}
void
gimp_display_shell_drop_component (GtkWidget *widget,
gint x,
gint y,
GimpImage *image,
GimpChannelType component,
gpointer data)
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
GimpImage *dest_image = shell->gdisp->gimage;
GimpChannel *channel;
GimpItem *new_item;
const gchar *desc;
gchar *name;
D (g_print ("drop component on canvas\n"));
if (dest_image->gimp->busy)
return;
channel = gimp_channel_new_from_component (image, component, NULL, NULL);
new_item = gimp_item_convert (GIMP_ITEM (channel), dest_image,
GIMP_TYPE_LAYER, TRUE);
g_object_unref (channel);
if (new_item)
{
GimpLayer *new_layer = GIMP_LAYER (new_item);
gint x, y, width, height;
gint off_x, off_y;
gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
NULL, NULL, &desc, NULL);
name = g_strdup_printf (_("%s Channel Copy"), desc);
gimp_object_set_name (GIMP_OBJECT (new_layer), name);
g_free (name);
gimp_image_undo_group_start (dest_image, GIMP_UNDO_GROUP_EDIT_PASTE,
_("Drop New Layer"));
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
gimp_item_offsets (new_item, &off_x, &off_y);
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
gimp_item_translate (new_item, off_x, off_y, FALSE);
gimp_image_add_layer (dest_image, new_layer, -1);
gimp_image_undo_group_end (dest_image);
gimp_image_flush (dest_image);
gimp_context_set_display (gimp_get_user_context (dest_image->gimp),
shell->gdisp);
}
}

View File

@ -20,42 +20,48 @@
#define __GIMP_DISPLAY_SHELL_DND_H__
void gimp_display_shell_drop_drawable (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_vectors (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_svg (GtkWidget *widget,
gint x,
gint y,
const guchar *svg_data,
gsize svg_data_length,
gpointer data);
void gimp_display_shell_drop_pattern (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_color (GtkWidget *widget,
gint x,
gint y,
const GimpRGB *color,
gpointer data);
void gimp_display_shell_drop_buffer (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_uri_list (GtkWidget *widget,
gint x,
gint y,
GList *uri_list,
gpointer data);
void gimp_display_shell_drop_drawable (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_vectors (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_svg (GtkWidget *widget,
gint x,
gint y,
const guchar *svg_data,
gsize svg_data_length,
gpointer data);
void gimp_display_shell_drop_pattern (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_color (GtkWidget *widget,
gint x,
gint y,
const GimpRGB *color,
gpointer data);
void gimp_display_shell_drop_buffer (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
void gimp_display_shell_drop_uri_list (GtkWidget *widget,
gint x,
gint y,
GList *uri_list,
gpointer data);
void gimp_display_shell_drop_component (GtkWidget *widget,
gint x,
gint y,
GimpImage *image,
GimpChannelType component,
gpointer data);
#endif /* __GIMP_DISPLAY_SHELL_DND_H__ */

View File

@ -349,33 +349,36 @@ gimp_display_shell_init (GimpDisplayShell *shell)
shell);
/* dnd stuff */
gimp_dnd_uri_list_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_uri_list,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_VECTORS,
gimp_display_shell_drop_vectors,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_PATTERN,
gimp_display_shell_drop_pattern,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_BUFFER,
gimp_display_shell_drop_buffer,
shell);
gimp_dnd_color_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_color,
shell);
gimp_dnd_svg_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_svg,
shell);
gimp_dnd_uri_list_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_uri_list,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_VECTORS,
gimp_display_shell_drop_vectors,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_PATTERN,
gimp_display_shell_drop_pattern,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_BUFFER,
gimp_display_shell_drop_buffer,
shell);
gimp_dnd_color_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_color,
shell);
gimp_dnd_svg_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_svg,
shell);
gimp_dnd_component_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_component,
shell);
gimp_help_connect (GTK_WIDGET (shell), gimp_standard_help_func,
GIMP_HELP_IMAGE_WINDOW, NULL);

View File

@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
@ -48,26 +49,32 @@
/* local function prototypes */
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_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);
/* public functions */
@ -103,6 +110,10 @@ gimp_toolbox_dnd_init (GimpToolbox *toolbox)
gimp_dnd_viewable_dest_add (toolbox->tool_wbox, GIMP_TYPE_BUFFER,
gimp_toolbox_drop_buffer,
dock->context);
gimp_dnd_component_dest_add (toolbox->tool_wbox,
gimp_toolbox_drop_component,
dock->context);
}
@ -231,3 +242,49 @@ gimp_toolbox_drop_buffer (GtkWidget *widget,
gimp_edit_paste_as_new (context->gimp, NULL, GIMP_BUFFER (viewable));
}
static void
gimp_toolbox_drop_component (GtkWidget *widget,
gint x,
gint y,
GimpImage *image,
GimpChannelType component,
gpointer data)
{
GimpChannel *channel;
GimpImage *new_image;
GimpLayer *new_layer;
const gchar *desc;
gchar *name;
new_image = gimp_create_image (image->gimp,
gimp_image_get_width (image),
gimp_image_get_height (image),
GIMP_GRAY, FALSE);
gimp_image_undo_disable (new_image);
gimp_image_set_resolution (new_image,
image->xresolution, image->yresolution);
gimp_image_set_unit (new_image, gimp_image_get_unit (image));
channel = gimp_channel_new_from_component (image, component, NULL, NULL);
new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (channel), new_image,
GIMP_TYPE_LAYER, FALSE));
g_object_unref (channel);
gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
NULL, NULL, &desc, NULL);
name = g_strdup_printf (_("%s Channel Copy"), desc);
gimp_object_set_name (GIMP_OBJECT (new_layer), name);
g_free (name);
gimp_image_add_layer (new_image, new_layer, 0);
gimp_image_undo_enable (new_image);
gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (new_image);
}