mirror of https://github.com/GNOME/gimp.git
app: add "image" as construct property to GimpItem
- The image *must* now be passed to g_object_new() when creating items - Remove the "image" parameter from all item configure() functions - Set the item's ID in gimp_item_set_image() if it has none yet
This commit is contained in:
parent
12e531f512
commit
5c8ec234cc
|
@ -1630,10 +1630,11 @@ gimp_channel_new (GimpImage *image,
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
channel = g_object_new (GIMP_TYPE_CHANNEL, NULL);
|
||||
channel = g_object_new (GIMP_TYPE_CHANNEL,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (channel),
|
||||
image,
|
||||
0, 0, width, height,
|
||||
GIMP_GRAY_IMAGE, name);
|
||||
|
||||
|
|
|
@ -418,7 +418,6 @@ gimp_drawable_duplicate (GimpItem *item,
|
|||
gimp_item_get_offset (item, &offset_x, &offset_y);
|
||||
|
||||
gimp_drawable_configure (new_drawable,
|
||||
gimp_item_get_image (item),
|
||||
offset_x,
|
||||
offset_y,
|
||||
gimp_item_get_width (item),
|
||||
|
@ -1187,7 +1186,6 @@ gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
|
|||
|
||||
void
|
||||
gimp_drawable_configure (GimpDrawable *drawable,
|
||||
GimpImage *image,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
|
@ -1196,10 +1194,9 @@ gimp_drawable_configure (GimpDrawable *drawable,
|
|||
const gchar *name)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
g_return_if_fail (width > 0 && height > 0);
|
||||
|
||||
gimp_item_configure (GIMP_ITEM (drawable), image,
|
||||
gimp_item_configure (GIMP_ITEM (drawable),
|
||||
offset_x, offset_y, width, height, name);
|
||||
|
||||
drawable->type = type;
|
||||
|
|
|
@ -124,7 +124,6 @@ gint64 gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
|
|||
gint height);
|
||||
|
||||
void gimp_drawable_configure (GimpDrawable *drawable,
|
||||
GimpImage *image,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
|
|
|
@ -828,10 +828,11 @@ gimp_group_layer_new (GimpImage *image)
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
group = g_object_new (GIMP_TYPE_GROUP_LAYER, NULL);
|
||||
group = g_object_new (GIMP_TYPE_GROUP_LAYER,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (group),
|
||||
image,
|
||||
0, 0, 1, 1,
|
||||
gimp_image_base_type_with_alpha (image),
|
||||
NULL);
|
||||
|
|
|
@ -57,6 +57,7 @@ enum
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_IMAGE,
|
||||
PROP_ID,
|
||||
PROP_WIDTH,
|
||||
PROP_HEIGHT,
|
||||
|
@ -103,6 +104,8 @@ struct _GimpItemPrivate
|
|||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_item_constructed (GObject *object);
|
||||
static void gimp_item_finalize (GObject *object);
|
||||
static void gimp_item_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
|
@ -111,7 +114,6 @@ static void gimp_item_get_property (GObject *object,
|
|||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_item_finalize (GObject *object);
|
||||
|
||||
static gint64 gimp_item_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size);
|
||||
|
@ -198,9 +200,10 @@ gimp_item_class_init (GimpItemClass *klass)
|
|||
gimp_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
object_class->constructed = gimp_item_constructed;
|
||||
object_class->finalize = gimp_item_finalize;
|
||||
object_class->set_property = gimp_item_set_property;
|
||||
object_class->get_property = gimp_item_get_property;
|
||||
object_class->finalize = gimp_item_finalize;
|
||||
|
||||
gimp_object_class->get_memsize = gimp_item_get_memsize;
|
||||
|
||||
|
@ -237,6 +240,11 @@ gimp_item_class_init (GimpItemClass *klass)
|
|||
klass->rotate_desc = NULL;
|
||||
klass->transform_desc = NULL;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_IMAGE,
|
||||
g_param_spec_object ("image", NULL, NULL,
|
||||
GIMP_TYPE_IMAGE,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT));
|
||||
g_object_class_install_property (object_class, PROP_ID,
|
||||
g_param_spec_int ("id", NULL, NULL,
|
||||
0, G_MAXINT, 0,
|
||||
|
@ -306,14 +314,59 @@ gimp_item_init (GimpItem *item)
|
|||
private->offset_node = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_constructed (GObject *object)
|
||||
{
|
||||
GimpItemPrivate *private = GET_PRIVATE (object);
|
||||
|
||||
if (G_OBJECT_CLASS (parent_class)->constructed)
|
||||
G_OBJECT_CLASS (parent_class)->constructed (object);
|
||||
|
||||
g_assert (GIMP_IS_IMAGE (private->image));
|
||||
g_assert (private->ID != 0);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_finalize (GObject *object)
|
||||
{
|
||||
GimpItemPrivate *private = GET_PRIVATE (object);
|
||||
|
||||
if (private->node)
|
||||
{
|
||||
g_object_unref (private->node);
|
||||
private->node = NULL;
|
||||
}
|
||||
|
||||
if (private->image && private->image->gimp)
|
||||
{
|
||||
g_hash_table_remove (private->image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID));
|
||||
private->image = NULL;
|
||||
}
|
||||
|
||||
if (private->parasites)
|
||||
{
|
||||
g_object_unref (private->parasites);
|
||||
private->parasites = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpItem *item = GIMP_ITEM (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_IMAGE:
|
||||
gimp_item_set_image (item, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -331,6 +384,9 @@ gimp_item_get_property (GObject *object,
|
|||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_IMAGE:
|
||||
g_value_set_object (value, private->image);
|
||||
break;
|
||||
case PROP_ID:
|
||||
g_value_set_int (value, private->ID);
|
||||
break;
|
||||
|
@ -362,33 +418,6 @@ gimp_item_get_property (GObject *object,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_finalize (GObject *object)
|
||||
{
|
||||
GimpItemPrivate *private = GET_PRIVATE (object);
|
||||
|
||||
if (private->node)
|
||||
{
|
||||
g_object_unref (private->node);
|
||||
private->node = NULL;
|
||||
}
|
||||
|
||||
if (private->image && private->image->gimp)
|
||||
{
|
||||
g_hash_table_remove (private->image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID));
|
||||
private->image = NULL;
|
||||
}
|
||||
|
||||
if (private->parasites)
|
||||
{
|
||||
g_object_unref (private->parasites);
|
||||
private->parasites = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gint64
|
||||
gimp_item_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size)
|
||||
|
@ -480,9 +509,11 @@ gimp_item_real_duplicate (GimpItem *item,
|
|||
}
|
||||
}
|
||||
|
||||
new_item = g_object_new (new_type, NULL);
|
||||
new_item = g_object_new (new_type,
|
||||
"image", gimp_item_get_image (item),
|
||||
NULL);
|
||||
|
||||
gimp_item_configure (new_item, gimp_item_get_image (item),
|
||||
gimp_item_configure (new_item,
|
||||
private->offset_x, private->offset_y,
|
||||
gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
|
@ -670,21 +701,16 @@ gimp_item_unset_removed (GimpItem *item)
|
|||
/**
|
||||
* gimp_item_configure:
|
||||
* @item: The #GimpItem to configure.
|
||||
* @image: The #GimpImage to which the item belongs.
|
||||
* @offset_x: The X offset to assign the item.
|
||||
* @offset_y: The Y offset to assign the item.
|
||||
* @width: The width to assign the item.
|
||||
* @height: The height to assign the item.
|
||||
* @name: The name to assign the item.
|
||||
*
|
||||
* This function is used to configure a new item. First, if the item
|
||||
* does not already have an ID, it is assigned the next available
|
||||
* one, and then inserted into the Item Hash Table. Next, it is
|
||||
* given basic item properties as specified by the arguments.
|
||||
* This function is used to configure a new item.
|
||||
*/
|
||||
void
|
||||
gimp_item_configure (GimpItem *item,
|
||||
GimpImage *image,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
|
@ -694,33 +720,11 @@ gimp_item_configure (GimpItem *item,
|
|||
GimpItemPrivate *private;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ITEM (item));
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
private = GET_PRIVATE (item);
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (item));
|
||||
|
||||
if (private->ID == 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
private->ID = image->gimp->next_item_ID++;
|
||||
|
||||
if (image->gimp->next_item_ID == G_MAXINT)
|
||||
image->gimp->next_item_ID = 1;
|
||||
}
|
||||
while (g_hash_table_lookup (image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID)));
|
||||
|
||||
g_hash_table_insert (image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID),
|
||||
item);
|
||||
|
||||
gimp_item_set_image (item, image);
|
||||
|
||||
g_object_notify (G_OBJECT (item), "id");
|
||||
}
|
||||
|
||||
if (item->width != width)
|
||||
{
|
||||
item->width = width;
|
||||
|
@ -1629,12 +1633,39 @@ gimp_item_set_image (GimpItem *item,
|
|||
|
||||
private = GET_PRIVATE (item);
|
||||
|
||||
if (image == private->image)
|
||||
return;
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (item));
|
||||
|
||||
if (private->ID == 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
private->ID = image->gimp->next_item_ID++;
|
||||
|
||||
if (image->gimp->next_item_ID == G_MAXINT)
|
||||
image->gimp->next_item_ID = 1;
|
||||
}
|
||||
while (g_hash_table_lookup (image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID)));
|
||||
|
||||
g_hash_table_insert (image->gimp->item_table,
|
||||
GINT_TO_POINTER (private->ID),
|
||||
item);
|
||||
|
||||
g_object_notify (G_OBJECT (item), "id");
|
||||
}
|
||||
|
||||
if (private->tattoo == 0 || private->image != image)
|
||||
{
|
||||
private->tattoo = gimp_image_get_new_tattoo (image);
|
||||
}
|
||||
|
||||
private->image = image;
|
||||
g_object_notify (G_OBJECT (item), "image");
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (item));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,7 +151,6 @@ gint gimp_item_get_index (GimpItem *item);
|
|||
GList * gimp_item_get_path (GimpItem *item);
|
||||
|
||||
void gimp_item_configure (GimpItem *item,
|
||||
GimpImage *image,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
|
|
|
@ -1116,10 +1116,11 @@ gimp_layer_new (GimpImage *image,
|
|||
g_return_val_if_fail (width > 0, NULL);
|
||||
g_return_val_if_fail (height > 0, NULL);
|
||||
|
||||
layer = g_object_new (GIMP_TYPE_LAYER, NULL);
|
||||
layer = g_object_new (GIMP_TYPE_LAYER,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (layer),
|
||||
image,
|
||||
0, 0, width, height,
|
||||
type,
|
||||
name);
|
||||
|
|
|
@ -194,10 +194,11 @@ gimp_layer_mask_new (GimpImage *image,
|
|||
{
|
||||
GimpLayerMask *layer_mask;
|
||||
|
||||
layer_mask = g_object_new (GIMP_TYPE_LAYER_MASK, NULL);
|
||||
layer_mask = g_object_new (GIMP_TYPE_LAYER_MASK,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (layer_mask),
|
||||
image,
|
||||
0, 0, width, height,
|
||||
GIMP_GRAY_IMAGE, name);
|
||||
|
||||
|
|
|
@ -524,10 +524,11 @@ gimp_selection_new (GimpImage *image,
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
channel = g_object_new (GIMP_TYPE_SELECTION, NULL);
|
||||
channel = g_object_new (GIMP_TYPE_SELECTION,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (channel),
|
||||
image,
|
||||
0, 0, width, height,
|
||||
GIMP_GRAY_IMAGE,
|
||||
NULL);
|
||||
|
|
|
@ -389,10 +389,11 @@ gimp_text_layer_new (GimpImage *image,
|
|||
if (! text->text && ! text->markup)
|
||||
return NULL;
|
||||
|
||||
layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
|
||||
layer = g_object_new (GIMP_TYPE_TEXT_LAYER,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (layer),
|
||||
image,
|
||||
0, 0, 1, 1,
|
||||
gimp_image_base_type_with_alpha (image),
|
||||
NULL);
|
||||
|
|
|
@ -641,9 +641,11 @@ gimp_vectors_new (GimpImage *image,
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
vectors = g_object_new (GIMP_TYPE_VECTORS, NULL);
|
||||
vectors = g_object_new (GIMP_TYPE_VECTORS,
|
||||
"image", image,
|
||||
NULL);
|
||||
|
||||
gimp_item_configure (GIMP_ITEM (vectors), image,
|
||||
gimp_item_configure (GIMP_ITEM (vectors),
|
||||
0, 0,
|
||||
gimp_image_get_width (image),
|
||||
gimp_image_get_height (image),
|
||||
|
|
Loading…
Reference in New Issue