From 62ad2403a094658375595e4cafa54c50e0fea4c5 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Sat, 14 Jun 2025 20:26:05 +0900 Subject: [PATCH] [USER32][COMCTL32] Edit: Optimize EDIT_SetCaretPos for speed (#8113) The caret move on IME was slow until this PR. JIRA issue: CORE-19268 - Don't use ImmIsIME but use IS_IME_HKL(hKL) in EDIT_SetCaretPos function. This change improves the caret speed. - Prohibit display of composition window for Korean in the handling of WM_IME_SETCONTEXT and WM_IME_STARTCOMPOSITION, because Korean doesn't want it. --- dll/win32/comctl32/edit.c | 57 +++++++++++++++++------------ win32ss/user/user32/controls/edit.c | 57 +++++++++++++++++------------ 2 files changed, 66 insertions(+), 48 deletions(-) diff --git a/dll/win32/comctl32/edit.c b/dll/win32/comctl32/edit.c index 8670e86f5c2..045a9ce18f7 100644 --- a/dll/win32/comctl32/edit.c +++ b/dll/win32/comctl32/edit.c @@ -1762,10 +1762,8 @@ static void EDIT_SetCaretPos(EDITSTATE *es, INT pos, SetCaretPos(pt.x, pt.y); - if (!ImmIsIME(hKL)) - return; - - EDIT_ImmSetCompositionWindow(es, pt); + if (IS_IME_HKL(hKL)) + EDIT_ImmSetCompositionWindow(es, pt); #else TRACE("%d - %dx%d\n", pos, (short)LOWORD(res), (short)HIWORD(res)); SetCaretPos((short)LOWORD(res), (short)HIWORD(res)); @@ -3884,7 +3882,7 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw) ShowCaret(es->hwndSelf); } #ifdef __REACTOS__ - if (ImmIsIME(GetKeyboardLayout(0))) + if (IS_IME_HKL(GetKeyboardLayout(0))) { LOGFONTW lf; HIMC hIMC = ImmGetContext(es->hwndSelf); @@ -5181,32 +5179,43 @@ static LRESULT CALLBACK EDIT_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR /* IME messages to make the edit control IME aware */ case WM_IME_SETCONTEXT: #ifdef __REACTOS__ - if (FALSE) /* FIXME: Condition */ - lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; - - if (wParam) { - HIMC hIMC = ImmGetContext(hwnd); - LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC); - if (pIC) - { - pIC->dwUIFlags &= ~0x40000; - ImmUnlockIMC(hIMC); - } - if (FALSE) /* FIXME: Condition */ - ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); - ImmReleaseContext(hwnd, hIMC); - } + HKL hKL = GetKeyboardLayout(0); - result = DefWindowProcW(hwnd, msg, wParam, lParam); + /* Korean doesn't want composition window */ + if (PRIMARYLANGID(LOWORD(hKL)) == LANG_KOREAN) + lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; + + if (wParam) + { + HIMC hIMC = ImmGetContext(hwnd); + LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC); + if (pIC) + { + pIC->dwUIFlags &= ~0x40000; + ImmUnlockIMC(hIMC); + } + if (FALSE) /* FIXME: Condition */ + ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); + ImmReleaseContext(hwnd, hIMC); + } + + result = DefWindowProcW(hwnd, msg, wParam, lParam); + } #endif break; case WM_IME_STARTCOMPOSITION: #ifdef __REACTOS__ - if (FALSE) /* FIXME: Condition */ - return TRUE; - result = DefWindowProcW(hwnd, msg, wParam, lParam); + { + HKL hKL = GetKeyboardLayout(0); + + /* Korean doesn't want composition window */ + if (PRIMARYLANGID(LOWORD(hKL)) == LANG_KOREAN) + return TRUE; + + result = DefWindowProcW(hwnd, msg, wParam, lParam); + } #else es->composition_start = es->selection_end; es->composition_len = 0; diff --git a/win32ss/user/user32/controls/edit.c b/win32ss/user/user32/controls/edit.c index a19690f8cd7..b6bf0704028 100644 --- a/win32ss/user/user32/controls/edit.c +++ b/win32ss/user/user32/controls/edit.c @@ -1914,10 +1914,8 @@ static void EDIT_SetCaretPos(EDITSTATE *es, INT pos, SetCaretPos(pt.x, pt.y); - if (!ImmIsIME(hKL)) - return; - - EDIT_ImmSetCompositionWindow(es, pt); + if (IS_IME_HKL(hKL)) + EDIT_ImmSetCompositionWindow(es, pt); #else TRACE("%d - %dx%d\n", pos, (short)LOWORD(res), (short)HIWORD(res)); SetCaretPos((short)LOWORD(res), (short)HIWORD(res)); @@ -4038,7 +4036,7 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw) ShowCaret(es->hwndSelf); } #ifdef __REACTOS__ - if (ImmIsIME(GetKeyboardLayout(0))) + if (IS_IME_HKL(GetKeyboardLayout(0))) { LOGFONTW lf; HIMC hIMC = ImmGetContext(es->hwndSelf); @@ -5387,32 +5385,43 @@ LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP /* IME messages to make the edit control IME aware */ case WM_IME_SETCONTEXT: #ifdef __REACTOS__ - if (FALSE) /* FIXME: Condition */ - lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; - - if (wParam) { - HIMC hIMC = ImmGetContext(hwnd); - LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC); - if (pIC) - { - pIC->dwUIFlags &= ~0x40000; - ImmUnlockIMC(hIMC); - } - if (GetWin32ClientInfo()->CI_flags & CI_WOW) - ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); - ImmReleaseContext(hwnd, hIMC); - } + HKL hKL = GetKeyboardLayout(0); - result = DefWindowProcT(hwnd, WM_IME_SETCONTEXT, wParam, lParam, unicode); + /* Korean doesn't want composition window */ + if (PRIMARYLANGID(LOWORD(hKL)) == LANG_KOREAN) + lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; + + if (wParam) + { + HIMC hIMC = ImmGetContext(hwnd); + LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC); + if (pIC) + { + pIC->dwUIFlags &= ~0x40000; + ImmUnlockIMC(hIMC); + } + if (GetWin32ClientInfo()->CI_flags & CI_WOW) + ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); + ImmReleaseContext(hwnd, hIMC); + } + + result = DefWindowProcT(hwnd, WM_IME_SETCONTEXT, wParam, lParam, unicode); + } #endif break; case WM_IME_STARTCOMPOSITION: #ifdef __REACTOS__ - if (FALSE) /* FIXME: Condition */ - return TRUE; - result = DefWindowProcT(hwnd, msg, wParam, lParam, unicode); + { + HKL hKL = GetKeyboardLayout(0); + + /* Korean doesn't want composition window */ + if (PRIMARYLANGID(LOWORD(hKL)) == LANG_KOREAN) + return TRUE; + + result = DefWindowProcT(hwnd, msg, wParam, lParam, unicode); + } #else es->composition_start = es->selection_end; es->composition_len = 0;