94
91
GimpUndoMode undo_mode);
96
93
static gboolean gimp_undo_create_preview_idle (gpointer data);
97
static void gimp_undo_create_preview_private (GimpUndo *undo);
94
static void gimp_undo_create_preview_private (GimpUndo *undo,
95
GimpContext *context);
98
G_DEFINE_TYPE (GimpUndo, gimp_undo, GIMP_TYPE_VIEWABLE)
100
#define parent_class gimp_undo_parent_class
100
102
static guint undo_signals[LAST_SIGNAL] = { 0 };
102
static GimpViewableClass *parent_class = NULL;
106
gimp_undo_get_type (void)
108
static GType undo_type = 0;
112
static const GTypeInfo undo_info =
114
sizeof (GimpUndoClass),
115
(GBaseInitFunc) NULL,
116
(GBaseFinalizeFunc) NULL,
117
(GClassInitFunc) gimp_undo_class_init,
118
NULL, /* class_finalize */
119
NULL, /* class_data */
122
NULL /* instance_init */
125
undo_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
134
106
gimp_undo_class_init (GimpUndoClass *klass)
177
147
g_object_class_install_property (object_class, PROP_IMAGE,
178
148
g_param_spec_object ("image", NULL, NULL,
150
GIMP_PARAM_READWRITE |
181
151
G_PARAM_CONSTRUCT_ONLY));
153
g_object_class_install_property (object_class, PROP_TIME,
154
g_param_spec_uint ("time", NULL, NULL,
156
GIMP_PARAM_READWRITE));
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,
162
GIMP_PARAM_READWRITE |
188
163
G_PARAM_CONSTRUCT_ONLY));
190
165
g_object_class_install_property (object_class, PROP_DIRTY_MASK,
193
168
GIMP_TYPE_DIRTY_MASK,
170
GIMP_PARAM_READWRITE |
196
171
G_PARAM_CONSTRUCT_ONLY));
198
g_object_class_install_property (object_class, PROP_DATA,
199
g_param_spec_pointer ("data", NULL, NULL,
201
G_PARAM_CONSTRUCT_ONLY));
203
g_object_class_install_property (object_class, PROP_SIZE,
204
g_param_spec_int64 ("size", NULL, NULL,
209
g_object_class_install_property (object_class, PROP_POP_FUNC,
210
g_param_spec_pointer ("pop-func", NULL, NULL,
212
G_PARAM_CONSTRUCT_ONLY));
214
g_object_class_install_property (object_class, PROP_FREE_FUNC,
215
g_param_spec_pointer ("free-func", NULL, NULL,
217
G_PARAM_CONSTRUCT_ONLY));
175
gimp_undo_init (GimpUndo *undo)
177
undo->time = time (NULL);
276
237
case PROP_DIRTY_MASK:
277
238
undo->dirty_mask = g_value_get_flags (value);
280
undo->data = g_value_get_pointer (value);
283
undo->size = g_value_get_int64 (value);
286
undo->pop_func = g_value_get_pointer (value);
289
undo->free_func = g_value_get_pointer (value);
292
242
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
305
255
switch (property_id)
308
g_value_set_object (value, undo->gimage);
258
g_value_set_object (value, undo->image);
261
g_value_set_uint (value, undo->time);
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);
317
g_value_set_pointer (value, undo->data);
320
g_value_set_int64 (value, undo->size);
323
g_value_set_pointer (value, undo->pop_func);
326
g_value_set_pointer (value, undo->free_func);
329
271
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
405
348
GimpUndoMode undo_mode,
406
349
GimpUndoAccumulator *accum)
409
undo->pop_func (undo, undo_mode, accum);
413
354
gimp_undo_real_free (GimpUndo *undo,
414
355
GimpUndoMode undo_mode)
417
undo->free_func (undo, undo_mode);
430
369
switch (undo_mode)
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);
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);
451
390
g_signal_emit (undo, undo_signals[FREE], 0, undo_mode);
393
typedef struct _GimpUndoIdle GimpUndoIdle;
398
GimpContext *context;
402
gimp_undo_idle_free (GimpUndoIdle *idle)
405
g_object_unref (idle->context);
455
gimp_undo_create_preview (GimpUndo *undo,
411
gimp_undo_create_preview (GimpUndo *undo,
412
GimpContext *context,
458
415
g_return_if_fail (GIMP_IS_UNDO (undo));
416
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
460
418
if (undo->preview || undo->preview_idle_id)
464
gimp_undo_create_preview_private (undo);
423
gimp_undo_create_preview_private (undo, context);
466
undo->preview_idle_id = g_idle_add (gimp_undo_create_preview_idle, undo);
427
GimpUndoIdle *idle = g_new0 (GimpUndoIdle, 1);
432
idle->context = g_object_ref (context);
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);
470
442
gimp_undo_create_preview_idle (gpointer data)
472
GimpUndo *undo = GIMP_UNDO (data);
444
GimpUndoIdle *idle = data;
474
if (undo == gimp_undo_stack_peek (undo->gimage->undo_stack))
446
if (idle->undo == gimp_undo_stack_peek (idle->undo->image->undo_stack))
476
gimp_undo_create_preview_private (undo);
448
gimp_undo_create_preview_private (idle->undo, idle->context);
479
undo->preview_idle_id = 0;
451
idle->undo->preview_idle_id = 0;
485
gimp_undo_create_preview_private (GimpUndo *undo)
457
gimp_undo_create_preview_private (GimpUndo *undo,
458
GimpContext *context)
487
GimpImage *image = undo->gimage;
488
GimpViewable *preview_viewable;
489
GimpViewSize preview_size;
460
GimpImage *image = undo->image;
461
GimpViewable *preview_viewable;
462
GimpViewSize preview_size;
493
466
switch (undo->undo_type)
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));
527
undo->preview = gimp_viewable_get_new_preview (preview_viewable,
500
undo->preview = gimp_viewable_get_new_preview (preview_viewable, context,
530
503
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (undo));
534
gimp_undo_refresh_preview (GimpUndo *undo)
507
gimp_undo_refresh_preview (GimpUndo *undo,
508
GimpContext *context)
536
510
g_return_if_fail (GIMP_IS_UNDO (undo));
511
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
538
513
if (undo->preview_idle_id)
536
gimp_undo_is_weak (GimpUndo *undo)
543
type = undo->undo_type;
545
switch (undo->undo_type)
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:
569
* Return value: the time in seconds since this undo item was created
572
gimp_undo_get_age (GimpUndo *undo)
574
guint now = time (NULL);
576
g_return_val_if_fail (GIMP_IS_UNDO (undo), 0);
577
g_return_val_if_fail (now >= undo->time, 0);
579
return now - undo->time;
583
* gimp_undo_reset_age:
586
* Changes the creation time of this undo item to the current time.
589
gimp_undo_reset_age (GimpUndo *undo)
591
g_return_if_fail (GIMP_IS_UNDO (undo));
593
undo->time = time (NULL);
595
g_object_notify (G_OBJECT (undo), "time");