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 "vectors-types.h"
25
#include "core/gimpcontainer.h"
26
#include "core/gimpimage.h"
28
#include "gimpvectors.h"
29
#include "gimpvectorsundo.h"
40
static GObject * gimp_vectors_undo_constructor (GType type,
42
GObjectConstructParam *params);
43
static void gimp_vectors_undo_set_property (GObject *object,
47
static void gimp_vectors_undo_get_property (GObject *object,
52
static gint64 gimp_vectors_undo_get_memsize (GimpObject *object,
55
static void gimp_vectors_undo_pop (GimpUndo *undo,
56
GimpUndoMode undo_mode,
57
GimpUndoAccumulator *accum);
60
G_DEFINE_TYPE (GimpVectorsUndo, gimp_vectors_undo, GIMP_TYPE_ITEM_UNDO)
62
#define parent_class gimp_vectors_undo_parent_class
66
gimp_vectors_undo_class_init (GimpVectorsUndoClass *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_vectors_undo_constructor;
73
object_class->set_property = gimp_vectors_undo_set_property;
74
object_class->get_property = gimp_vectors_undo_get_property;
76
gimp_object_class->get_memsize = gimp_vectors_undo_get_memsize;
78
undo_class->pop = gimp_vectors_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_VECTORS,
87
g_param_spec_object ("prev-vectors", NULL, NULL,
89
GIMP_PARAM_READWRITE |
90
G_PARAM_CONSTRUCT_ONLY));
94
gimp_vectors_undo_init (GimpVectorsUndo *undo)
99
gimp_vectors_undo_constructor (GType type,
101
GObjectConstructParam *params)
104
GimpVectorsUndo *vectors_undo;
106
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
108
vectors_undo = GIMP_VECTORS_UNDO (object);
110
g_assert (GIMP_IS_VECTORS (GIMP_ITEM_UNDO (object)->item));
116
gimp_vectors_undo_set_property (GObject *object,
121
GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (object);
125
case PROP_PREV_POSITION:
126
vectors_undo->prev_position = g_value_get_int (value);
128
case PROP_PREV_VECTORS:
129
vectors_undo->prev_vectors = g_value_get_object (value);
133
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
139
gimp_vectors_undo_get_property (GObject *object,
144
GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (object);
148
case PROP_PREV_POSITION:
149
g_value_set_int (value, vectors_undo->prev_position);
151
case PROP_PREV_VECTORS:
152
g_value_set_object (value, vectors_undo->prev_vectors);
156
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
162
gimp_vectors_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_vectors_undo_pop (GimpUndo *undo,
178
GimpUndoMode undo_mode,
179
GimpUndoAccumulator *accum)
181
GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (undo);
182
GimpVectors *vectors = GIMP_VECTORS (GIMP_ITEM_UNDO (undo)->item);
184
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
186
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
187
undo->undo_type == GIMP_UNDO_VECTORS_ADD) ||
188
(undo_mode == GIMP_UNDO_MODE_REDO &&
189
undo->undo_type == GIMP_UNDO_VECTORS_REMOVE))
193
/* record the current position */
194
vectors_undo->prev_position = gimp_image_get_vectors_index (undo->image,
197
gimp_container_remove (undo->image->vectors, GIMP_OBJECT (vectors));
198
gimp_item_removed (GIMP_ITEM (vectors));
200
if (vectors == gimp_image_get_active_vectors (undo->image))
201
gimp_image_set_active_vectors (undo->image,
202
vectors_undo->prev_vectors);
206
/* restore vectors */
208
/* record the active vectors */
209
vectors_undo->prev_vectors = gimp_image_get_active_vectors (undo->image);
211
gimp_container_insert (undo->image->vectors, GIMP_OBJECT (vectors),
212
vectors_undo->prev_position);
213
gimp_image_set_active_vectors (undo->image, vectors);
215
GIMP_ITEM (vectors)->removed = FALSE;