comparison src/video/windib/SDL_dibevents.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 89f90f32f6c0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
41 #define NO_GETKEYBOARDSTATE 41 #define NO_GETKEYBOARDSTATE
42 #endif 42 #endif
43 43
44 /* The translation table from a Microsoft VK keysym to a SDL keysym */ 44 /* The translation table from a Microsoft VK keysym to a SDL keysym */
45 static SDLKey VK_keymap[SDLK_LAST]; 45 static SDLKey VK_keymap[SDLK_LAST];
46 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed); 46 static SDL_keysym *TranslateKey (WPARAM vkey, UINT scancode,
47 SDL_keysym * keysym, int pressed);
47 48
48 /* Masks for processing the windows KEYDOWN and KEYUP messages */ 49 /* Masks for processing the windows KEYDOWN and KEYUP messages */
49 #define REPEATED_KEYMASK (1<<30) 50 #define REPEATED_KEYMASK (1<<30)
50 #define EXTENDED_KEYMASK (1<<24) 51 #define EXTENDED_KEYMASK (1<<24)
51 52
59 static WNDPROCTYPE userWindowProc = NULL; 60 static WNDPROCTYPE userWindowProc = NULL;
60 61
61 62
62 #ifdef _WIN32_WCE 63 #ifdef _WIN32_WCE
63 64
64 WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction) 65 WPARAM
65 { 66 rotateKey (WPARAM key, SDL_ScreenOrientation direction)
66 if (direction != SDL_ORIENTATION_LEFT) 67 {
67 return key; 68 if (direction != SDL_ORIENTATION_LEFT)
68 69 return key;
69 switch (key) { 70
70 case 0x26: /* up */ 71 switch (key) {
71 return 0x27; 72 case 0x26: /* up */
72 case 0x27: /* right */ 73 return 0x27;
73 return 0x28; 74 case 0x27: /* right */
74 case 0x28: /* down */ 75 return 0x28;
75 return 0x25; 76 case 0x28: /* down */
76 case 0x25: /* left */ 77 return 0x25;
77 return 0x26; 78 case 0x25: /* left */
78 } 79 return 0x26;
79 80 }
80 return key; 81
81 } 82 return key;
82 83 }
83 #endif 84
85 #endif
84 86
85 87
86 /* The main Win32 event handler */ 88 /* The main Win32 event handler */
87 LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 89 LRESULT
88 { 90 DIB_HandleMessage (_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
89 extern int posted; 91 {
90 92 extern int posted;
91 switch (msg) { 93
92 case WM_SYSKEYDOWN: 94 switch (msg) {
93 case WM_KEYDOWN: { 95 case WM_SYSKEYDOWN:
94 SDL_keysym keysym; 96 case WM_KEYDOWN:
97 {
98 SDL_keysym keysym;
95 99
96 #ifdef _WIN32_WCE 100 #ifdef _WIN32_WCE
97 // Drop GAPI artefacts 101 // Drop GAPI artefacts
98 if (wParam == 0x84 || wParam == 0x5B) 102 if (wParam == 0x84 || wParam == 0x5B)
99 return 0; 103 return 0;
100 104
101 // Rotate key if necessary 105 // Rotate key if necessary
102 if (this->hidden->orientation != SDL_ORIENTATION_UP) 106 if (this->hidden->orientation != SDL_ORIENTATION_UP)
103 wParam = rotateKey(wParam, this->hidden->orientation); 107 wParam = rotateKey (wParam, this->hidden->orientation);
104 #endif 108 #endif
105 /* Ignore repeated keys */ 109 /* Ignore repeated keys */
106 if ( lParam&REPEATED_KEYMASK ) { 110 if (lParam & REPEATED_KEYMASK) {
107 return(0); 111 return (0);
108 } 112 }
109 switch (wParam) { 113 switch (wParam) {
110 case VK_CONTROL: 114 case VK_CONTROL:
111 if ( lParam&EXTENDED_KEYMASK ) 115 if (lParam & EXTENDED_KEYMASK)
112 wParam = VK_RCONTROL; 116 wParam = VK_RCONTROL;
113 else 117 else
114 wParam = VK_LCONTROL; 118 wParam = VK_LCONTROL;
115 break; 119 break;
116 case VK_SHIFT: 120 case VK_SHIFT:
117 /* EXTENDED trick doesn't work here */ 121 /* EXTENDED trick doesn't work here */
118 { 122 {
119 Uint8 *state = SDL_GetKeyState(NULL); 123 Uint8 *state = SDL_GetKeyState (NULL);
120 if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { 124 if (state[SDLK_LSHIFT] == SDL_RELEASED
121 wParam = VK_LSHIFT; 125 && (GetKeyState (VK_LSHIFT) & 0x8000)) {
122 } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { 126 wParam = VK_LSHIFT;
123 wParam = VK_RSHIFT; 127 } else if (state[SDLK_RSHIFT] == SDL_RELEASED
124 } else { 128 && (GetKeyState (VK_RSHIFT) & 0x8000)) {
125 /* Probably a key repeat */ 129 wParam = VK_RSHIFT;
126 return(0); 130 } else {
127 } 131 /* Probably a key repeat */
128 } 132 return (0);
129 break; 133 }
130 case VK_MENU: 134 }
131 if ( lParam&EXTENDED_KEYMASK ) 135 break;
132 wParam = VK_RMENU; 136 case VK_MENU:
133 else 137 if (lParam & EXTENDED_KEYMASK)
134 wParam = VK_LMENU; 138 wParam = VK_RMENU;
135 break; 139 else
136 } 140 wParam = VK_LMENU;
141 break;
142 }
137 #ifdef NO_GETKEYBOARDSTATE 143 #ifdef NO_GETKEYBOARDSTATE
138 /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ 144 /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */
139 if ( SDL_TranslateUNICODE ) { 145 if (SDL_TranslateUNICODE) {
140 MSG m; 146 MSG m;
141 147
142 m.hwnd = hwnd; 148 m.hwnd = hwnd;
143 m.message = msg; 149 m.message = msg;
144 m.wParam = wParam; 150 m.wParam = wParam;
145 m.lParam = lParam; 151 m.lParam = lParam;
146 m.time = 0; 152 m.time = 0;
147 if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { 153 if (TranslateMessage (&m)
148 GetMessage(&m, hwnd, 0, WM_USER); 154 && PeekMessage (&m, hwnd, 0, WM_USER, PM_NOREMOVE)
149 wParam = m.wParam; 155 && (m.message == WM_CHAR)) {
150 } 156 GetMessage (&m, hwnd, 0, WM_USER);
151 } 157 wParam = m.wParam;
158 }
159 }
152 #endif /* NO_GETKEYBOARDSTATE */ 160 #endif /* NO_GETKEYBOARDSTATE */
153 posted = SDL_PrivateKeyboard(SDL_PRESSED, 161 posted = SDL_PrivateKeyboard (SDL_PRESSED,
154 TranslateKey(wParam,HIWORD(lParam),&keysym,1)); 162 TranslateKey (wParam,
155 } 163 HIWORD (lParam),
156 return(0); 164 &keysym, 1));
157 165 }
158 case WM_SYSKEYUP: 166 return (0);
159 case WM_KEYUP: { 167
160 SDL_keysym keysym; 168 case WM_SYSKEYUP:
169 case WM_KEYUP:
170 {
171 SDL_keysym keysym;
161 172
162 #ifdef _WIN32_WCE 173 #ifdef _WIN32_WCE
163 // Drop GAPI artifacts 174 // Drop GAPI artifacts
164 if (wParam == 0x84 || wParam == 0x5B) 175 if (wParam == 0x84 || wParam == 0x5B)
165 return 0; 176 return 0;
166 177
167 // Rotate key if necessary 178 // Rotate key if necessary
168 if (this->hidden->orientation != SDL_ORIENTATION_UP) 179 if (this->hidden->orientation != SDL_ORIENTATION_UP)
169 wParam = rotateKey(wParam, this->hidden->orientation); 180 wParam = rotateKey (wParam, this->hidden->orientation);
170 #endif 181 #endif
171 182
172 switch (wParam) { 183 switch (wParam) {
173 case VK_CONTROL: 184 case VK_CONTROL:
174 if ( lParam&EXTENDED_KEYMASK ) 185 if (lParam & EXTENDED_KEYMASK)
175 wParam = VK_RCONTROL; 186 wParam = VK_RCONTROL;
176 else 187 else
177 wParam = VK_LCONTROL; 188 wParam = VK_LCONTROL;
178 break; 189 break;
179 case VK_SHIFT: 190 case VK_SHIFT:
180 /* EXTENDED trick doesn't work here */ 191 /* EXTENDED trick doesn't work here */
181 { 192 {
182 Uint8 *state = SDL_GetKeyState(NULL); 193 Uint8 *state = SDL_GetKeyState (NULL);
183 if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { 194 if (state[SDLK_LSHIFT] == SDL_PRESSED
184 wParam = VK_LSHIFT; 195 && !(GetKeyState (VK_LSHIFT) & 0x8000)) {
185 } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { 196 wParam = VK_LSHIFT;
186 wParam = VK_RSHIFT; 197 } else if (state[SDLK_RSHIFT] == SDL_PRESSED
187 } else { 198 && !(GetKeyState (VK_RSHIFT) & 0x8000)) {
188 /* Probably a key repeat */ 199 wParam = VK_RSHIFT;
189 return(0); 200 } else {
190 } 201 /* Probably a key repeat */
191 } 202 return (0);
192 break; 203 }
193 case VK_MENU: 204 }
194 if ( lParam&EXTENDED_KEYMASK ) 205 break;
195 wParam = VK_RMENU; 206 case VK_MENU:
196 else 207 if (lParam & EXTENDED_KEYMASK)
197 wParam = VK_LMENU; 208 wParam = VK_RMENU;
198 break; 209 else
199 } 210 wParam = VK_LMENU;
200 /* Windows only reports keyup for print screen */ 211 break;
201 if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { 212 }
202 posted = SDL_PrivateKeyboard(SDL_PRESSED, 213 /* Windows only reports keyup for print screen */
203 TranslateKey(wParam,HIWORD(lParam),&keysym,1)); 214 if (wParam == VK_SNAPSHOT
204 } 215 && SDL_GetKeyState (NULL)[SDLK_PRINT] == SDL_RELEASED) {
205 posted = SDL_PrivateKeyboard(SDL_RELEASED, 216 posted = SDL_PrivateKeyboard (SDL_PRESSED,
206 TranslateKey(wParam,HIWORD(lParam),&keysym,0)); 217 TranslateKey (wParam,
207 } 218 HIWORD
208 return(0); 219 (lParam),
220 &keysym, 1));
221 }
222 posted = SDL_PrivateKeyboard (SDL_RELEASED,
223 TranslateKey (wParam,
224 HIWORD (lParam),
225 &keysym, 0));
226 }
227 return (0);
209 228
210 #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) 229 #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
211 case WM_SYSCOMMAND: { 230 case WM_SYSCOMMAND:
212 if ((wParam&0xFFF0)==SC_SCREENSAVE || 231 {
213 (wParam&0xFFF0)==SC_MONITORPOWER) 232 if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
214 return(0); 233 (wParam & 0xFFF0) == SC_MONITORPOWER)
215 } 234 return (0);
216 /* Fall through to default processing */ 235 }
236 /* Fall through to default processing */
217 #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ 237 #endif /* SC_SCREENSAVE && SC_MONITORPOWER */
218 238
219 default: { 239 default:
220 /* Only post the event if we're watching for it */ 240 {
221 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { 241 /* Only post the event if we're watching for it */
222 SDL_SysWMmsg wmmsg; 242 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
223 243 SDL_SysWMmsg wmmsg;
224 SDL_VERSION(&wmmsg.version); 244
225 wmmsg.hwnd = hwnd; 245 SDL_VERSION (&wmmsg.version);
226 wmmsg.msg = msg; 246 wmmsg.hwnd = hwnd;
227 wmmsg.wParam = wParam; 247 wmmsg.msg = msg;
228 wmmsg.lParam = lParam; 248 wmmsg.wParam = wParam;
229 posted = SDL_PrivateSysWMEvent(&wmmsg); 249 wmmsg.lParam = lParam;
230 250 posted = SDL_PrivateSysWMEvent (&wmmsg);
231 /* DJM: If the user isn't watching for private 251
232 messages in her SDL event loop, then pass it 252 /* DJM: If the user isn't watching for private
233 along to any win32 specific window proc. 253 messages in her SDL event loop, then pass it
234 */ 254 along to any win32 specific window proc.
235 } else if (userWindowProc) { 255 */
236 return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); 256 } else if (userWindowProc) {
237 } 257 return CallWindowProc (userWindowProc, hwnd, msg, wParam,
238 } 258 lParam);
239 break; 259 }
240 } 260 }
241 return(DefWindowProc(hwnd, msg, wParam, lParam)); 261 break;
242 } 262 }
243 263 return (DefWindowProc (hwnd, msg, wParam, lParam));
244 void DIB_PumpEvents(_THIS) 264 }
245 { 265
246 MSG msg; 266 void
247 267 DIB_PumpEvents (_THIS)
248 while ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { 268 {
249 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { 269 MSG msg;
250 DispatchMessage(&msg); 270
251 } 271 while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
252 } 272 if (GetMessage (&msg, NULL, 0, 0) > 0) {
253 } 273 DispatchMessage (&msg);
254 274 }
255 void DIB_InitOSKeymap(_THIS) 275 }
256 { 276 }
257 int i; 277
258 278 void
259 /* Map the VK keysyms */ 279 DIB_InitOSKeymap (_THIS)
260 for ( i=0; i<SDL_arraysize(VK_keymap); ++i ) 280 {
261 VK_keymap[i] = SDLK_UNKNOWN; 281 int i;
262 282
263 VK_keymap[VK_BACK] = SDLK_BACKSPACE; 283 /* Map the VK keysyms */
264 VK_keymap[VK_TAB] = SDLK_TAB; 284 for (i = 0; i < SDL_arraysize (VK_keymap); ++i)
265 VK_keymap[VK_CLEAR] = SDLK_CLEAR; 285 VK_keymap[i] = SDLK_UNKNOWN;
266 VK_keymap[VK_RETURN] = SDLK_RETURN; 286
267 VK_keymap[VK_PAUSE] = SDLK_PAUSE; 287 VK_keymap[VK_BACK] = SDLK_BACKSPACE;
268 VK_keymap[VK_ESCAPE] = SDLK_ESCAPE; 288 VK_keymap[VK_TAB] = SDLK_TAB;
269 VK_keymap[VK_SPACE] = SDLK_SPACE; 289 VK_keymap[VK_CLEAR] = SDLK_CLEAR;
270 VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE; 290 VK_keymap[VK_RETURN] = SDLK_RETURN;
271 VK_keymap[VK_COMMA] = SDLK_COMMA; 291 VK_keymap[VK_PAUSE] = SDLK_PAUSE;
272 VK_keymap[VK_MINUS] = SDLK_MINUS; 292 VK_keymap[VK_ESCAPE] = SDLK_ESCAPE;
273 VK_keymap[VK_PERIOD] = SDLK_PERIOD; 293 VK_keymap[VK_SPACE] = SDLK_SPACE;
274 VK_keymap[VK_SLASH] = SDLK_SLASH; 294 VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE;
275 VK_keymap[VK_0] = SDLK_0; 295 VK_keymap[VK_COMMA] = SDLK_COMMA;
276 VK_keymap[VK_1] = SDLK_1; 296 VK_keymap[VK_MINUS] = SDLK_MINUS;
277 VK_keymap[VK_2] = SDLK_2; 297 VK_keymap[VK_PERIOD] = SDLK_PERIOD;
278 VK_keymap[VK_3] = SDLK_3; 298 VK_keymap[VK_SLASH] = SDLK_SLASH;
279 VK_keymap[VK_4] = SDLK_4; 299 VK_keymap[VK_0] = SDLK_0;
280 VK_keymap[VK_5] = SDLK_5; 300 VK_keymap[VK_1] = SDLK_1;
281 VK_keymap[VK_6] = SDLK_6; 301 VK_keymap[VK_2] = SDLK_2;
282 VK_keymap[VK_7] = SDLK_7; 302 VK_keymap[VK_3] = SDLK_3;
283 VK_keymap[VK_8] = SDLK_8; 303 VK_keymap[VK_4] = SDLK_4;
284 VK_keymap[VK_9] = SDLK_9; 304 VK_keymap[VK_5] = SDLK_5;
285 VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON; 305 VK_keymap[VK_6] = SDLK_6;
286 VK_keymap[VK_EQUALS] = SDLK_EQUALS; 306 VK_keymap[VK_7] = SDLK_7;
287 VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET; 307 VK_keymap[VK_8] = SDLK_8;
288 VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH; 308 VK_keymap[VK_9] = SDLK_9;
289 VK_keymap[VK_OEM_102] = SDLK_LESS; 309 VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON;
290 VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET; 310 VK_keymap[VK_EQUALS] = SDLK_EQUALS;
291 VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE; 311 VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET;
292 VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE; 312 VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH;
293 VK_keymap[VK_A] = SDLK_a; 313 VK_keymap[VK_OEM_102] = SDLK_LESS;
294 VK_keymap[VK_B] = SDLK_b; 314 VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET;
295 VK_keymap[VK_C] = SDLK_c; 315 VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE;
296 VK_keymap[VK_D] = SDLK_d; 316 VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE;
297 VK_keymap[VK_E] = SDLK_e; 317 VK_keymap[VK_A] = SDLK_a;
298 VK_keymap[VK_F] = SDLK_f; 318 VK_keymap[VK_B] = SDLK_b;
299 VK_keymap[VK_G] = SDLK_g; 319 VK_keymap[VK_C] = SDLK_c;
300 VK_keymap[VK_H] = SDLK_h; 320 VK_keymap[VK_D] = SDLK_d;
301 VK_keymap[VK_I] = SDLK_i; 321 VK_keymap[VK_E] = SDLK_e;
302 VK_keymap[VK_J] = SDLK_j; 322 VK_keymap[VK_F] = SDLK_f;
303 VK_keymap[VK_K] = SDLK_k; 323 VK_keymap[VK_G] = SDLK_g;
304 VK_keymap[VK_L] = SDLK_l; 324 VK_keymap[VK_H] = SDLK_h;
305 VK_keymap[VK_M] = SDLK_m; 325 VK_keymap[VK_I] = SDLK_i;
306 VK_keymap[VK_N] = SDLK_n; 326 VK_keymap[VK_J] = SDLK_j;
307 VK_keymap[VK_O] = SDLK_o; 327 VK_keymap[VK_K] = SDLK_k;
308 VK_keymap[VK_P] = SDLK_p; 328 VK_keymap[VK_L] = SDLK_l;
309 VK_keymap[VK_Q] = SDLK_q; 329 VK_keymap[VK_M] = SDLK_m;
310 VK_keymap[VK_R] = SDLK_r; 330 VK_keymap[VK_N] = SDLK_n;
311 VK_keymap[VK_S] = SDLK_s; 331 VK_keymap[VK_O] = SDLK_o;
312 VK_keymap[VK_T] = SDLK_t; 332 VK_keymap[VK_P] = SDLK_p;
313 VK_keymap[VK_U] = SDLK_u; 333 VK_keymap[VK_Q] = SDLK_q;
314 VK_keymap[VK_V] = SDLK_v; 334 VK_keymap[VK_R] = SDLK_r;
315 VK_keymap[VK_W] = SDLK_w; 335 VK_keymap[VK_S] = SDLK_s;
316 VK_keymap[VK_X] = SDLK_x; 336 VK_keymap[VK_T] = SDLK_t;
317 VK_keymap[VK_Y] = SDLK_y; 337 VK_keymap[VK_U] = SDLK_u;
318 VK_keymap[VK_Z] = SDLK_z; 338 VK_keymap[VK_V] = SDLK_v;
319 VK_keymap[VK_DELETE] = SDLK_DELETE; 339 VK_keymap[VK_W] = SDLK_w;
320 340 VK_keymap[VK_X] = SDLK_x;
321 VK_keymap[VK_NUMPAD0] = SDLK_KP0; 341 VK_keymap[VK_Y] = SDLK_y;
322 VK_keymap[VK_NUMPAD1] = SDLK_KP1; 342 VK_keymap[VK_Z] = SDLK_z;
323 VK_keymap[VK_NUMPAD2] = SDLK_KP2; 343 VK_keymap[VK_DELETE] = SDLK_DELETE;
324 VK_keymap[VK_NUMPAD3] = SDLK_KP3; 344
325 VK_keymap[VK_NUMPAD4] = SDLK_KP4; 345 VK_keymap[VK_NUMPAD0] = SDLK_KP0;
326 VK_keymap[VK_NUMPAD5] = SDLK_KP5; 346 VK_keymap[VK_NUMPAD1] = SDLK_KP1;
327 VK_keymap[VK_NUMPAD6] = SDLK_KP6; 347 VK_keymap[VK_NUMPAD2] = SDLK_KP2;
328 VK_keymap[VK_NUMPAD7] = SDLK_KP7; 348 VK_keymap[VK_NUMPAD3] = SDLK_KP3;
329 VK_keymap[VK_NUMPAD8] = SDLK_KP8; 349 VK_keymap[VK_NUMPAD4] = SDLK_KP4;
330 VK_keymap[VK_NUMPAD9] = SDLK_KP9; 350 VK_keymap[VK_NUMPAD5] = SDLK_KP5;
331 VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD; 351 VK_keymap[VK_NUMPAD6] = SDLK_KP6;
332 VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE; 352 VK_keymap[VK_NUMPAD7] = SDLK_KP7;
333 VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY; 353 VK_keymap[VK_NUMPAD8] = SDLK_KP8;
334 VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS; 354 VK_keymap[VK_NUMPAD9] = SDLK_KP9;
335 VK_keymap[VK_ADD] = SDLK_KP_PLUS; 355 VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD;
336 356 VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE;
337 VK_keymap[VK_UP] = SDLK_UP; 357 VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY;
338 VK_keymap[VK_DOWN] = SDLK_DOWN; 358 VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS;
339 VK_keymap[VK_RIGHT] = SDLK_RIGHT; 359 VK_keymap[VK_ADD] = SDLK_KP_PLUS;
340 VK_keymap[VK_LEFT] = SDLK_LEFT; 360
341 VK_keymap[VK_INSERT] = SDLK_INSERT; 361 VK_keymap[VK_UP] = SDLK_UP;
342 VK_keymap[VK_HOME] = SDLK_HOME; 362 VK_keymap[VK_DOWN] = SDLK_DOWN;
343 VK_keymap[VK_END] = SDLK_END; 363 VK_keymap[VK_RIGHT] = SDLK_RIGHT;
344 VK_keymap[VK_PRIOR] = SDLK_PAGEUP; 364 VK_keymap[VK_LEFT] = SDLK_LEFT;
345 VK_keymap[VK_NEXT] = SDLK_PAGEDOWN; 365 VK_keymap[VK_INSERT] = SDLK_INSERT;
346 366 VK_keymap[VK_HOME] = SDLK_HOME;
347 VK_keymap[VK_F1] = SDLK_F1; 367 VK_keymap[VK_END] = SDLK_END;
348 VK_keymap[VK_F2] = SDLK_F2; 368 VK_keymap[VK_PRIOR] = SDLK_PAGEUP;
349 VK_keymap[VK_F3] = SDLK_F3; 369 VK_keymap[VK_NEXT] = SDLK_PAGEDOWN;
350 VK_keymap[VK_F4] = SDLK_F4; 370
351 VK_keymap[VK_F5] = SDLK_F5; 371 VK_keymap[VK_F1] = SDLK_F1;
352 VK_keymap[VK_F6] = SDLK_F6; 372 VK_keymap[VK_F2] = SDLK_F2;
353 VK_keymap[VK_F7] = SDLK_F7; 373 VK_keymap[VK_F3] = SDLK_F3;
354 VK_keymap[VK_F8] = SDLK_F8; 374 VK_keymap[VK_F4] = SDLK_F4;
355 VK_keymap[VK_F9] = SDLK_F9; 375 VK_keymap[VK_F5] = SDLK_F5;
356 VK_keymap[VK_F10] = SDLK_F10; 376 VK_keymap[VK_F6] = SDLK_F6;
357 VK_keymap[VK_F11] = SDLK_F11; 377 VK_keymap[VK_F7] = SDLK_F7;
358 VK_keymap[VK_F12] = SDLK_F12; 378 VK_keymap[VK_F8] = SDLK_F8;
359 VK_keymap[VK_F13] = SDLK_F13; 379 VK_keymap[VK_F9] = SDLK_F9;
360 VK_keymap[VK_F14] = SDLK_F14; 380 VK_keymap[VK_F10] = SDLK_F10;
361 VK_keymap[VK_F15] = SDLK_F15; 381 VK_keymap[VK_F11] = SDLK_F11;
362 382 VK_keymap[VK_F12] = SDLK_F12;
363 VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK; 383 VK_keymap[VK_F13] = SDLK_F13;
364 VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK; 384 VK_keymap[VK_F14] = SDLK_F14;
365 VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK; 385 VK_keymap[VK_F15] = SDLK_F15;
366 VK_keymap[VK_RSHIFT] = SDLK_RSHIFT; 386
367 VK_keymap[VK_LSHIFT] = SDLK_LSHIFT; 387 VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK;
368 VK_keymap[VK_RCONTROL] = SDLK_RCTRL; 388 VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK;
369 VK_keymap[VK_LCONTROL] = SDLK_LCTRL; 389 VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK;
370 VK_keymap[VK_RMENU] = SDLK_RALT; 390 VK_keymap[VK_RSHIFT] = SDLK_RSHIFT;
371 VK_keymap[VK_LMENU] = SDLK_LALT; 391 VK_keymap[VK_LSHIFT] = SDLK_LSHIFT;
372 VK_keymap[VK_RWIN] = SDLK_RSUPER; 392 VK_keymap[VK_RCONTROL] = SDLK_RCTRL;
373 VK_keymap[VK_LWIN] = SDLK_LSUPER; 393 VK_keymap[VK_LCONTROL] = SDLK_LCTRL;
374 394 VK_keymap[VK_RMENU] = SDLK_RALT;
375 VK_keymap[VK_HELP] = SDLK_HELP; 395 VK_keymap[VK_LMENU] = SDLK_LALT;
396 VK_keymap[VK_RWIN] = SDLK_RSUPER;
397 VK_keymap[VK_LWIN] = SDLK_LSUPER;
398
399 VK_keymap[VK_HELP] = SDLK_HELP;
376 #ifdef VK_PRINT 400 #ifdef VK_PRINT
377 VK_keymap[VK_PRINT] = SDLK_PRINT; 401 VK_keymap[VK_PRINT] = SDLK_PRINT;
378 #endif 402 #endif
379 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT; 403 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
380 VK_keymap[VK_CANCEL] = SDLK_BREAK; 404 VK_keymap[VK_CANCEL] = SDLK_BREAK;
381 VK_keymap[VK_APPS] = SDLK_MENU; 405 VK_keymap[VK_APPS] = SDLK_MENU;
382 } 406 }
383 407
384 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed) 408 static SDL_keysym *
385 { 409 TranslateKey (WPARAM vkey, UINT scancode, SDL_keysym * keysym, int pressed)
386 /* Set the keysym information */ 410 {
387 keysym->scancode = (unsigned char) scancode; 411 /* Set the keysym information */
388 keysym->sym = VK_keymap[vkey]; 412 keysym->scancode = (unsigned char) scancode;
389 keysym->mod = KMOD_NONE; 413 keysym->sym = VK_keymap[vkey];
390 keysym->unicode = 0; 414 keysym->mod = KMOD_NONE;
391 if ( pressed && SDL_TranslateUNICODE ) { 415 keysym->unicode = 0;
416 if (pressed && SDL_TranslateUNICODE) {
392 #ifdef NO_GETKEYBOARDSTATE 417 #ifdef NO_GETKEYBOARDSTATE
393 /* Uh oh, better hope the vkey is close enough.. */ 418 /* Uh oh, better hope the vkey is close enough.. */
394 keysym->unicode = vkey; 419 keysym->unicode = vkey;
395 #else 420 #else
396 BYTE keystate[256]; 421 BYTE keystate[256];
397 Uint16 wchars[2]; 422 Uint16 wchars[2];
398 423
399 GetKeyboardState(keystate); 424 GetKeyboardState (keystate);
400 if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) == 1) 425 if (SDL_ToUnicode
401 { 426 ((UINT) vkey, scancode, keystate, wchars,
402 keysym->unicode = wchars[0]; 427 sizeof (wchars) / sizeof (wchars[0]), 0) == 1) {
403 } 428 keysym->unicode = wchars[0];
429 }
404 #endif /* NO_GETKEYBOARDSTATE */ 430 #endif /* NO_GETKEYBOARDSTATE */
405 } 431 }
406 return(keysym); 432 return (keysym);
407 } 433 }
408 434
409 int DIB_CreateWindow(_THIS) 435 int
410 { 436 DIB_CreateWindow (_THIS)
411 char *windowid = SDL_getenv("SDL_WINDOWID"); 437 {
412 438 char *windowid = SDL_getenv ("SDL_WINDOWID");
413 SDL_RegisterApp(NULL, 0, 0); 439
414 440 SDL_RegisterApp (NULL, 0, 0);
415 SDL_windowid = (windowid != NULL); 441
416 if ( SDL_windowid ) { 442 SDL_windowid = (windowid != NULL);
443 if (SDL_windowid) {
417 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) 444 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
418 /* wince 2.1 does not have strtol */ 445 /* wince 2.1 does not have strtol */
419 wchar_t *windowid_t = SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t)); 446 wchar_t *windowid_t =
420 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, SDL_strlen(windowid) + 1); 447 SDL_malloc ((SDL_strlen (windowid) + 1) * sizeof (wchar_t));
421 SDL_Window = (HWND)wcstol(windowid_t, NULL, 0); 448 MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, windowid, -1,
422 SDL_free(windowid_t); 449 windowid_t, SDL_strlen (windowid) + 1);
450 SDL_Window = (HWND) wcstol (windowid_t, NULL, 0);
451 SDL_free (windowid_t);
423 #else 452 #else
424 SDL_Window = (HWND)SDL_strtoull(windowid, NULL, 0); 453 SDL_Window = (HWND) SDL_strtoull (windowid, NULL, 0);
425 #endif 454 #endif
426 if ( SDL_Window == NULL ) { 455 if (SDL_Window == NULL) {
427 SDL_SetError("Couldn't get user specified window"); 456 SDL_SetError ("Couldn't get user specified window");
428 return(-1); 457 return (-1);
429 } 458 }
430 459
431 /* DJM: we want all event's for the user specified 460 /* DJM: we want all event's for the user specified
432 window to be handled by SDL. 461 window to be handled by SDL.
433 */ 462 */
434 userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC); 463 userWindowProc =
435 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)WinMessage); 464 (WNDPROCTYPE) GetWindowLongPtr (SDL_Window, GWLP_WNDPROC);
436 } else { 465 SetWindowLongPtr (SDL_Window, GWLP_WNDPROC, (LONG_PTR) WinMessage);
437 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, 466 } else {
438 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), 467 SDL_Window = CreateWindow (SDL_Appname, SDL_Appname,
439 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); 468 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
440 if ( SDL_Window == NULL ) { 469 | WS_MINIMIZEBOX), CW_USEDEFAULT,
441 SDL_SetError("Couldn't create window"); 470 CW_USEDEFAULT, 0, 0, NULL, NULL,
442 return(-1); 471 SDL_Instance, NULL);
443 } 472 if (SDL_Window == NULL) {
444 ShowWindow(SDL_Window, SW_HIDE); 473 SDL_SetError ("Couldn't create window");
445 } 474 return (-1);
446 475 }
447 /* JC 14 Mar 2006 476 ShowWindow (SDL_Window, SW_HIDE);
448 Flush the message loop or this can cause big problems later 477 }
449 Especially if the user decides to use dialog boxes or assert()! 478
450 */ 479 /* JC 14 Mar 2006
451 WIN_FlushMessageQueue(); 480 Flush the message loop or this can cause big problems later
452 481 Especially if the user decides to use dialog boxes or assert()!
453 return(0); 482 */
454 } 483 WIN_FlushMessageQueue ();
455 484
456 void DIB_DestroyWindow(_THIS) 485 return (0);
457 { 486 }
458 if ( SDL_windowid ) { 487
459 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)userWindowProc); 488 void
460 } else { 489 DIB_DestroyWindow (_THIS)
461 DestroyWindow(SDL_Window); 490 {
462 } 491 if (SDL_windowid) {
463 SDL_UnregisterApp(); 492 SetWindowLongPtr (SDL_Window, GWLP_WNDPROC,
464 493 (LONG_PTR) userWindowProc);
465 /* JC 14 Mar 2006 494 } else {
466 Flush the message loop or this can cause big problems later 495 DestroyWindow (SDL_Window);
467 Especially if the user decides to use dialog boxes or assert()! 496 }
468 */ 497 SDL_UnregisterApp ();
469 WIN_FlushMessageQueue(); 498
470 } 499 /* JC 14 Mar 2006
500 Flush the message loop or this can cause big problems later
501 Especially if the user decides to use dialog boxes or assert()!
502 */
503 WIN_FlushMessageQueue ();
504 }
505
506 /* vi: set ts=4 sw=4 expandtab: */