Fixed bug #905
authorSam Lantinga <slouken@libsdl.org>
Tue, 15 Dec 2009 09:20:10 +0000
changeset 356607c8339c95c6
parent 3565 f43c8f688f77
child 3567 fb9ea4b549c3
Fixed bug #905

Give the foreign window message proc more control over Windows events.

This may need to be adjusted when we add the capability for the app to specify whether it wants SDL to handle input for the window or not.
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32window.c
     1.1 --- a/src/video/win32/SDL_win32events.c	Tue Dec 15 08:11:06 2009 +0000
     1.2 +++ b/src/video/win32/SDL_win32events.c	Tue Dec 15 09:20:10 2009 +0000
     1.3 @@ -101,6 +101,7 @@
     1.4      SDL_WindowData *data;
     1.5      RAWINPUT *raw;
     1.6      PACKET packet;
     1.7 +    LRESULT returnCode = -1;
     1.8  
     1.9      /* Send a SDL_SYSWMEVENT if the application wants them */
    1.10      if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
    1.11 @@ -211,7 +212,8 @@
    1.12                  }
    1.13              }
    1.14          }
    1.15 -        return (0);
    1.16 +        returnCode = 0;
    1.17 +        break;
    1.18  
    1.19  /* WinCE has no RawInput, so we use the classic mouse events.
    1.20     In classic Win32 this is done by WM_INPUT
    1.21 @@ -263,7 +265,8 @@
    1.22              }
    1.23              if (index < 0) {
    1.24                  /* New mouse?  Should we dynamically update mouse list? */
    1.25 -                return (0);
    1.26 +                returnCode = 0;
    1.27 +                break;
    1.28              }
    1.29  
    1.30              GetCursorPos(&point);
    1.31 @@ -316,7 +319,8 @@
    1.32              }
    1.33              SDL_stack_free(lpb);
    1.34          }
    1.35 -        return (0);
    1.36 +        returnCode = 0;
    1.37 +        break;
    1.38  #endif /* _WIN32_WCE */
    1.39  
    1.40      case WM_MOUSELEAVE:
    1.41 @@ -331,7 +335,8 @@
    1.42                  }
    1.43              }
    1.44          }
    1.45 -        return (0);
    1.46 +        returnCode = 0;
    1.47 +        break;
    1.48  
    1.49      case WM_SYSKEYDOWN:
    1.50      case WM_KEYDOWN:
    1.51 @@ -340,7 +345,8 @@
    1.52  
    1.53              /* Ignore repeated keys */
    1.54              if (lParam & REPEATED_KEYMASK) {
    1.55 -                return (0);
    1.56 +                returnCode = 0;
    1.57 +                break;
    1.58              }
    1.59  
    1.60              index = data->videodata->keyboard;
    1.61 @@ -364,7 +370,7 @@
    1.62                          wParam = VK_RSHIFT;
    1.63                      } else {
    1.64                          /* Probably a key repeat */
    1.65 -                        return (0);
    1.66 +                        wParam = 256;
    1.67                      }
    1.68                  }
    1.69                  break;
    1.70 @@ -384,7 +390,8 @@
    1.71                                      data->videodata->key_layout[wParam]);
    1.72              }
    1.73          }
    1.74 -        return (0);
    1.75 +        returnCode = 0;
    1.76 +        break;
    1.77  
    1.78      case WM_SYSKEYUP:
    1.79      case WM_KEYUP:
    1.80 @@ -412,7 +419,7 @@
    1.81                          wParam = VK_RSHIFT;
    1.82                      } else {
    1.83                          /* Probably a key repeat */
    1.84 -                        return (0);
    1.85 +                        wParam = 256;
    1.86                      }
    1.87                  }
    1.88                  break;
    1.89 @@ -440,7 +447,8 @@
    1.90                                      data->videodata->key_layout[wParam]);
    1.91              }
    1.92          }
    1.93 -        return (0);
    1.94 +        returnCode = 0;
    1.95 +        break;
    1.96  
    1.97      case WM_CHAR:
    1.98          {
    1.99 @@ -462,13 +470,15 @@
   1.100              }
   1.101              SDL_SendKeyboardText(data->videodata->keyboard, text);
   1.102          }
   1.103 -        return (0);
   1.104 +        returnCode = 0;
   1.105 +        break;
   1.106  
   1.107      case WM_INPUTLANGCHANGE:
   1.108          {
   1.109              WIN_UpdateKeymap(data->videodata->keyboard);
   1.110          }
   1.111 -        return (1);
   1.112 +        returnCode = 1;
   1.113 +        break;
   1.114  
   1.115      case WM_GETMINMAXINFO:
   1.116          {
   1.117 @@ -481,7 +491,8 @@
   1.118  
   1.119              /* If we allow resizing, let the resize happen naturally */
   1.120              if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_RESIZABLE) {
   1.121 -                return (0);
   1.122 +                returnCode = 0;
   1.123 +                break;
   1.124              }
   1.125  
   1.126              /* Get the current position of our window */
   1.127 @@ -523,7 +534,8 @@
   1.128              info->ptMaxTrackSize.x = w;
   1.129              info->ptMaxTrackSize.y = h;
   1.130          }
   1.131 -        return (0);
   1.132 +        returnCode = 0;
   1.133 +        break;
   1.134  
   1.135      case WM_WINDOWPOSCHANGED:
   1.136          {
   1.137 @@ -568,7 +580,7 @@
   1.138                      cursor = LoadCursor(NULL, IDC_ARROW);
   1.139                  }
   1.140                  SetCursor(cursor);
   1.141 -                return (TRUE);
   1.142 +                returnCode = TRUE;
   1.143              }
   1.144          }
   1.145          break;
   1.146 @@ -577,8 +589,8 @@
   1.147      case WM_QUERYNEWPALETTE:
   1.148          {
   1.149              /*
   1.150 -               WIN_RealizePalette(current_video);
   1.151 -               return (TRUE);
   1.152 +                WIN_RealizePalette(current_video);
   1.153 +                returnCode = TRUE;
   1.154               */
   1.155          }
   1.156          break;
   1.157 @@ -602,18 +614,8 @@
   1.158                                      0, 0);
   1.159              }
   1.160          }
   1.161 -        return (0);
   1.162 -
   1.163 -        /* If this isn't our window, we don't need to repaint the frame.
   1.164 -           This fixes a reentrancy issue that can cause stack overflows with foreign windows.
   1.165 -           3/21/09 Mason Wheeler */
   1.166 -    case WM_NCPAINT:
   1.167 -        {
   1.168 -            if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_FOREIGN) {
   1.169 -                return (0);
   1.170 -            }
   1.171 -            break;
   1.172 -        }
   1.173 +        returnCode = 0;
   1.174 +        break;
   1.175  
   1.176          /* We'll do our own drawing, prevent flicker */
   1.177      case WM_ERASEBKGND:
   1.178 @@ -637,9 +639,18 @@
   1.179          {
   1.180              SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0);
   1.181          }
   1.182 -        return (0);
   1.183 +        returnCode = 0;
   1.184 +        break;
   1.185      }
   1.186 -    return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
   1.187 +
   1.188 +    /* If there's a window proc, assume it's going to handle messages */
   1.189 +    if (data->wndproc) {
   1.190 +        return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
   1.191 +    } else if (returnCode >= 0) {
   1.192 +        return returnCode;
   1.193 +    } else {
   1.194 +        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
   1.195 +    }
   1.196  }
   1.197  
   1.198  void
     2.1 --- a/src/video/win32/SDL_win32window.c	Tue Dec 15 08:11:06 2009 +0000
     2.2 +++ b/src/video/win32/SDL_win32window.c	Tue Dec 15 09:20:10 2009 +0000
     2.3 @@ -112,11 +112,10 @@
     2.4  
     2.5      /* Set up the window proc function */
     2.6      data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
     2.7 -    if (data->wndproc == NULL) {
     2.8 -        data->wndproc = DefWindowProc;
     2.9 -    } else {
    2.10 -        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
    2.11 +    if (data->wndproc == DefWindowProc) {
    2.12 +        data->wndproc = NULL;
    2.13      }
    2.14 +    SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
    2.15  
    2.16      /* Fill in the SDL window with the window data */
    2.17      {