2007-01-29 03:00:13 +08:00
|
|
|
/* Gimp - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2007-01-29 03:00:13 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-01-29 03:00:13 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-01-29 03:00:13 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-11-03 00:39:38 +08:00
|
|
|
#include <gegl.h>
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2007-01-29 03:00:13 +08:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2007-11-17 02:19:30 +08:00
|
|
|
#include "gimp-utils.h"
|
2007-01-29 03:00:13 +08:00
|
|
|
#include "gimpitem.h"
|
|
|
|
#include "gimpitempropundo.h"
|
2007-02-02 18:55:38 +08:00
|
|
|
#include "gimpparasitelist.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PARASITE_NAME
|
|
|
|
};
|
2007-01-29 03:00:13 +08:00
|
|
|
|
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
static GObject * gimp_item_prop_undo_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
static void gimp_item_prop_undo_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_item_prop_undo_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
static gint64 gimp_item_prop_undo_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
2007-02-01 06:06:01 +08:00
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
static void gimp_item_prop_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum);
|
|
|
|
static void gimp_item_prop_undo_free (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode);
|
2007-01-29 03:00:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpItemPropUndo, gimp_item_prop_undo, GIMP_TYPE_ITEM_UNDO)
|
|
|
|
|
|
|
|
#define parent_class gimp_item_prop_undo_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_class_init (GimpItemPropUndoClass *klass)
|
|
|
|
{
|
2007-02-01 06:06:01 +08:00
|
|
|
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_item_prop_undo_constructor;
|
2007-02-02 18:55:38 +08:00
|
|
|
object_class->set_property = gimp_item_prop_undo_set_property;
|
|
|
|
object_class->get_property = gimp_item_prop_undo_get_property;
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-02-01 06:06:01 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_item_prop_undo_get_memsize;
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-02-01 06:06:01 +08:00
|
|
|
undo_class->pop = gimp_item_prop_undo_pop;
|
|
|
|
undo_class->free = gimp_item_prop_undo_free;
|
2007-02-02 18:55:38 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_PARASITE_NAME,
|
|
|
|
g_param_spec_string ("parasite-name",
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2007-01-29 03:00:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_init (GimpItemPropUndo *undo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gimp_item_prop_undo_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpItemPropUndo *item_prop_undo;
|
|
|
|
GimpItem *item;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
|
|
|
|
|
|
|
item = GIMP_ITEM_UNDO (object)->item;
|
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
switch (GIMP_UNDO (object)->undo_type)
|
2007-01-29 03:00:13 +08:00
|
|
|
{
|
2007-01-31 00:53:20 +08:00
|
|
|
case GIMP_UNDO_ITEM_RENAME:
|
2009-09-01 04:47:18 +08:00
|
|
|
item_prop_undo->name = g_strdup (gimp_object_get_name (item));
|
2007-01-31 00:53:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_ITEM_DISPLACE:
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (item,
|
|
|
|
&item_prop_undo->offset_x,
|
|
|
|
&item_prop_undo->offset_y);
|
2007-01-31 00:53:20 +08:00
|
|
|
break;
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
case GIMP_UNDO_ITEM_VISIBILITY:
|
|
|
|
item_prop_undo->visible = gimp_item_get_visible (item);
|
|
|
|
break;
|
2007-01-29 03:00:13 +08:00
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
case GIMP_UNDO_ITEM_LINKED:
|
|
|
|
item_prop_undo->linked = gimp_item_get_linked (item);
|
|
|
|
break;
|
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
case GIMP_UNDO_PARASITE_ATTACH:
|
|
|
|
case GIMP_UNDO_PARASITE_REMOVE:
|
|
|
|
g_assert (item_prop_undo->parasite_name != NULL);
|
|
|
|
|
|
|
|
item_prop_undo->parasite = gimp_parasite_copy
|
|
|
|
(gimp_item_parasite_find (item, item_prop_undo->parasite_name));
|
|
|
|
break;
|
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2007-01-29 03:00:13 +08:00
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_PARASITE_NAME:
|
|
|
|
item_prop_undo->parasite_name = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_PARASITE_NAME:
|
|
|
|
g_value_set_string (value, item_prop_undo->parasite_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-01 06:06:01 +08:00
|
|
|
static gint64
|
|
|
|
gimp_item_prop_undo_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
|
|
|
{
|
|
|
|
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
|
|
|
gint64 memsize = 0;
|
|
|
|
|
2007-11-17 02:19:30 +08:00
|
|
|
memsize += gimp_string_get_memsize (item_prop_undo->name);
|
|
|
|
memsize += gimp_string_get_memsize (item_prop_undo->parasite_name);
|
|
|
|
memsize += gimp_parasite_get_memsize (item_prop_undo->parasite, NULL);
|
2007-02-02 18:55:38 +08:00
|
|
|
|
2007-02-01 06:06:01 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
|
|
|
|
2007-01-29 03:00:13 +08:00
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
|
|
|
{
|
|
|
|
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo);
|
|
|
|
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
|
|
|
|
|
|
|
|
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
|
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
switch (undo->undo_type)
|
2007-01-29 03:00:13 +08:00
|
|
|
{
|
2007-01-31 00:53:20 +08:00
|
|
|
case GIMP_UNDO_ITEM_RENAME:
|
|
|
|
{
|
|
|
|
gchar *name;
|
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
name = g_strdup (gimp_object_get_name (item));
|
2007-01-31 00:53:20 +08:00
|
|
|
gimp_object_take_name (GIMP_OBJECT (item), item_prop_undo->name);
|
|
|
|
item_prop_undo->name = name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_ITEM_DISPLACE:
|
|
|
|
{
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (item, &offset_x, &offset_y);
|
2007-01-31 00:53:20 +08:00
|
|
|
|
|
|
|
gimp_item_translate (item,
|
|
|
|
item_prop_undo->offset_x - offset_x,
|
|
|
|
item_prop_undo->offset_y - offset_y,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
item_prop_undo->offset_x = offset_x;
|
|
|
|
item_prop_undo->offset_y = offset_y;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_ITEM_VISIBILITY:
|
|
|
|
{
|
|
|
|
gboolean visible;
|
|
|
|
|
|
|
|
visible = gimp_item_get_visible (item);
|
|
|
|
gimp_item_set_visible (item, item_prop_undo->visible, FALSE);
|
|
|
|
item_prop_undo->visible = visible;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_UNDO_ITEM_LINKED:
|
|
|
|
{
|
|
|
|
gboolean linked;
|
|
|
|
|
|
|
|
linked = gimp_item_get_linked (item);
|
|
|
|
gimp_item_set_linked (item, item_prop_undo->linked, FALSE);
|
|
|
|
item_prop_undo->linked = linked;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
case GIMP_UNDO_PARASITE_ATTACH:
|
|
|
|
case GIMP_UNDO_PARASITE_REMOVE:
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
parasite = item_prop_undo->parasite;
|
|
|
|
|
|
|
|
item_prop_undo->parasite = gimp_parasite_copy
|
|
|
|
(gimp_item_parasite_find (item, item_prop_undo->parasite_name));
|
|
|
|
|
|
|
|
if (parasite)
|
|
|
|
gimp_parasite_list_add (item->parasites, parasite);
|
|
|
|
else
|
|
|
|
gimp_parasite_list_remove (item->parasites,
|
|
|
|
item_prop_undo->parasite_name);
|
|
|
|
|
|
|
|
if (parasite)
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
default:
|
2007-01-29 03:00:13 +08:00
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_item_prop_undo_free (GimpUndo *undo,
|
2007-01-31 00:53:20 +08:00
|
|
|
GimpUndoMode undo_mode)
|
2007-01-29 03:00:13 +08:00
|
|
|
{
|
|
|
|
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo);
|
|
|
|
|
|
|
|
if (item_prop_undo->name)
|
|
|
|
{
|
|
|
|
g_free (item_prop_undo->name);
|
|
|
|
item_prop_undo->name = NULL;
|
|
|
|
}
|
2007-01-31 00:53:20 +08:00
|
|
|
|
2007-02-02 18:55:38 +08:00
|
|
|
if (item_prop_undo->parasite_name)
|
|
|
|
{
|
|
|
|
g_free (item_prop_undo->parasite_name);
|
|
|
|
item_prop_undo->parasite_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item_prop_undo->parasite)
|
|
|
|
{
|
|
|
|
gimp_parasite_free (item_prop_undo->parasite);
|
|
|
|
item_prop_undo->parasite = NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-31 00:53:20 +08:00
|
|
|
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
|
2007-01-29 03:00:13 +08:00
|
|
|
}
|