Sweden-Number/event.c

189 lines
5.1 KiB
C
Raw Normal View History

Release 0.2.0 Tue Jul 13 20:31:31 1993 Bob Amstadt (bob at pooh) * [global.c] Completed global memory pool API Sun Jul 11 16:59:52 1993 Alexandre Julliard * [message.c] [user.c] [user.spec] [windows.h] Added emulation of Windows message queue. Thu Jul 8 19:29:27 1993 Bob Amstadt (bob at pooh) * [build.c] Original by Bob Amstadt * [callback.c] Original by Bob Amstadt, updates by Alexandre Julliard * [dump.c] Original by Bob Amstadt * [global.c] Original by Bob Amstadt * [heap.c] Original by Bob Amstadt * [kernel.c] Original by Bob Amstadt * [ldt.c] Original by Bob Amstadt * [ldtlib.c] Original by Bob Amstadt * [relay.c] Original by Bob Amstadt * [resource.c] Original by Bob Amstadt, updates by Alexandre Juliard * [selector.c] Original by Bob Amstadt, updates by Eric Youngdale * [user.c] Original by Bob Amstadt * [wine.c] Original by Bob Amstadt, updates by Eric Youngdale and Alexandre Julliard * [wintcl.c] Original by Regents of the University of California, updates by Peter MacDonald and Alexandre Julliard * [callback.h] Original by Bob Amstadt * [dlls.h] Original by Bob Amstadt * [heap.h] Original by Bob Amstadt * [neexe.h] Original by Bob Amstadt * [prototypes.h] Original by Bob Amstadt, updates by Eric Youngdale * [segmem.h] Original by Bob Amstadt * [tkInt.h] Original by Regents of the University of California * [windows.h] Original by Peter MacDonald, updates by Alexandre Julliard and Bob Amstadt * [wine.h] Original by Eric Youngdale * [kernel.spec] Original by Bob Amstadt, updates by Alexandre Julliard * [gdi.spec] Original by Bob Amstadt, updates by Alexandre Julliard * [shell.spec] Original by Bob Amstadt * [unixlib.spec] Original by Bob Amstadt * [user.spec] Original by Bob Amstadt, updates by Alexandre Julliard * [win87em.spec] Original by Bob Amstadt * [Windows.tcl] Original by Peter MacDonald, updates by Alexandre Julliard * [build-spec.txt] Original by Bob Amstadt * [if1632.S] Original by Bob Amstadt, updates by Eric Youngdale
1993-07-15 13:13:45 +02:00
/*
* X events handling functions
*
* Copyright 1993 Alexandre Julliard
*/
static char Copyright[] = "Copyright Alexandre Julliard, 1993";
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Core.h>
#include "windows.h"
#define NB_BUTTONS 3 /* Windows can handle 3 buttons */
#define DBLCLICK_TIME 300 /* Max. time for a double click (milliseconds) */
/* Event handlers */
static void EVENT_expose();
static void EVENT_key();
static void EVENT_mouse_motion();
static void EVENT_mouse_button();
/***********************************************************************
* EVENT_AddHandlers
*
* Add the event handlers to the given window
*/
void EVENT_AddHandlers( Widget w, int hwnd )
{
XtAddEventHandler(w, ExposureMask, FALSE,
EVENT_expose, (XtPointer)hwnd );
XtAddEventHandler(w, KeyPressMask | KeyReleaseMask, FALSE,
EVENT_key, (XtPointer)hwnd );
XtAddEventHandler(w, PointerMotionMask, FALSE,
EVENT_mouse_motion, (XtPointer)hwnd );
XtAddEventHandler(w, ButtonPressMask | ButtonReleaseMask, FALSE,
EVENT_mouse_button, (XtPointer)hwnd );
}
/***********************************************************************
* EVENT_RemoveHandlers
*
* Remove the event handlers of the given window
*/
void EVENT_RemoveHandlers( Widget w, int hwnd )
{
XtRemoveEventHandler(w, ExposureMask, FALSE,
EVENT_expose, (XtPointer)hwnd );
XtRemoveEventHandler(w, KeyPressMask | KeyReleaseMask, FALSE,
EVENT_key, (XtPointer)hwnd );
XtRemoveEventHandler(w, PointerMotionMask, FALSE,
EVENT_mouse_motion, (XtPointer)hwnd );
XtRemoveEventHandler(w, ButtonPressMask | ButtonReleaseMask, FALSE,
EVENT_mouse_button, (XtPointer)hwnd );
}
/***********************************************************************
* EVENT_XStateToKeyState
*
* Translate a X event state (Button1Mask, ShiftMask, etc...) to
* a Windows key state (MK_SHIFT, MK_CONTROL, etc...)
*/
static WORD EVENT_XStateToKeyState( int state )
{
int kstate = 0;
if (state & Button1Mask) kstate |= MK_LBUTTON;
if (state & Button2Mask) kstate |= MK_MBUTTON;
if (state & Button3Mask) kstate |= MK_RBUTTON;
if (state & ShiftMask) kstate |= MK_SHIFT;
if (state & ControlMask) kstate |= MK_CONTROL;
return kstate;
}
/***********************************************************************
* EVENT_expose
*
* Handle a X expose event
*/
static void EVENT_expose( Widget w, int hwnd, XEvent *event,
Boolean *cont_dispatch )
{
MSG msg;
XExposeEvent * expEvt = (XExposeEvent *)expEvt;
msg.hwnd = hwnd;
msg.message = WM_PAINT;
msg.wParam = 0;
msg.lParam = 0;
msg.time = 0;
msg.pt.x = 0;
msg.pt.y = 0;
MSG_AddMsg( &msg, 0 );
}
/***********************************************************************
* EVENT_key
*
* Handle a X key event
*/
static void EVENT_key( Widget w, int hwnd, XKeyEvent *event,
Boolean *cont_dispatch )
{
MSG msg;
msg.hwnd = hwnd;
msg.message = (event->type == KeyRelease) ? WM_KEYUP : WM_KEYDOWN;
msg.wParam = 0;
msg.lParam = (event->x & 0xffff) | (event->y << 16);
msg.time = event->time;
msg.pt.x = event->x & 0xffff;
msg.pt.y = event->y & 0xffff;
MSG_AddMsg( &msg );
}
/***********************************************************************
* EVENT_mouse_motion
*
* Handle a X mouse motion event
*/
static void EVENT_mouse_motion( Widget w, int hwnd, XMotionEvent *event,
Boolean *cont_dispatch )
{
MSG msg;
msg.hwnd = hwnd;
msg.message = WM_MOUSEMOVE;
msg.wParam = EVENT_XStateToKeyState( event->state );
msg.lParam = (event->x & 0xffff) | (event->y << 16);
msg.time = event->time;
msg.pt.x = event->x & 0xffff;
msg.pt.y = event->y & 0xffff;
MSG_AddMsg( &msg );
}
/***********************************************************************
* EVENT_mouse_button
*
* Handle a X mouse button event
*/
static void EVENT_mouse_button( Widget w, int hwnd, XButtonEvent *event,
Boolean *cont_dispatch )
{
static WORD messages[3][NB_BUTTONS] =
{
{ WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN },
{ WM_LBUTTONUP, WM_MBUTTONUP, WM_RBUTTONUP },
{ WM_LBUTTONDBLCLK, WM_MBUTTONDBLCLK, WM_RBUTTONDBLCLK }
};
static unsigned long lastClickTime[NB_BUTTONS] = { 0, 0, 0 };
MSG msg;
int buttonNum, prevTime, type;
buttonNum = event->button-1;
if (buttonNum >= NB_BUTTONS) return;
if (event->type == ButtonRelease) type = 1;
else
{ /* Check if double-click */
prevTime = lastClickTime[buttonNum];
lastClickTime[buttonNum] = event->time;
type = (event->time - prevTime < DBLCLICK_TIME) ? 2 : 0;
}
msg.hwnd = hwnd;
msg.message = messages[type][buttonNum];
msg.wParam = EVENT_XStateToKeyState( event->state );
msg.lParam = (event->x & 0xffff) | (event->y << 16);
msg.time = event->time;
msg.pt.x = event->x & 0xffff;
msg.pt.y = event->y & 0xffff;
MSG_AddMsg( &msg );
}