Commit a65ef561 authored by Jukka Heinonen's avatar Jukka Heinonen Committed by Alexandre Julliard

Console mode DOS programs now receive mouse events.

Replaced GetMessage with PeekMessage, since MsgWaitForMultipleObjects is allowed to return spontaneously.
parent 53338721
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "wine/windef16.h" #include "wine/windef16.h"
#include "winbase.h" /* for LPSTARTUPINFO32A */ #include "winbase.h" /* for LPSTARTUPINFO32A */
#include "winnt.h" /* for PCONTEXT */ #include "winnt.h" /* for PCONTEXT */
#include "wincon.h" /* for MOUSE_EVENT_RECORD */
struct _DOSEVENT; struct _DOSEVENT;
...@@ -105,6 +106,7 @@ extern void WINAPI DOSVM_Int31Handler(CONTEXT86*); ...@@ -105,6 +106,7 @@ extern void WINAPI DOSVM_Int31Handler(CONTEXT86*);
/* int33.c */ /* int33.c */
extern void WINAPI DOSVM_Int33Handler(CONTEXT86*); extern void WINAPI DOSVM_Int33Handler(CONTEXT86*);
extern void WINAPI DOSVM_Int33Message(UINT,WPARAM,LPARAM); extern void WINAPI DOSVM_Int33Message(UINT,WPARAM,LPARAM);
extern void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD*);
/* int67.c */ /* int67.c */
extern void WINAPI DOSVM_Int67Handler(CONTEXT86*); extern void WINAPI DOSVM_Int67Handler(CONTEXT86*);
......
...@@ -245,8 +245,20 @@ static void DOSVM_ProcessConsole(void) ...@@ -245,8 +245,20 @@ static void DOSVM_ProcessConsole(void)
} }
DOSVM_Int09SendScan(scan,msg.Event.KeyEvent.uChar.AsciiChar); DOSVM_Int09SendScan(scan,msg.Event.KeyEvent.uChar.AsciiChar);
break; break;
case MOUSE_EVENT:
DOSVM_Int33Console(&msg.Event.MouseEvent);
break;
case WINDOW_BUFFER_SIZE_EVENT:
FIXME("unhandled WINDOW_BUFFER_SIZE_EVENT.\n");
break;
case MENU_EVENT:
FIXME("unhandled MENU_EVENT.\n");
break;
case FOCUS_EVENT:
FIXME("unhandled FOCUS_EVENT.\n");
break;
default: default:
FIXME("unhandled console event: %d\n", msg.EventType); FIXME("unknown console event: %d\n", msg.EventType);
} }
} }
} }
...@@ -358,40 +370,44 @@ DWORD WINAPI DOSVM_Loop( LPVOID lpExtra ) ...@@ -358,40 +370,44 @@ DWORD WINAPI DOSVM_Loop( LPVOID lpExtra )
DWORD waitret; DWORD waitret;
for(;;) { for(;;) {
TRACE_(int)("waiting for action\n"); TRACE_(int)("waiting for action\n");
waitret = MsgWaitForMultipleObjects(1, &obj, FALSE, INFINITE, QS_ALLINPUT); waitret = MsgWaitForMultipleObjects(1, &obj, FALSE, INFINITE, QS_ALLINPUT);
if (waitret == WAIT_OBJECT_0) { if (waitret == WAIT_OBJECT_0) {
DOSVM_ProcessConsole(); DOSVM_ProcessConsole();
} }
else if (waitret == WAIT_OBJECT_0 + 1) { else if (waitret == WAIT_OBJECT_0 + 1) {
GetMessageA(&msg, 0, 0, 0); while (PeekMessageA(&msg,0,0,0,PM_REMOVE)) {
if (msg.hwnd) { if (msg.hwnd) {
/* it's a window message */ /* it's a window message */
DOSVM_ProcessMessage(&msg); DOSVM_ProcessMessage(&msg);
DispatchMessageA(&msg); DispatchMessageA(&msg);
} else { } else {
/* it's a thread message */ /* it's a thread message */
switch (msg.message) { switch (msg.message) {
case WM_QUIT: case WM_QUIT:
/* stop this madness!! */ /* stop this madness!! */
return 0; return 0;
case WM_USER: case WM_USER:
/* run passed procedure in this thread */ /* run passed procedure in this thread */
/* (sort of like APC, but we signal the completion) */ /* (sort of like APC, but we signal the completion) */
{ {
DOS_SPC *spc = (DOS_SPC *)msg.lParam; DOS_SPC *spc = (DOS_SPC *)msg.lParam;
TRACE_(int)("calling %p with arg %08x\n", spc->proc, spc->arg); TRACE_(int)("calling %p with arg %08x\n", spc->proc, spc->arg);
(spc->proc)(spc->arg); (spc->proc)(spc->arg);
TRACE_(int)("done, signalling event %d\n", msg.wParam); TRACE_(int)("done, signalling event %d\n", msg.wParam);
SetEvent(msg.wParam); SetEvent(msg.wParam);
} }
break; break;
} }
}
}
}
else
{
ERR_(int)("MsgWaitForMultipleObjects returned unexpected value.\n");
return 0;
} }
}
else break;
} }
return 0;
} }
static WINE_EXCEPTION_FILTER(exception_handler) static WINE_EXCEPTION_FILTER(exception_handler)
......
...@@ -65,7 +65,8 @@ void WINAPI DOSVM_Int33Handler( CONTEXT86 *context ) ...@@ -65,7 +65,8 @@ void WINAPI DOSVM_Int33Handler( CONTEXT86 *context )
FIXME("Hide mouse cursor\n"); FIXME("Hide mouse cursor\n");
break; break;
case 0x03: case 0x03:
TRACE("Return mouse position and button status\n"); TRACE("Return mouse position and button status: (%ld,%ld) and %ld\n",
mouse_info.x, mouse_info.y, mouse_info.but);
BX_reg(context) = mouse_info.but; BX_reg(context) = mouse_info.but;
CX_reg(context) = mouse_info.x; CX_reg(context) = mouse_info.x;
DX_reg(context) = mouse_info.y; DX_reg(context) = mouse_info.y;
...@@ -148,6 +149,58 @@ static void MouseRelay(CONTEXT86 *context,void *mdata) ...@@ -148,6 +149,58 @@ static void MouseRelay(CONTEXT86 *context,void *mdata)
DPMI_CallRMProc(&ctx, NULL, 0, 0); DPMI_CallRMProc(&ctx, NULL, 0, 0);
} }
static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
{
mouse_info.x = mx;
mouse_info.y = my;
/* Left button down */
if(mask & 0x02) {
mouse_info.but |= 0x01;
mouse_info.llastx = mx;
mouse_info.llasty = my;
mouse_info.lbcount++;
}
/* Left button up */
if(mask & 0x04) {
mouse_info.but &= ~0x01;
}
/* Right button down */
if(mask & 0x08) {
mouse_info.but |= 0x02;
mouse_info.rlastx = mx;
mouse_info.rlasty = my;
mouse_info.rbcount++;
}
/* Right button up */
if(mask & 0x10) {
mouse_info.but &= ~0x02;
}
/* Middle button down */
if(mask & 0x20) {
mouse_info.but |= 0x04;
}
/* Middle button up */
if(mask & 0x40) {
mouse_info.but &= ~0x04;
}
if ((mask & mouse_info.callmask) && mouse_info.callback) {
MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
data->proc = mouse_info.callback;
data->mask = mask & mouse_info.callmask;
data->but = mouse_info.but;
data->x = mouse_info.x;
data->y = mouse_info.y;
DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
}
}
void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam) void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
{ {
WORD mask = 0; WORD mask = 0;
...@@ -159,54 +212,68 @@ void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam) ...@@ -159,54 +212,68 @@ void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
SX = 640/Width; SX = 640/Width;
if (!SX) SX=1; if (!SX) SX=1;
} }
mouse_info.x = LOWORD(lParam) * SX;
mouse_info.y = HIWORD(lParam) * SY;
switch (message) { switch (message) {
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
mask |= 0x01; mask |= 0x01;
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
mouse_info.but |= 0x01;
mask |= 0x02; mask |= 0x02;
mouse_info.llastx = mouse_info.x;
mouse_info.llasty = mouse_info.y;
mouse_info.lbcount++;
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
mouse_info.but &= ~0x01;
mask |= 0x04; mask |= 0x04;
break; break;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
mouse_info.but |= 0x02;
mask |= 0x08; mask |= 0x08;
mouse_info.rlastx = mouse_info.x;
mouse_info.rlasty = mouse_info.y;
mouse_info.rbcount++;
break; break;
case WM_RBUTTONUP: case WM_RBUTTONUP:
mouse_info.but &= ~0x02;
mask |= 0x10; mask |= 0x10;
break; break;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
case WM_MBUTTONDBLCLK: case WM_MBUTTONDBLCLK:
mouse_info.but |= 0x04;
mask |= 0x20; mask |= 0x20;
break; break;
case WM_MBUTTONUP: case WM_MBUTTONUP:
mouse_info.but &= ~0x04;
mask |= 0x40; mask |= 0x40;
break; break;
} }
if ((mask & mouse_info.callmask) && mouse_info.callback) { QueueMouseRelay(LOWORD(lParam) * SX,
MCALLDATA *data = calloc(1,sizeof(MCALLDATA)); HIWORD(lParam) * SY,
data->proc = mouse_info.callback; mask);
data->mask = mask & mouse_info.callmask; }
data->but = mouse_info.but;
data->x = mouse_info.x; void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
data->y = mouse_info.y; {
DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data); unsigned Height, Width;
} WORD mask = 0;
BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
BOOL oldLeftButton = mouse_info.but & 0x01;
BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
BOOL oldRightButton = mouse_info.but & 0x02;
BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
BOOL oldMiddleButton = mouse_info.but & 0x04;
if(newLeftButton && !oldLeftButton)
mask |= 0x02;
else if(!newLeftButton && oldLeftButton)
mask |= 0x04;
if(newRightButton && !oldRightButton)
mask |= 0x08;
else if(!newRightButton && oldRightButton)
mask |= 0x10;
if(newMiddleButton && !oldMiddleButton)
mask |= 0x20;
else if(!newMiddleButton && oldMiddleButton)
mask |= 0x40;
VGA_GetAlphaMode(&Width, &Height);
QueueMouseRelay(640 / Width * record->dwMousePosition.X,
200 / Height * record->dwMousePosition.Y,
mask);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment