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