Protect Win32 GDISP driver from some strange config file configurations

This commit is contained in:
inmarket 2016-10-01 18:11:12 +10:00
parent 81505c8be2
commit 0d1741a52e

View File

@ -80,7 +80,7 @@
#define GDISP_FLG_WRAPPED (GDISP_FLG_DRIVER<<4)
#endif
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
/* Include toggle support code */
#include "../../../src/ginput/ginput_driver_toggle.h"
@ -88,7 +88,7 @@
static GDisplay *toggleWindow;
#endif
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
// Include mouse support code
#define GMOUSE_DRIVER_VMT GMOUSEVMT_Win32
#include "../../../src/ginput/ginput_driver_mouse.h"
@ -130,7 +130,7 @@
}};
#endif
#if GINPUT_NEED_KEYBOARD
#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD
#define GKEYBOARD_DRIVER_VMT GKEYBOARDVMT_Win32
#include "../../../src/ginput/ginput_driver_keyboard.h"
@ -422,7 +422,7 @@ static HWND hWndParent = 0;
/* Driver local routines . */
/*===========================================================================*/
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
#define WIN32_BUTTON_AREA 16
#else
#define WIN32_BUTTON_AREA 0
@ -435,14 +435,14 @@ typedef struct winPriv {
HDC dcBuffer;
HBITMAP dcBitmap;
HBITMAP dcOldBitmap;
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
coord_t mousex, mousey;
uint16_t mousebuttons;
GMouse *mouse;
bool_t mouseenabled;
void (*capfn)(HWND hWnd, GDisplay *g, uint16_t buttons, coord_t x, coord_t y);
#endif
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
uint8_t toggles;
#endif
#if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
@ -455,7 +455,7 @@ void gfxEmulatorSetParentWindow(HWND hwnd) {
hWndParent = hwnd;
}
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
void gfxEmulatorMouseInject(GDisplay *g, uint16_t buttons, coord_t x, coord_t y) {
winPriv * priv;
@ -480,10 +480,10 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
PAINTSTRUCT ps;
GDisplay * g;
winPriv * priv;
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
uint16_t btns;
#endif
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
HBRUSH hbrOn, hbrOff;
HPEN pen;
RECT rect;
@ -512,7 +512,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
g->flags |= GDISP_FLG_READY;
break;
#if GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && (GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE)
case WM_LBUTTONDOWN:
// Get our GDisplay structure
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
@ -579,7 +579,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
break;
#endif
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
case WM_MBUTTONDOWN:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
@ -636,7 +636,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
break;
#endif
#if GINPUT_NEED_KEYBOARD
#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
@ -694,7 +694,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
priv->dcBuffer, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
// Paint the toggle area
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
if (ps.rcPaint.bottom >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) {
pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
hbrOn = CreateSolidBrush(RGB(0, 0, 255));
@ -791,7 +791,7 @@ static DWORD WINAPI WindowThread(void *param) {
// Set the window rectangle
rect.top = 0; rect.bottom = g->g.Height;
rect.left = 0; rect.right = g->g.Width;
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
if ((g->flags & GDISP_FLG_HASTOGGLE))
rect.bottom += WIN32_BUTTON_AREA;
#endif
@ -851,7 +851,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
g->g.Height = GDISP_SCREEN_HEIGHT;
// Turn on toggles for the first GINPUT_TOGGLE_CONFIG_ENTRIES windows
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
if (g->controllerdisplay < GINPUT_TOGGLE_CONFIG_ENTRIES) {
g->flags |= GDISP_FLG_HASTOGGLE;
toggleWindow = g;
@ -877,7 +877,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
Sleep(1);
// Create the associated mouse
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
priv->mouseenabled = hWndParent ? FALSE : TRUE;
priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
#endif
@ -1544,7 +1544,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
#endif
#if GINPUT_NEED_MOUSE
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance) {
(void) m;
(void) driverinstance;
@ -1593,7 +1593,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
#endif /* GINPUT_NEED_MOUSE */
#if GINPUT_NEED_KEYBOARD
#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD
static bool_t Win32KeyboardInit(GKeyboard *k, unsigned driverinstance) {
(void) driverinstance;
@ -1621,7 +1621,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
#endif
#if GINPUT_NEED_TOGGLE
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
#if GINPUT_TOGGLE_CONFIG_ENTRIES > 1
#error "GDISP Win32: GINPUT_TOGGLE_CONFIG_ENTRIES must be 1 until Toggles can use GDriver"
#endif