Fixed a small bug in the behavior of maximized MDI children.
[wine] / windows / mouse.c
1 /*
2  * MOUSE driver
3  * 
4  * Copyright 1998 Ulrich Weigand
5  * 
6  */
7
8 #include <string.h>
9
10 #include "debugtools.h"
11 #include "callback.h"
12 #include "builtin16.h"
13 #include "mouse.h"
14 #include "monitor.h"
15 #include "winuser.h"
16 #include "win.h"
17
18 DEFAULT_DEBUG_CHANNEL(event)
19
20 /**********************************************************************/
21
22 MOUSE_DRIVER *MOUSE_Driver = NULL;
23
24 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
25
26 /***********************************************************************
27  *           MOUSE_Inquire                       (MOUSE.1)
28  */
29 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
30 {
31     mouseInfo->msExist = TRUE;
32     mouseInfo->msRelative = FALSE;
33     mouseInfo->msNumButtons = 2;
34     mouseInfo->msRate = 34;  /* the DDK says so ... */
35     mouseInfo->msXThreshold = 0;
36     mouseInfo->msYThreshold = 0;
37     mouseInfo->msXRes = 0;
38     mouseInfo->msYRes = 0;
39     mouseInfo->msMouseCommPort = 0;
40
41     return sizeof(MOUSEINFO);
42 }
43
44 /***********************************************************************
45  *           MOUSE_Enable                        (MOUSE.2)
46  */
47 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
48 {
49     THUNK_Free( (FARPROC)DefMouseEventProc );
50     DefMouseEventProc = lpMouseEventProc;
51 }
52
53 static VOID WINAPI MOUSE_CallMouseEventProc( FARPROC16 proc,
54                                              DWORD dwFlags, DWORD dx, DWORD dy,
55                                              DWORD cButtons, DWORD dwExtraInfo )
56 {
57     CONTEXT86 context;
58
59     memset( &context, 0, sizeof(context) );
60     CS_reg(&context)  = SELECTOROF( proc );
61     EIP_reg(&context) = OFFSETOF( proc );
62     AX_reg(&context)  = (WORD)dwFlags;
63     BX_reg(&context)  = (WORD)dx;
64     CX_reg(&context)  = (WORD)dy;
65     DX_reg(&context)  = (WORD)cButtons;
66     SI_reg(&context)  = LOWORD( dwExtraInfo );
67     DI_reg(&context)  = HIWORD( dwExtraInfo );
68
69     CallTo16RegisterShort( &context, 0 );
70 }
71
72 VOID WINAPI WIN16_MOUSE_Enable( FARPROC16 proc )
73 {
74     LPMOUSE_EVENT_PROC thunk = 
75       (LPMOUSE_EVENT_PROC)THUNK_Alloc( proc, (RELAY)MOUSE_CallMouseEventProc );
76
77     MOUSE_Enable( thunk );
78 }
79
80 /***********************************************************************
81  *           MOUSE_Disable                       (MOUSE.3)
82  */
83 VOID WINAPI MOUSE_Disable(VOID)
84 {
85     THUNK_Free( (FARPROC)DefMouseEventProc );
86     DefMouseEventProc = 0;
87 }
88
89 /***********************************************************************
90  *           MOUSE_SendEvent
91  */
92 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY, 
93                       DWORD keyState, DWORD time, HWND hWnd )
94 {
95     int width  = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
96     int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
97     int iWndsLocks;
98     WINE_MOUSEEVENT wme;
99     BOOL bOldWarpPointer;
100
101     if ( !DefMouseEventProc ) return;
102
103     TRACE("(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
104
105     mouseStatus |= MOUSEEVENTF_ABSOLUTE;
106     posX = (((long)posX << 16) + width-1)  / width;
107     posY = (((long)posY << 16) + height-1) / height;
108
109     wme.magic    = WINE_MOUSEEVENT_MAGIC;
110     wme.keyState = keyState;
111     wme.time     = time;
112     wme.hWnd     = hWnd;
113
114     bOldWarpPointer = MOUSE_Driver->pEnableWarpPointer(FALSE);
115     /* To avoid deadlocks, we have to suspend all locks on windows structures
116        before the program control is passed to the mouse driver */
117     iWndsLocks = WIN_SuspendWndsLock();
118     DefMouseEventProc( mouseStatus, posX, posY, 0, (DWORD)&wme );
119     WIN_RestoreWndsLock(iWndsLocks);
120     MOUSE_Driver->pEnableWarpPointer(bOldWarpPointer);
121 }