imm: Ensure hCompStr handle is not NULL and check for empty composition strings properly.

This commit is contained in:
Aric Stewart 2008-02-15 13:22:28 -06:00 committed by Alexandre Julliard
parent e9063b7776
commit fd67f32ee3
1 changed files with 21 additions and 3 deletions

View File

@ -194,6 +194,18 @@ static LRESULT ImmInternalSendIMENotify(WPARAM notify, LPARAM lParam)
return 0; return 0;
} }
static HIMCC ImmCreateBlankCompStr(void)
{
HIMCC rc;
LPCOMPOSITIONSTRING ptr;
rc = ImmCreateIMCC(sizeof(COMPOSITIONSTRING));
ptr = (LPCOMPOSITIONSTRING)ImmLockIMCC(rc);
memset(ptr,0,sizeof(COMPOSITIONSTRING));
ptr->dwSize = sizeof(COMPOSITIONSTRING);
ImmUnlockIMCC(rc);
return rc;
}
static void ImmInternalSetOpenStatus(BOOL fOpen) static void ImmInternalSetOpenStatus(BOOL fOpen)
{ {
TRACE("Setting internal state to %s\n",(fOpen)?"OPEN":"CLOSED"); TRACE("Setting internal state to %s\n",(fOpen)?"OPEN":"CLOSED");
@ -202,7 +214,7 @@ static void ImmInternalSetOpenStatus(BOOL fOpen)
{ {
ShowWindow(hwndDefault,SW_HIDE); ShowWindow(hwndDefault,SW_HIDE);
ImmDestroyIMCC(root_context->IMC.hCompStr); ImmDestroyIMCC(root_context->IMC.hCompStr);
root_context->IMC.hCompStr = NULL; root_context->IMC.hCompStr = ImmCreateBlankCompStr();
} }
root_context->IMC.fOpen = fOpen; root_context->IMC.fOpen = fOpen;
@ -597,6 +609,9 @@ HIMC WINAPI ImmCreateContext(void)
new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData)); new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
/* hCompStr is never NULL */
new_context->IMC.hCompStr = ImmCreateBlankCompStr();
return (HIMC)new_context; return (HIMC)new_context;
} }
@ -1411,14 +1426,17 @@ BOOL WINAPI ImmNotifyIME(
TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL"); TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL");
{ {
BOOL send; BOOL send;
LPCOMPOSITIONSTRING lpCompStr;
if (pX11DRV_ForceXIMReset) if (pX11DRV_ForceXIMReset)
pX11DRV_ForceXIMReset(root_context->IMC.hWnd); pX11DRV_ForceXIMReset(root_context->IMC.hWnd);
send = (root_context->IMC.hCompStr!=NULL); lpCompStr = ImmLockIMCC(root_context->IMC.hCompStr);
send = (lpCompStr->dwCompStrLen != 0);
ImmUnlockIMCC(root_context->IMC.hCompStr);
ImmDestroyIMCC(root_context->IMC.hCompStr); ImmDestroyIMCC(root_context->IMC.hCompStr);
root_context->IMC.hCompStr = NULL; root_context->IMC.hCompStr = ImmCreateBlankCompStr();
if (send) if (send)
ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0, ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,