src/video/win32/SDL_win32window.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 27 Jul 2010 21:31:28 -0700
changeset 4569 e1664f94f026
parent 4500 eff4e88cc1e8
child 4694 c24ba2cc9583
permissions -rw-r--r--
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
/* we need to define it, so that raw input is included */
slouken@2710
    24
slouken@2710
    25
#if (_WIN32_WINNT < 0x0501)
slouken@2710
    26
#undef _WIN32_WINNT
slouken@2710
    27
#define _WIN32_WINNT 0x0501
slouken@2710
    28
#endif
slouken@2710
    29
slouken@1895
    30
#include "SDL_config.h"
slouken@1895
    31
slouken@1895
    32
#include "../SDL_sysvideo.h"
slouken@2970
    33
#include "../SDL_pixels_c.h"
slouken@1895
    34
#include "../../events/SDL_keyboard_c.h"
slouken@1895
    35
slouken@1895
    36
#include "SDL_win32video.h"
slouken@4569
    37
#include "SDL_win32window.h"
slouken@1895
    38
slouken@1895
    39
/* This is included after SDL_win32video.h, which includes windows.h */
slouken@1895
    40
#include "SDL_syswm.h"
slouken@4569
    41
#include "SDL_gapirender.h"
slouken@3168
    42
slouken@3168
    43
slouken@2713
    44
/* Fake window to help with DirectInput events. */
slouken@2713
    45
HWND SDL_HelperWindow = NULL;
slouken@2714
    46
static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
slouken@2714
    47
static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
slouken@2713
    48
static ATOM SDL_HelperWindowClass = 0;
slouken@2713
    49
slouken@1895
    50
static int
slouken@1951
    51
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
slouken@1895
    52
{
slouken@1951
    53
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@3685
    54
    SDL_VideoDisplay *display = window->display;
slouken@1895
    55
    SDL_WindowData *data;
slouken@1895
    56
slouken@1895
    57
    /* Allocate the window data */
slouken@1895
    58
    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
slouken@1895
    59
    if (!data) {
slouken@1895
    60
        SDL_OutOfMemory();
slouken@1895
    61
        return -1;
slouken@1895
    62
    }
slouken@3685
    63
    data->window = window;
slouken@1895
    64
    data->hwnd = hwnd;
slouken@1913
    65
    data->hdc = GetDC(hwnd);
slouken@1895
    66
    data->created = created;
slouken@1895
    67
    data->mouse_pressed = SDL_FALSE;
slouken@1951
    68
    data->videodata = videodata;
slouken@1895
    69
slouken@1895
    70
    /* Associate the data with the window */
slouken@1895
    71
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
slouken@1913
    72
        ReleaseDC(hwnd, data->hdc);
slouken@1895
    73
        SDL_free(data);
slouken@1895
    74
        WIN_SetError("SetProp() failed");
slouken@1895
    75
        return -1;
slouken@1895
    76
    }
slouken@1895
    77
slouken@1895
    78
    /* Set up the window proc function */
slouken@1895
    79
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
slouken@3566
    80
    if (data->wndproc == DefWindowProc) {
slouken@3566
    81
        data->wndproc = NULL;
slouken@1895
    82
    }
slouken@3566
    83
    SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
slouken@1895
    84
slouken@1895
    85
    /* Fill in the SDL window with the window data */
slouken@1895
    86
    {
slouken@1895
    87
        POINT point;
slouken@1895
    88
        point.x = 0;
slouken@1895
    89
        point.y = 0;
slouken@1895
    90
        if (ClientToScreen(hwnd, &point)) {
slouken@3530
    91
            SDL_Rect bounds;
slouken@3530
    92
            WIN_GetDisplayBounds(_this, display, &bounds);
slouken@3530
    93
            window->x = point.x - bounds.x;
slouken@3530
    94
            window->y = point.y - bounds.y;
slouken@1895
    95
        }
slouken@1895
    96
    }
slouken@1895
    97
    {
slouken@1895
    98
        RECT rect;
slouken@1895
    99
        if (GetClientRect(hwnd, &rect)) {
slouken@1895
   100
            window->w = rect.right;
slouken@1895
   101
            window->h = rect.bottom;
slouken@1895
   102
        }
slouken@1895
   103
    }
slouken@1895
   104
    {
slouken@1895
   105
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   106
        if (style & WS_VISIBLE) {
slouken@1895
   107
            window->flags |= SDL_WINDOW_SHOWN;
slouken@1895
   108
        } else {
slouken@1895
   109
            window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1895
   110
        }
slouken@1895
   111
        if (style & (WS_BORDER | WS_THICKFRAME)) {
slouken@1895
   112
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1895
   113
        } else {
slouken@1895
   114
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1895
   115
        }
slouken@1895
   116
        if (style & WS_THICKFRAME) {
slouken@1895
   117
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1895
   118
        } else {
slouken@1895
   119
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1895
   120
        }
slouken@1895
   121
        if (style & WS_MAXIMIZE) {
slouken@1895
   122
            window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1895
   123
        } else {
slouken@1895
   124
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1895
   125
        }
slouken@1895
   126
        if (style & WS_MINIMIZE) {
slouken@1895
   127
            window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1895
   128
        } else {
slouken@1895
   129
            window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1895
   130
        }
slouken@1895
   131
    }
slouken@1895
   132
    if (GetFocus() == hwnd) {
slouken@1895
   133
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@4465
   134
        SDL_SetKeyboardFocus(data->window);
slouken@1895
   135
slouken@1895
   136
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1895
   137
            RECT rect;
slouken@1895
   138
            GetClientRect(hwnd, &rect);
slouken@1895
   139
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   140
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   141
            ClipCursor(&rect);
slouken@1895
   142
        }
slouken@1895
   143
    }
slouken@1895
   144
slouken@1895
   145
    /* All done! */
slouken@1895
   146
    window->driverdata = data;
slouken@1895
   147
    return 0;
slouken@1895
   148
}
slouken@1895
   149
slouken@1895
   150
int
slouken@1895
   151
WIN_CreateWindow(_THIS, SDL_Window * window)
slouken@1895
   152
{
slouken@3685
   153
    SDL_VideoDisplay *display = window->display;
slouken@1895
   154
    HWND hwnd;
slouken@1895
   155
    RECT rect;
slouken@3528
   156
    SDL_Rect bounds;
slouken@1913
   157
    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
slouken@1895
   158
    int x, y;
slouken@1895
   159
    int w, h;
slouken@1895
   160
slouken@2876
   161
    if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
slouken@1895
   162
        style |= WS_POPUP;
slouken@1895
   163
    } else {
slouken@1895
   164
        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
slouken@1895
   165
    }
slouken@2876
   166
    if ((window->flags & SDL_WINDOW_RESIZABLE)
slouken@2876
   167
        && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@1895
   168
        style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
slouken@1895
   169
    }
slouken@1895
   170
slouken@1895
   171
    /* Figure out what the window area will be */
slouken@1895
   172
    rect.left = 0;
slouken@1895
   173
    rect.top = 0;
slouken@1895
   174
    rect.right = window->w;
slouken@1895
   175
    rect.bottom = window->h;
slouken@1895
   176
    AdjustWindowRectEx(&rect, style, FALSE, 0);
slouken@1895
   177
    w = (rect.right - rect.left);
slouken@1895
   178
    h = (rect.bottom - rect.top);
slouken@1895
   179
slouken@3528
   180
    WIN_GetDisplayBounds(_this, display, &bounds);
slouken@4486
   181
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@4486
   182
        /* The bounds when this window is visible is the fullscreen mode */
slouken@4486
   183
        SDL_DisplayMode fullscreen_mode;
slouken@4486
   184
        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
slouken@4486
   185
            bounds.w = fullscreen_mode.w;
slouken@4486
   186
            bounds.h = fullscreen_mode.h;
slouken@4486
   187
        }
slouken@4486
   188
    }
slouken@2876
   189
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   190
        || window->x == SDL_WINDOWPOS_CENTERED) {
slouken@4486
   191
        x = bounds.x + (bounds.w - w) / 2;
slouken@1895
   192
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@3528
   193
        if (bounds.x == 0) {
slouken@3528
   194
            x = CW_USEDEFAULT;
slouken@3528
   195
        } else {
slouken@3528
   196
            x = bounds.x;
slouken@3528
   197
        }
slouken@1895
   198
    } else {
slouken@3530
   199
        x = bounds.x + window->x + rect.left;
slouken@1895
   200
    }
slouken@2876
   201
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   202
        || window->y == SDL_WINDOWPOS_CENTERED) {
slouken@4486
   203
        y = bounds.y + (bounds.h - h) / 2;
slouken@3528
   204
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@3528
   205
        if (bounds.x == 0) {
slouken@3528
   206
            y = CW_USEDEFAULT;
slouken@3528
   207
        } else {
slouken@3528
   208
            y = bounds.y;
slouken@3528
   209
        }
slouken@1895
   210
    } else {
slouken@3530
   211
        y = bounds.y + window->y + rect.top;
slouken@1895
   212
    }
slouken@1895
   213
slouken@1956
   214
    hwnd =
slouken@1956
   215
        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
slouken@1956
   216
                     SDL_Instance, NULL);
slouken@1895
   217
    if (!hwnd) {
slouken@1895
   218
        WIN_SetError("Couldn't create window");
slouken@1895
   219
        return -1;
slouken@1895
   220
    }
slouken@1895
   221
slouken@2710
   222
    WIN_PumpEvents(_this);
slouken@2710
   223
slouken@1951
   224
    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
slouken@1895
   225
        DestroyWindow(hwnd);
slouken@1895
   226
        return -1;
slouken@1895
   227
    }
slouken@1952
   228
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   229
    if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1913
   230
        if (WIN_GL_SetupWindow(_this, window) < 0) {
slouken@1913
   231
            WIN_DestroyWindow(_this, window);
slouken@1913
   232
            return -1;
slouken@1913
   233
        }
slouken@1913
   234
    }
slouken@1913
   235
#endif
slouken@1895
   236
    return 0;
slouken@1895
   237
}
slouken@1895
   238
slouken@1895
   239
int
slouken@1895
   240
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1895
   241
{
slouken@1895
   242
    HWND hwnd = (HWND) data;
slouken@1895
   243
    LPTSTR title;
slouken@1895
   244
    int titleLen;
slouken@1895
   245
slouken@1895
   246
    /* Query the title from the existing window */
slouken@1895
   247
    titleLen = GetWindowTextLength(hwnd);
slouken@1895
   248
    title = SDL_stack_alloc(TCHAR, titleLen + 1);
slouken@1895
   249
    if (title) {
slouken@1895
   250
        titleLen = GetWindowText(hwnd, title, titleLen);
slouken@1895
   251
    } else {
slouken@1895
   252
        titleLen = 0;
slouken@1895
   253
    }
slouken@1895
   254
    if (titleLen > 0) {
slouken@1895
   255
        window->title = WIN_StringToUTF8(title);
slouken@1895
   256
    }
slouken@1895
   257
    if (title) {
slouken@1895
   258
        SDL_stack_free(title);
slouken@1895
   259
    }
slouken@1895
   260
slouken@1951
   261
    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
slouken@1895
   262
        return -1;
slouken@1895
   263
    }
slouken@1895
   264
    return 0;
slouken@1895
   265
}
slouken@1895
   266
slouken@1895
   267
void
slouken@1895
   268
WIN_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1895
   269
{
slouken@1895
   270
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   271
    LPTSTR title;
slouken@1895
   272
slouken@1895
   273
    if (window->title) {
slouken@1895
   274
        title = WIN_UTF8ToString(window->title);
slouken@1895
   275
    } else {
slouken@1895
   276
        title = NULL;
slouken@1895
   277
    }
slouken@1895
   278
    SetWindowText(hwnd, title ? title : TEXT(""));
slouken@1895
   279
    if (title) {
slouken@1895
   280
        SDL_free(title);
slouken@1895
   281
    }
slouken@1895
   282
}
slouken@1895
   283
slouken@1895
   284
void
slouken@2970
   285
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@2970
   286
{
slouken@2970
   287
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@2970
   288
    HICON hicon = NULL;
slouken@2970
   289
slouken@2990
   290
    if (icon) {
slouken@2970
   291
        BYTE *icon_bmp;
slouken@2970
   292
        int icon_len;
slouken@2970
   293
        SDL_RWops *dst;
slouken@2970
   294
        SDL_PixelFormat format;
slouken@2970
   295
        SDL_Surface *surface;
slouken@2970
   296
slouken@2970
   297
        /* Create temporary bitmap buffer */
slouken@2970
   298
        icon_len = 40 + icon->h * icon->w * 4;
slouken@2970
   299
        icon_bmp = SDL_stack_alloc(BYTE, icon_len);
slouken@2970
   300
        dst = SDL_RWFromMem(icon_bmp, icon_len);
slouken@2970
   301
        if (!dst) {
slouken@2970
   302
            SDL_stack_free(icon_bmp);
slouken@2970
   303
            return;
slouken@2970
   304
        }
slouken@2970
   305
slouken@2970
   306
        /* Write the BITMAPINFO header */
slouken@2970
   307
        SDL_WriteLE32(dst, 40);
slouken@2970
   308
        SDL_WriteLE32(dst, icon->w);
slouken@2990
   309
        SDL_WriteLE32(dst, icon->h * 2);
slouken@2970
   310
        SDL_WriteLE16(dst, 1);
slouken@2970
   311
        SDL_WriteLE16(dst, 32);
slouken@2970
   312
        SDL_WriteLE32(dst, BI_RGB);
slouken@2970
   313
        SDL_WriteLE32(dst, icon->h * icon->w * 4);
slouken@2970
   314
        SDL_WriteLE32(dst, 0);
slouken@2970
   315
        SDL_WriteLE32(dst, 0);
slouken@2970
   316
        SDL_WriteLE32(dst, 0);
slouken@2970
   317
        SDL_WriteLE32(dst, 0);
slouken@2970
   318
slouken@2970
   319
        /* Convert the icon to a 32-bit surface with alpha channel */
slouken@2970
   320
        SDL_InitFormat(&format, 32,
slouken@2970
   321
                       0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
slouken@2970
   322
        surface = SDL_ConvertSurface(icon, &format, 0);
slouken@2970
   323
        if (surface) {
slouken@2970
   324
            /* Write the pixels upside down into the bitmap buffer */
slouken@2970
   325
            int y = surface->h;
slouken@2970
   326
            while (y--) {
slouken@2990
   327
                Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
slouken@2970
   328
                SDL_RWwrite(dst, src, surface->pitch, 1);
slouken@2970
   329
            }
slouken@2970
   330
            SDL_FreeSurface(surface);
slouken@2970
   331
slouken@3097
   332
/* TODO: create the icon in WinCE (CreateIconFromResource isn't available) */
slouken@3097
   333
#ifndef _WIN32_WCE
slouken@2990
   334
            hicon =
slouken@2990
   335
                CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
slouken@3097
   336
#endif
slouken@2970
   337
        }
slouken@2970
   338
        SDL_RWclose(dst);
slouken@2970
   339
        SDL_stack_free(icon_bmp);
slouken@2970
   340
    }
slouken@2970
   341
slouken@2971
   342
    /* Set the icon for the window */
slouken@2990
   343
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
slouken@2971
   344
slouken@2971
   345
    /* Set the icon in the task manager (should we do this?) */
slouken@2990
   346
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
slouken@2970
   347
}
slouken@2970
   348
slouken@2970
   349
void
slouken@1895
   350
WIN_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1895
   351
{
slouken@3685
   352
    SDL_VideoDisplay *display = window->display;
slouken@1895
   353
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   354
    RECT rect;
slouken@3528
   355
    SDL_Rect bounds;
slouken@1895
   356
    DWORD style;
slouken@1895
   357
    HWND top;
slouken@3168
   358
    BOOL menu;
slouken@1895
   359
    int x, y;
slouken@4486
   360
    int w, h;
slouken@1895
   361
slouken@1895
   362
    /* Figure out what the window area will be */
slouken@1895
   363
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   364
        top = HWND_TOPMOST;
slouken@1895
   365
    } else {
slouken@1895
   366
        top = HWND_NOTOPMOST;
slouken@1895
   367
    }
slouken@1895
   368
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   369
    rect.left = 0;
slouken@1895
   370
    rect.top = 0;
slouken@1895
   371
    rect.right = window->w;
slouken@1895
   372
    rect.bottom = window->h;
slouken@3168
   373
#ifdef _WIN32_WCE
slouken@3168
   374
    menu = FALSE;
slouken@3168
   375
#else
slouken@3168
   376
    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@3168
   377
#endif
slouken@3168
   378
    AdjustWindowRectEx(&rect, style, menu, 0);
slouken@4486
   379
    w = (rect.right - rect.left);
slouken@4486
   380
    h = (rect.bottom - rect.top);
slouken@2875
   381
slouken@3528
   382
    WIN_GetDisplayBounds(_this, display, &bounds);
slouken@4486
   383
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@4486
   384
        /* The bounds when this window is visible is the fullscreen mode */
slouken@4486
   385
        SDL_DisplayMode fullscreen_mode;
slouken@4486
   386
        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
slouken@4486
   387
            bounds.w = fullscreen_mode.w;
slouken@4486
   388
            bounds.h = fullscreen_mode.h;
slouken@4486
   389
        }
slouken@4486
   390
    }
slouken@2876
   391
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   392
        || window->x == SDL_WINDOWPOS_CENTERED) {
slouken@4486
   393
        x = bounds.x + (bounds.w - w) / 2;
slouken@2875
   394
    } else {
slouken@3530
   395
        x = bounds.x + window->x + rect.left;
slouken@2875
   396
    }
slouken@2876
   397
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   398
        || window->y == SDL_WINDOWPOS_CENTERED) {
slouken@4486
   399
        y = bounds.y + (bounds.h - h) / 2;
slouken@2875
   400
    } else {
slouken@3530
   401
        y = bounds.y + window->y + rect.top;
slouken@2875
   402
    }
slouken@1895
   403
slouken@1956
   404
    SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
slouken@1895
   405
}
slouken@1895
   406
slouken@1895
   407
void
slouken@1895
   408
WIN_SetWindowSize(_THIS, SDL_Window * window)
slouken@1895
   409
{
slouken@1895
   410
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   411
    RECT rect;
slouken@1895
   412
    DWORD style;
slouken@1895
   413
    HWND top;
slouken@3168
   414
    BOOL menu;
slouken@1895
   415
    int w, h;
slouken@1895
   416
slouken@1895
   417
    /* Figure out what the window area will be */
slouken@1895
   418
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   419
        top = HWND_TOPMOST;
slouken@1895
   420
    } else {
slouken@1895
   421
        top = HWND_NOTOPMOST;
slouken@1895
   422
    }
slouken@1895
   423
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   424
    rect.left = 0;
slouken@1895
   425
    rect.top = 0;
slouken@1895
   426
    rect.right = window->w;
slouken@1895
   427
    rect.bottom = window->h;
slouken@3168
   428
#ifdef _WIN32_WCE
slouken@3168
   429
    menu = FALSE;
slouken@3168
   430
#else
slouken@3168
   431
    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@3168
   432
#endif
slouken@3168
   433
    AdjustWindowRectEx(&rect, style, menu, 0);
slouken@1895
   434
    w = (rect.right - rect.left);
slouken@1895
   435
    h = (rect.bottom - rect.top);
slouken@1895
   436
slouken@2968
   437
    SetWindowPos(hwnd, top, 0, 0, w, h, (SWP_NOCOPYBITS | SWP_NOMOVE));
slouken@1895
   438
}
slouken@1895
   439
slouken@1895
   440
void
slouken@1895
   441
WIN_ShowWindow(_THIS, SDL_Window * window)
slouken@1895
   442
{
slouken@4569
   443
#ifdef _WIN32_WCE
slouken@4569
   444
    WINCE_ShowWindow(_this, window, 1);
slouken@4569
   445
#else
slouken@1895
   446
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   447
    ShowWindow(hwnd, SW_SHOW);
slouken@3168
   448
#endif
slouken@1895
   449
}
slouken@1895
   450
slouken@1895
   451
void
slouken@1895
   452
WIN_HideWindow(_THIS, SDL_Window * window)
slouken@1895
   453
{
slouken@4569
   454
#ifdef _WIN32_WCE
slouken@4569
   455
    WINCE_ShowWindow(_this, window, 0);
slouken@4569
   456
#else
slouken@1895
   457
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   458
    ShowWindow(hwnd, SW_HIDE);
slouken@3168
   459
#endif
slouken@1895
   460
}
slouken@1895
   461
slouken@1895
   462
void
slouken@1895
   463
WIN_RaiseWindow(_THIS, SDL_Window * window)
slouken@1895
   464
{
slouken@1895
   465
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   466
    HWND top;
slouken@1895
   467
slouken@1895
   468
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   469
        top = HWND_TOPMOST;
slouken@1895
   470
    } else {
slouken@1895
   471
        top = HWND_NOTOPMOST;
slouken@1895
   472
    }
slouken@1895
   473
    SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
slouken@1895
   474
}
slouken@1895
   475
slouken@1895
   476
void
slouken@1895
   477
WIN_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1895
   478
{
slouken@1895
   479
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@4569
   480
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@3168
   481
slouken@3168
   482
#ifdef _WIN32_WCE
slouken@4569
   483
    if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
slouken@4569
   484
        videodata->SHFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
slouken@3168
   485
#endif
slouken@4569
   486
slouken@4569
   487
    ShowWindow(hwnd, SW_MAXIMIZE);
slouken@1895
   488
}
slouken@1895
   489
slouken@1895
   490
void
slouken@1895
   491
WIN_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1895
   492
{
slouken@1895
   493
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@4569
   494
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1895
   495
slouken@1895
   496
    ShowWindow(hwnd, SW_MINIMIZE);
slouken@3168
   497
slouken@3168
   498
#ifdef _WIN32_WCE
slouken@4569
   499
    if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
slouken@4569
   500
	videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
slouken@3168
   501
#endif
slouken@1895
   502
}
slouken@1895
   503
slouken@1895
   504
void
slouken@1895
   505
WIN_RestoreWindow(_THIS, SDL_Window * window)
slouken@1895
   506
{
slouken@1895
   507
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   508
slouken@1895
   509
    ShowWindow(hwnd, SW_RESTORE);
slouken@1895
   510
}
slouken@1895
   511
slouken@1895
   512
void
slouken@1895
   513
WIN_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1895
   514
{
slouken@1895
   515
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   516
slouken@2876
   517
    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
slouken@2876
   518
        && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@1895
   519
        RECT rect;
slouken@1895
   520
        GetClientRect(hwnd, &rect);
slouken@1895
   521
        ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   522
        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   523
        ClipCursor(&rect);
slouken@1895
   524
    } else {
slouken@1895
   525
        ClipCursor(NULL);
slouken@1895
   526
    }
slouken@1895
   527
}
slouken@1895
   528
slouken@1895
   529
void
slouken@1895
   530
WIN_DestroyWindow(_THIS, SDL_Window * window)
slouken@1895
   531
{
slouken@1895
   532
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1895
   533
slouken@1895
   534
    if (data) {
slouken@4569
   535
#ifdef _WIN32_WCE
slouken@4569
   536
	WINCE_ShowWindow(_this, window, 0);
slouken@4569
   537
#endif
slouken@1913
   538
        ReleaseDC(data->hwnd, data->hdc);
slouken@1895
   539
        if (data->created) {
slouken@1895
   540
            DestroyWindow(data->hwnd);
slouken@1895
   541
        }
slouken@1895
   542
        SDL_free(data);
slouken@1895
   543
    }
slouken@1895
   544
}
slouken@1895
   545
slouken@1895
   546
SDL_bool
slouken@1895
   547
WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1895
   548
{
slouken@1895
   549
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   550
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@1895
   551
        info->window = hwnd;
slouken@1895
   552
        return SDL_TRUE;
slouken@1895
   553
    } else {
slouken@1895
   554
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1895
   555
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1895
   556
        return SDL_FALSE;
slouken@1895
   557
    }
slouken@1895
   558
}
slouken@1895
   559
slouken@2713
   560
slouken@2713
   561
/*
slouken@2713
   562
 * Creates a HelperWindow used for DirectInput events.
slouken@2713
   563
 */
slouken@2713
   564
int
slouken@2713
   565
SDL_HelperWindowCreate(void)
slouken@2713
   566
{
slouken@3097
   567
    HINSTANCE hInstance = GetModuleHandle(NULL);
slouken@3097
   568
    WNDCLASS wce;
slouken@3196
   569
    HWND hWndParent = NULL;
slouken@2713
   570
bobbens@3045
   571
    /* Make sure window isn't created twice. */
bobbens@3045
   572
    if (SDL_HelperWindow != NULL) {
bobbens@3045
   573
        return 0;
bobbens@3045
   574
    }
bobbens@3045
   575
slouken@2713
   576
    /* Create the class. */
slouken@2714
   577
    SDL_zero(wce);
slouken@3097
   578
    wce.lpfnWndProc = DefWindowProc;
slouken@2713
   579
    wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
slouken@2713
   580
    wce.hInstance = hInstance;
slouken@2713
   581
slouken@2713
   582
    /* Register the class. */
slouken@3097
   583
    SDL_HelperWindowClass = RegisterClass(&wce);
slouken@2713
   584
    if (SDL_HelperWindowClass == 0) {
slouken@4500
   585
        WIN_SetError("Unable to create Helper Window Class");
slouken@2713
   586
        return -1;
slouken@2713
   587
    }
slouken@2713
   588
slouken@3168
   589
#ifndef _WIN32_WCE
slouken@3168
   590
    /* WinCE doesn't have HWND_MESSAGE */
slouken@3168
   591
    hWndParent = HWND_MESSAGE;
slouken@3168
   592
#endif
slouken@3168
   593
slouken@2713
   594
    /* Create the window. */
slouken@2714
   595
    SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
slouken@2714
   596
                                      SDL_HelperWindowName,
slouken@3168
   597
                                      WS_OVERLAPPED, CW_USEDEFAULT,
slouken@2714
   598
                                      CW_USEDEFAULT, CW_USEDEFAULT,
slouken@3168
   599
                                      CW_USEDEFAULT, hWndParent, NULL,
slouken@2714
   600
                                      hInstance, NULL);
slouken@2713
   601
    if (SDL_HelperWindow == NULL) {
bobbens@3045
   602
        UnregisterClass(SDL_HelperWindowClassName, hInstance);
slouken@4500
   603
        WIN_SetError("Unable to create Helper Window");
slouken@2713
   604
        return -1;
slouken@2713
   605
    }
slouken@2713
   606
slouken@2713
   607
    return 0;
slouken@2713
   608
}
slouken@2713
   609
slouken@2713
   610
slouken@2713
   611
/*
slouken@2713
   612
 * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
slouken@2713
   613
 */
slouken@2713
   614
void
slouken@2713
   615
SDL_HelperWindowDestroy(void)
slouken@2713
   616
{
slouken@3097
   617
    HINSTANCE hInstance = GetModuleHandle(NULL);
bobbens@2863
   618
slouken@2713
   619
    /* Destroy the window. */
bobbens@2863
   620
    if (SDL_HelperWindow != NULL) {
bobbens@2863
   621
        if (DestroyWindow(SDL_HelperWindow) == 0) {
slouken@4500
   622
            WIN_SetError("Unable to destroy Helper Window");
slouken@2865
   623
            return;
bobbens@2863
   624
        }
slouken@2713
   625
        SDL_HelperWindow = NULL;
slouken@2713
   626
    }
slouken@2713
   627
slouken@2713
   628
    /* Unregister the class. */
bobbens@2863
   629
    if (SDL_HelperWindowClass != 0) {
bobbens@2863
   630
        if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
slouken@4500
   631
            WIN_SetError("Unable to destroy Helper Window Class");
slouken@2865
   632
            return;
bobbens@2863
   633
        }
slouken@2713
   634
        SDL_HelperWindowClass = 0;
slouken@2713
   635
    }
slouken@2713
   636
}
slouken@2713
   637
slouken@2713
   638
slouken@1895
   639
/* vi: set ts=4 sw=4 expandtab: */