[IMM32] Rewrite ImmGetDescriptionA/W (#3780)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Sat, 3 Jul 2021 23:18:15 +0000 (08:18 +0900)
committerGitHub <noreply@github.com>
Sat, 3 Jul 2021 23:18:15 +0000 (08:18 +0900)
CORE-11700

dll/win32/imm32/imm.c
sdk/include/reactos/imm32_undoc.h [new file with mode: 0644]

index 45be160..ca026d4 100644 (file)
 #include "winreg.h"
 #include "wine/list.h"
 #ifdef __REACTOS__
+#include <stdlib.h>
 #include <ndk/umtypes.h>
 #include <ndk/pstypes.h>
 #include "../../../win32ss/include/ntuser.h"
+#include <imm32_undoc.h>
+#include <strsafe.h>
 #endif
 
 WINE_DEFAULT_DEBUG_CHANNEL(imm);
@@ -1765,6 +1768,22 @@ HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
 UINT WINAPI ImmGetDescriptionA(
   HKL hKL, LPSTR lpszDescription, UINT uBufLen)
 {
+#ifdef __REACTOS__
+    IMEINFOEX info;
+    size_t cch;
+
+    TRACE("ImmGetDescriptionA(%p,%p,%d)\n", hKL, lpszDescription, uBufLen);
+
+    if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) || !IS_IME_KBDLAYOUT(hKL))
+        return 0;
+
+    StringCchLengthW(info.wszImeDescription, _countof(info.wszImeDescription), &cch);
+    cch = WideCharToMultiByte(CP_ACP, 0, info.wszImeDescription, (INT)cch,
+                              lpszDescription, uBufLen, NULL, NULL);
+    if (uBufLen)
+        lpszDescription[cch] = 0;
+    return cch;
+#else
   WCHAR *buf;
   DWORD len;
 
@@ -1793,6 +1812,7 @@ UINT WINAPI ImmGetDescriptionA(
     return 0;
 
   return len - 1;
+#endif
 }
 
 /***********************************************************************
@@ -1800,6 +1820,21 @@ UINT WINAPI ImmGetDescriptionA(
  */
 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
 {
+#ifdef __REACTOS__
+    IMEINFOEX info;
+    size_t cch;
+
+    TRACE("ImmGetDescriptionW(%p, %p, %d)\n", hKL, lpszDescription, uBufLen);
+
+    if (!ImmGetImeInfoEx(&info, ImeInfoExKeyboardLayout, &hKL) || !IS_IME_KBDLAYOUT(hKL))
+        return 0;
+
+    if (uBufLen != 0)
+        StringCchCopyW(lpszDescription, uBufLen, info.wszImeDescription);
+
+    StringCchLengthW(info.wszImeDescription, _countof(info.wszImeDescription), &cch);
+    return (UINT)cch;
+#else
   static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
 
   FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
@@ -1808,6 +1843,7 @@ UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
   if (!uBufLen) return lstrlenW( name );
   lstrcpynW( lpszDescription, name, uBufLen );
   return lstrlenW( lpszDescription );
+#endif
 }
 
 /***********************************************************************
diff --git a/sdk/include/reactos/imm32_undoc.h b/sdk/include/reactos/imm32_undoc.h
new file mode 100644 (file)
index 0000000..32858af
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     Private header for imm32.dll
+ * COPYRIGHT:   Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
+ */
+
+#pragma once
+
+#define KBDLAYOUT_MASK 0xF000
+#define KBDLAYOUT_IME 0xE000
+#define IS_IME_KBDLAYOUT(hKL) ((HIWORD(hKL) & KBDLAYOUT_MASK) == KBDLAYOUT_IME)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+BOOL WINAPI
+ImmGetImeInfoEx(PIMEINFOEX pImeInfoEx, IMEINFOEXCLASS SearchType, PVOID pvSearchKey);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif