~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/vectors/gimpvectorsundo.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <glib-object.h>
 
22
 
 
23
#include "vectors-types.h"
 
24
 
 
25
#include "core/gimpcontainer.h"
 
26
#include "core/gimpimage.h"
 
27
 
 
28
#include "gimpvectors.h"
 
29
#include "gimpvectorsundo.h"
 
30
 
 
31
 
 
32
enum
 
33
{
 
34
  PROP_0,
 
35
  PROP_PREV_POSITION,
 
36
  PROP_PREV_VECTORS
 
37
};
 
38
 
 
39
 
 
40
static GObject * gimp_vectors_undo_constructor  (GType                  type,
 
41
                                                 guint                  n_params,
 
42
                                                 GObjectConstructParam *params);
 
43
static void      gimp_vectors_undo_set_property (GObject               *object,
 
44
                                                 guint                  property_id,
 
45
                                                 const GValue          *value,
 
46
                                                 GParamSpec            *pspec);
 
47
static void      gimp_vectors_undo_get_property (GObject               *object,
 
48
                                                 guint                  property_id,
 
49
                                                 GValue                *value,
 
50
                                                 GParamSpec            *pspec);
 
51
 
 
52
static gint64    gimp_vectors_undo_get_memsize  (GimpObject            *object,
 
53
                                                 gint64                *gui_size);
 
54
 
 
55
static void      gimp_vectors_undo_pop          (GimpUndo              *undo,
 
56
                                                 GimpUndoMode           undo_mode,
 
57
                                                 GimpUndoAccumulator   *accum);
 
58
 
 
59
 
 
60
G_DEFINE_TYPE (GimpVectorsUndo, gimp_vectors_undo, GIMP_TYPE_ITEM_UNDO)
 
61
 
 
62
#define parent_class gimp_vectors_undo_parent_class
 
63
 
 
64
 
 
65
static void
 
66
gimp_vectors_undo_class_init (GimpVectorsUndoClass *klass)
 
67
{
 
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);
 
71
 
 
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;
 
75
 
 
76
  gimp_object_class->get_memsize = gimp_vectors_undo_get_memsize;
 
77
 
 
78
  undo_class->pop                = gimp_vectors_undo_pop;
 
79
 
 
80
  g_object_class_install_property (object_class, PROP_PREV_POSITION,
 
81
                                   g_param_spec_int ("prev-position", NULL, NULL,
 
82
                                                     0, G_MAXINT, 0,
 
83
                                                     GIMP_PARAM_READWRITE |
 
84
                                                     G_PARAM_CONSTRUCT_ONLY));
 
85
 
 
86
  g_object_class_install_property (object_class, PROP_PREV_VECTORS,
 
87
                                   g_param_spec_object ("prev-vectors", NULL, NULL,
 
88
                                                        GIMP_TYPE_VECTORS,
 
89
                                                        GIMP_PARAM_READWRITE |
 
90
                                                        G_PARAM_CONSTRUCT_ONLY));
 
91
}
 
92
 
 
93
static void
 
94
gimp_vectors_undo_init (GimpVectorsUndo *undo)
 
95
{
 
96
}
 
97
 
 
98
static GObject *
 
99
gimp_vectors_undo_constructor (GType                  type,
 
100
                               guint                  n_params,
 
101
                               GObjectConstructParam *params)
 
102
{
 
103
  GObject       *object;
 
104
  GimpVectorsUndo *vectors_undo;
 
105
 
 
106
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
107
 
 
108
  vectors_undo = GIMP_VECTORS_UNDO (object);
 
109
 
 
110
  g_assert (GIMP_IS_VECTORS (GIMP_ITEM_UNDO (object)->item));
 
111
 
 
112
  return object;
 
113
}
 
114
 
 
115
static void
 
116
gimp_vectors_undo_set_property (GObject      *object,
 
117
                                guint         property_id,
 
118
                                const GValue *value,
 
119
                                GParamSpec   *pspec)
 
120
{
 
121
  GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (object);
 
122
 
 
123
  switch (property_id)
 
124
    {
 
125
    case PROP_PREV_POSITION:
 
126
      vectors_undo->prev_position = g_value_get_int (value);
 
127
      break;
 
128
    case PROP_PREV_VECTORS:
 
129
      vectors_undo->prev_vectors = g_value_get_object (value);
 
130
      break;
 
131
 
 
132
    default:
 
133
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
134
      break;
 
135
    }
 
136
}
 
137
 
 
138
static void
 
139
gimp_vectors_undo_get_property (GObject    *object,
 
140
                                guint       property_id,
 
141
                                GValue     *value,
 
142
                                GParamSpec *pspec)
 
143
{
 
144
  GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (object);
 
145
 
 
146
  switch (property_id)
 
147
    {
 
148
    case PROP_PREV_POSITION:
 
149
      g_value_set_int (value, vectors_undo->prev_position);
 
150
      break;
 
151
    case PROP_PREV_VECTORS:
 
152
      g_value_set_object (value, vectors_undo->prev_vectors);
 
153
      break;
 
154
 
 
155
    default:
 
156
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
157
      break;
 
158
    }
 
159
}
 
160
 
 
161
static gint64
 
162
gimp_vectors_undo_get_memsize (GimpObject *object,
 
163
                               gint64     *gui_size)
 
164
{
 
165
  GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
 
166
  gint64        memsize   = 0;
 
167
 
 
168
  if (! gimp_item_is_attached (item_undo->item))
 
169
    memsize += gimp_object_get_memsize (GIMP_OBJECT (item_undo->item),
 
170
                                        gui_size);
 
171
 
 
172
  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
 
173
                                                                  gui_size);
 
174
}
 
175
 
 
176
static void
 
177
gimp_vectors_undo_pop (GimpUndo            *undo,
 
178
                       GimpUndoMode         undo_mode,
 
179
                       GimpUndoAccumulator *accum)
 
180
{
 
181
  GimpVectorsUndo *vectors_undo = GIMP_VECTORS_UNDO (undo);
 
182
  GimpVectors     *vectors      = GIMP_VECTORS (GIMP_ITEM_UNDO (undo)->item);
 
183
 
 
184
  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
185
 
 
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))
 
190
    {
 
191
      /*  remove vectors  */
 
192
 
 
193
      /*  record the current position  */
 
194
      vectors_undo->prev_position = gimp_image_get_vectors_index (undo->image,
 
195
                                                                  vectors);
 
196
 
 
197
      gimp_container_remove (undo->image->vectors, GIMP_OBJECT (vectors));
 
198
      gimp_item_removed (GIMP_ITEM (vectors));
 
199
 
 
200
      if (vectors == gimp_image_get_active_vectors (undo->image))
 
201
        gimp_image_set_active_vectors (undo->image,
 
202
                                       vectors_undo->prev_vectors);
 
203
    }
 
204
  else
 
205
    {
 
206
      /*  restore vectors  */
 
207
 
 
208
      /*  record the active vectors  */
 
209
      vectors_undo->prev_vectors = gimp_image_get_active_vectors (undo->image);
 
210
 
 
211
      gimp_container_insert (undo->image->vectors, GIMP_OBJECT (vectors),
 
212
                             vectors_undo->prev_position);
 
213
      gimp_image_set_active_vectors (undo->image, vectors);
 
214
 
 
215
      GIMP_ITEM (vectors)->removed = FALSE;
 
216
    }
 
217
}