WinRT: added initial SDL_TEXTINPUT support
authorDavid Ludwig <dludwig@pobox.com>
Wed, 26 Nov 2014 21:34:15 -0500
changeset 9240 dc4ad21d8596
parent 9239 4a4293b8a37f
child 9241 4900e838abbc
WinRT: added initial SDL_TEXTINPUT support Further support regarding IME and on-screen keyboards is pending, some of which might not be 100% compatible with other platforms, given WinRT platform restrictions. An MSDN article at http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx indicates that on-screen keyboard display requires that the user first tap on a Windows/XAML text control. This change adds basic SDL_TEXTINPUT support, with input coming from hardware keyboards, at a minimum, and without the need for XAML integration (which is still pending integration into SDL, by and large).
src/core/winrt/SDL_winrtapp_direct3d.cpp
src/core/winrt/SDL_winrtapp_direct3d.h
src/video/winrt/SDL_winrtevents_c.h
src/video/winrt/SDL_winrtkeyboard.cpp
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp	Tue Nov 25 22:37:12 2014 +0100
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Wed Nov 26 21:34:15 2014 -0500
@@ -365,6 +365,9 @@
     window->KeyUp +=
         ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
 
+    window->CharacterReceived +=
+        ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(this, &SDL_WinRTApp::OnCharacterReceived);
+
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     HardwareButtons::BackPressed +=
         ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
@@ -703,6 +706,11 @@
     WINRT_ProcessKeyUpEvent(args);
 }
 
+void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args)
+{
+    WINRT_ProcessCharacterReceivedEvent(args);
+}
+
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
 void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
 {
--- a/src/core/winrt/SDL_winrtapp_direct3d.h	Tue Nov 25 22:37:12 2014 +0100
+++ b/src/core/winrt/SDL_winrtapp_direct3d.h	Wed Nov 26 21:34:15 2014 -0500
@@ -69,6 +69,7 @@
     void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
     void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
     void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
+    void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
 
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
--- a/src/video/winrt/SDL_winrtevents_c.h	Tue Nov 25 22:37:12 2014 +0100
+++ b/src/video/winrt/SDL_winrtevents_c.h	Wed Nov 26 21:34:15 2014 -0500
@@ -63,6 +63,7 @@
 /* Keyboard */
 extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args);
 extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
+extern void WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args);
 
 /* XAML Thread Management */
 extern void WINRT_CycleXAMLThread();
--- a/src/video/winrt/SDL_winrtkeyboard.cpp	Tue Nov 25 22:37:12 2014 +0100
+++ b/src/video/winrt/SDL_winrtkeyboard.cpp	Wed Nov 26 21:34:15 2014 -0500
@@ -365,4 +365,22 @@
     SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
 }
 
+void
+WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args)
+{
+    wchar_t src_ucs2[2];
+    char dest_utf8[16];
+    int result;
+
+    /* Setup src */
+    src_ucs2[0] = args->KeyCode;
+    src_ucs2[1] = L'\0';
+
+    /* Convert the text, then send an SDL_TEXTINPUT event. */
+    result = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&src_ucs2, -1, (LPSTR)dest_utf8, sizeof(dest_utf8), NULL, NULL);
+    if (result > 0) {
+        SDL_SendKeyboardText(dest_utf8);
+    }
+}
+
 #endif // SDL_VIDEO_DRIVER_WINRT