[goffice] Make event always accessible.



commit d4d1781ce87372afc9590f497cf8221066746bc0
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Mar 17 15:47:11 2010 +0100

    Make event always accessible.

 ChangeLog                   |    8 ++++++++
 goffice/canvas/goc-canvas.c |   26 ++++++++++++++------------
 goffice/canvas/goc-item.c   |   18 ++++++++++++++++++
 3 files changed, 40 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3d0f6a3..d71217f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-03-17  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/canvas/goc-canvas.c (key_release_cb), (key_press_cb),
+	(enter_notify_cb), (leave_notify_cb), (goc_canvas_init): ensure that the
+	GdkEvent can always be accessed if needed.
+	* goffice/canvas/goc-item.c (goc_item_key_pressed),
+	(goc_item_key_released), (goc_item_class_init): ditto.
+
 2010-03-10  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/canvas/goc-polyline.c (goc_polyline_prepare_draw): don't zoom
diff --git a/goffice/canvas/goc-canvas.c b/goffice/canvas/goc-canvas.c
index f6bbb70..91b2ddf 100644
--- a/goffice/canvas/goc-canvas.c
+++ b/goffice/canvas/goc-canvas.c
@@ -156,21 +156,18 @@ motion_cb (GocCanvas *canvas, GdkEventMotion *event, G_GNUC_UNUSED gpointer data
 	return result;
 }
 
-static void
-destroy_cb (GocCanvas *canvas, G_GNUC_UNUSED gpointer data)
-{
-}
-
 static gboolean
 key_release_cb (GocCanvas *canvas, GdkEventKey* event, G_GNUC_UNUSED gpointer data)
 {
-	return FALSE;
+	return (canvas->grabbed_item != NULL)?
+		GOC_ITEM_GET_CLASS (canvas->grabbed_item)->key_released (canvas->grabbed_item, event): FALSE;
 }
 
 static gboolean
 key_press_cb (GocCanvas *canvas, GdkEventKey* event, G_GNUC_UNUSED gpointer data)
 {
-	return FALSE;
+	return (canvas->grabbed_item != NULL)?
+		GOC_ITEM_GET_CLASS (canvas->grabbed_item)->key_pressed (canvas->grabbed_item, event): FALSE;
 }
 
 static gboolean
@@ -178,6 +175,7 @@ enter_notify_cb (GocCanvas *canvas, GdkEventCrossing* event, G_GNUC_UNUSED gpoin
 {
 	double x, y;
 	GocItem *item;
+	gboolean result = FALSE;
 
 	if (event->window != gtk_layout_get_bin_window (&canvas->base))
 		return TRUE;
@@ -187,16 +185,19 @@ enter_notify_cb (GocCanvas *canvas, GdkEventCrossing* event, G_GNUC_UNUSED gpoin
 	y = canvas->scroll_y1 + event->y / canvas->pixels_per_unit;
 	item = goc_canvas_get_item_at (canvas, x, y);;
 	if (item) {
+		canvas->cur_event = (GdkEvent *) event;
 		canvas->last_item = item;
-		return GOC_ITEM_GET_CLASS (item)->enter_notify (item, x, y);
+		result = GOC_ITEM_GET_CLASS (item)->enter_notify (item, x, y);
 	}
-	return FALSE;
+	canvas->cur_event = NULL;
+	return result;
 }
 
 static gboolean
 leave_notify_cb (GocCanvas *canvas, GdkEventCrossing* event, G_GNUC_UNUSED gpointer data)
 {
 	double x, y;
+	gboolean result = FALSE;
 
 	if (event->window != gtk_layout_get_bin_window (&canvas->base))
 		return TRUE;
@@ -205,11 +206,13 @@ leave_notify_cb (GocCanvas *canvas, GdkEventCrossing* event, G_GNUC_UNUSED gpoin
 		canvas->scroll_x1 +  event->x / canvas->pixels_per_unit;
 	y = canvas->scroll_y1 + event->y / canvas->pixels_per_unit;
 	if (canvas->last_item) {
-		gboolean result = GOC_ITEM_GET_CLASS (canvas->last_item)->leave_notify (canvas->last_item, x, y);
+		canvas->cur_event = (GdkEvent *) event;
+		result = GOC_ITEM_GET_CLASS (canvas->last_item)->leave_notify (canvas->last_item, x, y);
 		canvas->last_item = NULL;
 		return result;
 	}
-	return FALSE;
+	canvas->cur_event = NULL;
+	return result;
 }
 
 static void
@@ -278,7 +281,6 @@ goc_canvas_init (GocCanvas *canvas)
 	g_signal_connect (G_OBJECT (w), "button-press-event", G_CALLBACK (button_press_cb), NULL);
 	g_signal_connect (G_OBJECT (w), "button-release-event", G_CALLBACK (button_release_cb), NULL);
 	g_signal_connect (G_OBJECT (w), "motion-notify-event", G_CALLBACK (motion_cb), NULL);
-	g_signal_connect (G_OBJECT (w), "destroy", G_CALLBACK (destroy_cb), NULL);
 	g_signal_connect (G_OBJECT (w), "expose-event", G_CALLBACK (expose_cb), NULL);
 	g_signal_connect (G_OBJECT (w), "key_press_event", (GCallback) key_press_cb, NULL);
 	g_signal_connect (G_OBJECT (w), "key_release_event", (GCallback) key_release_cb, NULL);
diff --git a/goffice/canvas/goc-item.c b/goffice/canvas/goc-item.c
index 87beb32..9e31c93 100644
--- a/goffice/canvas/goc-item.c
+++ b/goffice/canvas/goc-item.c
@@ -163,6 +163,22 @@ goc_item_leave_notify (GocItem *item, double x, double y)
 		FALSE;
 }
 
+static gboolean
+goc_item_key_pressed (GocItem *item, GdkEventKey* ev)
+{
+	return (item->parent)?
+		GOC_ITEM_GET_CLASS (item->parent)->key_pressed (GOC_ITEM (item->parent), ev):
+		FALSE;
+}
+
+static gboolean
+goc_item_key_released (GocItem *item, GdkEventKey* ev)
+{
+	return (item->parent)?
+		GOC_ITEM_GET_CLASS (item->parent)->key_released (GOC_ITEM (item->parent), ev):
+		FALSE;
+}
+
 static void
 goc_item_realize (GocItem *item)
 {
@@ -256,6 +272,8 @@ goc_item_class_init (GocItemClass *item_klass)
 	item_klass->motion = goc_item_motion;
 	item_klass->enter_notify = goc_item_enter_notify;
 	item_klass->leave_notify = goc_item_leave_notify;
+	item_klass->key_pressed = goc_item_key_pressed;
+	item_klass->key_released = goc_item_key_released;
 }
 
 static void



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