From 436ed648e8ab70ba27ed9741be337de100e164c6 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 11 Feb 2003 13:52:47 +0000 Subject: [PATCH] added new virtual function duplicate() as replacement for all 2003-02-11 Michael Natterer * 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. --- ChangeLog | 34 ++++++++ app/actions/channels-commands.c | 6 +- app/actions/layers-commands.c | 6 +- app/actions/vectors-commands.c | 6 +- app/core/gimpchannel-combine.c | 96 ++++++++++++---------- app/core/gimpchannel-combine.h | 3 - app/core/gimpchannel.c | 96 ++++++++++++---------- app/core/gimpchannel.h | 3 - app/core/gimpdrawable.c | 118 +++++++++++++++------------ app/core/gimpdrawable.h | 3 - app/core/gimpimage-duplicate.c | 10 ++- app/core/gimpimage-mask.c | 4 +- app/core/gimpimage-qmask.c | 6 +- app/core/gimpimage-quick-mask.c | 6 +- app/core/gimpimage-undo-push.c | 12 +-- app/core/gimpitem.c | 93 +++++++++++++--------- app/core/gimpitem.h | 10 ++- app/core/gimplayer.c | 112 ++++++++++++++------------ app/core/gimplayer.h | 3 - app/core/gimplayermask.c | 60 +++++++++----- app/core/gimplayermask.h | 1 - app/dialogs/dialogs-constructors.c | 3 - app/gui/channels-commands.c | 6 +- app/gui/dialogs-constructors.c | 3 - app/gui/layers-commands.c | 6 +- app/gui/vectors-commands.c | 6 +- app/pdb/channel_cmds.c | 2 +- app/pdb/layer_cmds.c | 2 +- app/pdb/selection_cmds.c | 6 +- app/text/gimptextlayer.c | 123 +++++++++++++++++++---------- app/undo.c | 12 +-- app/vectors/gimpvectors.c | 62 +++++++++------ app/vectors/gimpvectors.h | 3 - app/widgets/gimpitemlistview.c | 10 +-- app/widgets/gimpitemlistview.h | 5 -- app/widgets/gimpitemtreeview.c | 10 +-- app/widgets/gimpitemtreeview.h | 5 -- app/widgets/gimptoolbox.c | 12 +-- tools/pdbgen/pdb/channel.pdb | 2 +- tools/pdbgen/pdb/layer.pdb | 2 +- tools/pdbgen/pdb/selection.pdb | 6 +- 41 files changed, 558 insertions(+), 416 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ada6c6e00..4695cfae78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2003-02-11 Michael Natterer + + * 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 * plug-ins/common/uniteditor.c: argh, the "cell-background-gdk" diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c index e88335fa71..4590e7026d 100644 --- a/app/actions/channels-commands.c +++ b/app/actions/channels-commands.c @@ -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); } diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c index 97ba216914..9c088090a3 100644 --- a/app/actions/layers-commands.c +++ b/app/actions/layers-commands.c @@ -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); diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c index 739332c4cf..4b9b193cc5 100644 --- a/app/actions/vectors-commands.c +++ b/app/actions/vectors-commands.c @@ -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); } diff --git a/app/core/gimpchannel-combine.c b/app/core/gimpchannel-combine.c index d0af6fa5db..946ce4650f 100644 --- a/app/core/gimpchannel-combine.c +++ b/app/core/gimpchannel-combine.c @@ -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) diff --git a/app/core/gimpchannel-combine.h b/app/core/gimpchannel-combine.h index a76d885c1b..0915c20692 100644 --- a/app/core/gimpchannel-combine.h +++ b/app/core/gimpchannel-combine.h @@ -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, diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index d0af6fa5db..946ce4650f 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -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) diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h index a76d885c1b..0915c20692 100644 --- a/app/core/gimpchannel.h +++ b/app/core/gimpchannel.h @@ -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, diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c index ebbd0b72e2..eb3cedcea8 100644 --- a/app/core/gimpdrawable.c +++ b/app/core/gimpdrawable.c @@ -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 diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h index ad0af7c0b8..05fba15b46 100644 --- a/app/core/gimpdrawable.h +++ b/app/core/gimpdrawable.h @@ -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, diff --git a/app/core/gimpimage-duplicate.c b/app/core/gimpimage-duplicate.c index e8e5ff01b6..8627b19375 100644 --- a/app/core/gimpimage-duplicate.c +++ b/app/core/gimpimage-duplicate.c @@ -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); diff --git a/app/core/gimpimage-mask.c b/app/core/gimpimage-mask.c index 31e200e655..26ffd2ca5b 100644 --- a/app/core/gimpimage-mask.c +++ b/app/core/gimpimage-mask.c @@ -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); diff --git a/app/core/gimpimage-qmask.c b/app/core/gimpimage-qmask.c index e8a4472f52..fbf582af46 100644 --- a/app/core/gimpimage-qmask.c +++ b/app/core/gimpimage-qmask.c @@ -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); diff --git a/app/core/gimpimage-quick-mask.c b/app/core/gimpimage-quick-mask.c index e8a4472f52..fbf582af46 100644 --- a/app/core/gimpimage-quick-mask.c +++ b/app/core/gimpimage-quick-mask.c @@ -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); diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index 6cd4356272..04d94bab88 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -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; - vmu->undo_vectors = gimp_vectors_copy (vmu->vectors, - G_TYPE_FROM_INSTANCE (vmu->vectors), - FALSE); + vmu->undo_vectors = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (vmu->vectors), + G_TYPE_FROM_INSTANCE (vmu->vectors), + FALSE)); gimp_vectors_copy_strokes (temp, vmu->vectors); diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c index ee91c05fd3..a7623fa11a 100644 --- a/app/core/gimpitem.c +++ b/app/core/gimpitem.c @@ -54,13 +54,17 @@ enum /* local function prototypes */ -static void gimp_item_class_init (GimpItemClass *klass); -static void gimp_item_init (GimpItem *item); +static void gimp_item_class_init (GimpItemClass *klass); +static void gimp_item_init (GimpItem *item); -static void gimp_item_finalize (GObject *object); +static void gimp_item_finalize (GObject *object); -static void gimp_item_name_changed (GimpObject *object); -static gsize gimp_item_get_memsize (GimpObject *object); +static void gimp_item_name_changed (GimpObject *object); +static gsize gimp_item_get_memsize (GimpObject *object); + +static GimpItem * gimp_item_real_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); /* private variables */ @@ -124,6 +128,7 @@ gimp_item_class_init (GimpItemClass *klass) gimp_object_class->get_memsize = gimp_item_get_memsize; klass->removed = NULL; + klass->duplicate = gimp_item_real_duplicate; } static void @@ -271,39 +276,10 @@ gimp_item_get_memsize (GimpObject *object) return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object); } -void -gimp_item_removed (GimpItem *item) -{ - g_return_if_fail (GIMP_IS_ITEM (item)); - - g_signal_emit (item, gimp_item_signals[REMOVED], 0); -} - -void -gimp_item_configure (GimpItem *item, - GimpImage *gimage, - const gchar *name) -{ - g_return_if_fail (GIMP_IS_ITEM (item)); - g_return_if_fail (item->ID == 0); - g_return_if_fail (item->gimage == 0); - g_return_if_fail (GIMP_IS_IMAGE (gimage)); - - item->ID = gimage->gimp->next_item_ID++; - - g_hash_table_insert (gimage->gimp->item_table, - GINT_TO_POINTER (item->ID), - item); - - gimp_item_set_image (item, gimage); - - gimp_object_set_name (GIMP_OBJECT (item), name ? name : _("Unnamed")); -} - -GimpItem * -gimp_item_copy (GimpItem *item, - GType new_type, - gboolean add_alpha) +static GimpItem * +gimp_item_real_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) { GimpItem *new_item; gchar *new_name; @@ -352,6 +328,47 @@ gimp_item_copy (GimpItem *item, return new_item; } +void +gimp_item_removed (GimpItem *item) +{ + g_return_if_fail (GIMP_IS_ITEM (item)); + + g_signal_emit (item, gimp_item_signals[REMOVED], 0); +} + +void +gimp_item_configure (GimpItem *item, + GimpImage *gimage, + const gchar *name) +{ + g_return_if_fail (GIMP_IS_ITEM (item)); + g_return_if_fail (item->ID == 0); + g_return_if_fail (item->gimage == 0); + g_return_if_fail (GIMP_IS_IMAGE (gimage)); + + item->ID = gimage->gimp->next_item_ID++; + + g_hash_table_insert (gimage->gimp->item_table, + GINT_TO_POINTER (item->ID), + item); + + gimp_item_set_image (item, gimage); + + gimp_object_set_name (GIMP_OBJECT (item), name ? name : _("Unnamed")); +} + +GimpItem * +gimp_item_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) +{ + g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); + g_return_val_if_fail (GIMP_IS_IMAGE (item->gimage), NULL); + g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_ITEM), NULL); + + return GIMP_ITEM_GET_CLASS (item)->duplicate (item, new_type, add_alpha); +} + gint gimp_item_get_ID (GimpItem *item) { diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h index b2bcbfca3d..a55031df47 100644 --- a/app/core/gimpitem.h +++ b/app/core/gimpitem.h @@ -49,7 +49,13 @@ struct _GimpItemClass { GimpViewableClass parent_class; - void (* removed) (GimpItem *item); + /* signals */ + void (* removed) (GimpItem *item); + + /* virtual functions */ + GimpItem * (* duplicate) (GimpItem *item, + GType new_type, + gboolean add_alpha); }; @@ -60,7 +66,7 @@ void gimp_item_removed (GimpItem *item); void gimp_item_configure (GimpItem *item, GimpImage *gimage, const gchar *name); -GimpItem * gimp_item_copy (GimpItem *item, +GimpItem * gimp_item_duplicate (GimpItem *item, GType new_type, gboolean add_alpha); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index 0fd98f4990..c2330fd35e 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -60,20 +60,24 @@ enum }; -static void gimp_layer_class_init (GimpLayerClass *klass); -static void gimp_layer_init (GimpLayer *layer); +static void gimp_layer_class_init (GimpLayerClass *klass); +static void gimp_layer_init (GimpLayer *layer); -static void gimp_layer_finalize (GObject *object); +static void gimp_layer_finalize (GObject *object); -static gsize gimp_layer_get_memsize (GimpObject *object); +static gsize gimp_layer_get_memsize (GimpObject *object); -static void gimp_layer_invalidate_preview (GimpViewable *viewable); +static void gimp_layer_invalidate_preview (GimpViewable *viewable); -static void gimp_layer_transform_color (GimpImage *gimage, - PixelRegion *layerPR, - PixelRegion *bufPR, - GimpDrawable *drawable, - GimpImageBaseType type); +static GimpItem * gimp_layer_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); + +static void gimp_layer_transform_color (GimpImage *gimage, + PixelRegion *layerPR, + PixelRegion *bufPR, + GimpDrawable *drawable, + GimpImageBaseType type); static guint layer_signals[LAST_SIGNAL] = { 0 }; @@ -115,10 +119,12 @@ gimp_layer_class_init (GimpLayerClass *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); @@ -173,6 +179,8 @@ gimp_layer_class_init (GimpLayerClass *klass) viewable_class->invalidate_preview = gimp_layer_invalidate_preview; + item_class->duplicate = gimp_layer_duplicate; + klass->opacity_changed = NULL; klass->mode_changed = NULL; klass->preserve_trans_changed = NULL; @@ -263,6 +271,46 @@ gimp_layer_invalidate_preview (GimpViewable *viewable) floating_sel_invalidate (layer); } +static GimpItem * +gimp_layer_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) +{ + GimpLayer *layer; + GimpItem *new_item; + GimpLayer *new_layer; + + g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL); + + new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type, + add_alpha); + + if (! GIMP_IS_LAYER (new_item)) + return new_item; + + layer = GIMP_LAYER (item); + new_layer = GIMP_LAYER (new_item); + + new_layer->linked = layer->linked; + new_layer->preserve_trans = layer->preserve_trans; + + new_layer->mode = layer->mode; + new_layer->opacity = layer->opacity; + + /* duplicate the layer mask if necessary */ + if (layer->mask) + { + new_layer->mask = + GIMP_LAYER_MASK (gimp_item_duplicate (GIMP_ITEM (layer->mask), + G_TYPE_FROM_INSTANCE (layer->mask), + FALSE)); + + gimp_layer_mask_set_layer (new_layer->mask, new_layer); + } + + return new_item; +} + static void gimp_layer_transform_color (GimpImage *gimage, PixelRegion *layerPR, @@ -336,37 +384,6 @@ gimp_layer_new (GimpImage *gimage, return layer; } -GimpLayer * -gimp_layer_copy (const GimpLayer *layer, - GType new_type, - gboolean add_alpha) -{ - GimpLayer *new_layer; - - g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL); - g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_LAYER), NULL); - - new_layer = GIMP_LAYER (gimp_drawable_copy (GIMP_DRAWABLE (layer), - new_type, - add_alpha)); - - new_layer->linked = layer->linked; - new_layer->preserve_trans = layer->preserve_trans; - - new_layer->mode = layer->mode; - new_layer->opacity = layer->opacity; - - /* duplicate the layer mask if necessary */ - if (layer->mask) - { - new_layer->mask = gimp_layer_mask_copy (layer->mask); - - gimp_layer_mask_set_layer (new_layer->mask, new_layer); - } - - return new_layer; -} - /** * gimp_layer_new_from_tiles: * @tiles: The buffer to make the new layer from. @@ -460,18 +477,9 @@ gimp_layer_new_from_drawable (GimpDrawable *drawable, src_base_type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)); new_base_type = gimp_image_base_type (dest_image); - if (GIMP_IS_LAYER (drawable)) - { - new_drawable = GIMP_DRAWABLE (gimp_layer_copy (GIMP_LAYER (drawable), - G_TYPE_FROM_INSTANCE (drawable), + new_drawable = GIMP_DRAWABLE (gimp_item_duplicate (GIMP_ITEM (drawable), + GIMP_TYPE_LAYER, TRUE)); - } - else - { - new_drawable = gimp_drawable_copy (drawable, - GIMP_TYPE_LAYER, - TRUE); - } if (src_base_type != new_base_type) { diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index 22ab61e05a..e9b1ca23fe 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -81,9 +81,6 @@ GimpLayer * gimp_layer_new (GimpImage *gimage, const gchar *name, gdouble opacity, GimpLayerModeEffects mode); -GimpLayer * gimp_layer_copy (const GimpLayer *layer, - GType new_type, - gboolean add_alpha); GimpLayer * gimp_layer_new_from_tiles (TileManager *tiles, GimpImage *dest_gimage, diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c index 3be6997496..eb41193674 100644 --- a/app/core/gimplayermask.c +++ b/app/core/gimplayermask.c @@ -45,8 +45,12 @@ enum }; -static void gimp_layer_mask_class_init (GimpLayerMaskClass *klass); -static void gimp_layer_mask_init (GimpLayerMask *layer_mask); +static void gimp_layer_mask_class_init (GimpLayerMaskClass *klass); +static void gimp_layer_mask_init (GimpLayerMask *layer_mask); + +static GimpItem * gimp_layer_mask_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); static guint layer_mask_signals[LAST_SIGNAL] = { 0 }; @@ -85,6 +89,10 @@ gimp_layer_mask_get_type (void) static void gimp_layer_mask_class_init (GimpLayerMaskClass *klass) { + GimpItemClass *item_class; + + item_class = GIMP_ITEM_CLASS (klass); + parent_class = g_type_class_peek_parent (klass); layer_mask_signals[APPLY_CHANGED] = @@ -113,6 +121,8 @@ gimp_layer_mask_class_init (GimpLayerMaskClass *klass) NULL, NULL, gimp_marshal_VOID__VOID, G_TYPE_NONE, 0); + + item_class->duplicate = gimp_layer_mask_duplicate; } static void @@ -124,6 +134,33 @@ gimp_layer_mask_init (GimpLayerMask *layer_mask) layer_mask->show_mask = FALSE; } +static GimpItem * +gimp_layer_mask_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) +{ + GimpLayerMask *layer_mask; + GimpItem *new_item; + GimpLayerMask *new_layer_mask; + + g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL); + + new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type, + add_alpha); + + if (! GIMP_IS_LAYER_MASK (new_item)) + return new_item; + + layer_mask = GIMP_LAYER_MASK (item); + new_layer_mask = GIMP_LAYER_MASK (new_item); + + new_layer_mask->apply_mask = layer_mask->apply_mask; + new_layer_mask->edit_mask = layer_mask->edit_mask; + new_layer_mask->show_mask = layer_mask->show_mask; + + return item; +} + GimpLayerMask * gimp_layer_mask_new (GimpImage *gimage, gint width, @@ -152,25 +189,6 @@ gimp_layer_mask_new (GimpImage *gimage, return layer_mask; } -GimpLayerMask * -gimp_layer_mask_copy (const GimpLayerMask *layer_mask) -{ - GimpLayerMask *new_layer_mask; - - g_return_val_if_fail (GIMP_IS_LAYER_MASK (layer_mask), NULL); - - new_layer_mask = - GIMP_LAYER_MASK (gimp_channel_copy (GIMP_CHANNEL (layer_mask), - GIMP_TYPE_LAYER_MASK, - FALSE)); - - new_layer_mask->apply_mask = layer_mask->apply_mask; - new_layer_mask->edit_mask = layer_mask->edit_mask; - new_layer_mask->show_mask = layer_mask->show_mask; - - return new_layer_mask; -} - void gimp_layer_mask_set_layer (GimpLayerMask *layer_mask, GimpLayer *layer) diff --git a/app/core/gimplayermask.h b/app/core/gimplayermask.h index 0242a631e9..27bd3be21c 100644 --- a/app/core/gimplayermask.h +++ b/app/core/gimplayermask.h @@ -63,7 +63,6 @@ GimpLayerMask * gimp_layer_mask_new (GimpImage *gimage, gint height, const gchar *name, const GimpRGB *color); -GimpLayerMask * gimp_layer_mask_copy (const GimpLayerMask *layer_mask); void gimp_layer_mask_set_layer (GimpLayerMask *layer_mask, GimpLayer *layer); diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index d5d55ce149..61e205ced3 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -643,7 +643,6 @@ dialogs_layer_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_layer, (GimpAddItemFunc) gimp_image_add_layer, (GimpRemoveItemFunc) layers_remove_layer, - (GimpCopyItemFunc) gimp_layer_copy, (GimpConvertItemFunc) gimp_layer_new_from_drawable, (GimpNewItemFunc) layers_new_layer_query, (GimpEditItemFunc) layers_edit_layer_query, @@ -686,7 +685,6 @@ dialogs_channel_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_channel, (GimpAddItemFunc) gimp_image_add_channel, (GimpRemoveItemFunc) gimp_image_remove_channel, - (GimpCopyItemFunc) gimp_channel_copy, (GimpConvertItemFunc) NULL, (GimpNewItemFunc) channels_new_channel_query, (GimpEditItemFunc) channels_edit_channel_query, @@ -726,7 +724,6 @@ dialogs_vectors_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_vectors, (GimpAddItemFunc) gimp_image_add_vectors, (GimpRemoveItemFunc) gimp_image_remove_vectors, - (GimpCopyItemFunc) gimp_vectors_copy, (GimpConvertItemFunc) NULL, (GimpNewItemFunc) vectors_new_vectors_query, (GimpEditItemFunc) vectors_edit_vectors_query, diff --git a/app/gui/channels-commands.c b/app/gui/channels-commands.c index e88335fa71..4590e7026d 100644 --- a/app/gui/channels-commands.c +++ b/app/gui/channels-commands.c @@ -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); } diff --git a/app/gui/dialogs-constructors.c b/app/gui/dialogs-constructors.c index d5d55ce149..61e205ced3 100644 --- a/app/gui/dialogs-constructors.c +++ b/app/gui/dialogs-constructors.c @@ -643,7 +643,6 @@ dialogs_layer_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_layer, (GimpAddItemFunc) gimp_image_add_layer, (GimpRemoveItemFunc) layers_remove_layer, - (GimpCopyItemFunc) gimp_layer_copy, (GimpConvertItemFunc) gimp_layer_new_from_drawable, (GimpNewItemFunc) layers_new_layer_query, (GimpEditItemFunc) layers_edit_layer_query, @@ -686,7 +685,6 @@ dialogs_channel_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_channel, (GimpAddItemFunc) gimp_image_add_channel, (GimpRemoveItemFunc) gimp_image_remove_channel, - (GimpCopyItemFunc) gimp_channel_copy, (GimpConvertItemFunc) NULL, (GimpNewItemFunc) channels_new_channel_query, (GimpEditItemFunc) channels_edit_channel_query, @@ -726,7 +724,6 @@ dialogs_vectors_list_view_new (GimpDialogFactory *factory, (GimpReorderItemFunc) gimp_image_position_vectors, (GimpAddItemFunc) gimp_image_add_vectors, (GimpRemoveItemFunc) gimp_image_remove_vectors, - (GimpCopyItemFunc) gimp_vectors_copy, (GimpConvertItemFunc) NULL, (GimpNewItemFunc) vectors_new_vectors_query, (GimpEditItemFunc) vectors_edit_vectors_query, diff --git a/app/gui/layers-commands.c b/app/gui/layers-commands.c index 97ba216914..9c088090a3 100644 --- a/app/gui/layers-commands.c +++ b/app/gui/layers-commands.c @@ -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); diff --git a/app/gui/vectors-commands.c b/app/gui/vectors-commands.c index 739332c4cf..4b9b193cc5 100644 --- a/app/gui/vectors-commands.c +++ b/app/gui/vectors-commands.c @@ -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); } diff --git a/app/pdb/channel_cmds.c b/app/pdb/channel_cmds.c index 2732fbebdd..a8e1b3f8ca 100644 --- a/app/pdb/channel_cmds.c +++ b/app/pdb/channel_cmds.c @@ -198,7 +198,7 @@ channel_copy_invoker (Gimp *gimp, success = FALSE; if (success) - success = (copy = gimp_channel_copy (channel, G_TYPE_FROM_INSTANCE (channel), TRUE)) != NULL; + success = (copy = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (channel), G_TYPE_FROM_INSTANCE (channel), FALSE))) != NULL; return_args = procedural_db_return_args (&channel_copy_proc, success); diff --git a/app/pdb/layer_cmds.c b/app/pdb/layer_cmds.c index 284176fa7f..7501974d1f 100644 --- a/app/pdb/layer_cmds.c +++ b/app/pdb/layer_cmds.c @@ -251,7 +251,7 @@ layer_copy_invoker (Gimp *gimp, add_alpha = args[1].value.pdb_int ? TRUE : FALSE; if (success) - success = (copy = gimp_layer_copy (layer, G_TYPE_FROM_INSTANCE (layer), add_alpha)) != NULL; + success = (copy = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (layer), G_TYPE_FROM_INSTANCE (layer), add_alpha))) != NULL; return_args = procedural_db_return_args (&layer_copy_proc, success); diff --git a/app/pdb/selection_cmds.c b/app/pdb/selection_cmds.c index 62ae1c8a86..0e68c49b5f 100644 --- a/app/pdb/selection_cmds.c +++ b/app/pdb/selection_cmds.c @@ -1024,9 +1024,9 @@ selection_combine_invoker (Gimp *gimp, if (gimp_drawable_width (GIMP_DRAWABLE (channel)) == gimage->width && gimp_drawable_height (GIMP_DRAWABLE (channel)) == gimage->height) { - new_channel = gimp_channel_copy (gimp_image_get_mask (gimage), - G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)), - TRUE); + new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)), + G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)), + FALSE)); gimp_channel_combine_mask (new_channel, channel, operation, diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c index 5f6a3ad664..e1920e9b13 100644 --- a/app/text/gimptextlayer.c +++ b/app/text/gimptextlayer.c @@ -32,6 +32,8 @@ #include "paint-funcs/paint-funcs.h" +#include "config/gimpconfig.h" + #include "core/gimpimage.h" #include "gimptext.h" @@ -39,20 +41,23 @@ #include "gimptextlayout.h" -static void gimp_text_layer_class_init (GimpTextLayerClass *klass); -static void gimp_text_layer_init (GimpTextLayer *layer); -static void gimp_text_layer_dispose (GObject *object); +static void gimp_text_layer_class_init (GimpTextLayerClass *klass); +static void gimp_text_layer_init (GimpTextLayer *layer); +static void gimp_text_layer_dispose (GObject *object); -static gsize gimp_text_layer_get_memsize (GimpObject *object); -static TempBuf * gimp_text_layer_get_preview (GimpViewable *viewable, - gint width, - gint height); +static gsize gimp_text_layer_get_memsize (GimpObject *object); +static TempBuf * gimp_text_layer_get_preview (GimpViewable *viewable, + gint width, + gint height); +static GimpItem * gimp_text_layer_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); -static void gimp_text_layer_notify_text (GimpTextLayer *layer); -static gboolean gimp_text_layer_idle_render (GimpTextLayer *layer); -static gboolean gimp_text_layer_render (GimpTextLayer *layer); -static void gimp_text_layer_render_layout (GimpTextLayer *layer, - GimpTextLayout *layout); +static void gimp_text_layer_notify_text (GimpTextLayer *layer); +static gboolean gimp_text_layer_idle_render (GimpTextLayer *layer); +static gboolean gimp_text_layer_render (GimpTextLayer *layer); +static void gimp_text_layer_render_layout (GimpTextLayer *layer, + GimpTextLayout *layout); static GimpLayerClass *parent_class = NULL; @@ -92,18 +97,22 @@ gimp_text_layer_class_init (GimpTextLayerClass *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); - object_class->dispose = gimp_text_layer_dispose; + object_class->dispose = gimp_text_layer_dispose; gimp_object_class->get_memsize = gimp_text_layer_get_memsize; - viewable_class->get_preview = gimp_text_layer_get_preview; + viewable_class->get_preview = gimp_text_layer_get_preview; + + item_class->duplicate = gimp_text_layer_duplicate; } static void @@ -133,6 +142,64 @@ gimp_text_layer_dispose (GObject *object) G_OBJECT_CLASS (parent_class)->dispose (object); } +static gsize +gimp_text_layer_get_memsize (GimpObject *object) +{ + GimpTextLayer *text_layer; + gsize memsize = 0; + + text_layer = GIMP_TEXT_LAYER (object); + + if (text_layer->text) + { + memsize += sizeof (GimpText); + + if (text_layer->text->text) + memsize += strlen (text_layer->text->text); + } + + return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object); +} + +static TempBuf * +gimp_text_layer_get_preview (GimpViewable *viewable, + gint width, + gint height) +{ + return GIMP_VIEWABLE_CLASS (parent_class)->get_preview (viewable, + width, height); +} + +static GimpItem * +gimp_text_layer_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) +{ + GimpTextLayer *text_layer; + GimpItem *new_item; + GimpTextLayer *new_text_layer; + + g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL); + + new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type, + add_alpha); + + if (! GIMP_IS_TEXT_LAYER (new_item)) + return new_item; + + text_layer = GIMP_TEXT_LAYER (item); + new_text_layer = GIMP_TEXT_LAYER (new_item); + + new_text_layer->text = + GIMP_TEXT (gimp_config_duplicate (G_OBJECT (text_layer->text))); + + g_signal_connect_object (new_text_layer->text, "notify", + G_CALLBACK (gimp_text_layer_notify_text), + new_text_layer, G_CONNECT_SWAPPED); + + return new_item; +} + GimpLayer * gimp_text_layer_new (GimpImage *image, GimpText *text) @@ -176,34 +243,6 @@ gimp_text_layer_get_text (GimpTextLayer *layer) return layer->text; } -static gsize -gimp_text_layer_get_memsize (GimpObject *object) -{ - GimpTextLayer *text_layer; - gsize memsize = 0; - - text_layer = GIMP_TEXT_LAYER (object); - - if (text_layer->text) - { - memsize += sizeof (GimpText); - - if (text_layer->text->text) - memsize += strlen (text_layer->text->text); - } - - return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object); -} - -static TempBuf * -gimp_text_layer_get_preview (GimpViewable *viewable, - gint width, - gint height) -{ - return GIMP_VIEWABLE_CLASS (parent_class)->get_preview (viewable, - width, height); -} - static void gimp_text_layer_notify_text (GimpTextLayer *layer) { diff --git a/app/undo.c b/app/undo.c index 6cd4356272..04d94bab88 100644 --- a/app/undo.c +++ b/app/undo.c @@ -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; - vmu->undo_vectors = gimp_vectors_copy (vmu->vectors, - G_TYPE_FROM_INSTANCE (vmu->vectors), - FALSE); + vmu->undo_vectors = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (vmu->vectors), + G_TYPE_FROM_INSTANCE (vmu->vectors), + FALSE)); gimp_vectors_copy_strokes (temp, vmu->vectors); diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c index 54a0deb3ad..da775714d9 100644 --- a/app/vectors/gimpvectors.c +++ b/app/vectors/gimpvectors.c @@ -33,12 +33,16 @@ #include "gimpvectors-preview.h" -static void gimp_vectors_class_init (GimpVectorsClass *klass); -static void gimp_vectors_init (GimpVectors *vectors); +static void gimp_vectors_class_init (GimpVectorsClass *klass); +static void gimp_vectors_init (GimpVectors *vectors); -static void gimp_vectors_finalize (GObject *object); +static void gimp_vectors_finalize (GObject *object); -static gsize gimp_vectors_get_memsize (GimpObject *object); +static gsize gimp_vectors_get_memsize (GimpObject *object); + +static GimpItem * gimp_vectors_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); /* private variables */ @@ -80,10 +84,12 @@ gimp_vectors_class_init (GimpVectorsClass *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); @@ -93,6 +99,8 @@ gimp_vectors_class_init (GimpVectorsClass *klass) viewable_class->get_new_preview = gimp_vectors_get_new_preview; + item_class->duplicate = gimp_vectors_duplicate; + klass->changed = NULL; klass->stroke_add = NULL; @@ -140,6 +148,31 @@ gimp_vectors_get_memsize (GimpObject *object) return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object); } +static GimpItem * +gimp_vectors_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha) +{ + GimpVectors *vectors; + GimpItem *new_item; + GimpVectors *new_vectors; + + g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_VECTORS), NULL); + + new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type, + add_alpha); + + if (! GIMP_IS_VECTORS (new_item)) + return new_item; + + vectors = GIMP_VECTORS (item); + new_vectors = GIMP_VECTORS (new_item); + + gimp_vectors_copy_strokes (vectors, new_vectors); + + return new_item;; +} + /* public functions */ @@ -158,27 +191,6 @@ gimp_vectors_new (GimpImage *gimage, return vectors; } -GimpVectors * -gimp_vectors_copy (const GimpVectors *vectors, - GType new_type, - gboolean add_alpha /* unused */) -{ - GimpVectors *new_vectors; - - g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); - g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_VECTORS), NULL); - - new_vectors = GIMP_VECTORS (gimp_item_copy (GIMP_ITEM (vectors), - new_type, - add_alpha)); - -#ifdef __GNUC__ -#warning FIXME: implement gimp_vectors_copy() -#endif - - return new_vectors; -} - void gimp_vectors_copy_strokes (const GimpVectors *src_vectors, GimpVectors *dest_vectors) diff --git a/app/vectors/gimpvectors.h b/app/vectors/gimpvectors.h index 4f9028f5fc..7d58a44c8c 100644 --- a/app/vectors/gimpvectors.h +++ b/app/vectors/gimpvectors.h @@ -96,9 +96,6 @@ GType gimp_vectors_get_type (void) G_GNUC_CONST; GimpVectors * gimp_vectors_new (GimpImage *gimage, const gchar *name); -GimpVectors * gimp_vectors_copy (const GimpVectors *vectors, - GType new_type, - gboolean add_alpha /* unused */); void gimp_vectors_copy_strokes (const GimpVectors *src_vectors, GimpVectors *dest_vectors); diff --git a/app/widgets/gimpitemlistview.c b/app/widgets/gimpitemlistview.c index 17cbeef1bf..dfc71f2e6a 100644 --- a/app/widgets/gimpitemlistview.c +++ b/app/widgets/gimpitemlistview.c @@ -285,7 +285,6 @@ gimp_item_list_view_new (gint preview_size, GimpReorderItemFunc reorder_item_func, GimpAddItemFunc add_item_func, GimpRemoveItemFunc remove_item_func, - GimpCopyItemFunc copy_item_func, GimpConvertItemFunc convert_item_func, GimpNewItemFunc new_item_func, GimpEditItemFunc edit_item_func, @@ -306,7 +305,6 @@ gimp_item_list_view_new (gint preview_size, g_return_val_if_fail (reorder_item_func != NULL, NULL); g_return_val_if_fail (add_item_func != NULL, NULL); g_return_val_if_fail (remove_item_func != NULL, NULL); - g_return_val_if_fail (copy_item_func != NULL, NULL); /* convert_item_func may be NULL */ g_return_val_if_fail (new_item_func != NULL, NULL); g_return_val_if_fail (edit_item_func != NULL, NULL); @@ -348,7 +346,6 @@ gimp_item_list_view_new (gint preview_size, list_view->reorder_item_func = reorder_item_func; list_view->add_item_func = add_item_func; list_view->remove_item_func = remove_item_func; - list_view->copy_item_func = copy_item_func; list_view->convert_item_func = convert_item_func; list_view->new_item_func = new_item_func; list_view->edit_item_func = edit_item_func; @@ -581,9 +578,10 @@ gimp_item_list_view_duplicate_clicked (GtkWidget *widget, viewable = view->get_item_func (view->gimage); - new_viewable = view->copy_item_func (viewable, - G_TYPE_FROM_INSTANCE (viewable), - TRUE); + new_viewable = (GimpViewable *) + gimp_item_duplicate (GIMP_ITEM (viewable), + G_TYPE_FROM_INSTANCE (viewable), + TRUE); if (GIMP_IS_VIEWABLE (new_viewable)) { diff --git a/app/widgets/gimpitemlistview.h b/app/widgets/gimpitemlistview.h index 6da9cf28e7..1e2de29b4c 100644 --- a/app/widgets/gimpitemlistview.h +++ b/app/widgets/gimpitemlistview.h @@ -39,9 +39,6 @@ typedef void (* GimpAddItemFunc) (GimpImage *gimage, gint index); typedef void (* GimpRemoveItemFunc) (GimpImage *gimage, GimpViewable *viewable); -typedef GimpViewable * (* GimpCopyItemFunc) (GimpViewable *viewable, - GType new_type, - gboolean add_alpha); typedef GimpViewable * (* GimpConvertItemFunc) (GimpViewable *viewable, GimpImage *dest_gimage); @@ -77,7 +74,6 @@ struct _GimpItemListView GimpReorderItemFunc reorder_item_func; GimpAddItemFunc add_item_func; GimpRemoveItemFunc remove_item_func; - GimpCopyItemFunc copy_item_func; GimpConvertItemFunc convert_item_func; GimpNewItemFunc new_item_func; @@ -115,7 +111,6 @@ GtkWidget * gimp_item_list_view_new (gint preview_size, GimpReorderItemFunc reorder_item_func, GimpAddItemFunc add_item_func, GimpRemoveItemFunc remove_item_func, - GimpCopyItemFunc copy_item_func, GimpConvertItemFunc convert_item_func, GimpNewItemFunc new_item_func, GimpEditItemFunc edit_item_func, diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c index 17cbeef1bf..dfc71f2e6a 100644 --- a/app/widgets/gimpitemtreeview.c +++ b/app/widgets/gimpitemtreeview.c @@ -285,7 +285,6 @@ gimp_item_list_view_new (gint preview_size, GimpReorderItemFunc reorder_item_func, GimpAddItemFunc add_item_func, GimpRemoveItemFunc remove_item_func, - GimpCopyItemFunc copy_item_func, GimpConvertItemFunc convert_item_func, GimpNewItemFunc new_item_func, GimpEditItemFunc edit_item_func, @@ -306,7 +305,6 @@ gimp_item_list_view_new (gint preview_size, g_return_val_if_fail (reorder_item_func != NULL, NULL); g_return_val_if_fail (add_item_func != NULL, NULL); g_return_val_if_fail (remove_item_func != NULL, NULL); - g_return_val_if_fail (copy_item_func != NULL, NULL); /* convert_item_func may be NULL */ g_return_val_if_fail (new_item_func != NULL, NULL); g_return_val_if_fail (edit_item_func != NULL, NULL); @@ -348,7 +346,6 @@ gimp_item_list_view_new (gint preview_size, list_view->reorder_item_func = reorder_item_func; list_view->add_item_func = add_item_func; list_view->remove_item_func = remove_item_func; - list_view->copy_item_func = copy_item_func; list_view->convert_item_func = convert_item_func; list_view->new_item_func = new_item_func; list_view->edit_item_func = edit_item_func; @@ -581,9 +578,10 @@ gimp_item_list_view_duplicate_clicked (GtkWidget *widget, viewable = view->get_item_func (view->gimage); - new_viewable = view->copy_item_func (viewable, - G_TYPE_FROM_INSTANCE (viewable), - TRUE); + new_viewable = (GimpViewable *) + gimp_item_duplicate (GIMP_ITEM (viewable), + G_TYPE_FROM_INSTANCE (viewable), + TRUE); if (GIMP_IS_VIEWABLE (new_viewable)) { diff --git a/app/widgets/gimpitemtreeview.h b/app/widgets/gimpitemtreeview.h index 6da9cf28e7..1e2de29b4c 100644 --- a/app/widgets/gimpitemtreeview.h +++ b/app/widgets/gimpitemtreeview.h @@ -39,9 +39,6 @@ typedef void (* GimpAddItemFunc) (GimpImage *gimage, gint index); typedef void (* GimpRemoveItemFunc) (GimpImage *gimage, GimpViewable *viewable); -typedef GimpViewable * (* GimpCopyItemFunc) (GimpViewable *viewable, - GType new_type, - gboolean add_alpha); typedef GimpViewable * (* GimpConvertItemFunc) (GimpViewable *viewable, GimpImage *dest_gimage); @@ -77,7 +74,6 @@ struct _GimpItemListView GimpReorderItemFunc reorder_item_func; GimpAddItemFunc add_item_func; GimpRemoveItemFunc remove_item_func; - GimpCopyItemFunc copy_item_func; GimpConvertItemFunc convert_item_func; GimpNewItemFunc new_item_func; @@ -115,7 +111,6 @@ GtkWidget * gimp_item_list_view_new (gint preview_size, GimpReorderItemFunc reorder_item_func, GimpAddItemFunc add_item_func, GimpRemoveItemFunc remove_item_func, - GimpCopyItemFunc copy_item_func, GimpConvertItemFunc convert_item_func, GimpNewItemFunc new_item_func, GimpEditItemFunc edit_item_func, diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c index 0e3bcf99bd..39b10eb201 100644 --- a/app/widgets/gimptoolbox.c +++ b/app/widgets/gimptoolbox.c @@ -867,15 +867,15 @@ toolbox_drop_drawable (GtkWidget *widget, if (GIMP_IS_LAYER (drawable)) { - new_layer = gimp_layer_copy (GIMP_LAYER (drawable), - G_TYPE_FROM_INSTANCE (drawable), - FALSE); + new_layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (drawable), + G_TYPE_FROM_INSTANCE (drawable), + FALSE)); } else { - new_layer = GIMP_LAYER (gimp_drawable_copy (drawable, - GIMP_TYPE_LAYER, - TRUE)); + new_layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (drawable), + GIMP_TYPE_LAYER, + TRUE)); } gimp_item_set_image (GIMP_ITEM (new_layer), new_gimage); diff --git a/tools/pdbgen/pdb/channel.pdb b/tools/pdbgen/pdb/channel.pdb index 284a6b20fc..e021454889 100644 --- a/tools/pdbgen/pdb/channel.pdb +++ b/tools/pdbgen/pdb/channel.pdb @@ -202,7 +202,7 @@ HELP desc => 'The newly copied channel', alias => 'copy' } ); - %invoke = ( code => 'success = (copy = gimp_channel_copy (channel, G_TYPE_FROM_INSTANCE (channel), TRUE)) != NULL;' ); + %invoke = ( code => 'success = (copy = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (channel), G_TYPE_FROM_INSTANCE (channel), FALSE))) != NULL;' ); } sub channel_delete { diff --git a/tools/pdbgen/pdb/layer.pdb b/tools/pdbgen/pdb/layer.pdb index e462c14bbb..91faaaee50 100644 --- a/tools/pdbgen/pdb/layer.pdb +++ b/tools/pdbgen/pdb/layer.pdb @@ -289,7 +289,7 @@ HELP ); %invoke = ( - code => 'success = (copy = gimp_layer_copy (layer, G_TYPE_FROM_INSTANCE (layer), add_alpha)) != NULL;' + code => 'success = (copy = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (layer), G_TYPE_FROM_INSTANCE (layer), add_alpha))) != NULL;' ); } diff --git a/tools/pdbgen/pdb/selection.pdb b/tools/pdbgen/pdb/selection.pdb index 5a701aad1a..f063d42335 100644 --- a/tools/pdbgen/pdb/selection.pdb +++ b/tools/pdbgen/pdb/selection.pdb @@ -370,9 +370,9 @@ HELP if (gimp_drawable_width (GIMP_DRAWABLE (channel)) == gimage->width && gimp_drawable_height (GIMP_DRAWABLE (channel)) == gimage->height) { - new_channel = gimp_channel_copy (gimp_image_get_mask (gimage), - G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)), - TRUE); + new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)), + G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)), + FALSE)); gimp_channel_combine_mask (new_channel, channel, operation, -- GitLab