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

« back to all changes in this revision

Viewing changes to app/core/gimplayerundo.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 "core-types.h"
 
24
 
 
25
#include "gimpcontainer.h"
 
26
#include "gimpimage.h"
 
27
#include "gimplayer.h"
 
28
#include "gimplayer-floating-sel.h"
 
29
#include "gimplayerundo.h"
 
30
 
 
31
 
 
32
enum
 
33
{
 
34
  PROP_0,
 
35
  PROP_PREV_POSITION,
 
36
  PROP_PREV_LAYER
 
37
};
 
38
 
 
39
 
 
40
static GObject * gimp_layer_undo_constructor  (GType                  type,
 
41
                                               guint                  n_params,
 
42
                                               GObjectConstructParam *params);
 
43
static void      gimp_layer_undo_set_property (GObject               *object,
 
44
                                               guint                  property_id,
 
45
                                               const GValue          *value,
 
46
                                               GParamSpec            *pspec);
 
47
static void      gimp_layer_undo_get_property (GObject               *object,
 
48
                                               guint                  property_id,
 
49
                                               GValue                *value,
 
50
                                               GParamSpec            *pspec);
 
51
 
 
52
static gint64    gimp_layer_undo_get_memsize  (GimpObject            *object,
 
53
                                               gint64                *gui_size);
 
54
 
 
55
static void      gimp_layer_undo_pop          (GimpUndo              *undo,
 
56
                                               GimpUndoMode           undo_mode,
 
57
                                               GimpUndoAccumulator   *accum);
 
58
 
 
59
 
 
60
G_DEFINE_TYPE (GimpLayerUndo, gimp_layer_undo, GIMP_TYPE_ITEM_UNDO)
 
61
 
 
62
#define parent_class gimp_layer_undo_parent_class
 
63
 
 
64
 
 
65
static void
 
66
gimp_layer_undo_class_init (GimpLayerUndoClass *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_layer_undo_constructor;
 
73
  object_class->set_property     = gimp_layer_undo_set_property;
 
74
  object_class->get_property     = gimp_layer_undo_get_property;
 
75
 
 
76
  gimp_object_class->get_memsize = gimp_layer_undo_get_memsize;
 
77
 
 
78
  undo_class->pop                = gimp_layer_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_LAYER,
 
87
                                   g_param_spec_object ("prev-layer", NULL, NULL,
 
88
                                                        GIMP_TYPE_LAYER,
 
89
                                                        GIMP_PARAM_READWRITE |
 
90
                                                        G_PARAM_CONSTRUCT_ONLY));
 
91
}
 
92
 
 
93
static void
 
94
gimp_layer_undo_init (GimpLayerUndo *undo)
 
95
{
 
96
}
 
97
 
 
98
static GObject *
 
99
gimp_layer_undo_constructor (GType                  type,
 
100
                             guint                  n_params,
 
101
                             GObjectConstructParam *params)
 
102
{
 
103
  GObject       *object;
 
104
  GimpLayerUndo *layer_undo;
 
105
 
 
106
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
107
 
 
108
  layer_undo = GIMP_LAYER_UNDO (object);
 
109
 
 
110
  g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
 
111
 
 
112
  return object;
 
113
}
 
114
 
 
115
static void
 
116
gimp_layer_undo_set_property (GObject      *object,
 
117
                              guint         property_id,
 
118
                              const GValue *value,
 
119
                              GParamSpec   *pspec)
 
120
{
 
121
  GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (object);
 
122
 
 
123
  switch (property_id)
 
124
    {
 
125
    case PROP_PREV_POSITION:
 
126
      layer_undo->prev_position = g_value_get_int (value);
 
127
      break;
 
128
    case PROP_PREV_LAYER:
 
129
      layer_undo->prev_layer = 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_layer_undo_get_property (GObject    *object,
 
140
                              guint       property_id,
 
141
                              GValue     *value,
 
142
                              GParamSpec *pspec)
 
143
{
 
144
  GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (object);
 
145
 
 
146
  switch (property_id)
 
147
    {
 
148
    case PROP_PREV_POSITION:
 
149
      g_value_set_int (value, layer_undo->prev_position);
 
150
      break;
 
151
    case PROP_PREV_LAYER:
 
152
      g_value_set_object (value, layer_undo->prev_layer);
 
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_layer_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_layer_undo_pop (GimpUndo            *undo,
 
178
                     GimpUndoMode         undo_mode,
 
179
                     GimpUndoAccumulator *accum)
 
180
{
 
181
  GimpLayerUndo *layer_undo = GIMP_LAYER_UNDO (undo);
 
182
  GimpLayer     *layer      = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
 
183
  gboolean       old_has_alpha;
 
184
 
 
185
  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
186
 
 
187
  old_has_alpha = gimp_image_has_alpha (undo->image);
 
188
 
 
189
  if ((undo_mode       == GIMP_UNDO_MODE_UNDO &&
 
190
       undo->undo_type == GIMP_UNDO_LAYER_ADD) ||
 
191
      (undo_mode       == GIMP_UNDO_MODE_REDO &&
 
192
       undo->undo_type == GIMP_UNDO_LAYER_REMOVE))
 
193
    {
 
194
      /*  remove layer  */
 
195
 
 
196
      /*  record the current position  */
 
197
      layer_undo->prev_position = gimp_image_get_layer_index (undo->image,
 
198
                                                              layer);
 
199
 
 
200
      gimp_container_remove (undo->image->layers, GIMP_OBJECT (layer));
 
201
      undo->image->layer_stack = g_slist_remove (undo->image->layer_stack,
 
202
                                                 layer);
 
203
 
 
204
      if (gimp_layer_is_floating_sel (layer))
 
205
        {
 
206
          /*  invalidate the boundary *before* setting the
 
207
           *  floating_sel pointer to NULL because the selection's
 
208
           *  outline is affected by the floating_sel and won't be
 
209
           *  completely cleared otherwise (bug #160247).
 
210
           */
 
211
          gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer));
 
212
 
 
213
          undo->image->floating_sel = NULL;
 
214
 
 
215
          /*  activate the underlying drawable  */
 
216
          floating_sel_activate_drawable (layer);
 
217
 
 
218
          gimp_image_floating_selection_changed (undo->image);
 
219
        }
 
220
      else if (layer == gimp_image_get_active_layer (undo->image))
 
221
        {
 
222
          if (layer_undo->prev_layer)
 
223
            {
 
224
              gimp_image_set_active_layer (undo->image, layer_undo->prev_layer);
 
225
            }
 
226
          else if (undo->image->layer_stack)
 
227
            {
 
228
              gimp_image_set_active_layer (undo->image,
 
229
                                           undo->image->layer_stack->data);
 
230
            }
 
231
          else
 
232
            {
 
233
              gimp_image_set_active_layer (undo->image, NULL);
 
234
            }
 
235
        }
 
236
 
 
237
      gimp_item_removed (GIMP_ITEM (layer));
 
238
    }
 
239
  else
 
240
    {
 
241
      /*  restore layer  */
 
242
 
 
243
      /*  record the active layer  */
 
244
      layer_undo->prev_layer = gimp_image_get_active_layer (undo->image);
 
245
 
 
246
      /*  if this is a floating selection, set the fs pointer  */
 
247
      if (gimp_layer_is_floating_sel (layer))
 
248
        undo->image->floating_sel = layer;
 
249
 
 
250
      gimp_container_insert (undo->image->layers,
 
251
                             GIMP_OBJECT (layer), layer_undo->prev_position);
 
252
      gimp_image_set_active_layer (undo->image, layer);
 
253
 
 
254
      if (gimp_layer_is_floating_sel (layer))
 
255
        gimp_image_floating_selection_changed (undo->image);
 
256
 
 
257
      GIMP_ITEM (layer)->removed = FALSE;
 
258
 
 
259
      if (layer->mask)
 
260
        GIMP_ITEM (layer->mask)->removed = FALSE;
 
261
    }
 
262
 
 
263
  if (old_has_alpha != gimp_image_has_alpha (undo->image))
 
264
    accum->alpha_changed = TRUE;
 
265
}