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 "gimpimage.h"
26
#include "gimpimage-guides.h"
27
#include "gimpguide.h"
28
#include "gimpguideundo.h"
38
static GObject * gimp_guide_undo_constructor (GType type,
40
GObjectConstructParam *params);
41
static void gimp_guide_undo_set_property (GObject *object,
45
static void gimp_guide_undo_get_property (GObject *object,
50
static void gimp_guide_undo_pop (GimpUndo *undo,
51
GimpUndoMode undo_mode,
52
GimpUndoAccumulator *accum);
53
static void gimp_guide_undo_free (GimpUndo *undo,
54
GimpUndoMode undo_mode);
57
G_DEFINE_TYPE (GimpGuideUndo, gimp_guide_undo, GIMP_TYPE_UNDO)
59
#define parent_class gimp_guide_undo_parent_class
63
gimp_guide_undo_class_init (GimpGuideUndoClass *klass)
65
GObjectClass *object_class = G_OBJECT_CLASS (klass);
66
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
68
object_class->constructor = gimp_guide_undo_constructor;
69
object_class->set_property = gimp_guide_undo_set_property;
70
object_class->get_property = gimp_guide_undo_get_property;
72
undo_class->pop = gimp_guide_undo_pop;
73
undo_class->free = gimp_guide_undo_free;
75
g_object_class_install_property (object_class, PROP_GUIDE,
76
g_param_spec_object ("guide", NULL, NULL,
78
GIMP_PARAM_READWRITE |
79
G_PARAM_CONSTRUCT_ONLY));
83
gimp_guide_undo_init (GimpGuideUndo *undo)
88
gimp_guide_undo_constructor (GType type,
90
GObjectConstructParam *params)
93
GimpGuideUndo *guide_undo;
95
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
97
guide_undo = GIMP_GUIDE_UNDO (object);
99
g_assert (GIMP_IS_GUIDE (guide_undo->guide));
101
guide_undo->orientation = gimp_guide_get_orientation (guide_undo->guide);
102
guide_undo->position = gimp_guide_get_position (guide_undo->guide);
108
gimp_guide_undo_set_property (GObject *object,
113
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (object);
118
guide_undo->guide = (GimpGuide *) g_value_dup_object (value);
122
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
128
gimp_guide_undo_get_property (GObject *object,
133
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (object);
138
g_value_set_object (value, guide_undo->guide);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
148
gimp_guide_undo_pop (GimpUndo *undo,
149
GimpUndoMode undo_mode,
150
GimpUndoAccumulator *accum)
152
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
153
GimpOrientationType orientation;
156
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
158
orientation = gimp_guide_get_orientation (guide_undo->guide);
159
position = gimp_guide_get_position (guide_undo->guide);
161
/* add and move guides manually (nor using the gimp_image_guide
162
* API), because we might be in the middle of an image resizing
163
* undo group and the guide's position might be temporarily out of
169
undo->image->guides = g_list_prepend (undo->image->guides,
171
gimp_guide_set_position (guide_undo->guide, guide_undo->position);
172
g_object_ref (guide_undo->guide);
173
gimp_image_update_guide (undo->image, guide_undo->guide);
175
else if (guide_undo->position == -1)
177
gimp_image_remove_guide (undo->image, guide_undo->guide, FALSE);
181
gimp_image_update_guide (undo->image, guide_undo->guide);
182
gimp_guide_set_position (guide_undo->guide, guide_undo->position);
183
gimp_image_update_guide (undo->image, guide_undo->guide);
186
gimp_guide_set_orientation (guide_undo->guide, guide_undo->orientation);
188
guide_undo->position = position;
189
guide_undo->orientation = orientation;
193
gimp_guide_undo_free (GimpUndo *undo,
194
GimpUndoMode undo_mode)
196
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
198
if (guide_undo->guide)
200
g_object_unref (guide_undo->guide);
201
guide_undo->guide = NULL;
204
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);