Commit d388d584 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/Makefile.am app/core/core-types.h app/core/gimpchannelundo.[ch]

2007-01-31  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpchannelundo.[ch]
	* app/core/gimplayerundo.[ch]
	* app/core/gimplayermaskundo.[ch]: new undo classes implementing
	channel, layer and layer mask add and remove undos.

	* app/vectors/Makefile.am
	* app/vectors/vectors-types.h
	* app/vectors/gimpvectorsundo.[ch]: vectors add and remove undos.

	* app/core/gimpimage-undo-push.[ch]: use the new undo classes.
	Removed "position" parameter from all "add" functions because
	it's useless.

	* app/core/gimpimage.c: changed accordingly.


svn path=/trunk/; revision=21822
parent 3cd8d484
2007-01-31 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpchannelundo.[ch]
* app/core/gimplayerundo.[ch]
* app/core/gimplayermaskundo.[ch]: new undo classes implementing
channel, layer and layer mask add and remove undos.
* app/vectors/Makefile.am
* app/vectors/vectors-types.h
* app/vectors/gimpvectorsundo.[ch]: vectors add and remove undos.
* app/core/gimpimage-undo-push.[ch]: use the new undo classes.
Removed "position" parameter from all "add" functions because
it's useless.
* app/core/gimpimage.c: changed accordingly.
2007-01-31 Sven Neumann <sven@gimp.org>
 
* plug-ins/common/screenshot.c (select_window_x11): if we can't
......@@ -78,6 +78,8 @@ libappcore_a_sources = \
gimpchannel-select.h \
gimpchannelpropundo.c \
gimpchannelpropundo.h \
gimpchannelundo.c \
gimpchannelundo.h \
gimpcontainer.c \
gimpcontainer.h \
gimpcontainer-filter.c \
......@@ -210,8 +212,12 @@ libappcore_a_sources = \
gimplayer-floating-sel.h \
gimplayermask.c \
gimplayermask.h \
gimplayermaskundo.c \
gimplayermaskundo.h \
gimplayerpropundo.c \
gimplayerpropundo.h \
gimplayerundo.c \
gimplayerundo.h \
gimplist.c \
gimplist.h \
gimpmaskundo.c \
......
......@@ -113,8 +113,11 @@ typedef struct _GimpUndo GimpUndo;
typedef struct _GimpImageUndo GimpImageUndo;
typedef struct _GimpItemUndo GimpItemUndo;
typedef struct _GimpItemPropUndo GimpItemPropUndo;
typedef struct _GimpChannelUndo GimpChannelUndo;
typedef struct _GimpChannelPropUndo GimpChannelPropUndo;
typedef struct _GimpDrawableUndo GimpDrawableUndo;
typedef struct _GimpLayerMaskUndo GimpLayerMaskUndo;
typedef struct _GimpLayerUndo GimpLayerUndo;
typedef struct _GimpLayerPropUndo GimpLayerPropUndo;
typedef struct _GimpMaskUndo GimpMaskUndo;
typedef struct _GimpGuideUndo GimpGuideUndo;
......
/* GIMP - The GNU 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 "gimpcontainer.h"
#include "gimpimage.h"
#include "gimpchannel.h"
#include "gimpchannelundo.h"
enum
{
PROP_0,
PROP_PREV_POSITION,
PROP_PREV_CHANNEL
};
static GObject * gimp_channel_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_channel_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_channel_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gint64 gimp_channel_undo_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_channel_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
G_DEFINE_TYPE (GimpChannelUndo, gimp_channel_undo, GIMP_TYPE_ITEM_UNDO)
#define parent_class gimp_channel_undo_parent_class
static void
gimp_channel_undo_class_init (GimpChannelUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_channel_undo_constructor;
object_class->set_property = gimp_channel_undo_set_property;
object_class->get_property = gimp_channel_undo_get_property;
gimp_object_class->get_memsize = gimp_channel_undo_get_memsize;
undo_class->pop = gimp_channel_undo_pop;
g_object_class_install_property (object_class, PROP_PREV_POSITION,
g_param_spec_int ("prev-position", NULL, NULL,
0, G_MAXINT, 0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_PREV_CHANNEL,
g_param_spec_object ("prev-channel", NULL, NULL,
GIMP_TYPE_CHANNEL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_channel_undo_init (GimpChannelUndo *undo)
{
}
static GObject *
gimp_channel_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpChannelUndo *channel_undo;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
channel_undo = GIMP_CHANNEL_UNDO (object);
g_assert (GIMP_IS_CHANNEL (GIMP_ITEM_UNDO (object)->item));
return object;
}
static void
gimp_channel_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
switch (property_id)
{
case PROP_PREV_POSITION:
channel_undo->prev_position = g_value_get_int (value);
break;
case PROP_PREV_CHANNEL:
channel_undo->prev_channel = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_channel_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (object);
switch (property_id)
{
case PROP_PREV_POSITION:
g_value_set_int (value, channel_undo->prev_position);
break;
case PROP_PREV_CHANNEL:
g_value_set_object (value, channel_undo->prev_channel);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint64
gimp_channel_undo_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object);
gint64 memsize = 0;
if (! gimp_item_is_attached (item_undo->item))
memsize += gimp_object_get_memsize (GIMP_OBJECT (item_undo->item),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
gimp_channel_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpChannelUndo *channel_undo = GIMP_CHANNEL_UNDO (undo);
GimpChannel *channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
undo->undo_type == GIMP_UNDO_CHANNEL_ADD) ||
(undo_mode == GIMP_UNDO_MODE_REDO &&
undo->undo_type == GIMP_UNDO_CHANNEL_REMOVE))
{
/* remove channel */
/* record the current position */
channel_undo->prev_position = gimp_image_get_channel_index (undo->image,
channel);
gimp_container_remove (undo->image->channels, GIMP_OBJECT (channel));
gimp_item_removed (GIMP_ITEM (channel));
if (channel == gimp_image_get_active_channel (undo->image))
{
if (channel_undo->prev_channel)
gimp_image_set_active_channel (undo->image,
channel_undo->prev_channel);
else
gimp_image_unset_active_channel (undo->image);
}
}
else
{
/* restore channel */
/* record the active channel */
channel_undo->prev_channel = gimp_image_get_active_channel (undo->image);
gimp_container_insert (undo->image->channels, GIMP_OBJECT (channel),
channel_undo->prev_position);
gimp_image_set_active_channel (undo->image, channel);
GIMP_ITEM (channel)->removed = FALSE;
}
}
/* GIMP - The GNU 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.
*/
#ifndef __GIMP_CHANNEL_UNDO_H__
#define __GIMP_CHANNEL_UNDO_H__
#include "gimpitemundo.h"
#define GIMP_TYPE_CHANNEL_UNDO (gimp_channel_undo_get_type ())
#define GIMP_CHANNEL_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CHANNEL_UNDO, GimpChannelUndo))
#define GIMP_CHANNEL_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CHANNEL_UNDO, GimpChannelUndoClass))
#define GIMP_IS_CHANNEL_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CHANNEL_UNDO))
#define GIMP_IS_CHANNEL_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CHANNEL_UNDO))
#define GIMP_CHANNEL_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CHANNEL_UNDO, GimpChannelUndoClass))
typedef struct _GimpChannelUndoClass GimpChannelUndoClass;
struct _GimpChannelUndo
{
GimpItemUndo parent_instance;
gint prev_position; /* former position in list */
GimpChannel *prev_channel; /* previous active channel */
};
struct _GimpChannelUndoClass
{
GimpItemUndoClass parent_class;
};
GType gimp_channel_undo_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_CHANNEL_UNDO_H__ */
This diff is collapsed.
......@@ -45,7 +45,7 @@ GimpUndo * gimp_image_undo_push_sample_point (GimpImage *image,
GimpSamplePoint *sample_point);
/* drawable undo */
/* drawable undos */
GimpUndo * gimp_image_undo_push_drawable (GimpImage *image,
const gchar *undo_desc,
......@@ -89,7 +89,6 @@ GimpUndo * gimp_image_undo_push_item_linked (GimpImage *image,
GimpUndo * gimp_image_undo_push_layer_add (GimpImage *image,
const gchar *undo_desc,
GimpLayer *layer,
gint prev_position,
GimpLayer *prev_layer);
GimpUndo * gimp_image_undo_push_layer_remove (GimpImage *image,
const gchar *undo_desc,
......@@ -144,7 +143,6 @@ GimpUndo * gimp_image_undo_push_layer_mask_show (GimpImage *image,
GimpUndo * gimp_image_undo_push_channel_add (GimpImage *image,
const gchar *undo_desc,
GimpChannel *channel,
gint prev_position,
GimpChannel *prev_channel);
GimpUndo * gimp_image_undo_push_channel_remove (GimpImage *image,
const gchar *undo_desc,
......@@ -164,7 +162,6 @@ GimpUndo * gimp_image_undo_push_channel_color (GimpImage *image,
GimpUndo * gimp_image_undo_push_vectors_add (GimpImage *image,
const gchar *undo_desc,
GimpVectors *vectors,
gint prev_position,
GimpVectors *prev_vectors);
GimpUndo * gimp_image_undo_push_vectors_remove (GimpImage *image,
const gchar *undo_desc,
......
......@@ -2814,7 +2814,7 @@ gimp_image_add_layer (GimpImage *image,
old_has_alpha = gimp_image_has_alpha (image);
gimp_image_undo_push_layer_add (image, _("Add Layer"),
layer, 0, active_layer);
layer, active_layer);
gimp_item_set_image (GIMP_ITEM (layer), image);
......@@ -3157,7 +3157,7 @@ gimp_image_add_channel (GimpImage *image,
active_channel = gimp_image_get_active_channel (image);
gimp_image_undo_push_channel_add (image, _("Add Channel"),
channel, 0, active_channel);
channel, active_channel);
gimp_item_set_image (GIMP_ITEM (channel), image);
......@@ -3409,7 +3409,7 @@ gimp_image_add_vectors (GimpImage *image,
active_vectors = gimp_image_get_active_vectors (image);
gimp_image_undo_push_vectors_add (image, _("Add Path"),
vectors, 0, active_vectors);
vectors, active_vectors);
gimp_item_set_image (GIMP_ITEM (vectors), image);
......
/* GIMP - The GNU 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 "gimplayer.h"
#include "gimplayermask.h"
#include "gimplayermaskundo.h"
enum
{
PROP_0,
PROP_LAYER_MASK
};
static GObject * gimp_layer_mask_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_layer_mask_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_layer_mask_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gint64 gimp_layer_mask_undo_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_layer_mask_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void gimp_layer_mask_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
G_DEFINE_TYPE (GimpLayerMaskUndo, gimp_layer_mask_undo, GIMP_TYPE_ITEM_UNDO)
#define parent_class gimp_layer_mask_undo_parent_class
static void
gimp_layer_mask_undo_class_init (GimpLayerMaskUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_layer_mask_undo_constructor;
object_class->set_property = gimp_layer_mask_undo_set_property;
object_class->get_property = gimp_layer_mask_undo_get_property;
gimp_object_class->get_memsize = gimp_layer_mask_undo_get_memsize;
undo_class->pop = gimp_layer_mask_undo_pop;
undo_class->free = gimp_layer_mask_undo_free;
g_object_class_install_property (object_class, PROP_LAYER_MASK,
g_param_spec_object ("layer-mask", NULL, NULL,
GIMP_TYPE_LAYER_MASK,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_layer_mask_undo_init (GimpLayerMaskUndo *undo)
{
}
static GObject *
gimp_layer_mask_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpLayerMaskUndo *layer_mask_undo;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
layer_mask_undo = GIMP_LAYER_MASK_UNDO (object);
g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
g_assert (GIMP_IS_LAYER_MASK (layer_mask_undo->layer_mask));
return object;
}
static void
gimp_layer_mask_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (object);
switch (property_id)
{
case PROP_LAYER_MASK:
layer_mask_undo->layer_mask = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_layer_mask_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (object);
switch (property_id)
{
case PROP_LAYER_MASK:
g_value_set_object (value, layer_mask_undo->layer_mask);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint64
gimp_layer_mask_undo_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (object);
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (object)->item);
gint64 memsize = 0;
/* don't use !gimp_item_is_attached() here */
if (gimp_layer_get_mask (layer) != layer_mask_undo->layer_mask)
memsize += gimp_object_get_memsize (GIMP_OBJECT (layer_mask_undo->layer_mask),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
gimp_layer_mask_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (undo);
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
undo->undo_type == GIMP_UNDO_LAYER_MASK_ADD) ||
(undo_mode == GIMP_UNDO_MODE_REDO &&
undo->undo_type == GIMP_UNDO_LAYER_MASK_REMOVE))
{
/* remove layer mask */
gimp_layer_apply_mask (layer, GIMP_MASK_DISCARD, FALSE);
}
else
{
/* restore layer mask */
gimp_layer_add_mask (layer, layer_mask_undo->layer_mask, FALSE);
GIMP_ITEM (layer_mask_undo->layer_mask)->removed = FALSE;
}
}
static void
gimp_layer_mask_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (undo);
if (layer_mask_undo->layer_mask)
{
g_object_unref (layer_mask_undo->layer_mask);
layer_mask_undo->layer_mask = NULL;
}
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
/* GIMP - The GNU 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.