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

app/core/gimpguideundo.c app/core/gimpimageundo.c

2007-01-30  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpguideundo.c
	* app/core/gimpimageundo.c
	* app/core/gimplayerpropundo.c
	* app/core/gimpsamplepointundo.c
	* app/core/gimpdrawableundo.c
	* app/core/gimpitempropundo.c
	* app/core/gimpchannelpropundo.c
	* app/core/gimpchannelundo.c
	* app/core/gimpitemundo.c: chain up last in GimpUndo::free(), use
	switch() in place of if/else when there is more than one undo type
	implemented in one file, g_assert_not_reached() in default:, some
	minor cleanups.


svn path=/trunk/; revision=21817
parent 13a3975b
2007-01-30 Michael Natterer <mitch@gimp.org>
* app/core/gimpguideundo.c
* app/core/gimpimageundo.c
* app/core/gimplayerpropundo.c
* app/core/gimpsamplepointundo.c
* app/core/gimpdrawableundo.c
* app/core/gimpitempropundo.c
* app/core/gimpchannelpropundo.c
* app/core/gimpchannelundo.c
* app/core/gimpitemundo.c: chain up last in GimpUndo::free(), use
switch() in place of if/else when there is more than one undo type
implemented in one file, g_assert_not_reached() in default:, some
minor cleanups.
2007-01-30 Michael Natterer <mitch@gimp.org>
 
* app/text/gimptextundo.[ch]: add support for
......@@ -78,9 +78,19 @@ gimp_channel_prop_undo_constructor (GType type,
image = GIMP_UNDO (object)->image;
channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (object)->item);
channel_prop_undo->position = gimp_image_get_channel_index (image, channel);
switch (GIMP_UNDO (object)->undo_type)
{
case GIMP_UNDO_CHANNEL_REPOSITION:
channel_prop_undo->position = gimp_image_get_channel_index (image, channel);
break;
gimp_channel_get_color (channel, &channel_prop_undo->color);
case GIMP_UNDO_CHANNEL_COLOR:
gimp_channel_get_color (channel, &channel_prop_undo->color);
break;
default:
g_assert_not_reached ();
}
return object;
}
......@@ -95,26 +105,31 @@ gimp_channel_prop_undo_pop (GimpUndo *undo,
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_CHANNEL_REPOSITION)
{
gint position;
position = gimp_image_get_channel_index (undo->image, channel);
gimp_image_position_channel (undo->image, channel,
channel_prop_undo->position,
FALSE, NULL);
channel_prop_undo->position = position;
}
else if (undo->undo_type == GIMP_UNDO_CHANNEL_COLOR)
{
GimpRGB color;
gimp_channel_get_color (channel, &color);
gimp_channel_set_color (channel, &channel_prop_undo->color, FALSE);
channel_prop_undo->color = color;
}
else
switch (undo->undo_type)
{
case GIMP_UNDO_CHANNEL_REPOSITION:
{
gint position;
position = gimp_image_get_channel_index (undo->image, channel);
gimp_image_position_channel (undo->image, channel,
channel_prop_undo->position,
FALSE, NULL);
channel_prop_undo->position = position;
}
break;
case GIMP_UNDO_CHANNEL_COLOR:
{
GimpRGB color;
gimp_channel_get_color (channel, &color);
gimp_channel_set_color (channel, &channel_prop_undo->color, FALSE);
channel_prop_undo->color = color;
}
break;
default:
g_assert_not_reached ();
}
}
......@@ -208,11 +208,11 @@ gimp_channel_undo_free (GimpUndo *undo,
{
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (channel_undo->tiles)
{
tile_manager_unref (channel_undo->tiles);
channel_undo->tiles = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -242,8 +242,6 @@ gimp_drawable_undo_free (GimpUndo *undo,
{
GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (drawable_undo->tiles)
{
tile_manager_unref (drawable_undo->tiles);
......@@ -255,4 +253,6 @@ gimp_drawable_undo_free (GimpUndo *undo,
tile_manager_unref (drawable_undo->src2_tiles);
drawable_undo->src2_tiles = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -195,11 +195,11 @@ gimp_guide_undo_free (GimpUndo *undo,
{
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (guide_undo->guide)
{
g_object_unref (guide_undo->guide);
guide_undo->guide = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -104,27 +104,40 @@ gimp_image_undo_constructor (GType type,
image = GIMP_UNDO (object)->image;
image_undo->base_type = image->base_type;
image_undo->width = image->width;
image_undo->height = image->height;
image_undo->xresolution = image->xresolution;
image_undo->yresolution = image->yresolution;
image_undo->resolution_unit = image->resolution_unit;
if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_IMAGE_GRID)
switch (GIMP_UNDO (object)->undo_type)
{
case GIMP_UNDO_IMAGE_TYPE:
image_undo->base_type = image->base_type;
break;
case GIMP_UNDO_IMAGE_SIZE:
image_undo->width = image->width;
image_undo->height = image->height;
break;
case GIMP_UNDO_IMAGE_RESOLUTION:
image_undo->xresolution = image->xresolution;
image_undo->yresolution = image->yresolution;
image_undo->resolution_unit = image->resolution_unit;
break;
case GIMP_UNDO_IMAGE_GRID:
g_assert (GIMP_IS_GRID (image_undo->grid));
GIMP_UNDO (object)->size +=
gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid), NULL);
}
else if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_IMAGE_COLORMAP)
{
break;
case GIMP_UNDO_IMAGE_COLORMAP:
image_undo->num_colors = gimp_image_get_colormap_size (image);
image_undo->colormap = g_memdup (gimp_image_get_colormap (image),
image_undo->num_colors * 3);
GIMP_UNDO (object)->size += image_undo->num_colors * 3;
break;
default:
g_assert_not_reached ();
}
return object;
......@@ -184,43 +197,48 @@ gimp_image_undo_pop (GimpUndo *undo,
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_IMAGE_TYPE)
switch (undo->undo_type)
{
GimpImageBaseType base_type;
case GIMP_UNDO_IMAGE_TYPE:
{
GimpImageBaseType base_type;
base_type = image_undo->base_type;
image_undo->base_type = undo->image->base_type;
g_object_set (undo->image, "base-type", base_type, NULL);
base_type = image_undo->base_type;
image_undo->base_type = undo->image->base_type;
g_object_set (undo->image, "base-type", base_type, NULL);
gimp_image_colormap_changed (undo->image, -1);
gimp_image_colormap_changed (undo->image, -1);
if (image_undo->base_type != undo->image->base_type)
accum->mode_changed = TRUE;
}
else if (undo->undo_type == GIMP_UNDO_IMAGE_SIZE)
{
gint width;
gint height;
if (image_undo->base_type != undo->image->base_type)
accum->mode_changed = TRUE;
}
break;
width = image_undo->width;
height = image_undo->height;
case GIMP_UNDO_IMAGE_SIZE:
{
gint width;
gint height;
image_undo->width = undo->image->width;
image_undo->height = undo->image->height;
width = image_undo->width;
height = image_undo->height;
g_object_set (undo->image,
"width", width,
"height", height,
NULL);
image_undo->width = undo->image->width;
image_undo->height = undo->image->height;
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (undo->image)));
g_object_set (undo->image,
"width", width,
"height", height,
NULL);
if (undo->image->width != image_undo->width ||
undo->image->height != image_undo->height)
accum->size_changed = TRUE;
}
else if (undo->undo_type == GIMP_UNDO_IMAGE_RESOLUTION)
{
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (undo->image)));
if (undo->image->width != image_undo->width ||
undo->image->height != image_undo->height)
accum->size_changed = TRUE;
}
break;
case GIMP_UNDO_IMAGE_RESOLUTION:
if (ABS (image_undo->xresolution - undo->image->xresolution) >= 1e-5 ||
ABS (image_undo->yresolution - undo->image->yresolution) >= 1e-5)
{
......@@ -249,49 +267,53 @@ gimp_image_undo_pop (GimpUndo *undo,
accum->unit_changed = TRUE;
}
}
else if (undo->undo_type == GIMP_UNDO_IMAGE_GRID)
{
GimpGrid *grid;
break;
undo->size -= gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
case GIMP_UNDO_IMAGE_GRID:
{
GimpGrid *grid;
grid = gimp_config_duplicate (GIMP_CONFIG (undo->image->grid));
undo->size -= gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
gimp_image_set_grid (undo->image, image_undo->grid, FALSE);
grid = gimp_config_duplicate (GIMP_CONFIG (undo->image->grid));
g_object_unref (image_undo->grid);
image_undo->grid = grid;
gimp_image_set_grid (undo->image, image_undo->grid, FALSE);
undo->size += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
}
else if (undo->undo_type == GIMP_UNDO_IMAGE_COLORMAP)
{
guchar *colormap;
gint num_colors;
g_object_unref (image_undo->grid);
image_undo->grid = grid;
undo->size += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
}
break;
case GIMP_UNDO_IMAGE_COLORMAP:
{
guchar *colormap;
gint num_colors;
undo->size -= image_undo->num_colors * 3;
undo->size -= image_undo->num_colors * 3;
num_colors = gimp_image_get_colormap_size (undo->image);
colormap = g_memdup (gimp_image_get_colormap (undo->image),
num_colors * 3);
num_colors = gimp_image_get_colormap_size (undo->image);
colormap = g_memdup (gimp_image_get_colormap (undo->image),
num_colors * 3);
gimp_image_set_colormap (undo->image,
image_undo->colormap, image_undo->num_colors,
FALSE);
gimp_image_set_colormap (undo->image,
image_undo->colormap, image_undo->num_colors,
FALSE);
if (image_undo->colormap)
g_free (image_undo->colormap);
if (image_undo->colormap)
g_free (image_undo->colormap);
image_undo->num_colors = num_colors;
image_undo->colormap = colormap;
image_undo->num_colors = num_colors;
image_undo->colormap = colormap;
undo->size += image_undo->num_colors * 3;
}
else
{
undo->size += image_undo->num_colors * 3;
}
break;
default:
g_assert_not_reached ();
}
}
......@@ -313,4 +335,6 @@ gimp_image_undo_free (GimpUndo *undo,
g_free (image_undo->colormap);
image_undo->colormap = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -78,18 +78,30 @@ gimp_item_prop_undo_constructor (GType type,
item = GIMP_ITEM_UNDO (object)->item;
if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_ITEM_RENAME)
switch (GIMP_UNDO (object)->undo_type)
{
case GIMP_UNDO_ITEM_RENAME:
item_prop_undo->name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
GIMP_UNDO (object)->size += strlen (item_prop_undo->name) + 1;
}
break;
case GIMP_UNDO_ITEM_DISPLACE:
gimp_item_offsets (item,
&item_prop_undo->offset_x,
&item_prop_undo->offset_y);
break;
gimp_item_offsets (item,
&item_prop_undo->offset_x,
&item_prop_undo->offset_y);
case GIMP_UNDO_ITEM_VISIBILITY:
item_prop_undo->visible = gimp_item_get_visible (item);
break;
item_prop_undo->visible = gimp_item_get_visible (item);
item_prop_undo->linked = gimp_item_get_linked (item);
case GIMP_UNDO_ITEM_LINKED:
item_prop_undo->linked = gimp_item_get_linked (item);
break;
default:
g_assert_not_reached ();
}
return object;
}
......@@ -104,66 +116,75 @@ gimp_item_prop_undo_pop (GimpUndo *undo,
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_ITEM_RENAME)
{
gchar *name;
undo->size -= strlen (item_prop_undo->name) + 1;
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
gimp_object_take_name (GIMP_OBJECT (item), item_prop_undo->name);
item_prop_undo->name = name;
undo->size += strlen (item_prop_undo->name) + 1;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_DISPLACE)
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_item_translate (item,
item_prop_undo->offset_x - offset_x,
item_prop_undo->offset_y - offset_y,
FALSE);
item_prop_undo->offset_x = offset_x;
item_prop_undo->offset_y = offset_y;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_VISIBILITY)
{
gboolean visible;
visible = gimp_item_get_visible (item);
gimp_item_set_visible (item, item_prop_undo->visible, FALSE);
item_prop_undo->visible = visible;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_LINKED)
{
gboolean linked;
linked = gimp_item_get_linked (item);
gimp_item_set_linked (item, item_prop_undo->linked, FALSE);
item_prop_undo->linked = linked;
}
else
switch (undo->undo_type)
{
case GIMP_UNDO_ITEM_RENAME:
{
gchar *name;
undo->size -= strlen (item_prop_undo->name) + 1;
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
gimp_object_take_name (GIMP_OBJECT (item), item_prop_undo->name);
item_prop_undo->name = name;
undo->size += strlen (item_prop_undo->name) + 1;
}
break;
case GIMP_UNDO_ITEM_DISPLACE:
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_item_translate (item,
item_prop_undo->offset_x - offset_x,
item_prop_undo->offset_y - offset_y,
FALSE);
item_prop_undo->offset_x = offset_x;
item_prop_undo->offset_y = offset_y;
}
break;
case GIMP_UNDO_ITEM_VISIBILITY:
{
gboolean visible;
visible = gimp_item_get_visible (item);
gimp_item_set_visible (item, item_prop_undo->visible, FALSE);
item_prop_undo->visible = visible;
}
break;
case GIMP_UNDO_ITEM_LINKED:
{
gboolean linked;
linked = gimp_item_get_linked (item);
gimp_item_set_linked (item, item_prop_undo->linked, FALSE);
item_prop_undo->linked = linked;
}
break;
default:
g_assert_not_reached ();
}
}
static void
gimp_item_prop_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
GimpUndoMode undo_mode)
{
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (item_prop_undo->name)
{
g_free (item_prop_undo->name);
item_prop_undo->name = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -140,11 +140,11 @@ gimp_item_undo_free (GimpUndo *undo,
{
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (item_undo->item)
{
g_object_unref (item_undo->item);
item_undo->item = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
......@@ -78,10 +78,27 @@ gimp_layer_prop_undo_constructor (GType type,
image = GIMP_UNDO (object)->image;
layer = GIMP_LAYER (GIMP_ITEM_UNDO (object)->item);
layer_prop_undo->position = gimp_image_get_layer_index (image, layer);
layer_prop_undo->mode = gimp_layer_get_mode (layer);
layer_prop_undo->opacity = gimp_layer_get_opacity (layer);
layer_prop_undo->lock_alpha = gimp_layer_get_lock_alpha (layer);
switch (GIMP_UNDO (object)->undo_type)
{
case GIMP_UNDO_LAYER_REPOSITION:
layer_prop_undo->position = gimp_image_get_layer_index (image, layer);
break;
case GIMP_UNDO_LAYER_MODE:
layer_prop_undo->mode = gimp_layer_get_mode (layer);
break;
case GIMP_UNDO_LAYER_OPACITY:
layer_prop_undo->opacity = gimp_layer_get_opacity (layer);
break;
case GIMP_UNDO_LAYER_LOCK_ALPHA:
layer_prop_undo->lock_alpha = gimp_layer_get_lock_alpha (layer);
break;
default:
g_assert_not_reached ();
}
return object;
}
......@@ -96,42 +113,51 @@ gimp_layer_prop_undo_pop (GimpUndo *undo,
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_LAYER_REPOSITION)
{
gint position;
position = gimp_image_get_layer_index (undo->image, layer);
gimp_image_position_layer (undo->image, layer,
layer_prop_undo->position,
FALSE, NULL);
layer_prop_undo->position = position;
}
else if (undo->undo_type == GIMP_UNDO_LAYER_MODE)
{
GimpLayerModeEffects mode;
mode = gimp_layer_get_mode (layer);
gimp_layer_set_mode (layer, layer_prop_undo->mode, FALSE);
layer_prop_undo->mode = mode;
}
else if (undo->undo_type == GIMP_UNDO_LAYER_OPACITY)
{
gdouble opacity;
opacity = gimp_layer_get_opacity (layer);
gimp_layer_set_opacity (layer, layer_prop_undo->opacity, FALSE);
layer_prop_undo->opacity = opacity;
}
else if (undo->undo_type == GIMP_UNDO_LAYER_LOCK_ALPHA)
{
gboolean lock_alpha;
lock_alpha = gimp_layer_get_lock_alpha (layer);
gimp_layer_set_lock_alpha (layer, layer_prop_undo->lock_alpha, FALSE);
layer_prop_undo->lock_alpha = lock_alpha;
}
else