Files
gimp/app/core/gimpundostack.c
Michael Natterer 24f3da165b changed GimpObject::get_memsize() to return a second value named
2003-08-25  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpobject.[ch]: changed GimpObject::get_memsize() to
	return a second value named "gui_size", where the primary return
	value is the "constant" actual size (as long as no operation is
	performed on the object), and the second "gui_size" return value
	is the size of temporary stuff like preview caches or boundary
	segments (which may change asynchronously, even if the object is
	on the undo stack).

	* app/core/gimp.c
	* app/core/gimpbrush.c
	* app/core/gimpbrushpipe.c
	* app/core/gimpbuffer.c
	* app/core/gimpchannel.c
	* app/core/gimpcontainer.c
	* app/core/gimpcontext.c
	* app/core/gimpdata.c
	* app/core/gimpdatafactory.c
	* app/core/gimpdrawable.c
	* app/core/gimpgradient.c
	* app/core/gimpimage-undo.c
	* app/core/gimpimage.c
	* app/core/gimpitem.c
	* app/core/gimplayer.c
	* app/core/gimplist.c
	* app/core/gimppalette.c
	* app/core/gimpparasitelist.c
	* app/core/gimppattern.c
	* app/core/gimpundo.c
	* app/core/gimpundostack.c
	* app/core/gimpviewable.c
	* app/text/gimptextlayer.c
	* app/vectors/gimpstroke.c
	* app/vectors/gimpvectors.c: changed get_memsize() implementations
	accordingly.

	* app/display/gimpdisplayshell-title.c
	* app/gui/debug-commands.c
	* app/widgets/gimppreview.c: changed callers accordingly.

	* app/core/gimpimage-undo-push.c: changed layer, channel, vectors
	and layer_mask undo steps to add/subtract the size of the
	resp. objects whenever they take/drop ownership of them. Ignore
	the objects' "gui_size" to get identical sizes on
	adding/subtracting. Fixes bug #120429.
2003-08-25 10:49:33 +00:00

270 lines
6.9 KiB
C

/* 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"
#include <glib-object.h>
#include "core-types.h"
#include "gimpimage.h"
#include "gimplist.h"
#include "gimpundo.h"
#include "gimpundostack.h"
static void gimp_undo_stack_class_init (GimpUndoStackClass *klass);
static void gimp_undo_stack_init (GimpUndoStack *stack);
static void gimp_undo_stack_finalize (GObject *object);
static gsize gimp_undo_stack_get_memsize (GimpObject *object,
gsize *gui_size);
static void gimp_undo_stack_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void gimp_undo_stack_free (GimpUndo *undo,
GimpUndoMode undo_mode);
static GimpUndoClass *parent_class = NULL;
GType
gimp_undo_stack_get_type (void)
{
static GType undo_stack_type = 0;
if (! undo_stack_type)
{
static const GTypeInfo undo_stack_info =
{
sizeof (GimpUndoStackClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_undo_stack_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpUndoStack),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_undo_stack_init,
};
undo_stack_type = g_type_register_static (GIMP_TYPE_UNDO,
"GimpUndoStack",
&undo_stack_info, 0);
}
return undo_stack_type;
}
static void
gimp_undo_stack_class_init (GimpUndoStackClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpUndoClass *undo_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
undo_class = GIMP_UNDO_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_undo_stack_finalize;
gimp_object_class->get_memsize = gimp_undo_stack_get_memsize;
undo_class->pop = gimp_undo_stack_pop;
undo_class->free = gimp_undo_stack_free;
}
static void
gimp_undo_stack_init (GimpUndoStack *stack)
{
stack->undos = gimp_list_new (GIMP_TYPE_UNDO,
GIMP_CONTAINER_POLICY_STRONG);
}
static void
gimp_undo_stack_finalize (GObject *object)
{
GimpUndoStack *stack;
stack = GIMP_UNDO_STACK (object);
if (stack->undos)
{
g_object_unref (stack->undos);
stack->undos = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gsize
gimp_undo_stack_get_memsize (GimpObject *object,
gsize *gui_size)
{
GimpUndoStack *stack;
gsize memsize = 0;
stack = GIMP_UNDO_STACK (object);
if (stack->undos)
memsize += gimp_object_get_memsize (GIMP_OBJECT (stack->undos), gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
gimp_undo_stack_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpUndoStack *stack;
GList *list;
stack = GIMP_UNDO_STACK (undo);
for (list = GIMP_LIST (stack->undos)->list;
list;
list = g_list_next (list))
{
GimpUndo *child;
child = GIMP_UNDO (list->data);
gimp_undo_pop (child, undo_mode, accum);
}
}
static void
gimp_undo_stack_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpUndoStack *stack;
GList *list;
stack = GIMP_UNDO_STACK (undo);
for (list = GIMP_LIST (stack->undos)->list;
list;
list = g_list_next (list))
{
GimpUndo *child;
child = GIMP_UNDO (list->data);
gimp_undo_free (child, undo_mode);
g_object_unref (child);
}
while (GIMP_LIST (stack->undos)->list)
gimp_container_remove (GIMP_CONTAINER (stack->undos),
GIMP_OBJECT (GIMP_LIST (stack->undos)->list->data));
}
GimpUndoStack *
gimp_undo_stack_new (GimpImage *gimage)
{
GimpUndoStack *stack;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
stack = GIMP_UNDO_STACK (g_object_new (GIMP_TYPE_UNDO_STACK, NULL));
GIMP_UNDO (stack)->gimage = gimage;
return stack;
}
void
gimp_undo_stack_push_undo (GimpUndoStack *stack,
GimpUndo *undo)
{
g_return_if_fail (GIMP_IS_UNDO_STACK (stack));
g_return_if_fail (GIMP_IS_UNDO (undo));
gimp_container_add (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
}
GimpUndo *
gimp_undo_stack_pop_undo (GimpUndoStack *stack,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpUndo *undo;
g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
g_return_val_if_fail (accum != NULL, NULL);
undo = (GimpUndo *)
gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0);
if (undo)
{
gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
gimp_undo_pop (undo, undo_mode, accum);
return undo;
}
return NULL;
}
GimpUndo *
gimp_undo_stack_free_bottom (GimpUndoStack *stack,
GimpUndoMode undo_mode)
{
GimpUndo *undo;
gint n_children;
g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
n_children = gimp_container_num_children (GIMP_CONTAINER (stack->undos));
undo = (GimpUndo *)
gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos),
n_children - 1);
if (undo)
{
gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
gimp_undo_free (undo, undo_mode);
return undo;
}
return NULL;
}
GimpUndo *
gimp_undo_stack_peek (GimpUndoStack *stack)
{
GimpObject *object;
g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0);
return (object ? GIMP_UNDO (object) : NULL);
}