[gimp] Add gimp_item_get_container() and gimp_item_get_index()
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] Add gimp_item_get_container() and gimp_item_get_index()
- Date: Sat, 1 Aug 2009 18:26:27 +0000 (UTC)
commit 297c2f00826b59c9b2a020618b878bdfb7bbb651
Author: Michael Natterer <mitch gimp org>
Date: Sat Aug 1 20:22:07 2009 +0200
Add gimp_item_get_container() and gimp_item_get_index()
* app/core/gimpitem.[ch]: add virtual function ::get_container() plus
pubic API wrapper which returns the children of the item's parent
viewable, or the right toplevel container of its image.
Add utility function get_index() which returns the item's index
within its container.
* app/core/gimpchannel.c
* app/vectors/gimpvectors.c: implement get_container() and return
the right image container.
* app/core/gimplayer.[ch]: same here, and remove previously added
public get_container() API.
* app/core/gimplayermask.c
* app/core/gimpselection.c: implement get_container() for these GimpChannel
subclasses and return NULL.
app/core/gimpchannel.c | 16 ++++++
app/core/gimpitem.c | 34 +++++++++++++
app/core/gimpitem.h | 114 ++++++++++++++++++++++--------------------
app/core/gimplayer.c | 38 ++++++--------
app/core/gimplayer.h | 2 -
app/core/gimplayermask.c | 22 ++++++---
app/core/gimpselection.c | 9 +++
app/vectors/gimpvectors.c | 120 +++++++++++++++++++++++++-------------------
8 files changed, 217 insertions(+), 138 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 8f32535..1bd6432 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -77,6 +77,8 @@ static gchar * gimp_channel_get_description (GimpViewable *viewable,
gchar **tooltip);
static gboolean gimp_channel_is_attached (GimpItem *item);
+static GimpContainer *
+ gimp_channel_get_container (GimpItem *item);
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type);
static void gimp_channel_convert (GimpItem *item,
@@ -249,6 +251,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
viewable_class->default_stock_id = "gimp-channel";
item_class->is_attached = gimp_channel_is_attached;
+ item_class->get_container = gimp_channel_get_container;
item_class->duplicate = gimp_channel_duplicate;
item_class->convert = gimp_channel_convert;
item_class->translate = gimp_channel_translate;
@@ -379,6 +382,19 @@ gimp_channel_is_attached (GimpItem *item)
gimp_container_have (gimp_item_get_image (item)->channels, GIMP_OBJECT (item)));
}
+static GimpContainer *
+gimp_channel_get_container (GimpItem *item)
+{
+ if (gimp_item_is_attached (item))
+ {
+ GimpImage *image = gimp_item_get_image (item);
+
+ return gimp_image_get_channels (image);
+ }
+
+ return NULL;
+}
+
static GimpItem *
gimp_channel_duplicate (GimpItem *item,
GType new_type)
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 425ff5f..6453dbd 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -167,6 +167,7 @@ gimp_item_class_init (GimpItemClass *klass)
klass->linked_changed = NULL;
klass->is_attached = NULL;
+ klass->get_container = NULL;
klass->duplicate = gimp_item_real_duplicate;
klass->convert = gimp_item_real_convert;
klass->rename = gimp_item_real_rename;
@@ -649,6 +650,39 @@ gimp_item_is_attached (GimpItem *item)
return GIMP_ITEM_GET_CLASS (item)->is_attached (item);
}
+GimpContainer *
+gimp_item_get_container (GimpItem *item)
+{
+ GimpViewable *parent;
+
+ g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
+
+ parent = gimp_viewable_get_parent (GIMP_VIEWABLE (item));
+
+ if (parent)
+ return gimp_viewable_get_children (GIMP_VIEWABLE (parent));
+
+ if (GIMP_ITEM_GET_CLASS (item)->get_container)
+ return GIMP_ITEM_GET_CLASS (item)->get_container (item);
+
+ return NULL;
+}
+
+gint
+gimp_item_get_index (GimpItem *item)
+{
+ GimpContainer *container;
+
+ g_return_val_if_fail (GIMP_IS_ITEM (item), -1);
+
+ container = gimp_item_get_container (item);
+
+ if (container)
+ return gimp_container_get_child_index (container, GIMP_OBJECT (item));
+
+ return -1;
+}
+
/**
* gimp_item_duplicate:
* @item: The #GimpItem to duplicate.
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 69ab0b2..8a692d6 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -61,63 +61,64 @@ struct _GimpItemClass
GimpViewableClass parent_class;
/* signals */
- void (* removed) (GimpItem *item);
- void (* visibility_changed) (GimpItem *item);
- void (* linked_changed) (GimpItem *item);
+ void (* removed) (GimpItem *item);
+ void (* visibility_changed) (GimpItem *item);
+ void (* linked_changed) (GimpItem *item);
/* virtual functions */
- gboolean (* is_attached) (GimpItem *item);
- GimpItem * (* duplicate) (GimpItem *item,
- GType new_type);
- void (* convert) (GimpItem *item,
- GimpImage *dest_image);
- gboolean (* rename) (GimpItem *item,
- const gchar *new_name,
- const gchar *undo_desc,
- GError **error);
- void (* translate) (GimpItem *item,
- gint offset_x,
- gint offset_y,
- gboolean push_undo);
- void (* scale) (GimpItem *item,
- gint new_width,
- gint new_height,
- gint new_offset_x,
- gint new_offset_y,
- GimpInterpolationType interpolation_type,
- GimpProgress *progress);
- void (* resize) (GimpItem *item,
- GimpContext *context,
- gint new_width,
- gint new_height,
- gint offset_x,
- gint offset_y);
- void (* flip) (GimpItem *item,
- GimpContext *context,
- GimpOrientationType flip_type,
- gdouble axis,
- gboolean clip_result);
- void (* rotate) (GimpItem *item,
- GimpContext *context,
- GimpRotationType rotate_type,
- gdouble center_x,
- gdouble center_y,
- gboolean clip_result);
- void (* transform) (GimpItem *item,
- GimpContext *context,
- const GimpMatrix3 *matrix,
- GimpTransformDirection direction,
- GimpInterpolationType interpolation_type,
- gint recursion_level,
- GimpTransformResize clip_result,
- GimpProgress *progress);
- gboolean (* stroke) (GimpItem *item,
- GimpDrawable *drawable,
- GimpStrokeOptions *stroke_options,
- gboolean push_undo,
- GimpProgress *progress,
- GError **error);
- GeglNode * (* get_node) (GimpItem *item);
+ gboolean (* is_attached) (GimpItem *item);
+ GimpContainer * (* get_container) (GimpItem *item);
+ GimpItem * (* duplicate) (GimpItem *item,
+ GType new_type);
+ void (* convert) (GimpItem *item,
+ GimpImage *dest_image);
+ gboolean (* rename) (GimpItem *item,
+ const gchar *new_name,
+ const gchar *undo_desc,
+ GError **error);
+ void (* translate) (GimpItem *item,
+ gint offset_x,
+ gint offset_y,
+ gboolean push_undo);
+ void (* scale) (GimpItem *item,
+ gint new_width,
+ gint new_height,
+ gint new_offset_x,
+ gint new_offset_y,
+ GimpInterpolationType interpolation_type,
+ GimpProgress *progress);
+ void (* resize) (GimpItem *item,
+ GimpContext *context,
+ gint new_width,
+ gint new_height,
+ gint offset_x,
+ gint offset_y);
+ void (* flip) (GimpItem *item,
+ GimpContext *context,
+ GimpOrientationType flip_type,
+ gdouble axis,
+ gboolean clip_result);
+ void (* rotate) (GimpItem *item,
+ GimpContext *context,
+ GimpRotationType rotate_type,
+ gdouble center_x,
+ gdouble center_y,
+ gboolean clip_result);
+ void (* transform) (GimpItem *item,
+ GimpContext *context,
+ const GimpMatrix3 *matrix,
+ GimpTransformDirection direction,
+ GimpInterpolationType interpolation_type,
+ gint recursion_level,
+ GimpTransformResize clip_result,
+ GimpProgress *progress);
+ gboolean (* stroke) (GimpItem *item,
+ GimpDrawable *drawable,
+ GimpStrokeOptions *stroke_options,
+ gboolean push_undo,
+ GimpProgress *progress,
+ GError **error);
+ GeglNode * (* get_node) (GimpItem *item);
const gchar *default_name;
@@ -139,6 +140,9 @@ gboolean gimp_item_is_removed (const GimpItem *item);
gboolean gimp_item_is_attached (GimpItem *item);
+GimpContainer * gimp_item_get_container (GimpItem *item);
+gint gimp_item_get_index (GimpItem *item);
+
void gimp_item_configure (GimpItem *item,
GimpImage *image,
gint offset_x,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 406c2d9..ce1bf23 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -97,6 +97,8 @@ static gchar * gimp_layer_get_description (GimpViewable *viewable,
static void gimp_layer_removed (GimpItem *item);
static gboolean gimp_layer_is_attached (GimpItem *item);
+static GimpContainer *
+ gimp_layer_get_container (GimpItem *item);
static GimpItem * gimp_layer_duplicate (GimpItem *item,
GType new_type);
static void gimp_layer_convert (GimpItem *item,
@@ -236,6 +238,7 @@ gimp_layer_class_init (GimpLayerClass *klass)
item_class->removed = gimp_layer_removed;
item_class->is_attached = gimp_layer_is_attached;
+ item_class->get_container = gimp_layer_get_container;
item_class->duplicate = gimp_layer_duplicate;
item_class->convert = gimp_layer_convert;
item_class->rename = gimp_layer_rename;
@@ -542,6 +545,19 @@ gimp_layer_is_attached (GimpItem *item)
gimp_container_have (gimp_item_get_image (item)->layers, GIMP_OBJECT (item)));
}
+static GimpContainer *
+gimp_layer_get_container (GimpItem *item)
+{
+ if (gimp_item_is_attached (item))
+ {
+ GimpImage *image = gimp_item_get_image (item);
+
+ return gimp_image_get_layers (image);
+ }
+
+ return NULL;
+}
+
static GimpItem *
gimp_layer_duplicate (GimpItem *item,
GType new_type)
@@ -2039,25 +2055,3 @@ gimp_layer_get_lock_alpha (const GimpLayer *layer)
return layer->lock_alpha;
}
-
-GimpContainer *
-gimp_layer_get_container (const GimpLayer *layer)
-{
- GimpViewable *parent;
-
- g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
-
- parent = gimp_viewable_get_parent (GIMP_VIEWABLE (layer));
-
- if (parent)
- return gimp_viewable_get_children (parent);
-
- if (gimp_item_is_attached (GIMP_ITEM (layer)))
- {
- GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
-
- return gimp_image_get_layers (image);
- }
-
- return NULL;
-}
diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h
index ca66ead..b092b82 100644
--- a/app/core/gimplayer.h
+++ b/app/core/gimplayer.h
@@ -137,7 +137,5 @@ void gimp_layer_set_lock_alpha (GimpLayer *layer,
gboolean push_undo);
gboolean gimp_layer_get_lock_alpha (const GimpLayer *layer);
-GimpContainer * gimp_layer_get_container (const GimpLayer *layer);
-
#endif /* __GIMP_LAYER_H__ */
diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c
index 3daa19a..d7ee46c 100644
--- a/app/core/gimplayermask.c
+++ b/app/core/gimplayermask.c
@@ -45,13 +45,15 @@ enum
};
-static gboolean gimp_layer_mask_is_attached (GimpItem *item);
-static GimpItem * gimp_layer_mask_duplicate (GimpItem *item,
- GType new_type);
-static gboolean gimp_layer_mask_rename (GimpItem *item,
- const gchar *new_name,
- const gchar *undo_desc,
- GError **error);
+static gboolean gimp_layer_mask_is_attached (GimpItem *item);
+static GimpContainer *
+ gimp_layer_mask_get_container (GimpItem *item);
+static GimpItem * gimp_layer_mask_duplicate (GimpItem *item,
+ GType new_type);
+static gboolean gimp_layer_mask_rename (GimpItem *item,
+ const gchar *new_name,
+ const gchar *undo_desc,
+ GError **error);
static void gimp_layer_mask_real_edit_changed (GimpLayerMask *layer_mask);
@@ -126,6 +128,12 @@ gimp_layer_mask_is_attached (GimpItem *item)
gimp_item_is_attached (GIMP_ITEM (layer)));
}
+static GimpContainer *
+gimp_layer_mask_get_container (GimpItem *item)
+{
+ return NULL;
+}
+
static GimpItem *
gimp_layer_mask_duplicate (GimpItem *item,
GType new_type)
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index 9b197a6..d4a824a 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -46,6 +46,8 @@
static gboolean gimp_selection_is_attached (GimpItem *item);
+static GimpContainer *
+ gimp_selection_get_container (GimpItem *item);
static void gimp_selection_translate (GimpItem *item,
gint offset_x,
gint offset_y,
@@ -143,6 +145,7 @@ gimp_selection_class_init (GimpSelectionClass *klass)
viewable_class->default_stock_id = "gimp-selection";
item_class->is_attached = gimp_selection_is_attached;
+ item_class->get_container = gimp_selection_get_container;
item_class->translate = gimp_selection_translate;
item_class->scale = gimp_selection_scale;
item_class->resize = gimp_selection_resize;
@@ -189,6 +192,12 @@ gimp_selection_is_attached (GimpItem *item)
gimp_image_get_mask (gimp_item_get_image (item)) == GIMP_CHANNEL (item));
}
+static GimpContainer *
+gimp_selection_get_container (GimpItem *item)
+{
+ return NULL;
+}
+
static void
gimp_selection_translate (GimpItem *item,
gint offset_x,
diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c
index 342f381..5548b1c 100644
--- a/app/vectors/gimpvectors.c
+++ b/app/vectors/gimpvectors.c
@@ -58,58 +58,60 @@ enum
};
-static void gimp_vectors_finalize (GObject *object);
-
-static gint64 gimp_vectors_get_memsize (GimpObject *object,
- gint64 *gui_size);
-
-static gboolean gimp_vectors_is_attached (GimpItem *item);
-static GimpItem * gimp_vectors_duplicate (GimpItem *item,
- GType new_type);
-static void gimp_vectors_convert (GimpItem *item,
- GimpImage *dest_image);
-static void gimp_vectors_translate (GimpItem *item,
- gint offset_x,
- gint offset_y,
- gboolean push_undo);
-static void gimp_vectors_scale (GimpItem *item,
- gint new_width,
- gint new_height,
- gint new_offset_x,
- gint new_offset_y,
- GimpInterpolationType interp_type,
- GimpProgress *progress);
-static void gimp_vectors_resize (GimpItem *item,
- GimpContext *context,
- gint new_width,
- gint new_height,
- gint offset_x,
- gint offset_y);
-static void gimp_vectors_flip (GimpItem *item,
- GimpContext *context,
- GimpOrientationType flip_type,
- gdouble axis,
- gboolean clip_result);
-static void gimp_vectors_rotate (GimpItem *item,
- GimpContext *context,
- GimpRotationType rotate_type,
- gdouble center_x,
- gdouble center_y,
- gboolean clip_result);
-static void gimp_vectors_transform (GimpItem *item,
- GimpContext *context,
- const GimpMatrix3 *matrix,
- GimpTransformDirection direction,
- GimpInterpolationType interp_type,
- gint recursion_level,
- GimpTransformResize clip_result,
- GimpProgress *progress);
-static gboolean gimp_vectors_stroke (GimpItem *item,
- GimpDrawable *drawable,
- GimpStrokeOptions *stroke_options,
- gboolean push_undo,
- GimpProgress *progress,
- GError **error);
+static void gimp_vectors_finalize (GObject *object);
+
+static gint64 gimp_vectors_get_memsize (GimpObject *object,
+ gint64 *gui_size);
+
+static gboolean gimp_vectors_is_attached (GimpItem *item);
+static GimpContainer *
+ gimp_vectors_get_container (GimpItem *item);
+static GimpItem * gimp_vectors_duplicate (GimpItem *item,
+ GType new_type);
+static void gimp_vectors_convert (GimpItem *item,
+ GimpImage *dest_image);
+static void gimp_vectors_translate (GimpItem *item,
+ gint offset_x,
+ gint offset_y,
+ gboolean push_undo);
+static void gimp_vectors_scale (GimpItem *item,
+ gint new_width,
+ gint new_height,
+ gint new_offset_x,
+ gint new_offset_y,
+ GimpInterpolationType interp_type,
+ GimpProgress *progress);
+static void gimp_vectors_resize (GimpItem *item,
+ GimpContext *context,
+ gint new_width,
+ gint new_height,
+ gint offset_x,
+ gint offset_y);
+static void gimp_vectors_flip (GimpItem *item,
+ GimpContext *context,
+ GimpOrientationType flip_type,
+ gdouble axis,
+ gboolean clip_result);
+static void gimp_vectors_rotate (GimpItem *item,
+ GimpContext *context,
+ GimpRotationType rotate_type,
+ gdouble center_x,
+ gdouble center_y,
+ gboolean clip_result);
+static void gimp_vectors_transform (GimpItem *item,
+ GimpContext *context,
+ const GimpMatrix3 *matrix,
+ GimpTransformDirection direction,
+ GimpInterpolationType interp_type,
+ gint recursion_level,
+ GimpTransformResize clip_result,
+ GimpProgress *progress);
+static gboolean gimp_vectors_stroke (GimpItem *item,
+ GimpDrawable *drawable,
+ GimpStrokeOptions *stroke_options,
+ gboolean push_undo,
+ GimpProgress *progress,
+ GError **error);
static void gimp_vectors_real_thaw (GimpVectors *vectors);
static void gimp_vectors_real_stroke_add (GimpVectors *vectors,
@@ -180,6 +182,7 @@ gimp_vectors_class_init (GimpVectorsClass *klass)
viewable_class->default_stock_id = "gimp-path";
item_class->is_attached = gimp_vectors_is_attached;
+ item_class->get_container = gimp_vectors_get_container;
item_class->duplicate = gimp_vectors_duplicate;
item_class->convert = gimp_vectors_convert;
item_class->translate = gimp_vectors_translate;
@@ -269,6 +272,19 @@ gimp_vectors_is_attached (GimpItem *item)
gimp_container_have (gimp_item_get_image (item)->vectors, GIMP_OBJECT (item)));
}
+static GimpContainer *
+gimp_vectors_get_container (GimpItem *item)
+{
+ if (gimp_item_is_attached (item))
+ {
+ GimpImage *image = gimp_item_get_image (item);
+
+ return gimp_image_get_vectors (image);
+ }
+
+ return NULL;
+}
+
static GimpItem *
gimp_vectors_duplicate (GimpItem *item,
GType new_type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]