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 "gimpchannel.h"
28
#include "gimpchannelundo.h"
39
static GObject * gimp_channel_undo_constructor (GType type,
41
GObjectConstructParam *params);
42
static void gimp_channel_undo_set_property (GObject *object,
46
static void gimp_channel_undo_get_property (GObject *object,
51
static gint64 gimp_channel_undo_get_memsize (GimpObject *object,
54
static void gimp_channel_undo_pop (GimpUndo *undo,
55
GimpUndoMode undo_mode,
56
GimpUndoAccumulator *accum);
59
G_DEFINE_TYPE (GimpChannelUndo, gimp_channel_undo, GIMP_TYPE_ITEM_UNDO)
61
#define parent_class gimp_channel_undo_parent_class
65
gimp_channel_undo_class_init (GimpChannelUndoClass *klass)
67
GObjectClass *object_class = G_OBJECT_CLASS (klass);
68
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
69
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
71
object_class->constructor = gimp_channel_undo_constructor;
72
object_class->set_property = gimp_channel_undo_set_property;
73
object_class->get_property = gimp_channel_undo_get_property;
75
gimp_object_class->get_memsize = gimp_channel_undo_get_memsize;
77
undo_class->pop = gimp_channel_undo_pop;
79
g_object_class_install_property (object_class, PROP_PREV_POSITION,
80
g_param_spec_int ("prev-position", NULL, NULL,
82
GIMP_PARAM_READWRITE |
83
G_PARAM_CONSTRUCT_ONLY));
85
g_object_class_install_property (object_class, PROP_PREV_CHANNEL,
86
g_param_spec_object ("prev-channel", NULL, NULL,
88
GIMP_PARAM_READWRITE |
89
G_PARAM_CONSTRUCT_ONLY));
93
gimp_channel_undo_init (GimpChannelUndo *undo)
98
gimp_channel_undo_constructor (GType type,
100
GObjectConstructParam *params)
103
GimpChannelUndo *channel_undo;
105
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
107
channel_undo = GIMP_CHANNEL_UNDO (object);
109
g_assert (GIMP_IS_CHANNEL (GIMP_ITEM_UNDO (object)->item));
115
gimp_channel_undo_set_property (GObject *object,
120
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
124
case PROP_PREV_POSITION:
125
channel_undo->prev_position = g_value_get_int (value);
127
case PROP_PREV_CHANNEL:
128
channel_undo->prev_channel = g_value_get_object (value);
132
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
138
gimp_channel_undo_get_property (GObject *object,
143
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
147
case PROP_PREV_POSITION:
148
g_value_set_int (value, channel_undo->prev_position);
150
case PROP_PREV_CHANNEL:
151
g_value_set_object (value, channel_undo->prev_channel);
155
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
161
gimp_channel_undo_get_memsize (GimpObject *object,
164
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
167
if (! gimp_item_is_attached (item_undo->item))
168
memsize += gimp_object_get_memsize (GIMP_OBJECT (item_undo->item),
171
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
176
gimp_channel_undo_pop (GimpUndo *undo,
177
GimpUndoMode undo_mode,
178
GimpUndoAccumulator *accum)
180
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (undo);
181
GimpChannel *channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
183
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
185
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
186
undo->undo_type == GIMP_UNDO_CHANNEL_ADD) ||
187
(undo_mode == GIMP_UNDO_MODE_REDO &&
188
undo->undo_type == GIMP_UNDO_CHANNEL_REMOVE))
192
/* record the current position */
193
channel_undo->prev_position = gimp_image_get_channel_index (undo->image,
196
gimp_container_remove (undo->image->channels, GIMP_OBJECT (channel));
197
gimp_item_removed (GIMP_ITEM (channel));
199
if (channel == gimp_image_get_active_channel (undo->image))
201
if (channel_undo->prev_channel)
202
gimp_image_set_active_channel (undo->image,
203
channel_undo->prev_channel);
205
gimp_image_unset_active_channel (undo->image);
210
/* restore channel */
212
/* record the active channel */
213
channel_undo->prev_channel = gimp_image_get_active_channel (undo->image);
215
gimp_container_insert (undo->image->channels, GIMP_OBJECT (channel),
216
channel_undo->prev_position);
217
gimp_image_set_active_channel (undo->image, channel);
219
GIMP_ITEM (channel)->removed = FALSE;