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

« back to all changes in this revision

Viewing changes to app/core/gimpchannelundo.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 "gimpchannel.h"
 
28
#include "gimpchannelundo.h"
 
29
 
 
30
 
 
31
enum
 
32
{
 
33
  PROP_0,
 
34
  PROP_PREV_POSITION,
 
35
  PROP_PREV_CHANNEL
 
36
};
 
37
 
 
38
 
 
39
static GObject * gimp_channel_undo_constructor  (GType                  type,
 
40
                                                 guint                  n_params,
 
41
                                                 GObjectConstructParam *params);
 
42
static void      gimp_channel_undo_set_property (GObject               *object,
 
43
                                                 guint                  property_id,
 
44
                                                 const GValue          *value,
 
45
                                                 GParamSpec            *pspec);
 
46
static void      gimp_channel_undo_get_property (GObject               *object,
 
47
                                                 guint                  property_id,
 
48
                                                 GValue                *value,
 
49
                                                 GParamSpec            *pspec);
 
50
 
 
51
static gint64    gimp_channel_undo_get_memsize  (GimpObject            *object,
 
52
                                                 gint64                *gui_size);
 
53
 
 
54
static void      gimp_channel_undo_pop          (GimpUndo              *undo,
 
55
                                                 GimpUndoMode           undo_mode,
 
56
                                                 GimpUndoAccumulator   *accum);
 
57
 
 
58
 
 
59
G_DEFINE_TYPE (GimpChannelUndo, gimp_channel_undo, GIMP_TYPE_ITEM_UNDO)
 
60
 
 
61
#define parent_class gimp_channel_undo_parent_class
 
62
 
 
63
 
 
64
static void
 
65
gimp_channel_undo_class_init (GimpChannelUndoClass *klass)
 
66
{
 
67
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
 
68
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
 
69
  GimpUndoClass   *undo_class        = GIMP_UNDO_CLASS (klass);
 
70
 
 
71
  object_class->constructor      = gimp_channel_undo_constructor;
 
72
  object_class->set_property     = gimp_channel_undo_set_property;
 
73
  object_class->get_property     = gimp_channel_undo_get_property;
 
74
 
 
75
  gimp_object_class->get_memsize = gimp_channel_undo_get_memsize;
 
76
 
 
77
  undo_class->pop                = gimp_channel_undo_pop;
 
78
 
 
79
  g_object_class_install_property (object_class, PROP_PREV_POSITION,
 
80
                                   g_param_spec_int ("prev-position", NULL, NULL,
 
81
                                                     0, G_MAXINT, 0,
 
82
                                                     GIMP_PARAM_READWRITE |
 
83
                                                     G_PARAM_CONSTRUCT_ONLY));
 
84
 
 
85
  g_object_class_install_property (object_class, PROP_PREV_CHANNEL,
 
86
                                   g_param_spec_object ("prev-channel", NULL, NULL,
 
87
                                                        GIMP_TYPE_CHANNEL,
 
88
                                                        GIMP_PARAM_READWRITE |
 
89
                                                        G_PARAM_CONSTRUCT_ONLY));
 
90
}
 
91
 
 
92
static void
 
93
gimp_channel_undo_init (GimpChannelUndo *undo)
 
94
{
 
95
}
 
96
 
 
97
static GObject *
 
98
gimp_channel_undo_constructor (GType                  type,
 
99
                               guint                  n_params,
 
100
                               GObjectConstructParam *params)
 
101
{
 
102
  GObject       *object;
 
103
  GimpChannelUndo *channel_undo;
 
104
 
 
105
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
106
 
 
107
  channel_undo = GIMP_CHANNEL_UNDO (object);
 
108
 
 
109
  g_assert (GIMP_IS_CHANNEL (GIMP_ITEM_UNDO (object)->item));
 
110
 
 
111
  return object;
 
112
}
 
113
 
 
114
static void
 
115
gimp_channel_undo_set_property (GObject      *object,
 
116
                                guint         property_id,
 
117
                                const GValue *value,
 
118
                                GParamSpec   *pspec)
 
119
{
 
120
  GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
 
121
 
 
122
  switch (property_id)
 
123
    {
 
124
    case PROP_PREV_POSITION:
 
125
      channel_undo->prev_position = g_value_get_int (value);
 
126
      break;
 
127
    case PROP_PREV_CHANNEL:
 
128
      channel_undo->prev_channel = g_value_get_object (value);
 
129
      break;
 
130
 
 
131
    default:
 
132
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
133
      break;
 
134
    }
 
135
}
 
136
 
 
137
static void
 
138
gimp_channel_undo_get_property (GObject    *object,
 
139
                                guint       property_id,
 
140
                                GValue     *value,
 
141
                                GParamSpec *pspec)
 
142
{
 
143
  GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
 
144
 
 
145
  switch (property_id)
 
146
    {
 
147
    case PROP_PREV_POSITION:
 
148
      g_value_set_int (value, channel_undo->prev_position);
 
149
      break;
 
150
    case PROP_PREV_CHANNEL:
 
151
      g_value_set_object (value, channel_undo->prev_channel);
 
152
      break;
 
153
 
 
154
    default:
 
155
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
156
      break;
 
157
    }
 
158
}
 
159
 
 
160
static gint64
 
161
gimp_channel_undo_get_memsize (GimpObject *object,
 
162
                               gint64     *gui_size)
 
163
{
 
164
  GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
 
165
  gint64        memsize   = 0;
 
166
 
 
167
  if (! gimp_item_is_attached (item_undo->item))
 
168
    memsize += gimp_object_get_memsize (GIMP_OBJECT (item_undo->item),
 
169
                                        gui_size);
 
170
 
 
171
  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
 
172
                                                                  gui_size);
 
173
}
 
174
 
 
175
static void
 
176
gimp_channel_undo_pop (GimpUndo            *undo,
 
177
                       GimpUndoMode         undo_mode,
 
178
                       GimpUndoAccumulator *accum)
 
179
{
 
180
  GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (undo);
 
181
  GimpChannel     *channel      = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
 
182
 
 
183
  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
184
 
 
185
  if ((undo_mode       == GIMP_UNDO_MODE_UNDO &&
 
186
       undo->undo_type == GIMP_UNDO_CHANNEL_ADD) ||
 
187
      (undo_mode       == GIMP_UNDO_MODE_REDO &&
 
188
       undo->undo_type == GIMP_UNDO_CHANNEL_REMOVE))
 
189
    {
 
190
      /*  remove channel  */
 
191
 
 
192
      /*  record the current position  */
 
193
      channel_undo->prev_position = gimp_image_get_channel_index (undo->image,
 
194
                                                                  channel);
 
195
 
 
196
      gimp_container_remove (undo->image->channels, GIMP_OBJECT (channel));
 
197
      gimp_item_removed (GIMP_ITEM (channel));
 
198
 
 
199
      if (channel == gimp_image_get_active_channel (undo->image))
 
200
        {
 
201
          if (channel_undo->prev_channel)
 
202
            gimp_image_set_active_channel (undo->image,
 
203
                                           channel_undo->prev_channel);
 
204
          else
 
205
            gimp_image_unset_active_channel (undo->image);
 
206
        }
 
207
    }
 
208
  else
 
209
    {
 
210
      /*  restore channel  */
 
211
 
 
212
      /*  record the active channel  */
 
213
      channel_undo->prev_channel = gimp_image_get_active_channel (undo->image);
 
214
 
 
215
      gimp_container_insert (undo->image->channels, GIMP_OBJECT (channel),
 
216
                             channel_undo->prev_position);
 
217
      gimp_image_set_active_channel (undo->image, channel);
 
218
 
 
219
      GIMP_ITEM (channel)->removed = FALSE;
 
220
    }
 
221
}