1
/* The GIMP -- an 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 "text-types.h"
25
#include "config/gimpconfig.h"
26
#include "config/gimpconfig-utils.h"
28
#include "core/gimpitem.h"
29
#include "core/gimpitemundo.h"
30
#include "core/gimp-utils.h"
33
#include "gimptextlayer.h"
34
#include "gimptextundo.h"
44
static void gimp_text_undo_class_init (GimpTextUndoClass *klass);
46
static GObject * gimp_text_undo_constructor (GType type,
48
GObjectConstructParam *params);
49
static void gimp_text_undo_set_property (GObject *object,
53
static void gimp_text_undo_get_property (GObject *object,
58
static gint64 gimp_text_undo_get_memsize (GimpObject *object,
61
static void gimp_text_undo_pop (GimpUndo *undo,
62
GimpUndoMode undo_mode,
63
GimpUndoAccumulator *accum);
64
static void gimp_text_undo_free (GimpUndo *undo,
65
GimpUndoMode undo_mode);
68
static GimpUndoClass *parent_class = NULL;
72
gimp_text_undo_get_type (void)
74
static GType undo_type = 0;
78
static const GTypeInfo undo_info =
80
sizeof (GimpTextUndoClass),
82
(GBaseFinalizeFunc) NULL,
83
(GClassInitFunc) gimp_text_undo_class_init,
84
NULL, /* class_finalize */
85
NULL, /* class_data */
86
sizeof (GimpTextUndo),
88
NULL /* instance_init */
91
undo_type = g_type_register_static (GIMP_TYPE_ITEM_UNDO, "GimpTextUndo",
99
gimp_text_undo_class_init (GimpTextUndoClass *klass)
101
GObjectClass *object_class = G_OBJECT_CLASS (klass);
102
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
103
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
105
parent_class = g_type_class_peek_parent (klass);
107
object_class->constructor = gimp_text_undo_constructor;
108
object_class->set_property = gimp_text_undo_set_property;
109
object_class->get_property = gimp_text_undo_get_property;
111
gimp_object_class->get_memsize = gimp_text_undo_get_memsize;
113
undo_class->pop = gimp_text_undo_pop;
114
undo_class->free = gimp_text_undo_free;
116
g_object_class_install_property (object_class, PROP_PARAM,
117
g_param_spec_param ("param", NULL, NULL,
120
G_PARAM_CONSTRUCT_ONLY));
124
gimp_text_undo_constructor (GType type,
126
GObjectConstructParam *params)
129
GimpTextUndo *text_undo;
130
GimpTextLayer *layer;
132
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
134
text_undo = GIMP_TEXT_UNDO (object);
136
g_assert (GIMP_IS_TEXT_LAYER (GIMP_ITEM_UNDO (text_undo)->item));
138
layer = GIMP_TEXT_LAYER (GIMP_ITEM_UNDO (text_undo)->item);
140
if (text_undo->pspec)
142
g_assert (text_undo->pspec->owner_type == GIMP_TYPE_TEXT);
144
text_undo->value = g_new0 (GValue, 1);
146
g_value_init (text_undo->value, text_undo->pspec->value_type);
147
g_object_get_property (G_OBJECT (layer->text),
148
text_undo->pspec->name, text_undo->value);
150
else if (layer->text)
152
text_undo->text = gimp_config_duplicate (GIMP_CONFIG (layer->text));
159
gimp_text_undo_set_property (GObject *object,
164
GimpTextUndo *text_undo = GIMP_TEXT_UNDO (object);
169
text_undo->pspec = g_value_get_param (value);
172
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
178
gimp_text_undo_get_property (GObject *object,
183
GimpTextUndo *text_undo = GIMP_TEXT_UNDO (object);
188
g_value_set_param (value, (GParamSpec *) text_undo->pspec);
191
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
197
gimp_text_undo_get_memsize (GimpObject *object,
200
GimpTextUndo *undo = GIMP_TEXT_UNDO (object);
204
memsize += gimp_g_value_get_memsize (undo->value);
207
memsize += gimp_object_get_memsize (GIMP_OBJECT (undo->text), NULL);
209
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
214
gimp_text_undo_pop (GimpUndo *undo,
215
GimpUndoMode undo_mode,
216
GimpUndoAccumulator *accum)
218
GimpTextUndo *text_undo = GIMP_TEXT_UNDO (undo);
219
GimpTextLayer *layer = GIMP_TEXT_LAYER (GIMP_ITEM_UNDO (undo)->item);
221
if (text_undo->pspec)
225
g_return_if_fail (layer->text != NULL);
227
value = g_new0 (GValue, 1);
228
g_value_init (value, text_undo->pspec->value_type);
230
g_object_get_property (G_OBJECT (layer->text),
231
text_undo->pspec->name, value);
233
g_object_set_property (G_OBJECT (layer->text),
234
text_undo->pspec->name, text_undo->value);
236
g_value_unset (text_undo->value);
237
g_free (text_undo->value);
239
text_undo->value = value;
245
text = (layer->text ?
246
gimp_config_duplicate (GIMP_CONFIG (layer->text)) : NULL);
248
if (layer->text && text_undo->text)
249
gimp_config_sync (GIMP_CONFIG (text_undo->text),
250
GIMP_CONFIG (layer->text), 0);
252
gimp_text_layer_set_text (layer, text_undo->text);
255
g_object_unref (text_undo->text);
257
text_undo->text = text;
260
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
264
gimp_text_undo_free (GimpUndo *undo,
265
GimpUndoMode undo_mode)
267
GimpTextUndo *text_undo = GIMP_TEXT_UNDO (undo);
271
g_object_unref (text_undo->text);
272
text_undo->text = NULL;
275
if (text_undo->pspec)
277
g_value_unset (text_undo->value);
278
g_free (text_undo->value);
280
text_undo->value = NULL;
281
text_undo->pspec = NULL;
284
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);