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

« back to all changes in this revision

Viewing changes to app/tools/gimptransformtoolundo.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 <gtk/gtk.h>
 
22
 
 
23
#include "tools-types.h"
 
24
 
 
25
#include "base/tile-manager.h"
 
26
 
 
27
#include "gimptoolcontrol.h"
 
28
#include "gimptransformtool.h"
 
29
#include "gimptransformtoolundo.h"
 
30
 
 
31
 
 
32
enum
 
33
{
 
34
  PROP_0,
 
35
  PROP_TRANSFORM_TOOL
 
36
};
 
37
 
 
38
 
 
39
static GObject * gimp_transform_tool_undo_constructor  (GType                  type,
 
40
                                                        guint                  n_params,
 
41
                                                        GObjectConstructParam *params);
 
42
static void      gimp_transform_tool_undo_set_property (GObject               *object,
 
43
                                                        guint                  property_id,
 
44
                                                        const GValue          *value,
 
45
                                                        GParamSpec            *pspec);
 
46
static void      gimp_transform_tool_undo_get_property (GObject               *object,
 
47
                                                        guint                  property_id,
 
48
                                                        GValue                *value,
 
49
                                                        GParamSpec            *pspec);
 
50
 
 
51
static void      gimp_transform_tool_undo_pop          (GimpUndo              *undo,
 
52
                                                        GimpUndoMode           undo_mode,
 
53
                                                        GimpUndoAccumulator   *accum);
 
54
static void      gimp_transform_tool_undo_free         (GimpUndo              *undo,
 
55
                                                        GimpUndoMode           undo_mode);
 
56
 
 
57
 
 
58
G_DEFINE_TYPE (GimpTransformToolUndo, gimp_transform_tool_undo, GIMP_TYPE_UNDO)
 
59
 
 
60
#define parent_class gimp_transform_tool_undo_parent_class
 
61
 
 
62
 
 
63
static void
 
64
gimp_transform_tool_undo_class_init (GimpTransformToolUndoClass *klass)
 
65
{
 
66
  GObjectClass  *object_class = G_OBJECT_CLASS (klass);
 
67
  GimpUndoClass *undo_class   = GIMP_UNDO_CLASS (klass);
 
68
 
 
69
  object_class->constructor  = gimp_transform_tool_undo_constructor;
 
70
  object_class->set_property = gimp_transform_tool_undo_set_property;
 
71
  object_class->get_property = gimp_transform_tool_undo_get_property;
 
72
 
 
73
  undo_class->pop            = gimp_transform_tool_undo_pop;
 
74
  undo_class->free           = gimp_transform_tool_undo_free;
 
75
 
 
76
  g_object_class_install_property (object_class, PROP_TRANSFORM_TOOL,
 
77
                                   g_param_spec_object ("transform-tool",
 
78
                                                        NULL, NULL,
 
79
                                                        GIMP_TYPE_TRANSFORM_TOOL,
 
80
                                                        GIMP_PARAM_READWRITE |
 
81
                                                        G_PARAM_CONSTRUCT_ONLY));
 
82
}
 
83
 
 
84
static void
 
85
gimp_transform_tool_undo_init (GimpTransformToolUndo *undo)
 
86
{
 
87
}
 
88
 
 
89
static GObject *
 
90
gimp_transform_tool_undo_constructor (GType                  type,
 
91
                                      guint                  n_params,
 
92
                                      GObjectConstructParam *params)
 
93
{
 
94
  GObject               *object;
 
95
  GimpTransformToolUndo *transform_tool_undo;
 
96
  GimpTransformTool     *transform_tool;
 
97
  gint                   i;
 
98
 
 
99
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
100
 
 
101
  transform_tool_undo = GIMP_TRANSFORM_TOOL_UNDO (object);
 
102
 
 
103
  g_assert (GIMP_IS_TRANSFORM_TOOL (transform_tool_undo->transform_tool));
 
104
 
 
105
  transform_tool = GIMP_TRANSFORM_TOOL (transform_tool_undo->transform_tool);
 
106
 
 
107
  for (i = 0; i < TRANS_INFO_SIZE; i++)
 
108
    transform_tool_undo->trans_info[i] = transform_tool->old_trans_info[i];
 
109
 
 
110
#if 0
 
111
  if (transform_tool->original)
 
112
    transform_tool_undo->original = tile_manager_ref (transform_tool->original);
 
113
#endif
 
114
 
 
115
  g_object_add_weak_pointer (G_OBJECT (transform_tool_undo->transform_tool),
 
116
                             (gpointer) &transform_tool_undo->transform_tool);
 
117
 
 
118
  return object;
 
119
}
 
120
 
 
121
static void
 
122
gimp_transform_tool_undo_set_property (GObject      *object,
 
123
                                       guint         property_id,
 
124
                                       const GValue *value,
 
125
                                       GParamSpec   *pspec)
 
126
{
 
127
  GimpTransformToolUndo *transform_tool_undo = GIMP_TRANSFORM_TOOL_UNDO (object);
 
128
 
 
129
  switch (property_id)
 
130
    {
 
131
    case PROP_TRANSFORM_TOOL:
 
132
      transform_tool_undo->transform_tool = g_value_get_object (value);
 
133
      break;
 
134
 
 
135
    default:
 
136
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
137
      break;
 
138
    }
 
139
}
 
140
 
 
141
static void
 
142
gimp_transform_tool_undo_get_property (GObject    *object,
 
143
                                       guint       property_id,
 
144
                                       GValue     *value,
 
145
                                       GParamSpec *pspec)
 
146
{
 
147
  GimpTransformToolUndo *transform_tool_undo = GIMP_TRANSFORM_TOOL_UNDO (object);
 
148
 
 
149
  switch (property_id)
 
150
    {
 
151
    case PROP_TRANSFORM_TOOL:
 
152
      g_value_set_object (value, transform_tool_undo->transform_tool);
 
153
      break;
 
154
 
 
155
    default:
 
156
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
157
      break;
 
158
    }
 
159
}
 
160
 
 
161
static void
 
162
gimp_transform_tool_undo_pop (GimpUndo              *undo,
 
163
                              GimpUndoMode           undo_mode,
 
164
                              GimpUndoAccumulator   *accum)
 
165
{
 
166
  GimpTransformToolUndo *transform_tool_undo = GIMP_TRANSFORM_TOOL_UNDO (undo);
 
167
 
 
168
  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
169
 
 
170
  if (transform_tool_undo->transform_tool)
 
171
    {
 
172
      GimpTransformTool *transform_tool;
 
173
      TileManager       *temp;
 
174
      gdouble            d;
 
175
      gint               i;
 
176
 
 
177
      transform_tool = transform_tool_undo->transform_tool;
 
178
 
 
179
      /*  swap the transformation information arrays  */
 
180
      for (i = 0; i < TRANS_INFO_SIZE; i++)
 
181
        {
 
182
          d = transform_tool_undo->trans_info[i];
 
183
          transform_tool_undo->trans_info[i] = transform_tool->trans_info[i];
 
184
          transform_tool->trans_info[i] = d;
 
185
        }
 
186
 
 
187
      /*  swap the original buffer--the source buffer for repeated transforms
 
188
       */
 
189
      temp                          = transform_tool_undo->original;
 
190
      transform_tool_undo->original = transform_tool->original;
 
191
      transform_tool->original      = temp;
 
192
 
 
193
      /*  If we're re-implementing the first transform, reactivate tool  */
 
194
      if (undo_mode == GIMP_UNDO_MODE_REDO && transform_tool->original)
 
195
        {
 
196
          gimp_tool_control_activate (GIMP_TOOL (transform_tool)->control);
 
197
 
 
198
          gimp_draw_tool_resume (GIMP_DRAW_TOOL (transform_tool));
 
199
        }
 
200
    }
 
201
 }
 
202
 
 
203
static void
 
204
gimp_transform_tool_undo_free (GimpUndo     *undo,
 
205
                               GimpUndoMode  undo_mode)
 
206
{
 
207
  GimpTransformToolUndo *transform_tool_undo = GIMP_TRANSFORM_TOOL_UNDO (undo);
 
208
 
 
209
  if (transform_tool_undo->transform_tool)
 
210
    {
 
211
      g_object_remove_weak_pointer (G_OBJECT (transform_tool_undo->transform_tool),
 
212
                                    (gpointer) &transform_tool_undo->transform_tool);
 
213
      transform_tool_undo->transform_tool = NULL;
 
214
    }
 
215
 
 
216
  if (transform_tool_undo->original)
 
217
    {
 
218
      tile_manager_unref (transform_tool_undo->original);
 
219
      transform_tool_undo->original = NULL;
 
220
    }
 
221
 
 
222
  GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
 
223
}