src/video/windows/SDL_windowswindow.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 22 Feb 2014 17:39:35 -0800
changeset 8238 9e09e1561e00
parent 8205 1a97f96f55cd
child 8253 75ad8ebb3768
permissions -rw-r--r--
Don't fail initialization if the helper window class already exists.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8144
diff changeset
     3
  Copyright (C) 1997-2014 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8072
diff changeset
    21
#include "../../SDL_internal.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
    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
7828
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7817
diff changeset
    25
#include "../../core/windows/SDL_windows.h"
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7817
diff changeset
    26
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    27
#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
    28
#include "../SDL_sysvideo.h"
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
    29
#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
    30
#include "../../events/SDL_keyboard_c.h"
8072
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
    31
#include "../../events/SDL_mouse_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
    32
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    33
#include "SDL_windowsvideo.h"
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    34
#include "SDL_windowswindow.h"
8144
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    35
#include "SDL_hints.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
    36
6523
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    37
/* Dropfile support */
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    38
#include <shellapi.h>
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
    39
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
    40
/* 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
    41
#include "SDL_syswm.h"
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    42
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    43
/* 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
    44
#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
    45
#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
    46
#endif
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    47
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    48
/* 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
    49
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
    50
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
    51
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
    52
static ATOM SDL_HelperWindowClass = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
    53
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
    54
#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
    55
#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
    56
#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
    57
#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
    58
#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
    59
#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
    60
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
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
    62
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
    63
{
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
    64
    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
    65
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    66
    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
    67
        style |= STYLE_FULLSCREEN;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    68
    } else {
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    69
        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
    70
            style |= STYLE_BORDERLESS;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    71
        } 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
    72
            style |= STYLE_NORMAL;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    73
        }
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    74
        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
    75
            style |= STYLE_RESIZABLE;
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    76
        }
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    77
    }
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
    78
    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
    79
}
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
    80
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
    81
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
    82
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
    83
{
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
    84
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
    85
    HWND hwnd = data->hwnd;
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
    86
    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
    87
    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
    88
    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
    89
    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
    90
    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
    91
    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
    92
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
    /* 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
    94
    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
    95
        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
    96
    } 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
    97
        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
    98
    }
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
    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
   100
    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
   101
    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
   102
    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
   103
    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
   104
    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
   105
    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
   106
    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
   107
    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
   108
    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
   109
    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
   110
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   111
    data->expected_resize = TRUE;
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
   112
    SetWindowPos(hwnd, top, x, y, w, h, flags);
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   113
    data->expected_resize = FALSE;
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
   114
}
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
   115
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
   116
static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   117
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
   118
{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   119
    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
   120
    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
   121
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
   122
    /* 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
   123
    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
   124
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   125
        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
   126
    }
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
   127
    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
   128
    data->hwnd = hwnd;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   129
    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
   130
    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
   131
    data->mouse_button_flags = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   132
    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
   133
5980
612b41c44af1 Make sure window->driverdata is set before we might need it.
Ryan C. Gordon <icculus@icculus.org>
parents: 5581
diff changeset
   134
    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
   135
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
   136
    /* 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
   137
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   138
        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
   139
        SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   140
        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
   141
    }
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
   142
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
   143
    /* 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
   144
#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
   145
    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
   146
    if (data->wndproc == WIN_WindowProc) {
3566
07c8339c95c6 Fixed bug #905
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   147
        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
   148
    } else {
4735
8568ebdb5f1f Added else to make things clear.
dewyatt
parents: 4733
diff changeset
   149
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
8568ebdb5f1f Added else to make things clear.
dewyatt
parents: 4733
diff changeset
   150
    }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   151
#else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   152
    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
   153
    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
   154
        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
   155
    } else {
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   156
        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
   157
    }
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   158
#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
   159
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
   160
    /* 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
   161
    {
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
   162
        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
   163
        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
   164
            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
   165
            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
   166
            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
   167
                /* 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
   168
                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
   169
            } 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
   170
                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
   171
                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
   172
            }
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
   173
        }
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
   174
    }
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
   175
    {
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
   176
        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
   177
        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
   178
        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
   179
        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
   180
            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
   181
            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
   182
        }
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
    {
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
        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
   186
        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
   187
            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
   188
        } 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
   189
            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
   190
        }
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
        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
   192
            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
   193
        } 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
   194
            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
   195
        }
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
        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
   197
            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
   198
        } 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
   199
            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
   200
        }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   201
#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
   202
        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
   203
            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
   204
        } else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   205
#endif
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   206
        {
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
   207
            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
   208
        }
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   209
#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
   210
        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
   211
            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
   212
        } else
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   213
#endif
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   214
        {
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
   215
            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
   216
        }
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
    }
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
    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
   219
        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
   220
        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
   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
        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
   223
            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
   224
            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
   225
            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
   226
            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
   227
            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
   228
        }
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
   229
    }
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
   230
6078
718b49ec039e Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   231
    /* Enable multi-touch */
4948
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   232
    if (videodata->RegisterTouchWindow) {
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   233
        videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
6546eaa20271 Fixed crash on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 4919
diff changeset
   234
    }
4919
716b2cbf4c9e First pass at Windows multi-touch gesture support
Sam Lantinga <slouken@libsdl.org>
parents: 4902
diff changeset
   235
6523
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   236
    /* Enable dropping files */
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   237
    DragAcceptFiles(hwnd, TRUE);
62d0193a7a02 Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   238
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
   239
    /* 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
   240
    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
   241
}
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
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
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
   244
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
   245
{
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
    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
   247
    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
   248
    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
   249
    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
   250
    int w, h;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   251
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
   252
    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
   253
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
   254
    /* Figure out what the window area will be */
5382
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   255
    rect.left = window->x;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   256
    rect.top = window->y;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   257
    rect.right = window->x + window->w;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   258
    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
   259
    AdjustWindowRectEx(&rect, style, FALSE, 0);
5382
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   260
    x = rect.left;
fd9a7a0afcbf Simplified Windows window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   261
    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
   262
    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
   263
    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
   264
1956
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   265
    hwnd =
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   266
        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
   267
                     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
   268
    if (!hwnd) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   269
        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
   270
    }
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
   271
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   272
    WIN_PumpEvents(_this);
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   273
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   274
    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
   275
        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
   276
        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
   277
    }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   278
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   279
#if SDL_VIDEO_OPENGL_WGL
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   280
    /* We need to initialize the extensions before deciding how to create ES profiles */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   281
    if (window->flags & SDL_WINDOW_OPENGL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   282
        WIN_GL_InitExtensions(_this);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   283
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   284
#endif
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   285
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   286
#if SDL_VIDEO_OPENGL_ES2
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   287
    if ((window->flags & SDL_WINDOW_OPENGL) &&
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   288
        _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   289
#if SDL_VIDEO_OPENGL_WGL           
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   290
        && (!_this->gl_data || !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   291
#endif  
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   292
        ) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   293
#if SDL_VIDEO_OPENGL_EGL  
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   294
        if (WIN_GLES_SetupWindow(_this, window) < 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   295
            WIN_DestroyWindow(_this, window);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   296
            return -1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   297
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   298
#else
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   299
        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   300
#endif /* SDL_VIDEO_OPENGL_EGL */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   301
    } else 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   302
#endif /* SDL_VIDEO_OPENGL_ES2 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   303
5088
455bc74f7034 Fixed bug #1100
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   304
#if SDL_VIDEO_OPENGL_WGL
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   305
    if (window->flags & SDL_WINDOW_OPENGL) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   306
        if (WIN_GL_SetupWindow(_this, window) < 0) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   307
            WIN_DestroyWindow(_this, window);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   308
            return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   309
        }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   310
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   311
#endif
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7941
diff changeset
   312
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
   313
    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
   314
}
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
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
   317
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
   318
{
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
    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
   320
    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
   321
    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
   322
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
    /* 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
   324
    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
   325
    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
   326
    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
   327
        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
   328
    } 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
   329
        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
   330
    }
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
   331
    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
   332
        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
   333
    }
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
   334
    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
   335
        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
   336
    }
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
   337
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   338
    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
   339
        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
   340
    }
8144
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   341
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   342
#if SDL_VIDEO_OPENGL_WGL
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   343
    {
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   344
        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   345
        if (hint) {
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   346
            // This hint is a pointer (in string form) of the address of
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   347
            // the window to share a pixel format with
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   348
            SDL_Window *otherWindow = NULL;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   349
            SDL_sscanf(hint, "%p", (void**)&otherWindow);
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   350
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   351
            // Do some error checking on the pointer
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   352
            if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   353
            {
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   354
                // If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   355
                if (otherWindow->flags & SDL_WINDOW_OPENGL)
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   356
                {
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   357
                    window->flags |= SDL_WINDOW_OPENGL;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   358
                    if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   359
                        return -1;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   360
                    }
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   361
                }
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   362
            }
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   363
        }
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   364
    }
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   365
#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
   366
    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
   367
}
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
   368
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
   369
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
   370
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
   371
{
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
   372
    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
   373
    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
   374
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
   375
    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
   376
        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
   377
    } 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
   378
        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
   379
    }
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
    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
   381
    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
   382
}
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
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
void
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   385
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
   386
{
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   387
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   388
    HICON hicon = NULL;
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   389
    BYTE *icon_bmp;
7527
7e254bcd3b9d Fixed variable scoping for Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7523
diff changeset
   390
    int icon_len, y;
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   391
    SDL_RWops *dst;
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   392
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   393
    /* Create temporary bitmap buffer */
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   394
    icon_len = 40 + icon->h * icon->w * 4;
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   395
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   396
    dst = SDL_RWFromMem(icon_bmp, icon_len);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   397
    if (!dst) {
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   398
        SDL_stack_free(icon_bmp);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   399
        return;
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   400
    }
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   401
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   402
    /* Write the BITMAPINFO header */
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   403
    SDL_WriteLE32(dst, 40);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   404
    SDL_WriteLE32(dst, icon->w);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   405
    SDL_WriteLE32(dst, icon->h * 2);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   406
    SDL_WriteLE16(dst, 1);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   407
    SDL_WriteLE16(dst, 32);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   408
    SDL_WriteLE32(dst, BI_RGB);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   409
    SDL_WriteLE32(dst, icon->h * icon->w * 4);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   410
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   411
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   412
    SDL_WriteLE32(dst, 0);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   413
    SDL_WriteLE32(dst, 0);
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   414
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   415
    /* 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
   416
    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
   417
    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
   418
    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
   419
        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
   420
        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
   421
    }
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   422
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   423
    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
   424
5418
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   425
    SDL_RWclose(dst);
f8ecf0869cc9 You can use SDL_ConvertSurfaceFormat() now
Sam Lantinga <slouken@libsdl.org>
parents: 5416
diff changeset
   426
    SDL_stack_free(icon_bmp);
2970
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   427
2971
a3012c6652ff Should we also set the icon in the task manager?
Sam Lantinga <slouken@libsdl.org>
parents: 2970
diff changeset
   428
    /* Set the icon for the window */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2971
diff changeset
   429
    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
   430
a3012c6652ff Should we also set the icon in the task manager?
Sam Lantinga <slouken@libsdl.org>
parents: 2970
diff changeset
   431
    /* Set the icon in the task manager (should we do this?) */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2971
diff changeset
   432
    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
   433
}
94b634c56455 Added support for translucent icons on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2968
diff changeset
   434
6427
34059553702a Consolidate some code in the Windows video target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   435
void
34059553702a Consolidate some code in the Windows video target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   436
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
   437
{
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
   438
    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
   439
}
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
   440
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
   441
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
   442
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
   443
{
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
   444
    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
   445
}
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
   446
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
   447
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
   448
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
   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
    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
   451
    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
   452
}
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
   453
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
   454
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
   455
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
   456
{
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
   457
    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
   458
    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
   459
}
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
   460
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
   461
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
   462
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
   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
    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
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
   465
}
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
   466
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
   467
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
   468
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
   469
{
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   470
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   471
    HWND hwnd = data->hwnd;
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   472
    data->expected_resize = TRUE;
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 4500
diff changeset
   473
    ShowWindow(hwnd, SW_MAXIMIZE);
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   474
    data->expected_resize = FALSE;
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
   475
}
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
   476
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
   477
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
   478
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
   479
{
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
   480
    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
   481
    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
   482
}
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
   483
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
   484
void
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   485
WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   486
{
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   487
    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
   488
    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
   489
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   490
    if (bordered) {
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   491
        style &= ~STYLE_BORDERLESS;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   492
        style |= STYLE_NORMAL;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   493
    } else {
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   494
        style &= ~STYLE_NORMAL;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   495
        style |= STYLE_BORDERLESS;
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   496
    }
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   497
0028fa91dfc6 Made Windows version of SDL_SetWindowBordered() mostly work.
Ryan C. Gordon <icculus@icculus.org>
parents: 6427
diff changeset
   498
    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
   499
    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
   500
}
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   501
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   502
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
   503
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
   504
{
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   505
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   506
    HWND hwnd = data->hwnd;
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   507
    data->expected_resize = TRUE;
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
   508
    ShowWindow(hwnd, SW_RESTORE);
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   509
    data->expected_resize = FALSE;
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
   510
}
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
   511
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
   512
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
   513
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
   514
{
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
   515
    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
   516
    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
   517
    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
   518
    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
   519
    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
   520
    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
   521
    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
   522
    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
   523
    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
   524
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
   525
    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
   526
        top = HWND_TOPMOST;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   527
    } else {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   528
        top = HWND_NOTOPMOST;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7089
diff changeset
   529
    }
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   530
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
   531
    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
   532
    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
   533
    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
   534
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
    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
   536
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
   537
    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
   538
        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
   539
        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
   540
        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
   541
        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
   542
    } 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
   543
        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
   544
        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
   545
        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
   546
        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
   547
        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
   548
        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
   549
        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
   550
        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
   551
        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
   552
        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
   553
    }
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
   554
    SetWindowLong(hwnd, GWL_STYLE, style);
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   555
    data->expected_resize = TRUE;
8205
1a97f96f55cd Fixed bug where a window created fullscreen and hidden would get activated and "shown" but never actually be visible.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   556
    SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
7941
7c249ca44069 Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7920
diff changeset
   557
    data->expected_resize = FALSE;
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
   558
}
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
   559
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   560
int
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   561
WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   562
{
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   563
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   564
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   565
    HDC hdc;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   566
    BOOL succeeded = FALSE;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   567
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   568
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   569
    if (hdc) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   570
        succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   571
        if (!succeeded) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   572
            WIN_SetError("SetDeviceGammaRamp()");
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   573
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   574
        DeleteDC(hdc);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   575
    }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   576
    return succeeded ? 0 : -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   577
}
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   578
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   579
int
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   580
WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   581
{
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   582
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   583
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   584
    HDC hdc;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   585
    BOOL succeeded = FALSE;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   586
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   587
    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   588
    if (hdc) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   589
        succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   590
        if (!succeeded) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   591
            WIN_SetError("GetDeviceGammaRamp()");
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   592
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   593
        DeleteDC(hdc);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   594
    }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   595
    return succeeded ? 0 : -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   596
}
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5418
diff changeset
   597
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
   598
void
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6535
diff changeset
   599
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
   600
{
8072
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   601
    WIN_UpdateClipCursor(window);
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   602
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
   603
    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
   604
        UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
6782
582d35419e8a Improvements from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   605
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
   606
        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
   607
            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
   608
        }
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
   609
        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
   610
    }
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
   611
}
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
   612
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
   613
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
   614
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
   615
{
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
   616
    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
   617
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
   618
    if (data) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   619
        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
   620
        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
   621
            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
   622
        } 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
   623
            /* 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
   624
            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
   625
#ifdef GWLP_WNDPROC
5581
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   626
                SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   627
                                 (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
   628
#else
5581
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   629
                SetWindowLong(data->hwnd, GWL_WNDPROC,
f40f9d3ca2bc Patched to compile (I hope).
Ryan C. Gordon <icculus@icculus.org>
parents: 5580
diff changeset
   630
                              (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
   631
#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
   632
            }
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
   633
        }
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
   634
        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
   635
    }
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
   636
}
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
   637
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
   638
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
   639
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
   640
{
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
   641
    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
   642
    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
   643
        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
   644
        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
   645
        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
   646
    } 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
   647
        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
   648
                     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
   649
        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
   650
    }
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
   651
}
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
   652
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   653
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   654
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   655
 * 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
   656
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   657
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   658
SDL_HelperWindowCreate(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   659
{
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   660
    HINSTANCE hInstance = GetModuleHandle(NULL);
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   661
    WNDCLASS wce;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   662
3045
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   663
    /* 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
   664
    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
   665
        return 0;
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   666
    }
9acb9f0f7f0d Some more safety around the SDL_HelperWindow stuff to avoid double creations.
Edgar Simo <bobbens@gmail.com>
parents: 2990
diff changeset
   667
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   668
    /* 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
   669
    SDL_zero(wce);
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   670
    wce.lpfnWndProc = DefWindowProc;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   671
    wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   672
    wce.hInstance = hInstance;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   673
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   674
    /* Register the class. */
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   675
    SDL_HelperWindowClass = RegisterClass(&wce);
8238
9e09e1561e00 Don't fail initialization if the helper window class already exists.
Sam Lantinga <slouken@libsdl.org>
parents: 8205
diff changeset
   676
    if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   677
        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
   678
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   679
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   680
    /* 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
   681
    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
   682
                                      SDL_HelperWindowName,
3168
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   683
                                      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
   684
                                      CW_USEDEFAULT, CW_USEDEFAULT,
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6428
diff changeset
   685
                                      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
   686
                                      hInstance, NULL);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   687
    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
   688
        UnregisterClass(SDL_HelperWindowClassName, hInstance);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6943
diff changeset
   689
        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
   690
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   691
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   692
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   693
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   694
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   695
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   696
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   697
 * 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
   698
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   699
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   700
SDL_HelperWindowDestroy(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   701
{
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   702
    HINSTANCE hInstance = GetModuleHandle(NULL);
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   703
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   704
    /* Destroy the window. */
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   705
    if (SDL_HelperWindow != NULL) {
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   706
        if (DestroyWindow(SDL_HelperWindow) == 0) {
4500
eff4e88cc1e8 Added Windows clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4486
diff changeset
   707
            WIN_SetError("Unable to destroy Helper Window");
2865
Sam Lantinga <slouken@libsdl.org>
parents: 2863
diff changeset
   708
            return;
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   709
        }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   710
        SDL_HelperWindow = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   711
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   712
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   713
    /* Unregister the class. */
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   714
    if (SDL_HelperWindowClass != 0) {
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   715
        if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
4500
eff4e88cc1e8 Added Windows clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4486
diff changeset
   716
            WIN_SetError("Unable to destroy Helper Window Class");
2865
Sam Lantinga <slouken@libsdl.org>
parents: 2863
diff changeset
   717
            return;
2863
b632927c28c8 Some error checking when destroying the HelperWindow.
Edgar Simo <bobbens@gmail.com>
parents: 2859
diff changeset
   718
        }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   719
        SDL_HelperWindowClass = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   720
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   721
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   722
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   723
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
   724
{
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   725
#ifdef WM_MOUSELEAVE
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   726
    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
   727
    TRACKMOUSEEVENT trackMouseEvent;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   728
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   729
    if (!data || !data->hwnd) {
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   730
        /* 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
   731
        return;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   732
    }
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   733
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   734
    trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   735
    trackMouseEvent.dwFlags = TME_LEAVE;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   736
    trackMouseEvent.hwndTrack = data->hwnd;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   737
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   738
    TrackMouseEvent(&trackMouseEvent);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   739
#endif /* WM_MOUSELEAVE */
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   740
}
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   741
8072
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   742
void
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   743
WIN_UpdateClipCursor(SDL_Window *window)
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   744
{
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   745
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   746
    SDL_Mouse *mouse = SDL_GetMouse();
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   747
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   748
    /* Don't clip the cursor while we're in the modal resize or move loop */
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   749
    if (data->in_modal_loop) {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   750
        ClipCursor(NULL);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   751
        return;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   752
    }
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   753
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   754
    if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   755
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   756
        if (mouse->relative_mode && !mouse->relative_mode_warp) {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   757
            LONG cx, cy;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   758
            RECT rect;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   759
            GetWindowRect(data->hwnd, &rect);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   760
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   761
            cx = (rect.left + rect.right) / 2;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   762
            cy = (rect.top + rect.bottom) / 2;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   763
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   764
            /* Make an absurdly small clip rect */
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   765
            rect.left = cx - 1;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   766
            rect.right = cx + 1;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   767
            rect.top = cy - 1;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   768
            rect.bottom = cy + 1;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   769
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   770
            ClipCursor(&rect);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   771
        } else {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   772
            RECT rect;
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   773
            if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   774
                ClientToScreen(data->hwnd, (LPPOINT) & rect);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   775
                ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   776
                ClipCursor(&rect);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   777
            }
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   778
        }
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   779
    } else {
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   780
        ClipCursor(NULL);
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   781
    }
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   782
}
9d8865351afd Setting the mouse in relative mode implies grabbing the mouse.
Sam Lantinga <slouken@libsdl.org>
parents: 8021
diff changeset
   783
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5980
diff changeset
   784
#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
   785
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
   786
/* vi: set ts=4 sw=4 expandtab: */