Added SDL_SetWindowsMessageHook() to facilitate full IME support on Windows
authorSam Lantinga <slouken@libsdl.org>
Wed, 13 May 2015 22:39:20 -0700
changeset 9597 345bc53b52b8
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
--- a/include/SDL_system.h	Wed May 13 22:37:26 2015 -0700
+++ b/include/SDL_system.h	Wed May 13 22:39:20 2015 -0700
@@ -42,6 +42,12 @@
 
 /* Platform specific functions for Windows */
 #ifdef __WIN32__
+	
+/**
+   \brief Set a function that is called for every windows message, before TranslateMessage()
+*/
+typedef void (*SDL_WindowsMessageHook)(void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
+extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback);
 
 /**
    \brief Returns the D3D9 adapter index that matches the specified display index.
--- a/src/dynapi/SDL_dynapi_overrides.h	Wed May 13 22:37:26 2015 -0700
+++ b/src/dynapi/SDL_dynapi_overrides.h	Wed May 13 22:39:20 2015 -0700
@@ -592,3 +592,4 @@
 #define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL
 #define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL
 #define SDL_GetGrabbedWindow SDL_GetGrabbedWindow_REAL
+#define SDL_SetWindowsMessageHook SDL_SetWindowsMessageHook_REAL
--- a/src/dynapi/SDL_dynapi_procs.h	Wed May 13 22:37:26 2015 -0700
+++ b/src/dynapi/SDL_dynapi_procs.h	Wed May 13 22:39:20 2015 -0700
@@ -624,3 +624,4 @@
 SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return)
 SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a),(a),)
--- a/src/video/windows/SDL_windowsevents.c	Wed May 13 22:37:26 2015 -0700
+++ b/src/video/windows/SDL_windowsevents.c	Wed May 13 22:39:20 2015 -0700
@@ -24,6 +24,7 @@
 
 #include "SDL_windowsvideo.h"
 #include "SDL_windowsshape.h"
+#include "SDL_system.h"
 #include "SDL_syswm.h"
 #include "SDL_timer.h"
 #include "SDL_vkeys.h"
@@ -925,6 +926,14 @@
     }
 }
 
+/* A message hook called before TranslateMessage() */
+static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
+
+void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback)
+{
+    g_WindowsMessageHook = callback;
+}
+
 void
 WIN_PumpEvents(_THIS)
 {
@@ -934,6 +943,10 @@
 
     if (g_WindowsEnableMessageLoop) {
         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+            if (g_WindowsMessageHook) {
+                g_WindowsMessageHook(msg.hwnd, msg.message, msg.wParam, msg.lParam);
+            }
+
             /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
             TranslateMessage(&msg);
             DispatchMessage(&msg);