added "drawable" as construct-only property so that the widget can be

2006-02-26  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpzoompreview.c: added "drawable" as construct-only
	property so that the widget can be constructed using g_object_new().
This commit is contained in:
Sven Neumann 2006-02-26 00:55:35 +00:00 committed by Sven Neumann
parent 9a6e032446
commit 5793fc391c
2 changed files with 110 additions and 19 deletions

View File

@ -1,3 +1,8 @@
2006-02-26 Sven Neumann <sven@gimp.org>
* libgimp/gimpzoompreview.c: added "drawable" as construct-only
property so that the widget can be constructed using g_object_new().
2006-02-26 Sven Neumann <sven@gimp.org>
* libgimp/gimpaspectpreview.c: added "drawable" as construct-only

View File

@ -34,6 +34,12 @@
#include "gimpzoompreview.h"
enum
{
PROP_0,
PROP_DRAWABLE
};
typedef struct GimpZoomPreviewPrivate
{
GimpDrawable *drawable;
@ -41,10 +47,23 @@ typedef struct GimpZoomPreviewPrivate
GdkRectangle extents;
} GimpZoomPreviewPrivate;
#define GIMP_ZOOM_PREVIEW_GET_PRIVATE(obj) \
((GimpZoomPreviewPrivate *) ((GimpZoomPreview *) (obj))->priv)
static GObject * gimp_zoom_preview_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_zoom_preview_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_zoom_preview_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
gdouble old_factor,
gdouble new_factor);
@ -66,6 +85,9 @@ static void gimp_zoom_preview_draw_thumb (GimpPreview *preview,
gint height);
static void gimp_zoom_preview_set_cursor (GimpPreview *preview);
static void gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable);
G_DEFINE_TYPE (GimpZoomPreview, gimp_zoom_preview, GIMP_TYPE_SCROLLED_PREVIEW)
#define parent_class gimp_zoom_preview_parent_class
@ -77,6 +99,10 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
object_class->constructor = gimp_zoom_preview_constructor;
object_class->get_property = gimp_zoom_preview_get_property;
object_class->set_property = gimp_zoom_preview_set_property;
widget_class->style_set = gimp_zoom_preview_style_set;
preview_class->draw = gimp_zoom_preview_draw;
@ -85,6 +111,11 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
preview_class->set_cursor = gimp_zoom_preview_set_cursor;
g_type_class_add_private (object_class, sizeof (GimpZoomPreviewPrivate));
g_object_class_install_property (object_class, PROP_DRAWABLE,
g_param_spec_pointer ("drawable", NULL, NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
@ -142,6 +173,61 @@ gimp_zoom_preview_init (GimpZoomPreview *preview)
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
}
static GObject *
gimp_zoom_preview_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimp_zoom_preview_set_adjustments (GIMP_ZOOM_PREVIEW (object), 1.0, 1.0);
return object;
}
static void
gimp_zoom_preview_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
switch (property_id)
{
case PROP_DRAWABLE:
g_value_set_pointer (value, gimp_zoom_preview_get_drawable (preview));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_zoom_preview_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
switch (property_id)
{
case PROP_DRAWABLE:
gimp_zoom_preview_set_drawable (preview,
g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
gdouble old_factor,
@ -422,28 +508,16 @@ gimp_zoom_preview_set_cursor (GimpPreview *preview)
}
}
/**
* gimp_zoom_preview_new:
* @drawable: a #GimpDrawable
*
* Creates a new #GimpZoomPreview widget for @drawable.
*
* Since: GIMP 2.4
**/
GtkWidget *
gimp_zoom_preview_new (GimpDrawable *drawable)
static void
gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable)
{
GimpZoomPreview *preview;
GimpZoomPreviewPrivate *priv;
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gint width, height;
gint max_width, max_height;
gint x1, y1;
gint x2, y2;
preview = g_object_new (GIMP_TYPE_ZOOM_PREVIEW, NULL);
priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
priv->drawable = drawable;
if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
@ -483,10 +557,22 @@ gimp_zoom_preview_new (GimpDrawable *drawable)
g_object_set (GIMP_PREVIEW (preview)->frame,
"ratio", (gdouble) width / (gdouble) height,
NULL);
}
gimp_zoom_preview_set_adjustments (preview, 1.0, 1.0);
return GTK_WIDGET (preview);
/**
* gimp_zoom_preview_new:
* @drawable: a #GimpDrawable
*
* Creates a new #GimpZoomPreview widget for @drawable.
*
* Since: GIMP 2.4
**/
GtkWidget *
gimp_zoom_preview_new (GimpDrawable *drawable)
{
return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
"drawable", drawable,
NULL);
}
/**