Added a userdata parameter for event filters. SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Jun 2006 08:18:44 +0000
branchSDL-1.3
changeset 17225daa04d862f1
parent 1721 1cc762cafff8
child 1723 4bdbb9b2bd0a
Added a userdata parameter for event filters.
Added a function to filter the existing queued events.
Added explicit support for relative mouse mode to the API.
include/SDL_events.h
include/SDL_mouse.h
include/SDL_video.h
src/SDL_compat.c
src/audio/SDL_mixer_MMX_VC.c
src/events/SDL_events.c
src/events/SDL_events_c.h
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/events/SDL_quit.c
src/events/SDL_windowevents.c
src/joystick/SDL_joystick.c
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32video.h
src/video/win32/SDL_win32window.c
src/video/win32/SDL_win32window.h
     1.1 --- a/include/SDL_events.h	Fri Jun 30 05:50:35 2006 +0000
     1.2 +++ b/include/SDL_events.h	Fri Jun 30 08:18:44 2006 +0000
     1.3 @@ -377,7 +377,7 @@
     1.4  
     1.5    The filter is protypted as:
     1.6  */
     1.7 -typedef int (SDLCALL * SDL_EventFilter) (SDL_Event * event);
     1.8 +typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
     1.9  /*
    1.10    If the filter returns 1, then the event will be added to the internal queue.
    1.11    If it returns 0, then the event will be dropped from the queue, but the 
    1.12 @@ -394,13 +394,21 @@
    1.13    If the quit event is generated by an interrupt signal, it will bypass the
    1.14    internal queue and be delivered to the application at the next event poll.
    1.15  */
    1.16 -extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter);
    1.17 +extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
    1.18 +                                                void *userdata);
    1.19  
    1.20  /*
    1.21    Return the current event filter - can be used to "chain" filters.
    1.22    If there is no event filter set, this function returns NULL.
    1.23  */
    1.24 -extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void);
    1.25 +extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void **userdata);
    1.26 +
    1.27 +/*
    1.28 +  Run the filter function on the current event queue, removing any
    1.29 +  events for which the filter returns 0.
    1.30 +*/
    1.31 +extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
    1.32 +                                              void *userdata);
    1.33  
    1.34  /*
    1.35    This function allows you to set the state of processing certain events.
     2.1 --- a/include/SDL_mouse.h	Fri Jun 30 05:50:35 2006 +0000
     2.2 +++ b/include/SDL_mouse.h	Fri Jun 30 08:18:44 2006 +0000
     2.3 @@ -75,9 +75,38 @@
     2.4  extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(void);
     2.5  
     2.6  /**
     2.7 + * \fn int SDL_SetRelativeMouseMode(SDL_bool enabled)
     2.8 + *
     2.9 + * \brief Set relative mouse mode for the currently selected mouse.
    2.10 + *
    2.11 + * \param enabled Whether or not to enable relative mode
    2.12 + *
    2.13 + * \return 0 on success, or -1 if relative mode is not supported.
    2.14 + *
    2.15 + * While the mouse is in relative mode, the cursor is hidden, and the
    2.16 + * driver will try to report continuous motion in the current window.
    2.17 + * Only relative motion events will be delivered, the mouse position
    2.18 + * will not change.
    2.19 + *
    2.20 + * \note This function will flush any pending mouse motion.
    2.21 + *
    2.22 + * \sa SDL_GetRelativeMouseMode()
    2.23 + */
    2.24 +extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
    2.25 +
    2.26 +/**
    2.27 + * \fn SDL_bool SDL_GetRelativeMouseMode()
    2.28 + *
    2.29 + * \brief Query whether relative mouse mode is enabled for the currently selected mouse.
    2.30 + *
    2.31 + * \sa SDL_SetRelativeMouseMode()
    2.32 + */
    2.33 +extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode();
    2.34 +
    2.35 +/**
    2.36   * \fn Uint8 SDL_GetMouseState(int *x, int *y)
    2.37   *
    2.38 - * \brief Retrieve the current state of the mouse.
    2.39 + * \brief Retrieve the current state of the currently selected mouse.
    2.40   *
    2.41   * The current button state is returned as a button bitmask, which can
    2.42   * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    2.43 @@ -89,7 +118,7 @@
    2.44  /**
    2.45   * \fn Uint8 SDL_GetRelativeMouseState(int *x, int *y)
    2.46   *
    2.47 - * \brief Retrieve the current state of the mouse.
    2.48 + * \brief Retrieve the state of the currently selected mouse.
    2.49   *
    2.50   * The current button state is returned as a button bitmask, which can
    2.51   * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
     3.1 --- a/include/SDL_video.h	Fri Jun 30 05:50:35 2006 +0000
     3.2 +++ b/include/SDL_video.h	Fri Jun 30 08:18:44 2006 +0000
     3.3 @@ -120,8 +120,8 @@
     3.4      SDL_WINDOW_SHOWN = 0x00000004,              /**< window is visible */
     3.5      SDL_WINDOW_BORDERLESS = 0x00000008,         /**< no window decoration */
     3.6      SDL_WINDOW_RESIZABLE = 0x00000010,          /**< window can be resized */
     3.7 -    SDL_WINDOW_MAXIMIZED = 0x00000020,          /**< maximized */
     3.8 -    SDL_WINDOW_MINIMIZED = 0x00000040,          /**< minimized */
     3.9 +    SDL_WINDOW_MINIMIZED = 0x00000020,          /**< minimized */
    3.10 +    SDL_WINDOW_MAXIMIZED = 0x00000040,          /**< maximized */
    3.11      SDL_WINDOW_INPUT_GRABBED = 0x00000100,      /**< window has grabbed input focus */
    3.12      SDL_WINDOW_KEYBOARD_FOCUS = 0x00000200,     /**< window has keyboard focus */
    3.13      SDL_WINDOW_MOUSE_FOCUS = 0x00000400,        /**< window has mouse focus */
     4.1 --- a/src/SDL_compat.c	Fri Jun 30 05:50:35 2006 +0000
     4.2 +++ b/src/SDL_compat.c	Fri Jun 30 08:18:44 2006 +0000
     4.3 @@ -153,10 +153,11 @@
     4.4      return modes;
     4.5  }
     4.6  
     4.7 -static int (*orig_eventfilter) (SDL_Event * event);
     4.8 +static SDL_EventFilter orig_eventfilter;
     4.9 +static void *orig_eventfilterparam;
    4.10  
    4.11  static int
    4.12 -SDL_CompatEventFilter(SDL_Event * event)
    4.13 +SDL_CompatEventFilter(void *userdata, SDL_Event * event)
    4.14  {
    4.15      SDL_Event fake;
    4.16  
    4.17 @@ -227,7 +228,7 @@
    4.18          }
    4.19      }
    4.20      if (orig_eventfilter) {
    4.21 -        return orig_eventfilter(event);
    4.22 +        return orig_eventfilter(orig_eventfilterparam, event);
    4.23      } else {
    4.24          return 1;
    4.25      }
    4.26 @@ -251,7 +252,8 @@
    4.27  SDL_Surface *
    4.28  SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
    4.29  {
    4.30 -    int (*filter) (SDL_Event * event);
    4.31 +    SDL_EventFilter filter;
    4.32 +    void *filterparam;
    4.33      const SDL_DisplayMode *desktop_mode;
    4.34      SDL_DisplayMode mode;
    4.35      Uint32 window_flags;
    4.36 @@ -280,11 +282,12 @@
    4.37      SDL_DestroyWindow(SDL_VideoWindow);
    4.38  
    4.39      /* Set up the event filter */
    4.40 -    filter = SDL_GetEventFilter();
    4.41 +    filter = SDL_GetEventFilter(&filterparam);
    4.42      if (filter != SDL_CompatEventFilter) {
    4.43          orig_eventfilter = filter;
    4.44 +        orig_eventfilterparam = filterparam;
    4.45      }
    4.46 -    SDL_SetEventFilter(SDL_CompatEventFilter);
    4.47 +    SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
    4.48  
    4.49      /* Create a new window */
    4.50      window_flags = SDL_WINDOW_SHOWN;
     5.1 --- a/src/audio/SDL_mixer_MMX_VC.c	Fri Jun 30 05:50:35 2006 +0000
     5.2 +++ b/src/audio/SDL_mixer_MMX_VC.c	Fri Jun 30 08:18:44 2006 +0000
     5.3 @@ -184,3 +184,5 @@
     5.4  }
     5.5  
     5.6  #endif /* SDL_ASSEMBLY_ROUTINES */
     5.7 +
     5.8 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/events/SDL_events.c	Fri Jun 30 05:50:35 2006 +0000
     6.2 +++ b/src/events/SDL_events.c	Fri Jun 30 08:18:44 2006 +0000
     6.3 @@ -34,6 +34,7 @@
     6.4  
     6.5  /* Public data -- the event filter */
     6.6  SDL_EventFilter SDL_EventOK = NULL;
     6.7 +void *SDL_EventOKParam;
     6.8  Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
     6.9  static Uint32 SDL_eventstate = 0;
    6.10  
    6.11 @@ -434,21 +435,43 @@
    6.12  }
    6.13  
    6.14  void
    6.15 -SDL_SetEventFilter(SDL_EventFilter filter)
    6.16 +SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
    6.17  {
    6.18      SDL_Event bitbucket;
    6.19  
    6.20      /* Set filter and discard pending events */
    6.21      SDL_EventOK = filter;
    6.22 +    SDL_EventOKParam = userdata;
    6.23      while (SDL_PollEvent(&bitbucket) > 0);
    6.24  }
    6.25  
    6.26  SDL_EventFilter
    6.27 -SDL_GetEventFilter(void)
    6.28 +SDL_GetEventFilter(void **userdata)
    6.29  {
    6.30 +    if (userdata) {
    6.31 +        *userdata = SDL_EventOKParam;
    6.32 +    }
    6.33      return (SDL_EventOK);
    6.34  }
    6.35  
    6.36 +void
    6.37 +SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
    6.38 +{
    6.39 +    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
    6.40 +        int spot;
    6.41 +
    6.42 +        spot = SDL_EventQ.head;
    6.43 +        while (spot != SDL_EventQ.tail) {
    6.44 +            if (filter(userdata, &SDL_EventQ.event[spot])) {
    6.45 +                spot = (spot + 1) % MAXEVENTS;
    6.46 +            } else {
    6.47 +                spot = SDL_CutEvent(spot);
    6.48 +            }
    6.49 +        }
    6.50 +    }
    6.51 +    SDL_mutexV(SDL_EventQ.lock);
    6.52 +}
    6.53 +
    6.54  Uint8
    6.55  SDL_EventState(Uint8 type, int state)
    6.56  {
    6.57 @@ -507,7 +530,8 @@
    6.58          SDL_memset(&event, 0, sizeof(event));
    6.59          event.type = SDL_SYSWMEVENT;
    6.60          event.syswm.msg = message;
    6.61 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
    6.62 +        if ((SDL_EventOK == NULL)
    6.63 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    6.64              posted = 1;
    6.65              SDL_PushEvent(&event);
    6.66          }
     7.1 --- a/src/events/SDL_events_c.h	Fri Jun 30 05:50:35 2006 +0000
     7.2 +++ b/src/events/SDL_events_c.h	Fri Jun 30 08:18:44 2006 +0000
     7.3 @@ -41,6 +41,7 @@
     7.4  
     7.5  /* The event filter function */
     7.6  extern SDL_EventFilter SDL_EventOK;
     7.7 +extern void *SDL_EventOKParam;
     7.8  
     7.9  /* The array of event processing states */
    7.10  extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
     8.1 --- a/src/events/SDL_keyboard.c	Fri Jun 30 05:50:35 2006 +0000
     8.2 +++ b/src/events/SDL_keyboard.c	Fri Jun 30 08:18:44 2006 +0000
     8.3 @@ -632,7 +632,7 @@
     8.4              keyboard->repeat.firsttime = 1;
     8.5              keyboard->repeat.timestamp = 1;
     8.6          }
     8.7 -        if ((SDL_EventOK == NULL) || SDL_EventOK(&event)) {
     8.8 +        if ((SDL_EventOK == NULL) || SDL_EventOK(SDL_EventOKParam, &event)) {
     8.9              posted = 1;
    8.10              SDL_PushEvent(&event);
    8.11          }
    8.12 @@ -669,7 +669,8 @@
    8.13                  if (interval > (Uint32) keyboard->repeat.interval) {
    8.14                      keyboard->repeat.timestamp = now;
    8.15                      if ((SDL_EventOK == NULL)
    8.16 -                        || SDL_EventOK(&keyboard->repeat.evt)) {
    8.17 +                        || SDL_EventOK(SDL_EventOKParam,
    8.18 +                                       &keyboard->repeat.evt)) {
    8.19                          SDL_PushEvent(&keyboard->repeat.evt);
    8.20                      }
    8.21                  }
     9.1 --- a/src/events/SDL_mouse.c	Fri Jun 30 05:50:35 2006 +0000
     9.2 +++ b/src/events/SDL_mouse.c	Fri Jun 30 08:18:44 2006 +0000
     9.3 @@ -165,6 +165,56 @@
     9.4      return mouse->focus;
     9.5  }
     9.6  
     9.7 +static int
     9.8 +FlushMouseMotion(void *param, SDL_Event * event)
     9.9 +{
    9.10 +    if (event->type == SDL_MOUSEMOTION
    9.11 +        && event->motion.which == (Uint8) SDL_current_mouse) {
    9.12 +        return 0;
    9.13 +    } else {
    9.14 +        return 1;
    9.15 +    }
    9.16 +}
    9.17 +
    9.18 +int
    9.19 +SDL_SetRelativeMouseMode(SDL_bool enabled)
    9.20 +{
    9.21 +    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
    9.22 +
    9.23 +    if (!mouse) {
    9.24 +        return -1;
    9.25 +    }
    9.26 +
    9.27 +    /* Flush pending mouse motion */
    9.28 +    mouse->flush_motion = SDL_TRUE;
    9.29 +    SDL_PumpEvents();
    9.30 +    mouse->flush_motion = SDL_FALSE;
    9.31 +    SDL_FilterEvents(FlushMouseMotion, mouse);
    9.32 +
    9.33 +    /* Set the relative mode */
    9.34 +    mouse->relative_mode = enabled;
    9.35 +
    9.36 +    /* Update cursor visibility */
    9.37 +    SDL_SetCursor(NULL);
    9.38 +
    9.39 +    if (!enabled) {
    9.40 +        /* Restore the expected mouse position */
    9.41 +        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    9.42 +    }
    9.43 +    return 0;
    9.44 +}
    9.45 +
    9.46 +SDL_bool
    9.47 +SDL_GetRelativeMouseMode()
    9.48 +{
    9.49 +    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
    9.50 +
    9.51 +    if (!mouse) {
    9.52 +        return SDL_FALSE;
    9.53 +    }
    9.54 +    return mouse->relative_mode;
    9.55 +}
    9.56 +
    9.57  Uint8
    9.58  SDL_GetMouseState(int *x, int *y)
    9.59  {
    9.60 @@ -224,7 +274,7 @@
    9.61      int xrel;
    9.62      int yrel;
    9.63  
    9.64 -    if (!mouse) {
    9.65 +    if (!mouse || mouse->flush_motion) {
    9.66          return 0;
    9.67      }
    9.68  
    9.69 @@ -252,13 +302,16 @@
    9.70      }
    9.71  
    9.72      /* Update internal mouse state */
    9.73 -    mouse->x = x;
    9.74 -    mouse->y = y;
    9.75 +    if (!mouse->relative_mode) {
    9.76 +        mouse->x = x;
    9.77 +        mouse->y = y;
    9.78 +    }
    9.79      mouse->xdelta += xrel;
    9.80      mouse->ydelta += yrel;
    9.81  
    9.82      /* Move the mouse cursor, if needed */
    9.83 -    if (mouse->MoveCursor && mouse->cur_cursor) {
    9.84 +    if (mouse->cursor_shown && !mouse->relative_mode &&
    9.85 +        mouse->MoveCursor && mouse->cur_cursor) {
    9.86          mouse->MoveCursor(mouse->cur_cursor);
    9.87      }
    9.88  
    9.89 @@ -274,7 +327,8 @@
    9.90          event.motion.xrel = xrel;
    9.91          event.motion.yrel = yrel;
    9.92          event.motion.windowID = mouse->focus;
    9.93 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
    9.94 +        if ((SDL_EventOK == NULL)
    9.95 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    9.96              posted = 1;
    9.97              SDL_PushEvent(&event);
    9.98          }
    9.99 @@ -332,7 +386,8 @@
   9.100          event.button.x = mouse->x;
   9.101          event.button.y = mouse->y;
   9.102          event.button.windowID = mouse->focus;
   9.103 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   9.104 +        if ((SDL_EventOK == NULL)
   9.105 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   9.106              posted = 1;
   9.107              SDL_PushEvent(&event);
   9.108          }
   9.109 @@ -457,7 +512,7 @@
   9.110          cursor = mouse->cur_cursor;
   9.111      }
   9.112  
   9.113 -    if (cursor && mouse->cursor_shown) {
   9.114 +    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
   9.115          if (mouse->ShowCursor) {
   9.116              mouse->ShowCursor(cursor);
   9.117          }
    10.1 --- a/src/events/SDL_mouse_c.h	Fri Jun 30 05:50:35 2006 +0000
    10.2 +++ b/src/events/SDL_mouse_c.h	Fri Jun 30 08:18:44 2006 +0000
    10.3 @@ -63,6 +63,8 @@
    10.4      int xdelta;
    10.5      int ydelta;
    10.6      Uint8 buttonstate;
    10.7 +    SDL_bool relative_mode;
    10.8 +    SDL_bool flush_motion;
    10.9  
   10.10      SDL_Cursor *cursors;
   10.11      SDL_Cursor *def_cursor;
    11.1 --- a/src/events/SDL_quit.c	Fri Jun 30 05:50:35 2006 +0000
    11.2 +++ b/src/events/SDL_quit.c	Fri Jun 30 08:18:44 2006 +0000
    11.3 @@ -88,7 +88,8 @@
    11.4      if (SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE) {
    11.5          SDL_Event event;
    11.6          event.type = SDL_QUIT;
    11.7 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
    11.8 +        if ((SDL_EventOK == NULL)
    11.9 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   11.10              posted = 1;
   11.11              SDL_PushEvent(&event);
   11.12          }
    12.1 --- a/src/events/SDL_windowevents.c	Fri Jun 30 05:50:35 2006 +0000
    12.2 +++ b/src/events/SDL_windowevents.c	Fri Jun 30 08:18:44 2006 +0000
    12.3 @@ -25,12 +25,75 @@
    12.4  
    12.5  #include "SDL_events.h"
    12.6  #include "SDL_events_c.h"
    12.7 +#include "../video/SDL_sysvideo.h"
    12.8  
    12.9  int
   12.10  SDL_PrivateWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
   12.11                         int data2)
   12.12  {
   12.13      int posted;
   12.14 +    SDL_Window *window;
   12.15 +
   12.16 +    window = SDL_GetWindowFromID(windowID);
   12.17 +    if (!window) {
   12.18 +        return 0;
   12.19 +    }
   12.20 +    switch (windowevent) {
   12.21 +    case SDL_WINDOWEVENT_SHOWN:
   12.22 +        if (window->flags & SDL_WINDOW_SHOWN) {
   12.23 +            return 0;
   12.24 +        }
   12.25 +        window->flags |= SDL_WINDOW_SHOWN;
   12.26 +        break;
   12.27 +    case SDL_WINDOWEVENT_HIDDEN:
   12.28 +        if (!(window->flags & SDL_WINDOW_SHOWN)) {
   12.29 +            return 0;
   12.30 +        }
   12.31 +        window->flags &= ~SDL_WINDOW_SHOWN;
   12.32 +        break;
   12.33 +    case SDL_WINDOWEVENT_MINIMIZED:
   12.34 +        if (window->flags & SDL_WINDOW_MINIMIZED) {
   12.35 +            return 0;
   12.36 +        }
   12.37 +        window->flags |= SDL_WINDOW_MINIMIZED;
   12.38 +        break;
   12.39 +    case SDL_WINDOWEVENT_MAXIMIZED:
   12.40 +        if (window->flags & SDL_WINDOW_MAXIMIZED) {
   12.41 +            return 0;
   12.42 +        }
   12.43 +        window->flags |= SDL_WINDOW_MAXIMIZED;
   12.44 +        break;
   12.45 +    case SDL_WINDOWEVENT_RESTORED:
   12.46 +        if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
   12.47 +            return 0;
   12.48 +        }
   12.49 +        window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
   12.50 +        break;
   12.51 +    case SDL_WINDOWEVENT_ENTER:
   12.52 +        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
   12.53 +            return 0;
   12.54 +        }
   12.55 +        window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   12.56 +        break;
   12.57 +    case SDL_WINDOWEVENT_LEAVE:
   12.58 +        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   12.59 +            return 0;
   12.60 +        }
   12.61 +        window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   12.62 +        break;
   12.63 +    case SDL_WINDOWEVENT_FOCUS_GAINED:
   12.64 +        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
   12.65 +            return 0;
   12.66 +        }
   12.67 +        window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
   12.68 +        break;
   12.69 +    case SDL_WINDOWEVENT_FOCUS_LOST:
   12.70 +        if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
   12.71 +            return 0;
   12.72 +        }
   12.73 +        window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
   12.74 +        break;
   12.75 +    }
   12.76  
   12.77      /* Post the event, if desired */
   12.78      posted = 0;
   12.79 @@ -41,7 +104,8 @@
   12.80          event.window.data1 = data1;
   12.81          event.window.data2 = data2;
   12.82          event.window.windowID = windowID;
   12.83 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   12.84 +        if ((SDL_EventOK == NULL)
   12.85 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   12.86              posted = 1;
   12.87              SDL_PushEvent(&event);
   12.88          }
    13.1 --- a/src/joystick/SDL_joystick.c	Fri Jun 30 05:50:35 2006 +0000
    13.2 +++ b/src/joystick/SDL_joystick.c	Fri Jun 30 08:18:44 2006 +0000
    13.3 @@ -448,7 +448,8 @@
    13.4          event.jaxis.which = joystick->index;
    13.5          event.jaxis.axis = axis;
    13.6          event.jaxis.value = value;
    13.7 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
    13.8 +        if ((SDL_EventOK == NULL)
    13.9 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.10              posted = 1;
   13.11              SDL_PushEvent(&event);
   13.12          }
   13.13 @@ -474,7 +475,8 @@
   13.14          event.jhat.which = joystick->index;
   13.15          event.jhat.hat = hat;
   13.16          event.jhat.value = value;
   13.17 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   13.18 +        if ((SDL_EventOK == NULL)
   13.19 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.20              posted = 1;
   13.21              SDL_PushEvent(&event);
   13.22          }
   13.23 @@ -503,7 +505,8 @@
   13.24          event.jball.ball = ball;
   13.25          event.jball.xrel = xrel;
   13.26          event.jball.yrel = yrel;
   13.27 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   13.28 +        if ((SDL_EventOK == NULL)
   13.29 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.30              posted = 1;
   13.31              SDL_PushEvent(&event);
   13.32          }
   13.33 @@ -542,7 +545,8 @@
   13.34          event.jbutton.which = joystick->index;
   13.35          event.jbutton.button = button;
   13.36          event.jbutton.state = state;
   13.37 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   13.38 +        if ((SDL_EventOK == NULL)
   13.39 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.40              posted = 1;
   13.41              SDL_PushEvent(&event);
   13.42          }
    14.1 --- a/src/video/win32/SDL_win32events.c	Fri Jun 30 05:50:35 2006 +0000
    14.2 +++ b/src/video/win32/SDL_win32events.c	Fri Jun 30 08:18:44 2006 +0000
    14.3 @@ -22,21 +22,363 @@
    14.4  #include "SDL_config.h"
    14.5  
    14.6  #include "SDL_win32video.h"
    14.7 +#include "../../events/SDL_events_c.h"
    14.8  
    14.9  
   14.10  LRESULT CALLBACK
   14.11  WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   14.12  {
   14.13      SDL_WindowData *data;
   14.14 -    SDL_Window *window;
   14.15  
   14.16      /* Get the window data for the window */
   14.17      data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
   14.18      if (!data) {
   14.19          return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
   14.20      }
   14.21 -    window = data->window;
   14.22 +#if 0
   14.23 +    switch (msg) {
   14.24  
   14.25 +    case WM_ACTIVATE:
   14.26 +        {
   14.27 +            BOOL minimized;
   14.28 +
   14.29 +            minimized = HIWORD(wParam);
   14.30 +            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
   14.31 +                SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN,
   14.32 +                                       0, 0);
   14.33 +                SDL_PrivateWindowEvent(data->windowID,
   14.34 +                                       SDL_WINDOWEVENT_RESTORED, 0, 0);
   14.35 +                if (IsZoomed(hwnd)) {
   14.36 +                    SDL_PrivateWindowEvent(data->windowID,
   14.37 +                                           SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   14.38 +                }
   14.39 +                SDL_PrivateWindowEvent(data->windowID,
   14.40 +                                       SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   14.41 +                /* FIXME: Restore mode state (mode, gamma, grab) */
   14.42 +                /* FIXME: Update keyboard state */
   14.43 +            } else {
   14.44 +                SDL_PrivateWindowEvent(data->windowID,
   14.45 +                                       SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   14.46 +                if (minimized) {
   14.47 +                    SDL_PrivateWindowEvent(data->windowID,
   14.48 +                                           SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   14.49 +                }
   14.50 +                /* FIXME: Restore desktop state (mode, gamma, grab) */
   14.51 +            }
   14.52 +            return (0);
   14.53 +        }
   14.54 +        break;
   14.55 +
   14.56 +    case WM_MOUSEMOVE:
   14.57 +        {
   14.58 +            int index;
   14.59 +            SDL_Mouse *mouse;
   14.60 +
   14.61 +            if (!
   14.62 +                (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_MOUSE_FOCUS))
   14.63 +            {
   14.64 +                /* mouse has entered the window */
   14.65 +                TRACKMOUSEEVENT tme;
   14.66 +
   14.67 +                tme.cbSize = sizeof(tme);
   14.68 +                tme.dwFlags = TME_LEAVE;
   14.69 +                tme.hwndTrack = hwnd;
   14.70 +                TrackMouseEvent(&tme);
   14.71 +
   14.72 +                SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_ENTER,
   14.73 +                                       0, 0);
   14.74 +            }
   14.75 +
   14.76 +            index = data->videodata->mouse;
   14.77 +            mouse = SDL_GetMouse(index);
   14.78 +            if (mouse) {
   14.79 +                int x, y;
   14.80 +                /* mouse has moved within the window */
   14.81 +                x = LOWORD(lParam);
   14.82 +                y = HIWORD(lParam);
   14.83 +                if (mouse->relative_mode) {
   14.84 +                    int w, h;
   14.85 +                    POINT center;
   14.86 +                    SDL_GetWindowSize(data->windowID, &w, &h);
   14.87 +                    center.x = (w / 2);
   14.88 +                    center.y = (h / 2);
   14.89 +                    x -= center.x;
   14.90 +                    y -= center.y;
   14.91 +                    if (x || y) {
   14.92 +                        ClientToScreen(SDL_Window, &center);
   14.93 +                        SetCursorPos(center.x, center.y);
   14.94 +                        SDL_SendMouseMotion(index, data->windowID, 1, x, y);
   14.95 +                    }
   14.96 +                } else {
   14.97 +                    SDL_SendMouseMotion(index, data->windowID, 0, x, y);
   14.98 +                }
   14.99 +            }
  14.100 +        }
  14.101 +        return (0);
  14.102 +
  14.103 +    case WM_MOUSELEAVE:
  14.104 +        {
  14.105 +            SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_LEAVE, 0,
  14.106 +                                   0);
  14.107 +        }
  14.108 +        return (0);
  14.109 +
  14.110 +    case WM_LBUTTONDOWN:
  14.111 +    case WM_LBUTTONUP:
  14.112 +    case WM_MBUTTONDOWN:
  14.113 +    case WM_MBUTTONUP:
  14.114 +    case WM_RBUTTONDOWN:
  14.115 +    case WM_RBUTTONUP:
  14.116 +        {
  14.117 +            int x, y;
  14.118 +            Uint8 button, state;
  14.119 +
  14.120 +            /* DJM:
  14.121 +               We want the SDL window to take focus so that
  14.122 +               it acts like a normal windows "component"
  14.123 +               (e.g. gains keyboard focus on a mouse click).
  14.124 +             */
  14.125 +            SetFocus(SDL_Window);
  14.126 +
  14.127 +            /* Figure out which button to use */
  14.128 +            switch (msg) {
  14.129 +            case WM_LBUTTONDOWN:
  14.130 +                button = SDL_BUTTON_LEFT;
  14.131 +                state = SDL_PRESSED;
  14.132 +                break;
  14.133 +            case WM_LBUTTONUP:
  14.134 +                button = SDL_BUTTON_LEFT;
  14.135 +                state = SDL_RELEASED;
  14.136 +                break;
  14.137 +            case WM_MBUTTONDOWN:
  14.138 +                button = SDL_BUTTON_MIDDLE;
  14.139 +                state = SDL_PRESSED;
  14.140 +                break;
  14.141 +            case WM_MBUTTONUP:
  14.142 +                button = SDL_BUTTON_MIDDLE;
  14.143 +                state = SDL_RELEASED;
  14.144 +                break;
  14.145 +            case WM_RBUTTONDOWN:
  14.146 +                button = SDL_BUTTON_RIGHT;
  14.147 +                state = SDL_PRESSED;
  14.148 +                break;
  14.149 +            case WM_RBUTTONUP:
  14.150 +                button = SDL_BUTTON_RIGHT;
  14.151 +                state = SDL_RELEASED;
  14.152 +                break;
  14.153 +            default:
  14.154 +                /* Eh? Unknown button? */
  14.155 +                return (0);
  14.156 +            }
  14.157 +            if (state == SDL_PRESSED) {
  14.158 +                /* Grab mouse so we get up events */
  14.159 +                if (++mouse_pressed > 0) {
  14.160 +                    SetCapture(hwnd);
  14.161 +                }
  14.162 +            } else {
  14.163 +                /* Release mouse after all up events */
  14.164 +                if (--mouse_pressed <= 0) {
  14.165 +                    ReleaseCapture();
  14.166 +                    mouse_pressed = 0;
  14.167 +                }
  14.168 +            }
  14.169 +            x = LOWORD(lParam);
  14.170 +            y = HIWORD(lParam);
  14.171 +#ifdef _WIN32_WCE
  14.172 +            if (SDL_VideoSurface)
  14.173 +                GapiTransform(this->hidden->userOrientation,
  14.174 +                              this->hidden->hiresFix, &x, &y);
  14.175 +#endif
  14.176 +            posted = SDL_PrivateMouseButton(state, button, x, y);
  14.177 +        }
  14.178 +
  14.179 +        return (0);
  14.180 +
  14.181 +
  14.182 +#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
  14.183 +    case WM_MOUSEWHEEL:
  14.184 +        if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) {
  14.185 +            int move = (short) HIWORD(wParam);
  14.186 +            if (move) {
  14.187 +                Uint8 button;
  14.188 +                if (move > 0)
  14.189 +                    button = SDL_BUTTON_WHEELUP;
  14.190 +                else
  14.191 +                    button = SDL_BUTTON_WHEELDOWN;
  14.192 +                posted = SDL_PrivateMouseButton(SDL_PRESSED, button, 0, 0);
  14.193 +                posted |= SDL_PrivateMouseButton(SDL_RELEASED, button, 0, 0);
  14.194 +            }
  14.195 +        }
  14.196 +        return (0);
  14.197 +#endif
  14.198 +
  14.199 +#ifdef WM_GETMINMAXINFO
  14.200 +        /* This message is sent as a way for us to "check" the values
  14.201 +         * of a position change.  If we don't like it, we can adjust
  14.202 +         * the values before they are changed.
  14.203 +         */
  14.204 +    case WM_GETMINMAXINFO:
  14.205 +        {
  14.206 +            MINMAXINFO *info;
  14.207 +            RECT size;
  14.208 +            int x, y;
  14.209 +            int style;
  14.210 +            int width;
  14.211 +            int height;
  14.212 +
  14.213 +            /* We don't want to clobber an internal resize */
  14.214 +            if (SDL_resizing)
  14.215 +                return (0);
  14.216 +
  14.217 +            /* We allow resizing with the SDL_RESIZABLE flag */
  14.218 +            if (SDL_PublicSurface
  14.219 +                && (SDL_PublicSurface->flags & SDL_RESIZABLE)) {
  14.220 +                return (0);
  14.221 +            }
  14.222 +
  14.223 +            /* Get the current position of our window */
  14.224 +            GetWindowRect(SDL_Window, &size);
  14.225 +            x = size.left;
  14.226 +            y = size.top;
  14.227 +
  14.228 +            /* Calculate current width and height of our window */
  14.229 +            size.top = 0;
  14.230 +            size.left = 0;
  14.231 +            if (SDL_PublicSurface != NULL) {
  14.232 +                size.bottom = SDL_PublicSurface->h;
  14.233 +                size.right = SDL_PublicSurface->w;
  14.234 +            } else {
  14.235 +                size.bottom = 0;
  14.236 +                size.right = 0;
  14.237 +            }
  14.238 +
  14.239 +            /* DJM - according to the docs for GetMenu(), the
  14.240 +               return value is undefined if hwnd is a child window.
  14.241 +               Aparently it's too difficult for MS to check
  14.242 +               inside their function, so I have to do it here.
  14.243 +             */
  14.244 +            style = GetWindowLong(hwnd, GWL_STYLE);
  14.245 +            AdjustWindowRect(&size,
  14.246 +                             style,
  14.247 +                             style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) !=
  14.248 +                             NULL);
  14.249 +
  14.250 +            width = size.right - size.left;
  14.251 +            height = size.bottom - size.top;
  14.252 +
  14.253 +            /* Fix our size to the current size */
  14.254 +            info = (MINMAXINFO *) lParam;
  14.255 +            info->ptMaxSize.x = width;
  14.256 +            info->ptMaxSize.y = height;
  14.257 +            info->ptMaxPosition.x = x;
  14.258 +            info->ptMaxPosition.y = y;
  14.259 +            info->ptMinTrackSize.x = width;
  14.260 +            info->ptMinTrackSize.y = height;
  14.261 +            info->ptMaxTrackSize.x = width;
  14.262 +            info->ptMaxTrackSize.y = height;
  14.263 +        }
  14.264 +
  14.265 +        return (0);
  14.266 +#endif /* WM_GETMINMAXINFO */
  14.267 +
  14.268 +    case WM_WINDOWPOSCHANGED:
  14.269 +        {
  14.270 +            SDL_VideoDevice *this = current_video;
  14.271 +            int w, h;
  14.272 +
  14.273 +            GetClientRect(SDL_Window, &SDL_bounds);
  14.274 +            ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds);
  14.275 +            ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds + 1);
  14.276 +            if (!SDL_resizing && !IsZoomed(SDL_Window) &&
  14.277 +                SDL_PublicSurface
  14.278 +                && !(SDL_PublicSurface->flags & SDL_FULLSCREEN)) {
  14.279 +                SDL_windowX = SDL_bounds.left;
  14.280 +                SDL_windowY = SDL_bounds.top;
  14.281 +            }
  14.282 +            w = SDL_bounds.right - SDL_bounds.left;
  14.283 +            h = SDL_bounds.bottom - SDL_bounds.top;
  14.284 +            if (this->input_grab != SDL_GRAB_OFF) {
  14.285 +                ClipCursor(&SDL_bounds);
  14.286 +            }
  14.287 +            if (SDL_PublicSurface
  14.288 +                && (SDL_PublicSurface->flags & SDL_RESIZABLE)) {
  14.289 +                SDL_PrivateResize(w, h);
  14.290 +            }
  14.291 +        }
  14.292 +
  14.293 +        break;
  14.294 +
  14.295 +        /* We need to set the cursor */
  14.296 +    case WM_SETCURSOR:
  14.297 +        {
  14.298 +            Uint16 hittest;
  14.299 +
  14.300 +            hittest = LOWORD(lParam);
  14.301 +            if (hittest == HTCLIENT) {
  14.302 +                SetCursor(SDL_hcursor);
  14.303 +                return (TRUE);
  14.304 +            }
  14.305 +        }
  14.306 +
  14.307 +        break;
  14.308 +
  14.309 +        /* We are about to get palette focus! */
  14.310 +    case WM_QUERYNEWPALETTE:
  14.311 +        {
  14.312 +            WIN_RealizePalette(current_video);
  14.313 +            return (TRUE);
  14.314 +        }
  14.315 +
  14.316 +        break;
  14.317 +
  14.318 +        /* Another application changed the palette */
  14.319 +    case WM_PALETTECHANGED:
  14.320 +        {
  14.321 +            WIN_PaletteChanged(current_video, (HWND) wParam);
  14.322 +        }
  14.323 +
  14.324 +        break;
  14.325 +
  14.326 +        /* We were occluded, refresh our display */
  14.327 +    case WM_PAINT:
  14.328 +        {
  14.329 +            HDC hdc;
  14.330 +            PAINTSTRUCT ps;
  14.331 +
  14.332 +            hdc = BeginPaint(SDL_Window, &ps);
  14.333 +            if (current_video->screen &&
  14.334 +                !(current_video->screen->flags & SDL_INTERNALOPENGL)) {
  14.335 +                WIN_WinPAINT(current_video, hdc);
  14.336 +            }
  14.337 +            EndPaint(SDL_Window, &ps);
  14.338 +        }
  14.339 +
  14.340 +        return (0);
  14.341 +
  14.342 +        /* DJM: Send an expose event in this case */
  14.343 +    case WM_ERASEBKGND:
  14.344 +        {
  14.345 +            posted = SDL_PrivateExpose();
  14.346 +        }
  14.347 +
  14.348 +        return (0);
  14.349 +
  14.350 +    case WM_CLOSE:
  14.351 +        {
  14.352 +            if ((posted = SDL_PrivateQuit()))
  14.353 +                PostQuitMessage(0);
  14.354 +        }
  14.355 +
  14.356 +        return (0);
  14.357 +
  14.358 +    case WM_DESTROY:
  14.359 +        {
  14.360 +            PostQuitMessage(0);
  14.361 +        }
  14.362 +
  14.363 +        return (0);
  14.364 +    }
  14.365 +#endif
  14.366      return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
  14.367  }
  14.368  
    15.1 --- a/src/video/win32/SDL_win32video.h	Fri Jun 30 05:50:35 2006 +0000
    15.2 +++ b/src/video/win32/SDL_win32video.h	Fri Jun 30 08:18:44 2006 +0000
    15.3 @@ -45,7 +45,7 @@
    15.4  
    15.5  /* Private display data */
    15.6  
    15.7 -typedef struct
    15.8 +typedef struct SDL_VideoData
    15.9  {
   15.10      int mouse;
   15.11      int keyboard;
    16.1 --- a/src/video/win32/SDL_win32window.c	Fri Jun 30 05:50:35 2006 +0000
    16.2 +++ b/src/video/win32/SDL_win32window.c	Fri Jun 30 08:18:44 2006 +0000
    16.3 @@ -40,9 +40,10 @@
    16.4          SDL_OutOfMemory();
    16.5          return -1;
    16.6      }
    16.7 -    data->window = window;
    16.8 +    data->windowID = window->id;
    16.9      data->hwnd = hwnd;
   16.10      data->created = created;
   16.11 +    data->videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata;
   16.12  
   16.13      /* Associate the data with the window */
   16.14      if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
    17.1 --- a/src/video/win32/SDL_win32window.h	Fri Jun 30 05:50:35 2006 +0000
    17.2 +++ b/src/video/win32/SDL_win32window.h	Fri Jun 30 08:18:44 2006 +0000
    17.3 @@ -29,10 +29,11 @@
    17.4  
    17.5  typedef struct
    17.6  {
    17.7 -    SDL_Window *window;
    17.8 +    SDL_WindowID windowID;
    17.9      HWND hwnd;
   17.10      WNDPROC wndproc;
   17.11      BOOL created;
   17.12 +    struct SDL_VideoData *videodata;
   17.13  } SDL_WindowData;
   17.14  
   17.15  extern int WIN_CreateWindow(_THIS, SDL_Window * window);