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

« back to all changes in this revision

Viewing changes to app/widgets/gimpdrawabletreeview.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimpdrawabletreeview.c
26
26
#include "widgets-types.h"
27
27
 
28
28
#include "core/gimp.h"
29
 
#include "core/gimpcontainer.h"
30
29
#include "core/gimpcontext.h"
31
30
#include "core/gimpdrawable.h"
32
31
#include "core/gimpdrawable-bucket-fill.h"
42
41
#include "gimp-intl.h"
43
42
 
44
43
 
45
 
static void   gimp_drawable_tree_view_class_init (GimpDrawableTreeViewClass *klass);
46
 
static void   gimp_drawable_tree_view_init       (GimpDrawableTreeView      *view);
47
 
 
48
 
static void   gimp_drawable_tree_view_view_iface_init (GimpContainerViewInterface *view_iface);
 
44
static void   gimp_drawable_tree_view_view_iface_init (GimpContainerViewInterface *iface);
49
45
 
50
46
static GObject * gimp_drawable_tree_view_constructor (GType             type,
51
47
                                                      guint             n_params,
52
48
                                                      GObjectConstructParam *params);
53
49
 
54
50
static gboolean gimp_drawable_tree_view_select_item (GimpContainerView *view,
55
 
                                                     GimpViewable      *item,
56
 
                                                     gpointer           insert_data);
 
51
                                                     GimpViewable      *item,
 
52
                                                     gpointer           insert_data);
 
53
 
 
54
static gboolean gimp_drawable_tree_view_drop_possible(GimpContainerTreeView *view,
 
55
                                                      GimpDndType          src_type,
 
56
                                                      GimpViewable        *src_viewable,
 
57
                                                      GimpViewable        *dest_viewable,
 
58
                                                      GtkTreeViewDropPosition  drop_pos,
 
59
                                                      GtkTreeViewDropPosition *return_drop_pos,
 
60
                                                      GdkDragAction       *return_drag_action);
 
61
static void   gimp_drawable_tree_view_drop_viewable (GimpContainerTreeView *view,
 
62
                                                     GimpViewable     *src_viewable,
 
63
                                                     GimpViewable     *dest_viewable,
 
64
                                                     GtkTreeViewDropPosition  drop_pos);
 
65
static void   gimp_drawable_tree_view_drop_color (GimpContainerTreeView *view,
 
66
                                                  const GimpRGB       *color,
 
67
                                                  GimpViewable        *dest_viewable,
 
68
                                                  GtkTreeViewDropPosition  drop_pos);
57
69
 
58
70
static void   gimp_drawable_tree_view_set_image  (GimpItemTreeView     *view,
59
 
                                                  GimpImage            *gimage);
 
71
                                                  GimpImage            *image);
60
72
 
61
73
static void   gimp_drawable_tree_view_floating_selection_changed
62
 
                                                 (GimpImage            *gimage,
 
74
                                                 (GimpImage            *image,
63
75
                                                  GimpDrawableTreeView *view);
64
76
 
65
77
static void   gimp_drawable_tree_view_new_pattern_dropped
66
78
                                                 (GtkWidget            *widget,
 
79
                                                  gint                  x,
 
80
                                                  gint                  y,
67
81
                                                  GimpViewable         *viewable,
68
82
                                                  gpointer              data);
69
83
static void   gimp_drawable_tree_view_new_color_dropped
70
84
                                                 (GtkWidget            *widget,
 
85
                                                  gint                  x,
 
86
                                                  gint                  y,
71
87
                                                  const GimpRGB        *color,
72
88
                                                  gpointer              data);
73
89
 
74
90
 
75
 
static GimpItemTreeViewClass      *parent_class      = NULL;
 
91
G_DEFINE_TYPE_WITH_CODE (GimpDrawableTreeView, gimp_drawable_tree_view,
 
92
                         GIMP_TYPE_ITEM_TREE_VIEW,
 
93
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
 
94
                                                gimp_drawable_tree_view_view_iface_init))
 
95
 
 
96
#define parent_class gimp_drawable_tree_view_parent_class
 
97
 
76
98
static GimpContainerViewInterface *parent_view_iface = NULL;
77
99
 
78
100
 
79
 
GType
80
 
gimp_drawable_tree_view_get_type (void)
81
 
{
82
 
  static GType view_type = 0;
83
 
 
84
 
  if (! view_type)
85
 
    {
86
 
      static const GTypeInfo view_info =
87
 
      {
88
 
        sizeof (GimpDrawableTreeViewClass),
89
 
        NULL,           /* base_init */
90
 
        NULL,           /* base_finalize */
91
 
        (GClassInitFunc) gimp_drawable_tree_view_class_init,
92
 
        NULL,           /* class_finalize */
93
 
        NULL,           /* class_data */
94
 
        sizeof (GimpDrawableTreeView),
95
 
        0,              /* n_preallocs */
96
 
        (GInstanceInitFunc) gimp_drawable_tree_view_init,
97
 
      };
98
 
 
99
 
      static const GInterfaceInfo view_iface_info =
100
 
      {
101
 
        (GInterfaceInitFunc) gimp_drawable_tree_view_view_iface_init,
102
 
        NULL,           /* iface_finalize */
103
 
        NULL            /* iface_data     */
104
 
      };
105
 
 
106
 
      view_type = g_type_register_static (GIMP_TYPE_ITEM_TREE_VIEW,
107
 
                                          "GimpDrawableTreeView",
108
 
                                          &view_info, G_TYPE_FLAG_ABSTRACT);
109
 
 
110
 
      g_type_add_interface_static (view_type, GIMP_TYPE_CONTAINER_VIEW,
111
 
                                   &view_iface_info);
112
 
    }
113
 
 
114
 
  return view_type;
115
 
}
116
 
 
117
101
static void
118
102
gimp_drawable_tree_view_class_init (GimpDrawableTreeViewClass *klass)
119
103
{
120
 
  GObjectClass          *object_class    = G_OBJECT_CLASS (klass);
121
 
  GimpItemTreeViewClass *item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
122
 
 
123
 
  parent_class = g_type_class_peek_parent (klass);
124
 
 
125
 
  object_class->constructor  = gimp_drawable_tree_view_constructor;
126
 
 
127
 
  item_view_class->set_image = gimp_drawable_tree_view_set_image;
 
104
  GObjectClass               *object_class;
 
105
  GimpContainerTreeViewClass *tree_view_class;
 
106
  GimpItemTreeViewClass      *item_view_class;
 
107
 
 
108
  object_class    = G_OBJECT_CLASS (klass);
 
109
  tree_view_class = GIMP_CONTAINER_TREE_VIEW_CLASS (klass);
 
110
  item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
 
111
 
 
112
  object_class->constructor      = gimp_drawable_tree_view_constructor;
 
113
 
 
114
  tree_view_class->drop_possible = gimp_drawable_tree_view_drop_possible;
 
115
  tree_view_class->drop_viewable = gimp_drawable_tree_view_drop_viewable;
 
116
  tree_view_class->drop_color    = gimp_drawable_tree_view_drop_color;
 
117
 
 
118
  item_view_class->set_image     = gimp_drawable_tree_view_set_image;
 
119
}
 
120
 
 
121
static void
 
122
gimp_drawable_tree_view_view_iface_init (GimpContainerViewInterface *iface)
 
123
{
 
124
  parent_view_iface = g_type_interface_peek_parent (iface);
 
125
 
 
126
  iface->select_item = gimp_drawable_tree_view_select_item;
128
127
}
129
128
 
130
129
static void
137
136
                                     guint                  n_params,
138
137
                                     GObjectConstructParam *params)
139
138
{
140
 
  GimpItemTreeView *item_view;
141
 
  GObject          *object;
 
139
  GimpContainerTreeView *tree_view;
 
140
  GimpItemTreeView      *item_view;
 
141
  GObject               *object;
142
142
 
143
143
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
144
144
 
 
145
  tree_view = GIMP_CONTAINER_TREE_VIEW (object);
145
146
  item_view = GIMP_ITEM_TREE_VIEW (object);
146
147
 
147
148
  gimp_dnd_viewable_dest_add (item_view->new_button, GIMP_TYPE_PATTERN,
148
 
                              gimp_drawable_tree_view_new_pattern_dropped,
 
149
                              gimp_drawable_tree_view_new_pattern_dropped,
149
150
                              item_view);
150
151
  gimp_dnd_color_dest_add (item_view->new_button,
151
152
                           gimp_drawable_tree_view_new_color_dropped,
152
153
                           item_view);
153
154
 
 
155
  gimp_dnd_color_dest_add    (GTK_WIDGET (tree_view->view),
 
156
                              NULL, tree_view);
 
157
  gimp_dnd_viewable_dest_add (GTK_WIDGET (tree_view->view), GIMP_TYPE_PATTERN,
 
158
                              NULL, tree_view);
 
159
 
154
160
  return object;
155
161
}
156
162
 
157
 
static void
158
 
gimp_drawable_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
159
 
{
160
 
  parent_view_iface = g_type_interface_peek_parent (view_iface);
161
 
 
162
 
  view_iface->select_item = gimp_drawable_tree_view_select_item;
163
 
}
164
 
 
165
163
 
166
164
/*  GimpContainerView methods  */
167
165
 
173
171
  GimpItemTreeView *item_view = GIMP_ITEM_TREE_VIEW (view);
174
172
  gboolean          success   = TRUE;
175
173
 
176
 
  if (item_view->gimage)
 
174
  if (item_view->image)
177
175
    {
178
 
      GimpViewable *floating_sel;
179
 
 
180
 
      floating_sel = (GimpViewable *)
181
 
        gimp_image_floating_sel (item_view->gimage);
182
 
 
183
 
      success = (item == NULL || floating_sel == NULL || item == floating_sel);
 
176
      GimpLayer *floating_sel = gimp_image_floating_sel (item_view->image);
 
177
 
 
178
      success = (item         == NULL ||
 
179
                 floating_sel == NULL ||
 
180
                 item         == GIMP_VIEWABLE (floating_sel));
184
181
    }
185
182
 
186
183
  if (success)
187
 
    return parent_view_iface->select_item (view, item, insert_data);
 
184
    success = parent_view_iface->select_item (view, item, insert_data);
188
185
 
189
186
  return success;
190
187
}
191
188
 
192
189
 
 
190
/*  GimpContainerTreeView methods  */
 
191
 
 
192
static gboolean
 
193
gimp_drawable_tree_view_drop_possible (GimpContainerTreeView   *tree_view,
 
194
                                       GimpDndType              src_type,
 
195
                                       GimpViewable            *src_viewable,
 
196
                                       GimpViewable            *dest_viewable,
 
197
                                       GtkTreeViewDropPosition  drop_pos,
 
198
                                       GtkTreeViewDropPosition *return_drop_pos,
 
199
                                       GdkDragAction           *return_drag_action)
 
200
{
 
201
  if (GIMP_CONTAINER_TREE_VIEW_CLASS (parent_class)->drop_possible (tree_view,
 
202
                                                                    src_type,
 
203
                                                                    src_viewable,
 
204
                                                                    dest_viewable,
 
205
                                                                    drop_pos,
 
206
                                                                    return_drop_pos,
 
207
                                                                    return_drag_action))
 
208
    {
 
209
      if (src_type == GIMP_DND_TYPE_COLOR ||
 
210
          src_type == GIMP_DND_TYPE_PATTERN)
 
211
        {
 
212
          if (! dest_viewable)
 
213
            return FALSE;
 
214
 
 
215
          if (return_drop_pos)
 
216
            {
 
217
              if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE)
 
218
                *return_drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
 
219
              else
 
220
                *return_drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER;
 
221
            }
 
222
        }
 
223
 
 
224
      return TRUE;
 
225
    }
 
226
 
 
227
  return FALSE;
 
228
}
 
229
 
 
230
static void
 
231
gimp_drawable_tree_view_drop_viewable (GimpContainerTreeView   *view,
 
232
                                       GimpViewable            *src_viewable,
 
233
                                       GimpViewable            *dest_viewable,
 
234
                                       GtkTreeViewDropPosition  drop_pos)
 
235
{
 
236
  if (dest_viewable && GIMP_IS_PATTERN (src_viewable))
 
237
    {
 
238
      gimp_drawable_bucket_fill_full (GIMP_DRAWABLE (dest_viewable),
 
239
                                      GIMP_PATTERN_BUCKET_FILL,
 
240
                                      GIMP_NORMAL_MODE, GIMP_OPACITY_OPAQUE,
 
241
                                      FALSE,             /* no seed fill */
 
242
                                      FALSE,             /* don't fill transp */
 
243
                                      GIMP_SELECT_CRITERION_COMPOSITE,
 
244
                                      0.0, FALSE,        /* fill params  */
 
245
                                      0.0, 0.0,          /* ignored      */
 
246
                                      NULL, GIMP_PATTERN (src_viewable));
 
247
      gimp_image_flush (GIMP_ITEM_TREE_VIEW (view)->image);
 
248
      return;
 
249
    }
 
250
 
 
251
  GIMP_CONTAINER_TREE_VIEW_CLASS (parent_class)->drop_viewable (view,
 
252
                                                                src_viewable,
 
253
                                                                dest_viewable,
 
254
                                                                drop_pos);
 
255
}
 
256
 
 
257
static void
 
258
gimp_drawable_tree_view_drop_color (GimpContainerTreeView   *view,
 
259
                                    const GimpRGB           *color,
 
260
                                    GimpViewable            *dest_viewable,
 
261
                                    GtkTreeViewDropPosition  drop_pos)
 
262
{
 
263
  if (dest_viewable)
 
264
    {
 
265
      gimp_drawable_bucket_fill_full (GIMP_DRAWABLE (dest_viewable),
 
266
                                      GIMP_FG_BUCKET_FILL,
 
267
                                      GIMP_NORMAL_MODE, GIMP_OPACITY_OPAQUE,
 
268
                                      FALSE,             /* no seed fill */
 
269
                                      FALSE,             /* don't fill transp */
 
270
                                      GIMP_SELECT_CRITERION_COMPOSITE,
 
271
                                      0.0, FALSE,        /* fill params  */
 
272
                                      0.0, 0.0,          /* ignored      */
 
273
                                      color, NULL);
 
274
      gimp_image_flush (GIMP_ITEM_TREE_VIEW (view)->image);
 
275
    }
 
276
}
 
277
 
 
278
 
193
279
/*  GimpItemTreeView methods  */
194
280
 
195
281
static void
196
282
gimp_drawable_tree_view_set_image (GimpItemTreeView *view,
197
 
                                   GimpImage        *gimage)
 
283
                                   GimpImage        *image)
198
284
{
199
 
  if (view->gimage)
200
 
    g_signal_handlers_disconnect_by_func (view->gimage,
 
285
  if (view->image)
 
286
    g_signal_handlers_disconnect_by_func (view->image,
201
287
                                          gimp_drawable_tree_view_floating_selection_changed,
202
288
                                          view);
203
289
 
204
 
  GIMP_ITEM_TREE_VIEW_CLASS (parent_class)->set_image (view, gimage);
 
290
  GIMP_ITEM_TREE_VIEW_CLASS (parent_class)->set_image (view, image);
205
291
 
206
 
  if (view->gimage)
207
 
    g_signal_connect (view->gimage,
208
 
                      "floating_selection_changed",
 
292
  if (view->image)
 
293
    g_signal_connect (view->image,
 
294
                      "floating-selection-changed",
209
295
                      G_CALLBACK (gimp_drawable_tree_view_floating_selection_changed),
210
296
                      view);
211
297
}
214
300
/*  callbacks  */
215
301
 
216
302
static void
217
 
gimp_drawable_tree_view_floating_selection_changed (GimpImage            *gimage,
218
 
                                                    GimpDrawableTreeView *view)
 
303
gimp_drawable_tree_view_floating_selection_changed (GimpImage            *image,
 
304
                                                    GimpDrawableTreeView *view)
219
305
{
220
306
  GimpItem *item;
221
307
 
222
 
  item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (gimage);
 
308
  item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (image);
223
309
 
224
310
  /*  update button states  */
225
311
  gimp_container_view_select_item (GIMP_CONTAINER_VIEW (view),
228
314
 
229
315
static void
230
316
gimp_drawable_tree_view_new_dropped (GimpItemTreeView   *view,
 
317
                                     gint                x,
 
318
                                     gint                y,
231
319
                                     GimpBucketFillMode  fill_mode,
232
320
                                     const GimpRGB      *color,
233
321
                                     GimpPattern        *pattern)
234
322
{
235
323
  GimpItem *item;
236
324
 
237
 
  gimp_image_undo_group_start (view->gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
 
325
  gimp_image_undo_group_start (view->image, GIMP_UNDO_GROUP_EDIT_PASTE,
238
326
                               _("New Layer"));
239
327
 
240
 
  item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->new_item (view->gimage);
 
328
  item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->new_item (view->image);
241
329
 
242
330
  if (item)
243
331
    {
244
 
      GimpDrawable *drawable = GIMP_DRAWABLE (item);
245
 
      GimpToolInfo *tool_info;
 
332
      /*  Get the bucket fill context  */
246
333
      GimpContext  *context;
247
 
 
248
 
      /*  Get the bucket fill context  */
249
 
      tool_info = (GimpToolInfo *)
250
 
        gimp_container_get_child_by_name (view->gimage->gimp->tool_info_list,
251
 
                                          "gimp-bucket-fill-tool");
 
334
      GimpToolInfo *tool_info = gimp_get_tool_info (view->image->gimp,
 
335
                                                    "gimp-bucket-fill-tool");
252
336
 
253
337
      if (tool_info && tool_info->tool_options)
254
338
        context = GIMP_CONTEXT (tool_info->tool_options);
255
339
      else
256
 
        context = view->context;
 
340
        context = gimp_container_view_get_context (GIMP_CONTAINER_VIEW (view));
257
341
 
258
 
      gimp_drawable_bucket_fill_full (drawable,
 
342
      gimp_drawable_bucket_fill_full (GIMP_DRAWABLE (item),
259
343
                                      fill_mode,
260
344
                                      gimp_context_get_paint_mode (context),
261
345
                                      gimp_context_get_opacity (context),
262
 
                                      FALSE /* no seed fill */,
263
 
                                      FALSE, 0.0, FALSE, 0.0, 0.0 /* fill params */,
 
346
                                      FALSE, /* no seed fill */
 
347
                                      FALSE, /* don't fill transp */
 
348
                                      GIMP_SELECT_CRITERION_COMPOSITE,
 
349
                                      0.0, FALSE, 0.0, 0.0 /* fill params */,
264
350
                                      color, pattern);
265
351
    }
266
352
 
267
 
  gimp_image_undo_group_end (view->gimage);
 
353
  gimp_image_undo_group_end (view->image);
268
354
 
269
 
  gimp_image_flush (view->gimage);
 
355
  gimp_image_flush (view->image);
270
356
}
271
357
 
272
358
static void
273
359
gimp_drawable_tree_view_new_pattern_dropped (GtkWidget    *widget,
 
360
                                             gint          x,
 
361
                                             gint          y,
274
362
                                             GimpViewable *viewable,
275
363
                                             gpointer      data)
276
364
{
277
 
  gimp_drawable_tree_view_new_dropped (GIMP_ITEM_TREE_VIEW (data),
 
365
  gimp_drawable_tree_view_new_dropped (GIMP_ITEM_TREE_VIEW (data), x, y,
278
366
                                       GIMP_PATTERN_BUCKET_FILL,
279
367
                                       NULL,
280
368
                                       GIMP_PATTERN (viewable));
282
370
 
283
371
static void
284
372
gimp_drawable_tree_view_new_color_dropped (GtkWidget     *widget,
 
373
                                           gint           x,
 
374
                                           gint           y,
285
375
                                           const GimpRGB *color,
286
376
                                           gpointer       data)
287
377
{
288
 
  gimp_drawable_tree_view_new_dropped (GIMP_ITEM_TREE_VIEW (data),
 
378
  gimp_drawable_tree_view_new_dropped (GIMP_ITEM_TREE_VIEW (data), x, y,
289
379
                                       GIMP_FG_BUCKET_FILL,
290
380
                                       color,
291
381
                                       NULL);