Proximity events, Pressure detection for multiple windows. Tablet button detection on the way. gsoc2008_manymouse
authorSzymon Wilczek
Wed, 23 Jul 2008 16:12:43 +0000
branchgsoc2008_manymouse
changeset 3767abc8acb8e3d7
parent 3766 24db5d326f57
child 3768 1b87a8beab9d
Proximity events, Pressure detection for multiple windows. Tablet button detection on the way.
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32keyboard.c
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32window.c
     1.1 --- a/src/events/SDL_mouse.c	Sun Jul 06 09:24:56 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Wed Jul 23 16:12:43 2008 +0000
     1.3 @@ -28,12 +28,12 @@
     1.4  #include "default_cursor.h"
     1.5  
     1.6  
     1.7 -static int SDL_num_mice;
     1.8 -static int SDL_current_mouse;
     1.9 -static SDL_Mouse **SDL_mice;
    1.10 -int *SDL_IdIndex;
    1.11 -int SDL_highestId;
    1.12 -int last_x, last_y;
    1.13 +static int SDL_num_mice=0;
    1.14 +static int SDL_current_mouse=-1;
    1.15 +static SDL_Mouse **SDL_mice=NULL;
    1.16 +static int *SDL_IdIndex=NULL;
    1.17 +static int SDL_highestId=-1;
    1.18 +static int last_x, last_y;
    1.19  int x_max, y_max;
    1.20  /* Public functions */
    1.21  int
    1.22 @@ -56,7 +56,7 @@
    1.23  {
    1.24      SDL_Mouse **mice;
    1.25      int selected_mouse;
    1.26 -    char* temp_name;
    1.27 +    //char* temp_name;
    1.28      /* Add the mouse to the list of mice */
    1.29      if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    1.30          mice =
    1.31 @@ -76,8 +76,8 @@
    1.32          return -1;
    1.33      }
    1.34      *SDL_mice[index] = *mouse;
    1.35 -    SDL_mice[index]->name=SDL_malloc(strlen(name)*sizeof(char));
    1.36 -    strcpy(SDL_mice[index]->name,name);
    1.37 +    SDL_mice[index]->name=SDL_malloc(SDL_strlen(name)*sizeof(char));
    1.38 +    SDL_strlcpy(SDL_mice[index]->name,name,255);
    1.39      SDL_mice[index]->pressure_max=pressure_max;
    1.40      SDL_mice[index]->pressure_min=pressure_min;
    1.41      SDL_mice[index]->cursor_shown = SDL_TRUE;
    1.42 @@ -721,7 +721,7 @@
    1.43      return shown;
    1.44  }
    1.45  
    1.46 -void SDL_SetIndexId(int id, int index)
    1.47 +int SDL_SetIndexId(int id, int index)
    1.48  {
    1.49      if(id>SDL_highestId)
    1.50      {
    1.51 @@ -741,6 +741,7 @@
    1.52      {
    1.53          SDL_IdIndex[id]=index;
    1.54      }
    1.55 +	return 1;
    1.56  }
    1.57  
    1.58  int SDL_GetIndexById(int id)
     2.1 --- a/src/events/SDL_mouse_c.h	Sun Jul 06 09:24:56 2008 +0000
     2.2 +++ b/src/events/SDL_mouse_c.h	Wed Jul 23 16:12:43 2008 +0000
     2.3 @@ -118,7 +118,7 @@
     2.4  
     2.5  extern int SDL_GetIndexById(int id);
     2.6  
     2.7 -extern void SDL_SetIndexId(int id, int index);
     2.8 +extern int SDL_SetIndexId(int id, int index);
     2.9  
    2.10  extern int SDL_GetNumOfMice(void);
    2.11  
     3.1 --- a/src/video/win32/SDL_win32events.c	Sun Jul 06 09:24:56 2008 +0000
     3.2 +++ b/src/video/win32/SDL_win32events.c	Wed Jul 23 16:12:43 2008 +0000
     3.3 @@ -1,720 +1,764 @@
     3.4 -/*
     3.5 -    SDL - Simple DirectMedia Layer
     3.6 -    Copyright (C) 1997-2006 Sam Lantinga
     3.7 -
     3.8 -    This library is free software; you can redistribute it and/or
     3.9 -    modify it under the terms of the GNU Lesser General Public
    3.10 -    License as published by the Free Software Foundation; either
    3.11 -    version 2.1 of the License, or (at your option) any later version.
    3.12 -
    3.13 -    This library is distributed in the hope that it will be useful,
    3.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 -    Lesser General Public License for more details.
    3.17 -
    3.18 -    You should have received a copy of the GNU Lesser General Public
    3.19 -    License along with this library; if not, write to the Free Software
    3.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 -
    3.22 -    Sam Lantinga
    3.23 -    slouken@libsdl.org
    3.24 -*/
    3.25 -#include "SDL_config.h"
    3.26 -
    3.27 -#include "SDL_win32video.h"
    3.28 -#include "SDL_syswm.h"
    3.29 -#include "SDL_vkeys.h"
    3.30 -#include "../../events/SDL_events_c.h"
    3.31 -
    3.32 -/*#define WMMSG_DEBUG*/
    3.33 -#ifdef WMMSG_DEBUG
    3.34 -#include <stdio.h>
    3.35 -#include "wmmsg.h"
    3.36 -#endif
    3.37 -
    3.38 -/* Masks for processing the windows KEYDOWN and KEYUP messages */
    3.39 -#define REPEATED_KEYMASK    (1<<30)
    3.40 -#define EXTENDED_KEYMASK    (1<<24)
    3.41 -
    3.42 -#define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
    3.43 -
    3.44 -/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
    3.45 -#ifndef WM_XBUTTONDOWN
    3.46 -#define WM_XBUTTONDOWN 0x020B
    3.47 -#endif
    3.48 -#ifndef WM_XBUTTONUP
    3.49 -#define WM_XBUTTONUP 0x020C
    3.50 -#endif
    3.51 -#ifndef GET_XBUTTON_WPARAM
    3.52 -#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
    3.53 -#endif
    3.54 -
    3.55 -static WPARAM
    3.56 -RemapVKEY(WPARAM wParam, LPARAM lParam)
    3.57 -{
    3.58 -    int i;
    3.59 -    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
    3.60 -
    3.61 -    /* Windows remaps alphabetic keys based on current layout.
    3.62 -       We try to provide USB scancodes, so undo this mapping.
    3.63 -     */
    3.64 -    if (wParam >= 'A' && wParam <= 'Z') {
    3.65 -        if (scancode != alpha_scancodes[wParam - 'A']) {
    3.66 -            for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    3.67 -                if (scancode == alpha_scancodes[i]) {
    3.68 -                    wParam = 'A' + i;
    3.69 -                    break;
    3.70 -                }
    3.71 -            }
    3.72 -        }
    3.73 -    }
    3.74 -
    3.75 -    /* Keypad keys are a little trickier, we always scan for them. */
    3.76 -    for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    3.77 -        if (scancode == keypad_scancodes[i]) {
    3.78 -            wParam = VK_NUMPAD0 + i;
    3.79 -            break;
    3.80 -        }
    3.81 -    }
    3.82 -
    3.83 -    return wParam;
    3.84 -}
    3.85 -
    3.86 -LRESULT CALLBACK
    3.87 -WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    3.88 -{
    3.89 -    SDL_WindowData *data;
    3.90 -
    3.91 -    /* Send a SDL_SYSWMEVENT if the application wants them */
    3.92 -    if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
    3.93 -        SDL_SysWMmsg wmmsg;
    3.94 -
    3.95 -        SDL_VERSION(&wmmsg.version);
    3.96 -        wmmsg.hwnd = hwnd;
    3.97 -        wmmsg.msg = msg;
    3.98 -        wmmsg.wParam = wParam;
    3.99 -        wmmsg.lParam = lParam;
   3.100 -        SDL_SendSysWMEvent(&wmmsg);
   3.101 -    }
   3.102 -
   3.103 -    /* Get the window data for the window */
   3.104 -    data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
   3.105 -    if (!data) {
   3.106 -        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
   3.107 -    }
   3.108 -#ifdef WMMSG_DEBUG
   3.109 -    {
   3.110 -        FILE *log = fopen("wmmsg.txt", "a");
   3.111 -        fprintf(log, "Received windows message: %p ", hwnd);
   3.112 -        if (msg > MAX_WMMSG) {
   3.113 -            fprintf(log, "%d", msg);
   3.114 -        } else {
   3.115 -            fprintf(log, "%s", wmtab[msg]);
   3.116 -        }
   3.117 -        fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
   3.118 -        fclose(log);
   3.119 -    }
   3.120 -#endif
   3.121 -
   3.122 -    switch (msg) {
   3.123 -
   3.124 -    case WM_SHOWWINDOW:
   3.125 -        {
   3.126 -            if (wParam) {
   3.127 -                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, 0,
   3.128 -                                    0);
   3.129 -            } else {
   3.130 -                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_HIDDEN, 0,
   3.131 -                                    0);
   3.132 -            }
   3.133 -        }
   3.134 -        break;
   3.135 -
   3.136 -    case WM_ACTIVATE:
   3.137 -        {
   3.138 -            int index;
   3.139 -            SDL_Keyboard *keyboard;
   3.140 -            BOOL minimized;
   3.141 -
   3.142 -            minimized = HIWORD(wParam);
   3.143 -            index = data->videodata->keyboard;
   3.144 -            keyboard = SDL_GetKeyboard(index);
   3.145 -            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
   3.146 -                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN,
   3.147 -                                    0, 0);
   3.148 -                SDL_SendWindowEvent(data->windowID,
   3.149 -                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
   3.150 -                if (IsZoomed(hwnd)) {
   3.151 -                    SDL_SendWindowEvent(data->windowID,
   3.152 -                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   3.153 -                }
   3.154 -                if (keyboard && keyboard->focus != data->windowID) {
   3.155 -                    SDL_SetKeyboardFocus(index, data->windowID);
   3.156 -                }
   3.157 -                /* FIXME: Update keyboard state */
   3.158 -            } else {
   3.159 -                if (keyboard && keyboard->focus == data->windowID) {
   3.160 -                    SDL_SetKeyboardFocus(index, 0);
   3.161 -                }
   3.162 -                if (minimized) {
   3.163 -                    SDL_SendWindowEvent(data->windowID,
   3.164 -                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   3.165 -                }
   3.166 -            }
   3.167 -            return (0);
   3.168 -        }
   3.169 -        break;
   3.170 -
   3.171 -    case WM_MOUSEMOVE:
   3.172 -        {
   3.173 -            int index;
   3.174 -            SDL_Mouse *mouse;
   3.175 -            int x, y;
   3.176 -
   3.177 -            index = data->videodata->mouse;
   3.178 -            mouse = SDL_GetMouse(index);
   3.179 -
   3.180 -            if (mouse->focus != data->windowID) {
   3.181 -                TRACKMOUSEEVENT tme;
   3.182 -
   3.183 -                tme.cbSize = sizeof(tme);
   3.184 -                tme.dwFlags = TME_LEAVE;
   3.185 -                tme.hwndTrack = hwnd;
   3.186 -                TrackMouseEvent(&tme);
   3.187 -
   3.188 -                SDL_SetMouseFocus(index, data->windowID);
   3.189 -            }
   3.190 -
   3.191 -            /* mouse has moved within the window */
   3.192 -            x = LOWORD(lParam);
   3.193 -            y = HIWORD(lParam);
   3.194 -            if (mouse->relative_mode) {
   3.195 -                int w, h;
   3.196 -                POINT center;
   3.197 -                SDL_GetWindowSize(data->windowID, &w, &h);
   3.198 -                center.x = (w / 2);
   3.199 -                center.y = (h / 2);
   3.200 -                x -= center.x;
   3.201 -                y -= center.y;
   3.202 -                if (x || y) {
   3.203 -                    ClientToScreen(hwnd, &center);
   3.204 -                    SetCursorPos(center.x, center.y);
   3.205 -                    SDL_SendMouseMotion(index, 1, x, y);
   3.206 -                }
   3.207 -            } else {
   3.208 -                SDL_SendMouseMotion(index, 0, x, y);
   3.209 -            }
   3.210 -        }
   3.211 -        return (0);
   3.212 -
   3.213 -    case WM_MOUSELEAVE:
   3.214 -        {
   3.215 -            int index;
   3.216 -            SDL_Mouse *mouse;
   3.217 -
   3.218 -            index = data->videodata->mouse;
   3.219 -            mouse = SDL_GetMouse(index);
   3.220 -
   3.221 -            if (mouse->focus == data->windowID) {
   3.222 -                SDL_SetMouseFocus(index, 0);
   3.223 -            }
   3.224 -        }
   3.225 -        return (0);
   3.226 -
   3.227 -    case WM_LBUTTONDOWN:
   3.228 -    case WM_LBUTTONUP:
   3.229 -    case WM_MBUTTONDOWN:
   3.230 -    case WM_MBUTTONUP:
   3.231 -    case WM_RBUTTONDOWN:
   3.232 -    case WM_RBUTTONUP:
   3.233 -    case WM_XBUTTONDOWN:
   3.234 -    case WM_XBUTTONUP:
   3.235 -        {
   3.236 -            int xbuttonval = 0;
   3.237 -            int index;
   3.238 -            SDL_Mouse *mouse;
   3.239 -            Uint8 button, state;
   3.240 -
   3.241 -            /* DJM:
   3.242 -               We want the SDL window to take focus so that
   3.243 -               it acts like a normal windows "component"
   3.244 -               (e.g. gains keyboard focus on a mouse click).
   3.245 -             */
   3.246 -            SetFocus(hwnd);
   3.247 -
   3.248 -            index = data->videodata->mouse;
   3.249 -            mouse = SDL_GetMouse(index);
   3.250 -
   3.251 -            /* Figure out which button to use */
   3.252 -            switch (msg) {
   3.253 -            case WM_LBUTTONDOWN:
   3.254 -                button = SDL_BUTTON_LEFT;
   3.255 -                state = SDL_PRESSED;
   3.256 -                break;
   3.257 -            case WM_LBUTTONUP:
   3.258 -                button = SDL_BUTTON_LEFT;
   3.259 -                state = SDL_RELEASED;
   3.260 -                break;
   3.261 -            case WM_MBUTTONDOWN:
   3.262 -                button = SDL_BUTTON_MIDDLE;
   3.263 -                state = SDL_PRESSED;
   3.264 -                break;
   3.265 -            case WM_MBUTTONUP:
   3.266 -                button = SDL_BUTTON_MIDDLE;
   3.267 -                state = SDL_RELEASED;
   3.268 -                break;
   3.269 -            case WM_RBUTTONDOWN:
   3.270 -                button = SDL_BUTTON_RIGHT;
   3.271 -                state = SDL_PRESSED;
   3.272 -                break;
   3.273 -            case WM_RBUTTONUP:
   3.274 -                button = SDL_BUTTON_RIGHT;
   3.275 -                state = SDL_RELEASED;
   3.276 -                break;
   3.277 -            case WM_XBUTTONDOWN:
   3.278 -                xbuttonval = GET_XBUTTON_WPARAM(wParam);
   3.279 -                button = SDL_BUTTON_X1 + xbuttonval - 1;
   3.280 -                state = SDL_PRESSED;
   3.281 -                break;
   3.282 -            case WM_XBUTTONUP:
   3.283 -                xbuttonval = GET_XBUTTON_WPARAM(wParam);
   3.284 -                button = SDL_BUTTON_X1 + xbuttonval - 1;
   3.285 -                state = SDL_RELEASED;
   3.286 -                break;
   3.287 -            default:
   3.288 -                /* Eh? Unknown button? */
   3.289 -                return (0);
   3.290 -            }
   3.291 -            if (state == SDL_PRESSED) {
   3.292 -                /* Grab mouse so we get up events */
   3.293 -                if (++data->mouse_pressed > 0) {
   3.294 -                    SetCapture(hwnd);
   3.295 -                }
   3.296 -            } else {
   3.297 -                /* Release mouse after all up events */
   3.298 -                if (--data->mouse_pressed <= 0) {
   3.299 -                    ReleaseCapture();
   3.300 -                    data->mouse_pressed = 0;
   3.301 -                }
   3.302 -            }
   3.303 -
   3.304 -            if (!mouse->relative_mode) {
   3.305 -                int x, y;
   3.306 -                x = LOWORD(lParam);
   3.307 -                y = HIWORD(lParam);
   3.308 -                SDL_SendMouseMotion(index, 0, x, y);
   3.309 -            }
   3.310 -            SDL_SendMouseButton(index, state, button);
   3.311 -
   3.312 -            /*
   3.313 -             * MSDN says:
   3.314 -             *  "Unlike the WM_LBUTTONUP, WM_MBUTTONUP, and WM_RBUTTONUP
   3.315 -             *   messages, an application should return TRUE from [an
   3.316 -             *   XBUTTON message] if it processes it. Doing so will allow
   3.317 -             *   software that simulates this message on Microsoft Windows
   3.318 -             *   systems earlier than Windows 2000 to determine whether
   3.319 -             *   the window procedure processed the message or called
   3.320 -             *   DefWindowProc to process it.
   3.321 -             */
   3.322 -            if (xbuttonval > 0) {
   3.323 -                return (TRUE);
   3.324 -            }
   3.325 -        }
   3.326 -        return (0);
   3.327 -
   3.328 -    case WM_MOUSEWHEEL:
   3.329 -        {
   3.330 -            int index;
   3.331 -            int motion = (short) HIWORD(wParam);
   3.332 -
   3.333 -            index = data->videodata->mouse;
   3.334 -            SDL_SendMouseWheel(index, 0, motion);
   3.335 -        }
   3.336 -        return (0);
   3.337 -
   3.338 -    case WM_SYSKEYDOWN:
   3.339 -    case WM_KEYDOWN:
   3.340 -        {
   3.341 -            int index;
   3.342 -
   3.343 -            /* Ignore repeated keys */
   3.344 -            if (lParam & REPEATED_KEYMASK) {
   3.345 -                return (0);
   3.346 -            }
   3.347 -
   3.348 -            index = data->videodata->keyboard;
   3.349 -            wParam = RemapVKEY(wParam, lParam);
   3.350 -            switch (wParam) {
   3.351 -            case VK_CONTROL:
   3.352 -                if (lParam & EXTENDED_KEYMASK)
   3.353 -                    wParam = VK_RCONTROL;
   3.354 -                else
   3.355 -                    wParam = VK_LCONTROL;
   3.356 -                break;
   3.357 -            case VK_SHIFT:
   3.358 -                /* EXTENDED trick doesn't work here */
   3.359 -                {
   3.360 -                    Uint8 *state = SDL_GetKeyboardState(NULL);
   3.361 -                    if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
   3.362 -                        && (GetKeyState(VK_LSHIFT) & 0x8000)) {
   3.363 -                        wParam = VK_LSHIFT;
   3.364 -                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
   3.365 -                               && (GetKeyState(VK_RSHIFT) & 0x8000)) {
   3.366 -                        wParam = VK_RSHIFT;
   3.367 -                    } else {
   3.368 -                        /* Probably a key repeat */
   3.369 -                        return (0);
   3.370 -                    }
   3.371 -                }
   3.372 -                break;
   3.373 -            case VK_MENU:
   3.374 -                if (lParam & EXTENDED_KEYMASK)
   3.375 -                    wParam = VK_RMENU;
   3.376 -                else
   3.377 -                    wParam = VK_LMENU;
   3.378 -                break;
   3.379 -            case VK_RETURN:
   3.380 -                if (lParam & EXTENDED_KEYMASK)
   3.381 -                    wParam = VK_ENTER;
   3.382 -                break;
   3.383 -            }
   3.384 -            if (wParam < 256) {
   3.385 -                SDL_SendKeyboardKey(index, SDL_PRESSED,
   3.386 -                                    data->videodata->key_layout[wParam]);
   3.387 -            }
   3.388 -        }
   3.389 -        return (0);
   3.390 -
   3.391 -    case WM_SYSKEYUP:
   3.392 -    case WM_KEYUP:
   3.393 -        {
   3.394 -            int index;
   3.395 -
   3.396 -            index = data->videodata->keyboard;
   3.397 -            wParam = RemapVKEY(wParam, lParam);
   3.398 -            switch (wParam) {
   3.399 -            case VK_CONTROL:
   3.400 -                if (lParam & EXTENDED_KEYMASK)
   3.401 -                    wParam = VK_RCONTROL;
   3.402 -                else
   3.403 -                    wParam = VK_LCONTROL;
   3.404 -                break;
   3.405 -            case VK_SHIFT:
   3.406 -                /* EXTENDED trick doesn't work here */
   3.407 -                {
   3.408 -                    Uint8 *state = SDL_GetKeyboardState(NULL);
   3.409 -                    if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
   3.410 -                        && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
   3.411 -                        wParam = VK_LSHIFT;
   3.412 -                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
   3.413 -                               && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
   3.414 -                        wParam = VK_RSHIFT;
   3.415 -                    } else {
   3.416 -                        /* Probably a key repeat */
   3.417 -                        return (0);
   3.418 -                    }
   3.419 -                }
   3.420 -                break;
   3.421 -            case VK_MENU:
   3.422 -                if (lParam & EXTENDED_KEYMASK)
   3.423 -                    wParam = VK_RMENU;
   3.424 -                else
   3.425 -                    wParam = VK_LMENU;
   3.426 -                break;
   3.427 -            case VK_RETURN:
   3.428 -                if (lParam & EXTENDED_KEYMASK)
   3.429 -                    wParam = VK_ENTER;
   3.430 -                break;
   3.431 -            }
   3.432 -            /* Windows only reports keyup for print screen */
   3.433 -            if (wParam == VK_SNAPSHOT
   3.434 -                && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
   3.435 -                SDL_RELEASED) {
   3.436 -                SDL_SendKeyboardKey(index, SDL_PRESSED,
   3.437 -                                    data->videodata->key_layout[wParam]);
   3.438 -            }
   3.439 -            if (wParam < 256) {
   3.440 -                SDL_SendKeyboardKey(index, SDL_RELEASED,
   3.441 -                                    data->videodata->key_layout[wParam]);
   3.442 -            }
   3.443 -        }
   3.444 -        return (0);
   3.445 -
   3.446 -    case WM_CHAR:
   3.447 -        {
   3.448 -            char text[4];
   3.449 -
   3.450 -            /* Convert to UTF-8 and send it on... */
   3.451 -            if (wParam <= 0x7F) {
   3.452 -                text[0] = (char) wParam;
   3.453 -                text[1] = '\0';
   3.454 -            } else if (wParam <= 0x7FF) {
   3.455 -                text[0] = 0xC0 | (char) ((wParam >> 6) & 0x1F);
   3.456 -                text[1] = 0x80 | (char) (wParam & 0x3F);
   3.457 -                text[2] = '\0';
   3.458 -            } else {
   3.459 -                text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
   3.460 -                text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
   3.461 -                text[2] = 0x80 | (char) (wParam & 0x3F);
   3.462 -                text[3] = '\0';
   3.463 -            }
   3.464 -            SDL_SendKeyboardText(data->videodata->keyboard, text);
   3.465 -        }
   3.466 -        return (0);
   3.467 -
   3.468 -    case WM_INPUTLANGCHANGE:
   3.469 -        {
   3.470 -            WIN_UpdateKeymap(data->videodata->keyboard);
   3.471 -        }
   3.472 -        return (1);
   3.473 -
   3.474 -    case WM_GETMINMAXINFO:
   3.475 -        {
   3.476 -            MINMAXINFO *info;
   3.477 -            RECT size;
   3.478 -            int x, y;
   3.479 -            int w, h;
   3.480 -            int style;
   3.481 -
   3.482 -            /* If we allow resizing, let the resize happen naturally */
   3.483 -            if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_RESIZABLE) {
   3.484 -                return (0);
   3.485 -            }
   3.486 -
   3.487 -            /* Get the current position of our window */
   3.488 -            GetWindowRect(hwnd, &size);
   3.489 -            x = size.left;
   3.490 -            y = size.top;
   3.491 -
   3.492 -            /* Calculate current size of our window */
   3.493 -            SDL_GetWindowSize(data->windowID, &w, &h);
   3.494 -            size.top = 0;
   3.495 -            size.left = 0;
   3.496 -            size.bottom = h;
   3.497 -            size.right = w;
   3.498 -
   3.499 -            /* DJM - according to the docs for GetMenu(), the
   3.500 -               return value is undefined if hwnd is a child window.
   3.501 -               Aparently it's too difficult for MS to check
   3.502 -               inside their function, so I have to do it here.
   3.503 -             */
   3.504 -            style = GetWindowLong(hwnd, GWL_STYLE);
   3.505 -            AdjustWindowRect(&size,
   3.506 -                             style,
   3.507 -                             style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) !=
   3.508 -                             NULL);
   3.509 -
   3.510 -            w = size.right - size.left;
   3.511 -            h = size.bottom - size.top;
   3.512 -
   3.513 -            /* Fix our size to the current size */
   3.514 -            info = (MINMAXINFO *) lParam;
   3.515 -            info->ptMaxSize.x = w;
   3.516 -            info->ptMaxSize.y = h;
   3.517 -            info->ptMaxPosition.x = x;
   3.518 -            info->ptMaxPosition.y = y;
   3.519 -            info->ptMinTrackSize.x = w;
   3.520 -            info->ptMinTrackSize.y = h;
   3.521 -            info->ptMaxTrackSize.x = w;
   3.522 -            info->ptMaxTrackSize.y = h;
   3.523 -        }
   3.524 -        return (0);
   3.525 -
   3.526 -    case WM_WINDOWPOSCHANGED:
   3.527 -        {
   3.528 -            RECT rect;
   3.529 -            int x, y;
   3.530 -            int w, h;
   3.531 -            Uint32 window_flags;
   3.532 -
   3.533 -            GetClientRect(hwnd, &rect);
   3.534 -            ClientToScreen(hwnd, (LPPOINT) & rect);
   3.535 -            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   3.536 -
   3.537 -            window_flags = SDL_GetWindowFlags(data->windowID);
   3.538 -            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
   3.539 -                (window_flags & SDL_WINDOW_INPUT_FOCUS)) {
   3.540 -                ClipCursor(&rect);
   3.541 -            }
   3.542 -
   3.543 -            x = rect.left;
   3.544 -            y = rect.top;
   3.545 -            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MOVED, x, y);
   3.546 -
   3.547 -            w = rect.right - rect.left;
   3.548 -            h = rect.bottom - rect.top;
   3.549 -            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESIZED, w,
   3.550 -                                h);
   3.551 -        }
   3.552 -        break;
   3.553 -
   3.554 -    case WM_SETCURSOR:
   3.555 -        {
   3.556 -            /*
   3.557 -               Uint16 hittest;
   3.558 -
   3.559 -               hittest = LOWORD(lParam);
   3.560 -               if (hittest == HTCLIENT) {
   3.561 -               SetCursor(SDL_hcursor);
   3.562 -               return (TRUE);
   3.563 -               }
   3.564 -             */
   3.565 -        }
   3.566 -        break;
   3.567 -
   3.568 -        /* We are about to get palette focus! */
   3.569 -    case WM_QUERYNEWPALETTE:
   3.570 -        {
   3.571 -            /*
   3.572 -               WIN_RealizePalette(current_video);
   3.573 -               return (TRUE);
   3.574 -             */
   3.575 -        }
   3.576 -        break;
   3.577 -
   3.578 -        /* Another application changed the palette */
   3.579 -    case WM_PALETTECHANGED:
   3.580 -        {
   3.581 -            /*
   3.582 -               WIN_PaletteChanged(current_video, (HWND) wParam);
   3.583 -             */
   3.584 -        }
   3.585 -        break;
   3.586 -
   3.587 -        /* We were occluded, refresh our display */
   3.588 -    case WM_PAINT:
   3.589 -        {
   3.590 -            RECT rect;
   3.591 -            if (GetUpdateRect(hwnd, &rect, FALSE)) {
   3.592 -                ValidateRect(hwnd, &rect);
   3.593 -                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
   3.594 -                                    0, 0);
   3.595 -            }
   3.596 -        }
   3.597 -        return (0);
   3.598 -
   3.599 -        /* We'll do our own drawing, prevent flicker */
   3.600 -    case WM_ERASEBKGND:
   3.601 -        {
   3.602 -        }
   3.603 -        return (1);
   3.604 -
   3.605 -    case WM_SYSCOMMAND:
   3.606 -        {
   3.607 -            /* Don't start the screensaver or blank the monitor in fullscreen apps */
   3.608 -            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
   3.609 -                (wParam & 0xFFF0) == SC_MONITORPOWER) {
   3.610 -                if (SDL_GetWindowFlags(data->windowID) &
   3.611 -                    SDL_WINDOW_FULLSCREEN) {
   3.612 -                    return (0);
   3.613 -                }
   3.614 -            }
   3.615 -        }
   3.616 -        break;
   3.617 -
   3.618 -    case WM_CLOSE:
   3.619 -        {
   3.620 -            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0);
   3.621 -        }
   3.622 -        return (0);
   3.623 -    }
   3.624 -    return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
   3.625 -}
   3.626 -
   3.627 -void
   3.628 -WIN_PumpEvents(_THIS)
   3.629 -{
   3.630 -    MSG msg;
   3.631 -    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
   3.632 -        TranslateMessage(&msg);
   3.633 -        DispatchMessage(&msg);
   3.634 -    }
   3.635 -}
   3.636 -
   3.637 -static int app_registered = 0;
   3.638 -LPTSTR SDL_Appname = NULL;
   3.639 -Uint32 SDL_Appstyle = 0;
   3.640 -HINSTANCE SDL_Instance = NULL;
   3.641 -
   3.642 -/* Register the class for this application */
   3.643 -int
   3.644 -SDL_RegisterApp(char *name, Uint32 style, void *hInst)
   3.645 -{
   3.646 -    WNDCLASS class;
   3.647 -
   3.648 -    /* Only do this once... */
   3.649 -    if (app_registered) {
   3.650 -        ++app_registered;
   3.651 -        return (0);
   3.652 -    }
   3.653 -    if (!name && !SDL_Appname) {
   3.654 -        name = "SDL_app";
   3.655 -        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
   3.656 -        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
   3.657 -    }
   3.658 -
   3.659 -    if (name) {
   3.660 -        SDL_Appname = WIN_UTF8ToString(name);
   3.661 -        SDL_Appstyle = style;
   3.662 -        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
   3.663 -    }
   3.664 -
   3.665 -    /* Register the application class */
   3.666 -    class.hCursor = NULL;
   3.667 -    class.hIcon = LoadImage(SDL_Instance, SDL_Appname,
   3.668 -                            IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
   3.669 -    class.lpszMenuName = NULL;
   3.670 -    class.lpszClassName = SDL_Appname;
   3.671 -    class.hbrBackground = NULL;
   3.672 -    class.hInstance = SDL_Instance;
   3.673 -    class.style = SDL_Appstyle;
   3.674 -    class.lpfnWndProc = DefWindowProc;
   3.675 -    class.cbWndExtra = 0;
   3.676 -    class.cbClsExtra = 0;
   3.677 -    if (!RegisterClass(&class)) {
   3.678 -        SDL_SetError("Couldn't register application class");
   3.679 -        return (-1);
   3.680 -    }
   3.681 -
   3.682 -    app_registered = 1;
   3.683 -    return (0);
   3.684 -}
   3.685 -
   3.686 -/* Unregisters the windowclass registered in SDL_RegisterApp above. */
   3.687 -void
   3.688 -SDL_UnregisterApp()
   3.689 -{
   3.690 -    WNDCLASS class;
   3.691 -
   3.692 -    /* SDL_RegisterApp might not have been called before */
   3.693 -    if (!app_registered) {
   3.694 -        return;
   3.695 -    }
   3.696 -    --app_registered;
   3.697 -    if (app_registered == 0) {
   3.698 -        /* Check for any registered window classes. */
   3.699 -        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
   3.700 -            UnregisterClass(SDL_Appname, SDL_Instance);
   3.701 -        }
   3.702 -        SDL_free(SDL_Appname);
   3.703 -        SDL_Appname = NULL;
   3.704 -    }
   3.705 -}
   3.706 -
   3.707 -/* Sets an error message based on GetLastError() */
   3.708 -void
   3.709 -WIN_SetError(const char *prefix)
   3.710 -{
   3.711 -    TCHAR buffer[1024];
   3.712 -    char *message;
   3.713 -
   3.714 -    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
   3.715 -                  NULL,
   3.716 -                  GetLastError(), 0, buffer, SDL_arraysize(buffer), NULL);
   3.717 -
   3.718 -    message = WIN_StringToUTF8(buffer);
   3.719 -    SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ":" : "", message);
   3.720 -    SDL_free(message);
   3.721 -}
   3.722 -
   3.723 -/* vi: set ts=4 sw=4 expandtab: */
   3.724 +/*
   3.725 +    SDL - Simple DirectMedia Layer
   3.726 +    Copyright (C) 1997-2006 Sam Lantinga
   3.727 +
   3.728 +    This library is free software; you can redistribute it and/or
   3.729 +    modify it under the terms of the GNU Lesser General Public
   3.730 +    License as published by the Free Software Foundation; either
   3.731 +    version 2.1 of the License, or (at your option) any later version.
   3.732 +
   3.733 +    This library is distributed in the hope that it will be useful,
   3.734 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.735 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   3.736 +    Lesser General Public License for more details.
   3.737 +
   3.738 +    You should have received a copy of the GNU Lesser General Public
   3.739 +    License along with this library; if not, write to the Free Software
   3.740 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   3.741 +
   3.742 +    Sam Lantinga
   3.743 +    slouken@libsdl.org
   3.744 +*/
   3.745 +#include "SDL_config.h"
   3.746 +
   3.747 +#include "SDL_win32video.h"
   3.748 +#include "SDL_syswm.h"
   3.749 +#include "SDL_vkeys.h"
   3.750 +#include "../../events/SDL_events_c.h"
   3.751 +#include <wintab.h>
   3.752 +#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
   3.753 +#define PACKETMODE 0
   3.754 +#include <pktdef.h>
   3.755 +
   3.756 +/*#define WMMSG_DEBUG*/
   3.757 +#ifdef WMMSG_DEBUG
   3.758 +#include <stdio.h>
   3.759 +#include "wmmsg.h"
   3.760 +#endif
   3.761 +
   3.762 +/* Masks for processing the windows KEYDOWN and KEYUP messages */
   3.763 +#define REPEATED_KEYMASK    (1<<30)
   3.764 +#define EXTENDED_KEYMASK    (1<<24)
   3.765 +
   3.766 +#define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
   3.767 +
   3.768 +/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
   3.769 +#ifndef WM_XBUTTONDOWN
   3.770 +#define WM_XBUTTONDOWN 0x020B
   3.771 +#endif
   3.772 +#ifndef WM_XBUTTONUP
   3.773 +#define WM_XBUTTONUP 0x020C
   3.774 +#endif
   3.775 +#ifndef GET_XBUTTON_WPARAM
   3.776 +#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
   3.777 +#endif
   3.778 +
   3.779 +#define pi 1.0
   3.780 +
   3.781 +int first=1;
   3.782 +
   3.783 +LOGCONTEXT lc;
   3.784 +
   3.785 +static WPARAM
   3.786 +RemapVKEY(WPARAM wParam, LPARAM lParam)
   3.787 +{
   3.788 +    int i;
   3.789 +    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
   3.790 +
   3.791 +    /* Windows remaps alphabetic keys based on current layout.
   3.792 +       We try to provide USB scancodes, so undo this mapping.
   3.793 +     */
   3.794 +    if (wParam >= 'A' && wParam <= 'Z') {
   3.795 +        if (scancode != alpha_scancodes[wParam - 'A']) {
   3.796 +            for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
   3.797 +                if (scancode == alpha_scancodes[i]) {
   3.798 +                    wParam = 'A' + i;
   3.799 +                    break;
   3.800 +                }
   3.801 +            }
   3.802 +        }
   3.803 +    }
   3.804 +
   3.805 +    /* Keypad keys are a little trickier, we always scan for them. */
   3.806 +    for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
   3.807 +        if (scancode == keypad_scancodes[i]) {
   3.808 +            wParam = VK_NUMPAD0 + i;
   3.809 +            break;
   3.810 +        }
   3.811 +    }
   3.812 +
   3.813 +    return wParam;
   3.814 +}
   3.815 +
   3.816 +LRESULT CALLBACK
   3.817 +WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   3.818 +{
   3.819 +    SDL_WindowData *data;
   3.820 +
   3.821 +	PACKET packet;
   3.822 +	
   3.823 +	/* Send a SDL_SYSWMEVENT if the application wants them */
   3.824 +    if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
   3.825 +        SDL_SysWMmsg wmmsg;
   3.826 +
   3.827 +        SDL_VERSION(&wmmsg.version);
   3.828 +        wmmsg.hwnd = hwnd;
   3.829 +        wmmsg.msg = msg;
   3.830 +        wmmsg.wParam = wParam;
   3.831 +        wmmsg.lParam = lParam;
   3.832 +        SDL_SendSysWMEvent(&wmmsg);
   3.833 +    }
   3.834 +
   3.835 +    /* Get the window data for the window */
   3.836 +    data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
   3.837 +    if (!data) {
   3.838 +        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
   3.839 +	}
   3.840 +#ifdef WMMSG_DEBUG
   3.841 +    {
   3.842 +        FILE *log = fopen("wmmsg.txt", "a");
   3.843 +        fprintf(log, "Received windows message: %p ", hwnd);
   3.844 +        if (msg > MAX_WMMSG) {
   3.845 +            fprintf(log, "%d", msg);
   3.846 +        } else {
   3.847 +            fprintf(log, "%s", wmtab[msg]);
   3.848 +        }
   3.849 +        fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
   3.850 +        fclose(log);
   3.851 +    }
   3.852 +#endif
   3.853 +
   3.854 +    switch (msg) {
   3.855 +	case WT_PACKET:
   3.856 +		{
   3.857 +			if (WTPacket((HCTX)lParam, wParam, &packet))
   3.858 +			{
   3.859 +				SDL_SendMouseMotion(0,0,(int)packet.pkX,(int)packet.pkY,(int)packet.pkNormalPressure);
   3.860 +			}
   3.861 +		}
   3.862 +		break;
   3.863 +	case WT_PROXIMITY:
   3.864 +		{
   3.865 +			int h_context=LOWORD(lParam);
   3.866 +			if(h_context==0)
   3.867 +			{
   3.868 +				SDL_SendProximity(0, 0, 0, SDL_PROXIMITYOUT);
   3.869 +			}
   3.870 +			else
   3.871 +			{
   3.872 +				SDL_SendProximity(0, 0, 0, SDL_PROXIMITYIN);
   3.873 +			}
   3.874 +		}
   3.875 +		break;
   3.876 +    case WM_SHOWWINDOW:
   3.877 +        {
   3.878 +            if (wParam) {
   3.879 +                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, 0,
   3.880 +                                    0);
   3.881 +            } else {
   3.882 +                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_HIDDEN, 0,
   3.883 +                                    0);
   3.884 +            }
   3.885 +        }
   3.886 +        break;
   3.887 +
   3.888 +    case WM_ACTIVATE:
   3.889 +        {
   3.890 +            int index;
   3.891 +            SDL_Keyboard *keyboard;
   3.892 +            BOOL minimized;
   3.893 +
   3.894 +            minimized = HIWORD(wParam);
   3.895 +            index = data->videodata->keyboard;
   3.896 +            keyboard = SDL_GetKeyboard(index);
   3.897 +            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
   3.898 +                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN,
   3.899 +                                    0, 0);
   3.900 +                SDL_SendWindowEvent(data->windowID,
   3.901 +                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
   3.902 +                if (IsZoomed(hwnd)) {
   3.903 +                    SDL_SendWindowEvent(data->windowID,
   3.904 +                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   3.905 +                }
   3.906 +                if (keyboard && keyboard->focus != data->windowID) {
   3.907 +                    SDL_SetKeyboardFocus(index, data->windowID);
   3.908 +                }
   3.909 +                /* FIXME: Update keyboard state */
   3.910 +            } else {
   3.911 +                if (keyboard && keyboard->focus == data->windowID) {
   3.912 +                    SDL_SetKeyboardFocus(index, 0);
   3.913 +                }
   3.914 +                if (minimized) {
   3.915 +                    SDL_SendWindowEvent(data->windowID,
   3.916 +                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   3.917 +                }
   3.918 +            }
   3.919 +            return (0);
   3.920 +        }
   3.921 +        break;
   3.922 +	case WT_CTXOPEN:
   3.923 +		{
   3.924 +			SDL_SendMouseMotion(0,1,1,0,0);
   3.925 +			SDL_SendMouseMotion(0,1,-1,0,0);
   3.926 +		}
   3.927 +    case WM_MOUSEMOVE:
   3.928 +        {
   3.929 +            int index;
   3.930 +            SDL_Mouse *mouse;
   3.931 +            int x, y;
   3.932 +
   3.933 +            index = data->videodata->mouse;
   3.934 +            mouse = SDL_GetMouse(index);
   3.935 +
   3.936 +            if (mouse->focus != data->windowID) {
   3.937 +                TRACKMOUSEEVENT tme;
   3.938 +
   3.939 +                tme.cbSize = sizeof(tme);
   3.940 +                tme.dwFlags = TME_LEAVE;
   3.941 +                tme.hwndTrack = hwnd;
   3.942 +                TrackMouseEvent(&tme);
   3.943 +
   3.944 +                SDL_SetMouseFocus(index, data->windowID);
   3.945 +            }
   3.946 +
   3.947 +            /* mouse has moved within the window */
   3.948 +            x = LOWORD(lParam);
   3.949 +            y = HIWORD(lParam);
   3.950 +			//printf("index: %d\n",index);
   3.951 +            if (mouse->relative_mode) {
   3.952 +                int w, h;
   3.953 +                POINT center;
   3.954 +                SDL_GetWindowSize(data->windowID, &w, &h);
   3.955 +                center.x = (w / 2);
   3.956 +                center.y = (h / 2);
   3.957 +                x -= center.x;
   3.958 +                y -= center.y;
   3.959 +                if (x || y) {
   3.960 +                    ClientToScreen(hwnd, &center);
   3.961 +                    SetCursorPos(center.x, center.y);
   3.962 +					SDL_SendMouseMotion(index, 1, x, y,0);
   3.963 +                }
   3.964 +            } else {
   3.965 +					SDL_SendMouseMotion(index, 0, x, y,0);
   3.966 +            }
   3.967 +        }
   3.968 +        return (0);
   3.969 +
   3.970 +    case WM_MOUSELEAVE:
   3.971 +        {
   3.972 +            int index;
   3.973 +            SDL_Mouse *mouse;
   3.974 +
   3.975 +            index = data->videodata->mouse;
   3.976 +            mouse = SDL_GetMouse(index);
   3.977 +
   3.978 +            if (mouse->focus == data->windowID) {
   3.979 +                SDL_SetMouseFocus(index, 0);
   3.980 +            }
   3.981 +        }
   3.982 +        return (0);
   3.983 +
   3.984 +    case WM_LBUTTONDOWN:
   3.985 +    case WM_LBUTTONUP:
   3.986 +    case WM_MBUTTONDOWN:
   3.987 +    case WM_MBUTTONUP:
   3.988 +    case WM_RBUTTONDOWN:
   3.989 +    case WM_RBUTTONUP:
   3.990 +    case WM_XBUTTONDOWN:
   3.991 +    case WM_XBUTTONUP:
   3.992 +        {
   3.993 +            int xbuttonval = 0;
   3.994 +            int index;
   3.995 +            SDL_Mouse *mouse;
   3.996 +            Uint8 button, state;
   3.997 +
   3.998 +            /* DJM:
   3.999 +               We want the SDL window to take focus so that
  3.1000 +               it acts like a normal windows "component"
  3.1001 +               (e.g. gains keyboard focus on a mouse click).
  3.1002 +             */
  3.1003 +            SetFocus(hwnd);
  3.1004 +
  3.1005 +            index = data->videodata->mouse;
  3.1006 +            mouse = SDL_GetMouse(index);
  3.1007 +
  3.1008 +            /* Figure out which button to use */
  3.1009 +            switch (msg) {
  3.1010 +            case WM_LBUTTONDOWN:
  3.1011 +                button = SDL_BUTTON_LEFT;
  3.1012 +                state = SDL_PRESSED;
  3.1013 +                break;
  3.1014 +            case WM_LBUTTONUP:
  3.1015 +                button = SDL_BUTTON_LEFT;
  3.1016 +                state = SDL_RELEASED;
  3.1017 +                break;
  3.1018 +            case WM_MBUTTONDOWN:
  3.1019 +                button = SDL_BUTTON_MIDDLE;
  3.1020 +                state = SDL_PRESSED;
  3.1021 +                break;
  3.1022 +            case WM_MBUTTONUP:
  3.1023 +                button = SDL_BUTTON_MIDDLE;
  3.1024 +                state = SDL_RELEASED;
  3.1025 +                break;
  3.1026 +            case WM_RBUTTONDOWN:
  3.1027 +                button = SDL_BUTTON_RIGHT;
  3.1028 +                state = SDL_PRESSED;
  3.1029 +                break;
  3.1030 +            case WM_RBUTTONUP:
  3.1031 +                button = SDL_BUTTON_RIGHT;
  3.1032 +                state = SDL_RELEASED;
  3.1033 +                break;
  3.1034 +            case WM_XBUTTONDOWN:
  3.1035 +                xbuttonval = GET_XBUTTON_WPARAM(wParam);
  3.1036 +                button = SDL_BUTTON_X1 + xbuttonval - 1;
  3.1037 +                state = SDL_PRESSED;
  3.1038 +                break;
  3.1039 +            case WM_XBUTTONUP:
  3.1040 +                xbuttonval = GET_XBUTTON_WPARAM(wParam);
  3.1041 +                button = SDL_BUTTON_X1 + xbuttonval - 1;
  3.1042 +                state = SDL_RELEASED;
  3.1043 +                break;
  3.1044 +            default:
  3.1045 +                /* Eh? Unknown button? */
  3.1046 +                return (0);
  3.1047 +            }
  3.1048 +            if (state == SDL_PRESSED) {
  3.1049 +                /* Grab mouse so we get up events */
  3.1050 +                if (++data->mouse_pressed > 0) {
  3.1051 +                    SetCapture(hwnd);
  3.1052 +                }
  3.1053 +            } else {
  3.1054 +                /* Release mouse after all up events */
  3.1055 +                if (--data->mouse_pressed <= 0) {
  3.1056 +                    ReleaseCapture();
  3.1057 +                    data->mouse_pressed = 0;
  3.1058 +                }
  3.1059 +            }
  3.1060 +
  3.1061 +            if (!mouse->relative_mode) {
  3.1062 +                int x, y;
  3.1063 +                x = LOWORD(lParam);
  3.1064 +                y = HIWORD(lParam);
  3.1065 +                SDL_SendMouseMotion(index, 0, x, y,0);
  3.1066 +            }
  3.1067 +            SDL_SendMouseButton(index, state, button);
  3.1068 +
  3.1069 +            /*
  3.1070 +             * MSDN says:
  3.1071 +             *  "Unlike the WM_LBUTTONUP, WM_MBUTTONUP, and WM_RBUTTONUP
  3.1072 +             *   messages, an application should return TRUE from [an
  3.1073 +             *   XBUTTON message] if it processes it. Doing so will allow
  3.1074 +             *   software that simulates this message on Microsoft Windows
  3.1075 +             *   systems earlier than Windows 2000 to determine whether
  3.1076 +             *   the window procedure processed the message or called
  3.1077 +             *   DefWindowProc to process it.
  3.1078 +             */
  3.1079 +            if (xbuttonval > 0) {
  3.1080 +                return (TRUE);
  3.1081 +            }
  3.1082 +        }
  3.1083 +        return (0);
  3.1084 +
  3.1085 +    case WM_MOUSEWHEEL:
  3.1086 +        {
  3.1087 +            int index;
  3.1088 +            int motion = (short) HIWORD(wParam);
  3.1089 +
  3.1090 +            index = data->videodata->mouse;
  3.1091 +            SDL_SendMouseWheel(index, 0, motion);
  3.1092 +        }
  3.1093 +        return (0);
  3.1094 +
  3.1095 +    case WM_SYSKEYDOWN:
  3.1096 +    case WM_KEYDOWN:
  3.1097 +        {
  3.1098 +            int index;
  3.1099 +
  3.1100 +            /* Ignore repeated keys */
  3.1101 +            if (lParam & REPEATED_KEYMASK) {
  3.1102 +                return (0);
  3.1103 +            }
  3.1104 +
  3.1105 +            index = data->videodata->keyboard;
  3.1106 +            wParam = RemapVKEY(wParam, lParam);
  3.1107 +            switch (wParam) {
  3.1108 +            case VK_CONTROL:
  3.1109 +                if (lParam & EXTENDED_KEYMASK)
  3.1110 +                    wParam = VK_RCONTROL;
  3.1111 +                else
  3.1112 +                    wParam = VK_LCONTROL;
  3.1113 +                break;
  3.1114 +            case VK_SHIFT:
  3.1115 +                /* EXTENDED trick doesn't work here */
  3.1116 +                {
  3.1117 +                    Uint8 *state = SDL_GetKeyboardState(NULL);
  3.1118 +                    if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
  3.1119 +                        && (GetKeyState(VK_LSHIFT) & 0x8000)) {
  3.1120 +                        wParam = VK_LSHIFT;
  3.1121 +                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
  3.1122 +                               && (GetKeyState(VK_RSHIFT) & 0x8000)) {
  3.1123 +                        wParam = VK_RSHIFT;
  3.1124 +                    } else {
  3.1125 +                        /* Probably a key repeat */
  3.1126 +                        return (0);
  3.1127 +                    }
  3.1128 +                }
  3.1129 +                break;
  3.1130 +            case VK_MENU:
  3.1131 +                if (lParam & EXTENDED_KEYMASK)
  3.1132 +                    wParam = VK_RMENU;
  3.1133 +                else
  3.1134 +                    wParam = VK_LMENU;
  3.1135 +                break;
  3.1136 +            case VK_RETURN:
  3.1137 +                if (lParam & EXTENDED_KEYMASK)
  3.1138 +                    wParam = VK_ENTER;
  3.1139 +                break;
  3.1140 +            }
  3.1141 +            if (wParam < 256) {
  3.1142 +                SDL_SendKeyboardKey(index, SDL_PRESSED,
  3.1143 +                                    data->videodata->key_layout[wParam]);
  3.1144 +            }
  3.1145 +        }
  3.1146 +        return (0);
  3.1147 +
  3.1148 +    case WM_SYSKEYUP:
  3.1149 +    case WM_KEYUP:
  3.1150 +        {
  3.1151 +            int index;
  3.1152 +
  3.1153 +            index = data->videodata->keyboard;
  3.1154 +            wParam = RemapVKEY(wParam, lParam);
  3.1155 +            switch (wParam) {
  3.1156 +            case VK_CONTROL:
  3.1157 +                if (lParam & EXTENDED_KEYMASK)
  3.1158 +                    wParam = VK_RCONTROL;
  3.1159 +                else
  3.1160 +                    wParam = VK_LCONTROL;
  3.1161 +                break;
  3.1162 +            case VK_SHIFT:
  3.1163 +                /* EXTENDED trick doesn't work here */
  3.1164 +                {
  3.1165 +                    Uint8 *state = SDL_GetKeyboardState(NULL);
  3.1166 +                    if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
  3.1167 +                        && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
  3.1168 +                        wParam = VK_LSHIFT;
  3.1169 +                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
  3.1170 +                               && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
  3.1171 +                        wParam = VK_RSHIFT;
  3.1172 +                    } else {
  3.1173 +                        /* Probably a key repeat */
  3.1174 +                        return (0);
  3.1175 +                    }
  3.1176 +                }
  3.1177 +                break;
  3.1178 +            case VK_MENU:
  3.1179 +                if (lParam & EXTENDED_KEYMASK)
  3.1180 +                    wParam = VK_RMENU;
  3.1181 +                else
  3.1182 +                    wParam = VK_LMENU;
  3.1183 +                break;
  3.1184 +            case VK_RETURN:
  3.1185 +                if (lParam & EXTENDED_KEYMASK)
  3.1186 +                    wParam = VK_ENTER;
  3.1187 +                break;
  3.1188 +            }
  3.1189 +            /* Windows only reports keyup for print screen */
  3.1190 +            if (wParam == VK_SNAPSHOT
  3.1191 +                && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
  3.1192 +                SDL_RELEASED) {
  3.1193 +                SDL_SendKeyboardKey(index, SDL_PRESSED,
  3.1194 +                                    data->videodata->key_layout[wParam]);
  3.1195 +            }
  3.1196 +            if (wParam < 256) {
  3.1197 +                SDL_SendKeyboardKey(index, SDL_RELEASED,
  3.1198 +                                    data->videodata->key_layout[wParam]);
  3.1199 +            }
  3.1200 +        }
  3.1201 +        return (0);
  3.1202 +
  3.1203 +    case WM_CHAR:
  3.1204 +        {
  3.1205 +            char text[4];
  3.1206 +
  3.1207 +            /* Convert to UTF-8 and send it on... */
  3.1208 +            if (wParam <= 0x7F) {
  3.1209 +                text[0] = (char) wParam;
  3.1210 +                text[1] = '\0';
  3.1211 +            } else if (wParam <= 0x7FF) {
  3.1212 +                text[0] = 0xC0 | (char) ((wParam >> 6) & 0x1F);
  3.1213 +                text[1] = 0x80 | (char) (wParam & 0x3F);
  3.1214 +                text[2] = '\0';
  3.1215 +            } else {
  3.1216 +                text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
  3.1217 +                text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
  3.1218 +                text[2] = 0x80 | (char) (wParam & 0x3F);
  3.1219 +                text[3] = '\0';
  3.1220 +            }
  3.1221 +            SDL_SendKeyboardText(data->videodata->keyboard, text);
  3.1222 +        }
  3.1223 +        return (0);
  3.1224 +
  3.1225 +    case WM_INPUTLANGCHANGE:
  3.1226 +        {
  3.1227 +            WIN_UpdateKeymap(data->videodata->keyboard);
  3.1228 +        }
  3.1229 +        return (1);
  3.1230 +
  3.1231 +    case WM_GETMINMAXINFO:
  3.1232 +        {
  3.1233 +            MINMAXINFO *info;
  3.1234 +            RECT size;
  3.1235 +            int x, y;
  3.1236 +            int w, h;
  3.1237 +            int style;
  3.1238 +
  3.1239 +            /* If we allow resizing, let the resize happen naturally */
  3.1240 +            if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_RESIZABLE) {
  3.1241 +                return (0);
  3.1242 +            }
  3.1243 +
  3.1244 +            /* Get the current position of our window */
  3.1245 +            GetWindowRect(hwnd, &size);
  3.1246 +            x = size.left;
  3.1247 +            y = size.top;
  3.1248 +
  3.1249 +            /* Calculate current size of our window */
  3.1250 +            SDL_GetWindowSize(data->windowID, &w, &h);
  3.1251 +            size.top = 0;
  3.1252 +            size.left = 0;
  3.1253 +            size.bottom = h;
  3.1254 +            size.right = w;
  3.1255 +
  3.1256 +            /* DJM - according to the docs for GetMenu(), the
  3.1257 +               return value is undefined if hwnd is a child window.
  3.1258 +               Aparently it's too difficult for MS to check
  3.1259 +               inside their function, so I have to do it here.
  3.1260 +             */
  3.1261 +            style = GetWindowLong(hwnd, GWL_STYLE);
  3.1262 +            AdjustWindowRect(&size,
  3.1263 +                             style,
  3.1264 +                             style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) !=
  3.1265 +                             NULL);
  3.1266 +
  3.1267 +            w = size.right - size.left;
  3.1268 +            h = size.bottom - size.top;
  3.1269 +
  3.1270 +            /* Fix our size to the current size */
  3.1271 +            info = (MINMAXINFO *) lParam;
  3.1272 +            info->ptMaxSize.x = w;
  3.1273 +            info->ptMaxSize.y = h;
  3.1274 +            info->ptMaxPosition.x = x;
  3.1275 +            info->ptMaxPosition.y = y;
  3.1276 +            info->ptMinTrackSize.x = w;
  3.1277 +            info->ptMinTrackSize.y = h;
  3.1278 +            info->ptMaxTrackSize.x = w;
  3.1279 +            info->ptMaxTrackSize.y = h;
  3.1280 +        }
  3.1281 +        return (0);
  3.1282 +
  3.1283 +    case WM_WINDOWPOSCHANGED:
  3.1284 +        {
  3.1285 +            RECT rect;
  3.1286 +            int x, y;
  3.1287 +            int w, h;
  3.1288 +            Uint32 window_flags;
  3.1289 +
  3.1290 +            GetClientRect(hwnd, &rect);
  3.1291 +            ClientToScreen(hwnd, (LPPOINT) & rect);
  3.1292 +            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
  3.1293 +
  3.1294 +            window_flags = SDL_GetWindowFlags(data->windowID);
  3.1295 +            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
  3.1296 +                (window_flags & SDL_WINDOW_INPUT_FOCUS)) {
  3.1297 +                ClipCursor(&rect);
  3.1298 +            }
  3.1299 +
  3.1300 +            x = rect.left;
  3.1301 +            y = rect.top;
  3.1302 +            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MOVED, x, y);
  3.1303 +
  3.1304 +            w = rect.right - rect.left;
  3.1305 +            h = rect.bottom - rect.top;
  3.1306 +            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESIZED, w,
  3.1307 +                                h);
  3.1308 +        }
  3.1309 +        break;
  3.1310 +
  3.1311 +    case WM_SETCURSOR:
  3.1312 +        {
  3.1313 +            /*
  3.1314 +               Uint16 hittest;
  3.1315 +
  3.1316 +               hittest = LOWORD(lParam);
  3.1317 +               if (hittest == HTCLIENT) {
  3.1318 +               SetCursor(SDL_hcursor);
  3.1319 +               return (TRUE);
  3.1320 +               }
  3.1321 +             */
  3.1322 +        }
  3.1323 +        break;
  3.1324 +
  3.1325 +        /* We are about to get palette focus! */
  3.1326 +    case WM_QUERYNEWPALETTE:
  3.1327 +        {
  3.1328 +            /*
  3.1329 +               WIN_RealizePalette(current_video);
  3.1330 +               return (TRUE);
  3.1331 +             */
  3.1332 +        }
  3.1333 +        break;
  3.1334 +
  3.1335 +        /* Another application changed the palette */
  3.1336 +    case WM_PALETTECHANGED:
  3.1337 +        {
  3.1338 +            /*
  3.1339 +               WIN_PaletteChanged(current_video, (HWND) wParam);
  3.1340 +             */
  3.1341 +        }
  3.1342 +        break;
  3.1343 +
  3.1344 +        /* We were occluded, refresh our display */
  3.1345 +    case WM_PAINT:
  3.1346 +        {
  3.1347 +            RECT rect;
  3.1348 +            if (GetUpdateRect(hwnd, &rect, FALSE)) {
  3.1349 +                ValidateRect(hwnd, &rect);
  3.1350 +                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
  3.1351 +                                    0, 0);
  3.1352 +            }
  3.1353 +        }
  3.1354 +        return (0);
  3.1355 +
  3.1356 +        /* We'll do our own drawing, prevent flicker */
  3.1357 +    case WM_ERASEBKGND:
  3.1358 +        {
  3.1359 +        }
  3.1360 +        return (1);
  3.1361 +
  3.1362 +    case WM_SYSCOMMAND:
  3.1363 +        {
  3.1364 +            /* Don't start the screensaver or blank the monitor in fullscreen apps */
  3.1365 +            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
  3.1366 +                (wParam & 0xFFF0) == SC_MONITORPOWER) {
  3.1367 +                if (SDL_GetWindowFlags(data->windowID) &
  3.1368 +                    SDL_WINDOW_FULLSCREEN) {
  3.1369 +                    return (0);
  3.1370 +                }
  3.1371 +            }
  3.1372 +        }
  3.1373 +        break;
  3.1374 +
  3.1375 +    case WM_CLOSE:
  3.1376 +        {
  3.1377 +            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0);
  3.1378 +        }
  3.1379 +        return (0);
  3.1380 +    }
  3.1381 +    return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
  3.1382 +}
  3.1383 +
  3.1384 +void
  3.1385 +WIN_PumpEvents(_THIS)
  3.1386 +{
  3.1387 +    MSG msg;
  3.1388 +
  3.1389 +    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  3.1390 +        TranslateMessage(&msg);
  3.1391 +        DispatchMessage(&msg);
  3.1392 +
  3.1393 +    }
  3.1394 +	/*while (GetMessage(&msg, NULL, 0, 0)) {
  3.1395 +        TranslateMessage(&msg);
  3.1396 +        DispatchMessage(&msg);
  3.1397 +    }*/
  3.1398 +	//WTClose(g_hCtx);
  3.1399 +}
  3.1400 +
  3.1401 +static int app_registered = 0;
  3.1402 +LPTSTR SDL_Appname = NULL;
  3.1403 +Uint32 SDL_Appstyle = 0;
  3.1404 +HINSTANCE SDL_Instance = NULL;
  3.1405 +
  3.1406 +/* Register the class for this application */
  3.1407 +int
  3.1408 +SDL_RegisterApp(char *name, Uint32 style, void *hInst)
  3.1409 +{
  3.1410 +    WNDCLASS class;
  3.1411 +
  3.1412 +    /* Only do this once... */
  3.1413 +    if (app_registered) {
  3.1414 +        ++app_registered;
  3.1415 +        return (0);
  3.1416 +    }
  3.1417 +    if (!name && !SDL_Appname) {
  3.1418 +        name = "SDL_app";
  3.1419 +        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
  3.1420 +        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
  3.1421 +    }
  3.1422 +
  3.1423 +    if (name) {
  3.1424 +        SDL_Appname = WIN_UTF8ToString(name);
  3.1425 +        SDL_Appstyle = style;
  3.1426 +        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
  3.1427 +    }
  3.1428 +
  3.1429 +    /* Register the application class */
  3.1430 +    class.hCursor = NULL;
  3.1431 +    class.hIcon = LoadImage(SDL_Instance, SDL_Appname,
  3.1432 +                            IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
  3.1433 +    class.lpszMenuName = NULL;
  3.1434 +    class.lpszClassName = SDL_Appname;
  3.1435 +    class.hbrBackground = NULL;
  3.1436 +    class.hInstance = SDL_Instance;
  3.1437 +    class.style = SDL_Appstyle;
  3.1438 +    class.lpfnWndProc = DefWindowProc;
  3.1439 +    class.cbWndExtra = 0;
  3.1440 +    class.cbClsExtra = 0;
  3.1441 +    if (!RegisterClass(&class)) {
  3.1442 +        SDL_SetError("Couldn't register application class");
  3.1443 +        return (-1);
  3.1444 +    }
  3.1445 +
  3.1446 +    app_registered = 1;
  3.1447 +    return (0);
  3.1448 +}
  3.1449 +
  3.1450 +/* Unregisters the windowclass registered in SDL_RegisterApp above. */
  3.1451 +void
  3.1452 +SDL_UnregisterApp()
  3.1453 +{
  3.1454 +    WNDCLASS class;
  3.1455 +
  3.1456 +    /* SDL_RegisterApp might not have been called before */
  3.1457 +    if (!app_registered) {
  3.1458 +        return;
  3.1459 +    }
  3.1460 +    --app_registered;
  3.1461 +    if (app_registered == 0) {
  3.1462 +        /* Check for any registered window classes. */
  3.1463 +        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
  3.1464 +            UnregisterClass(SDL_Appname, SDL_Instance);
  3.1465 +        }
  3.1466 +        SDL_free(SDL_Appname);
  3.1467 +        SDL_Appname = NULL;
  3.1468 +    }
  3.1469 +}
  3.1470 +
  3.1471 +/* Sets an error message based on GetLastError() */
  3.1472 +void
  3.1473 +WIN_SetError(const char *prefix)
  3.1474 +{
  3.1475 +    TCHAR buffer[1024];
  3.1476 +    char *message;
  3.1477 +
  3.1478 +    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  3.1479 +                  NULL,
  3.1480 +                  GetLastError(), 0, buffer, SDL_arraysize(buffer), NULL);
  3.1481 +
  3.1482 +    message = WIN_StringToUTF8(buffer);
  3.1483 +    SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ":" : "", message);
  3.1484 +    SDL_free(message);
  3.1485 +}
  3.1486 +
  3.1487 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/win32/SDL_win32keyboard.c	Sun Jul 06 09:24:56 2008 +0000
     4.2 +++ b/src/video/win32/SDL_win32keyboard.c	Wed Jul 23 16:12:43 2008 +0000
     4.3 @@ -54,20 +54,20 @@
     4.4  
     4.5      /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
     4.6      if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
     4.7 -        printf
     4.8 -            ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
     4.9 +        //printf
    4.10 +        //    ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    4.11          for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    4.12              alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
    4.13 -            printf("%d = %d\n", i, alpha_scancodes[i]);
    4.14 +       //     printf("%d = %d\n", i, alpha_scancodes[i]);
    4.15          }
    4.16      }
    4.17      if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    4.18 -        printf
    4.19 -            ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    4.20 +      //  printf
    4.21 +      //      ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    4.22          for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    4.23              keypad_scancodes[i] =
    4.24                  MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
    4.25 -            printf("%d = %d\n", i, keypad_scancodes[i]);
    4.26 +       //     printf("%d = %d\n", i, keypad_scancodes[i]);
    4.27          }
    4.28      }
    4.29  
     5.1 --- a/src/video/win32/SDL_win32video.c	Sun Jul 06 09:24:56 2008 +0000
     5.2 +++ b/src/video/win32/SDL_win32video.c	Wed Jul 23 16:12:43 2008 +0000
     5.3 @@ -31,10 +31,14 @@
     5.4  #include "SDL_d3drender.h"
     5.5  #include "SDL_gdirender.h"
     5.6  
     5.7 +#include <wintab.h>
     5.8 +
     5.9  /* Initialization/Query functions */
    5.10  static int WIN_VideoInit(_THIS);
    5.11  static void WIN_VideoQuit(_THIS);
    5.12  
    5.13 +HCTX* g_hCtx = NULL;
    5.14 +
    5.15  /* WIN32 driver bootstrap functions */
    5.16  
    5.17  static int
    5.18 @@ -157,6 +161,8 @@
    5.19      GDI_AddRenderDriver(_this);
    5.20  #endif
    5.21  
    5.22 +	g_hCtx = SDL_malloc(sizeof(HCTX));
    5.23 +
    5.24      WIN_InitKeyboard(_this);
    5.25      WIN_InitMouse(_this);
    5.26  
    5.27 @@ -169,6 +175,7 @@
    5.28      WIN_QuitModes(_this);
    5.29      WIN_QuitKeyboard(_this);
    5.30      WIN_QuitMouse(_this);
    5.31 +	SDL_free(g_hCtx);
    5.32  }
    5.33  
    5.34  /* vim: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/win32/SDL_win32window.c	Sun Jul 06 09:24:56 2008 +0000
     6.2 +++ b/src/video/win32/SDL_win32window.c	Wed Jul 23 16:12:43 2008 +0000
     6.3 @@ -1,412 +1,460 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2006 Sam Lantinga
     6.7 -
     6.8 -    This library is free software; you can redistribute it and/or
     6.9 -    modify it under the terms of the GNU Lesser General Public
    6.10 -    License as published by the Free Software Foundation; either
    6.11 -    version 2.1 of the License, or (at your option) any later version.
    6.12 -
    6.13 -    This library is distributed in the hope that it will be useful,
    6.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 -    Lesser General Public License for more details.
    6.17 -
    6.18 -    You should have received a copy of the GNU Lesser General Public
    6.19 -    License along with this library; if not, write to the Free Software
    6.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 -
    6.22 -    Sam Lantinga
    6.23 -    slouken@libsdl.org
    6.24 -*/
    6.25 -#include "SDL_config.h"
    6.26 -
    6.27 -#include "../SDL_sysvideo.h"
    6.28 -#include "../../events/SDL_keyboard_c.h"
    6.29 -
    6.30 -#include "SDL_win32video.h"
    6.31 -
    6.32 -/* This is included after SDL_win32video.h, which includes windows.h */
    6.33 -#include "SDL_syswm.h"
    6.34 -
    6.35 -
    6.36 -static int
    6.37 -SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
    6.38 -{
    6.39 -    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    6.40 -    SDL_WindowData *data;
    6.41 -
    6.42 -    /* Allocate the window data */
    6.43 -    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
    6.44 -    if (!data) {
    6.45 -        SDL_OutOfMemory();
    6.46 -        return -1;
    6.47 -    }
    6.48 -    data->windowID = window->id;
    6.49 -    data->hwnd = hwnd;
    6.50 -    data->hdc = GetDC(hwnd);
    6.51 -    data->created = created;
    6.52 -    data->mouse_pressed = SDL_FALSE;
    6.53 -    data->videodata = videodata;
    6.54 -
    6.55 -    /* Associate the data with the window */
    6.56 -    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
    6.57 -        ReleaseDC(hwnd, data->hdc);
    6.58 -        SDL_free(data);
    6.59 -        WIN_SetError("SetProp() failed");
    6.60 -        return -1;
    6.61 -    }
    6.62 -
    6.63 -    /* Set up the window proc function */
    6.64 -    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
    6.65 -    if (data->wndproc == NULL) {
    6.66 -        data->wndproc = DefWindowProc;
    6.67 -    } else {
    6.68 -        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
    6.69 -    }
    6.70 -
    6.71 -    /* Fill in the SDL window with the window data */
    6.72 -    {
    6.73 -        POINT point;
    6.74 -        point.x = 0;
    6.75 -        point.y = 0;
    6.76 -        if (ClientToScreen(hwnd, &point)) {
    6.77 -            window->x = point.x;
    6.78 -            window->y = point.y;
    6.79 -        }
    6.80 -    }
    6.81 -    {
    6.82 -        RECT rect;
    6.83 -        if (GetClientRect(hwnd, &rect)) {
    6.84 -            window->w = rect.right;
    6.85 -            window->h = rect.bottom;
    6.86 -        }
    6.87 -    }
    6.88 -    {
    6.89 -        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
    6.90 -        if (style & WS_VISIBLE) {
    6.91 -            window->flags |= SDL_WINDOW_SHOWN;
    6.92 -        } else {
    6.93 -            window->flags &= ~SDL_WINDOW_SHOWN;
    6.94 -        }
    6.95 -        if (style & (WS_BORDER | WS_THICKFRAME)) {
    6.96 -            window->flags &= ~SDL_WINDOW_BORDERLESS;
    6.97 -        } else {
    6.98 -            window->flags |= SDL_WINDOW_BORDERLESS;
    6.99 -        }
   6.100 -        if (style & WS_THICKFRAME) {
   6.101 -            window->flags |= SDL_WINDOW_RESIZABLE;
   6.102 -        } else {
   6.103 -            window->flags &= ~SDL_WINDOW_RESIZABLE;
   6.104 -        }
   6.105 -        if (style & WS_MAXIMIZE) {
   6.106 -            window->flags |= SDL_WINDOW_MAXIMIZED;
   6.107 -        } else {
   6.108 -            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   6.109 -        }
   6.110 -        if (style & WS_MINIMIZE) {
   6.111 -            window->flags |= SDL_WINDOW_MINIMIZED;
   6.112 -        } else {
   6.113 -            window->flags &= ~SDL_WINDOW_MINIMIZED;
   6.114 -        }
   6.115 -    }
   6.116 -    if (GetFocus() == hwnd) {
   6.117 -        int index = data->videodata->keyboard;
   6.118 -        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   6.119 -        SDL_SetKeyboardFocus(index, data->windowID);
   6.120 -
   6.121 -        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   6.122 -            RECT rect;
   6.123 -            GetClientRect(hwnd, &rect);
   6.124 -            ClientToScreen(hwnd, (LPPOINT) & rect);
   6.125 -            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   6.126 -            ClipCursor(&rect);
   6.127 -        }
   6.128 -    }
   6.129 -
   6.130 -    /* All done! */
   6.131 -    window->driverdata = data;
   6.132 -    return 0;
   6.133 -}
   6.134 -
   6.135 -int
   6.136 -WIN_CreateWindow(_THIS, SDL_Window * window)
   6.137 -{
   6.138 -    HWND hwnd;
   6.139 -    HWND top;
   6.140 -    RECT rect;
   6.141 -    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
   6.142 -    int x, y;
   6.143 -    int w, h;
   6.144 -
   6.145 -    if (window->flags & SDL_WINDOW_BORDERLESS) {
   6.146 -        style |= WS_POPUP;
   6.147 -    } else {
   6.148 -        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
   6.149 -    }
   6.150 -    if (window->flags & SDL_WINDOW_RESIZABLE) {
   6.151 -        style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
   6.152 -    }
   6.153 -
   6.154 -    /* Figure out what the window area will be */
   6.155 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.156 -        top = HWND_TOPMOST;
   6.157 -    } else {
   6.158 -        top = HWND_NOTOPMOST;
   6.159 -    }
   6.160 -    rect.left = 0;
   6.161 -    rect.top = 0;
   6.162 -    rect.right = window->w;
   6.163 -    rect.bottom = window->h;
   6.164 -    AdjustWindowRectEx(&rect, style, FALSE, 0);
   6.165 -    w = (rect.right - rect.left);
   6.166 -    h = (rect.bottom - rect.top);
   6.167 -
   6.168 -    if (window->x == SDL_WINDOWPOS_CENTERED) {
   6.169 -        x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
   6.170 -    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   6.171 -        x = CW_USEDEFAULT;
   6.172 -    } else {
   6.173 -        x = window->x + rect.left;
   6.174 -    }
   6.175 -    if (window->y == SDL_WINDOWPOS_CENTERED) {
   6.176 -        y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
   6.177 -    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   6.178 -        y = CW_USEDEFAULT;
   6.179 -    } else {
   6.180 -        y = window->y + rect.top;
   6.181 -    }
   6.182 -
   6.183 -    hwnd =
   6.184 -        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
   6.185 -                     SDL_Instance, NULL);
   6.186 -    WIN_PumpEvents(_this);
   6.187 -
   6.188 -    if (!hwnd) {
   6.189 -        WIN_SetError("Couldn't create window");
   6.190 -        return -1;
   6.191 -    }
   6.192 -
   6.193 -    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
   6.194 -        DestroyWindow(hwnd);
   6.195 -        return -1;
   6.196 -    }
   6.197 -#ifdef SDL_VIDEO_OPENGL_WGL
   6.198 -    if (window->flags & SDL_WINDOW_OPENGL) {
   6.199 -        if (WIN_GL_SetupWindow(_this, window) < 0) {
   6.200 -            WIN_DestroyWindow(_this, window);
   6.201 -            return -1;
   6.202 -        }
   6.203 -    }
   6.204 -#endif
   6.205 -    return 0;
   6.206 -}
   6.207 -
   6.208 -int
   6.209 -WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   6.210 -{
   6.211 -    HWND hwnd = (HWND) data;
   6.212 -    LPTSTR title;
   6.213 -    int titleLen;
   6.214 -
   6.215 -    /* Query the title from the existing window */
   6.216 -    titleLen = GetWindowTextLength(hwnd);
   6.217 -    title = SDL_stack_alloc(TCHAR, titleLen + 1);
   6.218 -    if (title) {
   6.219 -        titleLen = GetWindowText(hwnd, title, titleLen);
   6.220 -    } else {
   6.221 -        titleLen = 0;
   6.222 -    }
   6.223 -    if (titleLen > 0) {
   6.224 -        window->title = WIN_StringToUTF8(title);
   6.225 -    }
   6.226 -    if (title) {
   6.227 -        SDL_stack_free(title);
   6.228 -    }
   6.229 -
   6.230 -    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
   6.231 -        return -1;
   6.232 -    }
   6.233 -    return 0;
   6.234 -}
   6.235 -
   6.236 -void
   6.237 -WIN_SetWindowTitle(_THIS, SDL_Window * window)
   6.238 -{
   6.239 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.240 -    LPTSTR title;
   6.241 -
   6.242 -    if (window->title) {
   6.243 -        title = WIN_UTF8ToString(window->title);
   6.244 -    } else {
   6.245 -        title = NULL;
   6.246 -    }
   6.247 -    SetWindowText(hwnd, title ? title : TEXT(""));
   6.248 -    if (title) {
   6.249 -        SDL_free(title);
   6.250 -    }
   6.251 -}
   6.252 -
   6.253 -void
   6.254 -WIN_SetWindowPosition(_THIS, SDL_Window * window)
   6.255 -{
   6.256 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.257 -    RECT rect;
   6.258 -    DWORD style;
   6.259 -    HWND top;
   6.260 -    int x, y;
   6.261 -
   6.262 -    /* Figure out what the window area will be */
   6.263 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.264 -        top = HWND_TOPMOST;
   6.265 -    } else {
   6.266 -        top = HWND_NOTOPMOST;
   6.267 -    }
   6.268 -    style = GetWindowLong(hwnd, GWL_STYLE);
   6.269 -    rect.left = 0;
   6.270 -    rect.top = 0;
   6.271 -    rect.right = window->w;
   6.272 -    rect.bottom = window->h;
   6.273 -    AdjustWindowRectEx(&rect, style,
   6.274 -                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   6.275 -                                                           NULL), 0);
   6.276 -    x = window->x + rect.left;
   6.277 -    y = window->y + rect.top;
   6.278 -
   6.279 -    SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
   6.280 -}
   6.281 -
   6.282 -void
   6.283 -WIN_SetWindowSize(_THIS, SDL_Window * window)
   6.284 -{
   6.285 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.286 -    RECT rect;
   6.287 -    DWORD style;
   6.288 -    HWND top;
   6.289 -    int w, h;
   6.290 -
   6.291 -    /* Figure out what the window area will be */
   6.292 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.293 -        top = HWND_TOPMOST;
   6.294 -    } else {
   6.295 -        top = HWND_NOTOPMOST;
   6.296 -    }
   6.297 -    style = GetWindowLong(hwnd, GWL_STYLE);
   6.298 -    rect.left = 0;
   6.299 -    rect.top = 0;
   6.300 -    rect.right = window->w;
   6.301 -    rect.bottom = window->h;
   6.302 -    AdjustWindowRectEx(&rect, style,
   6.303 -                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   6.304 -                                                           NULL), 0);
   6.305 -    w = (rect.right - rect.left);
   6.306 -    h = (rect.bottom - rect.top);
   6.307 -
   6.308 -    SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE));
   6.309 -}
   6.310 -
   6.311 -void
   6.312 -WIN_ShowWindow(_THIS, SDL_Window * window)
   6.313 -{
   6.314 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.315 -
   6.316 -    ShowWindow(hwnd, SW_SHOW);
   6.317 -}
   6.318 -
   6.319 -void
   6.320 -WIN_HideWindow(_THIS, SDL_Window * window)
   6.321 -{
   6.322 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.323 -
   6.324 -    ShowWindow(hwnd, SW_HIDE);
   6.325 -}
   6.326 -
   6.327 -void
   6.328 -WIN_RaiseWindow(_THIS, SDL_Window * window)
   6.329 -{
   6.330 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.331 -    HWND top;
   6.332 -
   6.333 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.334 -        top = HWND_TOPMOST;
   6.335 -    } else {
   6.336 -        top = HWND_NOTOPMOST;
   6.337 -    }
   6.338 -    SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
   6.339 -}
   6.340 -
   6.341 -void
   6.342 -WIN_MaximizeWindow(_THIS, SDL_Window * window)
   6.343 -{
   6.344 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.345 -
   6.346 -    ShowWindow(hwnd, SW_MAXIMIZE);
   6.347 -}
   6.348 -
   6.349 -void
   6.350 -WIN_MinimizeWindow(_THIS, SDL_Window * window)
   6.351 -{
   6.352 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.353 -
   6.354 -    ShowWindow(hwnd, SW_MINIMIZE);
   6.355 -}
   6.356 -
   6.357 -void
   6.358 -WIN_RestoreWindow(_THIS, SDL_Window * window)
   6.359 -{
   6.360 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.361 -
   6.362 -    ShowWindow(hwnd, SW_RESTORE);
   6.363 -}
   6.364 -
   6.365 -void
   6.366 -WIN_SetWindowGrab(_THIS, SDL_Window * window)
   6.367 -{
   6.368 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.369 -
   6.370 -    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   6.371 -        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   6.372 -        RECT rect;
   6.373 -        GetClientRect(hwnd, &rect);
   6.374 -        ClientToScreen(hwnd, (LPPOINT) & rect);
   6.375 -        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   6.376 -        ClipCursor(&rect);
   6.377 -    } else {
   6.378 -        ClipCursor(NULL);
   6.379 -    }
   6.380 -}
   6.381 -
   6.382 -void
   6.383 -WIN_DestroyWindow(_THIS, SDL_Window * window)
   6.384 -{
   6.385 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   6.386 -
   6.387 -    if (data) {
   6.388 -#ifdef SDL_VIDEO_OPENGL_WGL
   6.389 -        if (window->flags & SDL_WINDOW_OPENGL) {
   6.390 -            WIN_GL_CleanupWindow(_this, window);
   6.391 -        }
   6.392 -#endif
   6.393 -        ReleaseDC(data->hwnd, data->hdc);
   6.394 -        if (data->created) {
   6.395 -            DestroyWindow(data->hwnd);
   6.396 -        }
   6.397 -        SDL_free(data);
   6.398 -    }
   6.399 -}
   6.400 -
   6.401 -SDL_bool
   6.402 -WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   6.403 -{
   6.404 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.405 -    if (info->version.major <= SDL_MAJOR_VERSION) {
   6.406 -        info->window = hwnd;
   6.407 -        return SDL_TRUE;
   6.408 -    } else {
   6.409 -        SDL_SetError("Application not compiled with SDL %d.%d\n",
   6.410 -                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   6.411 -        return SDL_FALSE;
   6.412 -    }
   6.413 -}
   6.414 -
   6.415 -/* vi: set ts=4 sw=4 expandtab: */
   6.416 +/*
   6.417 +    SDL - Simple DirectMedia Layer
   6.418 +    Copyright (C) 1997-2006 Sam Lantinga
   6.419 +
   6.420 +    This library is free software; you can redistribute it and/or
   6.421 +    modify it under the terms of the GNU Lesser General Public
   6.422 +    License as published by the Free Software Foundation; either
   6.423 +    version 2.1 of the License, or (at your option) any later version.
   6.424 +
   6.425 +    This library is distributed in the hope that it will be useful,
   6.426 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   6.427 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   6.428 +    Lesser General Public License for more details.
   6.429 +
   6.430 +    You should have received a copy of the GNU Lesser General Public
   6.431 +    License along with this library; if not, write to the Free Software
   6.432 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   6.433 +
   6.434 +    Sam Lantinga
   6.435 +    slouken@libsdl.org
   6.436 +*/
   6.437 +#include "SDL_config.h"
   6.438 +
   6.439 +#include "../SDL_sysvideo.h"
   6.440 +#include "../../events/SDL_keyboard_c.h"
   6.441 +
   6.442 +#include "SDL_win32video.h"
   6.443 +
   6.444 +/* This is included after SDL_win32video.h, which includes windows.h */
   6.445 +#include "SDL_syswm.h"
   6.446 +
   6.447 +#include <wintab.h>
   6.448 +#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
   6.449 +#define PACKETMODE 0
   6.450 +#include <pktdef.h>
   6.451 +
   6.452 +extern HCTX* g_hCtx;
   6.453 +
   6.454 +int highestId=0;
   6.455 +
   6.456 +static int
   6.457 +SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
   6.458 +{
   6.459 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
   6.460 +    SDL_WindowData *data;
   6.461 +
   6.462 +    /* Allocate the window data */
   6.463 +    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
   6.464 +    if (!data) {
   6.465 +        SDL_OutOfMemory();
   6.466 +        return -1;
   6.467 +    }
   6.468 +    data->windowID = window->id;
   6.469 +    data->hwnd = hwnd;
   6.470 +    data->hdc = GetDC(hwnd);
   6.471 +    data->created = created;
   6.472 +    data->mouse_pressed = SDL_FALSE;
   6.473 +    data->videodata = videodata;
   6.474 +
   6.475 +    /* Associate the data with the window */
   6.476 +    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
   6.477 +        ReleaseDC(hwnd, data->hdc);
   6.478 +        SDL_free(data);
   6.479 +        WIN_SetError("SetProp() failed");
   6.480 +        return -1;
   6.481 +    }
   6.482 +
   6.483 +    /* Set up the window proc function */
   6.484 +    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
   6.485 +    if (data->wndproc == NULL) {
   6.486 +        data->wndproc = DefWindowProc;
   6.487 +    } else {
   6.488 +        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
   6.489 +    }
   6.490 +
   6.491 +    /* Fill in the SDL window with the window data */
   6.492 +    {
   6.493 +        POINT point;
   6.494 +        point.x = 0;
   6.495 +        point.y = 0;
   6.496 +        if (ClientToScreen(hwnd, &point)) {
   6.497 +            window->x = point.x;
   6.498 +            window->y = point.y;
   6.499 +        }
   6.500 +    }
   6.501 +    {
   6.502 +        RECT rect;
   6.503 +        if (GetClientRect(hwnd, &rect)) {
   6.504 +            window->w = rect.right;
   6.505 +            window->h = rect.bottom;
   6.506 +        }
   6.507 +    }
   6.508 +    {
   6.509 +        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
   6.510 +        if (style & WS_VISIBLE) {
   6.511 +            window->flags |= SDL_WINDOW_SHOWN;
   6.512 +        } else {
   6.513 +            window->flags &= ~SDL_WINDOW_SHOWN;
   6.514 +        }
   6.515 +        if (style & (WS_BORDER | WS_THICKFRAME)) {
   6.516 +            window->flags &= ~SDL_WINDOW_BORDERLESS;
   6.517 +        } else {
   6.518 +            window->flags |= SDL_WINDOW_BORDERLESS;
   6.519 +        }
   6.520 +        if (style & WS_THICKFRAME) {
   6.521 +            window->flags |= SDL_WINDOW_RESIZABLE;
   6.522 +        } else {
   6.523 +            window->flags &= ~SDL_WINDOW_RESIZABLE;
   6.524 +        }
   6.525 +        if (style & WS_MAXIMIZE) {
   6.526 +            window->flags |= SDL_WINDOW_MAXIMIZED;
   6.527 +        } else {
   6.528 +            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   6.529 +        }
   6.530 +        if (style & WS_MINIMIZE) {
   6.531 +            window->flags |= SDL_WINDOW_MINIMIZED;
   6.532 +        } else {
   6.533 +            window->flags &= ~SDL_WINDOW_MINIMIZED;
   6.534 +        }
   6.535 +    }
   6.536 +    if (GetFocus() == hwnd) {
   6.537 +        int index = data->videodata->keyboard;
   6.538 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   6.539 +        SDL_SetKeyboardFocus(index, data->windowID);
   6.540 +
   6.541 +        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   6.542 +            RECT rect;
   6.543 +            GetClientRect(hwnd, &rect);
   6.544 +            ClientToScreen(hwnd, (LPPOINT) & rect);
   6.545 +            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   6.546 +            ClipCursor(&rect);
   6.547 +        }
   6.548 +    }
   6.549 +
   6.550 +    /* All done! */
   6.551 +    window->driverdata = data;
   6.552 +    return 0;
   6.553 +}
   6.554 +
   6.555 +int
   6.556 +WIN_CreateWindow(_THIS, SDL_Window * window)
   6.557 +{
   6.558 +	AXIS TabX,TabY;
   6.559 +	LOGCONTEXT lc;
   6.560 +    HWND hwnd;
   6.561 +    HWND top;
   6.562 +    RECT rect;
   6.563 +    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
   6.564 +    int x, y;
   6.565 +    int w, h;
   6.566 +
   6.567 +    if (window->flags & SDL_WINDOW_BORDERLESS) {
   6.568 +        style |= WS_POPUP;
   6.569 +    } else {
   6.570 +        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
   6.571 +    }
   6.572 +    if (window->flags & SDL_WINDOW_RESIZABLE) {
   6.573 +        style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
   6.574 +    }
   6.575 +
   6.576 +    /* Figure out what the window area will be */
   6.577 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.578 +        top = HWND_TOPMOST;
   6.579 +    } else {
   6.580 +        top = HWND_NOTOPMOST;
   6.581 +    }
   6.582 +    rect.left = 0;
   6.583 +    rect.top = 0;
   6.584 +    rect.right = window->w;
   6.585 +    rect.bottom = window->h;
   6.586 +    AdjustWindowRectEx(&rect, style, FALSE, 0);
   6.587 +    w = (rect.right - rect.left);
   6.588 +    h = (rect.bottom - rect.top);
   6.589 +
   6.590 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
   6.591 +        x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
   6.592 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   6.593 +        x = CW_USEDEFAULT;
   6.594 +    } else {
   6.595 +        x = window->x + rect.left;
   6.596 +    }
   6.597 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
   6.598 +        y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
   6.599 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   6.600 +        y = CW_USEDEFAULT;
   6.601 +    } else {
   6.602 +        y = window->y + rect.top;
   6.603 +    }	
   6.604 +
   6.605 +    hwnd =
   6.606 +        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
   6.607 +                     SDL_Instance, NULL);
   6.608 +	
   6.609 +	WTInfo(WTI_DEFCONTEXT, 0, &lc);
   6.610 +
   6.611 +	lc.lcPktData = PACKETDATA;
   6.612 +	lc.lcPktMode = PACKETMODE;
   6.613 +	lc.lcOptions |= CXO_MESSAGES;
   6.614 +	lc.lcMoveMask = PACKETDATA;
   6.615 +	lc.lcBtnDnMask=lc.lcBtnUpMask = PACKETDATA;
   6.616 +
   6.617 +	WTInfo(WTI_DEVICES,DVC_X,&TabX);
   6.618 +	WTInfo(WTI_DEVICES,DVC_Y,&TabY);
   6.619 +	
   6.620 +	lc.lcInOrgX = 0;
   6.621 +	lc.lcInOrgY = 0;
   6.622 +	
   6.623 +	lc.lcInExtX = TabX.axMax;
   6.624 +	lc.lcInExtY = TabY.axMax;
   6.625 +
   6.626 +	lc.lcOutOrgX = 0;
   6.627 +	lc.lcOutOrgY = 0;
   6.628 +
   6.629 +	lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
   6.630 +	lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
   6.631 +	if(window->id>highestId)
   6.632 +	{
   6.633 +		HCTX* tmp_hctx;
   6.634 +		highestId=window->id;
   6.635 +		tmp_hctx= (HCTX*)SDL_realloc(g_hCtx,(highestId+1)*sizeof(HCTX));
   6.636 +		if (!tmp_hctx) {
   6.637 +            SDL_OutOfMemory();
   6.638 +            return -1;
   6.639 +        }
   6.640 +		g_hCtx=tmp_hctx;
   6.641 +	}
   6.642 +
   6.643 +	g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
   6.644 +    WIN_PumpEvents(_this);
   6.645 +
   6.646 +    if (!hwnd) {
   6.647 +        WIN_SetError("Couldn't create window");
   6.648 +        return -1;
   6.649 +    }
   6.650 +
   6.651 +    if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
   6.652 +        DestroyWindow(hwnd);
   6.653 +        return -1;
   6.654 +    }
   6.655 +#ifdef SDL_VIDEO_OPENGL_WGL
   6.656 +    if (window->flags & SDL_WINDOW_OPENGL) {
   6.657 +        if (WIN_GL_SetupWindow(_this, window) < 0) {
   6.658 +            WIN_DestroyWindow(_this, window);
   6.659 +            return -1;
   6.660 +        }
   6.661 +    }
   6.662 +#endif
   6.663 +    return 0;
   6.664 +}
   6.665 +
   6.666 +int
   6.667 +WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   6.668 +{
   6.669 +    HWND hwnd = (HWND) data;
   6.670 +    LPTSTR title;
   6.671 +    int titleLen;
   6.672 +
   6.673 +    /* Query the title from the existing window */
   6.674 +    titleLen = GetWindowTextLength(hwnd);
   6.675 +    title = SDL_stack_alloc(TCHAR, titleLen + 1);
   6.676 +    if (title) {
   6.677 +        titleLen = GetWindowText(hwnd, title, titleLen);
   6.678 +    } else {
   6.679 +        titleLen = 0;
   6.680 +    }
   6.681 +    if (titleLen > 0) {
   6.682 +        window->title = WIN_StringToUTF8(title);
   6.683 +    }
   6.684 +    if (title) {
   6.685 +        SDL_stack_free(title);
   6.686 +    }
   6.687 +
   6.688 +    if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
   6.689 +        return -1;
   6.690 +    }
   6.691 +    return 0;
   6.692 +}
   6.693 +
   6.694 +void
   6.695 +WIN_SetWindowTitle(_THIS, SDL_Window * window)
   6.696 +{
   6.697 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.698 +    LPTSTR title;
   6.699 +
   6.700 +    if (window->title) {
   6.701 +        title = WIN_UTF8ToString(window->title);
   6.702 +    } else {
   6.703 +        title = NULL;
   6.704 +    }
   6.705 +    SetWindowText(hwnd, title ? title : TEXT(""));
   6.706 +    if (title) {
   6.707 +        SDL_free(title);
   6.708 +    }
   6.709 +}
   6.710 +
   6.711 +void
   6.712 +WIN_SetWindowPosition(_THIS, SDL_Window * window)
   6.713 +{
   6.714 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.715 +    RECT rect;
   6.716 +    DWORD style;
   6.717 +    HWND top;
   6.718 +    int x, y;
   6.719 +
   6.720 +    /* Figure out what the window area will be */
   6.721 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.722 +        top = HWND_TOPMOST;
   6.723 +    } else {
   6.724 +        top = HWND_NOTOPMOST;
   6.725 +    }
   6.726 +    style = GetWindowLong(hwnd, GWL_STYLE);
   6.727 +    rect.left = 0;
   6.728 +    rect.top = 0;
   6.729 +    rect.right = window->w;
   6.730 +    rect.bottom = window->h;
   6.731 +    AdjustWindowRectEx(&rect, style,
   6.732 +                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   6.733 +                                                           NULL), 0);
   6.734 +    x = window->x + rect.left;
   6.735 +    y = window->y + rect.top;
   6.736 +
   6.737 +    SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
   6.738 +}
   6.739 +
   6.740 +void
   6.741 +WIN_SetWindowSize(_THIS, SDL_Window * window)
   6.742 +{
   6.743 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.744 +    RECT rect;
   6.745 +    DWORD style;
   6.746 +    HWND top;
   6.747 +    int w, h;
   6.748 +
   6.749 +    /* Figure out what the window area will be */
   6.750 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.751 +        top = HWND_TOPMOST;
   6.752 +    } else {
   6.753 +        top = HWND_NOTOPMOST;
   6.754 +    }
   6.755 +    style = GetWindowLong(hwnd, GWL_STYLE);
   6.756 +    rect.left = 0;
   6.757 +    rect.top = 0;
   6.758 +    rect.right = window->w;
   6.759 +    rect.bottom = window->h;
   6.760 +    AdjustWindowRectEx(&rect, style,
   6.761 +                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   6.762 +                                                           NULL), 0);
   6.763 +    w = (rect.right - rect.left);
   6.764 +    h = (rect.bottom - rect.top);
   6.765 +
   6.766 +    SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE));
   6.767 +}
   6.768 +
   6.769 +void
   6.770 +WIN_ShowWindow(_THIS, SDL_Window * window)
   6.771 +{
   6.772 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.773 +
   6.774 +    ShowWindow(hwnd, SW_SHOW);
   6.775 +}
   6.776 +
   6.777 +void
   6.778 +WIN_HideWindow(_THIS, SDL_Window * window)
   6.779 +{
   6.780 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.781 +
   6.782 +    ShowWindow(hwnd, SW_HIDE);
   6.783 +}
   6.784 +
   6.785 +void
   6.786 +WIN_RaiseWindow(_THIS, SDL_Window * window)
   6.787 +{
   6.788 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.789 +    HWND top;
   6.790 +
   6.791 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   6.792 +        top = HWND_TOPMOST;
   6.793 +    } else {
   6.794 +        top = HWND_NOTOPMOST;
   6.795 +    }
   6.796 +    SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
   6.797 +}
   6.798 +
   6.799 +void
   6.800 +WIN_MaximizeWindow(_THIS, SDL_Window * window)
   6.801 +{
   6.802 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.803 +
   6.804 +    ShowWindow(hwnd, SW_MAXIMIZE);
   6.805 +}
   6.806 +
   6.807 +void
   6.808 +WIN_MinimizeWindow(_THIS, SDL_Window * window)
   6.809 +{
   6.810 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.811 +
   6.812 +    ShowWindow(hwnd, SW_MINIMIZE);
   6.813 +}
   6.814 +
   6.815 +void
   6.816 +WIN_RestoreWindow(_THIS, SDL_Window * window)
   6.817 +{
   6.818 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.819 +
   6.820 +    ShowWindow(hwnd, SW_RESTORE);
   6.821 +}
   6.822 +
   6.823 +void
   6.824 +WIN_SetWindowGrab(_THIS, SDL_Window * window)
   6.825 +{
   6.826 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.827 +
   6.828 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   6.829 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   6.830 +        RECT rect;
   6.831 +        GetClientRect(hwnd, &rect);
   6.832 +        ClientToScreen(hwnd, (LPPOINT) & rect);
   6.833 +        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   6.834 +        ClipCursor(&rect);
   6.835 +    } else {
   6.836 +        ClipCursor(NULL);
   6.837 +    }
   6.838 +}
   6.839 +
   6.840 +void
   6.841 +WIN_DestroyWindow(_THIS, SDL_Window * window)
   6.842 +{
   6.843 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   6.844 +
   6.845 +    if (data) {
   6.846 +#ifdef SDL_VIDEO_OPENGL_WGL
   6.847 +        if (window->flags & SDL_WINDOW_OPENGL) {
   6.848 +            WIN_GL_CleanupWindow(_this, window);
   6.849 +        }
   6.850 +#endif
   6.851 +        ReleaseDC(data->hwnd, data->hdc);
   6.852 +        if (data->created) {
   6.853 +			WTClose(g_hCtx[window->id]);
   6.854 +            DestroyWindow(data->hwnd);
   6.855 +        }
   6.856 +        SDL_free(data);
   6.857 +		WTClose(g_hCtx[window->id]);
   6.858 +    }
   6.859 +}
   6.860 +
   6.861 +SDL_bool
   6.862 +WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   6.863 +{
   6.864 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   6.865 +    if (info->version.major <= SDL_MAJOR_VERSION) {
   6.866 +        info->window = hwnd;
   6.867 +        return SDL_TRUE;
   6.868 +    } else {
   6.869 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
   6.870 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   6.871 +        return SDL_FALSE;
   6.872 +    }
   6.873 +}
   6.874 +
   6.875 +/* vi: set ts=4 sw=4 expandtab: */