Added SDL_SetWindowsMessageHook() to facilitate full IME support on Windows
authorSam Lantinga <slouken@libsdl.org>
Wed, 13 May 2015 22:39:20 -0700
changeset 9597345bc53b52b8
parent 9596 ac646c8a73ae
child 9598 5f50522bf2e1
Added SDL_SetWindowsMessageHook() to facilitate full IME support on Windows
include/SDL_system.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/video/SDL_egl.c
src/video/windows/SDL_windowsevents.c
     1.1 --- a/include/SDL_system.h	Wed May 13 22:37:26 2015 -0700
     1.2 +++ b/include/SDL_system.h	Wed May 13 22:39:20 2015 -0700
     1.3 @@ -42,6 +42,12 @@
     1.4  
     1.5  /* Platform specific functions for Windows */
     1.6  #ifdef __WIN32__
     1.7 +	
     1.8 +/**
     1.9 +   \brief Set a function that is called for every windows message, before TranslateMessage()
    1.10 +*/
    1.11 +typedef void (*SDL_WindowsMessageHook)(void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
    1.12 +extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback);
    1.13  
    1.14  /**
    1.15     \brief Returns the D3D9 adapter index that matches the specified display index.
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Wed May 13 22:37:26 2015 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Wed May 13 22:39:20 2015 -0700
     2.3 @@ -592,3 +592,4 @@
     2.4  #define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL
     2.5  #define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL
     2.6  #define SDL_GetGrabbedWindow SDL_GetGrabbedWindow_REAL
     2.7 +#define SDL_SetWindowsMessageHook SDL_SetWindowsMessageHook_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Wed May 13 22:37:26 2015 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Wed May 13 22:39:20 2015 -0700
     3.3 @@ -624,3 +624,4 @@
     3.4  SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return)
     3.5  SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
     3.6  SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
     3.7 +SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a),(a),)
     4.1 --- a/src/video/windows/SDL_windowsevents.c	Wed May 13 22:37:26 2015 -0700
     4.2 +++ b/src/video/windows/SDL_windowsevents.c	Wed May 13 22:39:20 2015 -0700
     4.3 @@ -24,6 +24,7 @@
     4.4  
     4.5  #include "SDL_windowsvideo.h"
     4.6  #include "SDL_windowsshape.h"
     4.7 +#include "SDL_system.h"
     4.8  #include "SDL_syswm.h"
     4.9  #include "SDL_timer.h"
    4.10  #include "SDL_vkeys.h"
    4.11 @@ -925,6 +926,14 @@
    4.12      }
    4.13  }
    4.14  
    4.15 +/* A message hook called before TranslateMessage() */
    4.16 +static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
    4.17 +
    4.18 +void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback)
    4.19 +{
    4.20 +    g_WindowsMessageHook = callback;
    4.21 +}
    4.22 +
    4.23  void
    4.24  WIN_PumpEvents(_THIS)
    4.25  {
    4.26 @@ -934,6 +943,10 @@
    4.27  
    4.28      if (g_WindowsEnableMessageLoop) {
    4.29          while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    4.30 +            if (g_WindowsMessageHook) {
    4.31 +                g_WindowsMessageHook(msg.hwnd, msg.message, msg.wParam, msg.lParam);
    4.32 +            }
    4.33 +
    4.34              /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
    4.35              TranslateMessage(&msg);
    4.36              DispatchMessage(&msg);