[cairo-commit] goocanvas/src goocanvasellipseview.c, 1.7, 1.8 goocanvasgroupview.c, 1.9, 1.10 goocanvasimageview.c, 1.7, 1.8 goocanvasitemviewsimple.c, 1.1, 1.2 goocanvaspathview.c, 1.5, 1.6 goocanvaspolylineview.c, 1.8, 1.9 goocanvasrectview.c, 1.7, 1.8 goocanvastextview.c, 1.8, 1.9 goocanvasview.c, 1.12, 1.13

Damon Chaplin commit at pdx.freedesktop.org
Sun Apr 16 15:29:46 PDT 2006


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv15745/src

Modified Files:
	goocanvasellipseview.c goocanvasgroupview.c 
	goocanvasimageview.c goocanvasitemviewsimple.c 
	goocanvaspathview.c goocanvaspolylineview.c 
	goocanvasrectview.c goocanvastextview.c goocanvasview.c 
Log Message:
2006-04-16  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasview.c (propagate_event, emit_pointer_event): ref views
	and check they are still valid.

	* src/*view.[hc]: made views hold reference on items, to ensure we
	never use invalid pointers.



Index: goocanvasellipseview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasellipseview.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvasellipseview.c	16 Apr 2006 13:20:05 -0000	1.7
+++ goocanvasellipseview.c	16 Apr 2006 22:29:44 -0000	1.8
@@ -76,7 +76,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_ELLIPSE_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) ellipse;
+  view->item = g_object_ref (ellipse);
 
   g_signal_connect (ellipse, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvasgroupview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasgroupview.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- goocanvasgroupview.c	16 Apr 2006 13:20:05 -0000	1.9
+++ goocanvasgroupview.c	16 Apr 2006 22:29:44 -0000	1.10
@@ -86,7 +86,7 @@
   group_view = GOO_CANVAS_GROUP_VIEW (g_object_new (GOO_TYPE_CANVAS_GROUP_VIEW, NULL));
   group_view->canvas_view = canvas_view;
   group_view->parent_view = parent_view;
-  group_view->group = group;
+  group_view->group = g_object_ref (group);
 
   add_child_views_recursively (group_view);
   connect_group_signals (group_view);
@@ -117,6 +117,10 @@
 
   g_ptr_array_free (group_view->item_views, TRUE);
 
+  /* Unref the group. */
+  g_object_unref (group_view->group);
+  group_view->group = NULL;
+
   G_OBJECT_CLASS (goo_canvas_group_view_parent_class)->finalize (object);
 }
 

Index: goocanvasimageview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasimageview.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvasimageview.c	16 Apr 2006 13:20:05 -0000	1.7
+++ goocanvasimageview.c	16 Apr 2006 22:29:44 -0000	1.8
@@ -73,7 +73,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_IMAGE_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) image;
+  view->item = g_object_ref (image);
 
   g_signal_connect (image, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvasitemviewsimple.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemviewsimple.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- goocanvasitemviewsimple.c	16 Apr 2006 13:20:05 -0000	1.1
+++ goocanvasitemviewsimple.c	16 Apr 2006 22:29:44 -0000	1.2
@@ -25,6 +25,7 @@
 
 
 static void canvas_item_view_interface_init  (GooCanvasItemViewIface *iface);
+static void goo_canvas_item_view_simple_finalize (GObject *object);
 
 G_DEFINE_TYPE_WITH_CODE (GooCanvasItemViewSimple, goo_canvas_item_view_simple,
 			 G_TYPE_OBJECT,
@@ -35,7 +36,9 @@
 static void
 goo_canvas_item_view_simple_class_init (GooCanvasItemViewSimpleClass *klass)
 {
+  GObjectClass *gobject_class = (GObjectClass*) klass;
 
+  gobject_class->finalize = goo_canvas_item_view_simple_finalize;
 }
 
 
@@ -49,6 +52,17 @@
 }
 
 
+static void
+goo_canvas_item_view_simple_finalize (GObject *object)
+{
+  GooCanvasItemViewSimple *simple_view = (GooCanvasItemViewSimple*) object;
+
+  /* Unref the item. */
+  g_object_unref (simple_view->item);
+  simple_view->item = NULL;
+}
+
+
 static GooCanvasItemView*
 goo_canvas_item_view_simple_get_parent_view (GooCanvasItemView   *view)
 {

Index: goocanvaspathview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspathview.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- goocanvaspathview.c	16 Apr 2006 13:20:05 -0000	1.5
+++ goocanvaspathview.c	16 Apr 2006 22:29:44 -0000	1.6
@@ -75,7 +75,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_PATH_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) path;
+  view->item = g_object_ref (path);
 
   g_signal_connect (path, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvaspolylineview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspolylineview.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- goocanvaspolylineview.c	16 Apr 2006 13:20:05 -0000	1.8
+++ goocanvaspolylineview.c	16 Apr 2006 22:29:44 -0000	1.9
@@ -74,7 +74,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_POLYLINE_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) polyline;
+  view->item = g_object_ref (polyline);
 
   g_signal_connect (polyline, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvasrectview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasrectview.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvasrectview.c	16 Apr 2006 13:20:05 -0000	1.7
+++ goocanvasrectview.c	16 Apr 2006 22:29:44 -0000	1.8
@@ -77,7 +77,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_RECT_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) rect;
+  view->item = g_object_ref (rect);
 
   g_signal_connect (rect, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvastextview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastextview.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- goocanvastextview.c	16 Apr 2006 13:20:05 -0000	1.8
+++ goocanvastextview.c	16 Apr 2006 22:29:44 -0000	1.9
@@ -79,7 +79,7 @@
 
   view = g_object_new (GOO_TYPE_CANVAS_TEXT_VIEW, NULL);
   view->parent_view = parent_view;
-  view->item = (GooCanvasItemSimple*) text;
+  view->item = g_object_ref (text);
 
   g_signal_connect (text, "changed",
 		    G_CALLBACK (goo_canvas_item_view_simple_item_changed),

Index: goocanvasview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasview.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goocanvasview.c	16 Apr 2006 21:00:54 -0000	1.12
+++ goocanvasview.c	16 Apr 2006 22:29:44 -0000	1.13
@@ -1227,8 +1227,8 @@
 		 gchar             *signal_name,
 		 GdkEvent          *event)
 {
-  GooCanvasItemView *ancestor, *parent;
-  gboolean stop_emission = FALSE;
+  GooCanvasItemView *ancestor;
+  gboolean stop_emission = FALSE, valid;
 
   /* Don't emit any events if the canvas is not realized. */
   if (!GTK_WIDGET_REALIZED (view))
@@ -1248,19 +1248,31 @@
       ancestor = view->root_view;
     }
 
+  /* Make sure the item_view pointer remains valid throughout the emission. */
+  if (item_view)
+    g_object_ref (item_view);
+
   while (ancestor)
     {
-      parent = goo_canvas_item_view_get_parent_view (ancestor);
+      g_object_ref (ancestor);
 
       g_signal_emit_by_name (ancestor, signal_name, item_view, event,
 			     &stop_emission);
 
-      if (stop_emission)
+      /* Check if the ancestor is still in the canvas. */
+      valid = VIEW_IS_VALID (ancestor) ? TRUE : FALSE;
+
+      g_object_unref (ancestor);
+
+      if (stop_emission || !valid)
 	break;
 
-      ancestor = parent;
+      ancestor = goo_canvas_item_view_get_parent_view (ancestor);
     }
 
+  if (item_view)
+    g_object_unref (item_view);
+
   return stop_emission;
 }
 
@@ -1289,6 +1301,10 @@
       target_item_view = view->pointer_grab_item_view;
     }
 
+  /* Check if the target item view is still in the canvas. */
+  if (target_item_view && !VIEW_IS_VALID (target_item_view))
+    return FALSE;
+
   /* Translate the x & y coordinates to the item's space. */
   switch (event.type)
     {



More information about the cairo-commit mailing list