[PATCH v2 4/4] user32: Move (Un)LoadKeyboardLayoutW from winex11.drv to user32.

Rémi Bernon rbernon at codeweavers.com
Fri Apr 23 12:30:08 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/user32/driver.c              | 26 ---------------
 dlls/user32/input.c               | 53 ++++++++++++++++++++++++++-----
 dlls/user32/user_private.h        |  2 --
 dlls/winex11.drv/keyboard.c       | 21 ------------
 dlls/winex11.drv/winex11.drv.spec |  2 --
 5 files changed, 45 insertions(+), 59 deletions(-)

diff --git a/dlls/user32/driver.c b/dlls/user32/driver.c
index 7f26a48657f..ac045148abf 100644
--- a/dlls/user32/driver.c
+++ b/dlls/user32/driver.c
@@ -111,11 +111,9 @@ static const USER_DRIVER *load_driver(void)
         GET_USER_FUNC(GetKeyboardLayout);
         GET_USER_FUNC(GetKeyboardLayoutList);
         GET_USER_FUNC(GetKeyboardLayoutName);
-        GET_USER_FUNC(LoadKeyboardLayout);
         GET_USER_FUNC(MapVirtualKeyEx);
         GET_USER_FUNC(RegisterHotKey);
         GET_USER_FUNC(ToUnicodeEx);
-        GET_USER_FUNC(UnloadKeyboardLayout);
         GET_USER_FUNC(UnregisterHotKey);
         GET_USER_FUNC(VkKeyScanEx);
         GET_USER_FUNC(DestroyCursorIcon);
@@ -268,11 +266,6 @@ static BOOL CDECL nulldrv_GetKeyboardLayoutName( LPWSTR name )
     return FALSE;
 }
 
-static HKL CDECL nulldrv_LoadKeyboardLayout( LPCWSTR name, UINT flags )
-{
-    return 0;
-}
-
 static UINT CDECL nulldrv_MapVirtualKeyEx( UINT code, UINT type, HKL layout )
 {
     return 0;
@@ -289,11 +282,6 @@ static INT CDECL nulldrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state, L
     return default_ret;
 }
 
-static BOOL CDECL nulldrv_UnloadKeyboardLayout( HKL layout )
-{
-    return 0;
-}
-
 static void CDECL nulldrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
 {
 }
@@ -489,11 +477,9 @@ static USER_DRIVER null_driver =
     nulldrv_GetKeyboardLayout,
     nulldrv_GetKeyboardLayoutList,
     nulldrv_GetKeyboardLayoutName,
-    nulldrv_LoadKeyboardLayout,
     nulldrv_MapVirtualKeyEx,
     nulldrv_RegisterHotKey,
     nulldrv_ToUnicodeEx,
-    nulldrv_UnloadKeyboardLayout,
     nulldrv_UnregisterHotKey,
     nulldrv_VkKeyScanEx,
     /* cursor/icon functions */
@@ -576,11 +562,6 @@ static BOOL CDECL loaderdrv_GetKeyboardLayoutName( LPWSTR name )
     return load_driver()->pGetKeyboardLayoutName( name );
 }
 
-static HKL CDECL loaderdrv_LoadKeyboardLayout( LPCWSTR name, UINT flags )
-{
-    return load_driver()->pLoadKeyboardLayout( name, flags );
-}
-
 static UINT CDECL loaderdrv_MapVirtualKeyEx( UINT code, UINT type, HKL layout )
 {
     return load_driver()->pMapVirtualKeyEx( code, type, layout );
@@ -597,11 +578,6 @@ static INT CDECL loaderdrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
     return load_driver()->pToUnicodeEx( virt, scan, state, str, size, flags, layout, default_ret );
 }
 
-static BOOL CDECL loaderdrv_UnloadKeyboardLayout( HKL layout )
-{
-    return load_driver()->pUnloadKeyboardLayout( layout );
-}
-
 static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
 {
     load_driver()->pUnregisterHotKey( hwnd, modifiers, vk );
@@ -704,11 +680,9 @@ static USER_DRIVER lazy_load_driver =
     loaderdrv_GetKeyboardLayout,
     loaderdrv_GetKeyboardLayoutList,
     loaderdrv_GetKeyboardLayoutName,
-    loaderdrv_LoadKeyboardLayout,
     loaderdrv_MapVirtualKeyEx,
     loaderdrv_RegisterHotKey,
     loaderdrv_ToUnicodeEx,
-    loaderdrv_UnloadKeyboardLayout,
     loaderdrv_UnregisterHotKey,
     loaderdrv_VkKeyScanEx,
     /* cursor/icon functions */
diff --git a/dlls/user32/input.c b/dlls/user32/input.c
index dbe00ee88cc..c4d89a8954e 100644
--- a/dlls/user32/input.c
+++ b/dlls/user32/input.c
@@ -77,6 +77,43 @@ static WORD get_key_state(void)
 }
 
 
+/***********************************************************************
+ *           get_locale_kbd_layout
+ */
+static HKL get_locale_kbd_layout(void)
+{
+    ULONG_PTR layout;
+    LANGID langid;
+
+    /* FIXME:
+     *
+     * layout = main_key_tab[kbd_layout].lcid;
+     *
+     * Winword uses return value of GetKeyboardLayout as a codepage
+     * to translate ANSI keyboard messages to unicode. But we have
+     * a problem with it: for instance Polish keyboard layout is
+     * identical to the US one, and therefore instead of the Polish
+     * locale id we return the US one.
+     */
+
+    layout = GetUserDefaultLCID();
+
+    /*
+     * Microsoft Office expects this value to be something specific
+     * for Japanese and Korean Windows with an IME the value is 0xe001
+     * We should probably check to see if an IME exists and if so then
+     * set this word properly.
+     */
+    langid = PRIMARYLANGID(LANGIDFROMLCID(layout));
+    if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
+        layout = MAKELONG( layout, 0xe001 ); /* IME */
+    else
+        layout |= layout << 16;
+
+    return (HKL)layout;
+}
+
+
 /**********************************************************************
  *		set_capture_window
  */
@@ -1086,11 +1123,11 @@ BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
 /***********************************************************************
  *		LoadKeyboardLayoutW (USER32.@)
  */
-HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
+HKL WINAPI LoadKeyboardLayoutW( const WCHAR *name, UINT flags )
 {
-    TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
-
-    return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
+    FIXME_(keyboard)( "name %s, flags %x, semi-stub!\n", debugstr_w( name ), flags );
+    /* FIXME: semi-stub: returning default layout */
+    return get_locale_kbd_layout();
 }
 
 /***********************************************************************
@@ -1113,11 +1150,11 @@ HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
 /***********************************************************************
  *		UnloadKeyboardLayout (USER32.@)
  */
-BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
+BOOL WINAPI UnloadKeyboardLayout( HKL layout )
 {
-    TRACE_(keyboard)("(%p)\n", hkl);
-
-    return USER_Driver->pUnloadKeyboardLayout(hkl);
+    FIXME_(keyboard)( "layout %p, stub!\n", layout );
+    SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
+    return FALSE;
 }
 
 typedef struct __TRACKINGLIST {
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 98eec94da57..49ddc6f67b4 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -68,11 +68,9 @@ typedef struct tagUSER_DRIVER {
     HKL    (CDECL *pGetKeyboardLayout)(DWORD);
     UINT   (CDECL *pGetKeyboardLayoutList)(INT, HKL *);
     BOOL   (CDECL *pGetKeyboardLayoutName)(LPWSTR);
-    HKL    (CDECL *pLoadKeyboardLayout)(LPCWSTR, UINT);
     UINT   (CDECL *pMapVirtualKeyEx)(UINT, UINT, HKL);
     BOOL   (CDECL *pRegisterHotKey)(HWND, UINT, UINT);
     INT    (CDECL *pToUnicodeEx)(UINT, UINT, const BYTE *, LPWSTR, int, UINT, HKL, INT);
-    BOOL   (CDECL *pUnloadKeyboardLayout)(HKL);
     void   (CDECL *pUnregisterHotKey)(HWND, UINT, UINT);
     SHORT  (CDECL *pVkKeyScanEx)(WCHAR, HKL);
     /* cursor/icon functions */
diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c
index 82dd67d9373..ae6ff0e3d54 100644
--- a/dlls/winex11.drv/keyboard.c
+++ b/dlls/winex11.drv/keyboard.c
@@ -1906,27 +1906,6 @@ HKL CDECL X11DRV_GetKeyboardLayout(DWORD dwThreadid)
 }
 
 
-/***********************************************************************
- *		LoadKeyboardLayout (X11DRV.@)
- */
-HKL CDECL X11DRV_LoadKeyboardLayout(LPCWSTR name, UINT flags)
-{
-    FIXME("%s, %04x: semi-stub! Returning default layout.\n", debugstr_w(name), flags);
-    return get_locale_kbd_layout();
-}
-
-
-/***********************************************************************
- *		UnloadKeyboardLayout (X11DRV.@)
- */
-BOOL CDECL X11DRV_UnloadKeyboardLayout(HKL hkl)
-{
-    FIXME("%p: stub!\n", hkl);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
 /***********************************************************************
  *		ActivateKeyboardLayout (X11DRV.@)
  */
diff --git a/dlls/winex11.drv/winex11.drv.spec b/dlls/winex11.drv/winex11.drv.spec
index 7aecac2c016..310186791f0 100644
--- a/dlls/winex11.drv/winex11.drv.spec
+++ b/dlls/winex11.drv/winex11.drv.spec
@@ -9,10 +9,8 @@
 @ cdecl GetKeyNameText(long ptr long) X11DRV_GetKeyNameText
 @ cdecl GetKeyboardLayout(long) X11DRV_GetKeyboardLayout
 @ cdecl GetKeyboardLayoutName(ptr) X11DRV_GetKeyboardLayoutName
-@ cdecl LoadKeyboardLayout(wstr long) X11DRV_LoadKeyboardLayout
 @ cdecl MapVirtualKeyEx(long long long) X11DRV_MapVirtualKeyEx
 @ cdecl ToUnicodeEx(long long ptr ptr long long long long) X11DRV_ToUnicodeEx
-@ cdecl UnloadKeyboardLayout(long) X11DRV_UnloadKeyboardLayout
 @ cdecl VkKeyScanEx(long long) X11DRV_VkKeyScanEx
 @ cdecl DestroyCursorIcon(long) X11DRV_DestroyCursorIcon
 @ cdecl SetCursor(long) X11DRV_SetCursor
-- 
2.31.0




More information about the wine-devel mailing list