It seems that hit detection for gnome canvas text items only works when the anchor is north-west. I am attaching a demo that creates a text items for each possible anchor and configures them to turn blue when the pointer is over them. A little mouse wiggling determines that the sensitive parts of the text widgets are: all of "North-West" (as it should be), the right half of "North", the bottom half of "West" and the bottom-right quarter of "Center". The other five text items are only sensitive along certain parts of their borders. Unless I am missing something this surely cannot be right. Details: gtk+-2.2.4 libart_lgpl_2.3.16 libgnomecanvas-2.4.0 Regards, Jeremy
#include <stdio.h> #include <gtk/gtk.h> #include <libgnomecanvas/libgnomecanvas.h> static void window_initialize(GtkWidget*); static void canvas_initialize(GtkWidget*); int main(int argc,char **argv) { GtkWidget *window, *canvas; gtk_init(&argc,&argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window_initialize(window); canvas = gnome_canvas_new(); canvas_initialize(canvas); gtk_container_add(GTK_CONTAINER(window),canvas); gtk_widget_show_all(window); gtk_main(); return 0; } static void window_destroy_handler(void) { gtk_main_quit(); } static void window_initialize(GtkWidget* window) { gtk_window_set_title(GTK_WINDOW(window),"Hot Text"); g_signal_connect(window,"destroy",window_destroy_handler,(gpointer)NULL); } #define CANVAS_ITEM_COUNT 9 typedef struct { const char *text; double y; double x; GtkAnchorType anchor; } canvas_item_spec_t; static const canvas_item_spec_t canvas_item_specs[]; static void canvas_item_event_handler(GnomeCanvasItem *text_item, GdkEvent *event, const char *text ) { printf("text: %s\n",text); switch (event->type) { case GDK_LEAVE_NOTIFY: g_object_set(text_item, "fill_color","black", 0); break; case GDK_ENTER_NOTIFY: g_object_set(text_item, "fill_color","blue", 0); break; default: break; } } static void canvas_initialize(GtkWidget* canvas) { GnomeCanvasGroup *canvas_root; int i; canvas_root = gnome_canvas_root(GNOME_CANVAS(canvas)); for (i=0;i<CANVAS_ITEM_COUNT;i++) { GnomeCanvasItem *text_item; const canvas_item_spec_t *canvas_item_spec; canvas_item_spec = &canvas_item_specs[i]; text_item = gnome_canvas_item_new(canvas_root, GNOME_TYPE_CANVAS_TEXT, "font", "Sans 20", "fill_color", "black", "text", canvas_item_spec->text, "x", canvas_item_spec->x, "y", canvas_item_spec->y, "anchor", canvas_item_spec->anchor, 0); g_signal_connect(G_OBJECT(text_item),"event", G_CALLBACK(canvas_item_event_handler), (gpointer)(canvas_item_spec->text) ); } } #define west (0.0) #define middle (200.0) #define east (400.0) #define north (0.0) #define center (50.0) #define south (100.0) static const canvas_item_spec_t canvas_item_specs[CANVAS_ITEM_COUNT] = { { "South-East", south, east, GTK_ANCHOR_SE, }, { "South", south, middle, GTK_ANCHOR_S, }, { "South-West", south, west, GTK_ANCHOR_SW, }, { "East", center, east, GTK_ANCHOR_E , }, { "Center", center, middle, GTK_ANCHOR_CENTER, }, { "West", center, west, GTK_ANCHOR_W, }, { "North-East", north, east, GTK_ANCHOR_NE, }, { "North", north, middle, GTK_ANCHOR_N, }, { "North-West", north, west, GTK_ANCHOR_NW, }, };