[evolution/rendering-cleanup: 21/63] gnome-canvas: Change GnomeCanvasItem->point vfunc



commit f419a3610bca628646f5c26ee28ff41a963fc1ee
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 10 02:31:45 2010 +0200

    gnome-canvas: Change GnomeCanvasItem->point vfunc
    
    Previously the function returned the distance to the nearest item. Now
    it only returns an item that is hit. This slightly changes semantics
    (button events are no longer dispatched to the nearest item, but only to
    the item actually clicked on), but makes the code way simpler and
    actually does what one would expect.

 calendar/gui/e-day-view-main-item.c        |   13 +----
 calendar/gui/e-day-view-time-item.c        |   15 +++----
 calendar/gui/e-day-view-top-item.c         |   13 +----
 calendar/gui/e-meeting-time-sel-item.c     |   18 +++-----
 calendar/gui/e-week-view-event-item.c      |   13 +----
 calendar/gui/e-week-view-main-item.c       |   13 +----
 calendar/gui/e-week-view-titles-item.c     |   13 +----
 libgnomecanvas/gnome-canvas-line.c         |   12 ++---
 libgnomecanvas/gnome-canvas-pixbuf.c       |   28 +++++-------
 libgnomecanvas/gnome-canvas-rich-text.c    |   32 +++-----------
 libgnomecanvas/gnome-canvas-shape.c        |   39 +++++------------
 libgnomecanvas/gnome-canvas-text.c         |   45 ++++---------------
 libgnomecanvas/gnome-canvas-widget.c       |   31 +++-----------
 libgnomecanvas/gnome-canvas.c              |   64 +++++++--------------------
 libgnomecanvas/gnome-canvas.h              |   13 +++---
 widgets/misc/e-calendar-item.c             |   13 ++----
 widgets/misc/e-canvas-background.c         |   16 +++----
 widgets/misc/e-canvas.c                    |   10 ++---
 widgets/table/e-table-field-chooser-item.c |    8 +--
 widgets/table/e-table-header-item.c        |    8 +--
 widgets/table/e-table-item.c               |    9 +---
 widgets/text/e-reflow.c                    |   18 +++-----
 widgets/text/e-text.c                      |   14 +++----
 23 files changed, 138 insertions(+), 320 deletions(-)
---
diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c
index 148843b..33e45bb 100644
--- a/calendar/gui/e-day-view-main-item.c
+++ b/calendar/gui/e-day-view-main-item.c
@@ -1235,21 +1235,14 @@ day_view_main_item_draw (GnomeCanvasItem *canvas_item,
 	gdk_region_destroy (draw_region);
 }
 
-static gdouble
+static GnomeCanvasItem *
 day_view_main_item_point (GnomeCanvasItem *item,
                           gdouble x,
                           gdouble y,
                           gint cx,
-                          gint cy,
-                          GnomeCanvasItem **actual_item)
+                          gint cy)
 {
-	/* This is supposed to return the nearest item to the point
-	 * and the distance.  Since we are the only item we just return
-	 * ourself and 0 for the distance.  This is needed so that we
-	 * get button/motion events. */
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c
index 9e430ec..e952515 100644
--- a/calendar/gui/e-day-view-time-item.c
+++ b/calendar/gui/e-day-view-time-item.c
@@ -80,10 +80,9 @@ static void e_day_view_time_item_draw (GnomeCanvasItem *item,
 				       GdkDrawable *drawable,
 				       gint x, gint y,
 				       gint width, gint height);
-static double e_day_view_time_item_point (GnomeCanvasItem *item,
-					  double x, double y,
-					  gint cx, gint cy,
-					  GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *e_day_view_time_item_point (GnomeCanvasItem *item,
+                                                    double x, double y,
+                                                    gint cx, gint cy);
 static gint e_day_view_time_item_event (GnomeCanvasItem *item,
 					GdkEvent *event);
 static void e_day_view_time_item_increment_time	(gint	*hour,
@@ -649,13 +648,11 @@ e_day_view_time_item_increment_time	(gint	*hour,
 	}
 }
 
-static double
+static GnomeCanvasItem *
 e_day_view_time_item_point (GnomeCanvasItem *item, double x, double y,
-			    gint cx, gint cy,
-			    GnomeCanvasItem **actual_item)
+			    gint cx, gint cy)
 {
-	*actual_item = item;
-	return 0.0;
+	return item;
 }
 
 static gint
diff --git a/calendar/gui/e-day-view-top-item.c b/calendar/gui/e-day-view-top-item.c
index c0b718d..41a2b66 100644
--- a/calendar/gui/e-day-view-top-item.c
+++ b/calendar/gui/e-day-view-top-item.c
@@ -781,21 +781,14 @@ day_view_top_item_draw (GnomeCanvasItem *canvas_item,
 	cairo_destroy (cr);
 }
 
-static double
+static GnomeCanvasItem *
 day_view_top_item_point (GnomeCanvasItem *item,
                          gdouble x,
                          gdouble y,
                          gint cx,
-                         gint cy,
-                         GnomeCanvasItem **actual_item)
+                         gint cy)
 {
-	/* This is supposed to return the nearest item the the point
-	 * and the distance.  Since we are the only item we just return
-	 * ourself and 0 for the distance.  This is needed so that we
-	 * get button/motion events. */
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/calendar/gui/e-meeting-time-sel-item.c b/calendar/gui/e-meeting-time-sel-item.c
index e1c5d56..2119127 100644
--- a/calendar/gui/e-meeting-time-sel-item.c
+++ b/calendar/gui/e-meeting-time-sel-item.c
@@ -54,10 +54,9 @@ static void e_meeting_time_selector_item_draw (GnomeCanvasItem *item,
 					       GdkDrawable *drawable,
 					       gint x, gint y,
 					       gint width, gint height);
-static double e_meeting_time_selector_item_point (GnomeCanvasItem *item,
-						  double x, double y,
-						  gint cx, gint cy,
-						  GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *e_meeting_time_selector_item_point (GnomeCanvasItem *item,
+                                                            double x, double y,
+                                                            gint cx, gint cy);
 static gint e_meeting_time_selector_item_event (GnomeCanvasItem *item,
 						GdkEvent *event);
 static gint e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item,
@@ -779,16 +778,11 @@ e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorIt
  * CANVAS ITEM ROUTINES - functions to be a GnomeCanvasItem.
  */
 
-/* This is supposed to return the nearest item the the point and the distance.
-   Since we are the only item we just return ourself and 0 for the distance.
-   This is needed so that we get button/motion events. */
-static double
+static GnomeCanvasItem *
 e_meeting_time_selector_item_point (GnomeCanvasItem *item, double x, double y,
-				    gint cx, gint cy,
-				    GnomeCanvasItem **actual_item)
+				    gint cx, gint cy)
 {
-	*actual_item = item;
-	return 0.0;
+	return item;
 }
 
 static gint
diff --git a/calendar/gui/e-week-view-event-item.c b/calendar/gui/e-week-view-event-item.c
index f2b3471..8309dcd 100644
--- a/calendar/gui/e-week-view-event-item.c
+++ b/calendar/gui/e-week-view-event-item.c
@@ -1126,21 +1126,14 @@ week_view_event_item_draw (GnomeCanvasItem *canvas_item,
 	gdk_region_destroy (draw_region);
 }
 
-static double
+static GnomeCanvasItem *
 week_view_event_item_point (GnomeCanvasItem *item,
                             gdouble x,
                             gdouble y,
                             gint cx,
-                            gint cy,
-                            GnomeCanvasItem **actual_item)
+                            gint cy)
 {
-	/* This is supposed to return the nearest item the the point
-	 * and the distance.  Since we are the only item we just return
-	 * ourself and 0 for the distance.  This is needed so that we
-	 * get button/motion events. */
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static gint
diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c
index a42b60e..5d09d45 100644
--- a/calendar/gui/e-week-view-main-item.c
+++ b/calendar/gui/e-week-view-main-item.c
@@ -411,21 +411,14 @@ week_view_main_item_draw (GnomeCanvasItem *canvas_item,
 	}
 }
 
-static gdouble
+static GnomeCanvasItem *
 week_view_main_item_point (GnomeCanvasItem *item,
                            gdouble x,
                            gdouble y,
                            gint cx,
-                           gint cy,
-                           GnomeCanvasItem **actual_item)
+                           gint cy)
 {
-	/* This is supposed to return the nearest item the the point
-	 * and the distance.  Since we are the only item we just return
-	 * ourself and 0 for the distance.  This is needed so that we
-	 * get button/motion events. */
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/calendar/gui/e-week-view-titles-item.c b/calendar/gui/e-week-view-titles-item.c
index ab7a9db..2e058d1 100644
--- a/calendar/gui/e-week-view-titles-item.c
+++ b/calendar/gui/e-week-view-titles-item.c
@@ -243,21 +243,14 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
 	g_object_unref (layout);
 }
 
-static double
+static GnomeCanvasItem *
 week_view_titles_item_point (GnomeCanvasItem *item,
                              gdouble x,
                              gdouble y,
                              gint cx,
-                             gint cy,
-                             GnomeCanvasItem **actual_item)
+                             gint cy)
 {
-	/* This is supposed to return the nearest item the the point
-	 * and the distance.  Since we are the only item we just return
-	 * ourself and 0 for the distance.  This is needed so that we
-	 * get button/motion events. */
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/libgnomecanvas/gnome-canvas-line.c b/libgnomecanvas/gnome-canvas-line.c
index 4e6364d..20cde8a 100644
--- a/libgnomecanvas/gnome-canvas-line.c
+++ b/libgnomecanvas/gnome-canvas-line.c
@@ -95,8 +95,8 @@ static void gnome_canvas_line_get_property (GObject              *object,
 static void   gnome_canvas_line_update      (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint flags);
 static void   gnome_canvas_line_draw        (GnomeCanvasItem *item, GdkDrawable *drawable,
 					     gint x, gint y, gint width, gint height);
-static gdouble gnome_canvas_line_point       (GnomeCanvasItem *item, gdouble x, gdouble y,
-					     gint cx, gint cy, GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *gnome_canvas_line_point  (GnomeCanvasItem *item, gdouble x, gdouble y,
+					     gint cx, gint cy);
 static void   gnome_canvas_line_bounds      (GnomeCanvasItem *item, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
 
 static GnomeCanvasItemClass *parent_class;
@@ -995,9 +995,9 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 	}
 }
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_line_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			 gint cx, gint cy, GnomeCanvasItem **actual_item)
+			 gint cx, gint cy)
 {
 	GnomeCanvasLine *line;
 	gdouble *line_points = NULL, *coords;
@@ -1015,8 +1015,6 @@ gnome_canvas_line_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 
 	line = GNOME_CANVAS_LINE (item);
 
-	*actual_item = item;
-
 	best = 1.0e36;
 
 	/* Handle smoothed lines by generating an expanded set ot points */
@@ -1174,7 +1172,7 @@ done:
 	if ((line_points != static_points) && (line_points != line->coords))
 		g_free (line_points);
 
-	return best;
+	return best == 0.0 ? item : NULL;
 }
 
 static void
diff --git a/libgnomecanvas/gnome-canvas-pixbuf.c b/libgnomecanvas/gnome-canvas-pixbuf.c
index 39324dc..499f83e 100644
--- a/libgnomecanvas/gnome-canvas-pixbuf.c
+++ b/libgnomecanvas/gnome-canvas-pixbuf.c
@@ -97,12 +97,11 @@ static void gnome_canvas_pixbuf_update (GnomeCanvasItem *item, gdouble *affine,
 					ArtSVP *clip_path, gint flags);
 static void gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 				      gint x, gint y, gint width, gint height);
-static gdouble gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
-					 gdouble x,
-					 gdouble y,
-					 gint cx,
-					 gint cy,
-					 GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
+                                                   gdouble x,
+                                                   gdouble y,
+                                                   gint cx,
+                                                   gint cy);
 static void gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item,
 					gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
 
@@ -884,13 +883,12 @@ gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 
 
 /* Point handler for the pixbuf canvas item */
-static double
+static GnomeCanvasItem *
 gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
                            gdouble x,
                            gdouble y,
                            gint cx,
-                           gint cy,
-                           GnomeCanvasItem **actual_item)
+                           gint cy)
 {
 	GnomeCanvasPixbuf *gcp;
 	PixbufPrivate *priv;
@@ -905,12 +903,10 @@ gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
 	priv = gcp->priv;
 	pixbuf = priv->pixbuf;
 
-	*actual_item = item;
-
 	no_hit = item->canvas->pixels_per_unit * 2 + 10;
 
 	if (!priv->pixbuf)
-		return no_hit;
+		return NULL;
 
 	gnome_canvas_item_i2c_affine (item, i2c);
 	compute_render_affine (gcp, render_affine, i2c);
@@ -924,19 +920,19 @@ gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
 
 	if (px < 0 || px >= gdk_pixbuf_get_width (pixbuf) ||
 	    py < 0 || py >= gdk_pixbuf_get_height (pixbuf))
-		return no_hit;
+		return NULL;
 
 	if (!gdk_pixbuf_get_has_alpha (pixbuf))
-		return 0.0;
+		return item;
 
 	src = gdk_pixbuf_get_pixels (pixbuf) +
 	    py * gdk_pixbuf_get_rowstride (pixbuf) +
 	    px * gdk_pixbuf_get_n_channels (pixbuf);
 
 	if (src[3] < 128)
-		return no_hit;
+		return NULL;
 	else
-		return 0.0;
+		return item;
 }
 
 
diff --git a/libgnomecanvas/gnome-canvas-rich-text.c b/libgnomecanvas/gnome-canvas-rich-text.c
index 32d1dbd..8cf04e5 100644
--- a/libgnomecanvas/gnome-canvas-rich-text.c
+++ b/libgnomecanvas/gnome-canvas-rich-text.c
@@ -122,10 +122,9 @@ static void gnome_canvas_rich_text_update (GnomeCanvasItem *item, gdouble *affin
 					  ArtSVP *clip_path, gint flags);
 static void gnome_canvas_rich_text_realize (GnomeCanvasItem *item);
 static void gnome_canvas_rich_text_unrealize (GnomeCanvasItem *item);
-static gdouble gnome_canvas_rich_text_point (GnomeCanvasItem *item,
-					   gdouble x, gdouble y,
-					   gint cx, gint cy,
-					   GnomeCanvasItem **actual_item);
+static GnomeCanvasItem * gnome_canvas_rich_text_point (GnomeCanvasItem *item,
+                                                       gdouble x, gdouble y,
+                                                       gint cx, gint cy);
 static void gnome_canvas_rich_text_draw (GnomeCanvasItem *item,
 					GdkDrawable *drawable,
 					gint x, gint y, gint width, gint height);
@@ -2083,16 +2082,13 @@ gnome_canvas_rich_text_update (GnomeCanvasItem *item, gdouble *affine,
 	gnome_canvas_update_bbox (item, x1, y1, x2, y2);
 } /* gnome_canvas_rich_text_update */
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_rich_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			     gint cx, gint cy, GnomeCanvasItem **actual_item)
+			     gint cx, gint cy)
 {
 	GnomeCanvasRichText *text = GNOME_CANVAS_RICH_TEXT (item);
 	gdouble ax, ay;
 	gdouble x1, x2, y1, y2;
-	gdouble dx, dy;
-
-	*actual_item = item;
 
 	/* This is a lame cop-out. Anywhere inside of the bounding box. */
 
@@ -2104,23 +2100,9 @@ gnome_canvas_rich_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 	y2 = ay + text->_priv->height;
 
 	if ((x > x1) && (y > y1) && (x < x2) && (y < y2))
-		return 0.0;
-
-	if (x < x1)
-		dx = x1 - x;
-	else if (x > x2)
-		dx = x - x2;
-	else
-		dx = 0.0;
-
-	if (y < y1)
-		dy = y1 - y;
-	else if (y > y2)
-		dy = y - y2;
-	else
-		dy = 0.0;
+		return item;
 
-	return sqrt (dx * dx + dy * dy);
+        return NULL;
 } /* gnome_canvas_rich_text_point */
 
 static void
diff --git a/libgnomecanvas/gnome-canvas-shape.c b/libgnomecanvas/gnome-canvas-shape.c
index 70f3516..d1e7c1c 100644
--- a/libgnomecanvas/gnome-canvas-shape.c
+++ b/libgnomecanvas/gnome-canvas-shape.c
@@ -75,8 +75,8 @@ static void   gnome_canvas_shape_realize     (GnomeCanvasItem *item);
 static void   gnome_canvas_shape_unrealize   (GnomeCanvasItem *item);
 static void   gnome_canvas_shape_draw        (GnomeCanvasItem *item, GdkDrawable *drawable,
                                               gint x, gint y, gint width, gint height);
-static gdouble gnome_canvas_shape_point       (GnomeCanvasItem *item, gdouble x, gdouble y,
-                                              gint cx, gint cy, GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *gnome_canvas_shape_point (GnomeCanvasItem *item, gdouble x, gdouble y,
+                                              gint cx, gint cy);
 static void   gnome_canvas_shape_bounds      (GnomeCanvasItem *item,
 					      gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
 
@@ -1084,12 +1084,11 @@ gnome_canvas_shape_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_
         gnome_canvas_shape_update_gdk (shape, affine, clip_path, flags);
 }
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_shape_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			    gint cx, gint cy, GnomeCanvasItem **actual_item)
+			    gint cx, gint cy)
 {
 	GnomeCanvasShape *shape;
-	gdouble dist;
 	gint wind;
 
 #if 0
@@ -1104,35 +1103,19 @@ gnome_canvas_shape_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 	/* todo: update? */
 	if (shape->priv->fill_set && shape->priv->fill_svp) {
 		wind = art_svp_point_wind (shape->priv->fill_svp, cx, cy);
-		if ((shape->priv->wind == ART_WIND_RULE_NONZERO) && (wind != 0)) {
-			*actual_item = item;
-			return 0.0;
-		}
-		if ((shape->priv->wind == ART_WIND_RULE_ODDEVEN) && ((wind & 0x1) != 0)) {
-			*actual_item = item;
-			return 0.0;
-		}
+		if ((shape->priv->wind == ART_WIND_RULE_NONZERO) && (wind != 0))
+			return item;
+		if ((shape->priv->wind == ART_WIND_RULE_ODDEVEN) && ((wind & 0x1) != 0))
+		        return item;
 	}
 
 	if (shape->priv->outline_set && shape->priv->outline_svp) {
 		wind = art_svp_point_wind (shape->priv->outline_svp, cx, cy);
-		if (wind) {
-			*actual_item = item;
-			return 0.0;
-		}
-	}
-
-	if (shape->priv->outline_set && shape->priv->outline_svp) {
-		dist = art_svp_point_dist (shape->priv->outline_svp, cx, cy);
-	} else if (shape->priv->fill_set && shape->priv->outline_svp) {
-		dist = art_svp_point_dist (shape->priv->fill_svp, cx, cy);
-	} else {
-		return 1e12;
+		if (wind)
+                        return item;
 	}
 
-	*actual_item = item;
-
-	return dist;
+	return NULL;
 }
 
 /* Helpers */
diff --git a/libgnomecanvas/gnome-canvas-text.c b/libgnomecanvas/gnome-canvas-text.c
index 2c4663f..b71b1af 100644
--- a/libgnomecanvas/gnome-canvas-text.c
+++ b/libgnomecanvas/gnome-canvas-text.c
@@ -120,12 +120,11 @@ static void gnome_canvas_text_realize (GnomeCanvasItem *item);
 static void gnome_canvas_text_unrealize (GnomeCanvasItem *item);
 static void gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 				    gint x, gint y, gint width, gint height);
-static gdouble gnome_canvas_text_point (GnomeCanvasItem *item,
-				       gdouble x,
-				       gdouble y,
-				       gint cx,
-				       gint cy,
-				       GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *gnome_canvas_text_point (GnomeCanvasItem *item,
+                                                 gdouble x,
+                                                 gdouble y,
+                                                 gint cx,
+                                                 gint cy);
 static void gnome_canvas_text_bounds (GnomeCanvasItem *item,
 				      gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
 
@@ -1415,28 +1414,22 @@ gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 }
 
 /* Point handler for the text item */
-static double
+static GnomeCanvasItem *
 gnome_canvas_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			 gint cx, gint cy, GnomeCanvasItem **actual_item)
+			 gint cx, gint cy)
 {
 	GnomeCanvasText *text;
 	PangoLayoutIter *iter;
 	gint x1, y1, x2, y2;
-	gint dx, dy;
-	gdouble dist, best;
 
 	text = GNOME_CANVAS_TEXT (item);
 
-	*actual_item = item;
-
 	/* The idea is to build bounding rectangles for each of the lines of
 	 * text (clipped by the clipping rectangle, if it is activated) and see
 	 * whether the point is inside any of these.  If it is, we are done.
 	 * Otherwise, calculate the distance to the nearest rectangle.
 	 */
 
-	best = 1.0e36;
-
 	iter = pango_layout_get_iter (text->layout);
 	do {
 		PangoRectangle log_rect;
@@ -1467,34 +1460,16 @@ gnome_canvas_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 
 		/* Calculate distance from point to rectangle */
 
-		if (cx < x1)
-			dx = x1 - cx;
-		else if (cx >= x2)
-			dx = cx - x2 + 1;
-		else
-			dx = 0;
-
-		if (cy < y1)
-			dy = y1 - cy;
-		else if (cy >= y2)
-			dy = cy - y2 + 1;
-		else
-			dy = 0;
-
-		if ((dx == 0) && (dy == 0)) {
+		if (cx >= x1 && cx < x2 && cy >= y1 && cy < y2) {
 			pango_layout_iter_free (iter);
-			return 0.0;
+			return item;
 		}
 
-		dist = sqrt (dx * dx + dy * dy);
-		if (dist < best)
-			best = dist;
-
 	} while (pango_layout_iter_next_line (iter));
 
 	pango_layout_iter_free (iter);
 
-	return best / item->canvas->pixels_per_unit;
+	return NULL;
 }
 
 /* Bounds handler for the text item */
diff --git a/libgnomecanvas/gnome-canvas-widget.c b/libgnomecanvas/gnome-canvas-widget.c
index 36cffad..b57b59e 100644
--- a/libgnomecanvas/gnome-canvas-widget.c
+++ b/libgnomecanvas/gnome-canvas-widget.c
@@ -63,12 +63,11 @@ static void	gnome_canvas_widget_update	(GnomeCanvasItem *item,
 						 gdouble *affine,
 						 ArtSVP *clip_path,
 						 gint flags);
-static gdouble	gnome_canvas_widget_point	(GnomeCanvasItem *item,
+static GnomeCanvasItem *gnome_canvas_widget_point (GnomeCanvasItem *item,
 						 gdouble x,
 						 gdouble y,
 						 gint cx,
-						 gint cy,
-						 GnomeCanvasItem **actual_item);
+						 gint cy);
 static void	gnome_canvas_widget_bounds	(GnomeCanvasItem *item,
 						 gdouble *x1,
 						 gdouble *y1,
@@ -491,18 +490,15 @@ gnome_canvas_widget_draw (GnomeCanvasItem *item,
 #endif
 }
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_widget_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			   gint cx, gint cy, GnomeCanvasItem **actual_item)
+			   gint cx, gint cy)
 {
 	GnomeCanvasWidget *witem;
 	gdouble x1, y1, x2, y2;
-	gdouble dx, dy;
 
 	witem = GNOME_CANVAS_WIDGET (item);
 
-	*actual_item = item;
-
 	gnome_canvas_c2w (item->canvas, witem->cx, witem->cy, &x1, &y1);
 
 	x2 = x1 + (witem->cwidth - 1) / item->canvas->pixels_per_unit;
@@ -511,25 +507,10 @@ gnome_canvas_widget_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 	/* Is point inside widget bounds? */
 
 	if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2))
-		return 0.0;
+		return item;
 
 	/* Point is outside widget bounds */
-
-	if (x < x1)
-		dx = x1 - x;
-	else if (x > x2)
-		dx = x - x2;
-	else
-		dx = 0.0;
-
-	if (y < y1)
-		dy = y1 - y;
-	else if (y > y2)
-		dy = y - y2;
-	else
-		dy = 0.0;
-
-	return sqrt (dx * dx + dy * dy);
+        return NULL;
 }
 
 static void
diff --git a/libgnomecanvas/gnome-canvas.c b/libgnomecanvas/gnome-canvas.c
index 84eda87..2f4d27b 100644
--- a/libgnomecanvas/gnome-canvas.c
+++ b/libgnomecanvas/gnome-canvas.c
@@ -512,13 +512,12 @@ gnome_canvas_item_invoke_update (GnomeCanvasItem *item,
  * This is potentially evil, as we are relying on matrix inversion (Lauris)
  */
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_item_invoke_point (GnomeCanvasItem *item,
                                 gdouble x,
                                 gdouble y,
                                 gint cx,
-                                gint cy,
-                                GnomeCanvasItem **actual_item)
+                                gint cy)
 {
 	/* Calculate x & y in item local coordinates */
 
@@ -555,9 +554,9 @@ gnome_canvas_item_invoke_point (GnomeCanvasItem *item,
 #endif
 
 	if (GNOME_CANVAS_ITEM_GET_CLASS (item)->point)
-		return GNOME_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy, actual_item);
+		return GNOME_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy);
 
-	return 1e18;
+	return NULL;
 }
 
 /**
@@ -1400,10 +1399,9 @@ static void   gnome_canvas_group_draw        (GnomeCanvasItem *item,
 					      GdkDrawable *drawable,
 					      gint x, gint y,
 					      gint width, gint height);
-static gdouble gnome_canvas_group_point       (GnomeCanvasItem *item,
+static GnomeCanvasItem *gnome_canvas_group_point (GnomeCanvasItem *item,
 					      gdouble x, gdouble y,
-					      gint cx, gint cy,
-					      GnomeCanvasItem **actual_item);
+					      gint cx, gint cy);
 static void   gnome_canvas_group_bounds      (GnomeCanvasItem *item,
 					      gdouble *x1, gdouble *y1,
 					      gdouble *x2, gdouble *y2);
@@ -1746,55 +1744,34 @@ gnome_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 }
 
 /* Point handler for canvas groups */
-static double
+static GnomeCanvasItem *
 gnome_canvas_group_point (GnomeCanvasItem *item,
                           gdouble x,
                           gdouble y,
                           gint cx,
-                          gint cy,
-                          GnomeCanvasItem **actual_item)
+                          gint cy)
 {
 	GnomeCanvasGroup *group;
 	GList *list;
 	GnomeCanvasItem *child, *point_item;
-	gdouble gx, gy;
-	gdouble dist, best;
-	gint has_point;
 
 	group = GNOME_CANVAS_GROUP (item);
 
-	best = 0.0;
-	*actual_item = NULL;
-
-	gx = x;
-	gy = y;
-
-	dist = 0.0; /* keep gcc happy */
-
-	for (list = group->item_list; list; list = list->next) {
+	for (list = g_list_last (group->item_list); list; list = list->prev) {
 		child = list->data;
 
 		if ((child->x1 > cx) || (child->y1 > cy) || (child->x2 < cx) || (child->y2 < cy))
 			continue;
 
-		point_item = NULL; /* cater for incomplete item implementations */
-
-		if ((child->flags & GNOME_CANVAS_ITEM_VISIBLE)
-		    && GNOME_CANVAS_ITEM_GET_CLASS (child)->point) {
-			dist = gnome_canvas_item_invoke_point (child, gx, gy, cx, cy, &point_item);
-			has_point = TRUE;
-		} else
-			has_point = FALSE;
+		if (!(child->flags & GNOME_CANVAS_ITEM_VISIBLE))
+                        continue;
 
-		if (has_point
-		    && point_item
-		    && ((gint) (dist * item->canvas->pixels_per_unit + 0.5) <= 0)) {
-			best = dist;
-			*actual_item = point_item;
-		}
+		point_item = gnome_canvas_item_invoke_point (child, x, y, cx, cy);
+		if (point_item)
+                        return point_item;
 	}
 
-	return best;
+	return NULL;
 }
 
 /* Bounds handler for canvas groups */
@@ -2690,8 +2667,7 @@ pick_current_item (GnomeCanvas *canvas, GdkEvent *event)
 		/* find the closest item */
 
 		if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE)
-			gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
-							&canvas->new_current_item);
+			canvas->new_current_item = gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy);
 		else
 			canvas->new_current_item = NULL;
 	} else
@@ -3570,19 +3546,13 @@ gnome_canvas_update_now (GnomeCanvas *canvas)
 GnomeCanvasItem *
 gnome_canvas_get_item_at (GnomeCanvas *canvas, gdouble x, gdouble y)
 {
-	GnomeCanvasItem *item;
-	gdouble dist;
 	gint cx, cy;
 
 	g_return_val_if_fail (GNOME_IS_CANVAS (canvas), NULL);
 
 	gnome_canvas_w2c (canvas, x, y, &cx, &cy);
 
-	dist = gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy, &item);
-	if ((gint) (dist * canvas->pixels_per_unit + 0.5) <= 0)
-		return item;
-	else
-		return NULL;
+	return gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy);
 }
 
 /* Queues an update of the canvas */
diff --git a/libgnomecanvas/gnome-canvas.h b/libgnomecanvas/gnome-canvas.h
index 864f9e6..70a8f5c 100644
--- a/libgnomecanvas/gnome-canvas.h
+++ b/libgnomecanvas/gnome-canvas.h
@@ -171,14 +171,13 @@ struct _GnomeCanvasItemClass {
 	void (* draw) (GnomeCanvasItem *item, GdkDrawable *drawable,
 		       gint x, gint y, gint width, gint height);
 
-	/* Calculate the distance from an item to the specified point.  It also
-         * returns a canvas item which is the item itself in the case of the
-         * object being an actual leaf item, or a child in case of the object
-         * being a canvas group.  (cx, cy) are the canvas pixel coordinates that
-         * correspond to the item-relative coordinates (x, y).
+        /* Returns the canvas item which is at the given location. This is the
+         * item itself in the case of the object being an actual leaf item, or
+         * a child in case of the object being a canvas group.  (cx, cy) are
+         * the canvas pixel coordinates that correspond to the item-relative
+         * coordinates (x, y).
 	 */
-	gdouble (* point) (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy,
-			  GnomeCanvasItem **actual_item);
+	GnomeCanvasItem * (* point) (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy);
 
 	/* Fetch the item's bounding box (need not be exactly tight).  This
 	 * should be in item-relative coordinates.
diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c
index f5d2f87..5ca1143 100644
--- a/widgets/misc/e-calendar-item.c
+++ b/widgets/misc/e-calendar-item.c
@@ -90,12 +90,11 @@ static void e_calendar_item_draw_day_numbers (ECalendarItem	*calitem,
 					      gint		 start_weekday,
 					      gint		 cells_x,
 					      gint		 cells_y);
-static gdouble e_calendar_item_point	(GnomeCanvasItem *item,
+static GnomeCanvasItem *e_calendar_item_point	(GnomeCanvasItem *item,
 					 gdouble		  x,
 					 gdouble		  y,
 					 gint		  cx,
-					 gint		  cy,
-					 GnomeCanvasItem **actual_item);
+					 gint		  cy);
 static void e_calendar_item_stop_selecting (ECalendarItem *calitem,
 					    guint32 time);
 static void e_calendar_item_selection_add_days (ECalendarItem *calitem,
@@ -1760,13 +1759,11 @@ e_calendar_item_get_week_number	(ECalendarItem *calitem,
 /* This is supposed to return the nearest item the the point and the distance.
    Since we are the only item we just return ourself and 0 for the distance.
    This is needed so that we get button/motion events. */
-static double
+static GnomeCanvasItem *
 e_calendar_item_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-			   gint cx, gint cy,
-			   GnomeCanvasItem **actual_item)
+		       gint cx, gint cy)
 {
-	*actual_item = item;
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/widgets/misc/e-canvas-background.c b/widgets/misc/e-canvas-background.c
index f617937..b2be246 100644
--- a/widgets/misc/e-canvas-background.c
+++ b/widgets/misc/e-canvas-background.c
@@ -371,23 +371,21 @@ ecb_draw (GnomeCanvasItem *item,
 			    x1, y1, x2 - x1, y2 - y1);
 }
 
-static double
-ecb_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy,
-	   GnomeCanvasItem **actual_item)
+static GnomeCanvasItem *
+ecb_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy)
 {
 	ECanvasBackground *ecb = E_CANVAS_BACKGROUND (item);
 
 	if (ecb->priv->x1 >= 0 && ecb->priv->x1 > x)
-		return 1.0;
+		return NULL;
 	if (ecb->priv->x2 >= 0 && ecb->priv->x2 < x)
-		return 1.0;
+		return NULL;
 	if (ecb->priv->y1 >= 0 && ecb->priv->y1 > y)
-		return 1.0;
+		return NULL;
 	if (ecb->priv->y2 >= 0 && ecb->priv->y2 < y)
-		return 1.0;
-	*actual_item = item;
+		return NULL;
 
-	return 0.0;
+	return item;
 }
 
 static void
diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c
index dfa529e..0b24b84 100644
--- a/widgets/misc/e-canvas.c
+++ b/widgets/misc/e-canvas.c
@@ -167,13 +167,12 @@ canvas_emit_event (GnomeCanvas *canvas,
  * invariant. */
 #define HACKISH_AFFINE
 
-static double
+static GnomeCanvasItem *
 gnome_canvas_item_invoke_point (GnomeCanvasItem *item,
                                 gdouble x,
                                 gdouble y,
                                 gint cx,
-                                gint cy,
-                                GnomeCanvasItem **actual_item)
+                                gint cy)
 {
 #ifdef HACKISH_AFFINE
 	gdouble i2w[6], w2c[6], i2c[6], c2i[6];
@@ -193,7 +192,7 @@ gnome_canvas_item_invoke_point (GnomeCanvasItem *item,
 #endif
 
 	return (* GNOME_CANVAS_ITEM_CLASS (G_OBJECT_GET_CLASS (item))->point) (
-		item, x, y, cx, cy, actual_item);
+		item, x, y, cx, cy);
 }
 
 /* Re-picks the current item in the canvas, based on the event's coordinates.
@@ -287,8 +286,7 @@ pick_current_item (GnomeCanvas *canvas, GdkEvent *event)
 		/* find the closest item */
 
 		if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE)
-			gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
-							&canvas->new_current_item);
+			canvas->new_current_item = gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy);
 		else
 			canvas->new_current_item = NULL;
 	} else
diff --git a/widgets/table/e-table-field-chooser-item.c b/widgets/table/e-table-field-chooser-item.c
index 67beee9..2004800 100644
--- a/widgets/table/e-table-field-chooser-item.c
+++ b/widgets/table/e-table-field-chooser-item.c
@@ -522,12 +522,10 @@ etfci_draw (GnomeCanvasItem *item,
 	}
 }
 
-static double
-etfci_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy,
-	    GnomeCanvasItem **actual_item)
+static GnomeCanvasItem *
+etfci_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy)
 {
-	*actual_item = item;
-	return 0.0;
+	return item;
 }
 
 static gboolean
diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c
index f3ed548..0f74442 100644
--- a/widgets/table/e-table-header-item.c
+++ b/widgets/table/e-table-header-item.c
@@ -1070,12 +1070,10 @@ ethi_draw (GnomeCanvasItem *item,
 	g_hash_table_destroy (arrows);
 }
 
-static double
-ethi_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy,
-	    GnomeCanvasItem **actual_item)
+static GnomeCanvasItem *
+ethi_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy)
 {
-	*actual_item = item;
-	return 0.0;
+	return item;
 }
 
 /*
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index 7bd0ed4..d68c69a 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -2042,13 +2042,10 @@ exit:
 	cairo_destroy (cr);
 }
 
-static double
-eti_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy,
-	   GnomeCanvasItem **actual_item)
+static GnomeCanvasItem *
+eti_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy)
 {
-	*actual_item = item;
-
-	return 0.0;
+	return item;
 }
 
 static gboolean
diff --git a/widgets/text/e-reflow.c b/widgets/text/e-reflow.c
index 5485b35..df45984 100644
--- a/widgets/text/e-reflow.c
+++ b/widgets/text/e-reflow.c
@@ -43,7 +43,7 @@ static void e_reflow_unrealize (GnomeCanvasItem *item);
 static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 				    gint x, gint y, gint width, gint height);
 static void e_reflow_update (GnomeCanvasItem *item, gdouble affine[6], ArtSVP *clip_path, gint flags);
-static gdouble e_reflow_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy, GnomeCanvasItem **actual_item);
+static GnomeCanvasItem *e_reflow_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy);
 static void e_reflow_reflow (GnomeCanvasItem *item, gint flags);
 static void set_empty (EReflow *reflow);
 
@@ -1341,22 +1341,16 @@ e_reflow_update (GnomeCanvasItem *item, gdouble affine[6], ArtSVP *clip_path, gi
 	}
 }
 
-static double
+static GnomeCanvasItem *
 e_reflow_point (GnomeCanvasItem *item,
-		gdouble x, gdouble y, gint cx, gint cy,
-		GnomeCanvasItem **actual_item)
+		gdouble x, gdouble y, gint cx, gint cy)
 {
-	gdouble distance = 1;
-
-	*actual_item = NULL;
+        GnomeCanvasItem *child;
 
 	if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->point)
-		distance = GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->point (item, x, y, cx, cy, actual_item);
-	if ((gint) (distance * item->canvas->pixels_per_unit + 0.5) <= 0 && *actual_item)
-		return distance;
+		child = GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->point (item, x, y, cx, cy);
 
-	*actual_item = item;
-	return 0;
+	return child ? child : item;
 #if 0
 	if (y >= E_REFLOW_BORDER_WIDTH && y <= reflow->height - E_REFLOW_BORDER_WIDTH) {
 		gfloat n_x;
diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c
index 9d9a113..14c7eaa 100644
--- a/widgets/text/e-text.c
+++ b/widgets/text/e-text.c
@@ -1674,9 +1674,9 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 }
 
 /* Point handler for the text item */
-static double
+static GnomeCanvasItem *
 e_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
-	      gint cx, gint cy, GnomeCanvasItem **actual_item)
+	      gint cx, gint cy)
 {
 	EText *text;
 	gdouble clip_width;
@@ -1684,8 +1684,6 @@ e_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 
 	text = E_TEXT (item);
 
-	*actual_item = item;
-
 	/* The idea is to build bounding rectangles for each of the lines of
 	 * text (clipped by the clipping rectangle, if it is activated) and see
 	 * whether the point is inside any of these.  If it is, we are done.
@@ -1710,17 +1708,17 @@ e_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 	    cx > text->clip_cx + clip_width ||
 	    cy < text->clip_cy ||
 	    cy > text->clip_cy + clip_height)
-		return 1;
+		return NULL;
 
 	if (text->fill_clip_rectangle || !text->text || !*text->text)
-		return 0;
+		return item;
 
 	cx -= text->cx;
 
 	if (pango_layout_xy_to_index (text->layout, cx, cy, NULL, NULL))
-		return 0;
+		return item;
 
-	return 1;
+	return NULL;
 }
 
 /* Bounds handler for the text item */



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