src/video/win32/SDL_win32window.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 25 Aug 2008 06:33:00 +0000
changeset 2710 44e49d3fa6cf
parent 1956 ba0d62354872
child 2713 0906692aa6a4
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Many-mouse and tablet support
by Szymon Wilczek, mentored by Ryan C. Gordon

Everything concerning the project is noted on the wiki:
http://wilku.ravenlord.ws/doku.php?id=start
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@1895
     3
    Copyright (C) 1997-2006 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@1895
    33
#include "../../events/SDL_keyboard_c.h"
slouken@1895
    34
slouken@1895
    35
#include "SDL_win32video.h"
slouken@1895
    36
slouken@1895
    37
/* This is included after SDL_win32video.h, which includes windows.h */
slouken@1895
    38
#include "SDL_syswm.h"
slouken@1895
    39
slouken@2710
    40
#include <wintab.h>
slouken@2710
    41
slouken@2710
    42
/* we're telling wintab that we want to receive movement, button events and pressure information in packets */
slouken@2710
    43
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
slouken@2710
    44
#define PACKETMODE 0
slouken@2710
    45
#include <pktdef.h>
slouken@2710
    46
slouken@2710
    47
extern HCTX *g_hCtx;            /* the table of tablet event contexts, each windows has to have it's own tablet context */
slouken@2710
    48
int highestId = 0;              /* the highest id of the tablet context */
slouken@1895
    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@1895
    54
    SDL_WindowData *data;
slouken@1895
    55
slouken@1895
    56
    /* Allocate the window data */
slouken@1895
    57
    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
slouken@1895
    58
    if (!data) {
slouken@1895
    59
        SDL_OutOfMemory();
slouken@1895
    60
        return -1;
slouken@1895
    61
    }
slouken@1895
    62
    data->windowID = window->id;
slouken@1895
    63
    data->hwnd = hwnd;
slouken@1913
    64
    data->hdc = GetDC(hwnd);
slouken@1895
    65
    data->created = created;
slouken@1895
    66
    data->mouse_pressed = SDL_FALSE;
slouken@1951
    67
    data->videodata = videodata;
slouken@1895
    68
slouken@1895
    69
    /* Associate the data with the window */
slouken@1895
    70
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
slouken@1913
    71
        ReleaseDC(hwnd, data->hdc);
slouken@1895
    72
        SDL_free(data);
slouken@1895
    73
        WIN_SetError("SetProp() failed");
slouken@1895
    74
        return -1;
slouken@1895
    75
    }
slouken@1895
    76
slouken@1895
    77
    /* Set up the window proc function */
slouken@1895
    78
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
slouken@1895
    79
    if (data->wndproc == NULL) {
slouken@1895
    80
        data->wndproc = DefWindowProc;
slouken@1895
    81
    } else {
slouken@1895
    82
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
slouken@1895
    83
    }
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@1895
    91
            window->x = point.x;
slouken@1895
    92
            window->y = point.y;
slouken@1895
    93
        }
slouken@1895
    94
    }
slouken@1895
    95
    {
slouken@1895
    96
        RECT rect;
slouken@1895
    97
        if (GetClientRect(hwnd, &rect)) {
slouken@1895
    98
            window->w = rect.right;
slouken@1895
    99
            window->h = rect.bottom;
slouken@1895
   100
        }
slouken@1895
   101
    }
slouken@1895
   102
    {
slouken@1895
   103
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   104
        if (style & WS_VISIBLE) {
slouken@1895
   105
            window->flags |= SDL_WINDOW_SHOWN;
slouken@1895
   106
        } else {
slouken@1895
   107
            window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1895
   108
        }
slouken@1895
   109
        if (style & (WS_BORDER | WS_THICKFRAME)) {
slouken@1895
   110
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1895
   111
        } else {
slouken@1895
   112
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1895
   113
        }
slouken@1895
   114
        if (style & WS_THICKFRAME) {
slouken@1895
   115
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1895
   116
        } else {
slouken@1895
   117
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1895
   118
        }
slouken@1895
   119
        if (style & WS_MAXIMIZE) {
slouken@1895
   120
            window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1895
   121
        } else {
slouken@1895
   122
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1895
   123
        }
slouken@1895
   124
        if (style & WS_MINIMIZE) {
slouken@1895
   125
            window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1895
   126
        } else {
slouken@1895
   127
            window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1895
   128
        }
slouken@1895
   129
    }
slouken@1895
   130
    if (GetFocus() == hwnd) {
slouken@1895
   131
        int index = data->videodata->keyboard;
slouken@1895
   132
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@1895
   133
        SDL_SetKeyboardFocus(index, data->windowID);
slouken@1895
   134
slouken@1895
   135
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1895
   136
            RECT rect;
slouken@1895
   137
            GetClientRect(hwnd, &rect);
slouken@1895
   138
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   139
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   140
            ClipCursor(&rect);
slouken@1895
   141
        }
slouken@1895
   142
    }
slouken@1895
   143
slouken@1895
   144
    /* All done! */
slouken@1895
   145
    window->driverdata = data;
slouken@1895
   146
    return 0;
slouken@1895
   147
}
slouken@1895
   148
slouken@1895
   149
int
slouken@1895
   150
WIN_CreateWindow(_THIS, SDL_Window * window)
slouken@1895
   151
{
slouken@2710
   152
    RAWINPUTDEVICE Rid;
slouken@2710
   153
    AXIS TabX, TabY;
slouken@2710
   154
    LOGCONTEXT lc;
slouken@1895
   155
    HWND hwnd;
slouken@1895
   156
    HWND top;
slouken@1895
   157
    RECT rect;
slouken@1913
   158
    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
slouken@1895
   159
    int x, y;
slouken@1895
   160
    int w, h;
slouken@1895
   161
slouken@1956
   162
    if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@1895
   163
        style |= WS_POPUP;
slouken@1895
   164
    } else {
slouken@1895
   165
        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
slouken@1895
   166
    }
slouken@1895
   167
    if (window->flags & SDL_WINDOW_RESIZABLE) {
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
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   173
        top = HWND_TOPMOST;
slouken@1895
   174
    } else {
slouken@1895
   175
        top = HWND_NOTOPMOST;
slouken@1895
   176
    }
slouken@1895
   177
    rect.left = 0;
slouken@1895
   178
    rect.top = 0;
slouken@1895
   179
    rect.right = window->w;
slouken@1895
   180
    rect.bottom = window->h;
slouken@1895
   181
    AdjustWindowRectEx(&rect, style, FALSE, 0);
slouken@1895
   182
    w = (rect.right - rect.left);
slouken@1895
   183
    h = (rect.bottom - rect.top);
slouken@1895
   184
slouken@1956
   185
    if (window->x == SDL_WINDOWPOS_CENTERED) {
slouken@1895
   186
        x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
slouken@1895
   187
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@1895
   188
        x = CW_USEDEFAULT;
slouken@1895
   189
    } else {
slouken@1895
   190
        x = window->x + rect.left;
slouken@1895
   191
    }
slouken@1956
   192
    if (window->y == SDL_WINDOWPOS_CENTERED) {
slouken@1895
   193
        y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
slouken@1895
   194
    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
slouken@1895
   195
        y = CW_USEDEFAULT;
slouken@1895
   196
    } else {
slouken@1895
   197
        y = window->y + rect.top;
slouken@1895
   198
    }
slouken@1895
   199
slouken@1956
   200
    hwnd =
slouken@1956
   201
        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
slouken@1956
   202
                     SDL_Instance, NULL);
slouken@1895
   203
    if (!hwnd) {
slouken@1895
   204
        WIN_SetError("Couldn't create window");
slouken@1895
   205
        return -1;
slouken@1895
   206
    }
slouken@1895
   207
slouken@2710
   208
    /* we're configuring the tablet data. See Wintab reference for more info */
slouken@2710
   209
    if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) {
slouken@2710
   210
        lc.lcPktData = PACKETDATA;
slouken@2710
   211
        lc.lcPktMode = PACKETMODE;
slouken@2710
   212
        lc.lcOptions |= CXO_MESSAGES;
slouken@2710
   213
        lc.lcOptions |= CXO_SYSTEM;
slouken@2710
   214
        lc.lcMoveMask = PACKETDATA;
slouken@2710
   215
        lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA;
slouken@2710
   216
        WTInfo(WTI_DEVICES, DVC_X, &TabX);
slouken@2710
   217
        WTInfo(WTI_DEVICES, DVC_Y, &TabY);
slouken@2710
   218
        lc.lcInOrgX = 0;
slouken@2710
   219
        lc.lcInOrgY = 0;
slouken@2710
   220
        lc.lcInExtX = TabX.axMax;
slouken@2710
   221
        lc.lcInExtY = TabY.axMax;
slouken@2710
   222
        lc.lcOutOrgX = 0;
slouken@2710
   223
        lc.lcOutOrgY = 0;
slouken@2710
   224
        lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
slouken@2710
   225
        lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
slouken@2710
   226
        if (window->id > highestId) {
slouken@2710
   227
            HCTX *tmp_hctx;
slouken@2710
   228
            highestId = window->id;
slouken@2710
   229
            tmp_hctx =
slouken@2710
   230
                (HCTX *) SDL_realloc(g_hCtx, (highestId + 1) * sizeof(HCTX));
slouken@2710
   231
            if (!tmp_hctx) {
slouken@2710
   232
                SDL_OutOfMemory();
slouken@2710
   233
                DestroyWindow(hwnd);
slouken@2710
   234
                return -1;
slouken@2710
   235
            }
slouken@2710
   236
            g_hCtx = tmp_hctx;
slouken@2710
   237
        }
slouken@2710
   238
        g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
slouken@2710
   239
    }
slouken@2710
   240
slouken@2710
   241
    /* we're telling the window, we want it to report raw input events from mice */
slouken@2710
   242
    Rid.usUsagePage = 0x01;
slouken@2710
   243
    Rid.usUsage = 0x02;
slouken@2710
   244
    Rid.dwFlags = RIDEV_INPUTSINK;
slouken@2710
   245
    Rid.hwndTarget = hwnd;
slouken@2710
   246
    RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
slouken@2710
   247
slouken@2710
   248
    WIN_PumpEvents(_this);
slouken@2710
   249
slouken@1951
   250
    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
slouken@1895
   251
        DestroyWindow(hwnd);
slouken@1895
   252
        return -1;
slouken@1895
   253
    }
slouken@1952
   254
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   255
    if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1913
   256
        if (WIN_GL_SetupWindow(_this, window) < 0) {
slouken@1913
   257
            WIN_DestroyWindow(_this, window);
slouken@1913
   258
            return -1;
slouken@1913
   259
        }
slouken@1913
   260
    }
slouken@1913
   261
#endif
slouken@1895
   262
    return 0;
slouken@1895
   263
}
slouken@1895
   264
slouken@1895
   265
int
slouken@1895
   266
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1895
   267
{
slouken@1895
   268
    HWND hwnd = (HWND) data;
slouken@1895
   269
    LPTSTR title;
slouken@1895
   270
    int titleLen;
slouken@1895
   271
slouken@1895
   272
    /* Query the title from the existing window */
slouken@1895
   273
    titleLen = GetWindowTextLength(hwnd);
slouken@1895
   274
    title = SDL_stack_alloc(TCHAR, titleLen + 1);
slouken@1895
   275
    if (title) {
slouken@1895
   276
        titleLen = GetWindowText(hwnd, title, titleLen);
slouken@1895
   277
    } else {
slouken@1895
   278
        titleLen = 0;
slouken@1895
   279
    }
slouken@1895
   280
    if (titleLen > 0) {
slouken@1895
   281
        window->title = WIN_StringToUTF8(title);
slouken@1895
   282
    }
slouken@1895
   283
    if (title) {
slouken@1895
   284
        SDL_stack_free(title);
slouken@1895
   285
    }
slouken@1895
   286
slouken@1951
   287
    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
slouken@1895
   288
        return -1;
slouken@1895
   289
    }
slouken@1895
   290
    return 0;
slouken@1895
   291
}
slouken@1895
   292
slouken@1895
   293
void
slouken@1895
   294
WIN_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1895
   295
{
slouken@1895
   296
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   297
    LPTSTR title;
slouken@1895
   298
slouken@1895
   299
    if (window->title) {
slouken@1895
   300
        title = WIN_UTF8ToString(window->title);
slouken@1895
   301
    } else {
slouken@1895
   302
        title = NULL;
slouken@1895
   303
    }
slouken@1895
   304
    SetWindowText(hwnd, title ? title : TEXT(""));
slouken@1895
   305
    if (title) {
slouken@1895
   306
        SDL_free(title);
slouken@1895
   307
    }
slouken@1895
   308
}
slouken@1895
   309
slouken@1895
   310
void
slouken@1895
   311
WIN_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1895
   312
{
slouken@1895
   313
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   314
    RECT rect;
slouken@1895
   315
    DWORD style;
slouken@1895
   316
    HWND top;
slouken@1895
   317
    int x, y;
slouken@1895
   318
slouken@1895
   319
    /* Figure out what the window area will be */
slouken@1895
   320
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   321
        top = HWND_TOPMOST;
slouken@1895
   322
    } else {
slouken@1895
   323
        top = HWND_NOTOPMOST;
slouken@1895
   324
    }
slouken@1895
   325
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   326
    rect.left = 0;
slouken@1895
   327
    rect.top = 0;
slouken@1895
   328
    rect.right = window->w;
slouken@1895
   329
    rect.bottom = window->h;
slouken@1895
   330
    AdjustWindowRectEx(&rect, style,
slouken@1895
   331
                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
slouken@1895
   332
                                                           NULL), 0);
slouken@1956
   333
    x = window->x + rect.left;
slouken@1956
   334
    y = window->y + rect.top;
slouken@1895
   335
slouken@1956
   336
    SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
slouken@1895
   337
}
slouken@1895
   338
slouken@1895
   339
void
slouken@1895
   340
WIN_SetWindowSize(_THIS, SDL_Window * window)
slouken@1895
   341
{
slouken@1895
   342
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   343
    RECT rect;
slouken@1895
   344
    DWORD style;
slouken@1895
   345
    HWND top;
slouken@1895
   346
    int w, h;
slouken@1895
   347
slouken@1895
   348
    /* Figure out what the window area will be */
slouken@1895
   349
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   350
        top = HWND_TOPMOST;
slouken@1895
   351
    } else {
slouken@1895
   352
        top = HWND_NOTOPMOST;
slouken@1895
   353
    }
slouken@1895
   354
    style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   355
    rect.left = 0;
slouken@1895
   356
    rect.top = 0;
slouken@1895
   357
    rect.right = window->w;
slouken@1895
   358
    rect.bottom = window->h;
slouken@1895
   359
    AdjustWindowRectEx(&rect, style,
slouken@1895
   360
                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
slouken@1895
   361
                                                           NULL), 0);
slouken@1895
   362
    w = (rect.right - rect.left);
slouken@1895
   363
    h = (rect.bottom - rect.top);
slouken@1895
   364
slouken@1895
   365
    SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE));
slouken@1895
   366
}
slouken@1895
   367
slouken@1895
   368
void
slouken@1895
   369
WIN_ShowWindow(_THIS, SDL_Window * window)
slouken@1895
   370
{
slouken@1895
   371
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   372
slouken@1895
   373
    ShowWindow(hwnd, SW_SHOW);
slouken@1895
   374
}
slouken@1895
   375
slouken@1895
   376
void
slouken@1895
   377
WIN_HideWindow(_THIS, SDL_Window * window)
slouken@1895
   378
{
slouken@1895
   379
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   380
slouken@1895
   381
    ShowWindow(hwnd, SW_HIDE);
slouken@1895
   382
}
slouken@1895
   383
slouken@1895
   384
void
slouken@1895
   385
WIN_RaiseWindow(_THIS, SDL_Window * window)
slouken@1895
   386
{
slouken@1895
   387
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   388
    HWND top;
slouken@1895
   389
slouken@1895
   390
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   391
        top = HWND_TOPMOST;
slouken@1895
   392
    } else {
slouken@1895
   393
        top = HWND_NOTOPMOST;
slouken@1895
   394
    }
slouken@1895
   395
    SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
slouken@1895
   396
}
slouken@1895
   397
slouken@1895
   398
void
slouken@1895
   399
WIN_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1895
   400
{
slouken@1895
   401
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   402
slouken@1895
   403
    ShowWindow(hwnd, SW_MAXIMIZE);
slouken@1895
   404
}
slouken@1895
   405
slouken@1895
   406
void
slouken@1895
   407
WIN_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1895
   408
{
slouken@1895
   409
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   410
slouken@1895
   411
    ShowWindow(hwnd, SW_MINIMIZE);
slouken@1895
   412
}
slouken@1895
   413
slouken@1895
   414
void
slouken@1895
   415
WIN_RestoreWindow(_THIS, SDL_Window * window)
slouken@1895
   416
{
slouken@1895
   417
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   418
slouken@1895
   419
    ShowWindow(hwnd, SW_RESTORE);
slouken@1895
   420
}
slouken@1895
   421
slouken@1895
   422
void
slouken@1895
   423
WIN_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1895
   424
{
slouken@1895
   425
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   426
slouken@1895
   427
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1895
   428
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@1895
   429
        RECT rect;
slouken@1895
   430
        GetClientRect(hwnd, &rect);
slouken@1895
   431
        ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   432
        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   433
        ClipCursor(&rect);
slouken@1895
   434
    } else {
slouken@1895
   435
        ClipCursor(NULL);
slouken@1895
   436
    }
slouken@1895
   437
}
slouken@1895
   438
slouken@1895
   439
void
slouken@1895
   440
WIN_DestroyWindow(_THIS, SDL_Window * window)
slouken@1895
   441
{
slouken@1895
   442
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1895
   443
slouken@1895
   444
    if (data) {
slouken@1952
   445
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   446
        if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1913
   447
            WIN_GL_CleanupWindow(_this, window);
slouken@1913
   448
        }
slouken@1913
   449
#endif
slouken@1913
   450
        ReleaseDC(data->hwnd, data->hdc);
slouken@1895
   451
        if (data->created) {
slouken@2710
   452
            WTClose(g_hCtx[window->id]);
slouken@1895
   453
            DestroyWindow(data->hwnd);
slouken@1895
   454
        }
slouken@1895
   455
        SDL_free(data);
slouken@1895
   456
    }
slouken@1895
   457
}
slouken@1895
   458
slouken@1895
   459
SDL_bool
slouken@1895
   460
WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1895
   461
{
slouken@1895
   462
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
slouken@1895
   463
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@1895
   464
        info->window = hwnd;
slouken@1895
   465
        return SDL_TRUE;
slouken@1895
   466
    } else {
slouken@1895
   467
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1895
   468
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1895
   469
        return SDL_FALSE;
slouken@1895
   470
    }
slouken@1895
   471
}
slouken@1895
   472
slouken@1895
   473
/* vi: set ts=4 sw=4 expandtab: */