src/video/win32/SDL_win32events.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 27 Jul 2010 21:31:28 -0700
changeset 4569 e1664f94f026
parent 4565 e2d46c5c7483
child 4694 c24ba2cc9583
permissions -rwxr-xr-x
Andrey A.

I made a video driver GAPI/RAW for WinCE (SDL-1.3).
RAW mode has a priority, and also, GAPI mode works with environment
"SDL_VIDEO_RENDERER=gapi" and for RAW mode "SDL_VIDEO_RENDERER=raw".

I checked the work on the screens of VGA, WVGA, QVGA, WQVGA, HVGA,
+ tested all modes with WindowsMobile Emulator.

Also, correctly draws the pointer position and the scale of the pointer
for VGA/WVGA modes,
correctly draws top left position for DM orientation screen, and
portrait/landscape/square geometry the screen also correct.

Also, I added a small fix for GDI fullscreen mode.

Patch for latest revision SDL-1.3 in an attachment.
Also added small path for mingw32ce build.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@1895
     4
slouken@1895
     5
    This library is free software; you can redistribute it and/or
slouken@1895
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1895
     7
    License as published by the Free Software Foundation; either
slouken@1895
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1895
     9
slouken@1895
    10
    This library is distributed in the hope that it will be useful,
slouken@1895
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1895
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1895
    13
    Lesser General Public License for more details.
slouken@1895
    14
slouken@1895
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1895
    16
    License along with this library; if not, write to the Free Software
slouken@1895
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1895
    18
slouken@1895
    19
    Sam Lantinga
slouken@1895
    20
    slouken@libsdl.org
slouken@1895
    21
*/
slouken@2710
    22
slouken@2710
    23
#if (_WIN32_WINNT < 0x0501)
slouken@2710
    24
#undef _WIN32_WINNT
slouken@2710
    25
#define _WIN32_WINNT 0x0501
slouken@2710
    26
#endif
slouken@2710
    27
slouken@1895
    28
#include "SDL_config.h"
slouken@1895
    29
slouken@1895
    30
#include "SDL_win32video.h"
slouken@1895
    31
#include "SDL_syswm.h"
slouken@1895
    32
#include "SDL_vkeys.h"
slouken@1895
    33
#include "../../events/SDL_events_c.h"
slouken@1895
    34
slouken@1895
    35
/*#define WMMSG_DEBUG*/
slouken@1895
    36
#ifdef WMMSG_DEBUG
slouken@1913
    37
#include <stdio.h>
slouken@1895
    38
#include "wmmsg.h"
slouken@1895
    39
#endif
slouken@1895
    40
slouken@1895
    41
/* Masks for processing the windows KEYDOWN and KEYUP messages */
slouken@2317
    42
#define REPEATED_KEYMASK    (1<<30)
slouken@2317
    43
#define EXTENDED_KEYMASK    (1<<24)
slouken@1895
    44
bob@2324
    45
#define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
slouken@2313
    46
icculus@2127
    47
/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
icculus@2127
    48
#ifndef WM_XBUTTONDOWN
icculus@2127
    49
#define WM_XBUTTONDOWN 0x020B
icculus@2127
    50
#endif
icculus@2127
    51
#ifndef WM_XBUTTONUP
icculus@2127
    52
#define WM_XBUTTONUP 0x020C
icculus@2127
    53
#endif
icculus@2127
    54
#ifndef GET_XBUTTON_WPARAM
icculus@2127
    55
#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
icculus@2127
    56
#endif
bobbens@2733
    57
#ifndef WM_INPUT
bobbens@2733
    58
#define WM_INPUT 0x00ff
bobbens@2733
    59
#endif
slouken@1895
    60
slouken@2310
    61
static WPARAM
slouken@2310
    62
RemapVKEY(WPARAM wParam, LPARAM lParam)
slouken@2310
    63
{
slouken@2317
    64
    int i;
bob@2324
    65
    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
slouken@2317
    66
slouken@2310
    67
    /* Windows remaps alphabetic keys based on current layout.
slouken@2310
    68
       We try to provide USB scancodes, so undo this mapping.
slouken@2310
    69
     */
slouken@2310
    70
    if (wParam >= 'A' && wParam <= 'Z') {
slouken@2311
    71
        if (scancode != alpha_scancodes[wParam - 'A']) {
slouken@2311
    72
            for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
slouken@2311
    73
                if (scancode == alpha_scancodes[i]) {
slouken@2310
    74
                    wParam = 'A' + i;
slouken@2310
    75
                    break;
slouken@2310
    76
                }
slouken@2310
    77
            }
slouken@2310
    78
        }
slouken@2310
    79
    }
slouken@2317
    80
slouken@3700
    81
    /* Keypad keys are a little trickier, we always scan for them.
slouken@3700
    82
       Keypad arrow keys have the same scancode as normal arrow keys,
slouken@3700
    83
       except they don't have the extended bit (0x1000000) set.
slouken@3700
    84
     */
slouken@3700
    85
    if (!(lParam & 0x1000000)) {
slouken@4561
    86
        if (wParam == VK_DELETE) {
slouken@4561
    87
            wParam = VK_DECIMAL;
slouken@4561
    88
        } else {
slouken@4561
    89
            for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
slouken@4561
    90
                if (scancode == keypad_scancodes[i]) {
slouken@4561
    91
                    wParam = VK_NUMPAD0 + i;
slouken@4561
    92
                    break;
slouken@4561
    93
                }
slouken@3700
    94
            }
slouken@2317
    95
        }
slouken@2317
    96
    }
slouken@2317
    97
slouken@2310
    98
    return wParam;
slouken@2310
    99
}
slouken@2310
   100
slouken@1895
   101
LRESULT CALLBACK
slouken@1895
   102
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@1895
   103
{
slouken@1895
   104
    SDL_WindowData *data;
slouken@3566
   105
    LRESULT returnCode = -1;
slouken@1895
   106
slouken@1951
   107
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@4429
   108
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1951
   109
        SDL_SysWMmsg wmmsg;
slouken@1951
   110
slouken@1951
   111
        SDL_VERSION(&wmmsg.version);
slouken@1951
   112
        wmmsg.hwnd = hwnd;
slouken@1951
   113
        wmmsg.msg = msg;
slouken@1951
   114
        wmmsg.wParam = wParam;
slouken@1951
   115
        wmmsg.lParam = lParam;
slouken@1951
   116
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
   117
    }
slouken@1951
   118
slouken@1895
   119
    /* Get the window data for the window */
slouken@1895
   120
    data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
slouken@1895
   121
    if (!data) {
slouken@1895
   122
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@1895
   123
    }
slouken@1895
   124
#ifdef WMMSG_DEBUG
slouken@1913
   125
    {
slouken@1913
   126
        FILE *log = fopen("wmmsg.txt", "a");
slouken@1913
   127
        fprintf(log, "Received windows message: %p ", hwnd);
slouken@1913
   128
        if (msg > MAX_WMMSG) {
slouken@1913
   129
            fprintf(log, "%d", msg);
slouken@1913
   130
        } else {
slouken@1913
   131
            fprintf(log, "%s", wmtab[msg]);
slouken@1913
   132
        }
slouken@1913
   133
        fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
slouken@1913
   134
        fclose(log);
slouken@1895
   135
    }
slouken@2710
   136
slouken@1895
   137
#endif
slouken@1895
   138
slouken@1895
   139
    switch (msg) {
slouken@1895
   140
slouken@1895
   141
    case WM_SHOWWINDOW:
slouken@1895
   142
        {
slouken@1895
   143
            if (wParam) {
slouken@3685
   144
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1895
   145
            } else {
slouken@3685
   146
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1895
   147
            }
slouken@1895
   148
        }
slouken@1895
   149
        break;
slouken@1895
   150
slouken@1895
   151
    case WM_ACTIVATE:
slouken@1895
   152
        {
slouken@1895
   153
            BOOL minimized;
slouken@1895
   154
slouken@1895
   155
            minimized = HIWORD(wParam);
slouken@1895
   156
            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
slouken@3685
   157
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   158
                SDL_SendWindowEvent(data->window,
slouken@1895
   159
                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@3139
   160
#ifndef _WIN32_WCE              /* WinCE misses IsZoomed() */
slouken@1895
   161
                if (IsZoomed(hwnd)) {
slouken@3685
   162
                    SDL_SendWindowEvent(data->window,
slouken@1895
   163
                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
slouken@1895
   164
                }
slouken@3139
   165
#endif
slouken@4465
   166
                if (SDL_GetKeyboardFocus() != data->window) {
slouken@4465
   167
                    SDL_SetKeyboardFocus(data->window);
slouken@1895
   168
                }
slouken@4504
   169
                /*
slouken@4504
   170
                 * FIXME: Update keyboard state
slouken@4504
   171
                 */
slouken@4504
   172
                WIN_CheckClipboardUpdate(data->videodata);
slouken@1895
   173
            } else {
slouken@4465
   174
                if (SDL_GetKeyboardFocus() == data->window) {
slouken@4465
   175
                    SDL_SetKeyboardFocus(NULL);
slouken@1895
   176
                }
slouken@1895
   177
                if (minimized) {
slouken@3685
   178
                    SDL_SendWindowEvent(data->window,
slouken@1895
   179
                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1895
   180
                }
slouken@1895
   181
            }
slouken@1895
   182
        }
slouken@3566
   183
        returnCode = 0;
slouken@3566
   184
        break;
slouken@1895
   185
slouken@4470
   186
	case WM_MOUSEMOVE:
slouken@4569
   187
#ifdef _WIN32_WCE
slouken@4569
   188
	/* transform coords for VGA, WVGA... */
slouken@4569
   189
	{
slouken@4569
   190
	    SDL_VideoData *videodata = data->videodata;
slouken@4569
   191
	    if(videodata->CoordTransform &&
slouken@4569
   192
		(videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW))
slouken@4569
   193
	    {
slouken@4569
   194
		POINT pt;
slouken@4569
   195
		pt.x = LOWORD(lParam);
slouken@4569
   196
		pt.y = HIWORD(lParam);
slouken@4569
   197
		videodata->CoordTransform(data->window, &pt);
slouken@4569
   198
    		SDL_SendMouseMotion(data->window, 0, pt.x, pt.y);
slouken@4569
   199
		break;
slouken@4569
   200
	    }
slouken@4569
   201
	}
slouken@4569
   202
#endif
slouken@4484
   203
        SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
slouken@3139
   204
        break;
slouken@3139
   205
slouken@3097
   206
    case WM_LBUTTONDOWN:
slouken@4484
   207
        SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT);
slouken@3139
   208
        break;
slouken@3139
   209
slouken@3097
   210
    case WM_LBUTTONUP:
slouken@4484
   211
        SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT);
slouken@3139
   212
        break;
slouken@3139
   213
slouken@1895
   214
    case WM_MOUSELEAVE:
slouken@4470
   215
        if (SDL_GetMouseFocus() == data->window) {
slouken@4470
   216
            SDL_SetMouseFocus(NULL);
slouken@1895
   217
        }
slouken@3566
   218
        returnCode = 0;
slouken@3566
   219
        break;
slouken@1895
   220
slouken@1895
   221
    case WM_SYSKEYDOWN:
slouken@1895
   222
    case WM_KEYDOWN:
slouken@1895
   223
        {
slouken@2310
   224
            wParam = RemapVKEY(wParam, lParam);
slouken@1895
   225
            switch (wParam) {
slouken@1895
   226
            case VK_CONTROL:
slouken@1895
   227
                if (lParam & EXTENDED_KEYMASK)
slouken@1895
   228
                    wParam = VK_RCONTROL;
slouken@1895
   229
                else
slouken@1895
   230
                    wParam = VK_LCONTROL;
slouken@1895
   231
                break;
slouken@1895
   232
            case VK_SHIFT:
slouken@1895
   233
                /* EXTENDED trick doesn't work here */
slouken@1895
   234
                {
slouken@2308
   235
                    Uint8 *state = SDL_GetKeyboardState(NULL);
slouken@2308
   236
                    if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
slouken@1895
   237
                        && (GetKeyState(VK_LSHIFT) & 0x8000)) {
slouken@1895
   238
                        wParam = VK_LSHIFT;
slouken@2308
   239
                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
slouken@1895
   240
                               && (GetKeyState(VK_RSHIFT) & 0x8000)) {
slouken@1895
   241
                        wParam = VK_RSHIFT;
slouken@1895
   242
                    } else {
slouken@1895
   243
                        /* Probably a key repeat */
slouken@3566
   244
                        wParam = 256;
slouken@1895
   245
                    }
slouken@1895
   246
                }
slouken@1895
   247
                break;
slouken@1895
   248
            case VK_MENU:
slouken@1895
   249
                if (lParam & EXTENDED_KEYMASK)
slouken@1895
   250
                    wParam = VK_RMENU;
slouken@1895
   251
                else
slouken@1895
   252
                    wParam = VK_LMENU;
slouken@1895
   253
                break;
slouken@2313
   254
            case VK_RETURN:
slouken@2313
   255
                if (lParam & EXTENDED_KEYMASK)
slouken@2313
   256
                    wParam = VK_ENTER;
slouken@2313
   257
                break;
slouken@1895
   258
            }
slouken@2308
   259
            if (wParam < 256) {
slouken@4465
   260
                SDL_SendKeyboardKey(SDL_PRESSED,
slouken@4565
   261
                                    data->videodata->key_layout[wParam]);
slouken@2308
   262
            }
slouken@1895
   263
        }
slouken@3566
   264
        returnCode = 0;
slouken@3566
   265
        break;
slouken@1895
   266
slouken@1895
   267
    case WM_SYSKEYUP:
slouken@1895
   268
    case WM_KEYUP:
slouken@1895
   269
        {
slouken@2310
   270
            wParam = RemapVKEY(wParam, lParam);
slouken@1895
   271
            switch (wParam) {
slouken@1895
   272
            case VK_CONTROL:
slouken@1895
   273
                if (lParam & EXTENDED_KEYMASK)
slouken@1895
   274
                    wParam = VK_RCONTROL;
slouken@1895
   275
                else
slouken@1895
   276
                    wParam = VK_LCONTROL;
slouken@1895
   277
                break;
slouken@1895
   278
            case VK_SHIFT:
slouken@1895
   279
                /* EXTENDED trick doesn't work here */
slouken@1895
   280
                {
slouken@2308
   281
                    Uint8 *state = SDL_GetKeyboardState(NULL);
slouken@2308
   282
                    if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
slouken@1895
   283
                        && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
slouken@1895
   284
                        wParam = VK_LSHIFT;
slouken@2308
   285
                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
slouken@1895
   286
                               && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
slouken@1895
   287
                        wParam = VK_RSHIFT;
slouken@1895
   288
                    } else {
slouken@1895
   289
                        /* Probably a key repeat */
slouken@3566
   290
                        wParam = 256;
slouken@1895
   291
                    }
slouken@1895
   292
                }
slouken@1895
   293
                break;
slouken@1895
   294
            case VK_MENU:
slouken@1895
   295
                if (lParam & EXTENDED_KEYMASK)
slouken@1895
   296
                    wParam = VK_RMENU;
slouken@1895
   297
                else
slouken@1895
   298
                    wParam = VK_LMENU;
slouken@1895
   299
                break;
slouken@2313
   300
            case VK_RETURN:
slouken@2313
   301
                if (lParam & EXTENDED_KEYMASK)
slouken@2313
   302
                    wParam = VK_ENTER;
slouken@2313
   303
                break;
slouken@1895
   304
            }
slouken@2710
   305
slouken@1895
   306
            /* Windows only reports keyup for print screen */
slouken@1895
   307
            if (wParam == VK_SNAPSHOT
slouken@2308
   308
                && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
slouken@2308
   309
                SDL_RELEASED) {
slouken@4465
   310
                SDL_SendKeyboardKey(SDL_PRESSED,
slouken@4565
   311
                                    data->videodata->key_layout[wParam]);
slouken@1895
   312
            }
slouken@2308
   313
            if (wParam < 256) {
slouken@4465
   314
                SDL_SendKeyboardKey(SDL_RELEASED,
slouken@4565
   315
                                    data->videodata->key_layout[wParam]);
slouken@2308
   316
            }
slouken@1895
   317
        }
slouken@3566
   318
        returnCode = 0;
slouken@3566
   319
        break;
slouken@1895
   320
slouken@2309
   321
    case WM_CHAR:
slouken@2309
   322
        {
slouken@2309
   323
            char text[4];
slouken@2309
   324
slouken@2309
   325
            /* Convert to UTF-8 and send it on... */
slouken@2309
   326
            if (wParam <= 0x7F) {
slouken@2309
   327
                text[0] = (char) wParam;
slouken@2309
   328
                text[1] = '\0';
slouken@2309
   329
            } else if (wParam <= 0x7FF) {
slouken@2309
   330
                text[0] = 0xC0 | (char) ((wParam >> 6) & 0x1F);
slouken@2309
   331
                text[1] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   332
                text[2] = '\0';
slouken@2309
   333
            } else {
slouken@2309
   334
                text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
slouken@2309
   335
                text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
slouken@2309
   336
                text[2] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   337
                text[3] = '\0';
slouken@2309
   338
            }
slouken@4465
   339
            SDL_SendKeyboardText(text);
slouken@2309
   340
        }
slouken@3566
   341
        returnCode = 0;
slouken@3566
   342
        break;
slouken@2309
   343
slouken@2311
   344
    case WM_INPUTLANGCHANGE:
slouken@2311
   345
        {
slouken@4465
   346
            WIN_UpdateKeymap();
slouken@2311
   347
        }
slouken@3566
   348
        returnCode = 1;
slouken@3566
   349
        break;
slouken@2311
   350
slouken@1895
   351
    case WM_GETMINMAXINFO:
slouken@1895
   352
        {
slouken@1895
   353
            MINMAXINFO *info;
slouken@1895
   354
            RECT size;
slouken@1895
   355
            int x, y;
slouken@1895
   356
            int w, h;
slouken@1895
   357
            int style;
slouken@3168
   358
            BOOL menu;
slouken@1895
   359
slouken@1895
   360
            /* If we allow resizing, let the resize happen naturally */
slouken@3685
   361
            if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
slouken@3566
   362
                returnCode = 0;
slouken@3566
   363
                break;
slouken@1895
   364
            }
slouken@1895
   365
slouken@1895
   366
            /* Get the current position of our window */
slouken@1895
   367
            GetWindowRect(hwnd, &size);
slouken@1895
   368
            x = size.left;
slouken@1895
   369
            y = size.top;
slouken@1895
   370
slouken@1895
   371
            /* Calculate current size of our window */
slouken@3685
   372
            SDL_GetWindowSize(data->window, &w, &h);
slouken@1895
   373
            size.top = 0;
slouken@1895
   374
            size.left = 0;
slouken@1895
   375
            size.bottom = h;
slouken@1895
   376
            size.right = w;
slouken@1895
   377
slouken@3168
   378
slouken@3168
   379
            style = GetWindowLong(hwnd, GWL_STYLE);
slouken@3168
   380
#ifdef _WIN32_WCE
slouken@3168
   381
            menu = FALSE;
slouken@3168
   382
#else
slouken@1895
   383
            /* DJM - according to the docs for GetMenu(), the
slouken@1895
   384
               return value is undefined if hwnd is a child window.
slouken@1895
   385
               Aparently it's too difficult for MS to check
slouken@1895
   386
               inside their function, so I have to do it here.
slouken@1895
   387
             */
slouken@3168
   388
            menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@3168
   389
#endif
slouken@3168
   390
            AdjustWindowRectEx(&size, style, menu, 0);
slouken@1895
   391
            w = size.right - size.left;
slouken@1895
   392
            h = size.bottom - size.top;
slouken@1895
   393
slouken@1895
   394
            /* Fix our size to the current size */
slouken@1895
   395
            info = (MINMAXINFO *) lParam;
slouken@1895
   396
            info->ptMaxSize.x = w;
slouken@1895
   397
            info->ptMaxSize.y = h;
slouken@1895
   398
            info->ptMaxPosition.x = x;
slouken@1895
   399
            info->ptMaxPosition.y = y;
slouken@1895
   400
            info->ptMinTrackSize.x = w;
slouken@1895
   401
            info->ptMinTrackSize.y = h;
slouken@1895
   402
            info->ptMaxTrackSize.x = w;
slouken@1895
   403
            info->ptMaxTrackSize.y = h;
slouken@1895
   404
        }
slouken@3566
   405
        returnCode = 0;
slouken@3566
   406
        break;
slouken@1895
   407
slouken@1895
   408
    case WM_WINDOWPOSCHANGED:
slouken@1895
   409
        {
slouken@1895
   410
            RECT rect;
slouken@1895
   411
            int x, y;
slouken@1895
   412
            int w, h;
slouken@1895
   413
            Uint32 window_flags;
slouken@1895
   414
slouken@3256
   415
            if (!GetClientRect(hwnd, &rect) ||
slouken@3256
   416
                (rect.right == rect.left && rect.bottom == rect.top)) {
slouken@3256
   417
                break;
slouken@3256
   418
            }
slouken@1895
   419
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   420
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   421
slouken@3685
   422
            window_flags = SDL_GetWindowFlags(data->window);
slouken@1895
   423
            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1895
   424
                (window_flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@1895
   425
                ClipCursor(&rect);
slouken@1895
   426
            }
slouken@1895
   427
slouken@1895
   428
            x = rect.left;
slouken@1895
   429
            y = rect.top;
slouken@3685
   430
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1895
   431
slouken@1895
   432
            w = rect.right - rect.left;
slouken@1895
   433
            h = rect.bottom - rect.top;
slouken@3685
   434
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, w,
slouken@1895
   435
                                h);
slouken@1895
   436
        }
slouken@1895
   437
        break;
slouken@1895
   438
slouken@1895
   439
    case WM_SETCURSOR:
slouken@1895
   440
        {
slouken@3076
   441
            Uint16 hittest;
slouken@1895
   442
slouken@3076
   443
            hittest = LOWORD(lParam);
slouken@3076
   444
            if (hittest == HTCLIENT) {
slouken@3076
   445
                /* FIXME: Implement the cursor API */
slouken@3076
   446
                static HCURSOR cursor;
slouken@3076
   447
                if (!cursor) {
slouken@3076
   448
                    cursor = LoadCursor(NULL, IDC_ARROW);
slouken@3076
   449
                }
slouken@3076
   450
                SetCursor(cursor);
slouken@3566
   451
                returnCode = TRUE;
slouken@3076
   452
            }
slouken@1895
   453
        }
slouken@1895
   454
        break;
slouken@1895
   455
slouken@1895
   456
        /* We are about to get palette focus! */
slouken@1895
   457
    case WM_QUERYNEWPALETTE:
slouken@1895
   458
        {
slouken@1895
   459
            /*
slouken@3566
   460
                WIN_RealizePalette(current_video);
slouken@3566
   461
                returnCode = TRUE;
slouken@1895
   462
             */
slouken@1895
   463
        }
slouken@1895
   464
        break;
slouken@1895
   465
slouken@1895
   466
        /* Another application changed the palette */
slouken@1895
   467
    case WM_PALETTECHANGED:
slouken@1895
   468
        {
slouken@1895
   469
            /*
slouken@1895
   470
               WIN_PaletteChanged(current_video, (HWND) wParam);
slouken@1895
   471
             */
slouken@1895
   472
        }
slouken@1895
   473
        break;
slouken@1895
   474
slouken@1895
   475
        /* We were occluded, refresh our display */
slouken@1895
   476
    case WM_PAINT:
slouken@1895
   477
        {
slouken@1895
   478
            RECT rect;
slouken@1895
   479
            if (GetUpdateRect(hwnd, &rect, FALSE)) {
slouken@1895
   480
                ValidateRect(hwnd, &rect);
slouken@3685
   481
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED,
slouken@1895
   482
                                    0, 0);
slouken@1895
   483
            }
slouken@1895
   484
        }
slouken@3566
   485
        returnCode = 0;
slouken@3566
   486
        break;
slouken@3095
   487
slouken@1895
   488
        /* We'll do our own drawing, prevent flicker */
slouken@1895
   489
    case WM_ERASEBKGND:
slouken@1895
   490
        {
slouken@1895
   491
        }
slouken@1895
   492
        return (1);
slouken@1895
   493
slouken@1895
   494
    case WM_SYSCOMMAND:
slouken@1895
   495
        {
slouken@1895
   496
            /* Don't start the screensaver or blank the monitor in fullscreen apps */
slouken@1895
   497
            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
slouken@1895
   498
                (wParam & 0xFFF0) == SC_MONITORPOWER) {
slouken@3032
   499
                if (SDL_GetVideoDevice()->suspend_screensaver) {
slouken@1895
   500
                    return (0);
slouken@1895
   501
                }
slouken@1895
   502
            }
slouken@1895
   503
        }
slouken@1895
   504
        break;
slouken@1895
   505
slouken@1895
   506
    case WM_CLOSE:
slouken@1895
   507
        {
slouken@3685
   508
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1895
   509
        }
slouken@3566
   510
        returnCode = 0;
slouken@3566
   511
        break;
slouken@1895
   512
    }
slouken@3566
   513
slouken@3566
   514
    /* If there's a window proc, assume it's going to handle messages */
slouken@3566
   515
    if (data->wndproc) {
slouken@3566
   516
        return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
slouken@3566
   517
    } else if (returnCode >= 0) {
slouken@3566
   518
        return returnCode;
slouken@3566
   519
    } else {
slouken@3566
   520
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@3566
   521
    }
slouken@1895
   522
}
slouken@1895
   523
slouken@1895
   524
void
slouken@1895
   525
WIN_PumpEvents(_THIS)
slouken@1895
   526
{
slouken@1895
   527
    MSG msg;
slouken@1895
   528
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
slouken@1895
   529
        TranslateMessage(&msg);
slouken@1895
   530
        DispatchMessage(&msg);
slouken@1895
   531
    }
slouken@1895
   532
}
slouken@1895
   533
slouken@1895
   534
static int app_registered = 0;
slouken@1895
   535
LPTSTR SDL_Appname = NULL;
slouken@1895
   536
Uint32 SDL_Appstyle = 0;
slouken@1895
   537
HINSTANCE SDL_Instance = NULL;
slouken@1895
   538
slouken@1895
   539
/* Register the class for this application */
slouken@1895
   540
int
slouken@1895
   541
SDL_RegisterApp(char *name, Uint32 style, void *hInst)
slouken@1895
   542
{
slouken@1895
   543
    WNDCLASS class;
slouken@1895
   544
slouken@1895
   545
    /* Only do this once... */
slouken@1895
   546
    if (app_registered) {
slouken@1895
   547
        ++app_registered;
slouken@1895
   548
        return (0);
slouken@1895
   549
    }
slouken@1895
   550
    if (!name && !SDL_Appname) {
slouken@1895
   551
        name = "SDL_app";
slouken@1895
   552
        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
slouken@1895
   553
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   554
    }
slouken@1895
   555
slouken@1895
   556
    if (name) {
slouken@1895
   557
        SDL_Appname = WIN_UTF8ToString(name);
slouken@1895
   558
        SDL_Appstyle = style;
slouken@1895
   559
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   560
    }
slouken@1895
   561
slouken@1895
   562
    /* Register the application class */
slouken@1895
   563
    class.hCursor = NULL;
slouken@2710
   564
    class.hIcon =
slouken@2710
   565
        LoadImage(SDL_Instance, SDL_Appname, IMAGE_ICON, 0, 0,
slouken@2710
   566
                  LR_DEFAULTCOLOR);
slouken@1895
   567
    class.lpszMenuName = NULL;
slouken@1895
   568
    class.lpszClassName = SDL_Appname;
slouken@1895
   569
    class.hbrBackground = NULL;
slouken@1895
   570
    class.hInstance = SDL_Instance;
slouken@1895
   571
    class.style = SDL_Appstyle;
slouken@1895
   572
    class.lpfnWndProc = DefWindowProc;
slouken@1895
   573
    class.cbWndExtra = 0;
slouken@1895
   574
    class.cbClsExtra = 0;
slouken@1895
   575
    if (!RegisterClass(&class)) {
slouken@1895
   576
        SDL_SetError("Couldn't register application class");
slouken@1895
   577
        return (-1);
slouken@1895
   578
    }
slouken@1895
   579
slouken@1895
   580
    app_registered = 1;
slouken@1895
   581
    return (0);
slouken@1895
   582
}
slouken@1895
   583
slouken@1895
   584
/* Unregisters the windowclass registered in SDL_RegisterApp above. */
slouken@1895
   585
void
slouken@1895
   586
SDL_UnregisterApp()
slouken@1895
   587
{
slouken@1895
   588
    WNDCLASS class;
slouken@1895
   589
slouken@1895
   590
    /* SDL_RegisterApp might not have been called before */
slouken@1895
   591
    if (!app_registered) {
slouken@1895
   592
        return;
slouken@1895
   593
    }
slouken@1895
   594
    --app_registered;
slouken@1895
   595
    if (app_registered == 0) {
slouken@1895
   596
        /* Check for any registered window classes. */
slouken@1895
   597
        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
slouken@1895
   598
            UnregisterClass(SDL_Appname, SDL_Instance);
slouken@1895
   599
        }
slouken@1895
   600
        SDL_free(SDL_Appname);
slouken@1895
   601
        SDL_Appname = NULL;
slouken@1895
   602
    }
slouken@1895
   603
}
slouken@1895
   604
slouken@1895
   605
/* vi: set ts=4 sw=4 expandtab: */