src/video/windows/SDL_windowswindow.c
author Ryan C. Gordon
Mon, 23 Jan 2017 12:06:10 -0500
changeset 10837 c2f241c2f6ad
parent 10816 c8d44526965e
child 10945 1300a3135d61
permissions -rw-r--r--
audio: Fix same bug as last commit, but for _mm_bslli_si128 vs _mm_slli_si128.
slouken@1895
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@1895
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1895
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1895
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1895
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1895
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@6044
    24
slouken@7828
    25
#include "../../core/windows/SDL_windows.h"
slouken@7828
    26
slouken@7523
    27
#include "SDL_assert.h"
slouken@1895
    28
#include "../SDL_sysvideo.h"
slouken@2970
    29
#include "../SDL_pixels_c.h"
slouken@1895
    30
#include "../../events/SDL_keyboard_c.h"
slouken@8072
    31
#include "../../events/SDL_mouse_c.h"
slouken@1895
    32
slouken@5062
    33
#include "SDL_windowsvideo.h"
slouken@5062
    34
#include "SDL_windowswindow.h"
slouken@8144
    35
#include "SDL_hints.h"
slouken@1895
    36
slouken@6523
    37
/* Dropfile support */
slouken@6523
    38
#include <shellapi.h>
slouken@6523
    39
slouken@5062
    40
/* This is included after SDL_windowsvideo.h, which includes windows.h */
slouken@1895
    41
#include "SDL_syswm.h"
slouken@3168
    42
slouken@5086
    43
/* Windows CE compatibility */
slouken@5086
    44
#ifndef SWP_NOCOPYBITS
slouken@5086
    45
#define SWP_NOCOPYBITS 0
slouken@5086
    46
#endif
slouken@3168
    47
slouken@2713
    48
/* Fake window to help with DirectInput events. */
slouken@2713
    49
HWND SDL_HelperWindow = NULL;
slouken@2714
    50
static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
slouken@2714
    51
static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
slouken@2713
    52
static ATOM SDL_HelperWindowClass = 0;
slouken@2713
    53
slouken@5305
    54
#define STYLE_BASIC         (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
slouken@5305
    55
#define STYLE_FULLSCREEN    (WS_POPUP)
slouken@5305
    56
#define STYLE_BORDERLESS    (WS_POPUP)
slouken@5305
    57
#define STYLE_NORMAL        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
slouken@5305
    58
#define STYLE_RESIZABLE     (WS_THICKFRAME | WS_MAXIMIZEBOX)
slouken@5305
    59
#define STYLE_MASK          (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
slouken@5305
    60
slouken@5305
    61
static DWORD
slouken@5305
    62
GetWindowStyle(SDL_Window * window)
slouken@5305
    63
{
slouken@5305
    64
    DWORD style = 0;
slouken@5305
    65
slouken@6078
    66
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@5305
    67
        style |= STYLE_FULLSCREEN;
slouken@6078
    68
    } else {
slouken@6078
    69
        if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@5305
    70
            style |= STYLE_BORDERLESS;
slouken@6078
    71
        } else {
slouken@5305
    72
            style |= STYLE_NORMAL;
slouken@6078
    73
        }
slouken@6078
    74
        if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5305
    75
            style |= STYLE_RESIZABLE;
slouken@6078
    76
        }
slouken@6078
    77
    }
slouken@5305
    78
    return style;
slouken@5305
    79
}
slouken@5305
    80
slouken@7585
    81
static void
slouken@7585
    82
WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
slouken@7585
    83
{
slouken@7941
    84
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
slouken@7941
    85
    HWND hwnd = data->hwnd;
slouken@7585
    86
    RECT rect;
slouken@7585
    87
    DWORD style;
slouken@7585
    88
    HWND top;
slouken@7585
    89
    BOOL menu;
slouken@7585
    90
    int x, y;
slouken@7585
    91
    int w, h;
slouken@7585
    92
slouken@7585
    93
    /* Figure out what the window area will be */
slouken@7585
    94
    if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
slouken@7585
    95
        top = HWND_TOPMOST;
slouken@7585
    96
    } else {
slouken@7585
    97
        top = HWND_NOTOPMOST;
slouken@7585
    98
    }
slouken@7585
    99
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@7585
   100
    rect.left = 0;
slouken@7585
   101
    rect.top = 0;
slouken@7585
   102
    rect.right = window->w;
slouken@7585
   103
    rect.bottom = window->h;
slouken@7585
   104
    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@7585
   105
    AdjustWindowRectEx(&rect, style, menu, 0);
slouken@7585
   106
    w = (rect.right - rect.left);
slouken@7585
   107
    h = (rect.bottom - rect.top);
slouken@7585
   108
    x = window->x + rect.left;
slouken@7585
   109
    y = window->y + rect.top;
slouken@7585
   110
slouken@8817
   111
    data->expected_resize = SDL_TRUE;
slouken@9886
   112
    SetWindowPos(hwnd, top, x, y, w, h, flags);
slouken@8817
   113
    data->expected_resize = SDL_FALSE;
slouken@7585
   114
}
slouken@7585
   115
slouken@1895
   116
static int
slouken@1951
   117
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
slouken@1895
   118
{
slouken@1951
   119
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1895
   120
    SDL_WindowData *data;
slouken@1895
   121
slouken@1895
   122
    /* Allocate the window data */
slouken@7775
   123
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1895
   124
    if (!data) {
icculus@7037
   125
        return SDL_OutOfMemory();
slouken@1895
   126
    }
slouken@3685
   127
    data->window = window;
slouken@1895
   128
    data->hwnd = hwnd;
slouken@1913
   129
    data->hdc = GetDC(hwnd);
slouken@10634
   130
    data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
slouken@1895
   131
    data->created = created;
slouken@6943
   132
    data->mouse_button_flags = 0;
slouken@1951
   133
    data->videodata = videodata;
slouken@9889
   134
    data->initializing = SDL_TRUE;
slouken@1895
   135
icculus@5980
   136
    window->driverdata = data;
icculus@5980
   137
slouken@1895
   138
    /* Associate the data with the window */
slouken@1895
   139
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
slouken@1913
   140
        ReleaseDC(hwnd, data->hdc);
slouken@1895
   141
        SDL_free(data);
icculus@7037
   142
        return WIN_SetError("SetProp() failed");
slouken@1895
   143
    }
slouken@1895
   144
slouken@1895
   145
    /* Set up the window proc function */
slouken@5086
   146
#ifdef GWLP_WNDPROC
slouken@1895
   147
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
dewyatt@4733
   148
    if (data->wndproc == WIN_WindowProc) {
slouken@3566
   149
        data->wndproc = NULL;
slouken@5086
   150
    } else {
dewyatt@4735
   151
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
dewyatt@4735
   152
    }
slouken@5086
   153
#else
slouken@5086
   154
    data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
slouken@5086
   155
    if (data->wndproc == WIN_WindowProc) {
slouken@5086
   156
        data->wndproc = NULL;
slouken@5086
   157
    } else {
slouken@5086
   158
        SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
slouken@5086
   159
    }
slouken@5086
   160
#endif
slouken@1895
   161
slouken@1895
   162
    /* Fill in the SDL window with the window data */
slouken@1895
   163
    {
slouken@7585
   164
        RECT rect;
slouken@7585
   165
        if (GetClientRect(hwnd, &rect)) {
slouken@7585
   166
            int w = rect.right;
slouken@7585
   167
            int h = rect.bottom;
slouken@7585
   168
            if ((window->w && window->w != w) || (window->h && window->h != h)) {
gabomdq@7663
   169
                /* We tried to create a window larger than the desktop and Windows didn't allow it.  Override! */
slouken@9886
   170
                RECT rect;
slouken@9886
   171
                DWORD style;
slouken@9886
   172
                BOOL menu;
slouken@9886
   173
                int x, y;
slouken@9886
   174
                int w, h;
slouken@9886
   175
slouken@9886
   176
                /* Figure out what the window area will be */
slouken@9886
   177
                style = GetWindowLong(hwnd, GWL_STYLE);
slouken@9886
   178
                rect.left = 0;
slouken@9886
   179
                rect.top = 0;
slouken@9886
   180
                rect.right = window->w;
slouken@9886
   181
                rect.bottom = window->h;
slouken@9886
   182
                menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@9886
   183
                AdjustWindowRectEx(&rect, style, menu, 0);
slouken@9886
   184
                w = (rect.right - rect.left);
slouken@9886
   185
                h = (rect.bottom - rect.top);
slouken@9886
   186
                x = window->x + rect.left;
slouken@9886
   187
                y = window->y + rect.top;
slouken@9886
   188
slouken@9886
   189
                SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
slouken@7585
   190
            } else {
slouken@7585
   191
                window->w = w;
slouken@7585
   192
                window->h = h;
slouken@7585
   193
            }
slouken@7585
   194
        }
slouken@7585
   195
    }
slouken@7585
   196
    {
slouken@1895
   197
        POINT point;
slouken@1895
   198
        point.x = 0;
slouken@1895
   199
        point.y = 0;
slouken@1895
   200
        if (ClientToScreen(hwnd, &point)) {
slouken@5246
   201
            window->x = point.x;
slouken@5246
   202
            window->y = point.y;
slouken@1895
   203
        }
slouken@1895
   204
    }
slouken@1895
   205
    {
slouken@1895
   206
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   207
        if (style & WS_VISIBLE) {
slouken@1895
   208
            window->flags |= SDL_WINDOW_SHOWN;
slouken@1895
   209
        } else {
slouken@1895
   210
            window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1895
   211
        }
slouken@1895
   212
        if (style & (WS_BORDER | WS_THICKFRAME)) {
slouken@1895
   213
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1895
   214
        } else {
slouken@1895
   215
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1895
   216
        }
slouken@1895
   217
        if (style & WS_THICKFRAME) {
slouken@1895
   218
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1895
   219
        } else {
slouken@1895
   220
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1895
   221
        }
slouken@5086
   222
#ifdef WS_MAXIMIZE
slouken@1895
   223
        if (style & WS_MAXIMIZE) {
slouken@1895
   224
            window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@5086
   225
        } else
slouken@5086
   226
#endif
slouken@5086
   227
        {
slouken@1895
   228
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1895
   229
        }
slouken@5086
   230
#ifdef WS_MINIMIZE
slouken@1895
   231
        if (style & WS_MINIMIZE) {
slouken@1895
   232
            window->flags |= SDL_WINDOW_MINIMIZED;
slouken@5086
   233
        } else
slouken@5086
   234
#endif
slouken@5086
   235
        {
slouken@1895
   236
            window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1895
   237
        }
slouken@1895
   238
    }
slouken@1895
   239
    if (GetFocus() == hwnd) {
slouken@1895
   240
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@4465
   241
        SDL_SetKeyboardFocus(data->window);
slouken@1895
   242
slouken@1895
   243
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1895
   244
            RECT rect;
slouken@1895
   245
            GetClientRect(hwnd, &rect);
slouken@1895
   246
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   247
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   248
            ClipCursor(&rect);
slouken@1895
   249
        }
slouken@1895
   250
    }
slouken@1895
   251
slouken@6078
   252
    /* Enable multi-touch */
slouken@4948
   253
    if (videodata->RegisterTouchWindow) {
slouken@4948
   254
        videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
slouken@4948
   255
    }
slouken@4919
   256
slouken@6523
   257
    /* Enable dropping files */
slouken@6523
   258
    DragAcceptFiles(hwnd, TRUE);
slouken@6523
   259
slouken@9889
   260
    data->initializing = SDL_FALSE;
slouken@9888
   261
slouken@1895
   262
    /* All done! */
slouken@1895
   263
    return 0;
slouken@1895
   264
}
slouken@1895
   265
slouken@10806
   266
slouken@10806
   267
slouken@1895
   268
int
slouken@1895
   269
WIN_CreateWindow(_THIS, SDL_Window * window)
slouken@1895
   270
{
slouken@1895
   271
    HWND hwnd;
slouken@1895
   272
    RECT rect;
slouken@5305
   273
    DWORD style = STYLE_BASIC;
slouken@1895
   274
    int x, y;
slouken@1895
   275
    int w, h;
slouken@7191
   276
slouken@5305
   277
    style |= GetWindowStyle(window);
slouken@1895
   278
slouken@1895
   279
    /* Figure out what the window area will be */
slouken@5382
   280
    rect.left = window->x;
slouken@5382
   281
    rect.top = window->y;
slouken@5382
   282
    rect.right = window->x + window->w;
slouken@5382
   283
    rect.bottom = window->y + window->h;
slouken@1895
   284
    AdjustWindowRectEx(&rect, style, FALSE, 0);
slouken@5382
   285
    x = rect.left;
slouken@5382
   286
    y = rect.top;
slouken@1895
   287
    w = (rect.right - rect.left);
slouken@1895
   288
    h = (rect.bottom - rect.top);
slouken@1895
   289
slouken@1956
   290
    hwnd =
slouken@1956
   291
        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
slouken@1956
   292
                     SDL_Instance, NULL);
slouken@1895
   293
    if (!hwnd) {
icculus@7037
   294
        return WIN_SetError("Couldn't create window");
slouken@1895
   295
    }
slouken@1895
   296
slouken@2710
   297
    WIN_PumpEvents(_this);
slouken@2710
   298
slouken@1951
   299
    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
slouken@1895
   300
        DestroyWindow(hwnd);
slouken@1895
   301
        return -1;
slouken@1895
   302
    }
gabomdq@8021
   303
slouken@10806
   304
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
slouken@10806
   305
        return 0;
gabomdq@8021
   306
    }
gabomdq@8021
   307
slouken@10806
   308
    /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
gabomdq@8021
   309
#if SDL_VIDEO_OPENGL_ES2
slouken@10806
   310
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
slouken@10806
   311
#if SDL_VIDEO_OPENGL_WGL
slouken@10806
   312
        && (!_this->gl_data || WIN_GL_UseEGL(_this))
slouken@10806
   313
#endif /* SDL_VIDEO_OPENGL_WGL */
slouken@10806
   314
    ) {
slouken@10806
   315
#if SDL_VIDEO_OPENGL_EGL
gabomdq@8021
   316
        if (WIN_GLES_SetupWindow(_this, window) < 0) {
gabomdq@8021
   317
            WIN_DestroyWindow(_this, window);
gabomdq@8021
   318
            return -1;
gabomdq@8021
   319
        }
slouken@10806
   320
        return 0;
gabomdq@8021
   321
#else
slouken@10806
   322
        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
slouken@10806
   323
#endif /* SDL_VIDEO_OPENGL_EGL */ 
slouken@10806
   324
    }
gabomdq@8021
   325
#endif /* SDL_VIDEO_OPENGL_ES2 */
gabomdq@8021
   326
slouken@5088
   327
#if SDL_VIDEO_OPENGL_WGL
slouken@10806
   328
    if (WIN_GL_SetupWindow(_this, window) < 0) {
slouken@10806
   329
        WIN_DestroyWindow(_this, window);
slouken@10806
   330
        return -1;
slouken@1913
   331
    }
slouken@10806
   332
#else
slouken@10806
   333
    return SDL_SetError("Could not create GL window (WGL support not configured)");
slouken@1913
   334
#endif
gabomdq@8021
   335
slouken@1895
   336
    return 0;
slouken@1895
   337
}
slouken@1895
   338
slouken@1895
   339
int
slouken@1895
   340
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1895
   341
{
slouken@1895
   342
    HWND hwnd = (HWND) data;
slouken@1895
   343
    LPTSTR title;
slouken@1895
   344
    int titleLen;
slouken@1895
   345
slouken@1895
   346
    /* Query the title from the existing window */
slouken@1895
   347
    titleLen = GetWindowTextLength(hwnd);
slouken@1895
   348
    title = SDL_stack_alloc(TCHAR, titleLen + 1);
slouken@1895
   349
    if (title) {
slouken@1895
   350
        titleLen = GetWindowText(hwnd, title, titleLen);
slouken@1895
   351
    } else {
slouken@1895
   352
        titleLen = 0;
slouken@1895
   353
    }
slouken@1895
   354
    if (titleLen > 0) {
slouken@1895
   355
        window->title = WIN_StringToUTF8(title);
slouken@1895
   356
    }
slouken@1895
   357
    if (title) {
slouken@1895
   358
        SDL_stack_free(title);
slouken@1895
   359
    }
slouken@1895
   360
slouken@1951
   361
    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
slouken@1895
   362
        return -1;
slouken@1895
   363
    }
slouken@8144
   364
slouken@8144
   365
#if SDL_VIDEO_OPENGL_WGL
slouken@8144
   366
    {
slouken@8144
   367
        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
slouken@8144
   368
        if (hint) {
philipp@8778
   369
            /* This hint is a pointer (in string form) of the address of
philipp@8778
   370
               the window to share a pixel format with
philipp@8778
   371
            */
slouken@8144
   372
            SDL_Window *otherWindow = NULL;
slouken@8144
   373
            SDL_sscanf(hint, "%p", (void**)&otherWindow);
slouken@8144
   374
philipp@8778
   375
            /* Do some error checking on the pointer */
slouken@8144
   376
            if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
slouken@8144
   377
            {
philipp@8778
   378
                /* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
slouken@8144
   379
                if (otherWindow->flags & SDL_WINDOW_OPENGL)
slouken@8144
   380
                {
slouken@8144
   381
                    window->flags |= SDL_WINDOW_OPENGL;
slouken@8144
   382
                    if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
slouken@8144
   383
                        return -1;
slouken@8144
   384
                    }
slouken@8144
   385
                }
slouken@8144
   386
            }
slouken@8144
   387
        }
slouken@8144
   388
    }
slouken@8144
   389
#endif
slouken@1895
   390
    return 0;
slouken@1895
   391
}
slouken@1895
   392
slouken@1895
   393
void
slouken@1895
   394
WIN_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1895
   395
{
slouken@1895
   396
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
icculus@9474
   397
    LPTSTR title = WIN_UTF8ToString(window->title);
icculus@9474
   398
    SetWindowText(hwnd, title);
slouken@7719
   399
    SDL_free(title);
slouken@1895
   400
}
slouken@1895
   401
slouken@1895
   402
void
slouken@2970
   403
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@2970
   404
{
slouken@2970
   405
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@2970
   406
    HICON hicon = NULL;
slouken@5418
   407
    BYTE *icon_bmp;
slouken@7527
   408
    int icon_len, y;
slouken@5418
   409
    SDL_RWops *dst;
slouken@2970
   410
slouken@5418
   411
    /* Create temporary bitmap buffer */
slouken@10816
   412
    icon_len = 40 + icon->h * icon->w * sizeof(Uint32);
slouken@5418
   413
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
slouken@5418
   414
    dst = SDL_RWFromMem(icon_bmp, icon_len);
slouken@5418
   415
    if (!dst) {
slouken@5418
   416
        SDL_stack_free(icon_bmp);
slouken@5418
   417
        return;
slouken@5418
   418
    }
slouken@2970
   419
slouken@5418
   420
    /* Write the BITMAPINFO header */
slouken@5418
   421
    SDL_WriteLE32(dst, 40);
slouken@5418
   422
    SDL_WriteLE32(dst, icon->w);
slouken@5418
   423
    SDL_WriteLE32(dst, icon->h * 2);
slouken@5418
   424
    SDL_WriteLE16(dst, 1);
slouken@5418
   425
    SDL_WriteLE16(dst, 32);
slouken@5418
   426
    SDL_WriteLE32(dst, BI_RGB);
slouken@10816
   427
    SDL_WriteLE32(dst, icon->h * icon->w * sizeof(Uint32));
slouken@5418
   428
    SDL_WriteLE32(dst, 0);
slouken@5418
   429
    SDL_WriteLE32(dst, 0);
slouken@5418
   430
    SDL_WriteLE32(dst, 0);
slouken@5418
   431
    SDL_WriteLE32(dst, 0);
slouken@2970
   432
slouken@7523
   433
    /* Write the pixels upside down into the bitmap buffer */
slouken@7523
   434
    SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
slouken@7527
   435
    y = icon->h;
slouken@7523
   436
    while (y--) {
slouken@7523
   437
        Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
slouken@10816
   438
        SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
slouken@7523
   439
    }
slouken@2970
   440
slouken@7523
   441
    hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
slouken@7523
   442
slouken@5418
   443
    SDL_RWclose(dst);
slouken@5418
   444
    SDL_stack_free(icon_bmp);
slouken@2970
   445
slouken@2971
   446
    /* Set the icon for the window */
slouken@2990
   447
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
slouken@2971
   448
slouken@2971
   449
    /* Set the icon in the task manager (should we do this?) */
slouken@2990
   450
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
slouken@2970
   451
}
slouken@2970
   452
icculus@6427
   453
void
icculus@6427
   454
WIN_SetWindowPosition(_THIS, SDL_Window * window)
icculus@6427
   455
{
slouken@6535
   456
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
slouken@1895
   457
}
slouken@1895
   458
slouken@1895
   459
void
slouken@1895
   460
WIN_SetWindowSize(_THIS, SDL_Window * window)
slouken@1895
   461
{
slouken@6535
   462
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
slouken@5246
   463
}
slouken@5246
   464
slouken@1895
   465
void
slouken@1895
   466
WIN_ShowWindow(_THIS, SDL_Window * window)
slouken@1895
   467
{
slouken@1895
   468
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   469
    ShowWindow(hwnd, SW_SHOW);
slouken@1895
   470
}
slouken@1895
   471
slouken@1895
   472
void
slouken@1895
   473
WIN_HideWindow(_THIS, SDL_Window * window)
slouken@1895
   474
{
slouken@1895
   475
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   476
    ShowWindow(hwnd, SW_HIDE);
slouken@1895
   477
}
slouken@1895
   478
slouken@1895
   479
void
slouken@1895
   480
WIN_RaiseWindow(_THIS, SDL_Window * window)
slouken@1895
   481
{
slime73@10450
   482
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slime73@10450
   483
    SetForegroundWindow(hwnd);
slouken@1895
   484
}
slouken@1895
   485
slouken@1895
   486
void
slouken@1895
   487
WIN_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1895
   488
{
slouken@7941
   489
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
slouken@7941
   490
    HWND hwnd = data->hwnd;
slouken@8817
   491
    data->expected_resize = SDL_TRUE;
slouken@4569
   492
    ShowWindow(hwnd, SW_MAXIMIZE);
slouken@8817
   493
    data->expected_resize = SDL_FALSE;
slouken@1895
   494
}
slouken@1895
   495
slouken@1895
   496
void
slouken@1895
   497
WIN_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1895
   498
{
slouken@1895
   499
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   500
    ShowWindow(hwnd, SW_MINIMIZE);
slouken@1895
   501
}
slouken@1895
   502
slouken@1895
   503
void
icculus@6422
   504
WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
icculus@6422
   505
{
slouken@8817
   506
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
slouken@8817
   507
    HWND hwnd = data->hwnd;
icculus@6428
   508
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
icculus@6428
   509
icculus@6428
   510
    if (bordered) {
icculus@6428
   511
        style &= ~STYLE_BORDERLESS;
icculus@6428
   512
        style |= STYLE_NORMAL;
icculus@6428
   513
    } else {
icculus@6428
   514
        style &= ~STYLE_NORMAL;
icculus@6428
   515
        style |= STYLE_BORDERLESS;
icculus@6428
   516
    }
icculus@6428
   517
slouken@8817
   518
    data->in_border_change = SDL_TRUE;
slouken@9886
   519
    SetWindowLong(hwnd, GWL_STYLE, style);
slouken@8817
   520
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
slouken@8817
   521
    data->in_border_change = SDL_FALSE;
icculus@6422
   522
}
icculus@6422
   523
icculus@6422
   524
void
icculus@10385
   525
WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
icculus@10385
   526
{
icculus@10385
   527
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
icculus@10385
   528
    HWND hwnd = data->hwnd;
icculus@10385
   529
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
icculus@10385
   530
icculus@10385
   531
    if (resizable) {
icculus@10385
   532
        style |= STYLE_RESIZABLE;
icculus@10385
   533
    } else {
icculus@10385
   534
        style &= ~STYLE_RESIZABLE;
icculus@10385
   535
    }
icculus@10385
   536
icculus@10385
   537
    SetWindowLong(hwnd, GWL_STYLE, style);
icculus@10385
   538
}
icculus@10385
   539
icculus@10385
   540
void
slouken@1895
   541
WIN_RestoreWindow(_THIS, SDL_Window * window)
slouken@1895
   542
{
slouken@7941
   543
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
slouken@7941
   544
    HWND hwnd = data->hwnd;
slouken@8817
   545
    data->expected_resize = SDL_TRUE;
slouken@1895
   546
    ShowWindow(hwnd, SW_RESTORE);
slouken@8817
   547
    data->expected_resize = SDL_FALSE;
slouken@1895
   548
}
slouken@1895
   549
slouken@1895
   550
void
slouken@5305
   551
WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
slouken@5305
   552
{
slouken@5305
   553
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@5305
   554
    HWND hwnd = data->hwnd;
slouken@5305
   555
    RECT rect;
slouken@5305
   556
    SDL_Rect bounds;
slouken@5305
   557
    DWORD style;
slouken@5305
   558
    HWND top;
slouken@5305
   559
    BOOL menu;
slouken@5305
   560
    int x, y;
slouken@5305
   561
    int w, h;
slouken@5305
   562
slouken@7585
   563
    if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
slouken@7191
   564
        top = HWND_TOPMOST;
slouken@7191
   565
    } else {
slouken@7191
   566
        top = HWND_NOTOPMOST;
slouken@7191
   567
    }
slouken@6782
   568
slouken@5305
   569
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@5305
   570
    style &= ~STYLE_MASK;
slouken@5305
   571
    style |= GetWindowStyle(window);
slouken@5305
   572
slouken@5305
   573
    WIN_GetDisplayBounds(_this, display, &bounds);
slouken@5305
   574
slouken@5305
   575
    if (fullscreen) {
slouken@5305
   576
        x = bounds.x;
slouken@5305
   577
        y = bounds.y;
slouken@5305
   578
        w = bounds.w;
slouken@5305
   579
        h = bounds.h;
dludwig@9990
   580
dludwig@9990
   581
        /* Unset the maximized flag.  This fixes
dludwig@9990
   582
           https://bugzilla.libsdl.org/show_bug.cgi?id=3215
dludwig@9990
   583
        */
dludwig@9990
   584
        if (style & WS_MAXIMIZE) {
dludwig@9990
   585
            data->windowed_mode_was_maximized = SDL_TRUE;
dludwig@9990
   586
            style &= ~WS_MAXIMIZE;
dludwig@9990
   587
        }
slouken@5305
   588
    } else {
dludwig@9990
   589
        /* Restore window-maximization state, as applicable.
dludwig@9990
   590
           Special care is taken to *not* do this if and when we're
dludwig@9990
   591
           alt-tab'ing away (to some other window; as indicated by
dludwig@9990
   592
           in_window_deactivation), otherwise
dludwig@9990
   593
           https://bugzilla.libsdl.org/show_bug.cgi?id=3215 can reproduce!
dludwig@9990
   594
        */
dludwig@9990
   595
        if (data->windowed_mode_was_maximized && !data->in_window_deactivation) {
dludwig@9990
   596
            style |= WS_MAXIMIZE;
dludwig@9990
   597
            data->windowed_mode_was_maximized = SDL_FALSE;
dludwig@9990
   598
        }
slouken@5305
   599
        rect.left = 0;
slouken@5305
   600
        rect.top = 0;
slouken@5398
   601
        rect.right = window->windowed.w;
slouken@5398
   602
        rect.bottom = window->windowed.h;
slouken@5305
   603
        menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@5305
   604
        AdjustWindowRectEx(&rect, style, menu, 0);
slouken@5305
   605
        w = (rect.right - rect.left);
slouken@5305
   606
        h = (rect.bottom - rect.top);
slouken@5398
   607
        x = window->windowed.x + rect.left;
slouken@5398
   608
        y = window->windowed.y + rect.top;
slouken@5305
   609
    }
slouken@5305
   610
    SetWindowLong(hwnd, GWL_STYLE, style);
slouken@8817
   611
    data->expected_resize = SDL_TRUE;
slouken@8205
   612
    SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
slouken@8817
   613
    data->expected_resize = SDL_FALSE;
slouken@5305
   614
}
slouken@5305
   615
slouken@5466
   616
int
slouken@5466
   617
WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
slouken@5466
   618
{
slouken@5466
   619
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5466
   620
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
slouken@5466
   621
    HDC hdc;
slouken@5466
   622
    BOOL succeeded = FALSE;
slouken@5466
   623
slouken@5466
   624
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
slouken@5466
   625
    if (hdc) {
slouken@5466
   626
        succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
slouken@5466
   627
        if (!succeeded) {
slouken@5466
   628
            WIN_SetError("SetDeviceGammaRamp()");
slouken@5466
   629
        }
slouken@5466
   630
        DeleteDC(hdc);
slouken@5466
   631
    }
slouken@5466
   632
    return succeeded ? 0 : -1;
slouken@5466
   633
}
slouken@5466
   634
slouken@5466
   635
int
slouken@5466
   636
WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
slouken@5466
   637
{
slouken@5466
   638
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5466
   639
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
slouken@5466
   640
    HDC hdc;
slouken@5466
   641
    BOOL succeeded = FALSE;
slouken@5466
   642
slouken@5466
   643
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
slouken@5466
   644
    if (hdc) {
slouken@5466
   645
        succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
slouken@5466
   646
        if (!succeeded) {
slouken@5466
   647
            WIN_SetError("GetDeviceGammaRamp()");
slouken@5466
   648
        }
slouken@5466
   649
        DeleteDC(hdc);
slouken@5466
   650
    }
slouken@5466
   651
    return succeeded ? 0 : -1;
slouken@5466
   652
}
slouken@5466
   653
slouken@5305
   654
void
slouken@6662
   655
WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
slouken@1895
   656
{
slouken@8072
   657
    WIN_UpdateClipCursor(window);
slouken@6782
   658
slouken@7585
   659
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@7584
   660
        UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
slouken@6782
   661
slouken@7584
   662
        if (!(window->flags & SDL_WINDOW_SHOWN)) {
slouken@7584
   663
            flags |= SWP_NOACTIVATE;
slouken@7584
   664
        }
slouken@7585
   665
        WIN_SetWindowPositionInternal(_this, window, flags);
slouken@7191
   666
    }
slouken@1895
   667
}
slouken@1895
   668
slouken@1895
   669
void
slouken@1895
   670
WIN_DestroyWindow(_THIS, SDL_Window * window)
slouken@1895
   671
{
slouken@1895
   672
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1895
   673
slouken@1895
   674
    if (data) {
slouken@1913
   675
        ReleaseDC(data->hwnd, data->hdc);
slouken@9665
   676
        RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
slouken@1895
   677
        if (data->created) {
slouken@1895
   678
            DestroyWindow(data->hwnd);
icculus@5580
   679
        } else {
icculus@5580
   680
            /* Restore any original event handler... */
icculus@5580
   681
            if (data->wndproc != NULL) {
icculus@5580
   682
#ifdef GWLP_WNDPROC
icculus@5581
   683
                SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
icculus@5581
   684
                                 (LONG_PTR) data->wndproc);
icculus@5580
   685
#else
icculus@5581
   686
                SetWindowLong(data->hwnd, GWL_WNDPROC,
icculus@5581
   687
                              (LONG_PTR) data->wndproc);
icculus@5580
   688
#endif
icculus@5580
   689
            }
slouken@1895
   690
        }
slouken@1895
   691
        SDL_free(data);
slouken@1895
   692
    }
slouken@8978
   693
    window->driverdata = NULL;
slouken@1895
   694
}
slouken@1895
   695
slouken@1895
   696
SDL_bool
slouken@1895
   697
WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1895
   698
{
icculus@9422
   699
    const SDL_WindowData *data = (const SDL_WindowData *) window->driverdata;
slouken@1895
   700
    if (info->version.major <= SDL_MAJOR_VERSION) {
philipp@10631
   701
        int versionnum = SDL_VERSIONNUM(info->version.major, info->version.minor, info->version.patch);
philipp@10631
   702
slouken@4900
   703
        info->subsystem = SDL_SYSWM_WINDOWS;
icculus@9422
   704
        info->info.win.window = data->hwnd;
philipp@10631
   705
philipp@10631
   706
        if (versionnum >= SDL_VERSIONNUM(2, 0, 4)) {
philipp@10631
   707
            info->info.win.hdc = data->hdc;
philipp@10631
   708
        }
philipp@10631
   709
slouken@10634
   710
        if (versionnum >= SDL_VERSIONNUM(2, 0, 5)) {
slouken@10634
   711
            info->info.win.hinstance = data->hinstance;
slouken@10634
   712
        }
slouken@10634
   713
slouken@1895
   714
        return SDL_TRUE;
slouken@1895
   715
    } else {
slouken@1895
   716
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1895
   717
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1895
   718
        return SDL_FALSE;
slouken@1895
   719
    }
slouken@1895
   720
}
slouken@1895
   721
slouken@2713
   722
slouken@2713
   723
/*
slouken@2713
   724
 * Creates a HelperWindow used for DirectInput events.
slouken@2713
   725
 */
slouken@2713
   726
int
slouken@2713
   727
SDL_HelperWindowCreate(void)
slouken@2713
   728
{
slouken@3097
   729
    HINSTANCE hInstance = GetModuleHandle(NULL);
slouken@3097
   730
    WNDCLASS wce;
slouken@2713
   731
bobbens@3045
   732
    /* Make sure window isn't created twice. */
bobbens@3045
   733
    if (SDL_HelperWindow != NULL) {
bobbens@3045
   734
        return 0;
bobbens@3045
   735
    }
bobbens@3045
   736
slouken@2713
   737
    /* Create the class. */
slouken@2714
   738
    SDL_zero(wce);
slouken@3097
   739
    wce.lpfnWndProc = DefWindowProc;
slouken@2713
   740
    wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
slouken@2713
   741
    wce.hInstance = hInstance;
slouken@2713
   742
slouken@2713
   743
    /* Register the class. */
slouken@3097
   744
    SDL_HelperWindowClass = RegisterClass(&wce);
slouken@8238
   745
    if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
icculus@7037
   746
        return WIN_SetError("Unable to create Helper Window Class");
slouken@2713
   747
    }
slouken@2713
   748
slouken@2713
   749
    /* Create the window. */
slouken@2714
   750
    SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
slouken@2714
   751
                                      SDL_HelperWindowName,
slouken@3168
   752
                                      WS_OVERLAPPED, CW_USEDEFAULT,
slouken@2714
   753
                                      CW_USEDEFAULT, CW_USEDEFAULT,
icculus@6430
   754
                                      CW_USEDEFAULT, HWND_MESSAGE, NULL,
slouken@2714
   755
                                      hInstance, NULL);
slouken@2713
   756
    if (SDL_HelperWindow == NULL) {
bobbens@3045
   757
        UnregisterClass(SDL_HelperWindowClassName, hInstance);
icculus@7037
   758
        return WIN_SetError("Unable to create Helper Window");
slouken@2713
   759
    }
slouken@2713
   760
slouken@2713
   761
    return 0;
slouken@2713
   762
}
slouken@2713
   763
slouken@2713
   764
slouken@2713
   765
/*
slouken@2713
   766
 * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
slouken@2713
   767
 */
slouken@2713
   768
void
slouken@2713
   769
SDL_HelperWindowDestroy(void)
slouken@2713
   770
{
slouken@3097
   771
    HINSTANCE hInstance = GetModuleHandle(NULL);
bobbens@2863
   772
slouken@2713
   773
    /* Destroy the window. */
bobbens@2863
   774
    if (SDL_HelperWindow != NULL) {
bobbens@2863
   775
        if (DestroyWindow(SDL_HelperWindow) == 0) {
slouken@4500
   776
            WIN_SetError("Unable to destroy Helper Window");
slouken@2865
   777
            return;
bobbens@2863
   778
        }
slouken@2713
   779
        SDL_HelperWindow = NULL;
slouken@2713
   780
    }
slouken@2713
   781
slouken@2713
   782
    /* Unregister the class. */
bobbens@2863
   783
    if (SDL_HelperWindowClass != 0) {
bobbens@2863
   784
        if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
slouken@4500
   785
            WIN_SetError("Unable to destroy Helper Window Class");
slouken@2865
   786
            return;
bobbens@2863
   787
        }
slouken@2713
   788
        SDL_HelperWindowClass = 0;
slouken@2713
   789
    }
slouken@2713
   790
}
slouken@2713
   791
jorgen@7089
   792
void WIN_OnWindowEnter(_THIS, SDL_Window * window)
jorgen@7089
   793
{
jorgen@7089
   794
#ifdef WM_MOUSELEAVE
jorgen@7089
   795
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
jorgen@7089
   796
    TRACKMOUSEEVENT trackMouseEvent;
jorgen@7089
   797
jorgen@7089
   798
    if (!data || !data->hwnd) {
jorgen@7089
   799
        /* The window wasn't fully initialized */
jorgen@7089
   800
        return;
jorgen@7089
   801
    }
jorgen@7089
   802
jorgen@7089
   803
    trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
jorgen@7089
   804
    trackMouseEvent.dwFlags = TME_LEAVE;
jorgen@7089
   805
    trackMouseEvent.hwndTrack = data->hwnd;
jorgen@7089
   806
jorgen@7089
   807
    TrackMouseEvent(&trackMouseEvent);
jorgen@7089
   808
#endif /* WM_MOUSELEAVE */
jorgen@7089
   809
}
jorgen@7089
   810
slouken@8072
   811
void
slouken@8072
   812
WIN_UpdateClipCursor(SDL_Window *window)
slouken@8072
   813
{
slouken@8072
   814
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@8072
   815
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@8072
   816
slouken@8916
   817
    if (data->focus_click_pending) {
slouken@8072
   818
        return;
slouken@8072
   819
    }
slouken@8072
   820
slouken@8072
   821
    if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
slouken@8072
   822
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@8072
   823
        if (mouse->relative_mode && !mouse->relative_mode_warp) {
slouken@8072
   824
            LONG cx, cy;
slouken@8072
   825
            RECT rect;
slouken@8072
   826
            GetWindowRect(data->hwnd, &rect);
slouken@8072
   827
slouken@8072
   828
            cx = (rect.left + rect.right) / 2;
slouken@8072
   829
            cy = (rect.top + rect.bottom) / 2;
slouken@8072
   830
slouken@8072
   831
            /* Make an absurdly small clip rect */
slouken@8072
   832
            rect.left = cx - 1;
slouken@8072
   833
            rect.right = cx + 1;
slouken@8072
   834
            rect.top = cy - 1;
slouken@8072
   835
            rect.bottom = cy + 1;
slouken@8072
   836
slouken@8072
   837
            ClipCursor(&rect);
slouken@8072
   838
        } else {
slouken@8072
   839
            RECT rect;
slouken@8072
   840
            if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
slouken@8072
   841
                ClientToScreen(data->hwnd, (LPPOINT) & rect);
slouken@8072
   842
                ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
slouken@8072
   843
                ClipCursor(&rect);
slouken@8072
   844
            }
slouken@8072
   845
        }
slouken@8072
   846
    } else {
slouken@8072
   847
        ClipCursor(NULL);
slouken@8072
   848
    }
slouken@8072
   849
}
slouken@8072
   850
icculus@8938
   851
int
icculus@8938
   852
WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
icculus@8938
   853
{
icculus@8938
   854
    return 0;  /* just succeed, the real work is done elsewhere. */
icculus@8938
   855
}
icculus@8938
   856
icculus@10025
   857
int
icculus@10025
   858
WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
icculus@10025
   859
{
icculus@10025
   860
    const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
icculus@10025
   861
    const HWND hwnd = data->hwnd;
icculus@10025
   862
    const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
icculus@10025
   863
icculus@10025
   864
    SDL_assert(style != 0);
icculus@10025
   865
icculus@10025
   866
    if (opacity == 1.0f) {
icculus@10025
   867
        /* want it fully opaque, just mark it unlayered if necessary. */
icculus@10025
   868
        if (style & WS_EX_LAYERED) {
icculus@10025
   869
            if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
icculus@10025
   870
                return WIN_SetError("SetWindowLong()");
icculus@10025
   871
            }
icculus@10025
   872
        }
icculus@10025
   873
    } else {
icculus@10025
   874
        const BYTE alpha = (BYTE) ((int) (opacity * 255.0f));
icculus@10025
   875
        /* want it transparent, mark it layered if necessary. */
icculus@10025
   876
        if ((style & WS_EX_LAYERED) == 0) {
icculus@10025
   877
            if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
icculus@10025
   878
                return WIN_SetError("SetWindowLong()");
icculus@10025
   879
            }
icculus@10025
   880
        }
icculus@10025
   881
icculus@10025
   882
        if (SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA) == 0) {
icculus@10025
   883
            return WIN_SetError("SetLayeredWindowAttributes()");
icculus@10025
   884
        }
icculus@10025
   885
    }
icculus@10025
   886
icculus@10025
   887
    return 0;
icculus@10025
   888
}
icculus@10025
   889
slouken@6044
   890
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
slouken@6044
   891
slouken@1895
   892
/* vi: set ts=4 sw=4 expandtab: */