app: add accessors for GimpItem::parasites and move it to private

This commit is contained in:
Michael Natterer 2011-01-31 23:51:18 +01:00
parent af160141db
commit ad88eb55a2
4 changed files with 108 additions and 50 deletions

View File

@ -390,19 +390,20 @@ gimp_image_merge_layers (GimpImage *image,
GimpMergeType merge_type,
const gchar *undo_desc)
{
GList *list;
GSList *reverse_list = NULL;
PixelRegion src1PR, src2PR, maskPR;
PixelRegion *mask;
GimpLayer *merge_layer;
GimpLayer *layer;
GimpLayer *bottom_layer;
gint count;
gint x1, y1, x2, y2;
gint off_x, off_y;
gint position;
gchar *name;
GimpLayer *parent;
GList *list;
GSList *reverse_list = NULL;
PixelRegion src1PR, src2PR, maskPR;
PixelRegion *mask;
GimpLayer *merge_layer;
GimpLayer *layer;
GimpLayer *bottom_layer;
GimpParasiteList *parasites;
gint count;
gint x1, y1, x2, y2;
gint off_x, off_y;
gint position;
gchar *name;
GimpLayer *parent;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
@ -570,9 +571,10 @@ gimp_image_merge_layers (GimpImage *image,
gimp_item_set_tattoo (GIMP_ITEM (merge_layer),
gimp_item_get_tattoo (GIMP_ITEM (bottom_layer)));
g_object_unref (GIMP_ITEM (merge_layer)->parasites);
GIMP_ITEM (merge_layer)->parasites =
gimp_parasite_list_copy (GIMP_ITEM (bottom_layer)->parasites);
parasites = gimp_item_get_parasites (GIMP_ITEM (bottom_layer));
parasites = gimp_parasite_list_copy (parasites);
gimp_item_set_parasites (GIMP_ITEM (merge_layer), parasites);
g_object_unref (parasites);
while (reverse_list)
{

View File

@ -78,9 +78,7 @@ struct _GimpItemPrivate
GimpImage *image; /* item owner */
#if 0
GimpParasiteList *parasites; /* Plug-in parasite data */
#endif
#if 0
gint width, height; /* size in pixels */
@ -295,7 +293,7 @@ gimp_item_init (GimpItem *item)
private->ID = 0;
private->tattoo = 0;
private->image = NULL;
item->parasites = gimp_parasite_list_new ();
private->parasites = gimp_parasite_list_new ();
item->width = 0;
item->height = 0;
private->offset_x = 0;
@ -367,7 +365,6 @@ gimp_item_get_property (GObject *object,
static void
gimp_item_finalize (GObject *object)
{
GimpItem *item = GIMP_ITEM (object);
GimpItemPrivate *private = GET_PRIVATE (object);
if (private->node)
@ -383,10 +380,10 @@ gimp_item_finalize (GObject *object)
private->image = NULL;
}
if (item->parasites)
if (private->parasites)
{
g_object_unref (item->parasites);
item->parasites = NULL;
g_object_unref (private->parasites);
private->parasites = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@ -396,10 +393,11 @@ static gint64
gimp_item_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpItem *item = GIMP_ITEM (object);
gint64 memsize = 0;
GimpItemPrivate *private = GET_PRIVATE (object);
gint64 memsize = 0;
memsize += gimp_object_get_memsize (GIMP_OBJECT (item->parasites), gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (private->parasites),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -492,8 +490,8 @@ gimp_item_real_duplicate (GimpItem *item,
g_free (new_name);
g_object_unref (new_item->parasites);
new_item->parasites = gimp_parasite_list_copy (item->parasites);
g_object_unref (GET_PRIVATE (new_item)->parasites);
GET_PRIVATE (new_item)->parasites = gimp_parasite_list_copy (private->parasites);
gimp_item_set_visible (new_item, gimp_item_get_visible (item), FALSE);
gimp_item_set_linked (new_item, gimp_item_get_linked (item), FALSE);
@ -1690,8 +1688,8 @@ gimp_item_replace_item (GimpItem *item,
gimp_item_set_tattoo (item, gimp_item_get_tattoo (replace));
gimp_item_set_tattoo (replace, 0);
item->parasites = replace->parasites;
replace->parasites = NULL;
private->parasites = GET_PRIVATE (replace)->parasites;
GET_PRIVATE (replace)->parasites = NULL;
gimp_item_get_offset (replace, &offset_x, &offset_y);
gimp_item_set_offset (item, offset_x, offset_y);
@ -1705,6 +1703,52 @@ gimp_item_replace_item (GimpItem *item,
gimp_item_set_lock_content (item, gimp_item_get_lock_content (replace), FALSE);
}
/**
* gimp_item_set_parasites:
* @item: a #GimpItem
* @parasites: a #GimpParasiteList
*
* Set an @item's #GimpParasiteList. It's usually never needed to
* fiddle with an item's parasite list directly. This function exists
* for special purposes only, like when creating items from unusual
* sources.
**/
void
gimp_item_set_parasites (GimpItem *item,
GimpParasiteList *parasites)
{
GimpItemPrivate *private;
g_return_if_fail (GIMP_IS_ITEM (item));
g_return_if_fail (GIMP_IS_PARASITE_LIST (parasites));
private = GET_PRIVATE (item);
if (parasites != private->parasites)
{
g_object_unref (private->parasites);
private->parasites = g_object_ref (parasites);
}
}
/**
* gimp_item_get_parasites:
* @item: a #GimpItem
*
* Get an @item's #GimpParasiteList. It's usually never needed to
* fiddle with an item's parasite list directly. This function exists
* for special purposes only, like when saving an item to XCF.
*
* Return value: The @item's #GimpParasiteList.
**/
GimpParasiteList *
gimp_item_get_parasites (const GimpItem *item)
{
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
return GET_PRIVATE (item)->parasites;
}
void
gimp_item_parasite_attach (GimpItem *item,
const GimpParasite *parasite,
@ -1750,7 +1794,7 @@ gimp_item_parasite_attach (GimpItem *item,
}
}
gimp_parasite_list_add (item->parasites, &copy);
gimp_parasite_list_add (private->parasites, &copy);
if (gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_PARENT))
{
@ -1784,7 +1828,7 @@ gimp_item_parasite_detach (GimpItem *item,
private = GET_PRIVATE (item);
parasite = gimp_parasite_list_find (item->parasites, name);
parasite = gimp_parasite_list_find (private->parasites, name);
if (! parasite)
return;
@ -1808,7 +1852,7 @@ gimp_item_parasite_detach (GimpItem *item,
}
}
gimp_parasite_list_remove (item->parasites, name);
gimp_parasite_list_remove (private->parasites, name);
}
const GimpParasite *
@ -1817,7 +1861,7 @@ gimp_item_parasite_find (const GimpItem *item,
{
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
return gimp_parasite_list_find (item->parasites, name);
return gimp_parasite_list_find (GET_PRIVATE (item)->parasites, name);
}
static void
@ -1832,17 +1876,20 @@ gchar **
gimp_item_parasite_list (const GimpItem *item,
gint *count)
{
gchar **list;
gchar **cur;
GimpItemPrivate *private;
gchar **list;
gchar **cur;
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (count != NULL, NULL);
*count = gimp_parasite_list_length (item->parasites);
private = GET_PRIVATE (item);
*count = gimp_parasite_list_length (private->parasites);
cur = list = g_new (gchar *, *count);
gimp_parasite_list_foreach (item->parasites,
gimp_parasite_list_foreach (private->parasites,
(GHFunc) gimp_item_parasite_list_foreach_func,
&cur);

View File

@ -36,8 +36,6 @@ struct _GimpItem
{
GimpViewable parent_instance;
GimpParasiteList *parasites; /* Plug-in parasite data */
gint width, height; /* size in pixels */
};
@ -274,6 +272,10 @@ void gimp_item_set_image (GimpItem *item,
void gimp_item_replace_item (GimpItem *item,
GimpItem *replace);
void gimp_item_set_parasites (GimpItem *item,
GimpParasiteList *parasites);
GimpParasiteList * gimp_item_get_parasites (const GimpItem *item);
void gimp_item_parasite_attach (GimpItem *item,
const GimpParasite *parasite,
gboolean push_undo);

View File

@ -455,8 +455,9 @@ xcf_save_layer_props (XcfInfo *info,
GimpLayer *layer,
GError **error)
{
gint offset_x;
gint offset_y;
GimpParasiteList *parasites;
gint offset_x;
gint offset_y;
if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
xcf_check_error (xcf_save_prop (info, image, PROP_GROUP_ITEM, error));
@ -535,10 +536,12 @@ xcf_save_layer_props (XcfInfo *info,
flags));
}
if (gimp_parasite_list_length (GIMP_ITEM (layer)->parasites) > 0)
parasites = gimp_item_get_parasites (GIMP_ITEM (layer));
if (gimp_parasite_list_length (parasites) > 0)
{
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
GIMP_ITEM (layer)->parasites));
parasites));
}
xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
@ -552,7 +555,8 @@ xcf_save_channel_props (XcfInfo *info,
GimpChannel *channel,
GError **error)
{
guchar col[3];
GimpParasiteList *parasites;
guchar col[3];
if (channel == gimp_image_get_active_channel (image))
xcf_check_error (xcf_save_prop (info, image, PROP_ACTIVE_CHANNEL, error));
@ -577,9 +581,13 @@ xcf_save_channel_props (XcfInfo *info,
xcf_check_error (xcf_save_prop (info, image, PROP_TATTOO, error,
gimp_item_get_tattoo (GIMP_ITEM (channel))));
if (gimp_parasite_list_length (GIMP_ITEM (channel)->parasites) > 0)
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
GIMP_ITEM (channel)->parasites));
parasites = gimp_item_get_parasites (GIMP_ITEM (channel));
if (gimp_parasite_list_length (parasites) > 0)
{
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
parasites));
}
xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
@ -1798,12 +1806,11 @@ xcf_save_vectors (XcfInfo *info,
* then each stroke
*/
parasites = GIMP_ITEM (vectors)->parasites;
name = gimp_object_get_name (vectors);
visible = gimp_item_get_visible (GIMP_ITEM (vectors));
linked = gimp_item_get_linked (GIMP_ITEM (vectors));
tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
parasites = gimp_item_get_parasites (GIMP_ITEM (vectors));
num_parasites = gimp_parasite_list_persistent_length (parasites);
num_strokes = g_list_length (vectors->strokes);