comparison src/video/wincommon/SDL_sysevents.c @ 1253:7c7ddaf195bf

Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP This is a collaborative effort between Alex Volkov and John Popplewell. Thanks guys! (Fixes bug #39)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 19 Jan 2006 09:09:32 +0000
parents 86d0d01290ea
children 94c0709f8856
comparison
equal deleted inserted replaced
1252:57be1c741b8b 1253:7c7ddaf195bf
76 LONG (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL; 76 LONG (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
77 void (*WIN_RealizePalette)(_THIS); 77 void (*WIN_RealizePalette)(_THIS);
78 void (*WIN_PaletteChanged)(_THIS, HWND window); 78 void (*WIN_PaletteChanged)(_THIS, HWND window);
79 void (*WIN_WinPAINT)(_THIS, HDC hdc); 79 void (*WIN_WinPAINT)(_THIS, HDC hdc);
80 extern void DIB_SwapGamma(_THIS); 80 extern void DIB_SwapGamma(_THIS);
81
82 /* Variables and support functions for SDL_ToUnicode() */
83 static int codepage;
84 static int Is9xME();
85 static int GetCodePage();
86 static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, BYTE *keystate, Uint16 *wchars, int wsize, UINT flags);
87
88 ToUnicodeFN SDL_ToUnicode = ToUnicode9xME;
89
81 90
82 #if defined(_WIN32_WCE) 91 #if defined(_WIN32_WCE)
83 92
84 // dynamically load aygshell dll because we want SDL to work on HPC and be300 93 // dynamically load aygshell dll because we want SDL to work on HPC and be300
85 HINSTANCE aygshell = NULL; 94 HINSTANCE aygshell = NULL;
620 case WM_DESTROY: { 629 case WM_DESTROY: {
621 PostQuitMessage(0); 630 PostQuitMessage(0);
622 } 631 }
623 return(0); 632 return(0);
624 633
634 case WM_INPUTLANGCHANGE: {
635 codepage = GetCodePage();
636 }
637 return(TRUE);
638
625 default: { 639 default: {
626 /* Special handling by the video driver */ 640 /* Special handling by the video driver */
627 if (HandleMessage) { 641 if (HandleMessage) {
628 return(HandleMessage(current_video, 642 return(HandleMessage(current_video,
629 hwnd, msg, wParam, lParam)); 643 hwnd, msg, wParam, lParam));
726 #endif /* WM_MOUSELEAVE */ 740 #endif /* WM_MOUSELEAVE */
727 741
728 /* Check for SDL_WINDOWID hack */ 742 /* Check for SDL_WINDOWID hack */
729 SDL_windowid = getenv("SDL_WINDOWID"); 743 SDL_windowid = getenv("SDL_WINDOWID");
730 744
745 /* Initialise variables for SDL_ToUnicode() */
746 codepage = GetCodePage();
747 SDL_ToUnicode = Is9xME() ? ToUnicode9xME : ToUnicode;
748
731 app_registered = 1; 749 app_registered = 1;
732 return(0); 750 return(0);
733 } 751 }
734 752
735 /* 753 /*
749 } 767 }
750 } 768 }
751 app_registered = 0; 769 app_registered = 0;
752 } 770 }
753 771
772 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
773
774 static int Is9xME()
775 {
776 OSVERSIONINFO info;
777
778 memset(&info, 0, sizeof(info));
779 info.dwOSVersionInfoSize = sizeof(info);
780 if (!GetVersionEx(&info)) {
781 return 0;
782 }
783 return (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
784 }
785
786 static int GetCodePage()
787 {
788 char buff[8];
789 int lcid = MAKELCID(LOWORD(GetKeyboardLayout(0)), SORT_DEFAULT);
790 int cp = GetACP();
791
792 if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff))) {
793 cp = atoi(buff);
794 }
795 return cp;
796 }
797
798 static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, PBYTE keystate, LPWSTR wchars, int wsize, UINT flags)
799 {
800 BYTE chars[2];
801
802 if (ToAsciiEx(vkey, scancode, keystate, (WORD*)chars, 0, GetKeyboardLayout(0)) == 1) {
803 return MultiByteToWideChar(codepage, 0, chars, 1, wchars, wsize);
804 }
805 return 0;
806 }
807