From 0be3cbafce5cf7e339a1733ffb3404a8aca2a761 Mon Sep 17 00:00:00 2001 From: "pavlov%netscape.com" Date: Tue, 15 Feb 2000 22:36:19 +0000 Subject: [PATCH] fix for bug 27734 r=saari --- widget/src/gtk/nsGtkEventHandler.cpp | 31 ++++++++++++++++++---------- widget/src/gtk/nsWidget.h | 6 ++++++ widget/src/gtk/nsWindow.cpp | 11 ++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/widget/src/gtk/nsGtkEventHandler.cpp b/widget/src/gtk/nsGtkEventHandler.cpp index 2a5c813b876b..752304e4b816 100644 --- a/widget/src/gtk/nsGtkEventHandler.cpp +++ b/widget/src/gtk/nsGtkEventHandler.cpp @@ -594,7 +594,7 @@ void handle_scrollbar_value_changed(GtkAdjustment *adj, gpointer p) #endif } -static gint composition_start(GdkEventKey *aEvent, nsWindow *aWin) +static gint composition_start(GdkEventKey *aEvent, nsWidget *aWin) { nsCompositionEvent compEvent; @@ -615,7 +615,7 @@ static gint composition_start(GdkEventKey *aEvent, nsWindow *aWin) return PR_TRUE; } -static gint composition_draw(GdkEventKey *aEvent, nsWindow *aWin) +static gint composition_draw(GdkEventKey *aEvent, nsWidget *aWin) { nsresult res= NS_OK; if (!aWin->mIMECompositionUniString) { @@ -669,7 +669,7 @@ static gint composition_draw(GdkEventKey *aEvent, nsWindow *aWin) return True; } -static gint composition_end(GdkEventKey *aEvent, nsWindow *aWin) +static gint composition_end(GdkEventKey *aEvent, nsWidget *aWin) { nsCompositionEvent compEvent; @@ -758,7 +758,10 @@ gint handle_key_release_event_for_text(GtkObject *w, GdkEventKey* event, gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) { nsKeyEvent kevent; - nsWindow* win = (nsWindow*)p; + nsWidget *win = (nsWidget*)p; + + if (win->focusWindow) + win = win->focusWindow; // work around for annoying things. if (event->keyval == GDK_Tab) @@ -774,12 +777,14 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) return PR_TRUE; NS_ADDREF(win); + // // First, dispatch the Key event as a virtual key down event + // but lie about where it came from and say it is from the + // window that currently has focus inside our app... // - InitKeyEvent(event, p, kevent, NS_KEY_DOWN); + InitKeyEvent(event, win, kevent, NS_KEY_DOWN); win->OnKey(kevent); - // @@ -793,16 +798,17 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) composition_draw(event, win); composition_end(event, win); } else { - InitKeyPressEvent(event,p, kevent); + InitKeyPressEvent(event, win, kevent); win->OnKey(kevent); } } else { // for Home/End/Up/Down/Left/Right/PageUp/PageDown key - InitKeyPressEvent(event,p, kevent); + InitKeyPressEvent(event, win, kevent); win->OnKey(kevent); } NS_RELEASE(win); + if (w) { gtk_signal_emit_stop_by_name (GTK_OBJECT(w), "key_press_event"); @@ -821,10 +827,13 @@ gint handle_key_release_event(GtkObject *w, GdkEventKey* event, gpointer p) || event->keyval == GDK_Control_R) return PR_TRUE; - nsKeyEvent kevent; - InitKeyEvent(event, p, kevent, NS_KEY_UP); + nsWidget *win = (nsWidget *)p; + if (win->focusWindow) + win = win->focusWindow; + + nsKeyEvent kevent; + InitKeyEvent(event, win, kevent, NS_KEY_UP); - nsWindow * win = (nsWindow *) p; NS_ADDREF(win); win->OnKey(kevent); NS_RELEASE(win); diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index d269edef453f..ddbb61d3a107 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -226,8 +226,14 @@ protected: // this is set when a given widget has the focus. PRBool mHasFocus; + + + // if anyone uses this for public access other than the key press/release code on the main window, i will kill you. pav +public: // this is the current GdkSuperWin with the focus static nsWidget *focusWindow; + +protected: // PRBool mIsDragDest; diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index 997fb46d92af..1ba4560f597f 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -1749,6 +1749,17 @@ NS_METHOD nsWindow::CreateNative(GtkObject *parentWidget) InstallToplevelDragMotionSignal(); InstallToplevelDragDropSignal(); InstallToplevelDragDataReceivedSignal(); + + AddToEventMask(mShell, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); + gtk_signal_connect(GTK_OBJECT(mShell), + "key_press_event", + GTK_SIGNAL_FUNC(handle_key_press_event), + this); + gtk_signal_connect(GTK_OBJECT(mShell), + "key_release_event", + GTK_SIGNAL_FUNC(handle_key_release_event), + this); + // set the shell window as a drop target gtk_drag_dest_set (mShell, (GtkDestDefaults)0,