imm32: Add a helper function to get the default context.
This commit is contained in:
parent
5448acc37a
commit
29ce21e25d
|
@ -494,34 +494,45 @@ static InputContextData* get_imc_data(HIMC hIMC)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IMMThreadData* IMM_GetInitializedThreadData(HWND hWnd)
|
static HIMC get_default_context( HWND hwnd )
|
||||||
{
|
{
|
||||||
IMMThreadData* thread_data = IMM_GetThreadDataForWindow(hWnd);
|
HIMC ret;
|
||||||
|
IMMThreadData* thread_data = IMM_GetThreadDataForWindow( hwnd );
|
||||||
|
|
||||||
if (!thread_data)
|
if (!thread_data) return 0;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!thread_data->defaultContext && thread_data->threadID == GetCurrentThreadId())
|
if (thread_data->defaultContext)
|
||||||
{
|
{
|
||||||
HIMC defaultContext;
|
ret = thread_data->defaultContext;
|
||||||
LeaveCriticalSection(&threaddata_cs);
|
LeaveCriticalSection(&threaddata_cs);
|
||||||
defaultContext = ImmCreateContext();
|
return ret;
|
||||||
if (defaultContext)
|
|
||||||
((InputContextData*)defaultContext)->threadDefault = TRUE;
|
|
||||||
thread_data = IMM_GetThreadDataForWindow(hWnd);
|
|
||||||
if (!thread_data)
|
|
||||||
{
|
|
||||||
IMM_DestroyContext(defaultContext);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* can't create a default context in another thread */
|
||||||
|
if (thread_data->threadID != GetCurrentThreadId())
|
||||||
|
{
|
||||||
|
LeaveCriticalSection(&threaddata_cs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LeaveCriticalSection(&threaddata_cs);
|
||||||
|
|
||||||
|
ret = ImmCreateContext();
|
||||||
|
if (!ret) return 0;
|
||||||
|
((InputContextData*)ret)->threadDefault = TRUE;
|
||||||
|
|
||||||
|
/* thread_data is in the current thread so we can assume it's still valid */
|
||||||
|
EnterCriticalSection(&threaddata_cs);
|
||||||
|
|
||||||
if (thread_data->defaultContext) /* someone beat us */
|
if (thread_data->defaultContext) /* someone beat us */
|
||||||
IMM_DestroyContext(defaultContext);
|
{
|
||||||
else
|
IMM_DestroyContext( ret );
|
||||||
thread_data->defaultContext = defaultContext;
|
ret = thread_data->defaultContext;
|
||||||
}
|
}
|
||||||
|
else thread_data->defaultContext = ret;
|
||||||
|
|
||||||
return thread_data;
|
LeaveCriticalSection(&threaddata_cs);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL IMM_IsCrossThreadAccess(HWND hWnd, HIMC hIMC)
|
static BOOL IMM_IsCrossThreadAccess(HWND hWnd, HIMC hIMC)
|
||||||
|
@ -547,7 +558,6 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
|
||||||
{
|
{
|
||||||
HIMC old = NULL;
|
HIMC old = NULL;
|
||||||
InputContextData *data = get_imc_data(hIMC);
|
InputContextData *data = get_imc_data(hIMC);
|
||||||
IMMThreadData* thread_data = NULL;
|
|
||||||
|
|
||||||
TRACE("(%p, %p):\n", hWnd, hIMC);
|
TRACE("(%p, %p):\n", hWnd, hIMC);
|
||||||
|
|
||||||
|
@ -563,20 +573,17 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
|
||||||
if (hIMC && IMM_IsCrossThreadAccess(hWnd, hIMC))
|
if (hIMC && IMM_IsCrossThreadAccess(hWnd, hIMC))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
thread_data = IMM_GetInitializedThreadData(hWnd);
|
|
||||||
if (!thread_data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (hWnd)
|
if (hWnd)
|
||||||
{
|
{
|
||||||
|
HIMC defaultContext = get_default_context( hWnd );
|
||||||
old = RemovePropW(hWnd,szwWineIMCProperty);
|
old = RemovePropW(hWnd,szwWineIMCProperty);
|
||||||
|
|
||||||
if (old == NULL)
|
if (old == NULL)
|
||||||
old = thread_data->defaultContext;
|
old = defaultContext;
|
||||||
else if (old == (HIMC)-1)
|
else if (old == (HIMC)-1)
|
||||||
old = NULL;
|
old = NULL;
|
||||||
|
|
||||||
if (hIMC != thread_data->defaultContext)
|
if (hIMC != defaultContext)
|
||||||
{
|
{
|
||||||
if (hIMC == NULL) /* Meaning disable imm for that window*/
|
if (hIMC == NULL) /* Meaning disable imm for that window*/
|
||||||
SetPropW(hWnd,szwWineIMCProperty,(HANDLE)-1);
|
SetPropW(hWnd,szwWineIMCProperty,(HANDLE)-1);
|
||||||
|
@ -591,7 +598,6 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
|
||||||
old_data->IMC.hWnd = NULL;
|
old_data->IMC.hWnd = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&threaddata_cs);
|
|
||||||
|
|
||||||
if (!hIMC)
|
if (!hIMC)
|
||||||
return old;
|
return old;
|
||||||
|
@ -633,18 +639,8 @@ static BOOL CALLBACK _ImmAssociateContextExEnumProc(HWND hwnd, LPARAM lParam)
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
|
BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
|
||||||
{
|
{
|
||||||
IMMThreadData* thread_data = NULL;
|
|
||||||
HIMC defaultContext = NULL;
|
|
||||||
|
|
||||||
TRACE("(%p, %p, 0x%x):\n", hWnd, hIMC, dwFlags);
|
TRACE("(%p, %p, 0x%x):\n", hWnd, hIMC, dwFlags);
|
||||||
|
|
||||||
thread_data = IMM_GetInitializedThreadData(hWnd);
|
|
||||||
if (!thread_data)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
defaultContext = thread_data->defaultContext;
|
|
||||||
LeaveCriticalSection(&threaddata_cs);
|
|
||||||
|
|
||||||
if (!hWnd)
|
if (!hWnd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -654,8 +650,12 @@ BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
|
||||||
ImmAssociateContext(hWnd,hIMC);
|
ImmAssociateContext(hWnd,hIMC);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case IACE_DEFAULT:
|
case IACE_DEFAULT:
|
||||||
|
{
|
||||||
|
HIMC defaultContext = get_default_context( hWnd );
|
||||||
|
if (!defaultContext) return FALSE;
|
||||||
ImmAssociateContext(hWnd,defaultContext);
|
ImmAssociateContext(hWnd,defaultContext);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
case IACE_IGNORENOCONTEXT:
|
case IACE_IGNORENOCONTEXT:
|
||||||
if (GetPropW(hWnd,szwWineIMCProperty))
|
if (GetPropW(hWnd,szwWineIMCProperty))
|
||||||
ImmAssociateContext(hWnd,hIMC);
|
ImmAssociateContext(hWnd,hIMC);
|
||||||
|
@ -1496,7 +1496,6 @@ BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
|
||||||
HIMC WINAPI ImmGetContext(HWND hWnd)
|
HIMC WINAPI ImmGetContext(HWND hWnd)
|
||||||
{
|
{
|
||||||
HIMC rc;
|
HIMC rc;
|
||||||
IMMThreadData* thread_data;
|
|
||||||
|
|
||||||
TRACE("%p\n", hWnd);
|
TRACE("%p\n", hWnd);
|
||||||
|
|
||||||
|
@ -1506,22 +1505,17 @@ HIMC WINAPI ImmGetContext(HWND hWnd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_data = IMM_GetInitializedThreadData(hWnd);
|
|
||||||
if (!thread_data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
rc = GetPropW(hWnd,szwWineIMCProperty);
|
rc = GetPropW(hWnd,szwWineIMCProperty);
|
||||||
if (rc == (HIMC)-1)
|
if (rc == (HIMC)-1)
|
||||||
rc = NULL;
|
rc = NULL;
|
||||||
else if (rc == NULL)
|
else if (rc == NULL)
|
||||||
rc = thread_data->defaultContext;
|
rc = get_default_context( hWnd );
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
InputContextData *data = rc;
|
InputContextData *data = rc;
|
||||||
data->IMC.hWnd = hWnd;
|
data->IMC.hWnd = hWnd;
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&threaddata_cs);
|
|
||||||
|
|
||||||
TRACE("returning %p\n", rc);
|
TRACE("returning %p\n", rc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue