added properties "gimp", "id", "width", "height" and "base-type". Moved

2004-07-14  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage.c: added properties "gimp", "id", "width",
	"height" and "base-type". Moved all code from gimp_image_new()
	to GObject::constructor().

	* app/core/gimpimage-convert.c
	* app/core/gimpimage-crop.c
	* app/core/gimpimage-resize.c
	* app/core/gimpimage-rotate.c
	* app/core/gimpimage-scale.c
	* app/core/gimpimage-undo-push.c: set "width", "height" and
	"base-type" with g_object_set() so "notify" is emitted on the
	properties.

	* app/core/gimpimage-undo.c (gimp_image_undo_pop_stack):
	freeze/thaw property notifications around undoing/redoing so they
	are not emitted in the middle of the undo operation.
This commit is contained in:
Michael Natterer 2004-07-14 12:12:50 +00:00 committed by Michael Natterer
parent 8e2e464f67
commit 87b5322fdb
9 changed files with 605 additions and 427 deletions

View File

@ -1,3 +1,22 @@
2004-07-14 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage.c: added properties "gimp", "id", "width",
"height" and "base-type". Moved all code from gimp_image_new()
to GObject::constructor().
* app/core/gimpimage-convert.c
* app/core/gimpimage-crop.c
* app/core/gimpimage-resize.c
* app/core/gimpimage-rotate.c
* app/core/gimpimage-scale.c
* app/core/gimpimage-undo-push.c: set "width", "height" and
"base-type" with g_object_set() so "notify" is emitted on the
properties.
* app/core/gimpimage-undo.c (gimp_image_undo_pop_stack):
freeze/thaw property notifications around undoing/redoing so they
are not emitted in the middle of the undo operation.
2004-07-14 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.c: converted tabs to spaces, cleanup,

View File

@ -776,6 +776,8 @@ gimp_image_convert (GimpImage *gimage,
break;
}
g_object_freeze_notify (G_OBJECT (gimage));
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_CONVERT,
undo_desc);
@ -784,7 +786,8 @@ gimp_image_convert (GimpImage *gimage,
/* Set the new base type */
old_type = gimage->base_type;
gimage->base_type = new_type;
g_object_set (gimage, "base-type", new_type, NULL);
/* initialize the colour conversion routines */
cpercep_init_conversions ();
@ -1023,6 +1026,7 @@ gimp_image_convert (GimpImage *gimage,
gimp_image_invalidate_layer_previews (gimage);
gimp_image_mode_changed (gimage);
g_object_thaw_notify (G_OBJECT (gimage));
gimp_unset_busy (gimage->gimp);
}

View File

@ -116,6 +116,8 @@ gimp_image_crop (GimpImage *gimage,
GimpItem *item;
GList *list;
g_object_freeze_notify (G_OBJECT (gimage));
if (crop_layers)
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_CROP,
_("Crop Image"));
@ -127,8 +129,10 @@ gimp_image_crop (GimpImage *gimage,
gimp_image_undo_push_image_size (gimage, NULL);
/* Set the new width and height */
gimage->width = width;
gimage->height = height;
g_object_set (gimage,
"width", width,
"height", height,
NULL);
/* Resize all channels */
for (list = GIMP_LIST (gimage->channels)->list;
@ -230,6 +234,7 @@ gimp_image_crop (GimpImage *gimage,
gimp_image_update (gimage, 0, 0, gimage->width, gimage->height);
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
g_object_thaw_notify (G_OBJECT (gimage));
}
gimp_unset_busy (gimage->gimp);

View File

@ -60,6 +60,8 @@ gimp_image_resize (GimpImage *gimage,
gimage->vectors->num_children +
1 /* selection */);
g_object_freeze_notify (G_OBJECT (gimage));
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_RESIZE,
_("Resize Image"));
@ -67,8 +69,10 @@ gimp_image_resize (GimpImage *gimage,
gimp_image_undo_push_image_size (gimage, NULL);
/* Set the new width and height */
gimage->width = new_width;
gimage->height = new_height;
g_object_set (gimage,
"width", new_width,
"height", new_height,
NULL);
/* Resize all channels */
for (list = GIMP_LIST (gimage->channels)->list;
@ -155,6 +159,7 @@ gimp_image_resize (GimpImage *gimage,
gimp_image_undo_group_end (gimage);
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
g_object_thaw_notify (G_OBJECT (gimage));
gimp_unset_busy (gimage->gimp);
}

View File

@ -72,6 +72,8 @@ gimp_image_rotate (GimpImage *gimage,
gimage->vectors->num_children +
1 /* selection */);
g_object_freeze_notify (G_OBJECT (gimage));
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_ROTATE, NULL);
/* Resize the image (if needed) */
@ -171,8 +173,10 @@ gimp_image_rotate (GimpImage *gimage,
{
gimp_image_undo_push_image_size (gimage, NULL);
gimage->width = new_image_width;
gimage->height = new_image_height;
g_object_set (gimage,
"width", new_image_width,
"height", new_image_height,
NULL);
if (gimage->xresolution != gimage->yresolution)
{
@ -191,6 +195,8 @@ gimp_image_rotate (GimpImage *gimage,
if (size_changed)
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
g_object_thaw_notify (G_OBJECT (gimage));
gimp_unset_busy (gimage->gimp);
}

View File

@ -64,21 +64,25 @@ gimp_image_scale (GimpImage *gimage,
gimage->vectors->num_children +
1 /* selection */);
g_object_freeze_notify (G_OBJECT (gimage));
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_SCALE,
_("Scale Image"));
/* Push the image size to the stack */
gimp_image_undo_push_image_size (gimage, NULL);
/* Set the new width and height */
old_width = gimage->width;
old_height = gimage->height;
gimage->width = new_width;
gimage->height = new_height;
img_scale_w = (gdouble) new_width / (gdouble) old_width;
img_scale_h = (gdouble) new_height / (gdouble) old_height;
/* Set the new width and height */
g_object_set (gimage,
"width", new_width,
"height", new_height,
NULL);
/* Scale all channels */
for (list = GIMP_LIST (gimage->channels)->list;
list;
@ -179,6 +183,7 @@ gimp_image_scale (GimpImage *gimage,
gimp_image_undo_group_end (gimage);
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
g_object_thaw_notify (G_OBJECT (gimage));
gimp_unset_busy (gimage->gimp);
}

View File

@ -111,7 +111,7 @@ undo_pop_image_type (GimpUndo *undo,
tmp = itu->base_type;
itu->base_type = undo->gimage->base_type;
undo->gimage->base_type = tmp;
g_object_set (undo->gimage, "base-type", tmp, NULL);
gimp_image_colormap_changed (undo->gimage, -1);
@ -190,8 +190,10 @@ undo_pop_image_size (GimpUndo *undo,
isu->width = undo->gimage->width;
isu->height = undo->gimage->height;
undo->gimage->width = width;
undo->gimage->height = height;
g_object_set (undo->gimage,
"width", width,
"height", height,
NULL);
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (undo->gimage)));

View File

@ -288,11 +288,12 @@ gimp_image_undo_pop_stack (GimpImage *gimage,
GimpUndo *undo;
GimpUndoAccumulator accum = { 0, };
g_object_freeze_notify (G_OBJECT (gimage));
undo = gimp_undo_stack_pop_undo (undo_stack, undo_mode, &accum);
if (! undo)
return;
if (undo)
{
if (GIMP_IS_UNDO_STACK (undo))
gimp_list_reverse (GIMP_LIST (GIMP_UNDO_STACK (undo)->undos));
@ -323,6 +324,9 @@ gimp_image_undo_pop_stack (GimpImage *gimage,
undo);
}
g_object_thaw_notify (G_OBJECT (gimage));
}
static void
gimp_image_undo_free_space (GimpImage *gimage)
{

View File

@ -99,12 +99,33 @@ enum
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_GIMP,
PROP_ID,
PROP_WIDTH,
PROP_HEIGHT,
PROP_BASE_TYPE
};
/* local function prototypes */
static void gimp_image_class_init (GimpImageClass *klass);
static void gimp_image_init (GimpImage *gimage);
static GObject *gimp_image_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_image_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_image_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_image_dispose (GObject *object);
static void gimp_image_finalize (GObject *object);
@ -209,13 +230,9 @@ gimp_image_get_type (void)
static void
gimp_image_class_init (GimpImageClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -419,6 +436,9 @@ gimp_image_class_init (GimpImageClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->constructor = gimp_image_constructor;
object_class->set_property = gimp_image_set_property;
object_class->get_property = gimp_image_get_property;
object_class->dispose = gimp_image_dispose;
object_class->finalize = gimp_image_finalize;
@ -453,6 +473,36 @@ gimp_image_class_init (GimpImageClass *klass)
klass->undo_event = NULL;
klass->flush = gimp_image_real_flush;
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp", NULL, NULL,
GIMP_TYPE_GIMP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_int ("id", NULL, NULL,
0, G_MAXINT, 0,
G_PARAM_READABLE));
g_object_class_install_property (object_class, PROP_WIDTH,
g_param_spec_int ("width", NULL, NULL,
1, GIMP_MAX_IMAGE_SIZE, 1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_int ("height", NULL, NULL,
1, GIMP_MAX_IMAGE_SIZE, 1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_BASE_TYPE,
g_param_spec_enum ("base-type", NULL, NULL,
GIMP_TYPE_IMAGE_BASE_TYPE,
GIMP_RGB,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
gimp_image_color_hash_init ();
}
@ -571,6 +621,135 @@ gimp_image_init (GimpImage *gimage)
gimage->flush_accum.mask_changed = FALSE;
}
static GObject *
gimp_image_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpImage *gimage;
GimpCoreConfig *config;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimage = GIMP_IMAGE (object);
g_assert (GIMP_IS_GIMP (gimage->gimp));
config = gimage->gimp->config;
gimage->ID = gimage->gimp->next_image_ID++;
g_hash_table_insert (gimage->gimp->image_table,
GINT_TO_POINTER (gimage->ID),
gimage);
gimage->xresolution = config->default_image->xresolution;
gimage->yresolution = config->default_image->yresolution;
gimage->unit = config->default_image->resolution_unit;
gimage->grid = gimp_config_duplicate (GIMP_CONFIG (config->default_grid));
switch (gimage->base_type)
{
case GIMP_RGB:
case GIMP_GRAY:
break;
case GIMP_INDEXED:
/* always allocate 256 colors for the colormap */
gimage->num_cols = 0;
gimage->cmap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
break;
default:
break;
}
/* create the selection mask */
gimage->selection_mask = gimp_selection_new (gimage,
gimage->width,
gimage->height);
g_object_ref (gimage->selection_mask);
gimp_item_sink (GIMP_ITEM (gimage->selection_mask));
g_signal_connect (gimage->selection_mask, "update",
G_CALLBACK (gimp_image_mask_update),
gimage);
g_signal_connect_object (config, "notify::transparency-type",
G_CALLBACK (gimp_image_invalidate_layer_previews),
gimage, G_CONNECT_SWAPPED);
g_signal_connect_object (config, "notify::transparency-size",
G_CALLBACK (gimp_image_invalidate_layer_previews),
gimage, G_CONNECT_SWAPPED);
g_signal_connect_object (config, "notify::layer-previews",
G_CALLBACK (gimp_viewable_size_changed),
gimage, G_CONNECT_SWAPPED);
return object;
}
static void
gimp_image_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpImage *gimage = GIMP_IMAGE (object);
switch (property_id)
{
case PROP_GIMP:
gimage->gimp = g_value_get_object (value);
break;
case PROP_ID:
g_assert_not_reached ();
break;
case PROP_WIDTH:
gimage->width = g_value_get_int (value);
break;
case PROP_HEIGHT:
gimage->height = g_value_get_int (value);
break;
case PROP_BASE_TYPE:
gimage->base_type = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_image_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpImage *gimage = GIMP_IMAGE (object);
switch (property_id)
{
case PROP_GIMP:
g_value_set_object (value, gimage->gimp);
break;
case PROP_ID:
g_value_set_int (value, gimage->ID);
break;
case PROP_WIDTH:
g_value_set_int (value, gimage->width);
break;
case PROP_HEIGHT:
g_value_set_int (value, gimage->height);
break;
case PROP_BASE_TYPE:
g_value_set_enum (value, gimage->base_type);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_image_dispose (GObject *object)
{
@ -1026,65 +1205,14 @@ gimp_image_new (Gimp *gimp,
gint height,
GimpImageBaseType base_type)
{
GimpImage *gimage;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
gimage = g_object_new (GIMP_TYPE_IMAGE, NULL);
gimage->gimp = gimp;
gimage->ID = gimp->next_image_ID++;
g_hash_table_insert (gimp->image_table,
GINT_TO_POINTER (gimage->ID),
(gpointer) gimage);
gimage->width = width;
gimage->height = height;
gimage->base_type = base_type;
gimage->xresolution = gimp->config->default_image->xresolution;
gimage->yresolution = gimp->config->default_image->yresolution;
gimage->unit = gimp->config->default_image->resolution_unit;
gimage->grid = gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_grid));
switch (base_type)
{
case GIMP_RGB:
case GIMP_GRAY:
break;
case GIMP_INDEXED:
/* always allocate 256 colors for the colormap */
gimage->num_cols = 0;
gimage->cmap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
break;
default:
break;
}
/* create the selection mask */
gimage->selection_mask = gimp_selection_new (gimage,
gimage->width,
gimage->height);
g_object_ref (gimage->selection_mask);
gimp_item_sink (GIMP_ITEM (gimage->selection_mask));
g_signal_connect (gimage->selection_mask, "update",
G_CALLBACK (gimp_image_mask_update),
gimage);
g_signal_connect_object (gimp->config, "notify::transparency-type",
G_CALLBACK (gimp_image_invalidate_layer_previews),
gimage, G_CONNECT_SWAPPED);
g_signal_connect_object (gimp->config, "notify::transparency-size",
G_CALLBACK (gimp_image_invalidate_layer_previews),
gimage, G_CONNECT_SWAPPED);
g_signal_connect_object (gimp->config, "notify::layer-previews",
G_CALLBACK (gimp_viewable_size_changed),
gimage, G_CONNECT_SWAPPED);
return gimage;
return g_object_new (GIMP_TYPE_IMAGE,
"gimp", gimp,
"width", width,
"height", height,
"base-type", base_type,
NULL);
}
GimpImageBaseType