Commit 7abaab62 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

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.
parent 4bbeec96
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
......
......@@ -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 *
......
......@@ -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 *
......
......@@ -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 *
......
......@@ -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,
......
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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;
return TRUE;
}
*width = pattern->mask->width;
*height = pattern->mask->height;
return FALSE;
return TRUE;
}
static TempBuf *
......
......@@ -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;
return TRUE;
}
*width = pattern->mask->width;
*height = pattern->mask->height;
return FALSE;
return TRUE;
}
static TempBuf *
......
......@@ -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;
/* 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);
}
if (viewable_class->get_popup_size (viewable,
width, height, dot_for_dot,
&w, &h))
/* limit the number of pixels to
* GIMP_VIEWABLE_MAX_POPUP_SIZE ^ 2
*/
if ((w * h) > SQR (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;
gdouble factor;
return TRUE;
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;
......
......@@ -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,
......
......@@ -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;
}
......@@ -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);