winemac: Use unixlib interface for macdrv_ime_set_text calls.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
Jacek Caban 2022-05-31 21:06:20 +02:00 committed by Alexandre Julliard
parent fa670ef001
commit 7fa47e47c9
6 changed files with 89 additions and 30 deletions

View file

@ -26,9 +26,19 @@
HMODULE macdrv_module = 0;
typedef NTSTATUS (WINAPI *kernel_callback)(void *params, ULONG size);
static const kernel_callback kernel_callbacks[] =
{
macdrv_ime_set_text,
};
C_ASSERT(NtUserDriverCallbackFirst + ARRAYSIZE(kernel_callbacks) == client_func_last);
static BOOL process_attach(void)
{
struct init_params params;
void **callback_table;
struct localized_string *str;
struct localized_string strings[] = {
@ -53,7 +63,12 @@ static BOOL process_attach(void)
str->len = LoadStringW(macdrv_module, str->id, (WCHAR *)&str->str, 0);
params.strings = strings;
return !MACDRV_CALL(init, &params);
if (MACDRV_CALL(init, &params)) return FALSE;
callback_table = NtCurrentTeb()->Peb->KernelCallbackTable;
memcpy( callback_table + NtUserDriverCallbackFirst, kernel_callbacks, sizeof(kernel_callbacks) );
return TRUE;
}
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)

View file

@ -141,6 +141,34 @@ static macdrv_event_mask get_event_mask(DWORD mask)
}
/***********************************************************************
* macdrv_im_set_text
*/
static void macdrv_im_set_text(const macdrv_event *event)
{
HWND hwnd = macdrv_get_window_hwnd(event->window);
struct ime_set_text_params *params;
CFIndex length = 0, size;
TRACE_(imm)("win %p/%p himc %p text %s complete %u\n", hwnd, event->window, event->im_set_text.data,
debugstr_cf(event->im_set_text.text), event->im_set_text.complete);
if (event->im_set_text.text)
length = CFStringGetLength(event->im_set_text.text);
size = offsetof(struct ime_set_text_params, text[length]);
if (!(params = malloc(size))) return;
params->hwnd = hwnd;
params->data = event->im_set_text.data;
params->cursor_pos = event->im_set_text.cursor_pos;
params->complete = event->im_set_text.complete;
if (length)
CFStringGetCharacters(event->im_set_text.text, CFRangeMake(0, length), params->text);
macdrv_client_func(client_func_ime_set_text, params, size);
}
/***********************************************************************
* macdrv_sent_text_input
*/

View file

@ -1395,38 +1395,25 @@ BOOL WINAPI ImeInquire(LPIMEINFO lpIMEInfo, LPWSTR lpszUIClass, LPCWSTR lpszOpti
/* Interfaces to other parts of the Mac driver */
/***********************************************************************
* macdrv_im_set_text
* macdrv_ime_set_text
*/
void macdrv_im_set_text(const macdrv_event *event)
NTSTATUS WINAPI macdrv_ime_set_text(void *arg, ULONG size)
{
HWND hwnd = macdrv_get_window_hwnd(event->window);
void *himc = event->im_set_text.data;
TRACE("win %p/%p himc %p text %s complete %u\n", hwnd, event->window, himc,
debugstr_cf(event->im_set_text.text), event->im_set_text.complete);
struct ime_set_text_params *params = arg;
ULONG length = (size - offsetof(struct ime_set_text_params, text)) / sizeof(WCHAR);
void *himc = params->data;
if (!himc) himc = RealIMC(FROM_MACDRV);
if (event->im_set_text.text)
if (length)
{
CFIndex length = CFStringGetLength(event->im_set_text.text);
const UniChar *chars = CFStringGetCharactersPtr(event->im_set_text.text);
UniChar *buffer = NULL;
if (!chars)
{
buffer = HeapAlloc(GetProcessHeap(), 0, length * sizeof(*buffer));
CFStringGetCharacters(event->im_set_text.text, CFRangeMake(0, length), buffer);
chars = buffer;
}
if (himc)
IME_SetCompositionString(himc, SCS_SETSTR, chars, length * sizeof(*chars),
event->im_set_text.cursor_pos, !event->im_set_text.complete);
IME_SetCompositionString(himc, SCS_SETSTR, params->text, length * sizeof(WCHAR),
params->cursor_pos, !params->complete);
else
{
INPUT input;
CFIndex i;
unsigned int i;
input.type = INPUT_KEYBOARD;
input.ki.wVk = 0;
@ -1435,20 +1422,19 @@ void macdrv_im_set_text(const macdrv_event *event)
for (i = 0; i < length; i++)
{
input.ki.wScan = chars[i];
input.ki.wScan = params->text[i];
input.ki.dwFlags = KEYEVENTF_UNICODE;
__wine_send_input(hwnd, &input, NULL);
__wine_send_input(params->hwnd, &input, NULL);
input.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
__wine_send_input(hwnd, &input, NULL);
__wine_send_input(params->hwnd, &input, NULL);
}
}
HeapFree(GetProcessHeap(), 0, buffer);
}
if (event->im_set_text.complete)
if (params->complete)
IME_NotifyComplete(himc);
return 0;
}
/**************************************************************************

View file

@ -289,13 +289,16 @@ extern CGImageRef create_cgimage_from_icon_bitmaps(HDC hdc, HANDLE icon, HBITMAP
extern NTSTATUS macdrv_ime_process_text_input(void *arg) DECLSPEC_HIDDEN;
extern void macdrv_im_set_text(const macdrv_event *event) DECLSPEC_HIDDEN;
extern NTSTATUS WINAPI macdrv_ime_set_text(void *params, ULONG size) DECLSPEC_HIDDEN;
extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
/* unixlib interface */
extern NTSTATUS macdrv_notify_icon(void *arg) DECLSPEC_HIDDEN;
extern NTSTATUS macdrv_client_func(enum macdrv_client_funcs func, const void *params,
ULONG size) DECLSPEC_HIDDEN;
/* user helpers */
static inline LRESULT send_message(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)

View file

@ -607,6 +607,14 @@ BOOL macdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param,
}
NTSTATUS macdrv_client_func(enum macdrv_client_funcs id, const void *params, ULONG size)
{
/* FIXME: use KeUserModeCallback instead */
NTSTATUS (WINAPI *func)(const void *, ULONG) = ((void **)NtCurrentTeb()->Peb->KernelCallbackTable)[id];
return func(params, size);
}
static NTSTATUS macdrv_ime_using_input_method(void *arg)
{
return macdrv_using_input_method();

View file

@ -62,3 +62,22 @@
DWORD msg;
struct _NOTIFYICONDATAW *data;
};
/* driver client callbacks exposed with KernelCallbackTable interface */
enum macdrv_client_funcs
{
client_func_ime_set_text = NtUserDriverCallbackFirst,
client_func_last
};
/* macdrv_ime_set_text params */
struct ime_set_text_params
{
HWND hwnd;
void *data;
UINT32 cursor_pos;
UINT32 complete;
WCHAR text[1];
};
C_ASSERT(client_func_last <= NtUserDriverCallbackLast + 1);