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

« back to all changes in this revision

Viewing changes to app/core/gimpundo.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
 * This program is free software; you can redistribute it and/or modify
31
31
#include "config/gimpcoreconfig.h"
32
32
 
33
33
#include "gimp.h"
 
34
#include "gimpcontext.h"
34
35
#include "gimpimage.h"
35
36
#include "gimpmarshal.h"
36
37
#include "gimpundo.h"
50
51
{
51
52
  PROP_0,
52
53
  PROP_IMAGE,
 
54
  PROP_TIME,
53
55
  PROP_UNDO_TYPE,
54
 
  PROP_DIRTY_MASK,
55
 
  PROP_DATA,
56
 
  PROP_SIZE,
57
 
  PROP_POP_FUNC,
58
 
  PROP_FREE_FUNC
 
56
  PROP_DIRTY_MASK
59
57
};
60
58
 
61
59
 
62
 
static void      gimp_undo_class_init          (GimpUndoClass       *klass);
63
 
 
64
60
static GObject * gimp_undo_constructor         (GType                type,
65
61
                                                guint                n_params,
66
62
                                                GObjectConstructParam *params);
84
80
                                                gint                *popup_width,
85
81
                                                gint                *popup_height);
86
82
static TempBuf * gimp_undo_get_new_preview     (GimpViewable        *viewable,
 
83
                                                GimpContext         *context,
87
84
                                                gint                 width,
88
85
                                                gint                 height);
89
86
 
94
91
                                                GimpUndoMode         undo_mode);
95
92
 
96
93
static gboolean  gimp_undo_create_preview_idle (gpointer             data);
97
 
static void   gimp_undo_create_preview_private (GimpUndo            *undo);
98
 
 
 
94
static void   gimp_undo_create_preview_private (GimpUndo            *undo,
 
95
                                                GimpContext         *context);
 
96
 
 
97
 
 
98
G_DEFINE_TYPE (GimpUndo, gimp_undo, GIMP_TYPE_VIEWABLE)
 
99
 
 
100
#define parent_class gimp_undo_parent_class
99
101
 
100
102
static guint undo_signals[LAST_SIGNAL] = { 0 };
101
103
 
102
 
static GimpViewableClass *parent_class = NULL;
103
 
 
104
 
 
105
 
GType
106
 
gimp_undo_get_type (void)
107
 
{
108
 
  static GType undo_type = 0;
109
 
 
110
 
  if (! undo_type)
111
 
    {
112
 
      static const GTypeInfo undo_info =
113
 
      {
114
 
        sizeof (GimpUndoClass),
115
 
        (GBaseInitFunc) NULL,
116
 
        (GBaseFinalizeFunc) NULL,
117
 
        (GClassInitFunc) gimp_undo_class_init,
118
 
        NULL,           /* class_finalize */
119
 
        NULL,           /* class_data     */
120
 
        sizeof (GimpUndo),
121
 
        0,              /* n_preallocs    */
122
 
        NULL            /* instance_init  */
123
 
      };
124
 
 
125
 
      undo_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
126
 
                                          "GimpUndo",
127
 
                                          &undo_info, 0);
128
 
  }
129
 
 
130
 
  return undo_type;
131
 
}
132
104
 
133
105
static void
134
106
gimp_undo_class_init (GimpUndoClass *klass)
137
109
  GimpObjectClass   *gimp_object_class = GIMP_OBJECT_CLASS (klass);
138
110
  GimpViewableClass *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
139
111
 
140
 
  parent_class = g_type_class_peek_parent (klass);
141
 
 
142
112
  undo_signals[POP] =
143
113
    g_signal_new ("pop",
144
114
                  G_TYPE_FROM_CLASS (klass),
177
147
  g_object_class_install_property (object_class, PROP_IMAGE,
178
148
                                   g_param_spec_object ("image", NULL, NULL,
179
149
                                                        GIMP_TYPE_IMAGE,
180
 
                                                        G_PARAM_READWRITE |
 
150
                                                        GIMP_PARAM_READWRITE |
181
151
                                                        G_PARAM_CONSTRUCT_ONLY));
182
152
 
 
153
  g_object_class_install_property (object_class, PROP_TIME,
 
154
                                   g_param_spec_uint ("time", NULL, NULL,
 
155
                                                      0, G_MAXUINT, 0,
 
156
                                                      GIMP_PARAM_READWRITE));
 
157
 
183
158
  g_object_class_install_property (object_class, PROP_UNDO_TYPE,
184
159
                                   g_param_spec_enum ("undo-type", NULL, NULL,
185
160
                                                      GIMP_TYPE_UNDO_TYPE,
186
161
                                                      GIMP_UNDO_GROUP_NONE,
187
 
                                                      G_PARAM_READWRITE |
 
162
                                                      GIMP_PARAM_READWRITE |
188
163
                                                      G_PARAM_CONSTRUCT_ONLY));
189
164
 
190
165
  g_object_class_install_property (object_class, PROP_DIRTY_MASK,
192
167
                                                       NULL, NULL,
193
168
                                                       GIMP_TYPE_DIRTY_MASK,
194
169
                                                       GIMP_DIRTY_NONE,
195
 
                                                       G_PARAM_READWRITE |
 
170
                                                       GIMP_PARAM_READWRITE |
196
171
                                                       G_PARAM_CONSTRUCT_ONLY));
197
 
 
198
 
  g_object_class_install_property (object_class, PROP_DATA,
199
 
                                   g_param_spec_pointer ("data", NULL, NULL,
200
 
                                                         G_PARAM_READWRITE |
201
 
                                                         G_PARAM_CONSTRUCT_ONLY));
202
 
 
203
 
  g_object_class_install_property (object_class, PROP_SIZE,
204
 
                                   g_param_spec_int64 ("size", NULL, NULL,
205
 
                                                       0, G_MAXINT64, 0,
206
 
                                                       G_PARAM_READWRITE |
207
 
                                                       G_PARAM_CONSTRUCT));
208
 
 
209
 
  g_object_class_install_property (object_class, PROP_POP_FUNC,
210
 
                                   g_param_spec_pointer ("pop-func", NULL, NULL,
211
 
                                                         G_PARAM_READWRITE |
212
 
                                                         G_PARAM_CONSTRUCT_ONLY));
213
 
 
214
 
  g_object_class_install_property (object_class, PROP_FREE_FUNC,
215
 
                                   g_param_spec_pointer ("free-func", NULL, NULL,
216
 
                                                         G_PARAM_READWRITE |
217
 
                                                         G_PARAM_CONSTRUCT_ONLY));
 
172
}
 
173
 
 
174
static void
 
175
gimp_undo_init (GimpUndo *undo)
 
176
{
 
177
  undo->time = time (NULL);
218
178
}
219
179
 
220
180
static GObject *
229
189
 
230
190
  undo = GIMP_UNDO (object);
231
191
 
232
 
  g_assert (GIMP_IS_IMAGE (undo->gimage));
233
 
 
234
 
  undo->time = time (NULL);
 
192
  g_assert (GIMP_IS_IMAGE (undo->image));
235
193
 
236
194
  return object;
237
195
}
268
226
    {
269
227
    case PROP_IMAGE:
270
228
      /* don't ref */
271
 
      undo->gimage = (GimpImage *) g_value_get_object (value);
 
229
      undo->image = g_value_get_object (value);
 
230
      break;
 
231
    case PROP_TIME:
 
232
      undo->time = g_value_get_uint (value);
272
233
      break;
273
234
    case PROP_UNDO_TYPE:
274
235
      undo->undo_type = g_value_get_enum (value);
276
237
    case PROP_DIRTY_MASK:
277
238
      undo->dirty_mask = g_value_get_flags (value);
278
239
      break;
279
 
    case PROP_DATA:
280
 
      undo->data = g_value_get_pointer (value);
281
 
      break;
282
 
    case PROP_SIZE:
283
 
      undo->size = g_value_get_int64 (value);
284
 
      break;
285
 
    case PROP_POP_FUNC:
286
 
      undo->pop_func = g_value_get_pointer (value);
287
 
      break;
288
 
    case PROP_FREE_FUNC:
289
 
      undo->free_func = g_value_get_pointer (value);
290
 
      break;
 
240
 
291
241
    default:
292
242
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
293
243
      break;
305
255
  switch (property_id)
306
256
    {
307
257
    case PROP_IMAGE:
308
 
      g_value_set_object (value, undo->gimage);
 
258
      g_value_set_object (value, undo->image);
 
259
      break;
 
260
    case PROP_TIME:
 
261
      g_value_set_uint (value, undo->time);
309
262
      break;
310
263
    case PROP_UNDO_TYPE:
311
264
      g_value_set_enum (value, undo->undo_type);
313
266
    case PROP_DIRTY_MASK:
314
267
      g_value_set_flags (value, undo->dirty_mask);
315
268
      break;
316
 
    case PROP_DATA:
317
 
      g_value_set_pointer (value, undo->data);
318
 
      break;
319
 
    case PROP_SIZE:
320
 
      g_value_set_int64 (value, undo->size);
321
 
      break;
322
 
    case PROP_POP_FUNC:
323
 
      g_value_set_pointer (value, undo->pop_func);
324
 
      break;
325
 
    case PROP_FREE_FUNC:
326
 
      g_value_set_pointer (value, undo->free_func);
327
 
      break;
 
269
 
328
270
    default:
329
271
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
330
272
      break;
336
278
                       gint64     *gui_size)
337
279
{
338
280
  GimpUndo *undo    = GIMP_UNDO (object);
339
 
  gint64    memsize = undo->size;
 
281
  gint64    memsize = 0;
340
282
 
341
283
  if (undo->preview)
342
284
    *gui_size += temp_buf_get_memsize (undo->preview);
369
311
 
370
312
static TempBuf *
371
313
gimp_undo_get_new_preview (GimpViewable *viewable,
 
314
                           GimpContext  *context,
372
315
                           gint          width,
373
316
                           gint          height)
374
317
{
405
348
                    GimpUndoMode         undo_mode,
406
349
                    GimpUndoAccumulator *accum)
407
350
{
408
 
  if (undo->pop_func)
409
 
    undo->pop_func (undo, undo_mode, accum);
410
351
}
411
352
 
412
353
static void
413
354
gimp_undo_real_free (GimpUndo     *undo,
414
355
                     GimpUndoMode  undo_mode)
415
356
{
416
 
  if (undo->free_func)
417
 
    undo->free_func (undo, undo_mode);
418
357
}
419
358
 
420
359
void
430
369
      switch (undo_mode)
431
370
        {
432
371
        case GIMP_UNDO_MODE_UNDO:
433
 
          gimp_image_clean (undo->gimage, undo->dirty_mask);
 
372
          gimp_image_clean (undo->image, undo->dirty_mask);
434
373
          break;
435
374
 
436
375
        case GIMP_UNDO_MODE_REDO:
437
 
          gimp_image_dirty (undo->gimage, undo->dirty_mask);
 
376
          gimp_image_dirty (undo->image, undo->dirty_mask);
438
377
          break;
439
378
        }
440
379
    }
451
390
  g_signal_emit (undo, undo_signals[FREE], 0, undo_mode);
452
391
}
453
392
 
 
393
typedef struct _GimpUndoIdle GimpUndoIdle;
 
394
 
 
395
struct _GimpUndoIdle
 
396
{
 
397
  GimpUndo    *undo;
 
398
  GimpContext *context;
 
399
};
 
400
 
 
401
static void
 
402
gimp_undo_idle_free (GimpUndoIdle *idle)
 
403
{
 
404
  if (idle->context)
 
405
    g_object_unref (idle->context);
 
406
 
 
407
  g_free (idle);
 
408
}
 
409
 
454
410
void
455
 
gimp_undo_create_preview (GimpUndo  *undo,
456
 
                          gboolean   create_now)
 
411
gimp_undo_create_preview (GimpUndo    *undo,
 
412
                          GimpContext *context,
 
413
                          gboolean     create_now)
457
414
{
458
415
  g_return_if_fail (GIMP_IS_UNDO (undo));
 
416
  g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
459
417
 
460
418
  if (undo->preview || undo->preview_idle_id)
461
419
    return;
462
420
 
463
421
  if (create_now)
464
 
    gimp_undo_create_preview_private (undo);
 
422
    {
 
423
      gimp_undo_create_preview_private (undo, context);
 
424
    }
465
425
  else
466
 
    undo->preview_idle_id = g_idle_add (gimp_undo_create_preview_idle, undo);
 
426
    {
 
427
      GimpUndoIdle *idle = g_new0 (GimpUndoIdle, 1);
 
428
 
 
429
      idle->undo = undo;
 
430
 
 
431
      if (context)
 
432
        idle->context = g_object_ref (context);
 
433
 
 
434
      undo->preview_idle_id =
 
435
        g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
 
436
                         gimp_undo_create_preview_idle, idle,
 
437
                         (GDestroyNotify) gimp_undo_idle_free);
 
438
    }
467
439
}
468
440
 
469
441
static gboolean
470
442
gimp_undo_create_preview_idle (gpointer data)
471
443
{
472
 
  GimpUndo *undo = GIMP_UNDO (data);
 
444
  GimpUndoIdle *idle = data;
473
445
 
474
 
  if (undo == gimp_undo_stack_peek (undo->gimage->undo_stack))
 
446
  if (idle->undo == gimp_undo_stack_peek (idle->undo->image->undo_stack))
475
447
    {
476
 
      gimp_undo_create_preview_private (undo);
 
448
      gimp_undo_create_preview_private (idle->undo, idle->context);
477
449
    }
478
450
 
479
 
  undo->preview_idle_id = 0;
 
451
  idle->undo->preview_idle_id = 0;
480
452
 
481
453
  return FALSE;
482
454
}
483
455
 
484
456
static void
485
 
gimp_undo_create_preview_private (GimpUndo *undo)
 
457
gimp_undo_create_preview_private (GimpUndo    *undo,
 
458
                                  GimpContext *context)
486
459
{
487
 
  GimpImage       *image = undo->gimage;
488
 
  GimpViewable    *preview_viewable;
489
 
  GimpViewSize     preview_size;
490
 
  gint             width;
491
 
  gint             height;
 
460
  GimpImage    *image = undo->image;
 
461
  GimpViewable *preview_viewable;
 
462
  GimpViewSize  preview_size;
 
463
  gint          width;
 
464
  gint          height;
492
465
 
493
466
  switch (undo->undo_type)
494
467
    {
495
 
    case GIMP_UNDO_GROUP_IMAGE_QMASK:
 
468
    case GIMP_UNDO_GROUP_IMAGE_QUICK_MASK:
496
469
    case GIMP_UNDO_GROUP_MASK:
497
470
    case GIMP_UNDO_MASK:
498
471
      preview_viewable = GIMP_VIEWABLE (gimp_image_get_mask (image));
524
497
        }
525
498
    }
526
499
 
527
 
  undo->preview = gimp_viewable_get_new_preview (preview_viewable,
 
500
  undo->preview = gimp_viewable_get_new_preview (preview_viewable, context,
528
501
                                                 width, height);
529
502
 
530
503
  gimp_viewable_invalidate_preview (GIMP_VIEWABLE (undo));
531
504
}
532
505
 
533
506
void
534
 
gimp_undo_refresh_preview (GimpUndo *undo)
 
507
gimp_undo_refresh_preview (GimpUndo    *undo,
 
508
                           GimpContext *context)
535
509
{
536
510
  g_return_if_fail (GIMP_IS_UNDO (undo));
 
511
  g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
537
512
 
538
513
  if (undo->preview_idle_id)
539
514
    return;
542
517
    {
543
518
      temp_buf_free (undo->preview);
544
519
      undo->preview = NULL;
545
 
      gimp_undo_create_preview (undo, FALSE);
 
520
      gimp_undo_create_preview (undo, context, FALSE);
546
521
    }
547
522
}
548
523
 
556
531
  else
557
532
    return "";
558
533
}
 
534
 
 
535
gboolean
 
536
gimp_undo_is_weak (GimpUndo *undo)
 
537
{
 
538
  GimpUndoType type;
 
539
 
 
540
  if (! undo)
 
541
    return FALSE;
 
542
 
 
543
  type = undo->undo_type;
 
544
 
 
545
  switch (undo->undo_type)
 
546
    {
 
547
    case GIMP_UNDO_GROUP_ITEM_VISIBILITY:
 
548
    case GIMP_UNDO_GROUP_ITEM_PROPERTIES:
 
549
    case GIMP_UNDO_GROUP_LAYER_APPLY_MASK:
 
550
    case GIMP_UNDO_ITEM_VISIBILITY:
 
551
    case GIMP_UNDO_LAYER_MODE:
 
552
    case GIMP_UNDO_LAYER_OPACITY:
 
553
    case GIMP_UNDO_LAYER_MASK_APPLY:
 
554
    case GIMP_UNDO_LAYER_MASK_SHOW:
 
555
      return TRUE;
 
556
      break;
 
557
 
 
558
    default:
 
559
      break;
 
560
    }
 
561
 
 
562
  return FALSE;
 
563
}
 
564
 
 
565
/**
 
566
 * gimp_undo_get_age:
 
567
 * @undo:
 
568
 *
 
569
 * Return value: the time in seconds since this undo item was created
 
570
 */
 
571
gint
 
572
gimp_undo_get_age (GimpUndo *undo)
 
573
{
 
574
  guint now = time (NULL);
 
575
 
 
576
  g_return_val_if_fail (GIMP_IS_UNDO (undo), 0);
 
577
  g_return_val_if_fail (now >= undo->time, 0);
 
578
 
 
579
  return now - undo->time;
 
580
}
 
581
 
 
582
/**
 
583
 * gimp_undo_reset_age:
 
584
 * @undo:
 
585
 *
 
586
 * Changes the creation time of this undo item to the current time.
 
587
 */
 
588
void
 
589
gimp_undo_reset_age (GimpUndo *undo)
 
590
{
 
591
  g_return_if_fail (GIMP_IS_UNDO (undo));
 
592
 
 
593
  undo->time = time (NULL);
 
594
 
 
595
  g_object_notify (G_OBJECT (undo), "time");
 
596
}