From 0ffa7576938bcc6adf6674f46d6bf3174fff0745 Mon Sep 17 00:00:00 2001 From: Qian Hong Date: Tue, 6 Aug 2013 01:39:27 +0800 Subject: [PATCH 6/6] imm32: Improved IMC implementation. To: wine-patches Reply-To: wine-devel Cc: Qian Hong --- dlls/imm32/imm.c | 46 ++++++++++++++++++++++++---------------------- dlls/imm32/tests/imm32.c | 16 ++++++++-------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c index bc7caba..d3f2167 100644 --- a/dlls/imm32/imm.c +++ b/dlls/imm32/imm.c @@ -69,7 +69,6 @@ typedef struct _tagImmHkl{ typedef struct tagInputContextData { - DWORD dwLock; INPUTCONTEXT IMC; ImmHkl *immKbd; @@ -615,8 +614,11 @@ HIMC WINAPI ImmCreateContext(void) InputContextData *new_context; LPGUIDELINE gl; LPCANDIDATEINFO ci; + HGLOBAL hmem; - new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData)); + hmem = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, sizeof(InputContextData)); + new_context = GlobalLock(hmem); + GlobalUnlock(hmem); /* Load the IME */ new_context->immKbd = IMM_GetImmHkl(GetKeyboardLayout(0)); @@ -662,24 +664,24 @@ HIMC WINAPI ImmCreateContext(void) static BOOL IMM_DestroyContext(HIMC hIMC) { InputContextData *data = hIMC; + HGLOBAL hmem = GlobalHandle(data); - TRACE("Destroying %p\n",hIMC); + TRACE("Destroying %p\n", hIMC); - if (hIMC) - { - data->immKbd->uSelected --; - data->immKbd->pImeSelect(hIMC, FALSE); - SendMessageW(data->IMC.hWnd, WM_IME_SELECT, FALSE, (LPARAM)GetKeyboardLayout(0)); + if (!hmem) + return FALSE; - ImmDestroyIMCC(data->IMC.hCompStr); - ImmDestroyIMCC(data->IMC.hCandInfo); - ImmDestroyIMCC(data->IMC.hGuideLine); - ImmDestroyIMCC(data->IMC.hPrivate); - ImmDestroyIMCC(data->IMC.hMsgBuf); + data->immKbd->uSelected --; + data->immKbd->pImeSelect(hIMC, FALSE); + SendMessageW(data->IMC.hWnd, WM_IME_SELECT, FALSE, (LPARAM)GetKeyboardLayout(0)); - HeapFree(GetProcessHeap(),0,data); - } - return TRUE; + ImmDestroyIMCC(data->IMC.hCompStr); + ImmDestroyIMCC(data->IMC.hCandInfo); + ImmDestroyIMCC(data->IMC.hGuideLine); + ImmDestroyIMCC(data->IMC.hPrivate); + ImmDestroyIMCC(data->IMC.hMsgBuf); + + return (GlobalFree(hmem) == NULL); } /*********************************************************************** @@ -2587,10 +2589,8 @@ DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType, LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC) { InputContextData *data = hIMC; - - if (!data) + if (!GlobalLock(GlobalHandle(data))) return NULL; - data->dwLock++; return &data->IMC; } @@ -2600,8 +2600,10 @@ LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC) BOOL WINAPI ImmUnlockIMC(HIMC hIMC) { InputContextData *data = hIMC; - if (data->dwLock) - data->dwLock--; + HGLOBAL hmem = GlobalHandle(data); + if (!hmem) + return FALSE; + GlobalUnlock(hmem); return TRUE; } @@ -2611,7 +2613,7 @@ BOOL WINAPI ImmUnlockIMC(HIMC hIMC) DWORD WINAPI ImmGetIMCLockCount(HIMC hIMC) { InputContextData *data = hIMC; - return data->dwLock; + return GlobalFlags(GlobalHandle(data)) & GMEM_LOCKCOUNT; } /*********************************************************************** diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c index 9b2aede..f82632b 100644 --- a/dlls/imm32/tests/imm32.c +++ b/dlls/imm32/tests/imm32.c @@ -716,15 +716,15 @@ static void test_ImmGetIMCLockCount(void) ok(ic != NULL, "ImmLockIMC failed!\n"); } count = ImmGetIMCLockCount(imc); - todo_wine ok(count == GMEM_LOCKCOUNT, "expect GMEM_LOCKCOUNT, returned %d\n", count); + ok(count == GMEM_LOCKCOUNT, "expect GMEM_LOCKCOUNT, returned %d\n", count); for (i = 0; i < GMEM_LOCKCOUNT - 1; i++) ImmUnlockIMC(imc); count = ImmGetIMCLockCount(imc); - todo_wine ok(count == 1, "expect 1, returned %d\n", count); + ok(count == 1, "expect 1, returned %d\n", count); ImmUnlockIMC(imc); count = ImmGetIMCLockCount(imc); - todo_wine ok(count == 0, "expect 0, returned %d\n", count); + ok(count == 0, "expect 0, returned %d\n", count); ImmDestroyContext(imc); } @@ -790,16 +790,16 @@ static void test_ImmDestroyContext(void) ret = ImmDestroyContext(imc); ok(ret == TRUE, "Destroy an locked IMC should success!\n"); ic = ImmLockIMC(imc); - todo_wine ok(ic == NULL, "Lock a destroyed IMC should fail!\n"); + ok(ic == NULL, "Lock a destroyed IMC should fail!\n"); ret = ImmUnlockIMC(imc); - todo_wine ok(ret == FALSE, "Unlock a destroyed IMC should fail!\n"); + ok(ret == FALSE, "Unlock a destroyed IMC should fail!\n"); count = ImmGetIMCLockCount(imc); - todo_wine ok(count == 0, "Get lock count of a destroyed IMC should return 0!\n"); + ok(count == 0, "Get lock count of a destroyed IMC should return 0!\n"); SetLastError(0xdeadbeef); ret = ImmDestroyContext(imc); - todo_wine ok(ret == FALSE, "Destroy a destroyed IMC should fail!\n"); + ok(ret == FALSE, "Destroy a destroyed IMC should fail!\n"); ret = GetLastError(); - todo_wine ok(ret == ERROR_INVALID_HANDLE, "wrong last error %08x!\n", ret); + ok(ret == ERROR_INVALID_HANDLE, "wrong last error %08x!\n", ret); } static void test_ImmDestroyIMCC(void) -- 1.7.9.5