Commit da74f126 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/core/gimpundo.[ch] app/core/gimpitemundo.[ch] removed all _new()

2004-07-12  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpundo.[ch]
	* app/core/gimpitemundo.[ch]
	* app/text/gimptextundo.[ch]: removed all _new() functions and
	added properties and GObject::constructor() implementations
	instead.

	* app/core/gimpimage-undo.[ch] (gimp_image_undo_push): added
	"GType undo_gtype" parameter and allow to pass name-value pairs as
	"...". Une the new GParameter utility functions to construct the
	appropriate undo step with g_object_newv().

	(gimp_image_undo_push_item): removed.

	(gimp_image_undo_push_undo): removed. Merged its code back into
	gimp_image_undo_push(), where it originally came from.

	* app/core/gimpimage-undo-push.c
	* app/core/gimpundostack.c
	* app/paint/gimppaintcore-undo.c
	* app/tools/gimptransformtool-undo.c
	* app/widgets/gimpundoeditor.c: changed accordingly.
parent 9593e52e
2004-07-12 Michael Natterer <mitch@gimp.org>
* app/core/gimpundo.[ch]
* app/core/gimpitemundo.[ch]
* app/text/gimptextundo.[ch]: removed all _new() functions and
added properties and GObject::constructor() implementations
instead.
* app/core/gimpimage-undo.[ch] (gimp_image_undo_push): added
"GType undo_gtype" parameter and allow to pass name-value pairs as
"...". Une the new GParameter utility functions to construct the
appropriate undo step with g_object_newv().
(gimp_image_undo_push_item): removed.
(gimp_image_undo_push_undo): removed. Merged its code back into
gimp_image_undo_push(), where it originally came from.
* app/core/gimpimage-undo-push.c
* app/core/gimpundostack.c
* app/paint/gimppaintcore-undo.c
* app/tools/gimptransformtool-undo.c
* app/widgets/gimpundoeditor.c: changed accordingly.
2004-07-12 Sven Neumann <sven@gimp.org>
* plug-ins/gfig/gfig-dialog.c
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
#include "config/gimpcoreconfig.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
#include "gimpitem.h"
......@@ -184,36 +185,24 @@ gimp_image_undo_group_end (GimpImage *gimage)
GimpUndo *
gimp_image_undo_push (GimpImage *gimage,
GType undo_gtype,
gint64 size,
gsize struct_size,
GimpUndoType type,
const gchar *name,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func)
GimpUndoFreeFunc free_func,
...)
{
return gimp_image_undo_push_item (gimage, NULL,
size, struct_size,
type, name, dirties_image,
pop_func, free_func);
}
GimpUndo *
gimp_image_undo_push_item (GimpImage *gimage,
GimpItem *item,
gint64 size,
gsize struct_size,
GimpUndoType type,
const gchar *name,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func)
{
GimpUndo *undo;
gpointer undo_struct = NULL;
GParameter *params = NULL;
gint n_params = 0;
va_list args;
GimpUndo *undo;
gpointer undo_struct = NULL;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (item == NULL || GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (g_type_is_a (undo_gtype, GIMP_TYPE_UNDO), NULL);
g_return_val_if_fail (type > GIMP_UNDO_GROUP_LAST, NULL);
/* Does this undo dirty the image? If so, we always want to mark
......@@ -225,40 +214,30 @@ gimp_image_undo_push_item (GimpImage *gimage,
if (gimage->undo_freeze_count > 0)
return NULL;
if (! name)
name = gimp_undo_type_to_name (type);
if (struct_size > 0)
undo_struct = g_malloc0 (struct_size);
if (item)
{
undo = gimp_item_undo_new (gimage, item,
type, name,
undo_struct, size,
dirties_image,
pop_func, free_func);
}
else
{
undo = gimp_undo_new (gimage,
type, name,
undo_struct, size,
dirties_image,
pop_func, free_func);
}
params = gimp_parameters_append (undo_gtype, params, &n_params,
"name", name,
"image", gimage,
"undo-type", type,
"dirties-image", dirties_image,
"data", undo_struct,
"size", size,
"pop-func", pop_func,
"free-func", free_func,
NULL);
if (gimp_image_undo_push_undo (gimage, undo))
return undo;
va_start (args, free_func);
params = gimp_parameters_append_valist (undo_gtype, params, &n_params, args);
va_end (args);
return NULL;
}
undo = g_object_newv (undo_gtype, n_params, params);
gboolean
gimp_image_undo_push_undo (GimpImage *gimage,
GimpUndo *undo)
{
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_UNDO (undo), FALSE);
g_return_val_if_fail (undo->gimage == gimage, FALSE);
g_return_val_if_fail (gimage->undo_freeze_count == 0, FALSE);
gimp_parameters_free (params, n_params);
/* nuke the redo stack */
gimp_image_undo_free_redo (gimage);
......@@ -282,7 +261,7 @@ gimp_image_undo_push_undo (GimpImage *gimage,
/* freeing undo space may have freed the newly pushed undo */
if (gimp_undo_stack_peek (gimage->undo_stack) == undo)
return TRUE;
return undo;
}
else
{
......@@ -292,10 +271,10 @@ gimp_image_undo_push_undo (GimpImage *gimage,
gimp_undo_stack_push_undo (undo_group, undo);
return TRUE;
return undo;
}
return FALSE;
return NULL;
}
......
......@@ -31,24 +31,15 @@ gboolean gimp_image_undo_group_start (GimpImage *gimage,
gboolean gimp_image_undo_group_end (GimpImage *gimage);
GimpUndo * gimp_image_undo_push (GimpImage *gimage,
GType undo_gtype,
gint64 size,
gsize struct_size,
GimpUndoType type,
const gchar *name,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func);
GimpUndo * gimp_image_undo_push_item (GimpImage *gimage,
GimpItem *item,
gint64 size,
gsize struct_size,
GimpUndoType type,
const gchar *name,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func);
gboolean gimp_image_undo_push_undo (GimpImage *gimage,
GimpUndo *undo);
GimpUndoFreeFunc free_func,
...);
#endif /* __GIMP_IMAGE_UNDO_H__ */
......@@ -27,11 +27,29 @@
#include "gimpitemundo.h"
static void gimp_item_undo_class_init (GimpItemUndoClass *klass);
static void gimp_item_undo_init (GimpItemUndo *undo);
enum
{
PROP_0,
PROP_ITEM
};
static void gimp_item_undo_class_init (GimpItemUndoClass *klass);
static void gimp_item_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
static GObject * gimp_item_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_item_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_item_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_item_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
static GimpUndoClass *parent_class = NULL;
......@@ -47,19 +65,19 @@ gimp_item_undo_get_type (void)
static const GTypeInfo undo_info =
{
sizeof (GimpItemUndoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_item_undo_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpItemUndo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_item_undo_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_item_undo_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpItemUndo),
0, /* n_preallocs */
NULL /* instance_init */
};
undo_type = g_type_register_static (GIMP_TYPE_UNDO,
"GimpItemUndo",
&undo_info, 0);
"GimpItemUndo",
&undo_info, 0);
}
return undo_type;
......@@ -68,30 +86,84 @@ gimp_item_undo_get_type (void)
static void
gimp_item_undo_class_init (GimpItemUndoClass *klass)
{
GObjectClass *object_class;
GimpUndoClass *undo_class;
object_class = G_OBJECT_CLASS (klass);
undo_class = GIMP_UNDO_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
undo_class->free = gimp_item_undo_free;
object_class->constructor = gimp_item_undo_constructor;
object_class->set_property = gimp_item_undo_set_property;
object_class->get_property = gimp_item_undo_get_property;
undo_class->free = gimp_item_undo_free;
g_object_class_install_property (object_class, PROP_ITEM,
g_param_spec_object ("item", NULL, NULL,
GIMP_TYPE_ITEM,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static GObject *
gimp_item_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpItemUndo *item_undo;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
item_undo = GIMP_ITEM_UNDO (object);
g_assert (GIMP_IS_ITEM (item_undo->item));
return object;
}
static void
gimp_item_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
switch (property_id)
{
case PROP_ITEM:
item_undo->item = (GimpItem *) g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_item_undo_init (GimpItemUndo *undo)
gimp_item_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
undo->item = NULL;
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
switch (property_id)
{
case PROP_ITEM:
g_value_set_object (value, item_undo->item);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_item_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpItemUndo *item_undo;
item_undo = GIMP_ITEM_UNDO (undo);
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
......@@ -101,40 +173,3 @@ gimp_item_undo_free (GimpUndo *undo,
item_undo->item = NULL;
}
}
GimpUndo *
gimp_item_undo_new (GimpImage *gimage,
GimpItem *item,
GimpUndoType undo_type,
const gchar *name,
gpointer data,
gint64 size,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func)
{
GimpUndo *undo;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (size == 0 || data != NULL, NULL);
if (! name)
name = gimp_undo_type_to_name (undo_type);
undo = g_object_new (GIMP_TYPE_ITEM_UNDO,
"name", name,
NULL);
undo->gimage = gimage;
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;
GIMP_ITEM_UNDO (undo)->item = g_object_ref (item);
return undo;
}
......@@ -46,17 +46,7 @@ struct _GimpItemUndoClass
};
GType gimp_item_undo_get_type (void) G_GNUC_CONST;
GimpUndo * gimp_item_undo_new (GimpImage *gimage,
GimpItem *item,
GimpUndoType undo_type,
const gchar *name,
gpointer data,
gint64 size,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func);
GType gimp_item_undo_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_ITEM_UNDO_H__ */
......@@ -42,11 +42,33 @@ enum
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_IMAGE,
PROP_UNDO_TYPE,
PROP_DIRTIES_IMAGE,
PROP_DATA,
PROP_SIZE,
PROP_POP_FUNC,
PROP_FREE_FUNC
};
static void gimp_undo_class_init (GimpUndoClass *klass);
static void gimp_undo_init (GimpUndo *undo);
static GObject * gimp_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_undo_finalize (GObject *object);
static void gimp_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gint64 gimp_undo_get_memsize (GimpObject *object,
gint64 *gui_size);
......@@ -86,19 +108,19 @@ gimp_undo_get_type (void)
static const GTypeInfo undo_info =
{
sizeof (GimpUndoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_undo_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpUndo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_undo_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_undo_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpUndo),
0, /* n_preallocs */
NULL /* instance_init */
};
undo_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
"GimpUndo",
&undo_info, 0);
"GimpUndo",
&undo_info, 0);
}
return undo_type;
......@@ -107,38 +129,37 @@ gimp_undo_get_type (void)
static void
gimp_undo_class_init (GimpUndoClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
undo_signals[POP] =
g_signal_new ("pop",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpUndoClass, pop),
NULL, NULL,
gimp_marshal_VOID__ENUM_POINTER,
G_TYPE_NONE, 2,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpUndoClass, pop),
NULL, NULL,
gimp_marshal_VOID__ENUM_POINTER,
G_TYPE_NONE, 2,
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,
gimp_marshal_VOID__ENUM,
G_TYPE_NONE, 1,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpUndoClass, free),
NULL, NULL,
gimp_marshal_VOID__ENUM,
G_TYPE_NONE, 1,
GIMP_TYPE_UNDO_MODE);
object_class->constructor = gimp_undo_constructor;
object_class->finalize = gimp_undo_finalize;
object_class->set_property = gimp_undo_set_property;
object_class->get_property = gimp_undo_get_property;
gimp_object_class->get_memsize = gimp_undo_get_memsize;
......@@ -148,18 +169,64 @@ gimp_undo_class_init (GimpUndoClass *klass)
klass->pop = gimp_undo_real_pop;
klass->free = gimp_undo_real_free;
g_object_class_install_property (object_class, PROP_IMAGE,
g_param_spec_object ("image", NULL, NULL,
GIMP_TYPE_IMAGE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_UNDO_TYPE,
g_param_spec_enum ("undo-type", NULL, NULL,
GIMP_TYPE_UNDO_TYPE,
GIMP_UNDO_GROUP_NONE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DIRTIES_IMAGE,
g_param_spec_boolean ("dirties-image",
NULL, NULL,
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DATA,
g_param_spec_pointer ("data", NULL, NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_SIZE,
g_param_spec_int64 ("size", NULL, NULL,
0, G_MAXINT64, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_POP_FUNC,
g_param_spec_pointer ("pop-func", NULL, NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_FREE_FUNC,
g_param_spec_pointer ("free-func", NULL, NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_undo_init (GimpUndo *undo)
static GObject *
gimp_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
undo->gimage = NULL;
undo->undo_type = 0;
undo->data = NULL;
undo->dirties_image = FALSE;
undo->pop_func = NULL;
undo->free_func = NULL;
undo->preview = NULL;
GObject *object;
GimpUndo *undo;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
undo = GIMP_UNDO (object);
g_assert (GIMP_IS_IMAGE (undo->gimage));
return object;
}
static void
......@@ -182,6 +249,81 @@ gimp_undo_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpUndo *undo = GIMP_UNDO (object);
switch (property_id)
{
case PROP_IMAGE:
/* don't ref */
undo->gimage = (GimpImage *) g_value_get_object (value);
break;
case PROP_UNDO_TYPE:
undo->undo_type = g_value_get_enum (value);
break;
case PROP_DIRTIES_IMAGE:
undo->dirties_image = g_value_get_boolean (value);
break;
case PROP_DATA:
undo->data = g_value_get_pointer (value);
break;
case PROP_SIZE:
undo->size = g_value_get_int64 (value);
break;
case PROP_POP_FUNC:
undo->pop_func = g_value_get_pointer (value);
break;
case PROP_FREE_FUNC:
undo->free_func = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpUndo *undo = GIMP_UNDO (object);
switch (property_id)
{
case PROP_IMAGE:
g_value_set_object (value, undo->gimage);
break;
case PROP_UNDO_TYPE:
g_value_set_enum (value, undo->undo_type);
break;
case PROP_DIRTIES_IMAGE:
g_value_set_boolean (value, undo->dirties_image);
break;
case PROP_DATA:
g_value_set_pointer (value, undo->data);
break;
case PROP_SIZE:
g_value_set_int64 (value, undo->size);
break;
case PROP_POP_FUNC:
g_value_set_pointer (value, undo->pop_func);
break;
case PROP_FREE_FUNC:
g_value_set_pointer (value, undo->free_func);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint64
gimp_undo_get_memsize (GimpObject *object,
gint64 *gui_size)
......@@ -268,39 +410,6 @@ gimp_undo_real_free (GimpUndo *undo,
undo->free_func (undo, undo_mode);
}
GimpUndo *
gimp_undo_new (GimpImage *gimage,
GimpUndoType undo_type,
const gchar *name,
gpointer data,
gint64 size,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func)
{
GimpUndo *undo;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (size == 0 || data != NULL, NULL);
if (! name)
name = gimp_undo_type_to_name (undo_type);
undo = g_object_new (GIMP_TYPE_UNDO,
"name", name,
NULL);
undo->gimage = gimage;
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;
return undo;
}
void
gimp_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
......
......@@ -76,15 +76,6 @@ struct _GimpUndoClass
GType gimp_undo_get_type (void) G_GNUC_CONST;
GimpUndo * gimp_undo_new (GimpImage *gimage,
GimpUndoType undo_type,
const gchar *name,
gpointer data,
gint64 size,
gboolean dirties_image,
GimpUndoPopFunc pop_func,
GimpUndoFreeFunc free_func);
void gimp_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);