2004-01-21 03:22:26 +01:00
|
|
|
/*
|
|
|
|
* Functions for further XIM control
|
|
|
|
*
|
|
|
|
* Copyright 2003 CodeWeavers, Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-01-21 03:22:26 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "x11drv.h"
|
|
|
|
#include "imm.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2010-02-24 12:04:14 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(xim);
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-04-15 17:34:54 +02:00
|
|
|
#ifndef HAVE_XICCALLBACK_CALLBACK
|
|
|
|
#define XICCallback XIMCallback
|
|
|
|
#define XICProc XIMProc
|
|
|
|
#endif
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
BOOL ximInComposeMode=FALSE;
|
|
|
|
|
2004-02-09 23:07:42 +01:00
|
|
|
/* moved here from imm32 for dll separation */
|
2004-01-21 03:22:26 +01:00
|
|
|
static DWORD dwCompStringLength = 0;
|
|
|
|
static LPBYTE CompositionString = NULL;
|
|
|
|
static DWORD dwCompStringSize = 0;
|
|
|
|
|
|
|
|
#define STYLE_OFFTHESPOT (XIMPreeditArea | XIMStatusArea)
|
|
|
|
#define STYLE_OVERTHESPOT (XIMPreeditPosition | XIMStatusNothing)
|
|
|
|
#define STYLE_ROOT (XIMPreeditNothing | XIMStatusNothing)
|
|
|
|
/* this uses all the callbacks to utilize full IME support */
|
|
|
|
#define STYLE_CALLBACK (XIMPreeditCallbacks | XIMStatusNothing)
|
2010-06-24 10:18:34 +02:00
|
|
|
/* in order to enable deadkey support */
|
2004-01-21 03:22:26 +01:00
|
|
|
#define STYLE_NONE (XIMPreeditNothing | XIMStatusNothing)
|
|
|
|
|
2008-04-10 12:29:01 +02:00
|
|
|
static XIMStyle ximStyle = 0;
|
|
|
|
static XIMStyle ximStyleRoot = 0;
|
|
|
|
static XIMStyle ximStyleRequest = STYLE_CALLBACK;
|
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
static void X11DRV_ImmSetInternalString(DWORD dwOffset,
|
2004-01-21 03:22:26 +01:00
|
|
|
DWORD selLength, LPWSTR lpComp, DWORD dwCompLen)
|
|
|
|
{
|
|
|
|
/* Composition strings are edited in chunks */
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int byte_length = dwCompLen * sizeof(WCHAR);
|
|
|
|
unsigned int byte_offset = dwOffset * sizeof(WCHAR);
|
|
|
|
unsigned int byte_selection = selLength * sizeof(WCHAR);
|
2010-02-12 06:54:24 +01:00
|
|
|
int byte_expansion = byte_length - byte_selection;
|
|
|
|
LPBYTE ptr_new;
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
TRACE("( %i, %i, %p, %d):\n", dwOffset, selLength, lpComp, dwCompLen );
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
if (byte_expansion + dwCompStringLength >= dwCompStringSize)
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
2010-02-12 06:54:24 +01:00
|
|
|
if (CompositionString)
|
|
|
|
ptr_new = HeapReAlloc(GetProcessHeap(), 0, CompositionString,
|
|
|
|
dwCompStringSize + byte_expansion);
|
2004-01-21 03:22:26 +01:00
|
|
|
else
|
2010-02-12 06:54:24 +01:00
|
|
|
ptr_new = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
dwCompStringSize + byte_expansion);
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
if (ptr_new == NULL)
|
|
|
|
{
|
|
|
|
ERR("Couldn't expand composition string buffer\n");
|
|
|
|
return;
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
CompositionString = ptr_new;
|
|
|
|
dwCompStringSize += byte_expansion;
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
ptr_new = CompositionString + byte_offset;
|
|
|
|
memmove(ptr_new + byte_length, ptr_new + byte_selection,
|
|
|
|
dwCompStringLength - byte_offset - byte_selection);
|
|
|
|
memcpy(ptr_new, lpComp, byte_length);
|
|
|
|
dwCompStringLength += byte_expansion;
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
IME_SetCompositionString(SCS_SETSTR, CompositionString,
|
|
|
|
dwCompStringLength, NULL, 0);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11DRV_XIMLookupChars( const char *str, DWORD count )
|
|
|
|
{
|
|
|
|
DWORD dwOutput;
|
2008-09-13 08:01:40 +02:00
|
|
|
WCHAR *wcOutput;
|
2004-01-21 03:22:26 +01:00
|
|
|
HWND focus;
|
|
|
|
|
2010-02-12 06:54:24 +01:00
|
|
|
TRACE("%p %u\n", str, count);
|
|
|
|
|
2008-09-13 08:01:40 +02:00
|
|
|
dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, NULL, 0);
|
|
|
|
wcOutput = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * dwOutput);
|
|
|
|
if (wcOutput == NULL)
|
|
|
|
return;
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, str, count, wcOutput, dwOutput);
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-04-07 15:35:42 +02:00
|
|
|
if ((focus = GetFocus()))
|
|
|
|
IME_UpdateAssociation(focus);
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2010-02-16 10:51:43 +01:00
|
|
|
IME_SetResultString(wcOutput, dwOutput);
|
2008-09-13 08:01:40 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wcOutput);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2010-02-18 15:06:31 +01:00
|
|
|
static BOOL XIMPreEditStateNotifyCallback(XIC xic, XPointer p, XPointer data)
|
|
|
|
{
|
|
|
|
const struct x11drv_win_data * const win_data = (struct x11drv_win_data *)p;
|
|
|
|
const XIMPreeditState state = ((XIMPreeditStateNotifyCallbackStruct *)data)->state;
|
|
|
|
|
|
|
|
TRACE("xic = %p, win = %lx, state = %lu\n", xic, win_data->whole_window, state);
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case XIMPreeditEnable:
|
|
|
|
IME_SetOpenStatus(TRUE, TRUE);
|
|
|
|
break;
|
|
|
|
case XIMPreeditDisable:
|
|
|
|
IME_SetOpenStatus(FALSE, TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
static int XIMPreEditStartCallback(XIC ic, XPointer client_data, XPointer call_data)
|
|
|
|
{
|
|
|
|
TRACE("PreEditStartCallback %p\n",ic);
|
2010-02-18 15:06:31 +01:00
|
|
|
IME_SetOpenStatus(TRUE, FALSE);
|
2004-01-21 03:22:26 +01:00
|
|
|
ximInComposeMode = TRUE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void XIMPreEditDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
|
|
|
|
{
|
|
|
|
TRACE("PreeditDoneCallback %p\n",ic);
|
|
|
|
ximInComposeMode = FALSE;
|
2010-02-12 06:54:33 +01:00
|
|
|
if (dwCompStringSize)
|
|
|
|
HeapFree(GetProcessHeap(), 0, CompositionString);
|
|
|
|
dwCompStringSize = 0;
|
|
|
|
dwCompStringLength = 0;
|
|
|
|
CompositionString = NULL;
|
2010-02-18 15:06:31 +01:00
|
|
|
IME_SetOpenStatus(FALSE, FALSE);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void XIMPreEditDrawCallback(XIM ic, XPointer client_data,
|
|
|
|
XIMPreeditDrawCallbackStruct *P_DR)
|
|
|
|
{
|
|
|
|
TRACE("PreEditDrawCallback %p\n",ic);
|
|
|
|
|
|
|
|
if (P_DR)
|
|
|
|
{
|
|
|
|
int sel = P_DR->chg_first;
|
|
|
|
int len = P_DR->chg_length;
|
|
|
|
if (P_DR->text)
|
|
|
|
{
|
|
|
|
if (! P_DR->text->encoding_is_wchar)
|
|
|
|
{
|
2008-03-20 20:52:49 +01:00
|
|
|
DWORD dwOutput;
|
|
|
|
WCHAR *wcOutput;
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
TRACE("multibyte\n");
|
|
|
|
dwOutput = MultiByteToWideChar(CP_UNIXCP, 0,
|
|
|
|
P_DR->text->string.multi_byte, -1,
|
2008-03-20 20:52:49 +01:00
|
|
|
NULL, 0);
|
|
|
|
wcOutput = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR) * dwOutput);
|
|
|
|
if (wcOutput)
|
|
|
|
{
|
|
|
|
dwOutput = MultiByteToWideChar(CP_UNIXCP, 0,
|
|
|
|
P_DR->text->string.multi_byte, -1,
|
|
|
|
wcOutput, dwOutput);
|
|
|
|
|
|
|
|
/* ignore null */
|
|
|
|
dwOutput --;
|
2010-02-12 06:54:24 +01:00
|
|
|
X11DRV_ImmSetInternalString (sel, len, wcOutput, dwOutput);
|
2008-03-20 20:52:49 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, wcOutput);
|
|
|
|
}
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("wchar PROBIBILY WRONG\n");
|
2010-02-12 06:54:24 +01:00
|
|
|
X11DRV_ImmSetInternalString (sel, len,
|
2004-01-21 03:22:26 +01:00
|
|
|
(LPWSTR)P_DR->text->string.wide_char,
|
|
|
|
P_DR->text->length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-02-12 06:54:24 +01:00
|
|
|
X11DRV_ImmSetInternalString (sel, len, NULL, 0);
|
2008-04-18 02:48:31 +02:00
|
|
|
IME_SetCursorPos(P_DR->caret);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
TRACE("Finished\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void XIMPreEditCaretCallback(XIC ic, XPointer client_data,
|
|
|
|
XIMPreeditCaretCallbackStruct *P_C)
|
|
|
|
{
|
2007-07-19 19:52:30 +02:00
|
|
|
TRACE("PreeditCaretCallback %p\n",ic);
|
|
|
|
|
|
|
|
if (P_C)
|
|
|
|
{
|
2008-04-07 15:35:42 +02:00
|
|
|
int pos = IME_GetCursorPos();
|
2007-07-19 19:52:30 +02:00
|
|
|
TRACE("pos: %d\n", pos);
|
|
|
|
switch(P_C->direction)
|
|
|
|
{
|
|
|
|
case XIMForwardChar:
|
|
|
|
case XIMForwardWord:
|
|
|
|
pos++;
|
|
|
|
break;
|
|
|
|
case XIMBackwardChar:
|
|
|
|
case XIMBackwardWord:
|
|
|
|
pos--;
|
|
|
|
break;
|
|
|
|
case XIMLineStart:
|
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
case XIMAbsolutePosition:
|
|
|
|
pos = P_C->position;
|
|
|
|
break;
|
|
|
|
case XIMDontChange:
|
|
|
|
P_C->position = pos;
|
|
|
|
return;
|
|
|
|
case XIMCaretUp:
|
|
|
|
case XIMCaretDown:
|
|
|
|
case XIMPreviousLine:
|
|
|
|
case XIMNextLine:
|
|
|
|
case XIMLineEnd:
|
|
|
|
FIXME("Not implemented\n");
|
|
|
|
break;
|
|
|
|
}
|
2008-04-18 02:48:31 +02:00
|
|
|
IME_SetCursorPos(pos);
|
2007-07-19 19:52:30 +02:00
|
|
|
P_C->position = pos;
|
|
|
|
}
|
|
|
|
TRACE("Finished\n");
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2004-02-27 22:32:54 +01:00
|
|
|
void X11DRV_ForceXIMReset(HWND hwnd)
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
|
|
|
XIC ic = X11DRV_get_ic(hwnd);
|
|
|
|
if (ic)
|
|
|
|
{
|
|
|
|
char* leftover;
|
|
|
|
TRACE("Forcing Reset %p\n",ic);
|
|
|
|
wine_tsx11_lock();
|
|
|
|
leftover = XmbResetIC(ic);
|
|
|
|
XFree(leftover);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-18 15:06:31 +01:00
|
|
|
BOOL X11DRV_SetPreeditState(HWND hwnd, BOOL fOpen)
|
|
|
|
{
|
|
|
|
XIC ic;
|
|
|
|
XIMPreeditState state;
|
|
|
|
XVaNestedList attr_set, attr_get;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ic = X11DRV_get_ic(hwnd);
|
|
|
|
if (!ic)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (fOpen)
|
|
|
|
state = XIMPreeditEnable;
|
|
|
|
else
|
|
|
|
state = XIMPreeditDisable;
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
wine_tsx11_lock();
|
|
|
|
|
|
|
|
attr_set = XVaCreateNestedList(0, XNPreeditState, state, NULL);
|
|
|
|
if (attr_set == NULL)
|
|
|
|
goto error1;
|
|
|
|
|
|
|
|
attr_get = XVaCreateNestedList(0, XNPreeditState, &state, NULL);
|
|
|
|
if (attr_get == NULL)
|
|
|
|
goto error2;
|
|
|
|
|
|
|
|
if (XSetICValues(ic, XNPreeditAttributes, attr_set, NULL) != NULL)
|
|
|
|
goto error3;
|
|
|
|
|
|
|
|
/* SCIM claims it supports XNPreeditState, but seems to ignore */
|
|
|
|
state = XIMPreeditUnKnown;
|
|
|
|
ret = XGetICValues(ic, XNPreeditAttributes, attr_get, NULL) == NULL &&
|
|
|
|
((fOpen && state == XIMPreeditEnable) ||
|
|
|
|
(!fOpen && state == XIMPreeditDisable));
|
|
|
|
error3:
|
|
|
|
XFree(attr_get);
|
|
|
|
error2:
|
|
|
|
XFree(attr_set);
|
|
|
|
error1:
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
/***********************************************************************
|
2008-04-10 12:29:01 +02:00
|
|
|
* X11DRV_InitXIM
|
|
|
|
*
|
|
|
|
* Process-wide XIM initialization.
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_InitXIM( const char *input_style )
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
2008-04-10 12:29:01 +02:00
|
|
|
BOOL ret;
|
2004-01-21 03:22:26 +01:00
|
|
|
|
|
|
|
if (!strcasecmp(input_style, "offthespot"))
|
|
|
|
ximStyleRequest = STYLE_OFFTHESPOT;
|
|
|
|
else if (!strcasecmp(input_style, "overthespot"))
|
|
|
|
ximStyleRequest = STYLE_OVERTHESPOT;
|
|
|
|
else if (!strcasecmp(input_style, "root"))
|
|
|
|
ximStyleRequest = STYLE_ROOT;
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
2008-04-10 12:29:01 +02:00
|
|
|
if (!(ret = XSupportsLocale()))
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
|
|
|
WARN("X does not support locale.\n");
|
|
|
|
}
|
2008-04-10 12:29:01 +02:00
|
|
|
else if (XSetLocaleModifiers("") == NULL)
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
|
|
|
WARN("Could not set locale modifiers.\n");
|
2008-04-10 12:29:01 +02:00
|
|
|
ret = FALSE;
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
2008-04-10 12:29:01 +02:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-21 11:18:07 +02:00
|
|
|
static void open_xim_callback( Display *display, XPointer ptr, XPointer data );
|
2008-04-04 13:44:36 +02:00
|
|
|
|
|
|
|
static void X11DRV_DestroyIM(XIM xim, XPointer p, XPointer data)
|
|
|
|
{
|
|
|
|
struct x11drv_thread_data *thread_data = x11drv_thread_data();
|
|
|
|
|
|
|
|
TRACE("xim = %p, p = %p\n", xim, p);
|
|
|
|
thread_data->xim = NULL;
|
|
|
|
ximStyle = 0;
|
|
|
|
wine_tsx11_lock();
|
2008-06-21 11:18:07 +02:00
|
|
|
XRegisterIMInstantiateCallback( thread_data->display, NULL, NULL, NULL, open_xim_callback, NULL );
|
2008-04-04 13:44:36 +02:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
|
2008-04-10 12:29:01 +02:00
|
|
|
/***********************************************************************
|
2008-05-05 15:08:33 +02:00
|
|
|
* X11DRV Ime creation
|
|
|
|
*
|
|
|
|
* Should always be called with the x11 lock held
|
|
|
|
*/
|
2008-06-21 11:18:07 +02:00
|
|
|
static BOOL open_xim( Display *display )
|
2008-04-10 12:29:01 +02:00
|
|
|
{
|
2008-04-04 13:44:36 +02:00
|
|
|
struct x11drv_thread_data *thread_data = x11drv_thread_data();
|
2008-04-10 12:29:01 +02:00
|
|
|
XIMStyle ximStyleCallback, ximStyleNone;
|
|
|
|
XIMStyles *ximStyles = NULL;
|
|
|
|
INT i;
|
|
|
|
XIM xim;
|
2008-04-04 13:44:36 +02:00
|
|
|
XIMCallback destroy;
|
2008-04-10 12:29:01 +02:00
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
xim = XOpenIM(display, NULL, NULL, NULL);
|
|
|
|
if (xim == NULL)
|
|
|
|
{
|
|
|
|
WARN("Could not open input method.\n");
|
2008-06-21 11:18:07 +02:00
|
|
|
return FALSE;
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
destroy.client_data = NULL;
|
|
|
|
destroy.callback = X11DRV_DestroyIM;
|
|
|
|
if (XSetIMValues(xim, XNDestroyCallback, &destroy, NULL))
|
|
|
|
{
|
|
|
|
WARN("Could not set destroy callback.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("xim = %p\n", xim);
|
2004-01-21 03:22:26 +01:00
|
|
|
TRACE("X display of IM = %p\n", XDisplayOfIM(xim));
|
|
|
|
TRACE("Using %s locale of Input Method\n", XLocaleOfIM(xim));
|
|
|
|
|
|
|
|
XGetIMValues(xim, XNQueryInputStyle, &ximStyles, NULL);
|
|
|
|
if (ximStyles == 0)
|
|
|
|
{
|
|
|
|
WARN("Could not find supported input style.\n");
|
2008-04-04 13:44:36 +02:00
|
|
|
XCloseIM(xim);
|
2008-06-21 11:18:07 +02:00
|
|
|
return FALSE;
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("ximStyles->count_styles = %d\n", ximStyles->count_styles);
|
|
|
|
|
|
|
|
ximStyleRoot = 0;
|
|
|
|
ximStyleNone = 0;
|
|
|
|
ximStyleCallback = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ximStyles->count_styles; ++i)
|
|
|
|
{
|
|
|
|
int style = ximStyles->supported_styles[i];
|
|
|
|
TRACE("ximStyles[%d] = %s%s%s%s%s\n", i,
|
|
|
|
(style&XIMPreeditArea)?"XIMPreeditArea ":"",
|
|
|
|
(style&XIMPreeditCallbacks)?"XIMPreeditCallbacks ":"",
|
|
|
|
(style&XIMPreeditPosition)?"XIMPreeditPosition ":"",
|
|
|
|
(style&XIMPreeditNothing)?"XIMPreeditNothing ":"",
|
|
|
|
(style&XIMPreeditNone)?"XIMPreeditNone ":"");
|
|
|
|
if (!ximStyle && (ximStyles->supported_styles[i] ==
|
|
|
|
ximStyleRequest))
|
|
|
|
{
|
|
|
|
ximStyle = ximStyleRequest;
|
|
|
|
TRACE("Setting Style: ximStyle = ximStyleRequest\n");
|
|
|
|
}
|
|
|
|
else if (!ximStyleRoot &&(ximStyles->supported_styles[i] ==
|
|
|
|
STYLE_ROOT))
|
|
|
|
{
|
|
|
|
ximStyleRoot = STYLE_ROOT;
|
|
|
|
TRACE("Setting Style: ximStyleRoot = STYLE_ROOT\n");
|
|
|
|
}
|
|
|
|
else if (!ximStyleCallback &&(ximStyles->supported_styles[i] ==
|
|
|
|
STYLE_CALLBACK))
|
|
|
|
{
|
|
|
|
ximStyleCallback = STYLE_CALLBACK;
|
|
|
|
TRACE("Setting Style: ximStyleCallback = STYLE_CALLBACK\n");
|
|
|
|
}
|
|
|
|
else if (!ximStyleNone && (ximStyles->supported_styles[i] ==
|
|
|
|
STYLE_NONE))
|
|
|
|
{
|
|
|
|
TRACE("Setting Style: ximStyleNone = STYLE_NONE\n");
|
|
|
|
ximStyleNone = STYLE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(ximStyles);
|
|
|
|
|
|
|
|
if (ximStyle == 0)
|
|
|
|
ximStyle = ximStyleRoot;
|
|
|
|
|
|
|
|
if (ximStyle == 0)
|
|
|
|
ximStyle = ximStyleNone;
|
|
|
|
|
|
|
|
if (ximStyleCallback == 0)
|
|
|
|
{
|
2011-08-02 22:20:32 +02:00
|
|
|
TRACE("No callback style available\n");
|
2004-01-21 03:22:26 +01:00
|
|
|
ximStyleCallback = ximStyle;
|
|
|
|
}
|
|
|
|
|
2006-10-24 13:32:00 +02:00
|
|
|
}
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
thread_data->xim = xim;
|
2008-05-05 15:08:33 +02:00
|
|
|
|
2008-10-18 16:03:48 +02:00
|
|
|
if ((ximStyle & (XIMPreeditNothing | XIMPreeditNone)) == 0 ||
|
|
|
|
(ximStyle & (XIMStatusNothing | XIMStatusNone)) == 0)
|
|
|
|
{
|
|
|
|
char **list;
|
|
|
|
int count;
|
|
|
|
thread_data->font_set = XCreateFontSet(display, "fixed",
|
|
|
|
&list, &count, NULL);
|
|
|
|
TRACE("ximFontSet = %p\n", thread_data->font_set);
|
|
|
|
TRACE("list = %p, count = %d\n", list, count);
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("list[%d] = %s\n", i, list[i]);
|
|
|
|
XFreeStringList(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
thread_data->font_set = NULL;
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
wine_tsx11_unlock();
|
2008-04-02 17:13:59 +02:00
|
|
|
IME_UpdateAssociation(NULL);
|
2008-05-05 15:08:33 +02:00
|
|
|
wine_tsx11_lock();
|
2008-06-21 11:18:07 +02:00
|
|
|
return TRUE;
|
2008-04-04 13:44:36 +02:00
|
|
|
}
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-06-21 11:18:07 +02:00
|
|
|
static void open_xim_callback( Display *display, XPointer ptr, XPointer data )
|
|
|
|
{
|
|
|
|
if (open_xim( display ))
|
|
|
|
XUnregisterIMInstantiateCallback( display, NULL, NULL, NULL, open_xim_callback, NULL);
|
|
|
|
}
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
void X11DRV_SetupXIM(void)
|
|
|
|
{
|
2008-06-21 11:18:07 +02:00
|
|
|
Display *display = thread_display();
|
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
wine_tsx11_lock();
|
2008-06-21 11:18:07 +02:00
|
|
|
if (!open_xim( display ))
|
|
|
|
XRegisterIMInstantiateCallback( display, NULL, NULL, NULL, open_xim_callback, NULL );
|
2004-01-21 03:22:26 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
static BOOL X11DRV_DestroyIC(XIC xic, XPointer p, XPointer data)
|
|
|
|
{
|
|
|
|
struct x11drv_win_data *win_data = (struct x11drv_win_data *)p;
|
|
|
|
TRACE("xic = %p, win = %lx\n", xic, win_data->whole_window);
|
|
|
|
win_data->xic = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-01-21 03:22:26 +01:00
|
|
|
|
2008-04-04 13:44:36 +02:00
|
|
|
|
|
|
|
XIC X11DRV_CreateIC(XIM xim, struct x11drv_win_data *data)
|
2004-01-21 03:22:26 +01:00
|
|
|
{
|
|
|
|
XPoint spot = {0};
|
|
|
|
XVaNestedList preedit = NULL;
|
|
|
|
XVaNestedList status = NULL;
|
|
|
|
XIC xic;
|
2008-04-15 17:34:54 +02:00
|
|
|
XICCallback destroy = {(XPointer)data, (XICProc)X11DRV_DestroyIC};
|
2010-02-18 15:06:31 +01:00
|
|
|
XICCallback P_StateNotifyCB, P_StartCB, P_DoneCB, P_DrawCB, P_CaretCB;
|
2004-01-21 03:22:26 +01:00
|
|
|
LANGID langid = PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale()));
|
2008-04-04 13:44:36 +02:00
|
|
|
Window win = data->whole_window;
|
2008-10-18 16:03:48 +02:00
|
|
|
XFontSet fontSet = x11drv_thread_data()->font_set;
|
2008-04-04 13:44:36 +02:00
|
|
|
|
|
|
|
TRACE("xim = %p\n", xim);
|
2004-01-21 03:22:26 +01:00
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
|
|
|
|
/* use complex and slow XIC initialization method only for CJK */
|
|
|
|
if (langid != LANG_CHINESE &&
|
|
|
|
langid != LANG_JAPANESE &&
|
|
|
|
langid != LANG_KOREAN)
|
|
|
|
{
|
|
|
|
xic = XCreateIC(xim,
|
|
|
|
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
|
|
|
XNClientWindow, win,
|
|
|
|
XNFocusWindow, win,
|
2008-04-04 13:44:36 +02:00
|
|
|
XNDestroyCallback, &destroy,
|
2005-04-13 17:23:29 +02:00
|
|
|
NULL);
|
2004-01-21 03:22:26 +01:00
|
|
|
wine_tsx11_unlock();
|
2008-04-04 13:44:36 +02:00
|
|
|
data->xic = xic;
|
2004-01-21 03:22:26 +01:00
|
|
|
return xic;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create callbacks */
|
2010-02-18 15:06:31 +01:00
|
|
|
P_StateNotifyCB.client_data = (XPointer)data;
|
2004-01-21 03:22:26 +01:00
|
|
|
P_StartCB.client_data = NULL;
|
|
|
|
P_DoneCB.client_data = NULL;
|
|
|
|
P_DrawCB.client_data = NULL;
|
|
|
|
P_CaretCB.client_data = NULL;
|
2010-02-18 15:06:31 +01:00
|
|
|
P_StateNotifyCB.callback = (XICProc)XIMPreEditStateNotifyCallback;
|
2008-04-15 17:34:54 +02:00
|
|
|
P_StartCB.callback = (XICProc)XIMPreEditStartCallback;
|
|
|
|
P_DoneCB.callback = (XICProc)XIMPreEditDoneCallback;
|
|
|
|
P_DrawCB.callback = (XICProc)XIMPreEditDrawCallback;
|
|
|
|
P_CaretCB.callback = (XICProc)XIMPreEditCaretCallback;
|
2004-01-21 03:22:26 +01:00
|
|
|
|
|
|
|
if ((ximStyle & (XIMPreeditNothing | XIMPreeditNone)) == 0)
|
|
|
|
{
|
|
|
|
preedit = XVaCreateNestedList(0,
|
2008-10-18 16:03:48 +02:00
|
|
|
XNFontSet, fontSet,
|
2004-01-21 03:22:26 +01:00
|
|
|
XNSpotLocation, &spot,
|
2010-02-18 15:06:31 +01:00
|
|
|
XNPreeditStateNotifyCallback, &P_StateNotifyCB,
|
2004-01-21 03:22:26 +01:00
|
|
|
XNPreeditStartCallback, &P_StartCB,
|
|
|
|
XNPreeditDoneCallback, &P_DoneCB,
|
|
|
|
XNPreeditDrawCallback, &P_DrawCB,
|
|
|
|
XNPreeditCaretCallback, &P_CaretCB,
|
|
|
|
NULL);
|
2005-09-12 12:30:05 +02:00
|
|
|
TRACE("preedit = %p\n", preedit);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preedit = XVaCreateNestedList(0,
|
2010-02-18 15:06:31 +01:00
|
|
|
XNPreeditStateNotifyCallback, &P_StateNotifyCB,
|
2004-01-21 03:22:26 +01:00
|
|
|
XNPreeditStartCallback, &P_StartCB,
|
|
|
|
XNPreeditDoneCallback, &P_DoneCB,
|
|
|
|
XNPreeditDrawCallback, &P_DrawCB,
|
|
|
|
XNPreeditCaretCallback, &P_CaretCB,
|
|
|
|
NULL);
|
|
|
|
|
2005-09-12 12:30:05 +02:00
|
|
|
TRACE("preedit = %p\n", preedit);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ximStyle & (XIMStatusNothing | XIMStatusNone)) == 0)
|
|
|
|
{
|
|
|
|
status = XVaCreateNestedList(0,
|
2008-10-18 16:03:48 +02:00
|
|
|
XNFontSet, fontSet,
|
2004-01-21 03:22:26 +01:00
|
|
|
NULL);
|
2005-09-12 12:30:05 +02:00
|
|
|
TRACE("status = %p\n", status);
|
2004-01-21 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (preedit != NULL && status != NULL)
|
|
|
|
{
|
|
|
|
xic = XCreateIC(xim,
|
|
|
|
XNInputStyle, ximStyle,
|
|
|
|
XNPreeditAttributes, preedit,
|
|
|
|
XNStatusAttributes, status,
|
|
|
|
XNClientWindow, win,
|
|
|
|
XNFocusWindow, win,
|
2008-04-04 13:44:36 +02:00
|
|
|
XNDestroyCallback, &destroy,
|
2004-01-21 03:22:26 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (preedit != NULL)
|
|
|
|
{
|
|
|
|
xic = XCreateIC(xim,
|
|
|
|
XNInputStyle, ximStyle,
|
|
|
|
XNPreeditAttributes, preedit,
|
|
|
|
XNClientWindow, win,
|
|
|
|
XNFocusWindow, win,
|
2008-04-04 13:44:36 +02:00
|
|
|
XNDestroyCallback, &destroy,
|
2004-01-21 03:22:26 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (status != NULL)
|
|
|
|
{
|
|
|
|
xic = XCreateIC(xim,
|
|
|
|
XNInputStyle, ximStyle,
|
|
|
|
XNStatusAttributes, status,
|
|
|
|
XNClientWindow, win,
|
|
|
|
XNFocusWindow, win,
|
2008-04-04 13:44:36 +02:00
|
|
|
XNDestroyCallback, &destroy,
|
2004-01-21 03:22:26 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xic = XCreateIC(xim,
|
|
|
|
XNInputStyle, ximStyle,
|
|
|
|
XNClientWindow, win,
|
|
|
|
XNFocusWindow, win,
|
2008-04-04 13:44:36 +02:00
|
|
|
XNDestroyCallback, &destroy,
|
2004-01-21 03:22:26 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2005-09-12 12:30:05 +02:00
|
|
|
TRACE("xic = %p\n", xic);
|
2008-04-04 13:44:36 +02:00
|
|
|
data->xic = xic;
|
2004-01-21 03:22:26 +01:00
|
|
|
|
|
|
|
if (preedit != NULL)
|
|
|
|
XFree(preedit);
|
|
|
|
if (status != NULL)
|
|
|
|
XFree(status);
|
|
|
|
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
return xic;
|
|
|
|
}
|