Commit 436ed648 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added new virtual function duplicate() as replacement for all

2003-02-11  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpitem.[ch]: added new virtual function duplicate()
	as replacement for all gimp_*_copy() functions.

	* app/core/gimpchannel.[ch]
	* app/core/gimpdrawable.[ch]
	* app/core/gimplayer.[ch]
	* app/core/gimplayermask.[ch]
	* app/vectors/gimpvectors.[ch]: replaced public copy() functions
	by duplicate() implementations.

	* app/text/gimptextlayer.c: added a duplicate() implementation.

	* app/widgets/gimpitemlistview.[ch]: removed the "copy_item_func"
	and simply call gimp_item_duplicate().

	* app/undo.c
	* app/core/gimpimage-duplicate.c
	* app/core/gimpimage-mask.c
	* app/core/gimpimage-qmask.c
	* app/gui/channels-commands.c
	* app/gui/dialogs-constructors.c
	* app/gui/layers-commands.c
	* app/gui/vectors-commands.c
	* app/widgets/gimptoolbox.c
	* tools/pdbgen/pdb/channel.pdb
	* tools/pdbgen/pdb/layer.pdb
	* tools/pdbgen/pdb/selection.pdb: changed accordingly.

	* app/pdb/channel_cmds.c
	* app/pdb/layer_cmds.c
	* app/pdb/selection_cmds.c: regenerated.
parent b0223ce4
2003-02-11 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added new virtual function duplicate()
as replacement for all gimp_*_copy() functions.
* app/core/gimpchannel.[ch]
* app/core/gimpdrawable.[ch]
* app/core/gimplayer.[ch]
* app/core/gimplayermask.[ch]
* app/vectors/gimpvectors.[ch]: replaced public copy() functions
by duplicate() implementations.
* app/text/gimptextlayer.c: added a duplicate() implementation.
* app/widgets/gimpitemlistview.[ch]: removed the "copy_item_func"
and simply call gimp_item_duplicate().
* app/undo.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.c
* app/core/gimpimage-qmask.c
* app/gui/channels-commands.c
* app/gui/dialogs-constructors.c
* app/gui/layers-commands.c
* app/gui/vectors-commands.c
* app/widgets/gimptoolbox.c
* tools/pdbgen/pdb/channel.pdb
* tools/pdbgen/pdb/layer.pdb
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/channel_cmds.c
* app/pdb/layer_cmds.c
* app/pdb/selection_cmds.c: regenerated.
2003-02-11 Sven Neumann <sven@gimp.org>
* plug-ins/common/uniteditor.c: argh, the "cell-background-gdk"
......
......@@ -120,9 +120,9 @@ channels_duplicate_channel_cmd_callback (GtkWidget *widget,
GimpChannel *new_channel;
return_if_no_channel (gimage, active_channel, data);
new_channel = gimp_channel_copy (active_channel,
G_TYPE_FROM_INSTANCE (active_channel),
TRUE);
new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (active_channel),
G_TYPE_FROM_INSTANCE (active_channel),
TRUE));
gimp_image_add_channel (gimage, new_channel, -1);
gimp_image_flush (gimage);
}
......
......@@ -200,9 +200,9 @@ layers_duplicate_cmd_callback (GtkWidget *widget,
GimpLayer *new_layer;
return_if_no_layer (gimage, active_layer, data);
new_layer = gimp_layer_copy (active_layer,
G_TYPE_FROM_INSTANCE (active_layer),
TRUE);
new_layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (active_layer),
G_TYPE_FROM_INSTANCE (active_layer),
TRUE));
gimp_image_add_layer (gimage, new_layer, -1);
gimp_image_flush (gimage);
......
......@@ -122,9 +122,9 @@ vectors_duplicate_vectors_cmd_callback (GtkWidget *widget,
GimpVectors *new_vectors;
return_if_no_vectors (gimage, active_vectors, data);
new_vectors = gimp_vectors_copy (active_vectors,
G_TYPE_FROM_INSTANCE (active_vectors),
TRUE);
new_vectors = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (active_vectors),
G_TYPE_FROM_INSTANCE (active_vectors),
TRUE));
gimp_image_add_vectors (gimage, new_vectors, -1);
gimp_image_flush (gimage);
}
......
......@@ -48,16 +48,20 @@
#include "libgimp/gimpintl.h"
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_finalize (GObject *object);
static void gimp_channel_finalize (GObject *object);
static gsize gimp_channel_get_memsize (GimpObject *object);
static gsize gimp_channel_get_memsize (GimpObject *object);
static void gimp_channel_push_undo (GimpChannel *mask);
static void gimp_channel_validate (TileManager *tm,
Tile *tile);
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_channel_push_undo (GimpChannel *mask);
static void gimp_channel_validate (TileManager *tm,
Tile *tile);
static GimpDrawableClass * parent_class = NULL;
......@@ -96,15 +100,19 @@ gimp_channel_class_init (GimpChannelClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpItemClass *item_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
item_class = GIMP_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_channel_finalize;
gimp_object_class->get_memsize = gimp_channel_get_memsize;
item_class->duplicate = gimp_channel_duplicate;
}
static void
......@@ -164,6 +172,45 @@ gimp_channel_get_memsize (GimpObject *object)
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
}
static GimpItem *
gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha)
{
GimpChannel *channel;
GimpItem *new_item;
GimpChannel *new_channel;
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
if (g_type_is_a (new_type, GIMP_TYPE_CHANNEL))
add_alpha = FALSE;
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
add_alpha);
if (! GIMP_IS_CHANNEL (new_item))
return new_item;
channel = GIMP_CHANNEL (item);
new_channel = GIMP_CHANNEL (new_item);
/* set the channel color and opacity */
new_channel->color = channel->color;
new_channel->show_masked = channel->show_masked;
/* selection mask variables */
new_channel->bounds_known = channel->bounds_known;
new_channel->empty = channel->empty;
new_channel->x1 = channel->x1;
new_channel->y1 = channel->y1;
new_channel->x2 = channel->x2;
new_channel->y2 = channel->y2;
return new_item;
}
static void
gimp_channel_push_undo (GimpChannel *mask)
{
......@@ -224,41 +271,6 @@ gimp_channel_new (GimpImage *gimage,
return channel;
}
GimpChannel *
gimp_channel_copy (const GimpChannel *channel,
GType new_type,
gboolean dummy) /* the dummy is for symmetry with
* gimp_layer_copy() because
* both functions are used as
* function pointers in
* GimpDrawableListView --Mitch
*/
{
GimpChannel *new_channel;
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_CHANNEL), NULL);
new_channel = GIMP_CHANNEL (gimp_drawable_copy (GIMP_DRAWABLE (channel),
new_type,
FALSE));
/* set the channel color and opacity */
new_channel->color = channel->color;
new_channel->show_masked = channel->show_masked;
/* selection mask variables */
new_channel->bounds_known = channel->bounds_known;
new_channel->empty = channel->empty;
new_channel->x1 = channel->x1;
new_channel->y1 = channel->y1;
new_channel->x2 = channel->x2;
new_channel->y2 = channel->y2;
return new_channel;
}
void
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color)
......
......@@ -77,9 +77,6 @@ GimpChannel * gimp_channel_new (GimpImage *gimage,
gint height,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_copy (const GimpChannel *channel,
GType new_type,
gboolean dummy);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
......
......@@ -48,16 +48,20 @@
#include "libgimp/gimpintl.h"
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_finalize (GObject *object);
static void gimp_channel_finalize (GObject *object);
static gsize gimp_channel_get_memsize (GimpObject *object);
static gsize gimp_channel_get_memsize (GimpObject *object);
static void gimp_channel_push_undo (GimpChannel *mask);
static void gimp_channel_validate (TileManager *tm,
Tile *tile);
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_channel_push_undo (GimpChannel *mask);
static void gimp_channel_validate (TileManager *tm,
Tile *tile);
static GimpDrawableClass * parent_class = NULL;
......@@ -96,15 +100,19 @@ gimp_channel_class_init (GimpChannelClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpItemClass *item_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
item_class = GIMP_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_channel_finalize;
gimp_object_class->get_memsize = gimp_channel_get_memsize;
item_class->duplicate = gimp_channel_duplicate;
}
static void
......@@ -164,6 +172,45 @@ gimp_channel_get_memsize (GimpObject *object)
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
}
static GimpItem *
gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha)
{
GimpChannel *channel;
GimpItem *new_item;
GimpChannel *new_channel;
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
if (g_type_is_a (new_type, GIMP_TYPE_CHANNEL))
add_alpha = FALSE;
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
add_alpha);
if (! GIMP_IS_CHANNEL (new_item))
return new_item;
channel = GIMP_CHANNEL (item);
new_channel = GIMP_CHANNEL (new_item);
/* set the channel color and opacity */
new_channel->color = channel->color;
new_channel->show_masked = channel->show_masked;
/* selection mask variables */
new_channel->bounds_known = channel->bounds_known;
new_channel->empty = channel->empty;
new_channel->x1 = channel->x1;
new_channel->y1 = channel->y1;
new_channel->x2 = channel->x2;
new_channel->y2 = channel->y2;
return new_item;
}
static void
gimp_channel_push_undo (GimpChannel *mask)
{
......@@ -224,41 +271,6 @@ gimp_channel_new (GimpImage *gimage,
return channel;
}
GimpChannel *
gimp_channel_copy (const GimpChannel *channel,
GType new_type,
gboolean dummy) /* the dummy is for symmetry with
* gimp_layer_copy() because
* both functions are used as
* function pointers in
* GimpDrawableListView --Mitch
*/
{
GimpChannel *new_channel;
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_CHANNEL), NULL);
new_channel = GIMP_CHANNEL (gimp_drawable_copy (GIMP_DRAWABLE (channel),
new_type,
FALSE));
/* set the channel color and opacity */
new_channel->color = channel->color;
new_channel->show_masked = channel->show_masked;
/* selection mask variables */
new_channel->bounds_known = channel->bounds_known;
new_channel->empty = channel->empty;
new_channel->x1 = channel->x1;
new_channel->y1 = channel->y1;
new_channel->x2 = channel->x2;
new_channel->y2 = channel->y2;
return new_channel;
}
void
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color)
......
......@@ -77,9 +77,6 @@ GimpChannel * gimp_channel_new (GimpImage *gimage,
gint height,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_copy (const GimpChannel *channel,
GType new_type,
gboolean dummy);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
......
......@@ -63,14 +63,18 @@ enum
/* local function prototypes */
static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init (GimpDrawable *drawable);
static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init (GimpDrawable *drawable);
static void gimp_drawable_finalize (GObject *object);
static void gimp_drawable_finalize (GObject *object);
static gsize gimp_drawable_get_memsize (GimpObject *object);
static gsize gimp_drawable_get_memsize (GimpObject *object);
static void gimp_drawable_invalidate_preview (GimpViewable *viewable);
static void gimp_drawable_invalidate_preview (GimpViewable *viewable);
static GimpItem * gimp_drawable_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
/* private variables */
......@@ -114,10 +118,12 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
GimpItemClass *item_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
item_class = GIMP_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -137,6 +143,8 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
viewable_class->invalidate_preview = gimp_drawable_invalidate_preview;
viewable_class->get_preview = gimp_drawable_get_preview;
item_class->duplicate = gimp_drawable_duplicate;
klass->visibility_changed = NULL;
}
......@@ -213,60 +221,28 @@ gimp_drawable_invalidate_preview (GimpViewable *viewable)
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint offset_x,
gint offset_y,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GIMP_IS_IMAGE (gimage));
/* if not already configured by gimp_item_copy() */
if (! GIMP_ITEM (drawable)->ID)
gimp_item_configure (GIMP_ITEM (drawable), gimage, name);
drawable->width = width;
drawable->height = height;
drawable->type = type;
drawable->bytes = GIMP_IMAGE_TYPE_BYTES (type);
drawable->has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (type);
drawable->offset_x = offset_x;
drawable->offset_y = offset_y;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height,
drawable->bytes);
drawable->visible = TRUE;
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}
GimpDrawable *
gimp_drawable_copy (GimpDrawable *drawable,
GType new_type,
gboolean add_alpha)
static GimpItem *
gimp_drawable_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha)
{
GimpDrawable *drawable;
GimpItem *new_item;
GimpDrawable *new_drawable;
GimpImageType new_image_type;
PixelRegion srcPR;
PixelRegion destPR;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
new_drawable = GIMP_DRAWABLE (gimp_item_copy (GIMP_ITEM (drawable),
new_type,
add_alpha));
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
add_alpha);
if (! GIMP_IS_DRAWABLE (new_item))
return new_item;
drawable = GIMP_DRAWABLE (item);
new_drawable = GIMP_DRAWABLE (new_item);
if (add_alpha)
new_image_type = gimp_drawable_type_with_alpha (drawable);
......@@ -300,7 +276,45 @@ gimp_drawable_copy (GimpDrawable *drawable,
else
add_alpha_region (&srcPR, &destPR);
return new_drawable;
return new_item;
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint offset_x,
gint offset_y,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GIMP_IS_IMAGE (gimage));
/* if not already configured by gimp_item_copy() */
if (! GIMP_ITEM (drawable)->ID)
gimp_item_configure (GIMP_ITEM (drawable), gimage, name);
drawable->width = width;
drawable->height = height;
drawable->type = type;
drawable->bytes = GIMP_IMAGE_TYPE_BYTES (type);
drawable->has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (type);
drawable->offset_x = offset_x;
drawable->offset_y = offset_y;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height,
drawable->bytes);
drawable->visible = TRUE;
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}
void
......
......@@ -71,9 +71,6 @@ void gimp_drawable_configure (GimpDrawable *drawable,
gint height,
GimpImageType type,
const gchar *name);
GimpDrawable * gimp_drawable_copy (GimpDrawable *drawable,
GType new_type,
gboolean add_alpha);
void gimp_drawable_update (GimpDrawable *drawable,
gint x,
......
......@@ -100,7 +100,9 @@ gimp_image_duplicate (GimpImage *gimage)
{
layer = (GimpLayer *) list->data;
new_layer = gimp_layer_copy (layer, G_TYPE_FROM_INSTANCE (layer), FALSE);
new_layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (layer),
G_TYPE_FROM_INSTANCE (layer),
FALSE));
gimp_item_set_image (GIMP_ITEM (new_layer), new_gimage);
......@@ -135,8 +137,10 @@ gimp_image_duplicate (GimpImage *gimage)
{
channel = (GimpChannel *) list->data;
new_channel = gimp_channel_copy (channel, G_TYPE_FROM_INSTANCE (channel),
TRUE);
new_channel =
GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (channel),
G_TYPE_FROM_INSTANCE (channel),
FALSE));
gimp_item_set_image (GIMP_ITEM (new_channel), new_gimage);
......
......@@ -632,7 +632,9 @@ gimp_image_mask_save (GimpImage *gimage)
mask = gimp_image_get_mask (gimage);
new_channel = gimp_channel_copy (mask, G_TYPE_FROM_INSTANCE (mask), FALSE);
new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (mask),
G_TYPE_FROM_INSTANCE (mask),
FALSE));
/* saved selections are not visible by default */
gimp_drawable_set_visible (GIMP_DRAWABLE (new_channel), FALSE);
......
......@@ -93,9 +93,9 @@ gimp_image_set_qmask_state (GimpImage *gimage,
}
else /* if selection */
{
mask = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage); /* Clear the selection */
gimp_image_add_channel (gimage, mask, 0);
......
......@@ -93,9 +93,9 @@ gimp_image_set_qmask_state (GimpImage *gimage,
}
else /* if selection */
{
mask = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage); /* Clear the selection */
gimp_image_add_channel (gimage, mask, 0);
......
......@@ -2706,9 +2706,9 @@ undo_push_vectors_mod (GimpImage *gimage,
new->free_func = undo_free_vectors_mod;
vmu->vectors = vectors;
vmu->undo_vectors = gimp_vectors_copy (vectors,
G_TYPE_FROM_INSTANCE (vectors),
FALSE);
vmu->undo_vectors = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (vectors),
G_TYPE_FROM_INSTANCE (vectors),
FALSE));
return TRUE;
}
......@@ -2729,9 +2729,9 @@ undo_pop_vectors_mod (GimpImage *gimage,
temp = vmu->undo_vectors;