gimp/app/undo.c

2589 lines
57 KiB
C
Raw Normal View History

1997-11-25 06:05:25 +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.
1997-11-25 06:05:25 +08:00
*/
#include <stdlib.h>
#include <string.h>
#include "appenv.h"
#include "by_color_select.h"
#include "channel.h"
#include "drawable.h"
#include "errors.h"
#include "floating_sel.h"
#include "gdisplay.h"
#include "gdisplay_ops.h"
#include "gimage_mask.h"
#include "gimprc.h"
#include "layer.h"
#include "paint_core.h"
#include "paint_funcs.h"
gave parasite undo a MISC_UNDO class for now so it compiles * app/gimpdrawable.c: gave parasite undo a MISC_UNDO class for now so it compiles * app/tools_cmds.c: fix crop invoker to give correct args to crop_image * app/color_cmds.c: s/GRAY/GRAY_LUT/g; * app/brush_select.[ch]: removed PDB procs, export brush_active_dialogs, brush_select_dialog, s/active_dialogs/brush_active_dialogs/ * app/gimage_cmds.[ch] * app/channel_ops.[ch]: removed channel ops PDB procs, moved duplicate function from gimage_cmds to channel_ops, export offset and duplicate * app/gimpbrushlist.[ch]: removed PDB procs * app/gradient.[ch]: removed PDB procs, * app/gradient_header.h: exported G_SAMPLE, GradSelect, num_gradients, grad_active_dialogs, gradient_select_dialog * app/gradient_select.c: removed PDB procs, s/active_dialogs/grad_active_dialogs/ * app/patterns.[ch]: removed PDB procs * app/pattern_select.[ch]: removed PDB procs, s/active_dialogs/pattern_active_dialogs/ * app/procedural_db.c: removed PDB procs and supporting functions * app/procedrual_db.h: fiddled with enums * app/channel_cmds.[ch] * app/drawable_cmds.[ch] * app/parasite_cmds.[ch]: pdbgenned now, removed header files * app/gimpparasite.c: minor cleanup * app/internal_procs.c: use pdbgen stuff * app/tools_cmds.c * app/text_tool_cmds.c: updated from pdbgen * app/brushes_cmds.c * app/brush_select_cmds.c * app/gradient_cmds.c * app/gradient_select_cmds.c * app/patterns_cmds.c * app/pattern_select_cmds.c * app/procedural_db_cmds.c: new pdbgen files * app/Makefile.am: file shuffle (see above) -Yosh
1999-04-24 04:54:02 +08:00
#include "parasitelist.h"
1997-11-25 06:05:25 +08:00
#include "tools.h"
#include "transform_core.h"
#include "undo.h"
#include "drawable_pvt.h"
#include "layer_pvt.h"
#include "channel_pvt.h"
#include "tile_manager_pvt.h"
1998-08-12 01:35:34 +08:00
#include "tile.h" /* ick. */
#include "libgimp/parasite.h"
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
#include "libgimp/gimpintl.h"
#include "gimpparasite.h"
1997-11-25 06:05:25 +08:00
typedef int (* UndoPopFunc) (GImage *, int, int, void *);
typedef void (* UndoFreeFunc) (int, void *);
typedef struct _undo Undo;
struct _undo
{
int type; /* undo type */
void * data; /* data to implement the undo */
long bytes; /* size of undo item */
UndoPopFunc pop_func; /* function pointer to undo pop proc */
UndoFreeFunc free_func; /* function with specifics for freeing */
};
/* Pop functions */
int undo_pop_image (GImage *, int, int, void *);
int undo_pop_mask (GImage *, int, int, void *);
int undo_pop_layer_displace (GImage *, int, int, void *);
int undo_pop_transform (GImage *, int, int, void *);
int undo_pop_paint (GImage *, int, int, void *);
int undo_pop_layer (GImage *, int, int, void *);
int undo_pop_layer_mod (GImage *, int, int, void *);
int undo_pop_layer_mask (GImage *, int, int, void *);
int undo_pop_channel (GImage *, int, int, void *);
int undo_pop_channel_mod (GImage *, int, int, void *);
int undo_pop_fs_to_layer (GImage *, int, int, void *);
int undo_pop_fs_rigor (GImage *, int, int, void *);
int undo_pop_fs_relax (GImage *, int, int, void *);
int undo_pop_gimage_mod (GImage *, int, int, void *);
int undo_pop_guide (GImage *, int, int, void *);
int undo_pop_parasite (GImage *, int, int, void *);
int undo_pop_qmask (GImage *, int, int, void *);
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
static int undo_pop_layer_rename (GImage *, int, int, void *);
static int undo_pop_cantundo (GImage *, int, int, void *);
1997-11-25 06:05:25 +08:00
/* Free functions */
void undo_free_image (int, void *);
void undo_free_mask (int, void *);
void undo_free_layer_displace (int, void *);
void undo_free_transform (int, void *);
void undo_free_paint (int, void *);
void undo_free_layer (int, void *);
void undo_free_layer_mod (int, void *);
void undo_free_layer_mask (int, void *);
void undo_free_channel (int, void *);
void undo_free_channel_mod (int, void *);
void undo_free_fs_to_layer (int, void *);
void undo_free_fs_rigor (int, void *);
void undo_free_fs_relax (int, void *);
void undo_free_gimage_mod (int, void *);
void undo_free_guide (int, void *);
void undo_free_parasite (int, void *);
void undo_free_qmask (int, void *);
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
static void undo_free_layer_rename (int, void *);
static void undo_free_cantundo (int, void *);
1997-11-25 06:05:25 +08:00
/* Sizing functions */
1999-07-20 03:46:05 +08:00
static int layer_size (Layer *);
static int channel_size (Channel *);
1997-11-25 06:05:25 +08:00
static int shrink_wrap = FALSE;
#define UNDO 0
#define REDO 1
static int
layer_size (Layer *layer)
{
int size;
1999-07-20 03:46:05 +08:00
size = sizeof (Layer) +
GIMP_DRAWABLE(layer)->width * GIMP_DRAWABLE(layer)->height * GIMP_DRAWABLE(layer)->bytes +
strlen (GIMP_DRAWABLE(layer)->name);
1997-11-25 06:05:25 +08:00
if (layer_get_mask (layer))
size += channel_size (GIMP_CHANNEL (layer_get_mask (layer)));
1997-11-25 06:05:25 +08:00
return size;
}
static int
channel_size (Channel *channel)
{
int size;
size = sizeof (Channel) + GIMP_DRAWABLE(channel)->width * GIMP_DRAWABLE(channel)->height +
strlen (GIMP_DRAWABLE(channel)->name);
1997-11-25 06:05:25 +08:00
return size;
}
static void
undo_free_list (GImage *gimage,
int state,
GSList *list)
1997-11-25 06:05:25 +08:00
{
GSList * orig;
1997-11-25 06:05:25 +08:00
Undo * undo;
orig = list;
while (list)
{
undo = (Undo *) list->data;
if (undo)
{
(* undo->free_func) (state, undo->data);
gimage->undo_bytes -= undo->bytes;
g_free (undo);
}
list = g_slist_next (list);
1997-11-25 06:05:25 +08:00
}
g_slist_free (orig);
1997-11-25 06:05:25 +08:00
}
static GSList *
1997-11-25 06:05:25 +08:00
remove_stack_bottom (GImage *gimage)
{
GSList *list;
GSList *last;
1997-11-25 06:05:25 +08:00
int in_group = 0;
list = gimage->undo_stack;
last = NULL;
while (list)
{
if (list->next == NULL)
{
if (last)
undo_free_list (gimage, UNDO, last->next);
else
undo_free_list (gimage, UNDO, list);
gimage->undo_levels --;
if (last)
last->next = NULL;
list = NULL;
}
else
{
if (list->data == NULL)
in_group = (in_group) ? 0 : 1;
/* Make sure last points to only a single item, or the
* tail of an aggregate undo item
*/
if ((list->data && !in_group) ||
(!list->data && !in_group))
last = list;
list = g_slist_next (list);
1997-11-25 06:05:25 +08:00
}
}
if (last)
return gimage->undo_stack;
else
return NULL;
}
static int
undo_free_up_space (GImage *gimage)
{
/* If there are 0 levels of undo return FALSE.
*/
if (levels_of_undo == 0)
return FALSE;
/* Delete the item on the bottom of the stack if we have the maximum
* levels of undo already
*/
while (gimage->undo_levels >= levels_of_undo)
gimage->undo_stack = remove_stack_bottom (gimage);
return TRUE;
}
static Undo *
undo_push (GImage *gimage,
long size,
int type)
{
Undo * new;
if (! gimage->undo_on)
return NULL;
size += sizeof (Undo);
if (gimage->redo_stack)
{
undo_free_list (gimage, REDO, gimage->redo_stack);
gimage->redo_stack = NULL;
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
/* If the image was dirty, but could become clean by redo-ing
* some actions, then it should now become 'infinitely' dirty.
* This is because we've just nuked the actions that would allow
* the image to become clean again. The only hope for salvation
* is to save the image now! -- austin */
if (gimage->dirty < 0)
gimage->dirty = 10000;
1997-11-25 06:05:25 +08:00
}
if (!gimage->pushing_undo_group)
if (! undo_free_up_space (gimage))
return NULL;
new = (Undo *) g_malloc (sizeof (Undo));
new->bytes = size;
gimage->undo_bytes += size;
if (!gimage->pushing_undo_group) /* only increment levels if not in a group */
{
new->type = type;
gimage->undo_levels ++;
}
else
new->type = gimage->pushing_undo_group;
gimage->undo_stack = g_slist_prepend (gimage->undo_stack, (void *) new);
1997-11-25 06:05:25 +08:00
return new;
}
static int
pop_stack (GImage *gimage,
GSList **stack_ptr,
GSList **unstack_ptr,
1999-07-20 03:46:05 +08:00
int state)
1997-11-25 06:05:25 +08:00
{
Undo * object;
GSList *stack;
GSList *tmp;
1997-11-25 06:05:25 +08:00
int status = 0;
int in_group = 0;
int x, y;
GDisplay *gdisp;
1997-11-25 06:05:25 +08:00
/* Keep popping until we pop a valid object
* or get to the end of a group if we're in one
*/
while (*stack_ptr)
{
stack = *stack_ptr;
object = (Undo *) stack->data;
if (object == NULL)
{
in_group = (in_group) ? 0 : 1;
if (in_group)
gimage->undo_levels += (state == UNDO) ? -1 : 1;
if (status && !in_group)
status = 1;
else
status = 0;
}
else
{
status = (* object->pop_func) (gimage, state, object->type, object->data);
if (!in_group)
gimage->undo_levels += (state == UNDO) ? -1 : 1;
}
*unstack_ptr = g_slist_prepend (*unstack_ptr, (void *) object);
1997-11-25 06:05:25 +08:00
tmp = stack;
*stack_ptr = g_slist_next (*stack_ptr);
1997-11-25 06:05:25 +08:00
tmp->next = NULL;
g_slist_free (tmp);
1997-11-25 06:05:25 +08:00
if (status && !in_group)
{
/* Flush any image updates and displays */
gdisp = gdisplay_active();
if (gdisp != NULL) {
if (gdisp->disp_xoffset || gdisp->disp_yoffset)
{
gdk_window_get_size (gdisp->canvas->window, &x, &y);
if (gdisp->disp_yoffset)
{
gdisplay_expose_area (gdisp, 0, 0, gdisp->disp_width,
gdisp->disp_yoffset);
gdisplay_expose_area (gdisp, 0, gdisp->disp_yoffset + y,
gdisp->disp_width, gdisp->disp_height);
}
if (gdisp->disp_xoffset)
{
gdisplay_expose_area (gdisp, 0, 0, gdisp->disp_xoffset,
gdisp->disp_height);
gdisplay_expose_area (gdisp, gdisp->disp_xoffset + x, 0,
gdisp->disp_width, gdisp->disp_height);
}
}
}
1997-11-25 06:05:25 +08:00
gdisplays_flush ();
/* If the shrink_wrap flag was set */
if (shrink_wrap)
{
gdisplays_shrink_wrap (gimage);
1997-11-25 06:05:25 +08:00
shrink_wrap = FALSE;
}
return TRUE;
}
}
return FALSE;
}
int
undo_pop (GImage *gimage)
{
return pop_stack (gimage, &gimage->undo_stack, &gimage->redo_stack, UNDO);
}
int
undo_redo (GImage *gimage)
{
return pop_stack (gimage, &gimage->redo_stack, &gimage->undo_stack, REDO);
}
void
undo_free (GImage *gimage)
{
undo_free_list (gimage, UNDO, gimage->undo_stack);
undo_free_list (gimage, REDO, gimage->redo_stack);
gimage->undo_stack = NULL;
gimage->redo_stack = NULL;
gimage->undo_bytes = 0;
gimage->undo_levels = 0;
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
/* If the image was dirty, but could become clean by redo-ing
* some actions, then it should now become 'infinitely' dirty.
* This is because we've just nuked the actions that would allow
* the image to become clean again. The only hope for salvation
* is to save the image now! -- austin */
if (gimage->dirty < 0)
gimage->dirty = 10000;
/* The same applies to the case where the image would become clean
* due to undo actions, but since user can't undo without an undo
* stack, that's not so much a problem. */
1997-11-25 06:05:25 +08:00
}
/**********************/
/* group Undo funcs */
int
undo_push_group_start (GImage *gimage,
int type)
{
if (! gimage->undo_on)
return FALSE;
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
gimage->group_count ++;
1997-11-25 06:05:25 +08:00
/* If we're already in a group...ignore */
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
if (gimage->group_count > 1)
1997-11-25 06:05:25 +08:00
return TRUE;
if (gimage->redo_stack)
{
undo_free_list (gimage, REDO, gimage->redo_stack);
gimage->redo_stack = NULL;
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
/* If the image was dirty, but could become clean by redo-ing
* some actions, then it should now become 'infinitely' dirty.
* This is because we've just nuked the actions that would allow
* the image to become clean again. The only hope for salvation
* is to save the image now! -- austin */
if (gimage->dirty < 0)
gimage->dirty = 10000;
1997-11-25 06:05:25 +08:00
}
if (! undo_free_up_space (gimage))
return FALSE;
gimage->pushing_undo_group = type;
gimage->undo_stack = g_slist_prepend (gimage->undo_stack, NULL);
1997-11-25 06:05:25 +08:00
gimage->undo_levels++;
return TRUE;
}
int
undo_push_group_end (GImage *gimage)
{
if (! gimage->undo_on)
return FALSE;
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
gimage->group_count --;
1997-11-25 06:05:25 +08:00
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
if (gimage->group_count == 0)
1997-11-25 06:05:25 +08:00
{
gimage->pushing_undo_group = 0;
gimage->undo_stack = g_slist_prepend (gimage->undo_stack, NULL);
1997-11-25 06:05:25 +08:00
}
return TRUE;
}
/*********************************/
/* Image Undo functions */
typedef struct _image_undo ImageUndo;
struct _image_undo
{
TileManager *tiles;
GimpDrawable *drawable;
1997-11-25 06:05:25 +08:00
int x1, y1, x2, y2;
int sparse;
};
int
1999-07-20 03:46:05 +08:00
undo_push_image (GImage *gimage,
GimpDrawable *drawable,
1999-07-20 03:46:05 +08:00
int x1,
int y1,
int x2,
int y2)
1997-11-25 06:05:25 +08:00
{
long size;
Undo *new;
ImageUndo *image_undo;
TileManager *tiles;
PixelRegion srcPR, destPR;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (drawable);
1997-11-25 06:05:25 +08:00
x1 = BOUNDS (x1, 0, drawable_width (drawable));
y1 = BOUNDS (y1, 0, drawable_height (drawable));
x2 = BOUNDS (x2, 0, drawable_width (drawable));
y2 = BOUNDS (y2, 0, drawable_height (drawable));
size = (x2 - x1) * (y2 - y1) * drawable_bytes (drawable) + sizeof (void *) * 2;
1997-11-25 06:05:25 +08:00
if ((new = undo_push (gimage, size, IMAGE_UNDO)))
{
image_undo = (ImageUndo *) g_malloc (sizeof (ImageUndo));
/* If we cannot create a new temp buf--either because our parameters are
* degenerate or something else failed, simply return an unsuccessful push.
*/
tiles = tile_manager_new ((x2 - x1), (y2 - y1), drawable_bytes (drawable));
pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE);
1997-11-25 06:05:25 +08:00
pixel_region_init (&destPR, tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE);
copy_region (&srcPR, &destPR);
/* set the image undo structure */
image_undo->tiles = tiles;
image_undo->drawable = drawable;
1997-11-25 06:05:25 +08:00
image_undo->x1 = x1;
image_undo->y1 = y1;
image_undo->x2 = x2;
image_undo->y2 = y2;
image_undo->sparse = FALSE;
new->data = image_undo;
new->pop_func = undo_pop_image;
new->free_func = undo_free_image;
return TRUE;
}
else
return FALSE;
}
int
1999-07-20 03:46:05 +08:00
undo_push_image_mod (GImage *gimage,
GimpDrawable *drawable,
1999-07-20 03:46:05 +08:00
int x1,
int y1,
int x2,
int y2,
void *tiles_ptr,
int sparse)
1997-11-25 06:05:25 +08:00
{
long size;
int dwidth, dheight;
1997-11-25 06:05:25 +08:00
Undo * new;
ImageUndo *image_undo;
TileManager *tiles;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (drawable);
1997-11-25 06:05:25 +08:00
if (! tiles_ptr)
return FALSE;
dwidth = drawable_width (drawable);
dheight = drawable_height (drawable);
x1 = BOUNDS (x1, 0, dwidth);
y1 = BOUNDS (y1, 0, dheight);
x2 = BOUNDS (x2, 0, dwidth);
y2 = BOUNDS (y2, 0, dheight);
1997-11-25 06:05:25 +08:00
tiles = (TileManager *) tiles_ptr;
size = tiles->width * tiles->height *
tiles->bpp + sizeof (void *) * 2;
1997-11-25 06:05:25 +08:00
if ((new = undo_push (gimage, size, IMAGE_MOD_UNDO)))
{
image_undo = (ImageUndo *) g_malloc (sizeof (ImageUndo));
image_undo->tiles = tiles;
image_undo->drawable = drawable;
1997-11-25 06:05:25 +08:00
image_undo->x1 = x1;
image_undo->y1 = y1;
image_undo->x2 = x2;
image_undo->y2 = y2;
image_undo->sparse = sparse;
new->data = image_undo;
new->pop_func = undo_pop_image;
new->free_func = undo_free_image;
return TRUE;
}
else
{
tile_manager_destroy (tiles);
return FALSE;
}
}
int
undo_pop_image (GImage *gimage,
int state,
int type,
void *image_undo_ptr)
{
ImageUndo *image_undo;
TileManager *tiles;
PixelRegion PR1, PR2;
int x, y;
int w, h;
image_undo = (ImageUndo *) image_undo_ptr;
tiles = image_undo->tiles;
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (image_undo->drawable);
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (image_undo->drawable);
break;
}
/* some useful values */
x = image_undo->x1;
y = image_undo->y1;
if (image_undo->sparse == FALSE)
{
w = tiles->width;
h = tiles->height;
1997-11-25 06:05:25 +08:00
pixel_region_init (&PR1, tiles, 0, 0, w, h, TRUE);
pixel_region_init (&PR2, drawable_data (image_undo->drawable), x, y, w, h, TRUE);
/* swap the regions */
swap_region (&PR1, &PR2);
}
else
{
int i, j;
Tile *src_tile;
Tile *dest_tile;
w = image_undo->x2 - image_undo->x1;
h = image_undo->y2 - image_undo->y1;
for (i = y; i < image_undo->y2; i += (TILE_HEIGHT - (i % TILE_HEIGHT)))
{
for (j = x; j < image_undo->x2; j += (TILE_WIDTH - (j % TILE_WIDTH)))
{
src_tile = tile_manager_get_tile (tiles, j, i, FALSE, FALSE);
1998-08-12 01:35:34 +08:00
if (tile_is_valid (src_tile) == TRUE)
1997-11-25 06:05:25 +08:00
{
1998-08-12 01:35:34 +08:00
/* swap tiles, not pixels! */
src_tile = tile_manager_get_tile (tiles, j, i, TRUE, FALSE /* TRUE */);
dest_tile = tile_manager_get_tile (drawable_data (image_undo->drawable), j, i, TRUE, FALSE /* TRUE */);
1998-08-12 01:35:34 +08:00
tile_manager_map_tile (tiles, j, i, dest_tile);
tile_manager_map_tile (drawable_data (image_undo->drawable), j, i, src_tile);
1998-08-12 01:35:34 +08:00
#if 0
swap_pixels (tile_data_pointer (src_tile, 0, 0),
tile_data_pointer (dest_tile, 0, 0),
tile_size (src_tile));
#endif
tile_release (dest_tile, FALSE /* TRUE */);
tile_release (src_tile, FALSE /* TRUE */);
1997-11-25 06:05:25 +08:00
}
}
}
}
drawable_update (image_undo->drawable, x, y, w, h);
return TRUE;
}
void
undo_free_image (int state,
void *image_undo_ptr)
{
ImageUndo *image_undo;
image_undo = (ImageUndo *) image_undo_ptr;
tile_manager_destroy (image_undo->tiles);
g_free (image_undo);
}
/******************************/
/* Mask Undo functions */
int
undo_push_mask (GImage *gimage,
void *mask_ptr)
{
Undo *new;
MaskUndo *mask_undo;
int size;
mask_undo = (MaskUndo *) mask_ptr;
if (mask_undo->tiles)
size = mask_undo->tiles->width * mask_undo->tiles->height;
1997-11-25 06:05:25 +08:00
else
size = 0;
if ((new = undo_push (gimage, size, MASK_UNDO)))
{
new->data = mask_undo;
new->pop_func = undo_pop_mask;
new->free_func = undo_free_mask;
return TRUE;
}
else
{
if (mask_undo->tiles)
tile_manager_destroy (mask_undo->tiles);
g_free (mask_undo);
return FALSE;
}
}
int
undo_pop_mask (GImage *gimage,
int state,
int type,
void *mask_ptr)
{
MaskUndo *mask_undo;
TileManager *new_tiles;
Channel *sel_mask;
PixelRegion srcPR, destPR;
int selection;
int x1, y1, x2, y2;
int width, height;
unsigned char empty = 0;
width = height = 0;
mask_undo = (MaskUndo *) mask_ptr;
/* save current selection mask */
sel_mask = gimage_get_mask (gimage);
selection = channel_bounds (sel_mask, &x1, &y1, &x2, &y2);
pixel_region_init (&srcPR, GIMP_DRAWABLE(sel_mask)->tiles, x1, y1, (x2 - x1), (y2 - y1), FALSE);
1997-11-25 06:05:25 +08:00
if (selection)
{
new_tiles = tile_manager_new (srcPR.w, srcPR.h, 1);
pixel_region_init (&destPR, new_tiles, 0, 0, srcPR.w, srcPR.h, TRUE);
copy_region (&srcPR, &destPR);
pixel_region_init (&srcPR, GIMP_DRAWABLE(sel_mask)->tiles, x1, y1, (x2 - x1), (y2 - y1), TRUE);
1997-11-25 06:05:25 +08:00
color_region (&srcPR, &empty);
}
else
new_tiles = NULL;
if (mask_undo->tiles)
{
width = mask_undo->tiles->width;
height = mask_undo->tiles->height;
1997-11-25 06:05:25 +08:00
pixel_region_init (&srcPR, mask_undo->tiles, 0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE(sel_mask)->tiles, mask_undo->x, mask_undo->y, width, height, TRUE);
1997-11-25 06:05:25 +08:00
copy_region (&srcPR, &destPR);
tile_manager_destroy (mask_undo->tiles);
}
/* invalidate the current bounds and boundary of the mask */
gimage_mask_invalidate (gimage);
if (mask_undo->tiles)
{
sel_mask->empty = FALSE;
sel_mask->x1 = mask_undo->x;
sel_mask->y1 = mask_undo->y;
sel_mask->x2 = mask_undo->x + width;
sel_mask->y2 = mask_undo->y + height;
}
else
{
sel_mask->empty = TRUE;
sel_mask->x1 = 0;
sel_mask->y1 = 0;
sel_mask->x2 = GIMP_DRAWABLE(sel_mask)->width;
sel_mask->y2 = GIMP_DRAWABLE(sel_mask)->height;
1997-11-25 06:05:25 +08:00
}
/* set the new mask undo parameters */
mask_undo->tiles = new_tiles;
mask_undo->x = x1;
mask_undo->y = y1;
/* we know the bounds */
sel_mask->bounds_known = TRUE;
/* if there is a "by color" selection dialog active
* for this gimage's mask, send it an update notice
*/
if (gimage->by_color_select)
by_color_select_initialize_by_image (gimage);
1997-11-25 06:05:25 +08:00
return TRUE;
}
void
undo_free_mask (int state,
void *mask_ptr)
{
MaskUndo *mask_undo;
mask_undo = (MaskUndo *) mask_ptr;
if (mask_undo->tiles)
tile_manager_destroy (mask_undo->tiles);
g_free (mask_undo);
}
/***************************************/
/* Layer displacement Undo functions */
int
1999-07-20 03:46:05 +08:00
undo_push_layer_displace (GImage *gimage,
GimpLayer *layer)
1997-11-25 06:05:25 +08:00
{
Undo * new;
int * info;
if ((new = undo_push (gimage, 12, LAYER_DISPLACE_UNDO)))
{
new->data = (void *) g_malloc (sizeof (int) * 3);
new->pop_func = undo_pop_layer_displace;
new->free_func = undo_free_layer_displace;
info = (int *) new->data;
info[0] = drawable_ID(GIMP_DRAWABLE(layer));
info[1] = GIMP_DRAWABLE(layer)->offset_x;
info[2] = GIMP_DRAWABLE(layer)->offset_y;
1997-11-25 06:05:25 +08:00
return TRUE;
}
else
return FALSE;
}
int
undo_pop_layer_displace (GImage *gimage,
int state,
int type,
void *info_ptr)
{
Layer * layer;
int old_offsets[2];
int *info;
info = (int *) info_ptr;
layer = layer_get_ID (info[0]);
if (layer)
{
old_offsets[0] = GIMP_DRAWABLE(layer)->offset_x;
old_offsets[1] = GIMP_DRAWABLE(layer)->offset_y;
drawable_update (GIMP_DRAWABLE(layer), 0, 0,
GIMP_DRAWABLE(layer)->width,
GIMP_DRAWABLE(layer)->height);
GIMP_DRAWABLE(layer)->offset_x = info[1];
GIMP_DRAWABLE(layer)->offset_y = info[2];
drawable_update (GIMP_DRAWABLE(layer), 0, 0,
GIMP_DRAWABLE(layer)->width,
GIMP_DRAWABLE(layer)->height);
if (layer->mask)
{
GIMP_DRAWABLE(layer->mask)->offset_x = info[1];
GIMP_DRAWABLE(layer->mask)->offset_y = info[2];
drawable_update (GIMP_DRAWABLE(layer->mask), 0, 0,
GIMP_DRAWABLE(layer->mask)->width,
GIMP_DRAWABLE(layer->mask)->height);
}
1997-11-25 06:05:25 +08:00
/* invalidate the selection boundary because of a layer modification */
layer_invalidate_boundary (layer);
info[1] = old_offsets[0];
info[2] = old_offsets[1];
return TRUE;
}
else
return FALSE;
}
void
undo_free_layer_displace (int state,
void *info_ptr)
{
g_free (info_ptr);
}
/*********************************/
/* Transform Undo */
int
undo_push_transform (GImage *gimage,
void *tu_ptr)
{
Undo * new;
int size;
size = sizeof (TransformUndo);
if ((new = undo_push (gimage, size, TRANSFORM_UNDO)))
{
new->data = tu_ptr;
new->pop_func = undo_pop_transform;
new->free_func = undo_free_transform;
return TRUE;
}
else
{
g_free (tu_ptr);
return FALSE;
}
}
int
undo_pop_transform (GImage *gimage,
int state,
int type,
void *tu_ptr)
{
TransformCore * tc;
TransformUndo * tu;
TileManager * temp;
double d;
int i;
/* Can't have ANY tool selected - maybe a plugin running */
if (active_tool == NULL)
return TRUE;
1997-11-25 06:05:25 +08:00
tc = (TransformCore *) active_tool->private;
tu = (TransformUndo *) tu_ptr;
paths_transform_do_undo(gimage,tu->path_undo);
1997-11-25 06:05:25 +08:00
/* only pop if the active tool is the tool that pushed this undo */
if (tu->tool_ID != active_tool->ID)
return TRUE;
/* swap the transformation information arrays */
for (i = 0; i < TRAN_INFO_SIZE; i++)
{
d = tu->trans_info[i];
tu->trans_info[i] = tc->trans_info[i];
tc->trans_info[i] = d;
}
/* swap the original buffer--the source buffer for repeated transforms
1997-11-25 06:05:25 +08:00
*/
temp = tu->original;
tu->original = tc->original;
tc->original = temp;
1997-11-25 06:05:25 +08:00
/* If we're re-implementing the first transform, reactivate tool */
if (state == REDO && tc->original)
{
active_tool->state = ACTIVE;
draw_core_resume (tc->core, active_tool);
1997-11-25 06:05:25 +08:00
}
return TRUE;
}
void
undo_free_transform (int state,
void *tu_ptr)
{
TransformUndo * tu;
tu = (TransformUndo *) tu_ptr;
if (tu->original)
tile_manager_destroy (tu->original);
paths_transform_free_undo(tu->path_undo);
1997-11-25 06:05:25 +08:00
g_free (tu);
}
/*********************************/
/* Paint Undo */
int
undo_push_paint (GImage *gimage,
void *pu_ptr)
{
Undo * new;
int size;
size = sizeof (PaintUndo);
if ((new = undo_push (gimage, size, PAINT_UNDO)))
{
new->data = pu_ptr;
new->pop_func = undo_pop_paint;
new->free_func = undo_free_paint;
return TRUE;
}
else
{
g_free (pu_ptr);
return FALSE;
}
}
int
undo_pop_paint (GImage *gimage,
int state,
int type,
void *pu_ptr)
{
PaintCore * pc;
PaintUndo * pu;
double tmp;
/* Can't have ANY tool selected - maybe a plugin running */
if (active_tool == NULL)
return TRUE;
1997-11-25 06:05:25 +08:00
pc = (PaintCore *) active_tool->private;
pu = (PaintUndo *) pu_ptr;
/* only pop if the active tool is the tool that pushed this undo */
if (pu->tool_ID != active_tool->ID)
return TRUE;
/* swap the paint core information */
tmp = pc->lastx;
pc->lastx = pu->lastx;
pu->lastx = tmp;
tmp = pc->lasty;
pc->lasty = pu->lasty;
pu->lasty = tmp;
tmp = pc->lastpressure;
pc->lastpressure = pu->lastpressure;
pu->lastpressure = tmp;
tmp = pc->lastxtilt;
pc->lastxtilt = pu->lastxtilt;
pu->lastxtilt = tmp;
tmp = pc->lastytilt;
pc->lastytilt = pu->lastytilt;
pu->lastytilt = tmp;
1997-11-25 06:05:25 +08:00
return TRUE;
}
void
undo_free_paint (int state,
void *pu_ptr)
{
PaintUndo * pu;
pu = (PaintUndo *) pu_ptr;
g_free (pu);
}
/*********************************/
/* New Layer Undo */
int
undo_push_layer (GImage *gimage,
void *lu_ptr)
{
LayerUndo *lu;
Undo *new;
int size;
lu = (LayerUndo *) lu_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(lu->layer));
1997-11-25 06:05:25 +08:00
size = layer_size (lu->layer) + sizeof (LayerUndo);
if ((new = undo_push (gimage, size, LAYER_UNDO)))
{
new->data = lu_ptr;
new->pop_func = undo_pop_layer;
new->free_func = undo_free_layer;
return TRUE;
}
else
{
/* if this is a remove layer, delete the layer */
if (lu->undo_type == 1)
layer_unref (lu->layer);
1997-11-25 06:05:25 +08:00
g_free (lu);
return FALSE;
}
}
1997-11-25 06:05:25 +08:00
int
undo_pop_layer (GImage *gimage,
int state,
int type,
void *lu_ptr)
{
LayerUndo *lu;
lu = (LayerUndo *) lu_ptr;
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(lu->layer));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(lu->layer));
1997-11-25 06:05:25 +08:00
break;
}
/* remove layer */
if ((state == UNDO && lu->undo_type == 0) ||
(state == REDO && lu->undo_type == 1))
{
/* record the current position */
lu->prev_position = gimage_get_layer_index (gimage, lu->layer);
1997-11-25 06:05:25 +08:00
/* set the previous layer */
gimage_set_active_layer (gimage, lu->prev_layer);
/* remove the layer */
gimage->layers = g_slist_remove (gimage->layers, lu->layer);
gimage->layer_stack = g_slist_remove (gimage->layer_stack, lu->layer);
1997-11-25 06:05:25 +08:00
/* reset the gimage values */
if (layer_is_floating_sel (lu->layer))
{
gimage->floating_sel = NULL;
1997-11-25 06:05:25 +08:00
/* reset the old drawable */
floating_sel_reset (lu->layer);
}
drawable_update (GIMP_DRAWABLE(lu->layer), 0, 0,
GIMP_DRAWABLE(lu->layer)->width,
GIMP_DRAWABLE(lu->layer)->height);
1997-11-25 06:05:25 +08:00
}
/* restore layer */
else
{
/* record the active layer */
lu->prev_layer = gimage->active_layer;
/* hide the current selection--for all views */
if (gimage->active_layer != NULL)
layer_invalidate_boundary ((gimage->active_layer));
1997-11-25 06:05:25 +08:00
/* if this is a floating selection, set the fs pointer */
if (layer_is_floating_sel (lu->layer))
gimage->floating_sel = lu->layer;
1997-11-25 06:05:25 +08:00
/* add the new layer */
gimage->layers = g_slist_insert (gimage->layers, lu->layer,
lu->prev_position);
gimage->layer_stack = g_slist_prepend (gimage->layer_stack, lu->layer);
gimage->active_layer = lu->layer;
drawable_update (GIMP_DRAWABLE(lu->layer), 0, 0,
GIMP_DRAWABLE(lu->layer)->width,
GIMP_DRAWABLE(lu->layer)->height);
1997-11-25 06:05:25 +08:00
}
return TRUE;
}
void
undo_free_layer (int state,
void *lu_ptr)
{
LayerUndo *lu;
lu = (LayerUndo *) lu_ptr;
/* Only free the layer if we're freeing from the redo
* stack and it's a layer add, or if we're freeing from
* the undo stack and it's a layer remove
*/
if ((state == REDO && lu->undo_type == 0) ||
(state == UNDO && lu->undo_type == 1))
layer_unref (lu->layer);
1997-11-25 06:05:25 +08:00
g_free (lu);
}
/*********************************/
/* Layer Mod Undo */
int
undo_push_layer_mod (GImage *gimage,
void *layer_ptr)
{
Layer *layer;
Undo *new;
TileManager *tiles;
void **data;
int size;
layer = (Layer *) layer_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(layer));
1997-11-25 06:05:25 +08:00
tiles = GIMP_DRAWABLE(layer)->tiles;
tiles->x = GIMP_DRAWABLE(layer)->offset_x;
tiles->y = GIMP_DRAWABLE(layer)->offset_y;
1999-07-20 03:46:05 +08:00
size = GIMP_DRAWABLE(layer)->width * GIMP_DRAWABLE(layer)->height *
GIMP_DRAWABLE(layer)->bytes + sizeof (void *) * 3;
1997-11-25 06:05:25 +08:00
if ((new = undo_push (gimage, size, LAYER_MOD)))
{
data = (void **) g_malloc (sizeof (void *) * 3);
new->data = data;
new->pop_func = undo_pop_layer_mod;
new->free_func = undo_free_layer_mod;
data[0] = layer_ptr;
data[1] = (void *) tiles;
data[2] = (void *) ((long) GIMP_DRAWABLE(layer)->type);
1997-11-25 06:05:25 +08:00
return TRUE;
}
else
{
tile_manager_destroy (tiles);
return FALSE;
}
}
int
undo_pop_layer_mod (GImage *gimage,
int state,
int type,
void *data_ptr)
{
void **data;
int layer_type;
TileManager *tiles;
TileManager *temp;
Layer *layer;
data = (void **) data_ptr;
layer = (Layer *) data[0];
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(layer));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(layer));
1997-11-25 06:05:25 +08:00
break;
}
tiles = (TileManager *) data[1];
/* Issue the first update */
gdisplays_update_area (gimage,
GIMP_DRAWABLE(layer)->offset_x, GIMP_DRAWABLE(layer)->offset_y,
GIMP_DRAWABLE(layer)->width, GIMP_DRAWABLE(layer)->height);
1997-11-25 06:05:25 +08:00
/* Create a tile manager to store the current layer contents */
temp = GIMP_DRAWABLE(layer)->tiles;
temp->x = GIMP_DRAWABLE(layer)->offset_x;
temp->y = GIMP_DRAWABLE(layer)->offset_y;
1997-11-25 06:05:25 +08:00
layer_type = (long) data[2];
data[2] = (void *) ((long) GIMP_DRAWABLE(layer)->type);
1997-11-25 06:05:25 +08:00
/* restore the layer's data */
GIMP_DRAWABLE(layer)->tiles = tiles;
GIMP_DRAWABLE(layer)->offset_x = tiles->x;
GIMP_DRAWABLE(layer)->offset_y = tiles->y;
GIMP_DRAWABLE(layer)->width = tiles->width;
GIMP_DRAWABLE(layer)->height = tiles->height;
GIMP_DRAWABLE(layer)->bytes = tiles->bpp;
GIMP_DRAWABLE(layer)->type = layer_type;
GIMP_DRAWABLE(layer)->has_alpha = TYPE_HAS_ALPHA (layer_type);
if (layer->mask)
{
GIMP_DRAWABLE(layer->mask)->offset_x = tiles->x;
GIMP_DRAWABLE(layer->mask)->offset_y = tiles->y;
}
1997-11-25 06:05:25 +08:00
/* If the layer type changed, update the gdisplay titles */
if (GIMP_DRAWABLE(layer)->type != (long) data[2])
gdisplays_update_title (GIMP_DRAWABLE(layer)->gimage);
1997-11-25 06:05:25 +08:00
/* Set the new tile manager */
data[1] = temp;
/* Issue the second update */
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(layer), 0, 0,
GIMP_DRAWABLE(layer)->width, GIMP_DRAWABLE(layer)->height);
1997-11-25 06:05:25 +08:00
return TRUE;
}
void
undo_free_layer_mod (int state,
void *data_ptr)
{
void ** data;
data = (void **) data_ptr;
tile_manager_destroy ((TileManager *) data[1]);
g_free (data);
}
/*********************************/
/* Layer Mask Undo */
int
undo_push_layer_mask (GImage *gimage,
void *lmu_ptr)
{
LayerMaskUndo *lmu;
Undo *new;
int size;
lmu = (LayerMaskUndo *) lmu_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(lmu->layer));
1997-11-25 06:05:25 +08:00
size = channel_size (GIMP_CHANNEL (lmu->mask)) + sizeof (LayerMaskUndo);
1997-11-25 06:05:25 +08:00
if ((new = undo_push (gimage, size, LAYER_MASK_UNDO)))
{
new->data = lmu_ptr;
new->pop_func = undo_pop_layer_mask;
new->free_func = undo_free_layer_mask;
return TRUE;
}
else
{
if (lmu->undo_type == 1)
layer_mask_delete (lmu->mask);
1997-11-25 06:05:25 +08:00
g_free (lmu);
return FALSE;
}
}
int
undo_pop_layer_mask (GImage *gimage,
int state,
int type,
void *lmu_ptr)
{
LayerMaskUndo *lmu;
lmu = (LayerMaskUndo *) lmu_ptr;
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(lmu->layer));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(lmu->layer));
1997-11-25 06:05:25 +08:00
break;
}
/* remove layer mask */
if ((state == UNDO && lmu->undo_type == 0) ||
(state == REDO && lmu->undo_type == 1))
{
/* remove the layer mask */
lmu->layer->mask = NULL;
lmu->layer->apply_mask = FALSE;
lmu->layer->edit_mask = FALSE;
lmu->layer->show_mask = FALSE;
1997-11-25 06:05:25 +08:00
/* if this is redoing a remove operation &
* the mode of application was DISCARD or
* this is undoing an add...
*/
if ((state == REDO && lmu->mode == DISCARD) || state == UNDO)
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(lmu->layer), 0, 0,
GIMP_DRAWABLE(lmu->layer)->width, GIMP_DRAWABLE(lmu->layer)->height);
1997-11-25 06:05:25 +08:00
}
/* restore layer */
else
{
lmu->layer->mask = lmu->mask;
1997-11-25 06:05:25 +08:00
lmu->layer->apply_mask = lmu->apply_mask;
lmu->layer->edit_mask = lmu->edit_mask;
lmu->layer->show_mask = lmu->show_mask;
1997-11-25 06:05:25 +08:00
gimage_set_layer_mask_edit (gimage, lmu->layer, lmu->edit_mask);
1997-11-25 06:05:25 +08:00
/* if this is undoing a remove operation &
* the mode of application was DISCARD or
* this is redoing an add
*/
if ((state == UNDO && lmu->mode == DISCARD) || state == REDO)
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(lmu->layer), 0, 0,
GIMP_DRAWABLE(lmu->layer)->width, GIMP_DRAWABLE(lmu->layer)->height);
1997-11-25 06:05:25 +08:00
}
return TRUE;
}
void
undo_free_layer_mask (int state,
void *lmu_ptr)
{
LayerMaskUndo *lmu;
lmu = (LayerMaskUndo *) lmu_ptr;
/* Only free the layer mask if we're freeing from the redo
* stack and it's a layer add, or if we're freeing from
* the undo stack and it's a layer remove
*/
if ((state == REDO && lmu->undo_type == 0) ||
(state == UNDO && lmu->undo_type == 1))
layer_mask_delete (lmu->mask);
1997-11-25 06:05:25 +08:00
g_free (lmu);
}
/*********************************/
/* New Channel Undo */
int
undo_push_channel (GImage *gimage,
void *cu_ptr)
{
ChannelUndo *cu;
Undo *new;
int size;
cu = (ChannelUndo *) cu_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(cu->channel));
1997-11-25 06:05:25 +08:00
size = channel_size (cu->channel) + sizeof (ChannelUndo);
if ((new = undo_push (gimage, size, CHANNEL_UNDO)))
{
new->data = cu_ptr;
new->pop_func = undo_pop_channel;
new->free_func = undo_free_channel;
return TRUE;
}
else
{
if (cu->undo_type == 1)
channel_delete (cu->channel);
g_free (cu);
return FALSE;
}
}
int
undo_pop_channel (GImage *gimage,
int state,
int type,
void *cu_ptr)
{
ChannelUndo *cu;
cu = (ChannelUndo *) cu_ptr;
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(cu->channel));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(cu->channel));
1997-11-25 06:05:25 +08:00
break;
}
/* remove channel */
if ((state == UNDO && cu->undo_type == 0) ||
(state == REDO && cu->undo_type == 1))
{
/* record the current position */
cu->prev_position = gimage_get_channel_index (gimage, cu->channel);
1997-11-25 06:05:25 +08:00
/* remove the channel */
gimage->channels = g_slist_remove (gimage->channels, cu->channel);
1997-11-25 06:05:25 +08:00
/* set the previous channel */
gimage_set_active_channel (gimage, cu->prev_channel);
/* update the area */
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(cu->channel), 0, 0,
GIMP_DRAWABLE(cu->channel)->width, GIMP_DRAWABLE(cu->channel)->height);
1997-11-25 06:05:25 +08:00
}
/* restore channel */
else
{
/* record the active channel */
cu->prev_channel = gimage->active_channel;
/* add the new channel */
gimage->channels = g_slist_insert (gimage->channels, cu->channel, cu->prev_position);
1997-11-25 06:05:25 +08:00
/* set the new channel */
gimage_set_active_channel (gimage, cu->channel);
1997-11-25 06:05:25 +08:00
/* update the area */
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(cu->channel), 0, 0,
GIMP_DRAWABLE(cu->channel)->width, GIMP_DRAWABLE(cu->channel)->height);
1997-11-25 06:05:25 +08:00
}
return TRUE;
}
void
undo_free_channel (int state,
void *cu_ptr)
{
ChannelUndo *cu;
cu = (ChannelUndo *) cu_ptr;
/* Only free the channel if we're freeing from the redo
* stack and it's a channel add, or if we're freeing from
* the undo stack and it's a channel remove
*/
if ((state == REDO && cu->undo_type == 0) ||
(state == UNDO && cu->undo_type == 1))
channel_delete (cu->channel);
g_free (cu);
}
/*********************************/
/* Channel Mod Undo */
int
undo_push_channel_mod (GImage *gimage,
void *channel_ptr)
{
Channel *channel;
TileManager *tiles;
Undo *new;
void **data;
int size;
channel = (Channel *) channel_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(channel));
1997-11-25 06:05:25 +08:00
tiles = GIMP_DRAWABLE(channel)->tiles;
size = GIMP_DRAWABLE(channel)->width * GIMP_DRAWABLE(channel)->height + sizeof (void *) * 2;
1997-11-25 06:05:25 +08:00
if ((new = undo_push (gimage, size, CHANNEL_MOD)))
{
data = (void **) g_malloc (sizeof (void *) * 2);
new->data = data;
new->pop_func = undo_pop_channel_mod;
new->free_func = undo_free_channel_mod;
data[0] = channel_ptr;
data[1] = (void *) tiles;
return TRUE;
}
else
{
tile_manager_destroy (tiles);
return FALSE;
}
}
int
undo_pop_channel_mod (GImage *gimage,
int state,
int type,
void *data_ptr)
{
void **data;
TileManager *tiles;
TileManager *temp;
Channel *channel;
data = (void **) data_ptr;
channel = (Channel *) data[0];
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(channel));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(channel));
1997-11-25 06:05:25 +08:00
break;
}
tiles = (TileManager *) data[1];
/* Issue the first update */
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(channel), 0, 0,
GIMP_DRAWABLE(channel)->width, GIMP_DRAWABLE(channel)->height);
1997-11-25 06:05:25 +08:00
temp = GIMP_DRAWABLE(channel)->tiles;
GIMP_DRAWABLE(channel)->tiles = tiles;
GIMP_DRAWABLE(channel)->width = tiles->width;
GIMP_DRAWABLE(channel)->height = tiles->height;
1997-11-25 06:05:25 +08:00
/* Set the new buffer */
data[1] = temp;
/* Issue the second update */
1999-07-20 03:46:05 +08:00
drawable_update (GIMP_DRAWABLE(channel), 0, 0,
GIMP_DRAWABLE(channel)->width, GIMP_DRAWABLE(channel)->height);
1997-11-25 06:05:25 +08:00
return TRUE;
}
void
undo_free_channel_mod (int state,
void *data_ptr)
{
void ** data;
data = (void **) data_ptr;
tile_manager_destroy ((TileManager *) data[1]);
g_free (data);
}
/**************************************/
/* Floating Selection to Layer Undo */
int
undo_push_fs_to_layer (GImage *gimage,
void *fsu_ptr)
{
FStoLayerUndo *fsu;
Undo *new;
int size;
fsu = (FStoLayerUndo *) fsu_ptr;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
size = sizeof (FStoLayerUndo);
if ((new = undo_push (gimage, size, CHANNEL_MOD)))
{
new->data = fsu_ptr;
new->pop_func = undo_pop_fs_to_layer;
new->free_func = undo_free_fs_to_layer;
return TRUE;
}
else
{
tile_manager_destroy (fsu->layer->fs.backing_store);
g_free (fsu);
return FALSE;
}
}
int
undo_pop_fs_to_layer (GImage *gimage,
int state,
int type,
void *fsu_ptr)
{
FStoLayerUndo *fsu;
fsu = (FStoLayerUndo *) fsu_ptr;
switch (state)
{
case UNDO:
gimage_clean (gimage);
drawable_clean (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
break;
case REDO:
gimage_dirty (gimage);
drawable_dirty (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
break;
}
switch (state)
{
case UNDO:
/* Update the preview for the floating sel */
drawable_invalidate_preview (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
fsu->layer->fs.drawable = fsu->drawable;
gimage->active_layer = fsu->layer;
gimage->floating_sel = fsu->layer;
1997-11-25 06:05:25 +08:00
/* restore the contents of the drawable */
1999-07-20 03:46:05 +08:00
floating_sel_store (fsu->layer,
GIMP_DRAWABLE(fsu->layer)->offset_x,
GIMP_DRAWABLE(fsu->layer)->offset_y,
GIMP_DRAWABLE(fsu->layer)->width,
GIMP_DRAWABLE(fsu->layer)->height);
1997-11-25 06:05:25 +08:00
fsu->layer->fs.initial = TRUE;
/* clear the selection */
layer_invalidate_boundary (fsu->layer);
/* Update the preview for the gimage and underlying drawable */
drawable_invalidate_preview (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
break;
case REDO:
/* restore the contents of the drawable */
1999-07-20 03:46:05 +08:00
floating_sel_restore (fsu->layer,
GIMP_DRAWABLE(fsu->layer)->offset_x,
GIMP_DRAWABLE(fsu->layer)->offset_y,
GIMP_DRAWABLE(fsu->layer)->width,
GIMP_DRAWABLE(fsu->layer)->height);
1997-11-25 06:05:25 +08:00
/* Update the preview for the gimage and underlying drawable */
drawable_invalidate_preview (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
/* clear the selection */
layer_invalidate_boundary (fsu->layer);
/* update the pointers */
fsu->layer->fs.drawable = NULL;
gimage->floating_sel = NULL;
1997-11-25 06:05:25 +08:00
/* Update the fs drawable */
drawable_invalidate_preview (GIMP_DRAWABLE(fsu->layer));
1997-11-25 06:05:25 +08:00
break;
}
return TRUE;
}
void
undo_free_fs_to_layer (int state,
void *fsu_ptr)
{
FStoLayerUndo *fsu;
fsu = (FStoLayerUndo *) fsu_ptr;
if (state == UNDO)
tile_manager_destroy (fsu->layer->fs.backing_store);
g_free (fsu);
}
/***********************************/
/* Floating Selection Rigor Undo */
int
undo_push_fs_rigor (GImage *gimage,
int layer_id)
{
Undo *new;
int size;
size = sizeof (int);
if ((new = undo_push (gimage, size, FS_RIGOR)))
{
new->data = g_new (int, 1);
new->pop_func = undo_pop_fs_rigor;
new->free_func = undo_free_fs_rigor;
*((int *) new->data) = layer_id;
return TRUE;
}
else
return FALSE;
}
int
undo_pop_fs_rigor (GImage *gimage,
int state,
int type,
void *layer_ptr)
{
int layer_id;
Layer *floating_layer;
layer_id = *((int *) layer_ptr);
if ((floating_layer = layer_get_ID (layer_id)) == NULL)
return FALSE;
if (! layer_is_floating_sel (floating_layer))
return FALSE;
switch (state)
{
case UNDO:
/* restore the contents of drawable the floating layer is attached to */
if (floating_layer->fs.initial == FALSE)
floating_sel_restore (floating_layer,
1999-07-20 03:46:05 +08:00
GIMP_DRAWABLE(floating_layer)->offset_x,
GIMP_DRAWABLE(floating_layer)->offset_y,
GIMP_DRAWABLE(floating_layer)->width,
GIMP_DRAWABLE(floating_layer)->height);
1997-11-25 06:05:25 +08:00
floating_layer->fs.initial = TRUE;
break;
case REDO:
/* store the affected area from the drawable in the backing store */
floating_sel_store (floating_layer,
1999-07-20 03:46:05 +08:00
GIMP_DRAWABLE(floating_layer)->offset_x,
GIMP_DRAWABLE(floating_layer)->offset_y,
GIMP_DRAWABLE(floating_layer)->width,
GIMP_DRAWABLE(floating_layer)->height);
1997-11-25 06:05:25 +08:00
floating_layer->fs.initial = TRUE;
break;
}
return TRUE;
}
void
undo_free_fs_rigor (int state,
void *layer_ptr)
{
g_free (layer_ptr);
}
/***********************************/
/* Floating Selection Relax Undo */
int
undo_push_fs_relax (GImage *gimage,
int layer_id)
{
Undo *new;
int size;
size = sizeof (int);
if ((new = undo_push (gimage, size, FS_RELAX)))
{
new->data = g_new (int, 1);
new->pop_func = undo_pop_fs_relax;
new->free_func = undo_free_fs_relax;
*((int *) new->data) = layer_id;
return TRUE;
}
else
return FALSE;
}
int
undo_pop_fs_relax (GImage *gimage,
int state,
int type,
void *layer_ptr)
{
int layer_id;
Layer *floating_layer;
layer_id = *((int *) layer_ptr);
if ((floating_layer = layer_get_ID (layer_id)) == NULL)
return FALSE;
if (! layer_is_floating_sel (floating_layer))
return FALSE;
switch (state)
{
case UNDO:
/* store the affected area from the drawable in the backing store */
floating_sel_store (floating_layer,
1999-07-20 03:46:05 +08:00
GIMP_DRAWABLE(floating_layer)->offset_x,
GIMP_DRAWABLE(floating_layer)->offset_y,
GIMP_DRAWABLE(floating_layer)->width,
GIMP_DRAWABLE(floating_layer)->height);
1997-11-25 06:05:25 +08:00
floating_layer->fs.initial = TRUE;
break;
case REDO:
/* restore the contents of drawable the floating layer is attached to */
if (floating_layer->fs.initial == FALSE)
floating_sel_restore (floating_layer,
1999-07-20 03:46:05 +08:00
GIMP_DRAWABLE(floating_layer)->offset_x,
GIMP_DRAWABLE(floating_layer)->offset_y,
GIMP_DRAWABLE(floating_layer)->width,
GIMP_DRAWABLE(floating_layer)->height);
1997-11-25 06:05:25 +08:00
floating_layer->fs.initial = TRUE;
break;
}
return TRUE;
}
void
undo_free_fs_relax (int state,
void *layer_ptr)
{
g_free (layer_ptr);
}
/*********************/
/* GImage Mod Undo */
int
undo_push_gimage_mod (GImage *gimage)
{
Undo *new;
int *data;
int size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (int) * 3;
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = (int *) g_malloc (sizeof (int) * 3);
new->data = data;
new->pop_func = undo_pop_gimage_mod;
new->free_func = undo_free_gimage_mod;
data[0] = gimage->width;
data[1] = gimage->height;
data[2] = gimage->base_type;
return TRUE;
}
return FALSE;
}
int
undo_pop_gimage_mod (GImage *gimage,
int state,
int type,
void *data_ptr)
{
int *data;
int tmp;
switch (state)
{
case UNDO:
gimage_clean (gimage);
break;
case REDO:
gimage_dirty (gimage);
break;
}
data = (int *) data_ptr;
tmp = data[0];
data[0] = gimage->width;
gimage->width = tmp;
tmp = data[1];
data[1] = gimage->height;
gimage->height = tmp;
tmp = data[2];
data[2] = gimage->base_type;
gimage->base_type = tmp;
gimage_projection_realloc (gimage);
gimage_mask_invalidate (gimage);
channel_invalidate_previews (gimage);
layer_invalidate_previews (gimage);
1997-11-25 06:05:25 +08:00
gimage_invalidate_preview (gimage);
gdisplays_update_full (gimage);
gdisplays_update_title (gimage);
1997-11-25 06:05:25 +08:00
gimp_image_colormap_changed (gimage, -1);
1997-11-25 06:05:25 +08:00
if (gimage->width != (int) data[0] || gimage->height != (int) data[1])
shrink_wrap = TRUE;
return TRUE;
}
void
undo_free_gimage_mod (int state,
void *data_ptr)
{
g_free (data_ptr);
}
/***********/
/* Qmask */
typedef struct _QmaskUndo QmaskUndo;
struct _QmaskUndo
{
GImage *gimage;
int qmask;
int orig;
};
int
undo_push_qmask (GImage *gimage,
int qmask)
{
Undo *new;
QmaskUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (QmaskUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = g_new (QmaskUndo, 1);
new->data = data;
new->pop_func = undo_pop_qmask;
new->free_func = undo_free_qmask;
data->gimage = gimage;
data->qmask = qmask;
data->orig = data->qmask;
return TRUE;
}
return FALSE;
}
int
undo_pop_qmask (GImage *gimage,
int state,
int type,
void *data_ptr)
{
QmaskUndo *data;
int tmp;
data = data_ptr;
tmp = data->qmask;
data->qmask = data->orig;
data->orig = tmp;
gimage->qmask_state = data->qmask;
switch (state)
{
case UNDO:
gimage_clean (gimage);
break;
case REDO:
gimage_dirty (gimage);
break;
}
return TRUE;
}
void
undo_free_qmask (int state,
void *data_ptr)
{
g_free (data_ptr);
}
1997-11-25 06:05:25 +08:00
/***********/
/* Guide */
typedef struct _GuideUndo GuideUndo;
struct _GuideUndo
{
GImage *gimage;
Guide *guide;
Guide orig;
};
int
undo_push_guide (GImage *gimage,
void *guide)
{
Undo *new;
GuideUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (GuideUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
((Guide *)(guide))->ref_count++;
1997-11-25 06:05:25 +08:00
data = g_new (GuideUndo, 1);
new->data = data;
new->pop_func = undo_pop_guide;
new->free_func = undo_free_guide;
data->gimage = gimage;
data->guide = guide;
data->orig = *(data->guide);
return TRUE;
}
return FALSE;
}
int
undo_pop_guide (GImage *gimage,
int state,
int type,
void *data_ptr)
{
GuideUndo *data;
Guide tmp;
int tmp_ref;
1997-11-25 06:05:25 +08:00
data = data_ptr;
gdisplays_expose_guide (gimage, data->guide);
gdisplays_expose_guide (gimage, &data->orig);
1997-11-25 06:05:25 +08:00
tmp_ref = data->guide->ref_count;
1997-11-25 06:05:25 +08:00
tmp = *(data->guide);
*(data->guide) = data->orig;
data->guide->ref_count = tmp_ref;
1997-11-25 06:05:25 +08:00
data->orig = tmp;
switch (state)
{
case UNDO:
gimage_clean (gimage);
break;
case REDO:
gimage_dirty (gimage);
break;
}
return TRUE;
}
void
undo_free_guide (int state,
void *data_ptr)
{
GuideUndo *data;
data = data_ptr;
data->guide->ref_count--;
if (data->guide->position < 0 && data->guide->ref_count <= 0)
gimage_delete_guide (data->gimage, data->guide);
1997-11-25 06:05:25 +08:00
g_free (data_ptr);
}
/************/
/* Parasite */
typedef struct _ParasiteUndo ParasiteUndo;
struct _ParasiteUndo
{
1999-07-20 03:46:05 +08:00
GImage *gimage;
GimpDrawable *drawable;
1999-07-20 03:46:05 +08:00
Parasite *parasite;
char *name;
};
int
undo_push_image_parasite (GImage *gimage,
void *parasite)
{
Undo *new;
ParasiteUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (ParasiteUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = g_new (ParasiteUndo, 1);
new->data = data;
new->pop_func = undo_pop_parasite;
new->free_func = undo_free_parasite;
data->gimage = gimage;
data->drawable = NULL;
1999-07-20 03:46:05 +08:00
data->name = g_strdup (parasite_name (parasite));
data->parasite = parasite_copy (gimp_image_find_parasite (gimage, data->name));
return TRUE;
}
return FALSE;
}
int
undo_push_image_parasite_remove (GImage *gimage,
const char *name)
{
Undo *new;
ParasiteUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (ParasiteUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = g_new (ParasiteUndo, 1);
new->data = data;
new->pop_func = undo_pop_parasite;
new->free_func = undo_free_parasite;
data->gimage = gimage;
data->drawable = NULL;
1999-07-20 03:46:05 +08:00
data->name = g_strdup (name);
data->parasite = parasite_copy (gimp_image_find_parasite (gimage, data->name));
return TRUE;
}
return FALSE;
}
int
undo_push_drawable_parasite (GImage *gimage,
GimpDrawable *drawable,
void *parasite)
{
Undo *new;
ParasiteUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (ParasiteUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = g_new (ParasiteUndo, 1);
new->data = data;
new->pop_func = undo_pop_parasite;
new->free_func = undo_free_parasite;
data->gimage = NULL;
data->drawable = drawable;
1999-07-20 03:46:05 +08:00
data->name = g_strdup (parasite_name (parasite));
data->parasite = parasite_copy (gimp_drawable_find_parasite (drawable, data->name));
return TRUE;
}
return FALSE;
}
int
undo_push_drawable_parasite_remove (GImage *gimage,
GimpDrawable *drawable,
const char *name)
{
Undo *new;
ParasiteUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (ParasiteUndo);
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
data = g_new (ParasiteUndo, 1);
new->data = data;
new->pop_func = undo_pop_parasite;
new->free_func = undo_free_parasite;
data->gimage = NULL;
data->drawable = drawable;
1999-07-20 03:46:05 +08:00
data->name = g_strdup (name);
data->parasite = parasite_copy (gimp_drawable_find_parasite (drawable, data->name));
return TRUE;
}
return FALSE;
}
int
undo_pop_parasite (GImage *gimage,
1999-07-20 03:46:05 +08:00
int state,
int type,
void *data_ptr)
{
ParasiteUndo *data;
Parasite *tmp;
data = data_ptr;
tmp = data->parasite;
if (data->gimage)
{
1999-07-20 03:46:05 +08:00
data->parasite = parasite_copy (gimp_image_find_parasite (gimage,
data->name));
if (tmp)
1999-07-20 03:46:05 +08:00
parasite_list_add (data->gimage->parasites, tmp);
else
1999-07-20 03:46:05 +08:00
parasite_list_remove (data->gimage->parasites, data->name);
}
else if (data->drawable)
{
1999-07-20 03:46:05 +08:00
data->parasite = parasite_copy (gimp_drawable_find_parasite (data->drawable,
data->name));
if (tmp)
1999-07-20 03:46:05 +08:00
parasite_list_add (data->drawable->parasites, tmp);
else
1999-07-20 03:46:05 +08:00
parasite_list_remove (data->drawable->parasites, data->name);
}
else
{
1999-07-20 03:46:05 +08:00
data->parasite = parasite_copy (gimp_find_parasite (data->name));
if (tmp)
1999-07-20 03:46:05 +08:00
gimp_attach_parasite (tmp);
else
1999-07-20 03:46:05 +08:00
gimp_detach_parasite (data->name);
}
if (tmp)
1999-07-20 03:46:05 +08:00
parasite_free (tmp);
/* if ((tmp && parasite_is_persistant(tmp)) || */
/* (data->parasite && parasite_is_persistant(data->parasite))) */
switch (state)
{
case UNDO:
gimage_clean (gimage);
break;
case REDO:
gimage_dirty (gimage);
break;
}
return TRUE;
}
void
undo_free_parasite (int state,
1999-07-20 03:46:05 +08:00
void *data_ptr)
{
ParasiteUndo *data;
data = data_ptr;
if (data->parasite)
parasite_free (data->parasite);
if (data->name)
g_free (data->name);
g_free (data_ptr);
}
Dirty flag now correct in all cases. Can be displayed in image window Mon Aug 23 10:15:32 EDT 1999 Austin Donnelly <austin@gimp.org> Dirty flag now correct in all cases. Can be displayed in image window title too. See NOTE near gimp_image_dirty() for details. * app/fileops.c: gimp_image_clean_all() after reverting an image. * app/gdisplay.c: register handlers for gimage dirty and clean signals to update image title. New image-title-format expansion: %Dx expands to x if the image is dirty. * app/gdisplay_ops.c: gimage->dirty flags != 0 is the correct condition to test to see if an image is dirty. * app/gimpdrawable.c: gimp_image_dirty() should never be called except from an undo_push_* function. Call undo_push_cantundo() if you want to dirty the image but can't be bothered writing an undo handler (be ashamed of yourself!). * app/gimpimage.c: new gimage signal: clean. Emitted when an undo operation takes place. Gimage changes when either dirty or clean is emitted, so if you need to update previews etc, look for both! Move group_count into gimage structure, since leaving it as a static in undo.c is bad if two undo groups are started on different images at the same time. More changes of gimp_image_dirty() to undo_push_cantundo() (parasite-related, plus layer moves). See the NOTE on dirty counter near gimp_image_dirty() for the full story. gimp_image_dirty() and gimp_image_clean() simplified - counter can go negative. * app/gimpimageP.h: group_count moved from undo.c * app/layers_dialog.c: push undo for layer name change, rather than dirtying the image. * app/undo.c: layer rename undo functions added. undo_push_cantundo() convenience functions added. group_count made per-gimage since everything else is. When blowing away redo stack, make image infinitely dirty if redo info contained file save point. * app/undo.h: added undo_push_layer_rename() and undo_push_cantundo(). * TODO: added idea for undo history window.
1999-08-23 22:34:58 +08:00
/*************/
/* Layer name change */
typedef struct {
Layer *layer;
gchar *old_name;
} LayerRenameUndo;
int
undo_push_layer_rename (GImage *gimage, Layer *layer)
{
Undo *new;
LayerRenameUndo *data;
long size;
/* increment the dirty flag for this gimage */
gimage_dirty (gimage);
size = sizeof (LayerRenameUndo);
if ((new = undo_push (gimage, size, LAYER_CHANGE)))
{
data = g_new (LayerRenameUndo, 1);
new->data = data;
new->pop_func = undo_pop_layer_rename;
new->free_func = undo_free_layer_rename;
data->layer = layer;
data->old_name = g_strdup (layer_get_name (layer));
return TRUE;
}
return FALSE;
}
static int
undo_pop_layer_rename (GImage *gimage,
int state,
int type,
void *data_ptr)
{
LayerRenameUndo *data = data_ptr;
gchar *tmp;
tmp = g_strdup (layer_get_name (data->layer));
layer_set_name (data->layer, data->old_name);
g_free (data->old_name);
data->old_name = tmp;
switch (state) {
case UNDO:
gimp_image_clean (gimage);
break;
case REDO:
gimp_image_dirty (gimage);
break;
}
return TRUE;
}
static void
undo_free_layer_rename (int state,
void *data_ptr)
{
LayerRenameUndo *data = data_ptr;
g_free (data->old_name);
g_free (data);
}
/*************/
/* Something for which programmer is too lazy to write an undo
* function for.
*/
int
undo_push_cantundo (GImage *gimage,
const char *action)
{
Undo *new;
/* This is the sole purpose of this type of undo: the ability to
* mark an image as having been mutated, without really providing
* any adequate undo facility. */
gimp_image_dirty (gimage);
new = undo_push (gimage, 0, GIMAGE_MOD);
if (!new)
return FALSE;
new->data = (void*)action;
new->pop_func = undo_pop_cantundo;
new->free_func = undo_free_cantundo;
return TRUE;
}
static int
undo_pop_cantundo (GImage *gimage,
int state,
int type,
void *data_ptr)
{
char *action = data_ptr;
switch (state) {
case UNDO:
g_message (_("Can't undo %s"), action);
gimp_image_clean (gimage);
break;
case REDO:
gimp_image_dirty (gimage);
break;
}
return TRUE;
}
static void
undo_free_cantundo (int state, void *data_ptr)
{
}