2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-03-05 09:01:16 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-03-05 09:01:16 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-03-05 09:01:16 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-03-05 09:01:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2004-07-13 01:10:34 +08:00
|
|
|
#include <time.h>
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2004-10-26 22:45:25 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2004-03-07 23:33:04 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2006-08-30 05:44:51 +08:00
|
|
|
#include "gimpcontext.h"
|
2001-03-05 09:01:16 +08:00
|
|
|
#include "gimpimage.h"
|
2010-02-05 03:06:49 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimpmarshal.h"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "gimptempbuf.h"
|
2001-03-05 09:01:16 +08:00
|
|
|
#include "gimpundo.h"
|
2003-02-20 20:47:42 +08:00
|
|
|
#include "gimpundostack.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2004-04-04 18:56:57 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
POP,
|
2003-02-13 01:11:34 +08:00
|
|
|
FREE,
|
2001-03-05 09:01:16 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-07-13 00:59:36 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_IMAGE,
|
2007-02-06 17:05:04 +08:00
|
|
|
PROP_TIME,
|
2004-07-13 00:59:36 +08:00
|
|
|
PROP_UNDO_TYPE,
|
2007-02-04 06:25:32 +08:00
|
|
|
PROP_DIRTY_MASK
|
2004-07-13 00:59:36 +08:00
|
|
|
};
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2012-04-09 02:25:49 +08:00
|
|
|
static void gimp_undo_constructed (GObject *object);
|
|
|
|
static void gimp_undo_finalize (GObject *object);
|
|
|
|
static void gimp_undo_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_undo_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static gint64 gimp_undo_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static gboolean gimp_undo_get_popup_size (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gboolean dot_for_dot,
|
|
|
|
gint *popup_width,
|
|
|
|
gint *popup_height);
|
|
|
|
static GimpTempBuf * gimp_undo_get_new_preview (GimpViewable *viewable,
|
|
|
|
GimpContext *context,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
|
|
|
static void gimp_undo_real_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum);
|
|
|
|
static void gimp_undo_real_free (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode);
|
|
|
|
|
|
|
|
static gboolean gimp_undo_create_preview_idle (gpointer data);
|
|
|
|
static void gimp_undo_create_preview_private (GimpUndo *undo,
|
|
|
|
GimpContext *context);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpUndo, gimp_undo, GIMP_TYPE_VIEWABLE)
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_undo_parent_class
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint undo_signals[LAST_SIGNAL] = { 0 };
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_class_init (GimpUndoClass *klass)
|
|
|
|
{
|
2004-07-13 00:59:36 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
undo_signals[POP] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_new ("pop",
|
2004-07-13 00:59:36 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpUndoClass, pop),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM_POINTER,
|
|
|
|
G_TYPE_NONE, 2,
|
2003-02-13 01:11:34 +08:00
|
|
|
GIMP_TYPE_UNDO_MODE,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
undo_signals[FREE] =
|
2003-02-13 01:11:34 +08:00
|
|
|
g_signal_new ("free",
|
2004-07-13 00:59:36 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpUndoClass, free),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
2003-02-13 01:11:34 +08:00
|
|
|
GIMP_TYPE_UNDO_MODE);
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2014-05-07 07:01:56 +08:00
|
|
|
object_class->constructed = gimp_undo_constructed;
|
|
|
|
object_class->finalize = gimp_undo_finalize;
|
|
|
|
object_class->set_property = gimp_undo_set_property;
|
|
|
|
object_class->get_property = gimp_undo_get_property;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2014-05-07 07:01:56 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_undo_get_memsize;
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2014-05-31 06:08:10 +08:00
|
|
|
viewable_class->default_icon_name = "edit-undo";
|
2014-05-07 07:01:56 +08:00
|
|
|
viewable_class->get_popup_size = gimp_undo_get_popup_size;
|
|
|
|
viewable_class->get_new_preview = gimp_undo_get_new_preview;
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2014-05-07 07:01:56 +08:00
|
|
|
klass->pop = gimp_undo_real_pop;
|
|
|
|
klass->free = gimp_undo_real_free;
|
2004-07-13 00:59:36 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_IMAGE,
|
|
|
|
g_param_spec_object ("image", NULL, NULL,
|
|
|
|
GIMP_TYPE_IMAGE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-07-13 00:59:36 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2007-02-06 17:05:04 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_TIME,
|
|
|
|
g_param_spec_uint ("time", NULL, NULL,
|
|
|
|
0, G_MAXUINT, 0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2004-07-13 00:59:36 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_UNDO_TYPE,
|
|
|
|
g_param_spec_enum ("undo-type", NULL, NULL,
|
|
|
|
GIMP_TYPE_UNDO_TYPE,
|
|
|
|
GIMP_UNDO_GROUP_NONE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-07-13 00:59:36 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2004-07-29 22:16:21 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_DIRTY_MASK,
|
|
|
|
g_param_spec_flags ("dirty-mask",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_DIRTY_MASK,
|
|
|
|
GIMP_DIRTY_NONE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-07-29 22:16:21 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void
|
|
|
|
gimp_undo_init (GimpUndo *undo)
|
|
|
|
{
|
|
|
|
undo->time = time (NULL);
|
|
|
|
}
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void
|
|
|
|
gimp_undo_constructed (GObject *object)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
2011-01-13 05:53:58 +08:00
|
|
|
GimpUndo *undo = GIMP_UNDO (object);
|
2004-07-13 00:59:36 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2004-07-13 00:59:36 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_assert (GIMP_IS_IMAGE (undo->image));
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_undo_finalize (GObject *object)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
2004-03-08 00:41:06 +08:00
|
|
|
GimpUndo *undo = GIMP_UNDO (object);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
if (undo->preview_idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (undo->preview_idle_id);
|
|
|
|
undo->preview_idle_id = 0;
|
|
|
|
}
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
if (undo->preview)
|
2001-07-25 23:22:55 +08:00
|
|
|
{
|
2012-04-09 06:16:46 +08:00
|
|
|
gimp_temp_buf_unref (undo->preview);
|
2001-07-25 23:22:55 +08:00
|
|
|
undo->preview = NULL;
|
|
|
|
}
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
2004-07-13 00:59:36 +08:00
|
|
|
static void
|
|
|
|
gimp_undo_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpUndo *undo = GIMP_UNDO (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
|
|
|
/* don't ref */
|
2006-11-25 22:57:26 +08:00
|
|
|
undo->image = g_value_get_object (value);
|
2004-07-13 00:59:36 +08:00
|
|
|
break;
|
2007-02-06 17:05:04 +08:00
|
|
|
case PROP_TIME:
|
|
|
|
undo->time = g_value_get_uint (value);
|
|
|
|
break;
|
2004-07-13 00:59:36 +08:00
|
|
|
case PROP_UNDO_TYPE:
|
|
|
|
undo->undo_type = g_value_get_enum (value);
|
|
|
|
break;
|
2004-07-29 22:16:21 +08:00
|
|
|
case PROP_DIRTY_MASK:
|
|
|
|
undo->dirty_mask = g_value_get_flags (value);
|
2004-07-13 00:59:36 +08:00
|
|
|
break;
|
2007-02-04 06:25:32 +08:00
|
|
|
|
2004-07-13 00:59:36 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpUndo *undo = GIMP_UNDO (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
2006-03-29 01:08:36 +08:00
|
|
|
g_value_set_object (value, undo->image);
|
2004-07-13 00:59:36 +08:00
|
|
|
break;
|
2007-02-06 17:05:04 +08:00
|
|
|
case PROP_TIME:
|
|
|
|
g_value_set_uint (value, undo->time);
|
|
|
|
break;
|
2004-07-13 00:59:36 +08:00
|
|
|
case PROP_UNDO_TYPE:
|
|
|
|
g_value_set_enum (value, undo->undo_type);
|
|
|
|
break;
|
2004-07-29 22:16:21 +08:00
|
|
|
case PROP_DIRTY_MASK:
|
|
|
|
g_value_set_flags (value, undo->dirty_mask);
|
2004-07-13 00:59:36 +08:00
|
|
|
break;
|
2007-02-04 06:25:32 +08:00
|
|
|
|
2004-07-13 00:59:36 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_undo_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2004-03-08 00:41:06 +08:00
|
|
|
GimpUndo *undo = GIMP_UNDO (object);
|
2007-02-04 06:25:32 +08:00
|
|
|
gint64 memsize = 0;
|
2003-02-13 01:11:34 +08:00
|
|
|
|
2012-04-09 05:56:52 +08:00
|
|
|
*gui_size += gimp_temp_buf_get_memsize (undo->preview);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2003-02-27 21:59:41 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_undo_get_popup_size (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gboolean dot_for_dot,
|
|
|
|
gint *popup_width,
|
|
|
|
gint *popup_height)
|
|
|
|
{
|
2004-03-08 00:41:06 +08:00
|
|
|
GimpUndo *undo = GIMP_UNDO (viewable);
|
2003-02-27 21:59:41 +08:00
|
|
|
|
|
|
|
if (undo->preview &&
|
2012-04-23 15:40:56 +08:00
|
|
|
(gimp_temp_buf_get_width (undo->preview) > width ||
|
|
|
|
gimp_temp_buf_get_height (undo->preview) > height))
|
2003-02-27 21:59:41 +08:00
|
|
|
{
|
2012-04-23 15:40:56 +08:00
|
|
|
*popup_width = gimp_temp_buf_get_width (undo->preview);
|
|
|
|
*popup_height = gimp_temp_buf_get_height (undo->preview);
|
2003-02-27 21:59:41 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-04-09 02:25:49 +08:00
|
|
|
static GimpTempBuf *
|
2003-02-27 00:15:50 +08:00
|
|
|
gimp_undo_get_new_preview (GimpViewable *viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
GimpContext *context,
|
2003-02-27 00:15:50 +08:00
|
|
|
gint width,
|
|
|
|
gint height)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2004-03-08 00:41:06 +08:00
|
|
|
GimpUndo *undo = GIMP_UNDO (viewable);
|
2003-02-27 00:15:50 +08:00
|
|
|
|
|
|
|
if (undo->preview)
|
|
|
|
{
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
|
|
|
|
2012-04-23 15:40:56 +08:00
|
|
|
gimp_viewable_calc_preview_size (gimp_temp_buf_get_width (undo->preview),
|
|
|
|
gimp_temp_buf_get_height (undo->preview),
|
2003-02-27 00:15:50 +08:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
NULL);
|
|
|
|
|
2012-04-23 15:40:56 +08:00
|
|
|
if (preview_width < gimp_temp_buf_get_width (undo->preview) &&
|
|
|
|
preview_height < gimp_temp_buf_get_height (undo->preview))
|
2003-02-27 00:15:50 +08:00
|
|
|
{
|
2012-04-09 05:56:52 +08:00
|
|
|
return gimp_temp_buf_scale (undo->preview,
|
|
|
|
preview_width, preview_height);
|
2003-02-27 00:15:50 +08:00
|
|
|
}
|
|
|
|
|
2012-04-09 05:56:52 +08:00
|
|
|
return gimp_temp_buf_copy (undo->preview);
|
2003-02-27 00:15:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_real_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_real_free (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode)
|
|
|
|
{
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
void
|
2003-02-13 01:11:34 +08:00
|
|
|
gimp_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
2003-02-13 01:11:34 +08:00
|
|
|
g_return_if_fail (accum != NULL);
|
|
|
|
|
2004-07-29 22:16:21 +08:00
|
|
|
if (undo->dirty_mask != GIMP_DIRTY_NONE)
|
2003-02-13 01:11:34 +08:00
|
|
|
{
|
|
|
|
switch (undo_mode)
|
|
|
|
{
|
|
|
|
case GIMP_UNDO_MODE_UNDO:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_clean (undo->image, undo->dirty_mask);
|
2003-02-13 01:11:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_MODE_REDO:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_dirty (undo->image, undo->dirty_mask);
|
2003-02-13 01:11:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-07-29 22:16:21 +08:00
|
|
|
|
|
|
|
g_signal_emit (undo, undo_signals[POP], 0, undo_mode, accum);
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-13 01:11:34 +08:00
|
|
|
gimp_undo_free (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
g_signal_emit (undo, undo_signals[FREE], 0, undo_mode);
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
2006-09-02 05:18:03 +08:00
|
|
|
typedef struct _GimpUndoIdle GimpUndoIdle;
|
|
|
|
|
|
|
|
struct _GimpUndoIdle
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
GimpContext *context;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_idle_free (GimpUndoIdle *idle)
|
|
|
|
{
|
|
|
|
if (idle->context)
|
|
|
|
g_object_unref (idle->context);
|
|
|
|
|
2007-05-22 18:43:48 +08:00
|
|
|
g_slice_free (GimpUndoIdle, idle);
|
2006-09-02 05:18:03 +08:00
|
|
|
}
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
void
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_undo_create_preview (GimpUndo *undo,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean create_now)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
2003-02-20 20:47:42 +08:00
|
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
2006-08-30 05:44:51 +08:00
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
2003-02-20 20:47:42 +08:00
|
|
|
|
|
|
|
if (undo->preview || undo->preview_idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (create_now)
|
2006-09-02 05:18:03 +08:00
|
|
|
{
|
|
|
|
gimp_undo_create_preview_private (undo, context);
|
|
|
|
}
|
2003-02-20 20:47:42 +08:00
|
|
|
else
|
2006-09-02 05:18:03 +08:00
|
|
|
{
|
2007-05-22 18:43:48 +08:00
|
|
|
GimpUndoIdle *idle = g_slice_new0 (GimpUndoIdle);
|
2006-09-02 05:18:03 +08:00
|
|
|
|
|
|
|
idle->undo = undo;
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
idle->context = g_object_ref (context);
|
|
|
|
|
|
|
|
undo->preview_idle_id =
|
2007-06-08 07:05:02 +08:00
|
|
|
g_idle_add_full (GIMP_VIEWABLE_PRIORITY_IDLE,
|
2007-02-06 17:05:04 +08:00
|
|
|
gimp_undo_create_preview_idle, idle,
|
|
|
|
(GDestroyNotify) gimp_undo_idle_free);
|
2006-09-02 05:18:03 +08:00
|
|
|
}
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_undo_create_preview_idle (gpointer data)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
2010-02-05 03:06:49 +08:00
|
|
|
GimpUndoIdle *idle = data;
|
|
|
|
GimpUndoStack *stack = gimp_image_get_undo_stack (idle->undo->image);
|
2003-02-20 20:47:42 +08:00
|
|
|
|
2010-02-05 03:06:49 +08:00
|
|
|
if (idle->undo == gimp_undo_stack_peek (stack))
|
2003-02-20 20:47:42 +08:00
|
|
|
{
|
2006-09-02 05:18:03 +08:00
|
|
|
gimp_undo_create_preview_private (idle->undo, idle->context);
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
2006-09-02 05:18:03 +08:00
|
|
|
idle->undo->preview_idle_id = 0;
|
2003-02-20 20:47:42 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-07 23:33:04 +08:00
|
|
|
static void
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_undo_create_preview_private (GimpUndo *undo,
|
|
|
|
GimpContext *context)
|
2003-02-20 20:47:42 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = undo->image;
|
2005-09-19 20:44:06 +08:00
|
|
|
GimpViewable *preview_viewable;
|
|
|
|
GimpViewSize preview_size;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2003-02-20 20:47:42 +08:00
|
|
|
|
|
|
|
switch (undo->undo_type)
|
|
|
|
{
|
2005-09-19 20:44:06 +08:00
|
|
|
case GIMP_UNDO_GROUP_IMAGE_QUICK_MASK:
|
2003-03-20 00:58:17 +08:00
|
|
|
case GIMP_UNDO_GROUP_MASK:
|
2003-02-20 20:47:42 +08:00
|
|
|
case GIMP_UNDO_MASK:
|
2004-03-07 23:33:04 +08:00
|
|
|
preview_viewable = GIMP_VIEWABLE (gimp_image_get_mask (image));
|
2003-02-20 20:47:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-03-07 23:33:04 +08:00
|
|
|
preview_viewable = GIMP_VIEWABLE (image);
|
2003-02-20 20:47:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-07 23:33:04 +08:00
|
|
|
preview_size = image->gimp->config->undo_preview_size;
|
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
if (gimp_image_get_width (image) <= preview_size &&
|
|
|
|
gimp_image_get_height (image) <= preview_size)
|
2003-02-20 20:47:42 +08:00
|
|
|
{
|
2007-12-26 00:21:40 +08:00
|
|
|
width = gimp_image_get_width (image);
|
|
|
|
height = gimp_image_get_height (image);
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-26 00:21:40 +08:00
|
|
|
if (gimp_image_get_width (image) > gimp_image_get_height (image))
|
2003-02-20 20:47:42 +08:00
|
|
|
{
|
2004-03-07 23:33:04 +08:00
|
|
|
width = preview_size;
|
2007-12-26 00:21:40 +08:00
|
|
|
height = MAX (1, (gimp_image_get_height (image) * preview_size /
|
|
|
|
gimp_image_get_width (image)));
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-07 23:33:04 +08:00
|
|
|
height = preview_size;
|
2007-12-26 00:21:40 +08:00
|
|
|
width = MAX (1, (gimp_image_get_width (image) * preview_size /
|
|
|
|
gimp_image_get_height (image)));
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
undo->preview = gimp_viewable_get_new_preview (preview_viewable, context,
|
2003-02-20 20:47:42 +08:00
|
|
|
width, height);
|
|
|
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (undo));
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
2004-03-20 07:42:42 +08:00
|
|
|
|
|
|
|
void
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_undo_refresh_preview (GimpUndo *undo,
|
|
|
|
GimpContext *context)
|
2004-03-20 07:42:42 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
2006-08-30 05:44:51 +08:00
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
2004-03-20 07:42:42 +08:00
|
|
|
|
|
|
|
if (undo->preview_idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (undo->preview)
|
|
|
|
{
|
2012-04-09 06:16:46 +08:00
|
|
|
gimp_temp_buf_unref (undo->preview);
|
2004-03-20 07:42:42 +08:00
|
|
|
undo->preview = NULL;
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_undo_create_preview (undo, context, FALSE);
|
2004-03-20 07:42:42 +08:00
|
|
|
}
|
|
|
|
}
|
2004-03-22 07:14:21 +08:00
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_undo_type_to_name (GimpUndoType type)
|
|
|
|
{
|
2004-10-26 22:45:25 +08:00
|
|
|
const gchar *desc;
|
2004-03-22 07:14:21 +08:00
|
|
|
|
2004-10-26 22:45:25 +08:00
|
|
|
if (gimp_enum_get_value (GIMP_TYPE_UNDO_TYPE, type, NULL, NULL, &desc, NULL))
|
|
|
|
return desc;
|
2004-04-04 18:56:57 +08:00
|
|
|
else
|
|
|
|
return "";
|
2004-03-22 07:14:21 +08:00
|
|
|
}
|
2006-06-13 10:03:44 +08:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_undo_is_weak (GimpUndo *undo)
|
|
|
|
{
|
|
|
|
if (! undo)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (undo->undo_type)
|
|
|
|
{
|
|
|
|
case GIMP_UNDO_GROUP_ITEM_VISIBILITY:
|
|
|
|
case GIMP_UNDO_GROUP_ITEM_PROPERTIES:
|
|
|
|
case GIMP_UNDO_GROUP_LAYER_APPLY_MASK:
|
|
|
|
case GIMP_UNDO_ITEM_VISIBILITY:
|
|
|
|
case GIMP_UNDO_LAYER_MODE:
|
|
|
|
case GIMP_UNDO_LAYER_OPACITY:
|
|
|
|
case GIMP_UNDO_LAYER_MASK_APPLY:
|
|
|
|
case GIMP_UNDO_LAYER_MASK_SHOW:
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-02-06 17:05:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_undo_get_age:
|
|
|
|
* @undo:
|
|
|
|
*
|
|
|
|
* Return value: the time in seconds since this undo item was created
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gimp_undo_get_age (GimpUndo *undo)
|
|
|
|
{
|
|
|
|
guint now = time (NULL);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_UNDO (undo), 0);
|
|
|
|
g_return_val_if_fail (now >= undo->time, 0);
|
|
|
|
|
|
|
|
return now - undo->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_undo_reset_age:
|
|
|
|
* @undo:
|
|
|
|
*
|
|
|
|
* Changes the creation time of this undo item to the current time.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_undo_reset_age (GimpUndo *undo)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
|
|
|
|
|
|
|
undo->time = time (NULL);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (undo), "time");
|
|
|
|
}
|