src/video/windows/SDL_windowswindow.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 14 Oct 2013 08:56:55 -0700
changeset 7817 357bccc72a1c
parent 7775 dad9001a9fc7
child 7828 1451063c8ecd
permissions -rw-r--r--
For some reason, trying to raise the window programmatically while it's alt-tabbed away will minimize it. Added a workaround for this.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6839
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5495
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5980
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINDOWS
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5980
diff changeset
    24
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    25
#include "SDL_assert.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "../SDL_sysvideo.h"
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
    27
#include "../SDL_pixels_c.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "../../events/SDL_keyboard_c.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    30
#include "SDL_windowsvideo.h"
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    31
#include "SDL_windowswindow.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
6523
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    33
/* Dropfile support */
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    34
#include <shellapi.h>
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    35
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    36
/* This is included after SDL_windowsvideo.h, which includes windows.h */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_syswm.h"
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    38
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    39
/* Windows CE compatibility */
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    40
#ifndef SWP_NOCOPYBITS
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    41
#define SWP_NOCOPYBITS 0
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    42
#endif
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    43
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    44
/* Fake window to help with DirectInput events. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    45
HWND SDL_HelperWindow = NULL;
2714
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
    46
static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
    47
static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    48
static ATOM SDL_HelperWindowClass = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    49
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    50
#define STYLE_BASIC         (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    51
#define STYLE_FULLSCREEN    (WS_POPUP)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    52
#define STYLE_BORDERLESS    (WS_POPUP)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    53
#define STYLE_NORMAL        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    54
#define STYLE_RESIZABLE     (WS_THICKFRAME | WS_MAXIMIZEBOX)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    55
#define STYLE_MASK          (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    56
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    57
static DWORD
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    58
GetWindowStyle(SDL_Window * window)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    59
{
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    60
    DWORD style = 0;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    61
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    62
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    63
        style |= STYLE_FULLSCREEN;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    64
    } else {
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    65
        if (window->flags & SDL_WINDOW_BORDERLESS) {
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    66
            style |= STYLE_BORDERLESS;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    67
        } else {
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    68
            style |= STYLE_NORMAL;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    69
        }
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    70
        if (window->flags & SDL_WINDOW_RESIZABLE) {
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    71
            style |= STYLE_RESIZABLE;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    72
        }
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    73
    }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    74
    return style;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    75
}
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    76
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    77
static void
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    78
WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    79
{
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    80
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    81
    RECT rect;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    82
    DWORD style;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    83
    HWND top;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    84
    BOOL menu;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    85
    int x, y;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    86
    int w, h;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    87
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    88
    /* Figure out what the window area will be */
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    89
    if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    90
        top = HWND_TOPMOST;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    91
    } else {
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    92
        top = HWND_NOTOPMOST;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    93
    }
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    94
    style = GetWindowLong(hwnd, GWL_STYLE);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    95
    rect.left = 0;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    96
    rect.top = 0;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    97
    rect.right = window->w;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    98
    rect.bottom = window->h;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
    99
    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   100
    AdjustWindowRectEx(&rect, style, menu, 0);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   101
    w = (rect.right - rect.left);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   102
    h = (rect.bottom - rect.top);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   103
    x = window->x + rect.left;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   104
    y = window->y + rect.top;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   105
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   106
    SetWindowPos(hwnd, top, x, y, w, h, flags);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   107
}
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   108
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   110
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   112
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    SDL_WindowData *data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    /* Allocate the window data */
7775
dad9001a9fc7 Fixed bug 2130 - Two members of Windows WindowData not initialized
Sam Lantinga <slouken@libsdl.org>
parents: 7762
diff changeset
   116
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   118
        return SDL_OutOfMemory();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3566
diff changeset
   120
    data->window = window;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    data->hwnd = hwnd;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   122
    data->hdc = GetDC(hwnd);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
    data->created = created;
6943
ce87e12970f5 sdl - use the wParam and rawinput data for mouse state rather than just the message type, fixes missing mouse up events when alt-tabing out of the window
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   124
    data->mouse_button_flags = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   125
    data->videodata = videodata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
5980
612b41c44af1 Make sure window->driverdata is set before we might need it.
Ryan C. Gordon <icculus@icculus.org>
parents: 5581
diff changeset
   127
    window->driverdata = data;
612b41c44af1 Make sure window->driverdata is set before we might need it.
Ryan C. Gordon <icculus@icculus.org>
parents: 5581
diff changeset
   128
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    /* Associate the data with the window */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   131
        ReleaseDC(hwnd, data->hdc);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   133
        return WIN_SetError("SetProp() failed");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    /* Set up the window proc function */
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   137
#ifdef GWLP_WNDPROC
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
4733
983eb9d5ed31 Change SDL to not use DefWindowProc as the window class' window procedure.
dewyatt
parents: 3697
diff changeset
   139
    if (data->wndproc == WIN_WindowProc) {
3566
07c8339c95c6 Fixed bug #905
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   140
        data->wndproc = NULL;
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   141
    } else {
4735
8568ebdb5f1f Added else to make things clear.
dewyatt
parents: 4733
diff changeset
   142
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
8568ebdb5f1f Added else to make things clear.
dewyatt
parents: 4733
diff changeset
   143
    }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   144
#else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   145
    data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   146
    if (data->wndproc == WIN_WindowProc) {
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   147
        data->wndproc = NULL;
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   148
    } else {
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   149
        SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   150
    }
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   151
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    /* Fill in the SDL window with the window data */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    {
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   155
        RECT rect;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   156
        if (GetClientRect(hwnd, &rect)) {
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   157
            int w = rect.right;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   158
            int h = rect.bottom;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   159
            if ((window->w && window->w != w) || (window->h && window->h != h)) {
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7585
diff changeset
   160
                /* We tried to create a window larger than the desktop and Windows didn't allow it.  Override! */
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   161
                WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   162
            } else {
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   163
                window->w = w;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   164
                window->h = h;
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   165
            }
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   166
        }
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   167
    }
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   168
    {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
        POINT point;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
        point.x = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
        point.y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
        if (ClientToScreen(hwnd, &point)) {
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5178
diff changeset
   173
            window->x = point.x;
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5178
diff changeset
   174
            window->y = point.y;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
        if (style & WS_VISIBLE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
            window->flags |= SDL_WINDOW_SHOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
            window->flags &= ~SDL_WINDOW_SHOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
        if (style & (WS_BORDER | WS_THICKFRAME)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
            window->flags &= ~SDL_WINDOW_BORDERLESS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
            window->flags |= SDL_WINDOW_BORDERLESS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
        if (style & WS_THICKFRAME) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
            window->flags |= SDL_WINDOW_RESIZABLE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
            window->flags &= ~SDL_WINDOW_RESIZABLE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
        }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   194
#ifdef WS_MAXIMIZE
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
        if (style & WS_MAXIMIZE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
            window->flags |= SDL_WINDOW_MAXIMIZED;
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   197
        } else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   198
#endif
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   199
        {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
        }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   202
#ifdef WS_MINIMIZE
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
        if (style & WS_MINIMIZE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
            window->flags |= SDL_WINDOW_MINIMIZED;
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   205
        } else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   206
#endif
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   207
        {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
            window->flags &= ~SDL_WINDOW_MINIMIZED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    if (GetFocus() == hwnd) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   213
        SDL_SetKeyboardFocus(data->window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
            RECT rect;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
            GetClientRect(hwnd, &rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
            ClientToScreen(hwnd, (LPPOINT) & rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
            ClipCursor(&rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   224
    /* Enable multi-touch */
4948
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   225
    if (videodata->RegisterTouchWindow) {
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   226
        videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   227
    }
4919
716b2cbf4c9e First pass at Windows multi-touch gesture support
Sam Lantinga <slouken@libsdl.org>
parents: 4902
diff changeset
   228
6523
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   229
    /* Enable dropping files */
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   230
    DragAcceptFiles(hwnd, TRUE);
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   231
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
    /* All done! */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
WIN_CreateWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
    HWND hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
    RECT rect;
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   241
    DWORD style = STYLE_BASIC;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
    int x, y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    int w, h;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   244
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   245
    style |= GetWindowStyle(window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
    /* Figure out what the window area will be */
5382
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   248
    rect.left = window->x;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   249
    rect.top = window->y;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   250
    rect.right = window->x + window->w;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   251
    rect.bottom = window->y + window->h;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
    AdjustWindowRectEx(&rect, style, FALSE, 0);
5382
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   253
    x = rect.left;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   254
    y = rect.top;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    w = (rect.right - rect.left);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
    h = (rect.bottom - rect.top);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
1956
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   258
    hwnd =
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   259
        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   260
                     SDL_Instance, NULL);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
    if (!hwnd) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   262
        return WIN_SetError("Couldn't create window");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   265
    WIN_PumpEvents(_this);
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   266
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   267
    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
        DestroyWindow(hwnd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    }
5088
455bc74f7034 Fixed bug #1100
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   271
#if SDL_VIDEO_OPENGL_WGL
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   272
    if (window->flags & SDL_WINDOW_OPENGL) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   273
        if (WIN_GL_SetupWindow(_this, window) < 0) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   274
            WIN_DestroyWindow(_this, window);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   275
            return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   276
        }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   277
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   278
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    HWND hwnd = (HWND) data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    LPTSTR title;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    int titleLen;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
    /* Query the title from the existing window */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
    titleLen = GetWindowTextLength(hwnd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    title = SDL_stack_alloc(TCHAR, titleLen + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    if (title) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
        titleLen = GetWindowText(hwnd, title, titleLen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
        titleLen = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    if (titleLen > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
        window->title = WIN_StringToUTF8(title);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
    if (title) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
        SDL_stack_free(title);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   304
    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
WIN_SetWindowTitle(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    LPTSTR title;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
    if (window->title) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
        title = WIN_UTF8ToString(window->title);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
        title = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    SetWindowText(hwnd, title ? title : TEXT(""));
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7663
diff changeset
   322
    SDL_free(title);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
void
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   326
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   327
{
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   328
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   329
    HICON hicon = NULL;
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   330
    BYTE *icon_bmp;
7527
7e254bcd3b9d Fixed variable scoping for Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7523
diff changeset
   331
    int icon_len, y;
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   332
    SDL_RWops *dst;
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   333
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   334
    /* Create temporary bitmap buffer */
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   335
    icon_len = 40 + icon->h * icon->w * 4;
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   336
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   337
    dst = SDL_RWFromMem(icon_bmp, icon_len);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   338
    if (!dst) {
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   339
        SDL_stack_free(icon_bmp);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   340
        return;
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   341
    }
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   342
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   343
    /* Write the BITMAPINFO header */
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   344
    SDL_WriteLE32(dst, 40);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   345
    SDL_WriteLE32(dst, icon->w);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   346
    SDL_WriteLE32(dst, icon->h * 2);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   347
    SDL_WriteLE16(dst, 1);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   348
    SDL_WriteLE16(dst, 32);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   349
    SDL_WriteLE32(dst, BI_RGB);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   350
    SDL_WriteLE32(dst, icon->h * icon->w * 4);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   351
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   352
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   353
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   354
    SDL_WriteLE32(dst, 0);
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   355
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   356
    /* Write the pixels upside down into the bitmap buffer */
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   357
    SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
7527
7e254bcd3b9d Fixed variable scoping for Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7523
diff changeset
   358
    y = icon->h;
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   359
    while (y--) {
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   360
        Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   361
        SDL_RWwrite(dst, src, icon->pitch, 1);
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   362
    }
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   363
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   364
    hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   365
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   366
    SDL_RWclose(dst);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   367
    SDL_stack_free(icon_bmp);
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   368
2971
a3012c6652ff Should we also set the icon in the task manager?
Sam Lantinga <slouken@libsdl.org>
parents: 2970
diff changeset
   369
    /* Set the icon for the window */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2971
diff changeset
   370
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
2971
a3012c6652ff Should we also set the icon in the task manager?
Sam Lantinga <slouken@libsdl.org>
parents: 2970
diff changeset
   371
a3012c6652ff Should we also set the icon in the task manager?
Sam Lantinga <slouken@libsdl.org>
parents: 2970
diff changeset
   372
    /* Set the icon in the task manager (should we do this?) */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2971
diff changeset
   373
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   374
}
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   375
6427
34059553702a Consolidate some code in the Windows video target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   376
void
34059553702a Consolidate some code in the Windows video target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   377
WIN_SetWindowPosition(_THIS, SDL_Window * window)
34059553702a Consolidate some code in the Windows video target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   378
{
6535
b117349cc8aa Fixed bug where SDL thought the window was shown and it wasn't actually.
Sam Lantinga <slouken@libsdl.org>
parents: 6523
diff changeset
   379
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
WIN_SetWindowSize(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
{
6535
b117349cc8aa Fixed bug where SDL thought the window was shown and it wasn't actually.
Sam Lantinga <slouken@libsdl.org>
parents: 6523
diff changeset
   385
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5178
diff changeset
   386
}
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5178
diff changeset
   387
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
WIN_ShowWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    ShowWindow(hwnd, SW_SHOW);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
WIN_HideWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    ShowWindow(hwnd, SW_HIDE);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
WIN_RaiseWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
{
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   405
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
7817
357bccc72a1c For some reason, trying to raise the window programmatically while it's alt-tabbed away will minimize it. Added a workaround for this.
Sam Lantinga <slouken@libsdl.org>
parents: 7775
diff changeset
   406
357bccc72a1c For some reason, trying to raise the window programmatically while it's alt-tabbed away will minimize it. Added a workaround for this.
Sam Lantinga <slouken@libsdl.org>
parents: 7775
diff changeset
   407
    /* Raising the window while alt-tabbed can cause it to be minimized for some reason? */
357bccc72a1c For some reason, trying to raise the window programmatically while it's alt-tabbed away will minimize it. Added a workaround for this.
Sam Lantinga <slouken@libsdl.org>
parents: 7775
diff changeset
   408
    WIN_RestoreWindow(_this, window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
WIN_MaximizeWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 4500
diff changeset
   415
    ShowWindow(hwnd, SW_MAXIMIZE);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
WIN_MinimizeWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    ShowWindow(hwnd, SW_MINIMIZE);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
void
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   426
WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   427
{
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   428
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
6428
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   429
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   430
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   431
    if (bordered) {
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   432
        style &= ~STYLE_BORDERLESS;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   433
        style |= STYLE_NORMAL;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   434
    } else {
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   435
        style &= ~STYLE_NORMAL;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   436
        style |= STYLE_BORDERLESS;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   437
    }
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   438
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   439
    SetWindowLong(hwnd, GWL_STYLE, style);
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   440
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOREPOSITION | SWP_NOZORDER |SWP_NOACTIVATE | SWP_NOSENDCHANGING);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   441
}
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   442
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   443
void
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
WIN_RestoreWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
    ShowWindow(hwnd, SW_RESTORE);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
void
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   452
WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   453
{
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   454
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   455
    HWND hwnd = data->hwnd;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   456
    RECT rect;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   457
    SDL_Rect bounds;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   458
    DWORD style;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   459
    HWND top;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   460
    BOOL menu;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   461
    int x, y;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   462
    int w, h;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   463
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   464
    if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   465
        top = HWND_TOPMOST;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   466
    } else {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   467
        top = HWND_NOTOPMOST;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   468
    }
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   469
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   470
    style = GetWindowLong(hwnd, GWL_STYLE);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   471
    style &= ~STYLE_MASK;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   472
    style |= GetWindowStyle(window);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   473
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   474
    WIN_GetDisplayBounds(_this, display, &bounds);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   475
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   476
    if (fullscreen) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   477
        x = bounds.x;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   478
        y = bounds.y;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   479
        w = bounds.w;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   480
        h = bounds.h;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   481
    } else {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   482
        rect.left = 0;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   483
        rect.top = 0;
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5382
diff changeset
   484
        rect.right = window->windowed.w;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5382
diff changeset
   485
        rect.bottom = window->windowed.h;
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   486
        menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   487
        AdjustWindowRectEx(&rect, style, menu, 0);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   488
        w = (rect.right - rect.left);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   489
        h = (rect.bottom - rect.top);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5382
diff changeset
   490
        x = window->windowed.x + rect.left;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5382
diff changeset
   491
        y = window->windowed.y + rect.top;
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   492
    }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   493
    SetWindowLong(hwnd, GWL_STYLE, style);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   494
    SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   495
}
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   496
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   497
int
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   498
WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   499
{
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   500
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   501
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   502
    HDC hdc;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   503
    BOOL succeeded = FALSE;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   504
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   505
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   506
    if (hdc) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   507
        succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   508
        if (!succeeded) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   509
            WIN_SetError("SetDeviceGammaRamp()");
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   510
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   511
        DeleteDC(hdc);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   512
    }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   513
    return succeeded ? 0 : -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   514
}
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   515
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   516
int
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   517
WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   518
{
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   519
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   520
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   521
    HDC hdc;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   522
    BOOL succeeded = FALSE;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   523
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   524
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   525
    if (hdc) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   526
        succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   527
        if (!succeeded) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   528
            WIN_SetError("GetDeviceGammaRamp()");
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   529
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   530
        DeleteDC(hdc);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   531
    }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   532
    return succeeded ? 0 : -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   533
}
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   534
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   535
void
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6535
diff changeset
   536
WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6535
diff changeset
   540
    if (grabbed) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
        RECT rect;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
        GetClientRect(hwnd, &rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
        ClientToScreen(hwnd, (LPPOINT) & rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
        ClipCursor(&rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
        ClipCursor(NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
    }
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   549
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   550
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
7584
864eca4d27a7 Fixed incorrect window state if the window is created grabbed. We don't want to activate the window if it isn't shown yet.
Sam Lantinga <slouken@libsdl.org>
parents: 7583
diff changeset
   551
        UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   552
7584
864eca4d27a7 Fixed incorrect window state if the window is created grabbed. We don't want to activate the window if it isn't shown yet.
Sam Lantinga <slouken@libsdl.org>
parents: 7583
diff changeset
   553
        if (!(window->flags & SDL_WINDOW_SHOWN)) {
864eca4d27a7 Fixed incorrect window state if the window is created grabbed. We don't want to activate the window if it isn't shown yet.
Sam Lantinga <slouken@libsdl.org>
parents: 7583
diff changeset
   554
            flags |= SWP_NOACTIVATE;
864eca4d27a7 Fixed incorrect window state if the window is created grabbed. We don't want to activate the window if it isn't shown yet.
Sam Lantinga <slouken@libsdl.org>
parents: 7583
diff changeset
   555
        }
7585
7fd59fc01ee7 Unify the SetWindowPos() calls so that they all set the window state based on SDL state.
Sam Lantinga <slouken@libsdl.org>
parents: 7584
diff changeset
   556
        WIN_SetWindowPositionInternal(_this, window, flags);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   557
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
WIN_DestroyWindow(_THIS, SDL_Window * window)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
    if (data) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   566
        ReleaseDC(data->hwnd, data->hdc);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
        if (data->created) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
            DestroyWindow(data->hwnd);
5580
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   569
        } else {
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   570
            /* Restore any original event handler... */
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   571
            if (data->wndproc != NULL) {
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   572
#ifdef GWLP_WNDPROC
5581
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   573
                SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   574
                                 (LONG_PTR) data->wndproc);
5580
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   575
#else
5581
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   576
                SetWindowLong(data->hwnd, GWL_WNDPROC,
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   577
                              (LONG_PTR) data->wndproc);
5580
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   578
#endif
0c407e6d14a9 If we didn't create win32 window, restore its event procedure on destruction.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   579
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
        SDL_free(data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
SDL_bool
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
    if (info->version.major <= SDL_MAJOR_VERSION) {
4900
69d9db65f248 Merged the Windows custom window system hooks into the union used by X11.
Sam Lantinga <slouken@libsdl.org>
parents: 4763
diff changeset
   590
        info->subsystem = SDL_SYSWM_WINDOWS;
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 5037
diff changeset
   591
        info->info.win.window = hwnd;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
        SDL_SetError("Application not compiled with SDL %d.%d\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
        return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   600
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   601
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   602
 * Creates a HelperWindow used for DirectInput events.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   603
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   604
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   605
SDL_HelperWindowCreate(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   606
{
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   607
    HINSTANCE hInstance = GetModuleHandle(NULL);
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   608
    WNDCLASS wce;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   609
3045
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   610
    /* Make sure window isn't created twice. */
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   611
    if (SDL_HelperWindow != NULL) {
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   612
        return 0;
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   613
    }
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   614
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   615
    /* Create the class. */
2714
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
   616
    SDL_zero(wce);
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   617
    wce.lpfnWndProc = DefWindowProc;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   618
    wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   619
    wce.hInstance = hInstance;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   620
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   621
    /* Register the class. */
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   622
    SDL_HelperWindowClass = RegisterClass(&wce);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   623
    if (SDL_HelperWindowClass == 0) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   624
        return WIN_SetError("Unable to create Helper Window Class");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   625
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   626
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   627
    /* Create the window. */
2714
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
   628
    SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
   629
                                      SDL_HelperWindowName,
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   630
                                      WS_OVERLAPPED, CW_USEDEFAULT,
2714
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
   631
                                      CW_USEDEFAULT, CW_USEDEFAULT,
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6428
diff changeset
   632
                                      CW_USEDEFAULT, HWND_MESSAGE, NULL,
2714
1d1be6137875 Merged last minute fixes from force feedback branch (r4031, r4033, r4034)
Sam Lantinga <slouken@libsdl.org>
parents: 2713
diff changeset
   633
                                      hInstance, NULL);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   634
    if (SDL_HelperWindow == NULL) {
3045
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   635
        UnregisterClass(SDL_HelperWindowClassName, hInstance);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   636
        return WIN_SetError("Unable to create Helper Window");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   637
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   638
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   639
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   640
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   641
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   642
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   643
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   644
 * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   645
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   646
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   647
SDL_HelperWindowDestroy(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   648
{
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   649
    HINSTANCE hInstance = GetModuleHandle(NULL);
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   650
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   651
    /* Destroy the window. */
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   652
    if (SDL_HelperWindow != NULL) {
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   653
        if (DestroyWindow(SDL_HelperWindow) == 0) {
4500
eff4e88cc1e8 Added Windows clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4486
diff changeset
   654
            WIN_SetError("Unable to destroy Helper Window");
2865
Sam Lantinga <slouken@libsdl.org>
parents: 2863
diff changeset
   655
            return;
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   656
        }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   657
        SDL_HelperWindow = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   658
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   659
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   660
    /* Unregister the class. */
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   661
    if (SDL_HelperWindowClass != 0) {
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   662
        if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
4500
eff4e88cc1e8 Added Windows clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4486
diff changeset
   663
            WIN_SetError("Unable to destroy Helper Window Class");
2865
Sam Lantinga <slouken@libsdl.org>
parents: 2863
diff changeset
   664
            return;
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   665
        }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   666
        SDL_HelperWindowClass = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   667
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   668
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   669
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   670
void WIN_OnWindowEnter(_THIS, SDL_Window * window)
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   671
{
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   672
#ifdef WM_MOUSELEAVE
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   673
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   674
    TRACKMOUSEEVENT trackMouseEvent;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   675
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   676
    if (!data || !data->hwnd) {
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   677
        /* The window wasn't fully initialized */
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   678
        return;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   679
    }
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   680
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   681
    trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   682
    trackMouseEvent.dwFlags = TME_LEAVE;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   683
    trackMouseEvent.hwndTrack = data->hwnd;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   684
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   685
    TrackMouseEvent(&trackMouseEvent);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   686
#endif /* WM_MOUSELEAVE */
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   687
}
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   688
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5980
diff changeset
   689
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5980
diff changeset
   690
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
/* vi: set ts=4 sw=4 expandtab: */