[gimp] app: add "image" as construct property to GimpItem



commit 5c8ec234ccc6440e4c3718dd14c9d283709596fa
Author: Michael Natterer <mitch gimp org>
Date:   Tue Feb 1 10:28:10 2011 +0100

    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

 app/core/gimpchannel.c    |    5 +-
 app/core/gimpdrawable.c   |    5 +-
 app/core/gimpdrawable.h   |    1 -
 app/core/gimpgrouplayer.c |    5 +-
 app/core/gimpitem.c       |  149 +++++++++++++++++++++++++++------------------
 app/core/gimpitem.h       |    1 -
 app/core/gimplayer.c      |    5 +-
 app/core/gimplayermask.c  |    5 +-
 app/core/gimpselection.c  |    5 +-
 app/text/gimptextlayer.c  |    5 +-
 app/vectors/gimpvectors.c |    6 +-
 11 files changed, 113 insertions(+), 79 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 5bf070f..4d4a0a1 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -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);
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index d179ae2..d374a1f 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -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;
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index cadf83c..a42203f 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -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,
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 8536ec4..da78bf0 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -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);
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index a927933..68b1469 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -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,
@@ -307,13 +315,58 @@ gimp_item_init (GimpItem *item)
 }
 
 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));
 }
 
 /**
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 02fa8cc..ba0d7ae 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -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,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index d3ba930..b7509cb 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -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);
diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c
index ce17dd7..7f7e420 100644
--- a/app/core/gimplayermask.c
+++ b/app/core/gimplayermask.c
@@ -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);
 
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index 4fd9fd4..6792610 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -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);
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 82227f2..a54b54a 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -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);
diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c
index e930974..0b08688 100644
--- a/app/vectors/gimpvectors.c
+++ b/app/vectors/gimpvectors.c
@@ -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),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]