[IMM32] Rewrite ImmConfigureIMEA/W (#3956)

- Rewrite ImmConfigureIMEA and ImmConfigureIMEW functions.
- Add IMS_... macros for WM_IME_SYSTEM message, into <undocuser.h>.
- Delete useless strdupAtoW and strdupWtoA inline functions.
CORE-11700
This commit is contained in:
Katayama Hirofumi MZ 2021-09-13 12:47:15 +09:00 committed by GitHub
parent 158a479a4e
commit dc9c5826be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 152 additions and 92 deletions

View file

@ -1199,3 +1199,121 @@ BOOL WINAPI ImmSetConversionStatus(HIMC hIMC, DWORD fdwConversion, DWORD fdwSent
return TRUE;
}
/***********************************************************************
* ImmConfigureIMEA (IMM32.@)
*/
BOOL WINAPI ImmConfigureIMEA(HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
{
BOOL ret = FALSE;
PIMEDPI pImeDpi;
REGISTERWORDW RegWordW;
LPREGISTERWORDA pRegWordA;
TRACE("(%p, %p, 0x%lX, %p)", hKL, hWnd, dwMode, lpData);
if (!ValidateHwndNoErr(hWnd) || Imm32IsCrossProcessAccess(hWnd))
return FALSE;
pImeDpi = ImmLockOrLoadImeDpi(hKL);
if (!pImeDpi)
return FALSE;
RtlZeroMemory(&RegWordW, sizeof(RegWordW));
if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) || !lpData ||
dwMode != IME_CONFIG_REGISTERWORD)
{
goto DoIt;
}
pRegWordA = lpData;
if (pRegWordA->lpReading)
{
RegWordW.lpReading = Imm32WideFromAnsi(pRegWordA->lpReading);
if (!RegWordW.lpReading)
goto Quit;
}
if (pRegWordA->lpWord)
{
RegWordW.lpWord = Imm32WideFromAnsi(pRegWordA->lpWord);
if (!RegWordW.lpWord)
goto Quit;
}
lpData = &RegWordW;
DoIt:
SendMessageW(hWnd, WM_IME_SYSTEM, IMS_OPENPROPERTYWINDOW, 0);
ret = pImeDpi->ImeConfigure(hKL, hWnd, dwMode, lpData);
SendMessageW(hWnd, WM_IME_SYSTEM, IMS_CLOSEPROPERTYWINDOW, 0);
Quit:
if (RegWordW.lpReading)
HeapFree(g_hImm32Heap, 0, RegWordW.lpReading);
if (RegWordW.lpWord)
HeapFree(g_hImm32Heap, 0, RegWordW.lpWord);
ImmUnlockImeDpi(pImeDpi);
return ret;
}
/***********************************************************************
* ImmConfigureIMEW (IMM32.@)
*/
BOOL WINAPI ImmConfigureIMEW(HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
{
BOOL ret = FALSE;
PIMEDPI pImeDpi;
REGISTERWORDA RegWordA;
LPREGISTERWORDW pRegWordW;
TRACE("(%p, %p, 0x%lX, %p)", hKL, hWnd, dwMode, lpData);
if (!ValidateHwndNoErr(hWnd) || Imm32IsCrossProcessAccess(hWnd))
return FALSE;
pImeDpi = ImmLockOrLoadImeDpi(hKL);
if (!pImeDpi)
return FALSE;
RtlZeroMemory(&RegWordA, sizeof(RegWordA));
if ((pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) || !lpData ||
dwMode != IME_CONFIG_REGISTERWORD)
{
goto DoIt;
}
pRegWordW = lpData;
if (pRegWordW->lpReading)
{
RegWordA.lpReading = Imm32AnsiFromWide(pRegWordW->lpReading);
if (!RegWordA.lpReading)
goto Quit;
}
if (pRegWordW->lpWord)
{
RegWordA.lpWord = Imm32AnsiFromWide(pRegWordW->lpWord);
if (!RegWordA.lpWord)
goto Quit;
}
lpData = &RegWordA;
DoIt:
SendMessageW(hWnd, WM_IME_SYSTEM, IMS_OPENPROPERTYWINDOW, 0);
ret = pImeDpi->ImeConfigure(hKL, hWnd, dwMode, lpData);
SendMessageW(hWnd, WM_IME_SYSTEM, IMS_CLOSEPROPERTYWINDOW, 0);
Quit:
if (RegWordA.lpReading)
HeapFree(g_hImm32Heap, 0, RegWordA.lpReading);
if (RegWordA.lpWord)
HeapFree(g_hImm32Heap, 0, RegWordA.lpWord);
ImmUnlockImeDpi(pImeDpi);
return ret;
}

View file

@ -177,30 +177,6 @@ static inline BOOL is_kbd_ime_unicode(const ImmHkl *hkl)
static InputContextData* get_imc_data(HIMC hIMC);
static inline WCHAR *strdupAtoW( const char *str )
{
WCHAR *ret = NULL;
if (str)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
}
return ret;
}
static inline CHAR *strdupWtoA( const WCHAR *str )
{
CHAR *ret = NULL;
if (str)
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
}
return ret;
}
static HMODULE load_graphics_driver(void)
{
static const WCHAR display_device_guid_propW[] = {
@ -446,74 +422,6 @@ BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
}
}
/***********************************************************************
* ImmConfigureIMEA (IMM32.@)
*/
BOOL WINAPI ImmConfigureIMEA(HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
{
ImmHkl *immHkl = IMM_GetImmHkl(hKL);
TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
return FALSE;
if (immHkl->hIME && immHkl->pImeConfigure)
{
if (dwMode != IME_CONFIG_REGISTERWORD || !is_kbd_ime_unicode(immHkl))
return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
else
{
REGISTERWORDW rww;
REGISTERWORDA *rwa = lpData;
BOOL rc;
rww.lpReading = strdupAtoW(rwa->lpReading);
rww.lpWord = strdupAtoW(rwa->lpWord);
rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rww);
HeapFree(GetProcessHeap(),0,rww.lpReading);
HeapFree(GetProcessHeap(),0,rww.lpWord);
return rc;
}
}
else
return FALSE;
}
/***********************************************************************
* ImmConfigureIMEW (IMM32.@)
*/
BOOL WINAPI ImmConfigureIMEW(HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
{
ImmHkl *immHkl = IMM_GetImmHkl(hKL);
TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
return FALSE;
if (immHkl->hIME && immHkl->pImeConfigure)
{
if (dwMode != IME_CONFIG_REGISTERWORD || is_kbd_ime_unicode(immHkl))
return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
else
{
REGISTERWORDW *rww = lpData;
REGISTERWORDA rwa;
BOOL rc;
rwa.lpReading = strdupWtoA(rww->lpReading);
rwa.lpWord = strdupWtoA(rww->lpWord);
rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rwa);
HeapFree(GetProcessHeap(),0,rwa.lpReading);
HeapFree(GetProcessHeap(),0,rwa.lpWord);
return rc;
}
}
else
return FALSE;
}
/***********************************************************************
* ImmCreateContext (IMM32.@)
*/

View file

@ -62,6 +62,40 @@ extern "C" {
#define WM_CBT 0x000003FF // ReactOS only.
#define WM_MAXIMUM 0x0001FFFF
/* wParam for WM_IME_SYSTEM */
#define IMS_DESTROYWINDOW 0x1
#define IMS_IME31COMPATIBLE 0x2
#define IMS_SETOPENSTATUS 0x3
#define IMS_SETACTIVECONTEXT 0x4
#define IMS_CHANGE_SHOWSTAT 0x5
#define IMS_WINDOWPOS 0x6
#define IMS_SENDIMEMSG 0x7
#define IMS_SENDIMEMSGEX 0x8
#define IMS_SETCANDIDATEPOS 0x9
#define IMS_SETCOMPOSITIONFONT 0xA
#define IMS_SETCOMPOSITIONWINDOW 0xB
#define IMS_CHECKENABLE 0xC
#define IMS_CONFIGUREIME 0xD
#define IMS_CONTROLIMEMSG 0xE
#define IMS_SETOPENCLOSE 0xF
#define IMS_ISACTIVATED 0x10
#define IMS_UNLOADTHREADLAYOUT 0x11
#define IMS_LCHGREQUEST 0x12
#define IMS_SETSOFTKBDONOFF 0x13
#define IMS_GETCONVERSIONMODE 0x14
#define IMS_IMEHELP 0x15
#define IMS_IMENT35SENDAPPMSG 0x16
#define IMS_ACTIVATECONTEXT 0x17
#define IMS_DEACTIVATECONTEXT 0x18
#define IMS_ACTIVATETHREADLAYOUT 0x19
#define IMS_CLOSEPROPERTYWINDOW 0x1A
#define IMS_OPENPROPERTYWINDOW 0x1B
#define IMS_GETIMEMENU 0x1C
#define IMS_ENDIMEMENU 0x1D
#define IMS_GETCONTEXT 0x1E
#define IMS_SENDNOTIFICATION 0x1F
#define IMS_FINALIZE_COMPSTR 0x20
/* Non SDK DCE types.*/
#define DCX_USESTYLE 0x00010000
#define DCX_KEEPCLIPRGN 0x00040000