goocanvas r43 - in trunk: . demo src



Author: damon
Date: Sun Mar 15 16:57:10 2009
New Revision: 43
URL: http://svn.gnome.org/viewvc/goocanvas?rev=43&view=rev

Log:

2009-03-15  Damon Chaplin  <damon gnome org>

	    * Released GooCanvas 0.14

2009-03-15  Damon Chaplin  <damon gnome org>

	    * src/goocanvas.c (goo_canvas_query_tooltip): new function to propagate the "query-tooltip"
	    signal up through the canvas items.

	    * src/goocanvasitem.[hc]: added "query-tooltip" signal and "tooltip" property.
	    * src/goocanvasitemmodel.c: added "tooltip" property.

	    * src/goocanvasitemsimple.c: added "tooltip" property and query_tooltip signal handler.

	    * configure.in: added dependancy on GTK+ 2.12 for tooltips.

	    * demo/mv-demo.c: 
	    * demo/demo.c: added tests for tooltips.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/README
   trunk/TODO
   trunk/configure.in
   trunk/demo/demo.c
   trunk/demo/mv-demo.c
   trunk/src/goocanvas.c
   trunk/src/goocanvasitem.c
   trunk/src/goocanvasitem.h
   trunk/src/goocanvasitemmodel.c
   trunk/src/goocanvasitemsimple.c
   trunk/src/goocanvasitemsimple.h
   trunk/src/goocanvasmarshal.list

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sun Mar 15 16:57:10 2009
@@ -1,4 +1,16 @@
 
+GooCanvas 0.14	(Mar 15 2009)
+==============
+
+ o Added support for tooltips (this means we need GTK+ 2.12).
+   (Note that there is a GTK+ bug which will cause problems with
+   tooltips on a large canvas. See bug #573294.)
+ o Added "x", "y", "width" and "height" properties to items that
+   didn't have them.
+ o Fixed bug in goo_canvas_convert_from_item_space().
+ o Added "scroll-event" signal to GooCanvasItem.
+
+
 GooCanvas 0.13	(Nov 30 2008)
 ==============
 

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Sun Mar 15 16:57:10 2009
@@ -43,6 +43,7 @@
  o Scrolling.
  o Zooming.
  o Static items that don't move as the canvas is scrolled or zoomed.
+ o Tooltips.
  o Item visibility setting - on/off/above zoom threshold.
  o Simple animation.
  o Scalable - support for thousands of items over a large canvas area.

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Sun Mar 15 16:57:10 2009
@@ -19,7 +19,6 @@
 
  o API for modifying GooCanvasPath data.
  o Editable text item - a port of GtkTextView.
- o Tooltips - I have code to support tooltips using the new API in GTK+ 2.12.
 
  o Need a function to setup a given cairo context with the defaults settings
    of a GooCanvas, e.g. default line width.

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Sun Mar 15 16:57:10 2009
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 
-AC_INIT(goocanvas, 0.13)
+AC_INIT(goocanvas, 0.14)
 AC_PREREQ(2.50)
 AC_CONFIG_SRCDIR(src/goocanvas.c)
 AC_CONFIG_HEADERS(config.h)
@@ -12,8 +12,8 @@
 # If interfaces changed but it is backwards compatible: AGE++, else AGE=0.
 #  i.e. the library supports interfaces CURRENT - AGE up to CURRENT.
 #  if two libraries have identical CURRENT and AGE, then newest REVISION used.
-CURRENT=5
-AGE=2
+CURRENT=6
+AGE=3
 REVISION=0
 
 LT_VERSION_INFO="$CURRENT:$REVISION:$AGE"
@@ -26,7 +26,7 @@
 AC_HEADER_STDC
 AM_PROG_LIBTOOL
 
-pkg_modules="gtk+-2.0 >= 2.10.0 glib-2.0 >= 2.10.0 cairo >= 1.4.0"
+pkg_modules="gtk+-2.0 >= 2.12.0 glib-2.0 >= 2.10.0 cairo >= 1.4.0"
 PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
 AC_SUBST(PACKAGE_CFLAGS)
 AC_SUBST(PACKAGE_LIBS)

Modified: trunk/demo/demo.c
==============================================================================
--- trunk/demo/demo.c	(original)
+++ trunk/demo/demo.c	Sun Mar 15 16:57:10 2009
@@ -491,6 +491,7 @@
 		      "bounds-from-origin", FALSE,
 		      "bounds-padding", 4.0,
 		      "background-color-rgb", 0xC3C3FF,
+ 		      "has-tooltip", TRUE,
 #if 0
 		      "redraw-when-scrolled", TRUE,
 #endif
@@ -852,6 +853,7 @@
   item = goo_canvas_rect_new (root, 20, 30, 50, 30,
 			      "stroke-color", "red",
 			      "line-width", 8.0,
+			      "tooltip", "Red stroked rectangle",
 			      NULL);
   setup_item_signals (item);
 
@@ -860,6 +862,7 @@
 			      "fill-pattern", pattern,
 			      "stroke-color", "black",
 			      "line-width", 4.0,
+			      "tooltip", "Medium Sea Green stippled rectangle",
 			      NULL);
   cairo_pattern_destroy (pattern);
   setup_item_signals (item);
@@ -867,6 +870,7 @@
   item = goo_canvas_rect_new (root, 10, 80, 70, 60,
 			      "fill-color", "steelblue",
 			      /*"fill-pattern", NULL,*/
+			      "tooltip", "Steel Blue rectangle",
 			      NULL);
   setup_item_signals (item);
 
@@ -874,6 +878,7 @@
 			      "fill-color-rgba", 0x3cb37180,
 			      "stroke-color", "blue",
 			      "line-width", 2.0,
+			      "tooltip", "Partially transparent rectangle",
 			      NULL);
   setup_item_signals (item);
 
@@ -882,11 +887,13 @@
 			      "radius-y", 10.0,
 			      "stroke-color", "yellow",
 			      "fill-color-rgba", 0x3cb3f180,
+			      "tooltip", "Rectangle with rounded corners",
 			      NULL);
   setup_item_signals (item);
 
   item = goo_demo_item_new (root, 30, 20, 50, 30,
 			    "fill-color", "yellow",
+			    "tooltip", "Yellow demo item",
 			    NULL);
   setup_item_signals (item);
 }

Modified: trunk/demo/mv-demo.c
==============================================================================
--- trunk/demo/mv-demo.c	(original)
+++ trunk/demo/mv-demo.c	Sun Mar 15 16:57:10 2009
@@ -415,6 +415,7 @@
 		      "bounds-from-origin", FALSE,
 		      "bounds-padding", 4.0,
 		      "background-color-rgb", 0xC3C3FF,
+ 		      "has-tooltip", TRUE,
 #if 0
 		      "redraw-when-scrolled", TRUE,
 #endif
@@ -746,6 +747,7 @@
   item = goo_canvas_rect_model_new (root, 20, 30, 50, 30,
 				    "stroke-color", "red",
 				    "line-width", 8.0,
+				    "tooltip", "Red stroked rectangle",
 				    NULL);
 
   pattern = create_stipple ("mediumseagreen", stipple_data);
@@ -753,17 +755,21 @@
 				    "fill-pattern", pattern,
 				    "stroke-color", "black",
 				    "line-width", 4.0,
+				    "tooltip", "Medium Sea Green stippled rectangle",
 				    NULL);
   cairo_pattern_destroy (pattern);
 
   item = goo_canvas_rect_model_new (root, 10, 80, 70, 60,
 				    "fill-color", "steelblue",
+				    /*"fill-pattern", NULL,*/
+				    "tooltip", "Steel Blue rectangle",
 				    NULL);
 
   item = goo_canvas_rect_model_new (root, 20, 90, 70, 60,
 				    "fill-color-rgba", 0x3cb37180,
 				    "stroke-color", "blue",
 				    "line-width", 2.0,
+				    "tooltip", "Partially transparent rectangle",
 				    NULL);
 
   item = goo_canvas_rect_model_new (root, 110, 80, 50, 30,
@@ -771,6 +777,7 @@
 				    "radius-y", 10.0,
 				    "stroke-color", "yellow",
 				    "fill-color-rgba", 0x3cb3f180,
+				    "tooltip", "Rectangle with rounded corners",
 				    NULL);
 }
 

Modified: trunk/src/goocanvas.c
==============================================================================
--- trunk/src/goocanvas.c	(original)
+++ trunk/src/goocanvas.c	Sun Mar 15 16:57:10 2009
@@ -201,6 +201,11 @@
 					    gboolean          include_internals,
 					    GtkCallback       callback,
 					    gpointer          callback_data);
+static gboolean goo_canvas_query_tooltip   (GtkWidget	     *widget,
+					    gint              x,
+					    gint              y,
+					    gboolean          keyboard_tip,
+					    GtkTooltip       *tooltip);
 
 static void	goo_canvas_set_scale_internal (GooCanvas     *canvas,
 					       gdouble        scale_x,
@@ -259,6 +264,7 @@
   widget_class->focus_in_event       = goo_canvas_focus_in;
   widget_class->focus_out_event      = goo_canvas_focus_out;
   widget_class->grab_broken_event    = goo_canvas_grab_broken;
+  widget_class->query_tooltip	     = goo_canvas_query_tooltip;
 
   container_class->remove	     = goo_canvas_remove;
   container_class->forall            = goo_canvas_forall;
@@ -4317,3 +4323,49 @@
 	}
     }
 }
+
+
+static gboolean
+goo_canvas_query_tooltip (GtkWidget  *widget,
+			  gint        x,
+			  gint        y,
+			  gboolean    keyboard_tip,
+			  GtkTooltip *tooltip)
+{
+  GooCanvas *canvas = (GooCanvas*) widget;
+  GooCanvasItem *item = canvas->pointer_item, *parent;
+  gdouble item_x = x, item_y = y;
+  gboolean tip_set = FALSE, has_transform;
+  cairo_matrix_t transform;
+
+  if (!item)
+    return FALSE;
+
+  /* Convert from pixels to the item's coordinate space. */
+  goo_canvas_convert_from_pixels (canvas, &item_x, &item_y);
+  goo_canvas_convert_to_item_space (canvas, item, &item_x, &item_y);
+
+  for (;;)
+    {
+      g_signal_emit_by_name (item, "query-tooltip", item_x, item_y,
+			     keyboard_tip, tooltip, &tip_set);
+      if (tip_set)
+	return TRUE;
+
+      parent = goo_canvas_item_get_parent (item);
+      if (!parent)
+	break;
+
+      /* Convert x & y to the parent's coordinate space. */
+      has_transform = goo_canvas_item_get_transform_for_child (parent, item,
+							       &transform);
+      if (has_transform)
+	cairo_matrix_transform_point (&transform, &item_x, &item_y);
+
+      item = parent;
+    }
+
+  /* We call the parent method in case the canvas itself has a tooltip set. */
+  return GTK_WIDGET_CLASS (goo_canvas_parent_class)->query_tooltip (widget, x, y, keyboard_tip, tooltip);
+}
+

Modified: trunk/src/goocanvasitem.c
==============================================================================
--- trunk/src/goocanvasitem.c	(original)
+++ trunk/src/goocanvasitem.c	Sun Mar 15 16:57:10 2009
@@ -49,6 +49,7 @@
   CHILD_NOTIFY,
   ANIMATION_FINISHED,
   SCROLL_EVENT,
+  QUERY_TOOLTIP,
 
   LAST_SIGNAL
 };
@@ -337,6 +338,37 @@
 		      GOO_TYPE_CANVAS_ITEM,
 		      GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
 
+      /**
+       * GooCanvasItem::query-tooltip:
+       * @item: the item which received the signal.
+       * @x: the x coordinate of the mouse.
+       * @y: the y coordinate of the mouse.
+       * @keyboard_mode: %TRUE if the tooltip was triggered using the keyboard.
+       * @tooltip: a #GtkTooltip.
+       *
+       * Emitted when the mouse has paused over the item for a certain amount
+       * of time, or the tooltip was requested via the keyboard.
+       *
+       * Note that if @keyboard_mode is %TRUE, the values of @x and @y are
+       * undefined and should not be used.
+       *
+       * If the item wants to display a tooltip it should update @tooltip
+       * and return %TRUE.
+       *
+       * Returns: %TRUE if the item has set a tooltip to show.
+       */
+      canvas_item_signals[QUERY_TOOLTIP] =
+	g_signal_new ("query-tooltip",
+		      iface_type,
+		      G_SIGNAL_RUN_LAST,
+		      G_STRUCT_OFFSET (GooCanvasItemIface, query_tooltip),
+		      goo_canvas_boolean_handled_accumulator, NULL,
+		      goo_canvas_marshal_BOOLEAN__DOUBLE_DOUBLE_BOOLEAN_OBJECT,
+		      G_TYPE_BOOLEAN, 4,
+		      G_TYPE_DOUBLE,
+		      G_TYPE_DOUBLE,
+		      G_TYPE_BOOLEAN,
+		      GTK_TYPE_TOOLTIP);
 
       /**
        * GooCanvasItem::grab-broken-event
@@ -484,6 +516,13 @@
 								 FALSE,
 								 G_PARAM_READWRITE));
 
+      g_object_interface_install_property (g_iface,
+					   g_param_spec_string ("tooltip",
+								_("Tooltip"),
+								_("The tooltip to display for the item"),
+								NULL,
+								G_PARAM_READWRITE));
+
       _goo_canvas_style_init ();
 
       initialized = TRUE;

Modified: trunk/src/goocanvasitem.h
==============================================================================
--- trunk/src/goocanvasitem.h	(original)
+++ trunk/src/goocanvasitem.h	Sun Mar 15 16:57:10 2009
@@ -127,6 +127,7 @@
  * @key_release_event: signal emitted when a key is released.
  * @grab_broken_event: signal emitted when a grab that the item has is lost.
  * @child_notify: signal emitted when a child property is changed.
+ * @query_tooltip: signal emitted to query the tooltip of an item.
  * @animation_finished: signal emitted when the item's animation has finished.
  * @scroll_event: signal emitted when the mouse wheel is activated within
  * the item.
@@ -274,18 +275,11 @@
 							 GdkEventGrabBroken	*event);
   void			(* child_notify)		(GooCanvasItem		*item,
 							 GParamSpec		*pspec);
-
-  /*< private >*/
-
-  /* We might use this in future to support tooltips. */
   gboolean		(* query_tooltip)		(GooCanvasItem		*item,
 							 gdouble		 x,
 							 gdouble		 y,
 							 gboolean		 keyboard_tooltip,
-							 gpointer /*GtkTooltip*/		*tooltip);
-
-
-  /*< public >*/
+							 GtkTooltip		*tooltip);
 
   gboolean		(* get_is_static)		(GooCanvasItem		*item);
   void			(* set_is_static)		(GooCanvasItem		*item,

Modified: trunk/src/goocanvasitemmodel.c
==============================================================================
--- trunk/src/goocanvasitemmodel.c	(original)
+++ trunk/src/goocanvasitemmodel.c	Sun Mar 15 16:57:10 2009
@@ -274,6 +274,13 @@
 								 FALSE,
 								 G_PARAM_READWRITE));
 
+      g_object_interface_install_property (g_iface,
+					   g_param_spec_string ("tooltip",
+								_("Tooltip"),
+								_("The tooltip to display for the item"),
+								NULL,
+								G_PARAM_READWRITE));
+
       _goo_canvas_style_init ();
 
       initialized = TRUE;

Modified: trunk/src/goocanvasitemsimple.c
==============================================================================
--- trunk/src/goocanvasitemsimple.c	(original)
+++ trunk/src/goocanvasitemsimple.c	Sun Mar 15 16:57:10 2009
@@ -79,7 +79,8 @@
   PROP_DESCRIPTION,
   PROP_CAN_FOCUS,
   PROP_CLIP_PATH,
-  PROP_CLIP_FILL_RULE
+  PROP_CLIP_FILL_RULE,
+  PROP_TOOLTIP
 };
 
 static gboolean accessibility_enabled = FALSE;
@@ -287,6 +288,9 @@
   g_object_class_override_property (gobject_class, PROP_CAN_FOCUS,
 				    "can-focus");
 
+  g_object_class_override_property (gobject_class, PROP_TOOLTIP,
+				    "tooltip");
+
   /**
    * GooCanvasItemSimple:clip-path
    *
@@ -545,6 +549,9 @@
     case PROP_CLIP_FILL_RULE:
       g_value_set_enum (value, simple_data->clip_fill_rule);
       break;
+    case PROP_TOOLTIP:
+      g_value_set_string (value, simple_data->tooltip);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -734,6 +741,9 @@
       simple_data->clip_fill_rule = g_value_get_enum (value);
       recompute_bounds = TRUE;
       break;
+    case PROP_TOOLTIP:
+      simple_data->tooltip = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1486,6 +1496,26 @@
 }
 
 
+static gboolean
+goo_canvas_item_simple_query_tooltip (GooCanvasItem  *item,
+				      gdouble         x,
+				      gdouble         y,
+				      gboolean        keyboard_tip,
+				      GtkTooltip     *tooltip)
+{
+  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
+  GooCanvasItemSimpleData *simple_data = simple->simple_data;
+
+  if (simple_data->tooltip)
+    {
+      gtk_tooltip_set_markup (tooltip, simple_data->tooltip);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+
 static void
 canvas_item_interface_init (GooCanvasItemIface *iface)
 {
@@ -1511,6 +1541,8 @@
 
   iface->get_model          = goo_canvas_item_simple_get_model;
   iface->set_model          = goo_canvas_item_simple_set_model_internal;
+
+  iface->query_tooltip	    = goo_canvas_item_simple_query_tooltip;
 }
 
 

Modified: trunk/src/goocanvasitemsimple.h
==============================================================================
--- trunk/src/goocanvasitemsimple.h	(original)
+++ trunk/src/goocanvasitemsimple.h	Sun Mar 15 16:57:10 2009
@@ -22,6 +22,7 @@
  * @transform: the transformation matrix of the item, or %NULL.
  * @clip_path_commands: an array of #GooCanvasPathCommand specifying the clip
  *  path of the item, or %NULL.
+ * @tooltip: the item's tooltip.
  * @visibility_threshold: the threshold scale setting at which to show the item
  *  (if the @visibility setting is set to %VISIBLE_ABOVE_THRESHOLD).
  * @visibility: the #GooCanvasItemVisibility setting specifying whether the
@@ -42,9 +43,6 @@
   GooCanvasStyle *style;
   cairo_matrix_t *transform;
   GArray *clip_path_commands;
-
-  /*< private >*/
-  /* We will store tooltips here in future. */
   gchar *tooltip;
 
   /*< public >*/

Modified: trunk/src/goocanvasmarshal.list
==============================================================================
--- trunk/src/goocanvasmarshal.list	(original)
+++ trunk/src/goocanvasmarshal.list	Sun Mar 15 16:57:10 2009
@@ -5,3 +5,4 @@
 VOID:OBJECT,OBJECT
 BOOLEAN:BOXED
 BOOLEAN:OBJECT,BOXED
+BOOLEAN:DOUBLE,DOUBLE,BOOLEAN,OBJECT



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