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

« back to all changes in this revision

Viewing changes to app/core/gimpsamplepointundo.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 "gimpimage.h"
 
26
#include "gimpimage-sample-points.h"
 
27
#include "gimpsamplepoint.h"
 
28
#include "gimpsamplepointundo.h"
 
29
 
 
30
 
 
31
enum
 
32
{
 
33
  PROP_0,
 
34
  PROP_SAMPLE_POINT
 
35
};
 
36
 
 
37
 
 
38
static GObject * gimp_sample_point_undo_constructor  (GType                  type,
 
39
                                                      guint                  n_params,
 
40
                                                      GObjectConstructParam *params);
 
41
static void      gimp_sample_point_undo_set_property (GObject               *object,
 
42
                                                      guint                  property_id,
 
43
                                                      const GValue          *value,
 
44
                                                      GParamSpec            *pspec);
 
45
static void      gimp_sample_point_undo_get_property (GObject               *object,
 
46
                                                      guint                  property_id,
 
47
                                                      GValue                *value,
 
48
                                                      GParamSpec            *pspec);
 
49
 
 
50
static void      gimp_sample_point_undo_pop          (GimpUndo              *undo,
 
51
                                                      GimpUndoMode           undo_mode,
 
52
                                                      GimpUndoAccumulator   *accum);
 
53
static void      gimp_sample_point_undo_free         (GimpUndo              *undo,
 
54
                                                      GimpUndoMode           undo_mode);
 
55
 
 
56
 
 
57
G_DEFINE_TYPE (GimpSamplePointUndo, gimp_sample_point_undo, GIMP_TYPE_UNDO)
 
58
 
 
59
#define parent_class gimp_sample_point_undo_parent_class
 
60
 
 
61
 
 
62
static void
 
63
gimp_sample_point_undo_class_init (GimpSamplePointUndoClass *klass)
 
64
{
 
65
  GObjectClass  *object_class = G_OBJECT_CLASS (klass);
 
66
  GimpUndoClass *undo_class   = GIMP_UNDO_CLASS (klass);
 
67
 
 
68
  object_class->constructor  = gimp_sample_point_undo_constructor;
 
69
  object_class->set_property = gimp_sample_point_undo_set_property;
 
70
  object_class->get_property = gimp_sample_point_undo_get_property;
 
71
 
 
72
  undo_class->pop            = gimp_sample_point_undo_pop;
 
73
  undo_class->free           = gimp_sample_point_undo_free;
 
74
 
 
75
  g_object_class_install_property (object_class, PROP_SAMPLE_POINT,
 
76
                                   g_param_spec_boxed ("sample-point", NULL, NULL,
 
77
                                                       GIMP_TYPE_SAMPLE_POINT,
 
78
                                                       GIMP_PARAM_READWRITE |
 
79
                                                       G_PARAM_CONSTRUCT_ONLY));
 
80
}
 
81
 
 
82
static void
 
83
gimp_sample_point_undo_init (GimpSamplePointUndo *undo)
 
84
{
 
85
}
 
86
 
 
87
static GObject *
 
88
gimp_sample_point_undo_constructor (GType                  type,
 
89
                                    guint                  n_params,
 
90
                                    GObjectConstructParam *params)
 
91
{
 
92
  GObject             *object;
 
93
  GimpSamplePointUndo *sample_point_undo;
 
94
 
 
95
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
96
 
 
97
  sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
 
98
 
 
99
  g_assert (sample_point_undo->sample_point != NULL);
 
100
 
 
101
  sample_point_undo->x = sample_point_undo->sample_point->x;
 
102
  sample_point_undo->y = sample_point_undo->sample_point->y;
 
103
 
 
104
  return object;
 
105
}
 
106
 
 
107
static void
 
108
gimp_sample_point_undo_set_property (GObject      *object,
 
109
                                     guint         property_id,
 
110
                                     const GValue *value,
 
111
                                     GParamSpec   *pspec)
 
112
{
 
113
  GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
 
114
 
 
115
  switch (property_id)
 
116
    {
 
117
    case PROP_SAMPLE_POINT:
 
118
      sample_point_undo->sample_point = g_value_dup_boxed (value);
 
119
      break;
 
120
 
 
121
    default:
 
122
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
123
      break;
 
124
    }
 
125
}
 
126
 
 
127
static void
 
128
gimp_sample_point_undo_get_property (GObject    *object,
 
129
                                     guint       property_id,
 
130
                                     GValue     *value,
 
131
                                     GParamSpec *pspec)
 
132
{
 
133
  GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
 
134
 
 
135
  switch (property_id)
 
136
    {
 
137
    case PROP_SAMPLE_POINT:
 
138
      g_value_set_boxed (value, sample_point_undo->sample_point);
 
139
      break;
 
140
 
 
141
    default:
 
142
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
143
      break;
 
144
    }
 
145
}
 
146
 
 
147
static void
 
148
gimp_sample_point_undo_pop (GimpUndo              *undo,
 
149
                            GimpUndoMode           undo_mode,
 
150
                            GimpUndoAccumulator   *accum)
 
151
{
 
152
  GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (undo);
 
153
  gint                 x;
 
154
  gint                 y;
 
155
 
 
156
  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
157
 
 
158
  x = sample_point_undo->sample_point->x;
 
159
  y = sample_point_undo->sample_point->y;
 
160
 
 
161
  /*  add and move sample points manually (nor using the
 
162
   *  gimp_image_sample_point API), because we might be in the middle
 
163
   *  of an image resizing undo group and the sample point's position
 
164
   *  might be temporarily out of image.
 
165
   */
 
166
 
 
167
  if (x == -1)
 
168
    {
 
169
      undo->image->sample_points =
 
170
        g_list_append (undo->image->sample_points,
 
171
                       sample_point_undo->sample_point);
 
172
 
 
173
      sample_point_undo->sample_point->x = sample_point_undo->x;
 
174
      sample_point_undo->sample_point->y = sample_point_undo->y;
 
175
      gimp_sample_point_ref (sample_point_undo->sample_point);
 
176
 
 
177
      gimp_image_sample_point_added (undo->image,
 
178
                                     sample_point_undo->sample_point);
 
179
      gimp_image_update_sample_point (undo->image,
 
180
                                      sample_point_undo->sample_point);
 
181
    }
 
182
  else if (sample_point_undo->x == -1)
 
183
    {
 
184
      gimp_image_remove_sample_point (undo->image,
 
185
                                      sample_point_undo->sample_point, FALSE);
 
186
    }
 
187
  else
 
188
    {
 
189
      gimp_image_update_sample_point (undo->image,
 
190
                                      sample_point_undo->sample_point);
 
191
      sample_point_undo->sample_point->x = sample_point_undo->x;
 
192
      sample_point_undo->sample_point->y = sample_point_undo->y;
 
193
      gimp_image_update_sample_point (undo->image,
 
194
                                      sample_point_undo->sample_point);
 
195
    }
 
196
 
 
197
  sample_point_undo->x = x;
 
198
  sample_point_undo->y = y;
 
199
}
 
200
 
 
201
static void
 
202
gimp_sample_point_undo_free (GimpUndo     *undo,
 
203
                             GimpUndoMode  undo_mode)
 
204
{
 
205
  GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (undo);
 
206
 
 
207
  if (sample_point_undo->sample_point)
 
208
    {
 
209
      gimp_sample_point_unref (sample_point_undo->sample_point);
 
210
      sample_point_undo->sample_point = NULL;
 
211
    }
 
212
 
 
213
  GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
 
214
}