mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
fd8ebdacef
commit
297c2f0082
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -58,58 +58,60 @@ enum
|
|||
};
|
||||
|
||||
|
||||
static void gimp_vectors_finalize (GObject *object);
|
||||
static void gimp_vectors_finalize (GObject *object);
|
||||
|
||||
static gint64 gimp_vectors_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size);
|
||||
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 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)
|
||||
|
|
Loading…
Reference in New Issue