1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "core-types.h"
25
#include "gimpcontainer.h"
26
#include "gimpimage.h"
27
#include "gimplayer.h"
28
#include "gimplayer-floating-sel.h"
29
#include "gimplayerundo.h"
40
static GObject * gimp_layer_undo_constructor (GType type,
42
GObjectConstructParam *params);
43
static void gimp_layer_undo_set_property (GObject *object,
47
static void gimp_layer_undo_get_property (GObject *object,
52
static gint64 gimp_layer_undo_get_memsize (GimpObject *object,
55
static void gimp_layer_undo_pop (GimpUndo *undo,
56
GimpUndoMode undo_mode,
57
GimpUndoAccumulator *accum);
60
G_DEFINE_TYPE (GimpLayerUndo, gimp_layer_undo, GIMP_TYPE_ITEM_UNDO)
62
#define parent_class gimp_layer_undo_parent_class
66
gimp_layer_undo_class_init (GimpLayerUndoClass *klass)
68
GObjectClass *object_class = G_OBJECT_CLASS (klass);
69
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
70
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
72
object_class->constructor = gimp_layer_undo_constructor;
73
object_class->set_property = gimp_layer_undo_set_property;
74
object_class->get_property = gimp_layer_undo_get_property;
76
gimp_object_class->get_memsize = gimp_layer_undo_get_memsize;
78
undo_class->pop = gimp_layer_undo_pop;
80
g_object_class_install_property (object_class, PROP_PREV_POSITION,
81
g_param_spec_int ("prev-position", NULL, NULL,
83
GIMP_PARAM_READWRITE |
84
G_PARAM_CONSTRUCT_ONLY));
86
g_object_class_install_property (object_class, PROP_PREV_LAYER,
87
g_param_spec_object ("prev-layer", NULL, NULL,
89
GIMP_PARAM_READWRITE |
90
G_PARAM_CONSTRUCT_ONLY));
94
gimp_layer_undo_init (GimpLayerUndo *undo)
99
gimp_layer_undo_constructor (GType type,
101
GObjectConstructParam *params)
104
GimpLayerUndo *layer_undo;
106
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
108
layer_undo = GIMP_LAYER_UNDO (object);
110
g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
116
gimp_layer_undo_set_property (GObject *object,
121
GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (object);
125
case PROP_PREV_POSITION:
126
layer_undo->prev_position = g_value_get_int (value);
128
case PROP_PREV_LAYER:
129
layer_undo->prev_layer = g_value_get_object (value);
133
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
139
gimp_layer_undo_get_property (GObject *object,
144
GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (object);
148
case PROP_PREV_POSITION:
149
g_value_set_int (value, layer_undo->prev_position);
151
case PROP_PREV_LAYER:
152
g_value_set_object (value, layer_undo->prev_layer);
156
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
162
gimp_layer_undo_get_memsize (GimpObject *object,
165
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
168
if (! gimp_item_is_attached (item_undo->item))
169
memsize += gimp_object_get_memsize (GIMP_OBJECT (item_undo->item),
172
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
177
gimp_layer_undo_pop (GimpUndo *undo,
178
GimpUndoMode undo_mode,
179
GimpUndoAccumulator *accum)
181
GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (undo);
182
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
183
gboolean old_has_alpha;
185
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
187
old_has_alpha = gimp_image_has_alpha (undo->image);
189
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
190
undo->undo_type == GIMP_UNDO_LAYER_ADD) ||
191
(undo_mode == GIMP_UNDO_MODE_REDO &&
192
undo->undo_type == GIMP_UNDO_LAYER_REMOVE))
196
/* record the current position */
197
layer_undo->prev_position = gimp_image_get_layer_index (undo->image,
200
gimp_container_remove (undo->image->layers, GIMP_OBJECT (layer));
201
undo->image->layer_stack = g_slist_remove (undo->image->layer_stack,
204
if (gimp_layer_is_floating_sel (layer))
206
/* invalidate the boundary *before* setting the
207
* floating_sel pointer to NULL because the selection's
208
* outline is affected by the floating_sel and won't be
209
* completely cleared otherwise (bug #160247).
211
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer));
213
undo->image->floating_sel = NULL;
215
/* activate the underlying drawable */
216
floating_sel_activate_drawable (layer);
218
gimp_image_floating_selection_changed (undo->image);
220
else if (layer == gimp_image_get_active_layer (undo->image))
222
if (layer_undo->prev_layer)
224
gimp_image_set_active_layer (undo->image, layer_undo->prev_layer);
226
else if (undo->image->layer_stack)
228
gimp_image_set_active_layer (undo->image,
229
undo->image->layer_stack->data);
233
gimp_image_set_active_layer (undo->image, NULL);
237
gimp_item_removed (GIMP_ITEM (layer));
243
/* record the active layer */
244
layer_undo->prev_layer = gimp_image_get_active_layer (undo->image);
246
/* if this is a floating selection, set the fs pointer */
247
if (gimp_layer_is_floating_sel (layer))
248
undo->image->floating_sel = layer;
250
gimp_container_insert (undo->image->layers,
251
GIMP_OBJECT (layer), layer_undo->prev_position);
252
gimp_image_set_active_layer (undo->image, layer);
254
if (gimp_layer_is_floating_sel (layer))
255
gimp_image_floating_selection_changed (undo->image);
257
GIMP_ITEM (layer)->removed = FALSE;
260
GIMP_ITEM (layer->mask)->removed = FALSE;
263
if (old_has_alpha != gimp_image_has_alpha (undo->image))
264
accum->alpha_changed = TRUE;