More event cleanup. Move button and crossing events into nsWidget.

This commit is contained in:
ramiro%netscape.com 1999-04-16 14:33:52 +00:00
parent 877d64444f
commit f16f605750
7 changed files with 491 additions and 347 deletions

View File

@ -62,18 +62,20 @@ nsButton::~nsButton()
void nsButton::InitCallbacks(char * aName)
{
nsWidget::InitCallbacks();
InstallButtonPressSignal(mWidget);
InstallButtonReleaseSignal(mWidget);
/* FIXME: we need to unconnect the signals connected from
* nsWidget::InitCallbacks that we provide here */
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_release_event",
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
// These are needed so that the events will go to us and not our parent.
AddToEventMask(mWidget,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_EXPOSURE_MASK |
GDK_FOCUS_CHANGE_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK);
}
/**

View File

@ -177,52 +177,6 @@ void InitConfigureEvent(GdkEventConfigure *aConf,
anEvent.time = 0;
}
//==============================================================
void InitMouseEvent(GdkEventButton *aGEB,
gpointer p,
nsMouseEvent &anEvent,
PRUint32 aEventType)
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
anEvent.eventStructType = NS_MOUSE_EVENT;
if (aGEB != NULL) {
anEvent.point.x = nscoord(aGEB->x);
anEvent.point.y = nscoord(aGEB->y);
anEvent.isShift = (aGEB->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isControl = (aGEB->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isAlt = (aGEB->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE;
anEvent.time = aGEB->time;
switch(aGEB->type)
{
case GDK_BUTTON_PRESS:
anEvent.clickCount = 1;
break;
case GDK_2BUTTON_PRESS:
anEvent.clickCount = 2;
break;
case GDK_3BUTTON_PRESS: /* Clamp to double-click */
anEvent.clickCount = 2;
break;
default:
anEvent.clickCount = 1;
}
}
}
//==============================================================
void UninitMouseEvent(GdkEventButton *aGEB,
gpointer p,
nsMouseEvent &anEvent,
PRUint32 aEventType)
{
}
//==============================================================
void InitExposeEvent(GdkEventExpose *aGEE,
gpointer p,
@ -424,106 +378,6 @@ gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p)
return PR_TRUE;
}
//==============================================================
gint handle_button_press_event(GtkWidget *w, GdkEventButton * event, gpointer p)
{
nsMouseEvent mevent;
int b = 0;
/* Switch on single, double, triple click. */
switch (event->type) {
case GDK_BUTTON_PRESS: /* Single click. */
switch (event->button) /* Which button? */
{
case 1:
b = NS_MOUSE_LEFT_BUTTON_DOWN;
break;
case 2:
b = NS_MOUSE_MIDDLE_BUTTON_DOWN;
break;
case 3:
b = NS_MOUSE_RIGHT_BUTTON_DOWN;
break;
default:
/* Single-click default. */
b = NS_MOUSE_LEFT_BUTTON_DOWN;
break;
}
break;
case GDK_2BUTTON_PRESS: /* Double click. */
switch (event->button) /* Which button? */
{
case 1:
b = NS_MOUSE_LEFT_DOUBLECLICK;
break;
case 2:
b = NS_MOUSE_MIDDLE_DOUBLECLICK;
break;
case 3:
b = NS_MOUSE_RIGHT_DOUBLECLICK;
break;
default:
/* Double-click default. */
b = NS_MOUSE_LEFT_DOUBLECLICK;
break;
}
break;
case GDK_3BUTTON_PRESS: /* Triple click. */
/* Unhandled triple click. */
break;
default:
break;
}
InitMouseEvent(event, p, mevent, b);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitMouseEvent(event, p, mevent, b);
return PR_TRUE;
}
//==============================================================
gint handle_button_release_event(GtkWidget *w, GdkEventButton * event, gpointer p)
{
nsMouseEvent mevent;
int b = 0;
switch (event->button)
{
case 1:
b = NS_MOUSE_LEFT_BUTTON_UP;
break;
case 2:
b = NS_MOUSE_MIDDLE_BUTTON_UP;
break;
case 3:
b = NS_MOUSE_RIGHT_BUTTON_UP;
break;
default:
b = NS_MOUSE_LEFT_BUTTON_UP;
break;
}
InitMouseEvent(event, p, mevent, b);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitMouseEvent(event, p, mevent, b);
return PR_TRUE;
}
//==============================================================
//==============================================================
gint handle_focus_in_event(GtkWidget *w, GdkEventFocus * event, gpointer p)
{
@ -531,11 +385,9 @@ gint handle_focus_in_event(GtkWidget *w, GdkEventFocus * event, gpointer 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;

View File

@ -27,8 +27,6 @@ class nsIMenuItem;
gint handle_configure_event(GtkWidget *w, GdkEventConfigure *conf, gpointer p);
void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p);
gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p);
gint handle_button_press_event(GtkWidget *w, GdkEventButton * event, gpointer p);
gint handle_button_release_event(GtkWidget *w, GdkEventButton * 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);

View File

@ -765,7 +765,8 @@ NS_METHOD nsWidget::Create(nsNativeWidget aParent,
//-------------------------------------------------------------------------
void nsWidget::InitCallbacks(char *aName)
{
#if 1
#if 0
/* basically we are keeping the parent from getting the childs signals by
* doing this. */
gtk_signal_connect_after(GTK_OBJECT(mWidget),
@ -984,28 +985,64 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent)
// GTK signal installers
//
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallMotionNotifySignal(GtkWidget * aWidget,
PRBool aInstallSignal,
PRBool aSetEvents)
void
nsWidget::AddToEventMask(GtkWidget * aWidget,
gint aEventMask)
{
NS_ASSERTION( nsnull != aWidget, "widget is null!");
NS_ASSERTION( aInstallSignal || aSetEvents, "nothing to do");
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( 0 != aEventMask, "mask is 0");
// Connect the signal if needed
if (aInstallSignal)
{
gtk_signal_connect(GTK_OBJECT(aWidget),
"motion_notify_event",
GTK_SIGNAL_FUNC(nsWidget::MotionNotifySignal),
(gpointer) this);
}
gtk_widget_add_events(aWidget,aEventMask);
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallMotionNotifySignal(GtkWidget * aWidget)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
// Set the events so widget will get the events if needed
if (aSetEvents)
{
gtk_widget_add_events(aWidget,GDK_POINTER_MOTION_MASK);
}
InstallSignal(aWidget,
"motion_notify_event",
GTK_SIGNAL_FUNC(nsWidget::MotionNotifySignal));
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallEnterNotifySignal(GtkWidget * aWidget)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
InstallSignal(aWidget,
"enter_notify_event",
GTK_SIGNAL_FUNC(nsWidget::EnterNotifySignal));
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallLeaveNotifySignal(GtkWidget * aWidget)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
InstallSignal(aWidget,
"leave_notify_event",
GTK_SIGNAL_FUNC(nsWidget::LeaveNotifySignal));
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallButtonPressSignal(GtkWidget * aWidget)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
InstallSignal(aWidget,
"button_press_event",
GTK_SIGNAL_FUNC(nsWidget::ButtonPressSignal));
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallButtonReleaseSignal(GtkWidget * aWidget)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
InstallSignal(aWidget,
"button_release_event",
GTK_SIGNAL_FUNC(nsWidget::ButtonReleaseSignal));
}
//////////////////////////////////////////////////////////////////
@ -1015,8 +1052,12 @@ nsWidget::InstallMotionNotifySignal(GtkWidget * aWidget,
//
//////////////////////////////////////////////////////////////////
/* virtual */ void
nsWidget::OnMotionNotify(GdkEventMotion * aGdkMotionEvent)
nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent)
{
// static int i = 0;
// printf("nsWidget::OnMotionNotifySignal(%d,%p,%d,%d)\n",
// i++,this,(int) aGdkMotionEvent->x,(int) aGdkMotionEvent->y);
nsMouseEvent event;
event.message = NS_MOUSE_MOVE;
@ -1037,6 +1078,254 @@ nsWidget::OnMotionNotify(GdkEventMotion * aGdkMotionEvent)
Release();
}
//////////////////////////////////////////////////////////////////
/* virtual */ void
nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
{
// printf("nsWidget::OnEnterNotifySignal(%p)\n",this);
nsMouseEvent event;
event.message = NS_MOUSE_ENTER;
event.widget = this;
event.eventStructType = NS_MOUSE_EVENT;
if (aGdkCrossingEvent != NULL)
{
event.point.x = nscoord(aGdkCrossingEvent->x);
event.point.y = nscoord(aGdkCrossingEvent->y);
event.time = aGdkCrossingEvent->time;
}
AddRef();
DispatchMouseEvent(event);
Release();
}
//////////////////////////////////////////////////////////////////////
/* virtual */ void
nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
{
// printf("nsWidget::OnLeaveNotifySignal(%p)\n",this);
nsMouseEvent event;
event.message = NS_MOUSE_EXIT;
event.widget = this;
event.eventStructType = NS_MOUSE_EVENT;
if (aGdkCrossingEvent != NULL)
{
event.point.x = nscoord(aGdkCrossingEvent->x);
event.point.y = nscoord(aGdkCrossingEvent->y);
event.time = aGdkCrossingEvent->time;
}
AddRef();
DispatchMouseEvent(event);
Release();
}
//////////////////////////////////////////////////////////////////////
/* virtual */ void
nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent)
{
// printf("nsWidget::OnButtonPressSignal(%p)\n",this);
nsMouseEvent event;
PRUint32 eventType = 0;
// Switch on single, double, triple click.
switch (aGdkButtonEvent->type)
{
// Single click.
case GDK_BUTTON_PRESS:
switch (aGdkButtonEvent->button) // Which button?
{
case 1:
eventType = NS_MOUSE_LEFT_BUTTON_DOWN;
break;
case 2:
eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN;
break;
case 3:
eventType = NS_MOUSE_RIGHT_BUTTON_DOWN;
break;
// Single-click default.
default:
eventType = NS_MOUSE_LEFT_BUTTON_DOWN;
break;
}
break;
// Double click.
case GDK_2BUTTON_PRESS:
switch (aGdkButtonEvent->button) // Which button?
{
case 1:
eventType = NS_MOUSE_LEFT_DOUBLECLICK;
break;
case 2:
eventType = NS_MOUSE_MIDDLE_DOUBLECLICK;
break;
case 3:
eventType = NS_MOUSE_RIGHT_DOUBLECLICK;
break;
default:
// Double-click default.
eventType = NS_MOUSE_LEFT_DOUBLECLICK;
break;
}
break;
// Triple click.
case GDK_3BUTTON_PRESS:
// Unhandled triple click.
break;
default:
break;
}
InitMouseEvent(aGdkButtonEvent, event, eventType);
AddRef();
DispatchMouseEvent(event);
Release();
}
//////////////////////////////////////////////////////////////////////
/* virtual */ void
nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent)
{
// printf("nsWidget::OnButtonReleaseSignal(%p)\n",this);
nsMouseEvent event;
PRUint32 eventType = 0;
switch (aGdkButtonEvent->button)
{
case 1:
eventType = NS_MOUSE_LEFT_BUTTON_UP;
break;
case 2:
eventType = NS_MOUSE_MIDDLE_BUTTON_UP;
break;
case 3:
eventType = NS_MOUSE_RIGHT_BUTTON_UP;
break;
default:
eventType = NS_MOUSE_LEFT_BUTTON_UP;
break;
}
InitMouseEvent(aGdkButtonEvent, event, eventType);
AddRef();
DispatchMouseEvent(event);
Release();
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//
// GTK event support methods
//
//////////////////////////////////////////////////////////////////
void
nsWidget::InstallSignal(GtkWidget * aWidget,
gchar * aSignalName,
GtkSignalFunc aSignalFunction)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( aSignalName, "signal name is null");
NS_ASSERTION( aSignalFunction, "signal function is null");
gtk_signal_connect(GTK_OBJECT(aWidget),
aSignalName,
GTK_SIGNAL_FUNC(aSignalFunction),
(gpointer) this);
}
//////////////////////////////////////////////////////////////////
void
nsWidget::InitMouseEvent(GdkEventButton * aGdkButtonEvent,
nsMouseEvent &anEvent,
PRUint32 aEventType)
{
anEvent.message = aEventType;
anEvent.widget = this;
anEvent.eventStructType = NS_MOUSE_EVENT;
if (aGdkButtonEvent != NULL) {
anEvent.point.x = nscoord(aGdkButtonEvent->x);
anEvent.point.y = nscoord(aGdkButtonEvent->y);
anEvent.isShift = (aGdkButtonEvent->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isControl = (aGdkButtonEvent->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isAlt = (aGdkButtonEvent->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE;
anEvent.time = aGdkButtonEvent->time;
switch(aGdkButtonEvent->type)
{
case GDK_BUTTON_PRESS:
anEvent.clickCount = 1;
break;
case GDK_2BUTTON_PRESS:
anEvent.clickCount = 2;
break;
case GDK_3BUTTON_PRESS: /* Clamp to double-click */
anEvent.clickCount = 2;
break;
default:
anEvent.clickCount = 1;
}
}
}
//////////////////////////////////////////////////////////////////
PRBool
nsWidget::DropEvent(GtkWidget * aWidget,
GdkWindow * aEventWindow)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aEventWindow, "event window is null");
#if 0
// For gtklayout widgets, we dont want to handle events
// that occur in the sub windows. Check the window member
// of the GdkEvent, if it is not the gtklayout's bin_window,
// drop the event.
if (GTK_IS_LAYOUT(aWidget))
{
GtkLayout * layout = GTK_LAYOUT(aWidget);
if (aEventWindow != layout->bin_window)
{
return PR_TRUE;
}
}
#endif
return PR_FALSE;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
@ -1045,19 +1334,112 @@ nsWidget::OnMotionNotify(GdkEventMotion * aGdkMotionEvent)
//
//////////////////////////////////////////////////////////////////
/* static */ gint
nsWidget::MotionNotifySignal(GtkWidget * aWidget,
nsWidget::MotionNotifySignal(GtkWidget * aWidget,
GdkEventMotion * aGdkMotionEvent,
gpointer aData)
gpointer aData)
{
NS_ASSERTION( nsnull != aWidget, "widget is null!");
NS_ASSERTION( nsnull != aGdkMotionEvent, "event is null!");
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aGdkMotionEvent, "event is null");
nsWidget * widget = (nsWidget *) aData;
NS_ASSERTION( nsnull != widget, "instance pointer is null!");
NS_ASSERTION( nsnull != widget, "instance pointer is null");
widget->OnMotionNotify(aGdkMotionEvent);
if (widget->DropEvent(aWidget, aGdkMotionEvent->window))
{
return PR_TRUE;
}
widget->OnMotionNotifySignal(aGdkMotionEvent);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////
/* static */ gint
nsWidget::EnterNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aGdkCrossingEvent, "event is null");
nsWidget * widget = (nsWidget *) aData;
NS_ASSERTION( nsnull != widget, "instance pointer is null");
if (widget->DropEvent(aWidget, aGdkCrossingEvent->window))
{
return PR_TRUE;
}
widget->OnEnterNotifySignal(aGdkCrossingEvent);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////
/* static */ gint
nsWidget::LeaveNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aGdkCrossingEvent, "event is null");
nsWidget * widget = (nsWidget *) aData;
NS_ASSERTION( nsnull != widget, "instance pointer is null");
if (widget->DropEvent(aWidget, aGdkCrossingEvent->window))
{
return PR_TRUE;
}
widget->OnLeaveNotifySignal(aGdkCrossingEvent);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////
/* static */ gint
nsWidget::ButtonPressSignal(GtkWidget * aWidget,
GdkEventButton * aGdkButtonEvent,
gpointer aData)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aGdkButtonEvent, "event is null");
nsWidget * widget = (nsWidget *) aData;
NS_ASSERTION( nsnull != widget, "instance pointer is null");
if (widget->DropEvent(aWidget, aGdkButtonEvent->window))
{
return PR_TRUE;
}
widget->OnButtonPressSignal(aGdkButtonEvent);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////
/* static */ gint
nsWidget::ButtonReleaseSignal(GtkWidget * aWidget,
GdkEventButton * aGdkButtonEvent,
gpointer aData)
{
NS_ASSERTION( nsnull != aWidget, "widget is null");
NS_ASSERTION( nsnull != aGdkButtonEvent, "event is null");
nsWidget * widget = (nsWidget *) aData;
NS_ASSERTION( nsnull != widget, "instance pointer is null");
if (widget->DropEvent(aWidget, aGdkButtonEvent->window))
{
return PR_TRUE;
}
widget->OnButtonReleaseSignal(aGdkButtonEvent);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////

View File

@ -143,16 +143,29 @@ class nsWidget : public nsBaseWidget
// GTK signal installers
//
//////////////////////////////////////////////////////////////////
void InstallMotionNotifySignal(GtkWidget * aWidget,
PRBool aInstallSignal,
PRBool aSetEvents);
void InstallMotionNotifySignal(GtkWidget * aWidget);
void InstallEnterNotifySignal(GtkWidget * aWidget);
void InstallLeaveNotifySignal(GtkWidget * aWidget);
void InstallButtonPressSignal(GtkWidget * aWidget);
void InstallButtonReleaseSignal(GtkWidget * aWidget);
void AddToEventMask(GtkWidget * aWidget,
gint aEventMask);
//////////////////////////////////////////////////////////////////
//
// OnSomething handlers
//
//////////////////////////////////////////////////////////////////
virtual void OnMotionNotify(GdkEventMotion * aGdkMotionEvent);
virtual void OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent);
virtual void OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent);
virtual void OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent);
virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent);
virtual void OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent);
private:
@ -161,10 +174,42 @@ private:
// GTK widget signals
//
//////////////////////////////////////////////////////////////////
static gint MotionNotifySignal(GtkWidget * aWidget,
GdkEventMotion * aGdkMotionEvent,
gpointer aData);
static gint MotionNotifySignal(GtkWidget * aWidget,
GdkEventMotion * aGdkMotionEvent,
gpointer aData);
static gint EnterNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData);
static gint LeaveNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData);
static gint ButtonPressSignal(GtkWidget * aWidget,
GdkEventButton * aGdkButtonEvent,
gpointer aData);
static gint ButtonReleaseSignal(GtkWidget * aWidget,
GdkEventButton * aGdkButtonEvent,
gpointer aData);
//////////////////////////////////////////////////////////////////
//
// GTK event support methods
//
//////////////////////////////////////////////////////////////////
void InstallSignal(GtkWidget * aWidget,
gchar * aSignalName,
GtkSignalFunc aSignalFunction);
PRBool DropEvent(GtkWidget * aWidget,
GdkWindow * aEventWindow);
void InitMouseEvent(GdkEventButton * aGdkButtonEvent,
nsMouseEvent & anEvent,
PRUint32 aEventType);
protected:
GtkWidget *mWidget;
nsIWidget *mParent;

View File

@ -205,15 +205,17 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget)
GTK_WIDGET_SET_FLAGS(mWidget, GTK_CAN_FOCUS);
gtk_widget_set_app_paintable(mWidget, PR_TRUE);
gtk_widget_set_events (mWidget,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_EXPOSURE_MASK |
GDK_FOCUS_CHANGE_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_LEAVE_NOTIFY_MASK);
AddToEventMask(mWidget,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_EXPOSURE_MASK |
GDK_FOCUS_CHANGE_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK);
if (!parentWidget) {
@ -278,27 +280,16 @@ void nsWindow::InitCallbacks(char * aName)
"size_allocate",
GTK_SIGNAL_FUNC(handle_size_allocate),
this);
gtk_signal_connect_after(GTK_OBJECT(mWidget),
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_release_event",
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
InstallMotionNotifySignal(mWidget,PR_TRUE,PR_TRUE);
InstallButtonPressSignal(mWidget);
gtk_signal_connect(GTK_OBJECT(mWidget),
"enter_notify_event",
GTK_SIGNAL_FUNC(nsWindow::EnterNotifySignal),
(gpointer) this);
InstallButtonReleaseSignal(mWidget);
gtk_signal_connect(GTK_OBJECT(mWidget),
"leave_notify_event",
GTK_SIGNAL_FUNC(nsWindow::LeaveNotifySignal),
(gpointer) this);
InstallMotionNotifySignal(mWidget);
InstallEnterNotifySignal(mWidget);
InstallLeaveNotifySignal(mWidget);
gtk_signal_connect(GTK_OBJECT(mWidget),
"draw",
@ -620,106 +611,6 @@ nsWindow::OnDrawSignal(GdkRectangle * aArea)
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
// Crossing signals
//
//////////////////////////////////////////////////////////////////////
void
nsWindow::InitCrossingEvent(GdkEventCrossing * aGdkCrossingEvent,
nsMouseEvent & aMouseEvent,
PRUint32 aEventType)
{
aMouseEvent.message = aEventType;
aMouseEvent.widget = (nsWidget *) this;
aMouseEvent.eventStructType = NS_MOUSE_EVENT;
if (aGdkCrossingEvent != NULL)
{
aMouseEvent.point.x = nscoord(aGdkCrossingEvent->x);
aMouseEvent.point.y = nscoord(aGdkCrossingEvent->y);
aMouseEvent.time = aGdkCrossingEvent->time;
}
}
//////////////////////////////////////////////////////////////////////
void
nsWindow::UninitCrossingEvent(GdkEventCrossing * aGdkCrossingEvent,
nsMouseEvent & aMouseEvent,
PRUint32 aEventType)
{
}
//////////////////////////////////////////////////////////////////////
/* static */ gint
nsWindow::EnterNotifySignal(GtkWidget * /* aWidget */,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData)
{
nsWindow * window = (nsWindow *) aData;
NS_ASSERTION(nsnull != window,"window is null");
return window->OnEnterNotifySignal(aGdkCrossingEvent);
}
//////////////////////////////////////////////////////////////////////
/* virtual */ gint
nsWindow::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
{
//printf("nsWindow::OnEnterNotifySignal()\n");
nsMouseEvent mevent;
InitCrossingEvent(aGdkCrossingEvent, mevent, NS_MOUSE_ENTER);
nsWindow * win = (nsWindow *) this;
NS_ADDREF(win);
win->DispatchMouseEvent(mevent);
NS_RELEASE(win);
UninitCrossingEvent(aGdkCrossingEvent, mevent, NS_MOUSE_ENTER);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////
/* static */ gint
nsWindow::LeaveNotifySignal(GtkWidget * /* aWidget */,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData)
{
nsWindow * window = (nsWindow *) aData;
NS_ASSERTION(nsnull != window,"window is null");
return window->OnLeaveNotifySignal(aGdkCrossingEvent);
}
//////////////////////////////////////////////////////////////////////
/* virtual */ gint
nsWindow::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
{
//printf("nsWindow::OnLeaveNotifySignal()\n");
nsMouseEvent mevent;
InitCrossingEvent(aGdkCrossingEvent, mevent, NS_MOUSE_EXIT);
nsWindow * win = (nsWindow *) this;
NS_ADDREF(win);
win->DispatchMouseEvent(mevent);
NS_RELEASE(win);
UninitCrossingEvent(aGdkCrossingEvent, mevent, NS_MOUSE_EXIT);
return PR_TRUE;
}
//////////////////////////////////////////////////////////////////////
ChildWindow::ChildWindow()
{
}

View File

@ -110,32 +110,6 @@ protected:
virtual gint OnDrawSignal(GdkRectangle * aArea);
//////////////////////////////////////////////////////////////////////
//
// Crossing signals
//
//////////////////////////////////////////////////////////////////////
void InitCrossingEvent(GdkEventCrossing * aGdkCrossingEvent,
nsMouseEvent & aMouseEvent,
PRUint32 aEventType);
void UninitCrossingEvent(GdkEventCrossing * aGdkCrossingEvent,
nsMouseEvent & aMouseEvent,
PRUint32 aEventType);
static gint EnterNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData);
virtual gint OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent);
static gint LeaveNotifySignal(GtkWidget * aWidget,
GdkEventCrossing * aGdkCrossingEvent,
gpointer aData);
virtual gint OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent);
//////////////////////////////////////////////////////////////////////
virtual void InitCallbacks(char * aName = nsnull);