https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ef003fa47d2d7bdb70ce2…
commit ef003fa47d2d7bdb70ce26dd2b08160f0143125e
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Sep 28 22:03:25 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Sep 28 22:03:25 2021 +0900
[IMM32] Rewrite ImmAssociateContext (#3979)
CORE-11700
---
dll/win32/imm32/imm.c | 87 ++++++++++++++-------------------------------------
1 file changed, 23 insertions(+), 64 deletions(-)
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 135b7afc6ee..ab97e052c9a 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -169,87 +169,46 @@ static InputContextData* get_imc_data(HIMC hIMC)
return data;
}
-static HIMC get_default_context( HWND hwnd )
-{
- FIXME("Don't use this function\n");
- return FALSE;
-}
-
-static BOOL IMM_IsCrossThreadAccess(HWND hWnd, HIMC hIMC)
-{
- InputContextData *data;
-
- if (hWnd)
- {
- DWORD thread = GetWindowThreadProcessId(hWnd, NULL);
- if (thread != GetCurrentThreadId()) return TRUE;
- }
- data = get_imc_data(hIMC);
- if (data && data->threadID != GetCurrentThreadId())
- return TRUE;
-
- return FALSE;
-}
-
/***********************************************************************
* ImmAssociateContext (IMM32.@)
*/
HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
{
- HIMC old = NULL;
- InputContextData *data = get_imc_data(hIMC);
+ PWND pWnd;
+ HWND hwndFocus;
+ DWORD dwValue;
+ HIMC hOldIMC;
- TRACE("(%p, %p):\n", hWnd, hIMC);
+ TRACE("(%p, %p)\n", hWnd, hIMC);
- if(hIMC && !data)
+ if (!Imm32IsImmMode())
return NULL;
- /*
- * If already associated just return
- */
- if (hIMC && data->IMC.hWnd == hWnd)
- return hIMC;
-
- if (hIMC && IMM_IsCrossThreadAccess(hWnd, hIMC))
+ pWnd = ValidateHwndNoErr(hWnd);
+ if (!pWnd)
return NULL;
- if (hWnd)
- {
- HIMC defaultContext = get_default_context( hWnd );
- old = RemovePropW(hWnd,szwWineIMCProperty);
-
- if (old == NULL)
- old = defaultContext;
- else if (old == (HIMC)-1)
- old = NULL;
-
- if (hIMC != defaultContext)
- {
- if (hIMC == NULL) /* Meaning disable imm for that window*/
- SetPropW(hWnd,szwWineIMCProperty,(HANDLE)-1);
- else
- SetPropW(hWnd,szwWineIMCProperty,hIMC);
- }
+ if (hIMC && Imm32IsCrossThreadAccess(hIMC))
+ return NULL;
- if (old)
- {
- InputContextData *old_data = (InputContextData *)old;
- if (old_data->IMC.hWnd == hWnd)
- old_data->IMC.hWnd = NULL;
- }
- }
+ hOldIMC = pWnd->hImc;
+ if (hOldIMC == hIMC)
+ return hIMC;
- if (!hIMC)
- return old;
+ dwValue = NtUserAssociateInputContext(hWnd, hIMC, 0);
+ if (dwValue == 0)
+ return hOldIMC;
+ if (dwValue != 1)
+ return NULL;
- if(GetActiveWindow() == data->IMC.hWnd)
+ hwndFocus = (HWND)NtUserQueryWindow(hWnd, QUERY_WINDOW_FOCUS);
+ if (hwndFocus == hWnd)
{
- SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
- data->IMC.hWnd = hWnd;
- SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
+ ImmSetActiveContext(hWnd, hOldIMC, FALSE);
+ ImmSetActiveContext(hWnd, hIMC, TRUE);
}
- return old;
+ return hOldIMC;
}
/***********************************************************************