gimp r27227 - in trunk: . app/core



Author: mitch
Date: Sat Oct 11 10:14:21 2008
New Revision: 27227
URL: http://svn.gnome.org/viewvc/gimp?rev=27227&view=rev

Log:
2008-10-11  Michael Natterer  <mitch gimp org>

	Fix old bug in the GimpContainer implementation that wasn't
	visible before the drawable stack completly b0rked when removing
	the second-last item:

	* app/core/gimpcontainer.c: add default implementations of ::add()
	and ::remove() and update container->num_children there instead of
	in the gimp_container_add() and _remove() wrapper functions.
	This way not only external callbacks connected to the "add" and
	"remove" signals are called with the correct num_children, also
	implemtations of ::add() and ::remove() in subclass have the right
	number available before/after upchaining. Add paranoia code to the
	wrapper functions which check if the subclass reall chains up.

	* app/core/gimplist.c: chain up in add() and remove().



Modified:
   trunk/ChangeLog
   trunk/app/core/gimpcontainer.c
   trunk/app/core/gimplist.c

Modified: trunk/app/core/gimpcontainer.c
==============================================================================
--- trunk/app/core/gimpcontainer.c	(original)
+++ trunk/app/core/gimpcontainer.c	Sat Oct 11 10:14:21 2008
@@ -88,6 +88,11 @@
 static gint64     gimp_container_get_memsize     (GimpObject       *object,
                                                   gint64           *gui_size);
 
+static void       gimp_container_real_add        (GimpContainer    *container,
+                                                  GimpObject       *object);
+static void       gimp_container_real_remove     (GimpContainer    *container,
+                                                  GimpObject       *object);
+
 static gboolean   gimp_container_serialize       (GimpConfig       *config,
                                                   GimpConfigWriter *writer,
                                                   gpointer          data);
@@ -170,8 +175,8 @@
 
   gimp_object_class->get_memsize = gimp_container_get_memsize;
 
-  klass->add                     = NULL;
-  klass->remove                  = NULL;
+  klass->add                     = gimp_container_real_add;
+  klass->remove                  = gimp_container_real_remove;
   klass->reorder                 = NULL;
   klass->freeze                  = NULL;
   klass->thaw                    = NULL;
@@ -304,6 +309,21 @@
                                                                   gui_size);
 }
 
+static void
+gimp_container_real_add (GimpContainer *container,
+                         GimpObject    *object)
+{
+  container->num_children++;
+}
+
+static void
+gimp_container_real_remove (GimpContainer *container,
+                            GimpObject    *object)
+{
+  container->num_children--;
+}
+
+
 typedef struct
 {
   GimpConfigWriter *writer;
@@ -515,9 +535,8 @@
 gimp_container_add (GimpContainer *container,
                     GimpObject    *object)
 {
-  GimpContainerHandler *handler;
-  GList                *list;
-  gulong                handler_id;
+  GList *list;
+  gint   n_children;
 
   g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
   g_return_val_if_fail (object != NULL, FALSE);
@@ -534,7 +553,8 @@
 
   for (list = container->handlers; list; list = g_list_next (list))
     {
-      handler = (GimpContainerHandler *) list->data;
+      GimpContainerHandler *handler = list->data;
+      gulong                handler_id;
 
       handler_id = g_signal_connect (object,
                                      handler->signame,
@@ -558,10 +578,19 @@
       break;
     }
 
-  container->num_children++;
+  n_children = container->num_children;
 
   g_signal_emit (container, container_signals[ADD], 0, object);
 
+  if (n_children == container->num_children)
+    {
+      g_warning ("%s: GimpContainer::add() implementation did not "
+                 "chain up. Please report this at http://www.gimp.org/bugs/";,
+                 G_STRFUNC);
+
+      container->num_children++;
+    }
+
   return TRUE;
 }
 
@@ -569,9 +598,8 @@
 gimp_container_remove (GimpContainer *container,
                        GimpObject    *object)
 {
-  GimpContainerHandler *handler;
-  GList                *list;
-  gulong                handler_id;
+  GList *list;
+  gint   n_children;
 
   g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
   g_return_val_if_fail (object != NULL, FALSE);
@@ -588,7 +616,8 @@
 
   for (list = container->handlers; list; list = g_list_next (list))
     {
-      handler = (GimpContainerHandler *) list->data;
+      GimpContainerHandler *handler = list->data;
+      gulong                handler_id;
 
       handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
                                                          handler->quark));
@@ -601,10 +630,18 @@
         }
     }
 
-  container->num_children--;
+  n_children = container->num_children;
+
+  g_signal_emit (container, container_signals[REMOVE], 0, object);
 
-  g_signal_emit (container, container_signals[REMOVE], 0,
-                 object);
+  if (n_children == container->num_children)
+    {
+      g_warning ("%s: GimpContainer::remove() implementation did not "
+                 "chain up. Please report this at http://www.gimp.org/bugs/";,
+                 G_STRFUNC);
+
+      container->num_children--;
+    }
 
   switch (container->policy)
     {

Modified: trunk/app/core/gimplist.c
==============================================================================
--- trunk/app/core/gimplist.c	(original)
+++ trunk/app/core/gimplist.c	Sat Oct 11 10:14:21 2008
@@ -230,6 +230,8 @@
     list->list = g_list_append (list->list, object);
   else
     list->list = g_list_prepend (list->list, object);
+
+  GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
 }
 
 static void
@@ -244,6 +246,8 @@
                                           list);
 
   list->list = g_list_remove (list->list, object);
+
+  GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
 }
 
 static void



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