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.
This commit is contained in:
ramiro%netscape.com 1999-07-09 11:15:59 +00:00
parent 66f3cad02c
commit f2ce98faf9
6 changed files with 221 additions and 100 deletions

View File

@ -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; 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) void menu_item_activate_handler(GtkWidget *w, gpointer p)
{ {

View File

@ -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_release_event(GtkWidget *w, GdkEventKey* event, gpointer p);
gint handle_key_press_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 handle_scrollbar_value_changed(GtkAdjustment *adjustment, gpointer p);
void menu_item_activate_handler(GtkWidget *w, 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_FSBOk_Callback(GtkWidget *w, gpointer p);
//---------------------------------------------------- //----------------------------------------------------
gint nsGtkWidget_Focus_Callback(GtkWidget *w, gpointer p);
gint CheckButton_Toggle_Callback(GtkWidget *w, gpointer p); gint CheckButton_Toggle_Callback(GtkWidget *w, gpointer p);
gint nsGtkWidget_RadioButton_ArmCallback(GtkWidget *w, gpointer p); gint nsGtkWidget_RadioButton_ArmCallback(GtkWidget *w, gpointer p);

View File

@ -953,6 +953,14 @@ PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg)
return result; return result;
} }
PRBool nsWidget::DispatchFocus(nsGUIEvent &aEvent)
{
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// //
@ -1145,6 +1153,26 @@ nsWidget::InstallButtonReleaseSignal(GtkWidget * aWidget)
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
void 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) nsWidget::InstallRealizeSignal(GtkWidget * aWidget)
{ {
NS_ASSERTION( nsnull != aWidget, "widget is null"); NS_ASSERTION( nsnull != aWidget, "widget is null");
@ -1166,17 +1194,23 @@ nsWidget::InstallRealizeSignal(GtkWidget * aWidget)
// Turning TRACE_EVENTS on will cause printfs for all // Turning TRACE_EVENTS on will cause printfs for all
// mouse events that are dispatched. // 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
#undef TRACE_EVENTS_MOTION
#ifdef DEBUG #ifdef DEBUG
void void
nsWidget::DebugPrintEvent(nsGUIEvent & aEvent, nsWidget::DebugPrintEvent(nsGUIEvent & aEvent,
char * sMessage, char * sMessage,
GtkWidget * aGtkWidget) GtkWidget * aGtkWidget,
PRBool aPrintCoords,
PRBool aPrintXID)
{ {
char * eventName = nsnull; nsString eventName = "UNKNOWN";
switch(aEvent.message) switch(aEvent.message)
{ {
@ -1256,20 +1290,54 @@ nsWidget::DebugPrintEvent(nsGUIEvent & aEvent,
eventName = "NS_DRAGDROP_DROP"; eventName = "NS_DRAGDROP_DROP";
break; break;
case NS_GOTFOCUS:
eventName = "NS_GOTFOCUS";
break;
case NS_LOSTFOCUS:
eventName = "NS_LOSTFOCUS";
break;
default: default:
eventName = "UNKNOWN"; break; {
char buf[32];
sprintf(buf,"%d",aEvent.message);
eventName = buf;
}
break;
} }
static int sPrintCount=0; static int sPrintCount=0;
printf("%4d %7s(this=%10p, name=%10s, event=%16s, (%3d, %3d)\n", printf("%4d %-14s(this=%-8p , name=%-12s",
sPrintCount++, sPrintCount++,
sMessage, sMessage,
this, this,
gtk_widget_get_name(aGtkWidget), gtk_widget_get_name(aGtkWidget));
eventName,
aEvent.point.x, if (aPrintXID)
aEvent.point.y); {
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 #endif // DEBUG
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -1332,8 +1400,8 @@ nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent)
event.time = aGdkMotionEvent->time; event.time = aGdkMotionEvent->time;
} }
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS_MOTION
DebugPrintEvent(event,"Motion",mWidget); DebugPrintEvent(event,"Motion",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1361,7 +1429,7 @@ nsWidget::OnDragMotionSignal(GdkDragContext *aGdkDragContext)
event.point.y = 19; event.point.y = 19;
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"Motion",mWidget); DebugPrintEvent(event,"Motion",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1382,7 +1450,7 @@ nsWidget::OnDragBeginSignal(GdkDragContext * aGdkDragContext)
event.eventStructType = NS_MOUSE_EVENT; event.eventStructType = NS_MOUSE_EVENT;
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"Drag",mWidget); DebugPrintEvent(event,"Drag",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1408,7 +1476,7 @@ nsWidget::OnDragDropSignal(GdkDragContext *aDragContext)
event.point.y = 19; event.point.y = 19;
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"Drop",mWidget); DebugPrintEvent(event,"Drop",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1449,7 +1517,7 @@ nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
} }
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"Enter",mWidget); DebugPrintEvent(event,"Enter",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1488,7 +1556,7 @@ nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
} }
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"Leave",mWidget); DebugPrintEvent(event,"Leave",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
AddRef(); AddRef();
@ -1567,7 +1635,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent)
InitMouseEvent(aGdkButtonEvent, event, eventType); InitMouseEvent(aGdkButtonEvent, event, eventType);
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"ButtonPress",mWidget); DebugPrintEvent(event,"ButtonPress",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
// Set the button motion target and remeber the widget and root coords // Set the button motion target and remeber the widget and root coords
@ -1615,7 +1683,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent)
InitMouseEvent(aGdkButtonEvent, event, eventType); InitMouseEvent(aGdkButtonEvent, event, eventType);
#ifdef TRACE_EVENTS #ifdef TRACE_EVENTS
DebugPrintEvent(event,"ButtonRelease",mWidget); DebugPrintEvent(event,"ButtonRelease",mWidget,PR_FALSE,PR_TRUE);
#endif #endif
if (nsnull != sButtonMotionTarget) if (nsnull != sButtonMotionTarget)
@ -1634,6 +1702,66 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent)
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/* virtual */ void /* 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() nsWidget::OnRealize()
{ {
// printf("nsWidget::OnRealize(%p)\n",this); // printf("nsWidget::OnRealize(%p)\n",this);
@ -1946,7 +2074,60 @@ nsWidget::RealizeSignal(GtkWidget * aWidget,
return PR_TRUE; 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 * /* virtual */ GdkWindow *
nsWidget::GetWindowForSetBackground() nsWidget::GetWindowForSetBackground()

View File

@ -144,6 +144,8 @@ class nsWidget : public nsBaseWidget
PRBool ConvertStatus(nsEventStatus aStatus); PRBool ConvertStatus(nsEventStatus aStatus);
PRBool DispatchMouseEvent(nsMouseEvent& aEvent); PRBool DispatchMouseEvent(nsMouseEvent& aEvent);
PRBool DispatchStandardEvent(PRUint32 aMsg); PRBool DispatchStandardEvent(PRUint32 aMsg);
PRBool DispatchFocus(nsGUIEvent &aEvent);
// are we a "top level" widget? // are we a "top level" widget?
PRBool mIsToplevel; PRBool mIsToplevel;
@ -199,6 +201,10 @@ class nsWidget : public nsBaseWidget
void InstallButtonReleaseSignal(GtkWidget * aWidget); void InstallButtonReleaseSignal(GtkWidget * aWidget);
void InstallFocusInSignal(GtkWidget * aWidget);
void InstallFocusOutSignal(GtkWidget * aWidget);
void InstallRealizeSignal(GtkWidget * aWidget); void InstallRealizeSignal(GtkWidget * aWidget);
void AddToEventMask(GtkWidget * aWidget, void AddToEventMask(GtkWidget * aWidget,
@ -217,6 +223,8 @@ class nsWidget : public nsBaseWidget
virtual void OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent); virtual void OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent);
virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent); virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent);
virtual void OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent); virtual void OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent);
virtual void OnFocusInSignal(GdkEventFocus * aGdkFocusEvent);
virtual void OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent);
virtual void OnRealize(); virtual void OnRealize();
virtual void OnDestroySignal(GtkWidget* aGtkWidget); virtual void OnDestroySignal(GtkWidget* aGtkWidget);
@ -280,6 +288,14 @@ private:
gpointer aData); gpointer aData);
static gint FocusInSignal(GtkWidget * aWidget,
GdkEventFocus * aGdkFocusEvent,
gpointer aData);
static gint FocusOutSignal(GtkWidget * aWidget,
GdkEventFocus * aGdkFocusEvent,
gpointer aData);
protected: protected:
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -301,7 +317,9 @@ protected:
#ifdef DEBUG #ifdef DEBUG
void DebugPrintEvent(nsGUIEvent & aEvent, void DebugPrintEvent(nsGUIEvent & aEvent,
char * sMessage, char * sMessage,
GtkWidget * aGtkWidget); GtkWidget * aGtkWidget,
PRBool aPrintCoords,
PRBool aPrintXID);
#endif #endif
GtkWidget *mWidget; GtkWidget *mWidget;

View File

@ -385,6 +385,9 @@ void nsWindow::InitCallbacks(char * aName)
InstallDragMotionSignal(mWidget); InstallDragMotionSignal(mWidget);
InstallDragDropSignal(mWidget); InstallDragDropSignal(mWidget);
// Focus
InstallFocusInSignal(mWidget);
InstallFocusOutSignal(mWidget);
gtk_signal_connect(GTK_OBJECT(mWidget), gtk_signal_connect(GTK_OBJECT(mWidget),
"draw", "draw",
@ -403,14 +406,6 @@ void nsWindow::InitCallbacks(char * aName)
"key_release_event", "key_release_event",
GTK_SIGNAL_FUNC(handle_key_release_event), GTK_SIGNAL_FUNC(handle_key_release_event),
this); 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; return PR_FALSE;
} }
PRBool nsWindow::DispatchFocus(nsGUIEvent &aEvent)
{
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
}
PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos) PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos)
{ {
return PR_FALSE; return PR_FALSE;

View File

@ -97,7 +97,6 @@ public:
// Utility methods // Utility methods
virtual PRBool OnPaint(nsPaintEvent &event); virtual PRBool OnPaint(nsPaintEvent &event);
PRBool OnKey(nsKeyEvent &aEvent); PRBool OnKey(nsKeyEvent &aEvent);
PRBool DispatchFocus(nsGUIEvent &aEvent);
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
// in nsWidget now // in nsWidget now
// virtual PRBool OnResize(nsSizeEvent &aEvent); // virtual PRBool OnResize(nsSizeEvent &aEvent);