@@ -73,6 +73,7 @@ struct _BaobabChartPrivate
7373 GList * first_item ;
7474 GList * last_item ;
7575 GList * highlighted_item ;
76+ GList * tooltip_item ;
7677};
7778
7879/* Signals */
@@ -153,6 +154,8 @@ static gint baobab_chart_scroll (GtkWidget *widget,
153154 GdkEventScroll * event );
154155static gint baobab_chart_motion_notify (GtkWidget * widget ,
155156 GdkEventMotion * event );
157+ static gint baobab_chart_enter_notify (GtkWidget * widget ,
158+ GdkEventCrossing * event );
156159static gint baobab_chart_leave_notify (GtkWidget * widget ,
157160 GdkEventCrossing * event );
158161static inline void baobab_chart_disconnect_signals (GtkWidget * chart ,
@@ -257,6 +260,7 @@ baobab_chart_init (BaobabChart *chart)
257260 priv -> first_item = NULL ;
258261 priv -> last_item = NULL ;
259262 priv -> highlighted_item = NULL ;
263+ priv -> tooltip_item = NULL ;
260264}
261265
262266static void
@@ -325,7 +329,7 @@ baobab_chart_realize (GtkWidget *widget)
325329 GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
326330 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
327331 GDK_POINTER_MOTION_HINT_MASK | GDK_LEAVE_NOTIFY_MASK |
328- GDK_SCROLL_MASK );
332+ GDK_ENTER_NOTIFY_MASK | GDK_SCROLL_MASK );
329333}
330334
331335static void
@@ -997,9 +1001,10 @@ baobab_chart_set_item_highlight (GtkWidget *chart,
9971001 & item -> rect , TRUE);
9981002}
9991003
1000- static gint
1001- baobab_chart_motion_notify (GtkWidget * widget ,
1002- GdkEventMotion * event )
1004+ static void
1005+ baobab_chart_highlight_item_at_position (GtkWidget * widget ,
1006+ gint x ,
1007+ gint y )
10031008{
10041009 BaobabChartPrivate * priv ;
10051010 BaobabChartClass * class ;
@@ -1016,7 +1021,7 @@ baobab_chart_motion_notify (GtkWidget *widget,
10161021 {
10171022 item = (BaobabChartItem * ) node -> data ;
10181023
1019- if ((item -> visible ) && (class -> is_point_over_item (widget , item , event -> x , event -> y )))
1024+ if ((item -> visible ) && (class -> is_point_over_item (widget , item , x , y )))
10201025 {
10211026 if (priv -> highlighted_item != node )
10221027 {
@@ -1039,6 +1044,20 @@ baobab_chart_motion_notify (GtkWidget *widget,
10391044 baobab_chart_set_item_highlight (widget , priv -> highlighted_item , FALSE);
10401045 gtk_widget_set_has_tooltip (widget , FALSE);
10411046 }
1047+ }
1048+
1049+ static gint
1050+ baobab_chart_motion_notify (GtkWidget * widget ,
1051+ GdkEventMotion * event )
1052+ {
1053+ BaobabChartPrivate * priv ;
1054+
1055+ /* Highlight any item the pointer is over */
1056+ baobab_chart_highlight_item_at_position (widget , event -> x , event -> y );
1057+
1058+ /* Set the tooltip item to the highlighted item, if any */
1059+ priv = BAOBAB_CHART (widget )-> priv ;
1060+ priv -> tooltip_item = priv -> highlighted_item ;
10421061
10431062 /* Continue receiving motion notifies */
10441063 gdk_event_request_motions (event );
@@ -1058,6 +1077,22 @@ baobab_chart_leave_notify (GtkWidget *widget,
10581077 return FALSE;
10591078}
10601079
1080+ static gint
1081+ baobab_chart_enter_notify (GtkWidget * widget ,
1082+ GdkEventCrossing * event )
1083+ {
1084+ BaobabChartPrivate * priv ;
1085+
1086+ /* Highlight any item the pointer is over */
1087+ baobab_chart_highlight_item_at_position (widget , event -> x , event -> y );
1088+
1089+ /* Set the tooltip item to the highlighted item, if any */
1090+ priv = BAOBAB_CHART (widget )-> priv ;
1091+ priv -> tooltip_item = priv -> highlighted_item ;
1092+
1093+ return FALSE;
1094+ }
1095+
10611096static inline void
10621097baobab_chart_connect_signals (GtkWidget * chart ,
10631098 GtkTreeModel * model )
@@ -1094,6 +1129,10 @@ baobab_chart_connect_signals (GtkWidget *chart,
10941129 "leave-notify-event" ,
10951130 G_CALLBACK (baobab_chart_leave_notify ),
10961131 chart );
1132+ g_signal_connect (chart ,
1133+ "enter-notify-event" ,
1134+ G_CALLBACK (baobab_chart_enter_notify ),
1135+ chart );
10971136 g_signal_connect (chart ,
10981137 "button-release-event" ,
10991138 G_CALLBACK (baobab_chart_button_release ),
@@ -1128,6 +1167,9 @@ baobab_chart_disconnect_signals (GtkWidget *chart,
11281167 g_signal_handlers_disconnect_by_func (chart ,
11291168 baobab_chart_leave_notify ,
11301169 chart );
1170+ g_signal_handlers_disconnect_by_func (chart ,
1171+ baobab_chart_enter_notify ,
1172+ chart );
11311173 g_signal_handlers_disconnect_by_func (chart ,
11321174 baobab_chart_button_release ,
11331175 chart );
@@ -1147,10 +1189,10 @@ baobab_chart_query_tooltip (GtkWidget *widget,
11471189
11481190 priv = BAOBAB_CHART (widget )-> priv ;
11491191
1150- if (priv -> highlighted_item == NULL )
1192+ if (priv -> tooltip_item == NULL )
11511193 return FALSE;
11521194
1153- item = (BaobabChartItem * ) priv -> highlighted_item -> data ;
1195+ item = (BaobabChartItem * ) priv -> tooltip_item -> data ;
11541196
11551197 if ( (item -> name == NULL ) || (item -> size == NULL ) )
11561198 return FALSE;
0 commit comments