https://git.reactos.org/?p=reactos.git;a=commitdiff;h=19d24143e92eb65b2a85b…
commit 19d24143e92eb65b2a85bf26c87d275b38c306d2
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Aug 14 10:39:20 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Aug 14 10:39:20 2021 +0900
[IMM32] Rewrite ImmGetRegisterWordStyleA/W (#3901)
- Rewrite ImmGetRegisterWordStyleA and ImmGetRegisterWordStyleW functions.
- Modify win32ss/include/imetable.h.
CORE-11700
---
dll/win32/imm32/imm.c | 127 +++++++++++++++++++++++++++++++++------------
win32ss/include/imetable.h | 2 +-
2 files changed, 96 insertions(+), 33 deletions(-)
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 29e8aba138d..c3ea57fb2cd 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -3087,26 +3087,58 @@ DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
UINT WINAPI ImmGetRegisterWordStyleA(
HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
{
- ImmHkl *immHkl = IMM_GetImmHkl(hKL);
- TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
- if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
+ UINT iItem, ret = 0;
+ PIMEDPI pImeDpi;
+ LPSTYLEBUFA pDestA;
+ LPSTYLEBUFW pSrcW, pNewStylesW = NULL;
+ size_t cchW;
+ INT cchA;
+
+ TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf);
+
+ pImeDpi = ImmLockOrLoadImeDpi(hKL);
+ if (!pImeDpi)
+ return 0;
+
+ if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE))
{
- if (!is_kbd_ime_unicode(immHkl))
- return immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)lpStyleBuf);
- else
- {
- STYLEBUFW sbw;
- UINT rc;
+ ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf);
+ goto Quit;
+ }
- rc = immHkl->pImeGetRegisterWordStyle(nItem,&sbw);
- WideCharToMultiByte(CP_ACP, 0, sbw.szDescription, -1,
- lpStyleBuf->szDescription, 32, NULL, NULL);
- lpStyleBuf->dwStyle = sbw.dwStyle;
- return rc;
+ if (nItem > 0)
+ {
+ pNewStylesW = Imm32HeapAlloc(0, nItem * sizeof(STYLEBUFW));
+ if (!pNewStylesW)
+ goto Quit;
+ }
+
+ ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesW);
+
+ if (nItem > 0)
+ {
+ /* lpStyleBuf <-- pNewStylesW */
+ for (iItem = 0; iItem < ret; ++iItem)
+ {
+ pSrcW = &pNewStylesW[iItem];
+ pDestA = &lpStyleBuf[iItem];
+ pDestA->dwStyle = pSrcW->dwStyle;
+ StringCchLengthW(pSrcW->szDescription, _countof(pSrcW->szDescription),
&cchW);
+ cchA = WideCharToMultiByte(CP_ACP, MB_PRECOMPOSED,
+ pSrcW->szDescription, (INT)cchW,
+ pDestA->szDescription,
_countof(pDestA->szDescription),
+ NULL, NULL);
+ if (cchA > _countof(pDestA->szDescription) - 1)
+ cchA = _countof(pDestA->szDescription) - 1;
+ pDestA->szDescription[cchA] = 0;
}
}
- else
- return 0;
+
+Quit:
+ if (pNewStylesW)
+ HeapFree(g_hImm32Heap, 0, pNewStylesW);
+ ImmUnlockImeDpi(pImeDpi);
+ return ret;
}
/***********************************************************************
@@ -3115,26 +3147,57 @@ UINT WINAPI ImmGetRegisterWordStyleA(
UINT WINAPI ImmGetRegisterWordStyleW(
HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
{
- ImmHkl *immHkl = IMM_GetImmHkl(hKL);
- TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
- if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
+ UINT iItem, ret = 0;
+ PIMEDPI pImeDpi;
+ LPSTYLEBUFA pSrcA, pNewStylesA = NULL;
+ LPSTYLEBUFW pDestW;
+ size_t cchA;
+ INT cchW;
+
+ TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf);
+
+ pImeDpi = ImmLockOrLoadImeDpi(hKL);
+ if (!pImeDpi)
+ return 0;
+
+ if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)
{
- if (is_kbd_ime_unicode(immHkl))
- return immHkl->pImeGetRegisterWordStyle(nItem,lpStyleBuf);
- else
- {
- STYLEBUFA sba;
- UINT rc;
+ ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf);
+ goto Quit;
+ }
- rc = immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)&sba);
- MultiByteToWideChar(CP_ACP, 0, sba.szDescription, -1,
- lpStyleBuf->szDescription, 32);
- lpStyleBuf->dwStyle = sba.dwStyle;
- return rc;
+ if (nItem > 0)
+ {
+ pNewStylesA = Imm32HeapAlloc(0, nItem * sizeof(STYLEBUFA));
+ if (!pNewStylesA)
+ goto Quit;
+ }
+
+ ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesA);
+
+ if (nItem > 0)
+ {
+ /* lpStyleBuf <-- pNewStylesA */
+ for (iItem = 0; iItem < ret; ++iItem)
+ {
+ pSrcA = &pNewStylesA[iItem];
+ pDestW = &lpStyleBuf[iItem];
+ pDestW->dwStyle = pSrcA->dwStyle;
+ StringCchLengthA(pSrcA->szDescription, _countof(pSrcA->szDescription),
&cchA);
+ cchW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
+ pSrcA->szDescription, (INT)cchA,
+ pDestW->szDescription,
_countof(pDestW->szDescription));
+ if (cchW > _countof(pDestW->szDescription) - 1)
+ cchW = _countof(pDestW->szDescription) - 1;
+ pDestW->szDescription[cchW] = 0;
}
}
- else
- return 0;
+
+Quit:
+ if (pNewStylesA)
+ HeapFree(g_hImm32Heap, 0, pNewStylesA);
+ ImmUnlockImeDpi(pImeDpi);
+ return ret;
}
/***********************************************************************
diff --git a/win32ss/include/imetable.h b/win32ss/include/imetable.h
index 3bfd5c1d562..2385e812e3a 100644
--- a/win32ss/include/imetable.h
+++ b/win32ss/include/imetable.h
@@ -3,7 +3,7 @@ DEFINE_IME_ENTRY(BOOL, ImeInquire, (LPIMEINFO lpIMEInfo, LPVOID
lpszWndClass, DW
DEFINE_IME_ENTRY(DWORD, ImeConversionList, (HIMC hIMC, LPCVOID lpSrc, LPCANDIDATELIST
lpDst, DWORD dwBufLen, UINT uFlag), FALSE)
DEFINE_IME_ENTRY(BOOL, ImeRegisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID
lpszString), FALSE)
DEFINE_IME_ENTRY(BOOL, ImeUnregisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID
lpszString), FALSE)
-DEFINE_IME_ENTRY(UINT, ImeGetRegisterWordStyle, (UINT nItem, LPSTYLEBUFW lpStyleBuf),
FALSE)
+DEFINE_IME_ENTRY(UINT, ImeGetRegisterWordStyle, (UINT nItem, LPVOID lpStyleBuf), FALSE)
DEFINE_IME_ENTRY(UINT, ImeEnumRegisterWord, (HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString, LPVOID lpData), FALSE)
DEFINE_IME_ENTRY(BOOL, ImeConfigure, (HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData),
FALSE)
DEFINE_IME_ENTRY(BOOL, ImeDestroy, (UINT uReserved), FALSE)