#pragma pack(?) changed to #include "*pack*.h"
[wine] / windows / mouse.c
1 /*
2  * MOUSE driver
3  * 
4  * Copyright 1998 Ulrich Weigand
5  * 
6  */
7
8 #include "debug.h"
9 #include "mouse.h"
10 #include "monitor.h"
11 #include "winuser.h"
12 #include "win.h"
13
14 DEFAULT_DEBUG_CHANNEL(event)
15
16 /**********************************************************************/
17
18 MOUSE_DRIVER *MOUSE_Driver = NULL;
19
20 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
21
22 /***********************************************************************
23  *           MOUSE_Inquire                       (MOUSE.1)
24  */
25 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
26 {
27     mouseInfo->msExist = TRUE;
28     mouseInfo->msRelative = FALSE;
29     mouseInfo->msNumButtons = 2;
30     mouseInfo->msRate = 34;  /* the DDK says so ... */
31     mouseInfo->msXThreshold = 0;
32     mouseInfo->msYThreshold = 0;
33     mouseInfo->msXRes = 0;
34     mouseInfo->msYRes = 0;
35     mouseInfo->msMouseCommPort = 0;
36
37     return sizeof(MOUSEINFO);
38 }
39
40 /***********************************************************************
41  *           MOUSE_Enable                        (MOUSE.2)
42  */
43 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
44 {
45     DefMouseEventProc = lpMouseEventProc;
46 }
47
48 /***********************************************************************
49  *           MOUSE_Disable                       (MOUSE.3)
50  */
51 VOID WINAPI MOUSE_Disable(VOID)
52 {
53     DefMouseEventProc = 0;
54 }
55
56 /***********************************************************************
57  *           MOUSE_SendEvent
58  */
59 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY, 
60                       DWORD keyState, DWORD time, HWND hWnd )
61 {
62     int width  = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
63     int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
64     int iWndsLocks;
65     WINE_MOUSEEVENT wme;
66     BOOL bOldWarpPointer;
67
68     if ( !DefMouseEventProc ) return;
69
70     TRACE( event, "(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
71
72     mouseStatus |= MOUSEEVENTF_ABSOLUTE;
73     posX = (((long)posX << 16) + width-1)  / width;
74     posY = (((long)posY << 16) + height-1) / height;
75
76     wme.magic    = WINE_MOUSEEVENT_MAGIC;
77     wme.keyState = keyState;
78     wme.time     = time;
79     wme.hWnd     = hWnd;
80
81     bOldWarpPointer = MOUSE_Driver->pEnableWarpPointer(FALSE);
82     /* To avoid deadlocks, we have to suspend all locks on windows structures
83        before the program control is passed to the mouse driver */
84     iWndsLocks = WIN_SuspendWndsLock();
85     DefMouseEventProc( mouseStatus, posX, posY, 0, (DWORD)&wme );
86     WIN_RestoreWndsLock(iWndsLocks);
87     MOUSE_Driver->pEnableWarpPointer(bOldWarpPointer);
88 }