src/video/wincommon/SDL_sysevents.c
changeset 1253 7c7ddaf195bf
parent 1251 86d0d01290ea
child 1272 94c0709f8856
     1.1 --- a/src/video/wincommon/SDL_sysevents.c	Thu Jan 19 08:53:12 2006 +0000
     1.2 +++ b/src/video/wincommon/SDL_sysevents.c	Thu Jan 19 09:09:32 2006 +0000
     1.3 @@ -79,6 +79,15 @@
     1.4  void (*WIN_WinPAINT)(_THIS, HDC hdc);
     1.5  extern void DIB_SwapGamma(_THIS);
     1.6  
     1.7 +/* Variables and support functions for SDL_ToUnicode() */
     1.8 +static int codepage;
     1.9 +static int Is9xME();
    1.10 +static int GetCodePage();
    1.11 +static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, BYTE *keystate, Uint16 *wchars, int wsize, UINT flags);
    1.12 +
    1.13 +ToUnicodeFN SDL_ToUnicode = ToUnicode9xME;
    1.14 +
    1.15 +
    1.16  #if defined(_WIN32_WCE)
    1.17  
    1.18  // dynamically load aygshell dll because we want SDL to work on HPC and be300
    1.19 @@ -622,6 +631,11 @@
    1.20  		}
    1.21  		return(0);
    1.22  
    1.23 +		case WM_INPUTLANGCHANGE: {
    1.24 +			codepage = GetCodePage();
    1.25 +		}
    1.26 +		return(TRUE);
    1.27 +
    1.28  		default: {
    1.29  			/* Special handling by the video driver */
    1.30  			if (HandleMessage) {
    1.31 @@ -728,6 +742,10 @@
    1.32  	/* Check for SDL_WINDOWID hack */
    1.33  	SDL_windowid = getenv("SDL_WINDOWID");
    1.34  
    1.35 +	/* Initialise variables for SDL_ToUnicode() */
    1.36 +	codepage = GetCodePage();
    1.37 +	SDL_ToUnicode = Is9xME() ? ToUnicode9xME : ToUnicode;
    1.38 +
    1.39  	app_registered = 1;
    1.40  	return(0);
    1.41  }
    1.42 @@ -751,3 +769,39 @@
    1.43  	app_registered = 0;
    1.44  }
    1.45  
    1.46 +/* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
    1.47 +
    1.48 +static int Is9xME()
    1.49 +{
    1.50 +	OSVERSIONINFO   info;
    1.51 +
    1.52 +	memset(&info, 0, sizeof(info));
    1.53 +	info.dwOSVersionInfoSize = sizeof(info);
    1.54 +	if (!GetVersionEx(&info)) {
    1.55 +		return 0;
    1.56 +	}
    1.57 +	return (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
    1.58 +}
    1.59 +
    1.60 +static int GetCodePage()
    1.61 +{
    1.62 +	char	buff[8];
    1.63 +	int	lcid = MAKELCID(LOWORD(GetKeyboardLayout(0)), SORT_DEFAULT);
    1.64 +	int	cp = GetACP();
    1.65 +
    1.66 +	if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff))) {
    1.67 +		cp = atoi(buff);
    1.68 +	}
    1.69 +	return cp;
    1.70 +}
    1.71 +
    1.72 +static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, PBYTE keystate, LPWSTR wchars, int wsize, UINT flags)
    1.73 +{
    1.74 +	BYTE	chars[2];
    1.75 +
    1.76 +	if (ToAsciiEx(vkey, scancode, keystate, (WORD*)chars, 0, GetKeyboardLayout(0)) == 1) {
    1.77 +		return MultiByteToWideChar(codepage, 0, chars, 1, wchars, wsize);
    1.78 +	}
    1.79 +	return 0;
    1.80 +}
    1.81 +