added virtual function GimpViewable::get_size() and public API

2005-05-25  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpviewable.[ch]: added virtual function
	GimpViewable::get_size() and public API gimp_viewable_get_size()
	which return width and height and a boolean indicating if the
	viewable has a size at all.
	Added default implementation of GimpViewable::get_popup_size()
	using the new get_size() API.

	* app/core/gimpbrush.c
	* app/core/gimpbuffer.c
	* app/core/gimpdrawable.c
	* app/core/gimpimage.c
	* app/core/gimppattern.c: implement GimpViewable::get_size().

	* app/core/gimpbrush.c
	* app/core/gimppattern.c: removed GimpViewable::get_popup_size()
	implementations, the default one is good enough.

	* app/core/gimpbrushpipe.c (gimp_brush_pipe_get_popup_size):
	redirect to gimp_viewable_get_size() instead of duplicating its
	return values.

	* app/widgets/gimpcontainertreeview.c
	* app/widgets/gimpview.c: allow pixbuf dragging out of any
	viewable that has a size.

	* app/widgets/gimpdrawabletreeview.c: removed pixbuf dragging code
	here.

	* app/widgets/gimpdnd.c: set gimp busy around encoding/decoding
	pixbufs into/from GtkSelectionData, because it can be a time
	consuming operation.
This commit is contained in:
Michael Natterer 2005-05-25 10:05:17 +00:00 committed by Michael Natterer
parent 4bbeec9640
commit 7abaab62e0
15 changed files with 276 additions and 180 deletions

View File

@ -1,3 +1,37 @@
2005-05-25 Michael Natterer <mitch@gimp.org>
* app/core/gimpviewable.[ch]: added virtual function
GimpViewable::get_size() and public API gimp_viewable_get_size()
which return width and height and a boolean indicating if the
viewable has a size at all.
Added default implementation of GimpViewable::get_popup_size()
using the new get_size() API.
* app/core/gimpbrush.c
* app/core/gimpbuffer.c
* app/core/gimpdrawable.c
* app/core/gimpimage.c
* app/core/gimppattern.c: implement GimpViewable::get_size().
* app/core/gimpbrush.c
* app/core/gimppattern.c: removed GimpViewable::get_popup_size()
implementations, the default one is good enough.
* app/core/gimpbrushpipe.c (gimp_brush_pipe_get_popup_size):
redirect to gimp_viewable_get_size() instead of duplicating its
return values.
* app/widgets/gimpcontainertreeview.c
* app/widgets/gimpview.c: allow pixbuf dragging out of any
viewable that has a size.
* app/widgets/gimpdrawabletreeview.c: removed pixbuf dragging code
here.
* app/widgets/gimpdnd.c: set gimp busy around encoding/decoding
pixbufs into/from GtkSelectionData, because it can be a time
consuming operation.
2005-05-25 Michael Natterer <mitch@gimp.org>
* app/widgets/gimptoolbox-dnd.c (gimp_toolbox_drop_pixbuf): fixed

View File

@ -52,12 +52,9 @@ static void gimp_brush_finalize (GObject *object);
static gint64 gimp_brush_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_brush_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
static gboolean gimp_brush_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static TempBuf * gimp_brush_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
@ -130,7 +127,7 @@ gimp_brush_class_init (GimpBrushClass *klass)
gimp_object_class->get_memsize = gimp_brush_get_memsize;
viewable_class->default_stock_id = "gimp-tool-paintbrush";
viewable_class->get_popup_size = gimp_brush_get_popup_size;
viewable_class->get_size = gimp_brush_get_size;
viewable_class->get_new_preview = gimp_brush_get_new_preview;
viewable_class->get_description = gimp_brush_get_description;
@ -192,24 +189,16 @@ gimp_brush_get_memsize (GimpObject *object,
}
static gboolean
gimp_brush_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height)
gimp_brush_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpBrush *brush = GIMP_BRUSH (viewable);
if (brush->mask->width > width || brush->mask->height > height)
{
*popup_width = brush->mask->width;
*popup_height = brush->mask->height;
*width = brush->mask->width;
*height = brush->mask->height;
return TRUE;
}
return FALSE;
return TRUE;
}
static TempBuf *

View File

@ -215,12 +215,7 @@ gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
gint *popup_width,
gint *popup_height)
{
GimpBrush *brush = GIMP_BRUSH (viewable);
*popup_width = brush->mask->width;
*popup_height = brush->mask->height;
return TRUE;
return gimp_viewable_get_size (viewable, popup_width, popup_height);
}
static GimpBrush *

View File

@ -215,12 +215,7 @@ gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
gint *popup_width,
gint *popup_height)
{
GimpBrush *brush = GIMP_BRUSH (viewable);
*popup_width = brush->mask->width;
*popup_height = brush->mask->height;
return TRUE;
return gimp_viewable_get_size (viewable, popup_width, popup_height);
}
static GimpBrush *

View File

@ -41,6 +41,9 @@ static void gimp_buffer_finalize (GObject *object);
static gint64 gimp_buffer_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_buffer_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static void gimp_buffer_get_preview_size (GimpViewable *viewable,
gint size,
gboolean is_popup,
@ -105,6 +108,7 @@ gimp_buffer_class_init (GimpBufferClass *klass)
gimp_object_class->get_memsize = gimp_buffer_get_memsize;
viewable_class->default_stock_id = "gtk-paste";
viewable_class->get_size = gimp_buffer_get_size;
viewable_class->get_preview_size = gimp_buffer_get_preview_size;
viewable_class->get_popup_size = gimp_buffer_get_popup_size;
viewable_class->get_new_preview = gimp_buffer_get_new_preview;
@ -135,11 +139,9 @@ static gint64
gimp_buffer_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpBuffer *buffer;
GimpBuffer *buffer = GIMP_BUFFER (object);
gint64 memsize = 0;
buffer = GIMP_BUFFER (object);
if (buffer->tiles)
memsize += tile_manager_get_memsize (buffer->tiles, FALSE);
@ -147,6 +149,19 @@ gimp_buffer_get_memsize (GimpObject *object,
gui_size);
}
static gboolean
gimp_buffer_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpBuffer *buffer = GIMP_BUFFER (viewable);
*width = gimp_buffer_get_width (buffer);
*height = gimp_buffer_get_height (buffer);
return TRUE;
}
static void
gimp_buffer_get_preview_size (GimpViewable *viewable,
gint size,

View File

@ -71,6 +71,9 @@ static void gimp_drawable_finalize (GObject *object);
static gint64 gimp_drawable_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_drawable_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static void gimp_drawable_invalidate_preview (GimpViewable *viewable);
static GimpItem * gimp_drawable_duplicate (GimpItem *item,
@ -230,6 +233,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
gimp_object_class->get_memsize = gimp_drawable_get_memsize;
viewable_class->get_size = gimp_drawable_get_size;
viewable_class->invalidate_preview = gimp_drawable_invalidate_preview;
viewable_class->get_preview = gimp_drawable_get_preview;
@ -306,6 +310,19 @@ gimp_drawable_get_memsize (GimpObject *object,
gui_size);
}
static gboolean
gimp_drawable_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpItem *item = GIMP_ITEM (viewable);
*width = item->width;
*height = item->height;
return TRUE;
}
static void
gimp_drawable_invalidate_preview (GimpViewable *viewable)
{

View File

@ -136,6 +136,9 @@ static void gimp_image_name_changed (GimpObject *object);
static gint64 gimp_image_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_image_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static void gimp_image_invalidate_preview (GimpViewable *viewable);
static void gimp_image_size_changed (GimpViewable *viewable);
static gchar * gimp_image_get_description (GimpViewable *viewable,
@ -472,6 +475,7 @@ gimp_image_class_init (GimpImageClass *klass)
gimp_object_class->get_memsize = gimp_image_get_memsize;
viewable_class->default_stock_id = "gimp-image";
viewable_class->get_size = gimp_image_get_size;
viewable_class->invalidate_preview = gimp_image_invalidate_preview;
viewable_class->size_changed = gimp_image_size_changed;
viewable_class->get_preview_size = gimp_image_get_preview_size;
@ -993,6 +997,19 @@ gimp_image_get_memsize (GimpObject *object,
gui_size);
}
static gboolean
gimp_image_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpImage *image = GIMP_IMAGE (viewable);
*width = image->width;
*height = image->height;
return TRUE;
}
static void
gimp_image_invalidate_preview (GimpViewable *viewable)
{

View File

@ -65,12 +65,9 @@ static void gimp_pattern_finalize (GObject *object);
static gint64 gimp_pattern_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_pattern_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_heigh);
static gboolean gimp_pattern_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static TempBuf * gimp_pattern_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
@ -132,7 +129,7 @@ gimp_pattern_class_init (GimpPatternClass *klass)
gimp_object_class->get_memsize = gimp_pattern_get_memsize;
viewable_class->default_stock_id = "gimp-tool-bucket-fill";
viewable_class->get_popup_size = gimp_pattern_get_popup_size;
viewable_class->get_size = gimp_pattern_get_size;
viewable_class->get_new_preview = gimp_pattern_get_new_preview;
viewable_class->get_description = gimp_pattern_get_description;
@ -175,24 +172,16 @@ gimp_pattern_get_memsize (GimpObject *object,
}
static gboolean
gimp_pattern_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height)
gimp_pattern_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpPattern *pattern = GIMP_PATTERN (viewable);
if (pattern->mask->width > width || pattern->mask->height > height)
{
*popup_width = pattern->mask->width;
*popup_height = pattern->mask->height;
*width = pattern->mask->width;
*height = pattern->mask->height;
return TRUE;
}
return FALSE;
return TRUE;
}
static TempBuf *

View File

@ -65,12 +65,9 @@ static void gimp_pattern_finalize (GObject *object);
static gint64 gimp_pattern_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_pattern_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_heigh);
static gboolean gimp_pattern_get_size (GimpViewable *viewable,
gint *width,
gint *height);
static TempBuf * gimp_pattern_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
@ -132,7 +129,7 @@ gimp_pattern_class_init (GimpPatternClass *klass)
gimp_object_class->get_memsize = gimp_pattern_get_memsize;
viewable_class->default_stock_id = "gimp-tool-bucket-fill";
viewable_class->get_popup_size = gimp_pattern_get_popup_size;
viewable_class->get_size = gimp_pattern_get_size;
viewable_class->get_new_preview = gimp_pattern_get_new_preview;
viewable_class->get_description = gimp_pattern_get_description;
@ -175,24 +172,16 @@ gimp_pattern_get_memsize (GimpObject *object,
}
static gboolean
gimp_pattern_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height)
gimp_pattern_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpPattern *pattern = GIMP_PATTERN (viewable);
if (pattern->mask->width > width || pattern->mask->height > height)
{
*popup_width = pattern->mask->width;
*popup_height = pattern->mask->height;
*width = pattern->mask->width;
*height = pattern->mask->height;
return TRUE;
}
return FALSE;
return TRUE;
}
static TempBuf *

View File

@ -80,6 +80,12 @@ static void gimp_viewable_real_get_preview_size (GimpViewable *viewable,
gboolean dot_for_dot,
gint *width,
gint *height);
static gboolean gimp_viewable_real_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
static gchar * gimp_viewable_real_get_description (GimpViewable *viewable,
gchar **tooltip);
static gboolean gimp_viewable_serialize_property (GimpConfig *config,
@ -175,8 +181,9 @@ gimp_viewable_class_init (GimpViewableClass *klass)
klass->invalidate_preview = gimp_viewable_real_invalidate_preview;
klass->size_changed = NULL;
klass->get_size = NULL;
klass->get_preview_size = gimp_viewable_real_get_preview_size;
klass->get_popup_size = NULL;
klass->get_popup_size = gimp_viewable_real_get_popup_size;
klass->get_preview = NULL;
klass->get_new_preview = NULL;
klass->get_pixbuf = NULL;
@ -304,6 +311,30 @@ gimp_viewable_real_get_preview_size (GimpViewable *viewable,
*height = size;
}
static gboolean
gimp_viewable_real_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height)
{
gint w, h;
if (gimp_viewable_get_size (viewable, &w, &h))
{
if (w > width || h > height)
{
*popup_width = w;
*popup_height = h;
return TRUE;
}
}
return FALSE;
}
static GdkPixbuf *
gimp_viewable_real_get_new_pixbuf (GimpViewable *viewable,
gint width,
@ -496,6 +527,29 @@ gimp_viewable_calc_preview_size (gint aspect_width,
if (scaling_up) *scaling_up = (xratio > 1.0) || (yratio > 1.0);
}
gboolean
gimp_viewable_get_size (GimpViewable *viewable,
gint *width,
gint *height)
{
GimpViewableClass *viewable_class;
gboolean retval = FALSE;
gint w = 0;
gint h = 0;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), FALSE);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
if (viewable_class->get_size)
retval = viewable_class->get_size (viewable, &w, &h);
if (width) *width = w;
if (height) *height = h;
return retval;
}
/**
* gimp_viewable_get_preview_size:
* @viewable: the object for which to calculate the preview size.
@ -562,58 +616,52 @@ gimp_viewable_get_popup_size (GimpViewable *viewable,
gint *popup_width,
gint *popup_height)
{
GimpViewableClass *viewable_class;
gint w, h;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), FALSE);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
if (viewable_class->get_popup_size)
if (GIMP_VIEWABLE_GET_CLASS (viewable)->get_popup_size (viewable,
width, height,
dot_for_dot,
&w, &h))
{
gint w, h;
if (w < 1) w = 1;
if (h < 1) h = 1;
if (viewable_class->get_popup_size (viewable,
width, height, dot_for_dot,
&w, &h))
/* limit the popup to 2 * GIMP_VIEWABLE_MAX_POPUP_SIZE
* on each axis.
*/
if ((w > (2 * GIMP_VIEWABLE_MAX_POPUP_SIZE)) ||
(h > (2 * GIMP_VIEWABLE_MAX_POPUP_SIZE)))
{
if (w < 1) w = 1;
if (h < 1) h = 1;
/* limit the popup to 2 * GIMP_VIEWABLE_MAX_POPUP_SIZE
* on each axis.
*/
if ((w > (2 * GIMP_VIEWABLE_MAX_POPUP_SIZE)) ||
(h > (2 * GIMP_VIEWABLE_MAX_POPUP_SIZE)))
{
gimp_viewable_calc_preview_size (w, h,
2 * GIMP_VIEWABLE_MAX_POPUP_SIZE,
2 * GIMP_VIEWABLE_MAX_POPUP_SIZE,
dot_for_dot, 1.0, 1.0,
&w, &h, NULL);
}
/* limit the number of pixels to
* GIMP_VIEWABLE_MAX_POPUP_SIZE ^ 2
*/
if ((w * h) > SQR (GIMP_VIEWABLE_MAX_POPUP_SIZE))
{
gdouble factor;
factor = sqrt (((gdouble) (w * h) /
(gdouble) SQR (GIMP_VIEWABLE_MAX_POPUP_SIZE)));
w = RINT ((gdouble) w / factor);
h = RINT ((gdouble) h / factor);
}
if (w < 1) w = 1;
if (h < 1) h = 1;
if (popup_width) *popup_width = w;
if (popup_height) *popup_height = h;
return TRUE;
gimp_viewable_calc_preview_size (w, h,
2 * GIMP_VIEWABLE_MAX_POPUP_SIZE,
2 * GIMP_VIEWABLE_MAX_POPUP_SIZE,
dot_for_dot, 1.0, 1.0,
&w, &h, NULL);
}
/* limit the number of pixels to
* GIMP_VIEWABLE_MAX_POPUP_SIZE ^ 2
*/
if ((w * h) > SQR (GIMP_VIEWABLE_MAX_POPUP_SIZE))
{
gdouble factor;
factor = sqrt (((gdouble) (w * h) /
(gdouble) SQR (GIMP_VIEWABLE_MAX_POPUP_SIZE)));
w = RINT ((gdouble) w / factor);
h = RINT ((gdouble) h / factor);
}
if (w < 1) w = 1;
if (h < 1) h = 1;
if (popup_width) *popup_width = w;
if (popup_height) *popup_height = h;
return TRUE;
}
return FALSE;

View File

@ -64,6 +64,9 @@ struct _GimpViewableClass
void (* size_changed) (GimpViewable *viewable);
/* virtual functions */
gboolean (* get_size) (GimpViewable *viewable,
gint *width,
gint *height);
void (* get_preview_size) (GimpViewable *viewable,
gint size,
gboolean is_popup,
@ -109,6 +112,9 @@ void gimp_viewable_calc_preview_size (gint aspect_width,
gint *return_height,
gboolean *scaling_up);
gboolean gimp_viewable_get_size (GimpViewable *viewable,
gint *width,
gint *height);
void gimp_viewable_get_preview_size (GimpViewable *viewable,
gint size,
gboolean popup,

View File

@ -98,6 +98,8 @@ static void gimp_container_tree_view_renderer_update (GimpViewRenderer *r
static GimpViewable * gimp_container_tree_view_drag_viewable (GtkWidget *widget,
gpointer data);
static GdkPixbuf * gimp_container_tree_view_drag_pixbuf (GtkWidget *widget,
gpointer data);
static GimpContainerBoxClass *parent_class = NULL;
@ -476,6 +478,9 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (tree_view->view),
old_container->children_type))
{
if (GIMP_VIEWABLE_CLASS (g_type_class_peek (old_container->children_type))->get_size)
gimp_dnd_pixbuf_source_remove (GTK_WIDGET (tree_view->view));
gtk_drag_source_unset (GTK_WIDGET (tree_view->view));
}
@ -495,6 +500,11 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
container->children_type,
gimp_container_tree_view_drag_viewable,
tree_view);
if (GIMP_VIEWABLE_CLASS (g_type_class_peek (container->children_type))->get_size)
gimp_dnd_pixbuf_source_add (GTK_WIDGET (tree_view->view),
gimp_container_tree_view_drag_pixbuf,
tree_view);
}
/* connect button_press_event after DND so we can keep the list from
@ -1085,3 +1095,18 @@ gimp_container_tree_view_drag_viewable (GtkWidget *widget,
return tree_view->dnd_viewable;
}
static GdkPixbuf *
gimp_container_tree_view_drag_pixbuf (GtkWidget *widget,
gpointer data)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
GimpViewable *viewable = tree_view->dnd_viewable;
gint width;
gint height;
if (viewable && gimp_viewable_get_size (viewable, &width, &height))
return gimp_viewable_get_new_pixbuf (viewable, width, height);
return NULL;
}

View File

@ -1462,8 +1462,12 @@ gimp_dnd_get_pixbuf_data (GtkWidget *widget,
if (pixbuf)
{
gimp_set_busy (the_dnd_gimp);
gtk_selection_data_set_pixbuf (selection, pixbuf);
g_object_unref (pixbuf);
gimp_unset_busy (the_dnd_gimp);
}
}
@ -1477,8 +1481,12 @@ gimp_dnd_set_pixbuf_data (GtkWidget *widget,
{
GdkPixbuf *pixbuf;
gimp_set_busy (the_dnd_gimp);
pixbuf = gtk_selection_data_get_pixbuf (selection);
gimp_unset_busy (the_dnd_gimp);
if (! pixbuf)
return FALSE;

View File

@ -51,8 +51,6 @@ static GObject * gimp_drawable_tree_view_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_drawable_tree_view_set_container (GimpContainerView *view,
GimpContainer *container);
static gboolean gimp_drawable_tree_view_select_item (GimpContainerView *view,
GimpViewable *item,
gpointer insert_data);
@ -80,10 +78,6 @@ static void gimp_drawable_tree_view_floating_selection_changed
(GimpImage *gimage,
GimpDrawableTreeView *view);
static GdkPixbuf * gimp_drawable_tree_view_drag_pixbuf
(GtkWidget *widget,
gpointer data);
static void gimp_drawable_tree_view_new_pattern_dropped
(GtkWidget *widget,
gint x,
@ -201,37 +195,12 @@ gimp_drawable_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
{
parent_view_iface = g_type_interface_peek_parent (view_iface);
view_iface->set_container = gimp_drawable_tree_view_set_container;
view_iface->select_item = gimp_drawable_tree_view_select_item;
view_iface->select_item = gimp_drawable_tree_view_select_item;
}
/* GimpContainerView methods */
static void
gimp_drawable_tree_view_set_container (GimpContainerView *view,
GimpContainer *container)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
GimpContainer *old_container;
old_container = gimp_container_view_get_container (GIMP_CONTAINER_VIEW (view));
if (old_container && ! container)
{
gimp_dnd_pixbuf_source_remove (GTK_WIDGET (tree_view->view));
}
parent_view_iface->set_container (view, container);
if (! old_container && container)
{
gimp_dnd_pixbuf_source_add (GTK_WIDGET (tree_view->view),
gimp_drawable_tree_view_drag_pixbuf,
tree_view);
}
}
static gboolean
gimp_drawable_tree_view_select_item (GimpContainerView *view,
GimpViewable *item,
@ -378,30 +347,6 @@ gimp_drawable_tree_view_floating_selection_changed (GimpImage *gimage
(GimpViewable *) item);
}
static GdkPixbuf *
gimp_drawable_tree_view_drag_pixbuf (GtkWidget *widget,
gpointer data)
{
GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data);
GimpImage *gimage = view->gimage;
GimpItem *item;
GdkPixbuf *pixbuf = NULL;
item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (gimage);
if (item)
{
pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (item),
gimp_item_width (item),
gimp_item_height (item));
if (pixbuf)
g_object_ref (pixbuf);
}
return pixbuf;
}
static void
gimp_drawable_tree_view_new_dropped (GimpItemTreeView *view,
gint x,

View File

@ -90,6 +90,8 @@ static void gimp_view_update_callback (GimpViewRenderer *renderer,
static GimpViewable * gimp_view_drag_viewable (GtkWidget *widget,
gpointer data);
static GdkPixbuf * gimp_view_drag_pixbuf (GtkWidget *widget,
gpointer data);
@ -587,6 +589,9 @@ gimp_view_real_set_viewable (GimpView *view,
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (view),
G_TYPE_FROM_INSTANCE (view->viewable)))
{
if (gimp_viewable_get_size (view->viewable, NULL, NULL))
gimp_dnd_pixbuf_source_remove (GTK_WIDGET (view));
gtk_drag_source_unset (GTK_WIDGET (view));
}
}
@ -602,6 +607,11 @@ gimp_view_real_set_viewable (GimpView *view,
viewable_type,
gimp_view_drag_viewable,
NULL);
if (gimp_viewable_get_size (viewable, NULL, NULL))
gimp_dnd_pixbuf_source_add (GTK_WIDGET (view),
gimp_view_drag_pixbuf,
NULL);
}
}
@ -806,3 +816,17 @@ gimp_view_drag_viewable (GtkWidget *widget,
{
return GIMP_VIEW (widget)->viewable;
}
static GdkPixbuf *
gimp_view_drag_pixbuf (GtkWidget *widget,
gpointer data)
{
GimpViewable *viewable = GIMP_VIEW (widget)->viewable;
gint width;
gint height;
if (viewable && gimp_viewable_get_size (viewable, &width, &height))
return gimp_viewable_get_new_pixbuf (viewable, width, height);
return NULL;
}