From 4da8e00b62f24d65d8c97be5aea43e1a5dae3a37 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Sat, 24 Nov 2001 00:24:18 +0000 Subject: [PATCH] Handle events in windows other than widget->event_window properly. Fri Nov 23 19:22:50 2001 Owen Taylor * gtk/gtknotebook.c: Handle events in windows other than widget->event_window properly. (#65079, reported by Damon Chaplin) * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. --- ChangeLog | 10 ++++++- ChangeLog.pre-2-0 | 10 ++++++- ChangeLog.pre-2-10 | 10 ++++++- ChangeLog.pre-2-2 | 10 ++++++- ChangeLog.pre-2-4 | 10 ++++++- ChangeLog.pre-2-6 | 10 ++++++- ChangeLog.pre-2-8 | 10 ++++++- gdk/gdkevents.c | 2 +- gtk/gtknotebook.c | 70 ++++++++++++++++++++++++++++++++++++---------- 9 files changed, 120 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index d8e178ba0f..8f7e4d899d 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,7 +1,15 @@ +Fri Nov 23 19:22:50 2001 Owen Taylor + + * gtk/gtknotebook.c: Handle events in windows other + than widget->event_window properly. (#65079, reported + by Damon Chaplin) + + * gdk/gdkevents.c (gdk_event_get_coords): Fix x/y bug. + Fri Nov 23 18:57:46 2001 Owen Taylor * gtk/gtkmessagedialog.c (gtk_message_dialog_init): Align - the image at the top, #65020, request from Seth Nickell) + the image at the top. (#65020, request from Seth Nickell) Fri Nov 23 18:49:53 2001 Owen Taylor diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index 4b92195538..fce4dbcbe3 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -603,7 +603,7 @@ gdk_event_get_coords (GdkEvent *event, if (x_win) *x_win = x; if (y_win) - *y_win = x; + *y_win = y; return fetched; } diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index f9f08c2113..ae2ff72fc8 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -1315,8 +1315,8 @@ gtk_notebook_get_arrow (GtkNotebook *notebook, gtk_notebook_get_event_window_position (notebook, &event_window_pos); gtk_notebook_get_arrow_rect (notebook, &arrow_rect); - x -= arrow_rect.x - event_window_pos.x; - y -= arrow_rect.y - event_window_pos.y; + x -= arrow_rect.x; + y -= arrow_rect.y; if (y >= 0 && y < arrow_rect.height) { @@ -1380,6 +1380,40 @@ gtk_notebook_arrow_button_press (GtkNotebook *notebook, return TRUE; } +static gboolean +get_widget_coordinates (GtkWidget *widget, + GdkEvent *event, + gint *x, + gint *y) +{ + GdkWindow *window = ((GdkEventAny *)event)->window; + gdouble tx, ty; + + if (!gdk_event_get_coords (event, &tx, &ty)) + return FALSE; + + while (window && window != widget->window) + { + gint window_x, window_y; + + gdk_window_get_position (window, &window_x, &window_y); + tx += window_x; + ty += window_y; + + window = gdk_window_get_parent (window); + } + + if (window) + { + *x = tx; + *y = ty; + + return TRUE; + } + else + return FALSE; +} + static gboolean gtk_notebook_button_press (GtkWidget *widget, GdkEventButton *event) @@ -1388,7 +1422,6 @@ gtk_notebook_button_press (GtkWidget *widget, GtkNotebookPage *page; GList *children; GtkArrowType arrow; - GdkRectangle event_window_pos; gint num; gint x, y; @@ -1396,7 +1429,10 @@ gtk_notebook_button_press (GtkWidget *widget, notebook->button) return FALSE; - arrow = gtk_notebook_get_arrow (notebook, event->x, event->y); + if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y)) + return FALSE; + + arrow = gtk_notebook_get_arrow (notebook, x, y); if (arrow) return gtk_notebook_arrow_button_press (notebook, arrow, event); @@ -1407,12 +1443,6 @@ gtk_notebook_button_press (GtkWidget *widget, return TRUE; } - /* Translate coordinates from event_window to widget->window - */ - gtk_notebook_get_event_window_position (notebook, &event_window_pos); - x = event->x + event_window_pos.x; - y = event->y + event_window_pos.y; - num = 0; children = notebook->children; while (children) @@ -1496,13 +1526,17 @@ gtk_notebook_enter_notify (GtkWidget *widget, { GtkNotebook *notebook; GtkArrowType arrow; + gint x, y; g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); notebook = GTK_NOTEBOOK (widget); - arrow = gtk_notebook_get_arrow (notebook, event->x, event->y); + if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y)) + return FALSE; + + arrow = gtk_notebook_get_arrow (notebook, x, y); if (arrow != notebook->in_child) { @@ -1521,8 +1555,12 @@ gtk_notebook_leave_notify (GtkWidget *widget, { GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkArrowType arrow; + gint x, y; - arrow = gtk_notebook_get_arrow (notebook, event->x, event->y); + if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y)) + return FALSE; + + arrow = gtk_notebook_get_arrow (notebook, x, y); if (notebook->in_child) { @@ -1539,11 +1577,15 @@ gtk_notebook_motion_notify (GtkWidget *widget, { GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkArrowType arrow; - + gint x, y; + if (notebook->button) return FALSE; - arrow = gtk_notebook_get_arrow (notebook, event->x, event->y); + if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y)) + return FALSE; + + arrow = gtk_notebook_get_arrow (notebook, x, y); if (arrow != notebook->in_child) {