From e0224cdbfbacec49c72c4ae22c6e661790c6b68b Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 7 Feb 2010 12:03:07 +0100 Subject: [PATCH] Add get_parent() API for items, layers, channels and vectors this is pretty pointless from an abstraction point of view, but using these functions will make the code a lot more readable by getting rid of tons of ugly casts to and from GimpViewable whenever getting an item's parent. --- app/core/gimpchannel.c | 8 ++++++++ app/core/gimpchannel.h | 2 ++ app/core/gimpitem.c | 8 ++++++++ app/core/gimpitem.h | 2 ++ app/core/gimplayer.c | 8 ++++++++ app/core/gimplayer.h | 2 ++ app/vectors/gimpvectors.c | 8 ++++++++ app/vectors/gimpvectors.h | 3 ++- 8 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index 7d68e73270..7354976e05 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -1684,6 +1684,14 @@ gimp_channel_new_from_component (GimpImage *image, return channel; } +GimpChannel * +gimp_channel_get_parent (GimpChannel *channel) +{ + g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL); + + return GIMP_CHANNEL (gimp_viewable_get_parent (GIMP_VIEWABLE (channel))); +} + void gimp_channel_set_color (GimpChannel *channel, const GimpRGB *color, diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h index 8618d660d2..5b1dd7742c 100644 --- a/app/core/gimpchannel.h +++ b/app/core/gimpchannel.h @@ -138,6 +138,8 @@ GimpChannel * gimp_channel_new_from_component (GimpImage *image, const gchar *name, const GimpRGB *color); +GimpChannel * gimp_channel_get_parent (GimpChannel *channel); + gdouble gimp_channel_get_opacity (const GimpChannel *channel); void gimp_channel_set_opacity (GimpChannel *channel, gdouble opacity, diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c index 383983148b..34b0219681 100644 --- a/app/core/gimpitem.c +++ b/app/core/gimpitem.c @@ -689,6 +689,14 @@ gimp_item_is_attached (const GimpItem *item) return GIMP_ITEM_GET_CLASS (item)->is_attached (item); } +GimpItem * +gimp_item_get_parent (GimpItem *item) +{ + g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); + + return GIMP_ITEM (gimp_viewable_get_parent (GIMP_VIEWABLE (item))); +} + GimpItemTree * gimp_item_get_tree (GimpItem *item) { diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h index 9810d1c314..c59cb31b75 100644 --- a/app/core/gimpitem.h +++ b/app/core/gimpitem.h @@ -143,6 +143,8 @@ gboolean gimp_item_is_removed (const GimpItem *item); gboolean gimp_item_is_attached (const GimpItem *item); +GimpItem * gimp_item_get_parent (GimpItem *item); + GimpItemTree * gimp_item_get_tree (GimpItem *item); GimpContainer * gimp_item_get_container (GimpItem *item); GList * gimp_item_get_container_iter (GimpItem *item); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index 62d3bfd5ce..fe5892dc8c 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -1339,6 +1339,14 @@ gimp_layer_new_from_region (PixelRegion *region, return new_layer; } +GimpLayer * +gimp_layer_get_parent (GimpLayer *layer) +{ + g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL); + + return GIMP_LAYER (gimp_viewable_get_parent (GIMP_VIEWABLE (layer))); +} + GimpLayerMask * gimp_layer_get_mask (const GimpLayer *layer) { diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index c45d24553d..1ac2197e93 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -96,6 +96,8 @@ GimpLayer * gimp_layer_new_from_region (PixelRegion *region, gdouble opacity, GimpLayerModeEffects mode); +GimpLayer * gimp_layer_get_parent (GimpLayer *layer); + GimpLayerMask * gimp_layer_get_mask (const GimpLayer *layer); GimpLayerMask * gimp_layer_create_mask (const GimpLayer *layer, GimpAddMaskType mask_type, diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c index e0d3aeac03..e570217cac 100644 --- a/app/vectors/gimpvectors.c +++ b/app/vectors/gimpvectors.c @@ -587,6 +587,14 @@ gimp_vectors_new (GimpImage *image, return vectors; } +GimpVectors * +gimp_vectors_get_parent (GimpVectors *vectors) +{ + g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); + + return GIMP_VECTORS (gimp_viewable_get_parent (GIMP_VIEWABLE (vectors))); +} + void gimp_vectors_freeze (GimpVectors *vectors) { diff --git a/app/vectors/gimpvectors.h b/app/vectors/gimpvectors.h index 235e925b6d..9a91f1575e 100644 --- a/app/vectors/gimpvectors.h +++ b/app/vectors/gimpvectors.h @@ -88,6 +88,8 @@ GType gimp_vectors_get_type (void) G_GNUC_CONST; GimpVectors * gimp_vectors_new (GimpImage *image, const gchar *name); +GimpVectors * gimp_vectors_get_parent (GimpVectors *vectors); + void gimp_vectors_freeze (GimpVectors *vectors); void gimp_vectors_thaw (GimpVectors *vectors); @@ -97,7 +99,6 @@ void gimp_vectors_add_strokes (const GimpVectors *src_vectors, GimpVectors *dest_vectors); - /* accessing / modifying the anchors */ GimpAnchor * gimp_vectors_anchor_get (const GimpVectors *vectors,