src/video/windib/SDL_dibevents.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 Feb 2006 08:46:50 +0000
changeset 1402 d910939febfa
parent 1379 c0a74f199ecf
child 1433 bb6839704ed6
permissions -rw-r--r--
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@1330
    24
#include "SDL_windows.h"
slouken@0
    25
slouken@1358
    26
#include "SDL_main.h"
slouken@0
    27
#include "SDL_events.h"
slouken@0
    28
#include "SDL_syswm.h"
slouken@1361
    29
#include "../../events/SDL_sysevents.h"
slouken@1361
    30
#include "../../events/SDL_events_c.h"
slouken@1361
    31
#include "../wincommon/SDL_lowvideo.h"
slouken@0
    32
#include "SDL_dibvideo.h"
slouken@0
    33
#include "SDL_vkeys.h"
slouken@0
    34
slouken@0
    35
#ifndef WM_APP
slouken@0
    36
#define WM_APP	0x8000
slouken@0
    37
#endif
slouken@0
    38
slouken@0
    39
#ifdef _WIN32_WCE
slouken@0
    40
#define NO_GETKEYBOARDSTATE
slouken@0
    41
#endif
slouken@0
    42
slouken@0
    43
/* The translation table from a Microsoft VK keysym to a SDL keysym */
slouken@0
    44
static SDLKey VK_keymap[SDLK_LAST];
slouken@0
    45
static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed);
slouken@0
    46
slouken@0
    47
/* Masks for processing the windows KEYDOWN and KEYUP messages */
slouken@0
    48
#define REPEATED_KEYMASK	(1<<30)
slouken@0
    49
#define EXTENDED_KEYMASK	(1<<24)
slouken@0
    50
slouken@145
    51
/* DJM: If the user setup the window for us, we want to save his window proc,
slouken@145
    52
   and give him a chance to handle some messages. */
slouken@1303
    53
#ifdef STRICT
slouken@1303
    54
#define WNDPROCTYPE	WNDPROC
slouken@1303
    55
#else
slouken@1303
    56
#define WNDPROCTYPE	FARPROC
slouken@1303
    57
#endif
slouken@1303
    58
static WNDPROCTYPE userWindowProc = NULL;
slouken@145
    59
icculus@1251
    60
icculus@1251
    61
#ifdef _WIN32_WCE
icculus@1251
    62
icculus@1251
    63
WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction) 
icculus@1251
    64
{
icculus@1251
    65
	if (direction != SDL_ORIENTATION_LEFT)
icculus@1251
    66
		return key;
icculus@1251
    67
icculus@1251
    68
	switch (key) {
icculus@1251
    69
		case 0x26: /* up */
icculus@1251
    70
			return 0x27;
icculus@1251
    71
		case 0x27: /* right */
icculus@1251
    72
			return 0x28;
icculus@1251
    73
		case 0x28: /* down */
icculus@1251
    74
			return 0x25;
icculus@1251
    75
		case 0x25: /* left */
icculus@1251
    76
			return 0x26;
icculus@1251
    77
	}
icculus@1251
    78
icculus@1251
    79
	return key;
icculus@1251
    80
}
icculus@1251
    81
icculus@1251
    82
#endif 
icculus@1251
    83
icculus@1251
    84
slouken@0
    85
/* The main Win32 event handler */
slouken@0
    86
LONG
slouken@0
    87
 DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@0
    88
{
slouken@0
    89
	extern int posted;
slouken@0
    90
slouken@0
    91
	switch (msg) {
slouken@0
    92
		case WM_SYSKEYDOWN:
slouken@0
    93
		case WM_KEYDOWN: {
slouken@0
    94
			SDL_keysym keysym;
slouken@0
    95
icculus@1251
    96
#ifdef _WIN32_WCE
icculus@1251
    97
			// Drop GAPI artefacts
icculus@1251
    98
			if (wParam == 0x84 || wParam == 0x5B)
icculus@1251
    99
				return 0;
icculus@1251
   100
icculus@1251
   101
			// Rotate key if necessary
icculus@1251
   102
			if (this->hidden->orientation != SDL_ORIENTATION_UP)
icculus@1251
   103
				wParam = rotateKey(wParam, this->hidden->orientation);	
icculus@1251
   104
#endif 
slouken@0
   105
			/* Ignore repeated keys */
slouken@0
   106
			if ( lParam&REPEATED_KEYMASK ) {
slouken@0
   107
				return(0);
slouken@0
   108
			}
slouken@0
   109
			switch (wParam) {
slouken@0
   110
				case VK_CONTROL:
slouken@0
   111
					if ( lParam&EXTENDED_KEYMASK )
slouken@0
   112
						wParam = VK_RCONTROL;
slouken@0
   113
					else
slouken@0
   114
						wParam = VK_LCONTROL;
slouken@0
   115
					break;
slouken@0
   116
				case VK_SHIFT:
slouken@0
   117
					/* EXTENDED trick doesn't work here */
slouken@1282
   118
					{
slouken@1282
   119
					Uint8 *state = SDL_GetKeyState(NULL);
slouken@1282
   120
					if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) {
slouken@558
   121
						wParam = VK_LSHIFT;
slouken@1282
   122
					} else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) {
slouken@558
   123
						wParam = VK_RSHIFT;
slouken@558
   124
					} else {
slouken@1282
   125
						/* Probably a key repeat */
slouken@1282
   126
						return(0);
slouken@1282
   127
					}
slouken@558
   128
					}
slouken@0
   129
					break;
slouken@0
   130
				case VK_MENU:
slouken@0
   131
					if ( lParam&EXTENDED_KEYMASK )
slouken@0
   132
						wParam = VK_RMENU;
slouken@0
   133
					else
slouken@0
   134
						wParam = VK_LMENU;
slouken@0
   135
					break;
slouken@0
   136
			}
slouken@112
   137
#ifdef NO_GETKEYBOARDSTATE
slouken@112
   138
			/* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */
slouken@112
   139
			if ( SDL_TranslateUNICODE ) {
slouken@140
   140
				MSG m;
slouken@112
   141
slouken@140
   142
				m.hwnd = hwnd;
slouken@140
   143
				m.message = msg;
slouken@140
   144
				m.wParam = wParam;
slouken@140
   145
				m.lParam = lParam;
slouken@140
   146
				m.time = 0;
slouken@140
   147
				if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
slouken@112
   148
					GetMessage(&m, hwnd, 0, WM_USER);
slouken@112
   149
			    		wParam = m.wParam;
slouken@112
   150
				}
slouken@112
   151
			}
slouken@112
   152
#endif /* NO_GETKEYBOARDSTATE */
slouken@0
   153
			posted = SDL_PrivateKeyboard(SDL_PRESSED,
slouken@0
   154
				TranslateKey(wParam,HIWORD(lParam),&keysym,1));
slouken@0
   155
		}
slouken@0
   156
		return(0);
slouken@0
   157
slouken@0
   158
		case WM_SYSKEYUP:
slouken@0
   159
		case WM_KEYUP: {
slouken@0
   160
			SDL_keysym keysym;
slouken@0
   161
icculus@1251
   162
#ifdef _WIN32_WCE
icculus@1251
   163
			// Drop GAPI artefacts
icculus@1251
   164
			if (wParam == 0x84 || wParam == 0x5B)
icculus@1251
   165
				return 0;
icculus@1251
   166
icculus@1251
   167
			// Rotate key if necessary
icculus@1251
   168
			if (this->hidden->orientation != SDL_ORIENTATION_UP)
icculus@1251
   169
				wParam = rotateKey(wParam, this->hidden->orientation);	
icculus@1251
   170
#endif
icculus@1251
   171
slouken@0
   172
			switch (wParam) {
slouken@0
   173
				case VK_CONTROL:
slouken@0
   174
					if ( lParam&EXTENDED_KEYMASK )
slouken@0
   175
						wParam = VK_RCONTROL;
slouken@0
   176
					else
slouken@0
   177
						wParam = VK_LCONTROL;
slouken@0
   178
					break;
slouken@0
   179
				case VK_SHIFT:
slouken@0
   180
					/* EXTENDED trick doesn't work here */
slouken@1282
   181
					{
slouken@1282
   182
					Uint8 *state = SDL_GetKeyState(NULL);
slouken@1282
   183
					if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
slouken@572
   184
						wParam = VK_LSHIFT;
slouken@1282
   185
					} else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
slouken@572
   186
						wParam = VK_RSHIFT;
slouken@572
   187
					} else {
slouken@1282
   188
						/* Probably a key repeat */
slouken@1282
   189
						return(0);
slouken@1282
   190
					}
slouken@572
   191
					}
slouken@0
   192
					break;
slouken@0
   193
				case VK_MENU:
slouken@0
   194
					if ( lParam&EXTENDED_KEYMASK )
slouken@0
   195
						wParam = VK_RMENU;
slouken@0
   196
					else
slouken@0
   197
						wParam = VK_LMENU;
slouken@0
   198
					break;
slouken@0
   199
			}
slouken@0
   200
			posted = SDL_PrivateKeyboard(SDL_RELEASED,
slouken@0
   201
				TranslateKey(wParam,HIWORD(lParam),&keysym,0));
slouken@0
   202
		}
slouken@0
   203
		return(0);
slouken@0
   204
icculus@726
   205
#if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
icculus@726
   206
		case WM_SYSCOMMAND: {
icculus@726
   207
			if ((wParam&0xFFF0)==SC_SCREENSAVE ||
icculus@726
   208
				(wParam&0xFFF0)==SC_MONITORPOWER)
icculus@726
   209
					return(0);
icculus@726
   210
		}
icculus@726
   211
		/* Fall through to default processing */
icculus@726
   212
#endif /* SC_SCREENSAVE && SC_MONITORPOWER */
icculus@726
   213
slouken@0
   214
		default: {
slouken@0
   215
			/* Only post the event if we're watching for it */
slouken@0
   216
			if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
slouken@0
   217
			        SDL_SysWMmsg wmmsg;
slouken@0
   218
slouken@0
   219
				SDL_VERSION(&wmmsg.version);
slouken@0
   220
				wmmsg.hwnd = hwnd;
slouken@0
   221
				wmmsg.msg = msg;
slouken@0
   222
				wmmsg.wParam = wParam;
slouken@0
   223
				wmmsg.lParam = lParam;
slouken@0
   224
				posted = SDL_PrivateSysWMEvent(&wmmsg);
slouken@145
   225
slouken@145
   226
			/* DJM: If the user isn't watching for private
slouken@145
   227
				messages in her SDL event loop, then pass it
slouken@145
   228
				along to any win32 specific window proc.
slouken@145
   229
			 */
slouken@145
   230
			} else if (userWindowProc) {
slouken@721
   231
				return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam);
slouken@0
   232
			}
slouken@0
   233
		}
slouken@0
   234
		break;
slouken@0
   235
	}
slouken@0
   236
	return(DefWindowProc(hwnd, msg, wParam, lParam));
slouken@0
   237
}
slouken@0
   238
slouken@0
   239
void DIB_PumpEvents(_THIS)
slouken@0
   240
{
slouken@0
   241
	MSG msg;
slouken@0
   242
slouken@523
   243
	while ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) {
slouken@523
   244
		if ( GetMessage(&msg, NULL, 0, 0) > 0 ) {
slouken@0
   245
			DispatchMessage(&msg);
slouken@0
   246
		}
slouken@0
   247
	}
slouken@0
   248
}
slouken@0
   249
slouken@0
   250
void DIB_InitOSKeymap(_THIS)
slouken@0
   251
{
slouken@0
   252
	int i;
slouken@0
   253
slouken@0
   254
	/* Map the VK keysyms */
slouken@1379
   255
	for ( i=0; i<SDL_arraysize(VK_keymap); ++i )
slouken@0
   256
		VK_keymap[i] = SDLK_UNKNOWN;
slouken@0
   257
slouken@0
   258
	VK_keymap[VK_BACK] = SDLK_BACKSPACE;
slouken@0
   259
	VK_keymap[VK_TAB] = SDLK_TAB;
slouken@0
   260
	VK_keymap[VK_CLEAR] = SDLK_CLEAR;
slouken@0
   261
	VK_keymap[VK_RETURN] = SDLK_RETURN;
slouken@0
   262
	VK_keymap[VK_PAUSE] = SDLK_PAUSE;
slouken@0
   263
	VK_keymap[VK_ESCAPE] = SDLK_ESCAPE;
slouken@0
   264
	VK_keymap[VK_SPACE] = SDLK_SPACE;
slouken@0
   265
	VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE;
slouken@0
   266
	VK_keymap[VK_COMMA] = SDLK_COMMA;
slouken@0
   267
	VK_keymap[VK_MINUS] = SDLK_MINUS;
slouken@0
   268
	VK_keymap[VK_PERIOD] = SDLK_PERIOD;
slouken@0
   269
	VK_keymap[VK_SLASH] = SDLK_SLASH;
slouken@0
   270
	VK_keymap[VK_0] = SDLK_0;
slouken@0
   271
	VK_keymap[VK_1] = SDLK_1;
slouken@0
   272
	VK_keymap[VK_2] = SDLK_2;
slouken@0
   273
	VK_keymap[VK_3] = SDLK_3;
slouken@0
   274
	VK_keymap[VK_4] = SDLK_4;
slouken@0
   275
	VK_keymap[VK_5] = SDLK_5;
slouken@0
   276
	VK_keymap[VK_6] = SDLK_6;
slouken@0
   277
	VK_keymap[VK_7] = SDLK_7;
slouken@0
   278
	VK_keymap[VK_8] = SDLK_8;
slouken@0
   279
	VK_keymap[VK_9] = SDLK_9;
slouken@0
   280
	VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON;
slouken@0
   281
	VK_keymap[VK_EQUALS] = SDLK_EQUALS;
slouken@0
   282
	VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET;
slouken@0
   283
	VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH;
slouken@1253
   284
	VK_keymap[VK_OEM_102] = SDLK_LESS;
slouken@0
   285
	VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET;
slouken@0
   286
	VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE;
slouken@327
   287
	VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE;
slouken@0
   288
	VK_keymap[VK_A] = SDLK_a;
slouken@0
   289
	VK_keymap[VK_B] = SDLK_b;
slouken@0
   290
	VK_keymap[VK_C] = SDLK_c;
slouken@0
   291
	VK_keymap[VK_D] = SDLK_d;
slouken@0
   292
	VK_keymap[VK_E] = SDLK_e;
slouken@0
   293
	VK_keymap[VK_F] = SDLK_f;
slouken@0
   294
	VK_keymap[VK_G] = SDLK_g;
slouken@0
   295
	VK_keymap[VK_H] = SDLK_h;
slouken@0
   296
	VK_keymap[VK_I] = SDLK_i;
slouken@0
   297
	VK_keymap[VK_J] = SDLK_j;
slouken@0
   298
	VK_keymap[VK_K] = SDLK_k;
slouken@0
   299
	VK_keymap[VK_L] = SDLK_l;
slouken@0
   300
	VK_keymap[VK_M] = SDLK_m;
slouken@0
   301
	VK_keymap[VK_N] = SDLK_n;
slouken@0
   302
	VK_keymap[VK_O] = SDLK_o;
slouken@0
   303
	VK_keymap[VK_P] = SDLK_p;
slouken@0
   304
	VK_keymap[VK_Q] = SDLK_q;
slouken@0
   305
	VK_keymap[VK_R] = SDLK_r;
slouken@0
   306
	VK_keymap[VK_S] = SDLK_s;
slouken@0
   307
	VK_keymap[VK_T] = SDLK_t;
slouken@0
   308
	VK_keymap[VK_U] = SDLK_u;
slouken@0
   309
	VK_keymap[VK_V] = SDLK_v;
slouken@0
   310
	VK_keymap[VK_W] = SDLK_w;
slouken@0
   311
	VK_keymap[VK_X] = SDLK_x;
slouken@0
   312
	VK_keymap[VK_Y] = SDLK_y;
slouken@0
   313
	VK_keymap[VK_Z] = SDLK_z;
slouken@0
   314
	VK_keymap[VK_DELETE] = SDLK_DELETE;
slouken@0
   315
slouken@0
   316
	VK_keymap[VK_NUMPAD0] = SDLK_KP0;
slouken@0
   317
	VK_keymap[VK_NUMPAD1] = SDLK_KP1;
slouken@0
   318
	VK_keymap[VK_NUMPAD2] = SDLK_KP2;
slouken@0
   319
	VK_keymap[VK_NUMPAD3] = SDLK_KP3;
slouken@0
   320
	VK_keymap[VK_NUMPAD4] = SDLK_KP4;
slouken@0
   321
	VK_keymap[VK_NUMPAD5] = SDLK_KP5;
slouken@0
   322
	VK_keymap[VK_NUMPAD6] = SDLK_KP6;
slouken@0
   323
	VK_keymap[VK_NUMPAD7] = SDLK_KP7;
slouken@0
   324
	VK_keymap[VK_NUMPAD8] = SDLK_KP8;
slouken@0
   325
	VK_keymap[VK_NUMPAD9] = SDLK_KP9;
slouken@0
   326
	VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD;
slouken@0
   327
	VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE;
slouken@0
   328
	VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY;
slouken@0
   329
	VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS;
slouken@0
   330
	VK_keymap[VK_ADD] = SDLK_KP_PLUS;
slouken@0
   331
slouken@0
   332
	VK_keymap[VK_UP] = SDLK_UP;
slouken@0
   333
	VK_keymap[VK_DOWN] = SDLK_DOWN;
slouken@0
   334
	VK_keymap[VK_RIGHT] = SDLK_RIGHT;
slouken@0
   335
	VK_keymap[VK_LEFT] = SDLK_LEFT;
slouken@0
   336
	VK_keymap[VK_INSERT] = SDLK_INSERT;
slouken@0
   337
	VK_keymap[VK_HOME] = SDLK_HOME;
slouken@0
   338
	VK_keymap[VK_END] = SDLK_END;
slouken@0
   339
	VK_keymap[VK_PRIOR] = SDLK_PAGEUP;
slouken@0
   340
	VK_keymap[VK_NEXT] = SDLK_PAGEDOWN;
slouken@0
   341
slouken@0
   342
	VK_keymap[VK_F1] = SDLK_F1;
slouken@0
   343
	VK_keymap[VK_F2] = SDLK_F2;
slouken@0
   344
	VK_keymap[VK_F3] = SDLK_F3;
slouken@0
   345
	VK_keymap[VK_F4] = SDLK_F4;
slouken@0
   346
	VK_keymap[VK_F5] = SDLK_F5;
slouken@0
   347
	VK_keymap[VK_F6] = SDLK_F6;
slouken@0
   348
	VK_keymap[VK_F7] = SDLK_F7;
slouken@0
   349
	VK_keymap[VK_F8] = SDLK_F8;
slouken@0
   350
	VK_keymap[VK_F9] = SDLK_F9;
slouken@0
   351
	VK_keymap[VK_F10] = SDLK_F10;
slouken@0
   352
	VK_keymap[VK_F11] = SDLK_F11;
slouken@0
   353
	VK_keymap[VK_F12] = SDLK_F12;
slouken@0
   354
	VK_keymap[VK_F13] = SDLK_F13;
slouken@0
   355
	VK_keymap[VK_F14] = SDLK_F14;
slouken@0
   356
	VK_keymap[VK_F15] = SDLK_F15;
slouken@0
   357
slouken@0
   358
	VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK;
slouken@0
   359
	VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK;
slouken@0
   360
	VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK;
slouken@0
   361
	VK_keymap[VK_RSHIFT] = SDLK_RSHIFT;
slouken@0
   362
	VK_keymap[VK_LSHIFT] = SDLK_LSHIFT;
slouken@0
   363
	VK_keymap[VK_RCONTROL] = SDLK_RCTRL;
slouken@0
   364
	VK_keymap[VK_LCONTROL] = SDLK_LCTRL;
slouken@0
   365
	VK_keymap[VK_RMENU] = SDLK_RALT;
slouken@0
   366
	VK_keymap[VK_LMENU] = SDLK_LALT;
slouken@0
   367
	VK_keymap[VK_RWIN] = SDLK_RSUPER;
slouken@0
   368
	VK_keymap[VK_LWIN] = SDLK_LSUPER;
slouken@0
   369
slouken@0
   370
	VK_keymap[VK_HELP] = SDLK_HELP;
slouken@0
   371
#ifdef VK_PRINT
slouken@0
   372
	VK_keymap[VK_PRINT] = SDLK_PRINT;
slouken@0
   373
#endif
slouken@0
   374
	VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
slouken@0
   375
	VK_keymap[VK_CANCEL] = SDLK_BREAK;
slouken@0
   376
	VK_keymap[VK_APPS] = SDLK_MENU;
slouken@0
   377
}
slouken@0
   378
slouken@0
   379
static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed)
slouken@0
   380
{
slouken@0
   381
	/* Set the keysym information */
slouken@0
   382
	keysym->scancode = (unsigned char) scancode;
slouken@0
   383
	keysym->sym = VK_keymap[vkey];
slouken@0
   384
	keysym->mod = KMOD_NONE;
slouken@0
   385
	keysym->unicode = 0;
slouken@1253
   386
	if ( pressed && SDL_TranslateUNICODE ) {
slouken@0
   387
#ifdef NO_GETKEYBOARDSTATE
slouken@0
   388
		/* Uh oh, better hope the vkey is close enough.. */
slouken@0
   389
		keysym->unicode = vkey;
slouken@0
   390
#else
slouken@1253
   391
		BYTE	keystate[256];
slouken@1253
   392
		Uint16	wchars[2];
slouken@0
   393
slouken@0
   394
		GetKeyboardState(keystate);
slouken@1253
   395
		if (SDL_ToUnicode(vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) == 1)
slouken@1253
   396
		{
slouken@1253
   397
			keysym->unicode = wchars[0];
slouken@0
   398
		}
slouken@0
   399
#endif /* NO_GETKEYBOARDSTATE */
slouken@0
   400
	}
slouken@0
   401
	return(keysym);
slouken@0
   402
}
slouken@0
   403
slouken@0
   404
int DIB_CreateWindow(_THIS)
slouken@0
   405
{
slouken@1336
   406
	char *windowid = SDL_getenv("SDL_WINDOWID");
icculus@1152
   407
slouken@1288
   408
	SDL_RegisterApp(NULL, 0, 0);
slouken@1280
   409
slouken@1280
   410
	SDL_windowid = (windowid != NULL);
slouken@0
   411
	if ( SDL_windowid ) {
icculus@1152
   412
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
slouken@1280
   413
		/* wince 2.1 does not have strtol */
slouken@1336
   414
		wchar_t *windowid_t = SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t));
slouken@1336
   415
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, SDL_strlen(windowid) + 1);
slouken@1280
   416
		SDL_Window = (HWND)wcstol(windowid_t, NULL, 0);
slouken@1336
   417
		SDL_free(windowid_t);
icculus@1152
   418
#else
slouken@1336
   419
		SDL_Window = (HWND)SDL_strtol(windowid, NULL, 0);
icculus@1152
   420
#endif
slouken@974
   421
		if ( SDL_Window == NULL ) {
slouken@974
   422
			SDL_SetError("Couldn't get user specified window");
slouken@974
   423
			return(-1);
slouken@974
   424
		}
slouken@974
   425
slouken@974
   426
		/* DJM: we want all event's for the user specified
slouken@974
   427
			window to be handled by SDL.
slouken@974
   428
		 */
slouken@1303
   429
		userWindowProc = (WNDPROCTYPE)GetWindowLong(SDL_Window, GWL_WNDPROC);
slouken@974
   430
		SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)WinMessage);
slouken@0
   431
	} else {
slouken@0
   432
		SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
slouken@0
   433
                        (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX),
slouken@833
   434
                        CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL);
slouken@0
   435
		if ( SDL_Window == NULL ) {
slouken@0
   436
			SDL_SetError("Couldn't create window");
slouken@0
   437
			return(-1);
slouken@0
   438
		}
slouken@0
   439
		ShowWindow(SDL_Window, SW_HIDE);
slouken@0
   440
	}
slouken@0
   441
	return(0);
slouken@0
   442
}
slouken@0
   443
slouken@0
   444
void DIB_DestroyWindow(_THIS)
slouken@0
   445
{
slouken@974
   446
	if ( SDL_windowid ) {
slouken@974
   447
		SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)userWindowProc);
slouken@974
   448
	} else {
slouken@0
   449
		DestroyWindow(SDL_Window);
slouken@0
   450
	}
slouken@1288
   451
	SDL_UnregisterApp();
slouken@0
   452
}