2001-03-05 09:01:16 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
#include "gimpimage.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimpmarshal.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
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
static void gimp_undo_class_init (GimpUndoClass *klass);
|
|
|
|
static void gimp_undo_init (GimpUndo *undo);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
static void gimp_undo_finalize (GObject *object);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
static gsize gimp_undo_get_memsize (GimpObject *object);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
static TempBuf * gimp_undo_get_new_preview (GimpViewable *viewable,
|
2003-02-20 20:47:42 +08:00
|
|
|
gint width,
|
|
|
|
gint height);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
static gboolean gimp_undo_create_preview_idle (gpointer data);
|
|
|
|
static void gimp_undo_create_preview_private (GimpUndo *undo);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
static guint undo_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GimpViewableClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
GType
|
2001-03-05 09:01:16 +08:00
|
|
|
gimp_undo_get_type (void)
|
|
|
|
{
|
2001-07-25 23:22:55 +08:00
|
|
|
static GType undo_type = 0;
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
if (! undo_type)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo undo_info =
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpUndoClass),
|
2001-08-11 22:39:19 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_undo_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpUndo),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_undo_init,
|
2001-03-05 09:01:16 +08:00
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
undo_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
|
|
|
|
"GimpUndo",
|
|
|
|
&undo_info, 0);
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return undo_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_class_init (GimpUndoClass *klass)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
GObjectClass *object_class;
|
2002-01-31 00:14:26 +08:00
|
|
|
GimpObjectClass *gimp_object_class;
|
2001-08-11 22:39:19 +08:00
|
|
|
GimpViewableClass *viewable_class;
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
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
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-05 09:01:16 +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",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpUndoClass, pop),
|
|
|
|
NULL, NULL,
|
2003-02-20 20:47:42 +08:00
|
|
|
gimp_marshal_VOID__ENUM_POINTER,
|
|
|
|
G_TYPE_NONE, 2,
|
2003-02-13 01:11:34 +08:00
|
|
|
GIMP_TYPE_UNDO_MODE,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
undo_signals[FREE] =
|
|
|
|
g_signal_new ("free",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpUndoClass, free),
|
|
|
|
NULL, NULL,
|
2003-02-20 20:47:42 +08:00
|
|
|
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
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
object_class->finalize = gimp_undo_finalize;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_undo_get_memsize;
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
viewable_class->get_new_preview = gimp_undo_get_new_preview;
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
klass->pop = gimp_undo_real_pop;
|
|
|
|
klass->free = gimp_undo_real_free;
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_init (GimpUndo *undo)
|
|
|
|
{
|
2003-02-20 20:47:42 +08:00
|
|
|
undo->gimage = NULL;
|
|
|
|
undo->undo_type = 0;
|
2001-03-05 09:01:16 +08:00
|
|
|
undo->data = NULL;
|
|
|
|
undo->dirties_image = FALSE;
|
|
|
|
undo->pop_func = NULL;
|
|
|
|
undo->free_func = NULL;
|
|
|
|
undo->preview = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_undo_finalize (GObject *object)
|
2001-03-05 09:01:16 +08:00
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
|
|
|
|
undo = GIMP_UNDO (object);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
temp_buf_free (undo->preview);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static gsize
|
|
|
|
gimp_undo_get_memsize (GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gsize memsize = 0;
|
|
|
|
|
|
|
|
undo = GIMP_UNDO (object);
|
|
|
|
|
2003-02-13 01:11:34 +08:00
|
|
|
memsize += undo->size;
|
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
if (undo->preview)
|
|
|
|
memsize += temp_buf_get_memsize (undo->preview);
|
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TempBuf *
|
2003-02-27 00:15:50 +08:00
|
|
|
gimp_undo_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2003-02-27 00:15:50 +08:00
|
|
|
GimpUndo *undo;
|
|
|
|
|
|
|
|
undo = GIMP_UNDO (viewable);
|
|
|
|
|
|
|
|
if (undo->preview)
|
|
|
|
{
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
|
|
|
|
|
|
|
gimp_viewable_calc_preview_size (viewable,
|
|
|
|
undo->preview->width,
|
|
|
|
undo->preview->height,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (preview_width < undo->preview->width &&
|
|
|
|
preview_height < undo->preview->height)
|
|
|
|
{
|
|
|
|
return temp_buf_scale (undo->preview, preview_width, preview_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp_buf_copy (undo->preview, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2003-02-20 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_real_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
|
|
|
{
|
|
|
|
if (undo->pop_func)
|
|
|
|
undo->pop_func (undo, undo_mode, accum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_undo_real_free (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode)
|
|
|
|
{
|
|
|
|
if (undo->free_func)
|
|
|
|
undo->free_func (undo, undo_mode);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2001-03-05 09:01:16 +08:00
|
|
|
GimpUndo *
|
2003-02-20 20:47:42 +08:00
|
|
|
gimp_undo_new (GimpImage *gimage,
|
|
|
|
GimpUndoType undo_type,
|
2003-02-13 01:11:34 +08:00
|
|
|
const gchar *name,
|
2001-03-05 09:01:16 +08:00
|
|
|
gpointer data,
|
2003-02-13 01:11:34 +08:00
|
|
|
gsize size,
|
2001-03-05 09:01:16 +08:00
|
|
|
gboolean dirties_image,
|
|
|
|
GimpUndoPopFunc pop_func,
|
|
|
|
GimpUndoFreeFunc free_func)
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
2003-02-13 01:11:34 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2003-02-20 20:47:42 +08:00
|
|
|
g_return_val_if_fail (size == 0 || data != NULL, NULL);
|
2003-02-13 01:11:34 +08:00
|
|
|
|
|
|
|
undo = g_object_new (GIMP_TYPE_UNDO,
|
|
|
|
"name", name,
|
|
|
|
NULL);
|
2003-02-20 20:47:42 +08:00
|
|
|
|
|
|
|
undo->gimage = gimage;
|
2003-02-13 01:11:34 +08:00
|
|
|
undo->undo_type = undo_type;
|
|
|
|
undo->data = data;
|
|
|
|
undo->size = size;
|
|
|
|
undo->dirties_image = dirties_image ? TRUE : FALSE;
|
|
|
|
undo->pop_func = pop_func;
|
|
|
|
undo->free_func = free_func;
|
2001-03-05 09:01:16 +08:00
|
|
|
|
|
|
|
return undo;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
g_signal_emit (undo, undo_signals[POP], 0, undo_mode, accum);
|
2001-03-05 09:01:16 +08:00
|
|
|
|
2003-02-13 01:11:34 +08:00
|
|
|
if (undo->dirties_image)
|
|
|
|
{
|
|
|
|
switch (undo_mode)
|
|
|
|
{
|
|
|
|
case GIMP_UNDO_MODE_UNDO:
|
2003-02-20 20:47:42 +08:00
|
|
|
gimp_image_clean (undo->gimage);
|
2003-02-13 01:11:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_MODE_REDO:
|
2003-02-20 20:47:42 +08:00
|
|
|
gimp_image_dirty (undo->gimage);
|
2003-02-13 01:11:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-02-20 20:47:42 +08:00
|
|
|
void
|
|
|
|
gimp_undo_create_preview (GimpUndo *undo,
|
|
|
|
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));
|
|
|
|
|
|
|
|
if (undo->preview || undo->preview_idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (create_now)
|
|
|
|
gimp_undo_create_preview_private (undo);
|
|
|
|
else
|
|
|
|
undo->preview_idle_id = g_idle_add (gimp_undo_create_preview_idle, undo);
|
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
|
|
|
{
|
2003-02-20 20:47:42 +08:00
|
|
|
GimpUndo *undo;
|
|
|
|
|
|
|
|
undo = GIMP_UNDO (data);
|
|
|
|
|
|
|
|
if (undo == gimp_undo_stack_peek (undo->gimage->undo_stack))
|
|
|
|
{
|
|
|
|
gimp_undo_create_preview_private (undo);
|
|
|
|
}
|
|
|
|
|
|
|
|
undo->preview_idle_id = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_undo_create_preview_private (GimpUndo *undo)
|
|
|
|
{
|
|
|
|
GimpViewable *preview_viewable;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
switch (undo->undo_type)
|
|
|
|
{
|
|
|
|
case GIMP_UNDO_GROUP_IMAGE_QMASK:
|
|
|
|
case GIMP_UNDO_IMAGE_QMASK:
|
|
|
|
case GIMP_UNDO_MASK:
|
|
|
|
preview_viewable = GIMP_VIEWABLE (gimp_image_get_mask (undo->gimage));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
preview_viewable = GIMP_VIEWABLE (undo->gimage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (undo->gimage->width <= 64 && undo->gimage->height <= 64)
|
|
|
|
{
|
|
|
|
width = undo->gimage->width;
|
|
|
|
height = undo->gimage->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (undo->gimage->width > undo->gimage->height)
|
|
|
|
{
|
|
|
|
width = 64;
|
|
|
|
height = MAX (1, undo->gimage->height * 64 / undo->gimage->width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
height = 64;
|
|
|
|
width = MAX (1, undo->gimage->width * 64 / undo->gimage->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undo->preview = gimp_viewable_get_new_preview (preview_viewable,
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (undo));
|
2001-03-05 09:01:16 +08:00
|
|
|
}
|