Commit e242e094 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

imm32: Rewrite ImmGetDescription(A|W).

parent 85489a53
...@@ -1728,52 +1728,49 @@ HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd) ...@@ -1728,52 +1728,49 @@ HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
} }
/*********************************************************************** /***********************************************************************
* ImmGetDescriptionA (IMM32.@) * ImmGetDescriptionA (IMM32.@)
*/ */
UINT WINAPI ImmGetDescriptionA( UINT WINAPI ImmGetDescriptionA( HKL hkl, LPSTR bufferA, UINT lengthA )
HKL hKL, LPSTR lpszDescription, UINT uBufLen)
{ {
WCHAR *buf; WCHAR *bufferW;
DWORD len; DWORD lengthW;
TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
/* find out how many characters in the unicode buffer */
len = ImmGetDescriptionW( hKL, NULL, 0 );
if (!len)
return 0;
/* allocate a buffer of that size */
buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
if( !buf )
return 0;
/* fetch the unicode buffer */
len = ImmGetDescriptionW( hKL, buf, len + 1 );
/* convert it back to ANSI */
len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
lpszDescription, uBufLen, NULL, NULL );
HeapFree( GetProcessHeap(), 0, buf ); TRACE( "hkl %p, bufferA %p, lengthA %d\n", hkl, bufferA, lengthA );
if (len == 0) if (!(lengthW = ImmGetDescriptionW( hkl, NULL, 0 ))) return 0;
return 0; if (!(bufferW = malloc( (lengthW + 1) * sizeof(WCHAR) ))) return 0;
lengthW = ImmGetDescriptionW( hkl, bufferW, lengthW + 1 );
lengthA = WideCharToMultiByte( CP_ACP, 0, bufferW, lengthW, bufferA,
bufferA ? lengthA : 0, NULL, NULL );
if (bufferA) bufferA[lengthA] = 0;
free( bufferW );
return len - 1; return lengthA;
} }
/*********************************************************************** /***********************************************************************
* ImmGetDescriptionW (IMM32.@) * ImmGetDescriptionW (IMM32.@)
*/ */
UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen) UINT WINAPI ImmGetDescriptionW( HKL hkl, WCHAR *buffer, UINT length )
{ {
FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen); WCHAR path[MAX_PATH];
HKEY hkey = 0;
DWORD size;
TRACE( "hkl %p, buffer %p, length %u\n", hkl, buffer, length );
swprintf( path, ARRAY_SIZE(path), layouts_formatW, (ULONG)(ULONG_PTR)hkl );
if (RegOpenKeyW( HKEY_LOCAL_MACHINE, path, &hkey )) return 0;
if (!hKL) return 0; size = ARRAY_SIZE(path) * sizeof(WCHAR);
if (!uBufLen) return lstrlenW(L"Wine XIM" ); if (RegGetValueW( hkey, NULL, L"Layout Text", RRF_RT_REG_SZ, NULL, path, &size )) *path = 0;
lstrcpynW( lpszDescription, L"Wine XIM", uBufLen ); RegCloseKey( hkey );
return lstrlenW( lpszDescription );
size = wcslen( path );
if (!buffer) return size;
lstrcpynW( buffer, path, length );
return wcslen( buffer );
} }
/*********************************************************************** /***********************************************************************
......
...@@ -2851,10 +2851,8 @@ static void test_ImmGetDescription(void) ...@@ -2851,10 +2851,8 @@ static void test_ImmGetDescription(void)
ret = ImmGetDescriptionA( NULL, NULL, 100 ); ret = ImmGetDescriptionA( NULL, NULL, 100 );
ok( !ret, "ImmGetDescriptionA returned %lu\n", ret ); ok( !ret, "ImmGetDescriptionA returned %lu\n", ret );
ret = ImmGetDescriptionW( hkl, bufferW, 100 ); ret = ImmGetDescriptionW( hkl, bufferW, 100 );
todo_wine
ok( !ret, "ImmGetDescriptionW returned %lu\n", ret ); ok( !ret, "ImmGetDescriptionW returned %lu\n", ret );
ret = ImmGetDescriptionA( hkl, bufferA, 100 ); ret = ImmGetDescriptionA( hkl, bufferA, 100 );
todo_wine
ok( !ret, "ImmGetDescriptionA returned %lu\n", ret ); ok( !ret, "ImmGetDescriptionA returned %lu\n", ret );
ret = GetLastError(); ret = GetLastError();
ok( ret == 0xdeadbeef, "got error %lu\n", ret ); ok( ret == 0xdeadbeef, "got error %lu\n", ret );
...@@ -2868,46 +2866,33 @@ static void test_ImmGetDescription(void) ...@@ -2868,46 +2866,33 @@ static void test_ImmGetDescription(void)
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetDescriptionA( hkl, bufferA, 2 ); ret = ImmGetDescriptionA( hkl, bufferA, 2 );
ok( ret == 0, "ImmGetDescriptionA returned %lu\n", ret ); ok( ret == 0, "ImmGetDescriptionA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetDescriptionW( hkl, bufferW, 11 ); ret = ImmGetDescriptionW( hkl, bufferW, 11 );
todo_wine
ok( ret == 10, "ImmGetDescriptionW returned %lu\n", ret ); ok( ret == 10, "ImmGetDescriptionW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, L"WineTest I" ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, L"WineTest I" ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetDescriptionA( hkl, bufferA, 11 ); ret = ImmGetDescriptionA( hkl, bufferA, 11 );
todo_wine
ok( ret == 0, "ImmGetDescriptionA returned %lu\n", ret ); ok( ret == 0, "ImmGetDescriptionA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetDescriptionW( hkl, bufferW, 12 ); ret = ImmGetDescriptionW( hkl, bufferW, 12 );
todo_wine
ok( ret == 11, "ImmGetDescriptionW returned %lu\n", ret ); ok( ret == 11, "ImmGetDescriptionW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, L"WineTest IM" ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, L"WineTest IM" ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetDescriptionA( hkl, bufferA, 12 ); ret = ImmGetDescriptionA( hkl, bufferA, 12 );
todo_wine
ok( ret == 12, "ImmGetDescriptionA returned %lu\n", ret ); ok( ret == 12, "ImmGetDescriptionA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "WineTest IME" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "WineTest IME" ), "got bufferA %s\n", debugstr_a(bufferA) );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetDescriptionW( hkl, bufferW, 13 ); ret = ImmGetDescriptionW( hkl, bufferW, 13 );
todo_wine
ok( ret == 12, "ImmGetDescriptionW returned %lu\n", ret ); ok( ret == 12, "ImmGetDescriptionW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, L"WineTest IME" ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, L"WineTest IME" ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetDescriptionA( hkl, bufferA, 13 ); ret = ImmGetDescriptionA( hkl, bufferA, 13 );
todo_wine
ok( ret == 12, "ImmGetDescriptionA returned %lu\n", ret ); ok( ret == 12, "ImmGetDescriptionA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "WineTest IME" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "WineTest IME" ), "got bufferA %s\n", debugstr_a(bufferA) );
ime_cleanup( hkl ); ime_cleanup( hkl );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment