From f2ce98faf95a2bb3a3dedfe0625be945d524bef9 Mon Sep 17 00:00:00 2001 From: "ramiro%netscape.com" Date: Fri, 9 Jul 1999 11:15:59 +0000 Subject: [PATCH] Add some useful debuggin information. This change does not affect any functionality at all. Its just a rearranging of some code and adding debug stuff so that we can debug event related bugs. In particular (but not limited to) focus events. --- widget/src/gtk/nsGtkEventHandler.cpp | 56 ------- widget/src/gtk/nsGtkEventHandler.h | 7 - widget/src/gtk/nsWidget.cpp | 217 ++++++++++++++++++++++++--- widget/src/gtk/nsWidget.h | 20 ++- widget/src/gtk/nsWindow.cpp | 20 +-- widget/src/gtk/nsWindow.h | 1 - 6 files changed, 221 insertions(+), 100 deletions(-) diff --git a/widget/src/gtk/nsGtkEventHandler.cpp b/widget/src/gtk/nsGtkEventHandler.cpp index 88e398400f84..77993e0e0f9b 100644 --- a/widget/src/gtk/nsGtkEventHandler.cpp +++ b/widget/src/gtk/nsGtkEventHandler.cpp @@ -311,30 +311,6 @@ void UninitKeyEvent(GdkEventKey *aGEK, { } -//============================================================== -void InitFocusEvent(GdkEventFocus *aGEF, - gpointer p, - nsGUIEvent &anEvent, - PRUint32 aEventType) -{ - anEvent.message = aEventType; - anEvent.widget = (nsWidget *) p; - - anEvent.eventStructType = NS_GUI_EVENT; - - anEvent.time = 0; - anEvent.point.x = 0; - anEvent.point.y = 0; -} - -//============================================================== -void UninitFocusEvent(GdkEventFocus *aGEF, - gpointer p, - nsGUIEvent &anEvent, - PRUint32 aEventType) -{ -} - /*============================================================== ============================================================== ============================================================= @@ -442,38 +418,6 @@ gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p) return PR_TRUE; } -//============================================================== -gint handle_focus_in_event(GtkWidget *w, GdkEventFocus * event, gpointer p) -{ - nsWindow *win = (nsWindow *)p; - if (!win->IsDestroying()) { - nsGUIEvent gevent; - InitFocusEvent(event, p, gevent, NS_GOTFOCUS); - win->AddRef(); - win->DispatchFocus(gevent); - win->Release(); - UninitFocusEvent(event, p, gevent, NS_GOTFOCUS); - } - return PR_TRUE; -} - -//============================================================== -gint handle_focus_out_event(GtkWidget *w, GdkEventFocus * event, gpointer p) -{ - nsWindow *win = (nsWindow *)p; - if (!win->IsDestroying()) { - nsGUIEvent gevent; - InitFocusEvent(event, p, gevent, NS_LOSTFOCUS); - - win->AddRef(); - win->DispatchFocus(gevent); - win->Release(); - - UninitFocusEvent(event, p, gevent, NS_LOSTFOCUS); - } - return PR_TRUE; -} - //============================================================== void menu_item_activate_handler(GtkWidget *w, gpointer p) { diff --git a/widget/src/gtk/nsGtkEventHandler.h b/widget/src/gtk/nsGtkEventHandler.h index 44774009bdc1..a2d6f4bbff54 100644 --- a/widget/src/gtk/nsGtkEventHandler.h +++ b/widget/src/gtk/nsGtkEventHandler.h @@ -31,9 +31,6 @@ gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p); gint handle_key_release_event(GtkWidget *w, GdkEventKey* event, gpointer p); gint handle_key_press_event(GtkWidget *w, GdkEventKey* event, gpointer p); -gint handle_focus_in_event(GtkWidget *w, GdkEventFocus * event, gpointer p); -gint handle_focus_out_event(GtkWidget *w, GdkEventFocus * event, gpointer p); - void handle_scrollbar_value_changed(GtkAdjustment *adjustment, gpointer p); void menu_item_activate_handler(GtkWidget *w, gpointer p); @@ -47,10 +44,6 @@ gint nsGtkWidget_FSBCancel_Callback(GtkWidget *w, gpointer p); gint nsGtkWidget_FSBOk_Callback(GtkWidget *w, gpointer p); //---------------------------------------------------- -gint nsGtkWidget_Focus_Callback(GtkWidget *w, gpointer p); - - - gint CheckButton_Toggle_Callback(GtkWidget *w, gpointer p); gint nsGtkWidget_RadioButton_ArmCallback(GtkWidget *w, gpointer p); diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 2805342e9443..2e5fbd6cfe4a 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -953,6 +953,14 @@ PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg) return result; } +PRBool nsWidget::DispatchFocus(nsGUIEvent &aEvent) +{ + if (mEventCallback) { + return DispatchWindowEvent(&aEvent); + } + return PR_FALSE; +} + //------------------------------------------------------------------------- // @@ -1145,6 +1153,26 @@ nsWidget::InstallButtonReleaseSignal(GtkWidget * aWidget) } ////////////////////////////////////////////////////////////////// void +nsWidget::InstallFocusInSignal(GtkWidget * aWidget) +{ + NS_ASSERTION( nsnull != aWidget, "widget is null"); + + InstallSignal(aWidget, + "focus_in_event", + GTK_SIGNAL_FUNC(nsWidget::FocusInSignal)); +} +////////////////////////////////////////////////////////////////// +void +nsWidget::InstallFocusOutSignal(GtkWidget * aWidget) +{ + NS_ASSERTION( nsnull != aWidget, "widget is null"); + + InstallSignal(aWidget, + "focus_out_event", + GTK_SIGNAL_FUNC(nsWidget::FocusOutSignal)); +} +////////////////////////////////////////////////////////////////// +void nsWidget::InstallRealizeSignal(GtkWidget * aWidget) { NS_ASSERTION( nsnull != aWidget, "widget is null"); @@ -1166,17 +1194,23 @@ nsWidget::InstallRealizeSignal(GtkWidget * aWidget) // Turning TRACE_EVENTS on will cause printfs for all // mouse events that are dispatched. // +// Motion events are extra noisy so they get their own +// define: TRACE_EVENTS_MOTION +// ////////////////////////////////////////////////////////////////// #undef TRACE_EVENTS +#undef TRACE_EVENTS_MOTION #ifdef DEBUG void -nsWidget::DebugPrintEvent(nsGUIEvent & aEvent, +nsWidget::DebugPrintEvent(nsGUIEvent & aEvent, char * sMessage, - GtkWidget * aGtkWidget) + GtkWidget * aGtkWidget, + PRBool aPrintCoords, + PRBool aPrintXID) { - char * eventName = nsnull; + nsString eventName = "UNKNOWN"; switch(aEvent.message) { @@ -1256,20 +1290,54 @@ nsWidget::DebugPrintEvent(nsGUIEvent & aEvent, eventName = "NS_DRAGDROP_DROP"; break; + case NS_GOTFOCUS: + eventName = "NS_GOTFOCUS"; + break; + + case NS_LOSTFOCUS: + eventName = "NS_LOSTFOCUS"; + break; + default: - eventName = "UNKNOWN"; break; + { + char buf[32]; + + sprintf(buf,"%d",aEvent.message); + + eventName = buf; + } + break; } static int sPrintCount=0; - printf("%4d %7s(this=%10p, name=%10s, event=%16s, (%3d, %3d)\n", + printf("%4d %-14s(this=%-8p , name=%-12s", sPrintCount++, sMessage, this, - gtk_widget_get_name(aGtkWidget), - eventName, - aEvent.point.x, - aEvent.point.y); + gtk_widget_get_name(aGtkWidget)); + + if (aPrintXID) + { + printf(" , xid=%-8p", + GDK_WINDOW_XWINDOW(mWidget->window)); + } + + printf(" , event=%-16s", + (const char *) nsAutoCString(eventName)); + + if (aPrintCoords) + { + printf(" , x=%-3d, y=%d)", + aEvent.point.x, + aEvent.point.y); + } + else + { + printf(")"); + } + + printf("\n"); } #endif // DEBUG ////////////////////////////////////////////////////////////////// @@ -1332,8 +1400,8 @@ nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent) event.time = aGdkMotionEvent->time; } -#ifdef TRACE_EVENTS - DebugPrintEvent(event,"Motion",mWidget); +#ifdef TRACE_EVENTS_MOTION + DebugPrintEvent(event,"Motion",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1361,7 +1429,7 @@ nsWidget::OnDragMotionSignal(GdkDragContext *aGdkDragContext) event.point.y = 19; #ifdef TRACE_EVENTS - DebugPrintEvent(event,"Motion",mWidget); + DebugPrintEvent(event,"Motion",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1382,7 +1450,7 @@ nsWidget::OnDragBeginSignal(GdkDragContext * aGdkDragContext) event.eventStructType = NS_MOUSE_EVENT; #ifdef TRACE_EVENTS - DebugPrintEvent(event,"Drag",mWidget); + DebugPrintEvent(event,"Drag",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1408,7 +1476,7 @@ nsWidget::OnDragDropSignal(GdkDragContext *aDragContext) event.point.y = 19; #ifdef TRACE_EVENTS - DebugPrintEvent(event,"Drop",mWidget); + DebugPrintEvent(event,"Drop",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1449,7 +1517,7 @@ nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent) } #ifdef TRACE_EVENTS - DebugPrintEvent(event,"Enter",mWidget); + DebugPrintEvent(event,"Enter",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1488,7 +1556,7 @@ nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent) } #ifdef TRACE_EVENTS - DebugPrintEvent(event,"Leave",mWidget); + DebugPrintEvent(event,"Leave",mWidget,PR_FALSE,PR_TRUE); #endif AddRef(); @@ -1567,7 +1635,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) InitMouseEvent(aGdkButtonEvent, event, eventType); #ifdef TRACE_EVENTS - DebugPrintEvent(event,"ButtonPress",mWidget); + DebugPrintEvent(event,"ButtonPress",mWidget,PR_FALSE,PR_TRUE); #endif // Set the button motion target and remeber the widget and root coords @@ -1615,7 +1683,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) InitMouseEvent(aGdkButtonEvent, event, eventType); #ifdef TRACE_EVENTS - DebugPrintEvent(event,"ButtonRelease",mWidget); + DebugPrintEvent(event,"ButtonRelease",mWidget,PR_FALSE,PR_TRUE); #endif if (nsnull != sButtonMotionTarget) @@ -1634,6 +1702,66 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) } ////////////////////////////////////////////////////////////////////// /* virtual */ void +nsWidget::OnFocusInSignal(GdkEventFocus * aGdkFocusEvent) +{ + if (mIsDestroying) + return; + + nsGUIEvent event; + + event.message = NS_GOTFOCUS; + event.widget = this; + + event.eventStructType = NS_GUI_EVENT; + +// event.time = aGdkFocusEvent->time;; +// event.time = PR_Now(); + event.time = 0; + event.point.x = 0; + event.point.y = 0; + +#ifdef TRACE_EVENTS + DebugPrintEvent(event,"FocusIn",mWidget,PR_FALSE,PR_TRUE); +#endif + + AddRef(); + + DispatchFocus(event); + + Release(); +} +////////////////////////////////////////////////////////////////////// +/* virtual */ void +nsWidget::OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent) +{ + if (mIsDestroying) + return; + + nsGUIEvent event; + + event.message = NS_LOSTFOCUS; + event.widget = this; + + event.eventStructType = NS_GUI_EVENT; + +// event.time = aGdkFocusEvent->time;; +// event.time = PR_Now(); + event.time = 0; + event.point.x = 0; + event.point.y = 0; + +#ifdef TRACE_EVENTS + DebugPrintEvent(event,"FocusOut",mWidget,PR_FALSE,PR_TRUE); +#endif + + AddRef(); + + DispatchFocus(event); + + Release(); +} +////////////////////////////////////////////////////////////////////// +/* virtual */ void nsWidget::OnRealize() { // printf("nsWidget::OnRealize(%p)\n",this); @@ -1946,7 +2074,60 @@ nsWidget::RealizeSignal(GtkWidget * aWidget, return PR_TRUE; } ////////////////////////////////////////////////////////////////////// +/* static */ gint +nsWidget::FocusInSignal(GtkWidget * aWidget, + GdkEventFocus * aGdkFocusEvent, + gpointer aData) +{ + // printf("nsWidget::ButtonReleaseSignal(%p)\n",aData); + NS_ASSERTION( nsnull != aWidget, "widget is null"); + NS_ASSERTION( nsnull != aGdkFocusEvent, "event is null"); + + nsWidget * widget = (nsWidget *) aData; + + NS_ASSERTION( nsnull != widget, "instance pointer is null"); + +// if (widget->DropEvent(aWidget, aGdkFocusEvent->window)) +// { +// return PR_TRUE; +// } + + widget->OnFocusInSignal(aGdkFocusEvent); + + if (GTK_IS_WINDOW(aWidget)) + gtk_signal_emit_stop_by_name(GTK_OBJECT(aWidget), "focus_in_event"); + + return PR_TRUE; +} +////////////////////////////////////////////////////////////////////// +/* static */ gint +nsWidget::FocusOutSignal(GtkWidget * aWidget, + GdkEventFocus * aGdkFocusEvent, + gpointer aData) +{ + // printf("nsWidget::ButtonReleaseSignal(%p)\n",aData); + + NS_ASSERTION( nsnull != aWidget, "widget is null"); + NS_ASSERTION( nsnull != aGdkFocusEvent, "event is null"); + + nsWidget * widget = (nsWidget *) aData; + + NS_ASSERTION( nsnull != widget, "instance pointer is null"); + +// if (widget->DropEvent(aWidget, aGdkFocusEvent->window)) +// { +// return PR_TRUE; +// } + + widget->OnFocusOutSignal(aGdkFocusEvent); + + if (GTK_IS_WINDOW(aWidget)) + gtk_signal_emit_stop_by_name(GTK_OBJECT(aWidget), "focus_out_event"); + + return PR_TRUE; +} +////////////////////////////////////////////////////////////////////// /* virtual */ GdkWindow * nsWidget::GetWindowForSetBackground() diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index 006b9c6c2d3d..77045f6377b6 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -144,6 +144,8 @@ class nsWidget : public nsBaseWidget PRBool ConvertStatus(nsEventStatus aStatus); PRBool DispatchMouseEvent(nsMouseEvent& aEvent); PRBool DispatchStandardEvent(PRUint32 aMsg); + PRBool DispatchFocus(nsGUIEvent &aEvent); + // are we a "top level" widget? PRBool mIsToplevel; @@ -199,6 +201,10 @@ class nsWidget : public nsBaseWidget void InstallButtonReleaseSignal(GtkWidget * aWidget); + void InstallFocusInSignal(GtkWidget * aWidget); + + void InstallFocusOutSignal(GtkWidget * aWidget); + void InstallRealizeSignal(GtkWidget * aWidget); void AddToEventMask(GtkWidget * aWidget, @@ -217,6 +223,8 @@ class nsWidget : public nsBaseWidget virtual void OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent); virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent); virtual void OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent); + virtual void OnFocusInSignal(GdkEventFocus * aGdkFocusEvent); + virtual void OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent); virtual void OnRealize(); virtual void OnDestroySignal(GtkWidget* aGtkWidget); @@ -280,6 +288,14 @@ private: gpointer aData); + static gint FocusInSignal(GtkWidget * aWidget, + GdkEventFocus * aGdkFocusEvent, + gpointer aData); + + static gint FocusOutSignal(GtkWidget * aWidget, + GdkEventFocus * aGdkFocusEvent, + gpointer aData); + protected: ////////////////////////////////////////////////////////////////// @@ -301,7 +317,9 @@ protected: #ifdef DEBUG void DebugPrintEvent(nsGUIEvent & aEvent, char * sMessage, - GtkWidget * aGtkWidget); + GtkWidget * aGtkWidget, + PRBool aPrintCoords, + PRBool aPrintXID); #endif GtkWidget *mWidget; diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index e4b64f4e3c59..0d8de0417a4a 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -385,6 +385,9 @@ void nsWindow::InitCallbacks(char * aName) InstallDragMotionSignal(mWidget); InstallDragDropSignal(mWidget); + // Focus + InstallFocusInSignal(mWidget); + InstallFocusOutSignal(mWidget); gtk_signal_connect(GTK_OBJECT(mWidget), "draw", @@ -403,14 +406,6 @@ void nsWindow::InitCallbacks(char * aName) "key_release_event", GTK_SIGNAL_FUNC(handle_key_release_event), this); - gtk_signal_connect(GTK_OBJECT(mWidget), - "focus_in_event", - GTK_SIGNAL_FUNC(handle_focus_in_event), - this); - gtk_signal_connect(GTK_OBJECT(mWidget), - "focus_out_event", - GTK_SIGNAL_FUNC(handle_focus_out_event), - this); } //------------------------------------------------------------------------- @@ -595,15 +590,6 @@ PRBool nsWindow::OnKey(nsKeyEvent &aEvent) return PR_FALSE; } - -PRBool nsWindow::DispatchFocus(nsGUIEvent &aEvent) -{ - if (mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos) { return PR_FALSE; diff --git a/widget/src/gtk/nsWindow.h b/widget/src/gtk/nsWindow.h index ae9e5515e580..887119105946 100644 --- a/widget/src/gtk/nsWindow.h +++ b/widget/src/gtk/nsWindow.h @@ -97,7 +97,6 @@ public: // Utility methods virtual PRBool OnPaint(nsPaintEvent &event); PRBool OnKey(nsKeyEvent &aEvent); - PRBool DispatchFocus(nsGUIEvent &aEvent); virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); // in nsWidget now // virtual PRBool OnResize(nsSizeEvent &aEvent);