winemac: Use the default ImeToAsciiEx implementation.
And support updates pushed from the host IME directly.
This commit is contained in:
parent
2d6fa95217
commit
f341b8003c
3 changed files with 10 additions and 121 deletions
|
@ -34,25 +34,6 @@
|
|||
WINE_DEFAULT_DEBUG_CHANNEL(event);
|
||||
WINE_DECLARE_DEBUG_CHANNEL(imm);
|
||||
|
||||
/* IME works synchronously, key input is passed from ImeProcessKey, to the
|
||||
* host IME. We wait for it to be handled, or not, which is notified using
|
||||
* the sent_text_input event. Meanwhile, while processing the key, the host
|
||||
* IME may send one or more im_set_text events to update the input text.
|
||||
*
|
||||
* If ImeProcessKey returns TRUE, ImeToAsciiEx is then be called to retrieve
|
||||
* the composition string updates. We use ime_update.comp_str != NULL as flag that
|
||||
* composition is started, even if the preedit text is empty.
|
||||
*
|
||||
* If ImeProcessKey returns FALSE, ImeToAsciiEx will not be called.
|
||||
*/
|
||||
struct ime_update
|
||||
{
|
||||
DWORD cursor_pos;
|
||||
WCHAR *comp_str;
|
||||
WCHAR *result_str;
|
||||
};
|
||||
static struct ime_update ime_update;
|
||||
|
||||
/* return the name of an Mac event */
|
||||
static const char *dbgstr_event(int type)
|
||||
{
|
||||
|
@ -166,6 +147,11 @@ static macdrv_event_mask get_event_mask(DWORD mask)
|
|||
return event_mask;
|
||||
}
|
||||
|
||||
static void post_ime_update( HWND hwnd, UINT cursor_pos, WCHAR *comp_str, WCHAR *result_str )
|
||||
{
|
||||
NtUserMessageCall( hwnd, WINE_IME_POST_UPDATE, cursor_pos, (LPARAM)comp_str,
|
||||
result_str, NtUserImeDriverCall, FALSE );
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* macdrv_im_set_text
|
||||
|
@ -173,7 +159,6 @@ static macdrv_event_mask get_event_mask(DWORD mask)
|
|||
static void macdrv_im_set_text(const macdrv_event *event)
|
||||
{
|
||||
HWND hwnd = macdrv_get_window_hwnd(event->window);
|
||||
CFIndex length = 0;
|
||||
WCHAR *text = NULL;
|
||||
|
||||
TRACE_(imm)("win %p/%p himc %p text %s complete %u\n", hwnd, event->window, event->im_set_text.himc,
|
||||
|
@ -181,27 +166,16 @@ static void macdrv_im_set_text(const macdrv_event *event)
|
|||
|
||||
if (event->im_set_text.text)
|
||||
{
|
||||
length = CFStringGetLength(event->im_set_text.text);
|
||||
CFIndex length = CFStringGetLength(event->im_set_text.text);
|
||||
if (!(text = malloc((length + 1) * sizeof(WCHAR)))) return;
|
||||
if (length) CFStringGetCharacters(event->im_set_text.text, CFRangeMake(0, length), text);
|
||||
text[length] = 0;
|
||||
}
|
||||
|
||||
/* discard any pending comp text */
|
||||
free(ime_update.comp_str);
|
||||
ime_update.comp_str = NULL;
|
||||
ime_update.cursor_pos = -1;
|
||||
if (event->im_set_text.complete) post_ime_update(hwnd, -1, NULL, text);
|
||||
else post_ime_update(hwnd, event->im_set_text.cursor_pos, text, NULL);
|
||||
|
||||
if (event->im_set_text.complete)
|
||||
{
|
||||
free(ime_update.result_str);
|
||||
ime_update.result_str = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
ime_update.comp_str = text;
|
||||
ime_update.cursor_pos = event->im_set_text.cursor_pos;
|
||||
}
|
||||
free(text);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -210,90 +184,7 @@ static void macdrv_im_set_text(const macdrv_event *event)
|
|||
static void macdrv_sent_text_input(const macdrv_event *event)
|
||||
{
|
||||
TRACE_(imm)("handled: %s\n", event->sent_text_input.handled ? "TRUE" : "FALSE");
|
||||
*event->sent_text_input.done = event->sent_text_input.handled || ime_update.result_str ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* ImeToAsciiEx (MACDRV.@)
|
||||
*/
|
||||
UINT macdrv_ImeToAsciiEx(UINT vkey, UINT vsc, const BYTE *state, COMPOSITIONSTRING *compstr, HIMC himc)
|
||||
{
|
||||
UINT needed = sizeof(COMPOSITIONSTRING), comp_len, result_len;
|
||||
struct ime_update *update = &ime_update;
|
||||
void *dst;
|
||||
|
||||
TRACE_(imm)("vkey %#x, vsc %#x, state %p, compstr %p, himc %p\n", vkey, vsc, state, compstr, himc);
|
||||
|
||||
if (!update->comp_str) comp_len = 0;
|
||||
else
|
||||
{
|
||||
comp_len = wcslen(update->comp_str);
|
||||
needed += comp_len * sizeof(WCHAR); /* GCS_COMPSTR */
|
||||
needed += comp_len; /* GCS_COMPATTR */
|
||||
needed += 2 * sizeof(DWORD); /* GCS_COMPCLAUSE */
|
||||
}
|
||||
|
||||
if (!update->result_str) result_len = 0;
|
||||
else
|
||||
{
|
||||
result_len = wcslen(update->result_str);
|
||||
needed += result_len * sizeof(WCHAR); /* GCS_RESULTSTR */
|
||||
needed += 2 * sizeof(DWORD); /* GCS_RESULTCLAUSE */
|
||||
}
|
||||
|
||||
if (compstr->dwSize < needed)
|
||||
{
|
||||
compstr->dwSize = needed;
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memset( compstr, 0, sizeof(*compstr) );
|
||||
compstr->dwSize = sizeof(*compstr);
|
||||
|
||||
if (update->comp_str)
|
||||
{
|
||||
compstr->dwCursorPos = update->cursor_pos;
|
||||
|
||||
compstr->dwCompStrLen = comp_len;
|
||||
compstr->dwCompStrOffset = compstr->dwSize;
|
||||
dst = (BYTE *)compstr + compstr->dwCompStrOffset;
|
||||
memcpy(dst, update->comp_str, compstr->dwCompStrLen * sizeof(WCHAR));
|
||||
compstr->dwSize += compstr->dwCompStrLen * sizeof(WCHAR);
|
||||
|
||||
compstr->dwCompClauseLen = 2 * sizeof(DWORD);
|
||||
compstr->dwCompClauseOffset = compstr->dwSize;
|
||||
dst = (BYTE *)compstr + compstr->dwCompClauseOffset;
|
||||
*((DWORD *)dst + 0) = 0;
|
||||
*((DWORD *)dst + 1) = compstr->dwCompStrLen;
|
||||
compstr->dwSize += compstr->dwCompClauseLen;
|
||||
|
||||
compstr->dwCompAttrLen = compstr->dwCompStrLen;
|
||||
compstr->dwCompAttrOffset = compstr->dwSize;
|
||||
dst = (BYTE *)compstr + compstr->dwCompAttrOffset;
|
||||
memset(dst, ATTR_INPUT, compstr->dwCompAttrLen);
|
||||
compstr->dwSize += compstr->dwCompAttrLen;
|
||||
}
|
||||
|
||||
if (update->result_str)
|
||||
{
|
||||
compstr->dwResultStrLen = result_len;
|
||||
compstr->dwResultStrOffset = compstr->dwSize;
|
||||
dst = (BYTE *)compstr + compstr->dwResultStrOffset;
|
||||
memcpy(dst, update->result_str, compstr->dwResultStrLen * sizeof(WCHAR));
|
||||
compstr->dwSize += compstr->dwResultStrLen * sizeof(WCHAR);
|
||||
|
||||
compstr->dwResultClauseLen = 2 * sizeof(DWORD);
|
||||
compstr->dwResultClauseOffset = compstr->dwSize;
|
||||
dst = (BYTE *)compstr + compstr->dwResultClauseOffset;
|
||||
*((DWORD *)dst + 0) = 0;
|
||||
*((DWORD *)dst + 1) = compstr->dwResultStrLen;
|
||||
compstr->dwSize += compstr->dwResultClauseLen;
|
||||
}
|
||||
|
||||
free(update->result_str);
|
||||
update->result_str = NULL;
|
||||
return 0;
|
||||
*event->sent_text_input.done = event->sent_text_input.handled ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -304,7 +304,6 @@ static const struct user_driver_funcs macdrv_funcs =
|
|||
.pUpdateLayeredWindow = macdrv_UpdateLayeredWindow,
|
||||
.pVkKeyScanEx = macdrv_VkKeyScanEx,
|
||||
.pImeProcessKey = macdrv_ImeProcessKey,
|
||||
.pImeToAsciiEx = macdrv_ImeToAsciiEx,
|
||||
.pNotifyIMEStatus = macdrv_NotifyIMEStatus,
|
||||
.pWindowMessage = macdrv_WindowMessage,
|
||||
.pWindowPosChanged = macdrv_WindowPosChanged,
|
||||
|
|
|
@ -167,7 +167,6 @@ extern BOOL macdrv_RegisterHotKey(HWND hwnd, UINT mod_flags, UINT vkey);
|
|||
extern void macdrv_UnregisterHotKey(HWND hwnd, UINT modifiers, UINT vkey);
|
||||
extern SHORT macdrv_VkKeyScanEx(WCHAR wChar, HKL hkl);
|
||||
extern UINT macdrv_ImeProcessKey(HIMC himc, UINT wparam, UINT lparam, const BYTE *state);
|
||||
extern UINT macdrv_ImeToAsciiEx(UINT vkey, UINT vsc, const BYTE *state, COMPOSITIONSTRING *compstr, HIMC himc);
|
||||
extern UINT macdrv_MapVirtualKeyEx(UINT wCode, UINT wMapType, HKL hkl);
|
||||
extern INT macdrv_ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
|
||||
LPWSTR bufW, int bufW_size, UINT flags, HKL hkl);
|
||||
|
|
Loading…
Add table
Reference in a new issue