wined3d: Do not set last_was_pshader from the GLSL fragment pipe.
[wine.git] / dlls / imm32 / ime.c
blob60672b366ab4a4ee4bed322aa5a8adaf2deb8d9d
1 /*
2 * Copyright 2023 RĂ©mi Bernon for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stddef.h>
22 #include "imm_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(imm);
26 struct ime_private
28 BOOL in_composition;
29 HFONT hfont;
32 static const char *debugstr_imn( WPARAM wparam )
34 switch (wparam)
36 case IMN_OPENSTATUSWINDOW: return "IMN_OPENSTATUSWINDOW";
37 case IMN_CLOSESTATUSWINDOW: return "IMN_CLOSESTATUSWINDOW";
38 case IMN_OPENCANDIDATE: return "IMN_OPENCANDIDATE";
39 case IMN_CHANGECANDIDATE: return "IMN_CHANGECANDIDATE";
40 case IMN_CLOSECANDIDATE: return "IMN_CLOSECANDIDATE";
41 case IMN_SETCONVERSIONMODE: return "IMN_SETCONVERSIONMODE";
42 case IMN_SETSENTENCEMODE: return "IMN_SETSENTENCEMODE";
43 case IMN_SETOPENSTATUS: return "IMN_SETOPENSTATUS";
44 case IMN_SETCANDIDATEPOS: return "IMN_SETCANDIDATEPOS";
45 case IMN_SETCOMPOSITIONFONT: return "IMN_SETCOMPOSITIONFONT";
46 case IMN_SETCOMPOSITIONWINDOW: return "IMN_SETCOMPOSITIONWINDOW";
47 case IMN_GUIDELINE: return "IMN_GUIDELINE";
48 case IMN_SETSTATUSWINDOWPOS: return "IMN_SETSTATUSWINDOWPOS";
49 case IMN_WINE_SET_OPEN_STATUS: return "IMN_WINE_SET_OPEN_STATUS";
50 case IMN_WINE_SET_COMP_STRING: return "IMN_WINE_SET_COMP_STRING";
51 default: return wine_dbg_sprintf( "%#Ix", wparam );
55 static const char *debugstr_imc( WPARAM wparam )
57 switch (wparam)
59 case IMC_GETCANDIDATEPOS: return "IMC_GETCANDIDATEPOS";
60 case IMC_SETCANDIDATEPOS: return "IMC_SETCANDIDATEPOS";
61 case IMC_GETCOMPOSITIONFONT: return "IMC_GETCOMPOSITIONFONT";
62 case IMC_SETCOMPOSITIONFONT: return "IMC_SETCOMPOSITIONFONT";
63 case IMC_GETCOMPOSITIONWINDOW: return "IMC_GETCOMPOSITIONWINDOW";
64 case IMC_SETCOMPOSITIONWINDOW: return "IMC_SETCOMPOSITIONWINDOW";
65 case IMC_GETSTATUSWINDOWPOS: return "IMC_GETSTATUSWINDOWPOS";
66 case IMC_SETSTATUSWINDOWPOS: return "IMC_SETSTATUSWINDOWPOS";
67 case IMC_CLOSESTATUSWINDOW: return "IMC_CLOSESTATUSWINDOW";
68 case IMC_OPENSTATUSWINDOW: return "IMC_OPENSTATUSWINDOW";
69 default: return wine_dbg_sprintf( "%#Ix", wparam );
73 static WCHAR *input_context_get_comp_str( INPUTCONTEXT *ctx, BOOL result, UINT *length )
75 COMPOSITIONSTRING *string;
76 WCHAR *text = NULL;
77 UINT len, off;
79 if (!(string = ImmLockIMCC( ctx->hCompStr ))) return NULL;
80 len = result ? string->dwResultStrLen : string->dwCompStrLen;
81 off = result ? string->dwResultStrOffset : string->dwCompStrOffset;
83 if (len && off && (text = malloc( (len + 1) * sizeof(WCHAR) )))
85 memcpy( text, (BYTE *)string + off, len * sizeof(WCHAR) );
86 text[len] = 0;
87 *length = len;
90 ImmUnlockIMCC( ctx->hCompStr );
91 return text;
94 static void input_context_set_comp_str( INPUTCONTEXT *ctx, const WCHAR *str, UINT len )
96 COMPOSITIONSTRING *compstr;
97 HIMCC himcc;
98 UINT size;
99 BYTE *dst;
101 TRACE( "ctx %p, str %s\n", ctx, debugstr_wn( str, len ) );
103 size = sizeof(*compstr);
104 size += len * sizeof(WCHAR); /* GCS_COMPSTR */
105 size += len; /* GCS_COMPSTRATTR */
106 size += 2 * sizeof(DWORD); /* GCS_COMPSTRCLAUSE */
108 if (!(himcc = ImmReSizeIMCC( ctx->hCompStr, size )))
109 WARN( "Failed to resize input context composition string\n" );
110 else if (!(compstr = ImmLockIMCC( (ctx->hCompStr = himcc) )))
111 WARN( "Failed to lock input context composition string\n" );
112 else
114 memset( compstr, 0, sizeof(*compstr) );
115 compstr->dwSize = sizeof(*compstr);
117 if (len)
119 compstr->dwCursorPos = len;
121 compstr->dwCompStrLen = len;
122 compstr->dwCompStrOffset = compstr->dwSize;
123 dst = (BYTE *)compstr + compstr->dwCompStrOffset;
124 memcpy( dst, str, compstr->dwCompStrLen * sizeof(WCHAR) );
125 compstr->dwSize += compstr->dwCompStrLen * sizeof(WCHAR);
127 compstr->dwCompClauseLen = 2 * sizeof(DWORD);
128 compstr->dwCompClauseOffset = compstr->dwSize;
129 dst = (BYTE *)compstr + compstr->dwCompClauseOffset;
130 *((DWORD *)dst + 0) = 0;
131 *((DWORD *)dst + 1) = compstr->dwCompStrLen;
132 compstr->dwSize += compstr->dwCompClauseLen;
134 compstr->dwCompAttrLen = compstr->dwCompStrLen;
135 compstr->dwCompAttrOffset = compstr->dwSize;
136 dst = (BYTE *)compstr + compstr->dwCompAttrOffset;
137 memset( dst, ATTR_INPUT, compstr->dwCompAttrLen );
138 compstr->dwSize += compstr->dwCompAttrLen;
141 ImmUnlockIMCC( ctx->hCompStr );
145 static HFONT input_context_select_ui_font( INPUTCONTEXT *ctx, HDC hdc )
147 struct ime_private *priv;
148 HFONT font = NULL;
149 if (!(priv = ImmLockIMCC( ctx->hPrivate ))) return NULL;
150 if (priv->hfont) font = SelectObject( hdc, priv->hfont );
151 ImmUnlockIMCC( ctx->hPrivate );
152 return font;
155 static void ime_send_message( HIMC himc, UINT message, WPARAM wparam, LPARAM lparam )
157 INPUTCONTEXT *ctx;
158 TRANSMSG *msgs;
159 HIMCC himcc;
161 if (!(ctx = ImmLockIMC( himc ))) return;
162 if (!(himcc = ImmReSizeIMCC( ctx->hMsgBuf, (ctx->dwNumMsgBuf + 1) * sizeof(*msgs) )))
163 WARN( "Failed to resize input context message buffer\n" );
164 else if (!(msgs = ImmLockIMCC( (ctx->hMsgBuf = himcc) )))
165 WARN( "Failed to lock input context message buffer\n" );
166 else
168 TRANSMSG msg = {.message = message, .wParam = wparam, .lParam = lparam};
169 msgs[ctx->dwNumMsgBuf++] = msg;
170 ImmUnlockIMCC( ctx->hMsgBuf );
173 ImmUnlockIMC( himc );
174 ImmGenerateMessage( himc );
177 static UINT ime_set_composition_status( HIMC himc, BOOL composition )
179 struct ime_private *priv;
180 INPUTCONTEXT *ctx;
181 UINT msg = 0;
183 if (!(ctx = ImmLockIMC( himc ))) return 0;
184 if ((priv = ImmLockIMCC( ctx->hPrivate )))
186 if (!priv->in_composition && composition) msg = WM_IME_STARTCOMPOSITION;
187 else if (priv->in_composition && !composition) msg = WM_IME_ENDCOMPOSITION;
188 priv->in_composition = composition;
189 ImmUnlockIMCC( ctx->hPrivate );
191 ImmUnlockIMC( himc );
193 return msg;
196 static void ime_ui_paint( HIMC himc, HWND hwnd )
198 PAINTSTRUCT ps;
199 RECT rect, new_rect;
200 HDC hdc;
201 HMONITOR monitor;
202 MONITORINFO mon_info;
203 INPUTCONTEXT *ctx;
204 POINT offset;
205 WCHAR *str;
206 UINT len;
208 if (!(ctx = ImmLockIMC( himc ))) return;
210 hdc = BeginPaint( hwnd, &ps );
212 GetClientRect( hwnd, &rect );
213 FillRect( hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1) );
214 new_rect = rect;
216 if ((str = input_context_get_comp_str( ctx, FALSE, &len )))
218 HFONT font = input_context_select_ui_font( ctx, hdc );
219 SIZE size;
220 POINT pt;
222 GetTextExtentPoint32W( hdc, str, len, &size );
223 pt.x = size.cx;
224 pt.y = size.cy;
225 LPtoDP( hdc, &pt, 1 );
228 * How this works based on tests on windows:
229 * CFS_POINT: then we start our window at the point and grow it as large
230 * as it needs to be for the string.
231 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
232 * window is only as large as we need for the string, but we do not
233 * grow such that our window exceeds the given rect. Wrapping if
234 * needed and possible. If our ptCurrentPos is outside of our rect
235 * then no window is displayed.
236 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
237 * maybe because the default MSIME does not do any IME adjusting.
239 if (ctx->cfCompForm.dwStyle != CFS_DEFAULT)
241 POINT cpt = ctx->cfCompForm.ptCurrentPos;
242 ClientToScreen( ctx->hWnd, &cpt );
243 rect.left = cpt.x;
244 rect.top = cpt.y;
245 rect.right = rect.left + pt.x;
246 rect.bottom = rect.top + pt.y;
247 offset.x = offset.y = 0;
248 monitor = MonitorFromPoint( cpt, MONITOR_DEFAULTTOPRIMARY );
250 else /* CFS_DEFAULT */
252 /* Windows places the default IME window in the bottom left */
253 HWND target = ctx->hWnd;
254 if (!target) target = GetFocus();
256 GetWindowRect( target, &rect );
257 rect.top = rect.bottom;
258 rect.right = rect.left + pt.x + 20;
259 rect.bottom = rect.top + pt.y + 20;
260 offset.x = offset.y = 10;
261 monitor = MonitorFromWindow( target, MONITOR_DEFAULTTOPRIMARY );
264 if (ctx->cfCompForm.dwStyle == CFS_RECT)
266 RECT client = ctx->cfCompForm.rcArea;
267 MapWindowPoints( ctx->hWnd, 0, (POINT *)&client, 2 );
268 IntersectRect( &rect, &rect, &client );
269 DrawTextW( hdc, str, len, &rect, DT_WORDBREAK | DT_CALCRECT );
272 if (ctx->cfCompForm.dwStyle == CFS_DEFAULT)
274 /* make sure we are on the desktop */
275 mon_info.cbSize = sizeof(mon_info);
276 GetMonitorInfoW( monitor, &mon_info );
278 if (rect.bottom > mon_info.rcWork.bottom)
280 int shift = rect.bottom - mon_info.rcWork.bottom;
281 rect.top -= shift;
282 rect.bottom -= shift;
284 if (rect.left < 0)
286 rect.right -= rect.left;
287 rect.left = 0;
289 if (rect.right > mon_info.rcWork.right)
291 int shift = rect.right - mon_info.rcWork.right;
292 rect.left -= shift;
293 rect.right -= shift;
297 new_rect = rect;
298 OffsetRect( &rect, offset.x - rect.left, offset.y - rect.top );
299 DrawTextW( hdc, str, len, &rect, DT_WORDBREAK );
301 if (font) SelectObject( hdc, font );
302 free( str );
305 EndPaint( hwnd, &ps );
306 ImmUnlockIMC( himc );
308 if (!EqualRect( &rect, &new_rect ))
309 SetWindowPos( hwnd, HWND_TOPMOST, new_rect.left, new_rect.top, new_rect.right - new_rect.left,
310 new_rect.bottom - new_rect.top, SWP_NOACTIVATE );
313 static void ime_ui_update_window( INPUTCONTEXT *ctx, HWND hwnd )
315 WCHAR *str;
316 UINT len;
318 if (!(str = input_context_get_comp_str( ctx, FALSE, &len )) || !*str)
319 ShowWindow( hwnd, SW_HIDE );
320 else
322 ShowWindow( hwnd, SW_SHOWNOACTIVATE );
323 RedrawWindow( hwnd, NULL, NULL, RDW_ERASENOW | RDW_INVALIDATE );
325 free( str );
327 ctx->hWnd = GetFocus();
330 static void ime_ui_composition( HIMC himc, HWND hwnd, LPARAM lparam )
332 INPUTCONTEXT *ctx;
333 if (lparam & GCS_RESULTSTR) return;
334 if (!(ctx = ImmLockIMC( himc ))) return;
335 ime_ui_update_window( ctx, hwnd );
336 ImmUnlockIMC( himc );
339 static void ime_ui_start_composition( HIMC himc, HWND hwnd )
341 INPUTCONTEXT *ctx;
342 if (!(ctx = ImmLockIMC( himc ))) return;
343 ime_ui_update_window( ctx, hwnd );
344 ImmUnlockIMC( himc );
347 static UINT ime_set_comp_string( HIMC himc, LPARAM lparam )
349 union
351 struct
353 UINT uMsgCount;
354 TRANSMSG TransMsg[10];
356 TRANSMSGLIST list;
357 } buffer = {.uMsgCount = ARRAY_SIZE(buffer.TransMsg)};
358 INPUTCONTEXT *ctx;
359 TRANSMSG *msgs;
360 HIMCC himcc;
361 UINT count;
363 TRACE( "himc %p\n", himc );
365 if (!(ctx = ImmLockIMC( himc ))) return 0;
367 count = ImeToAsciiEx( VK_PROCESSKEY, lparam, NULL, &buffer.list, 0, himc );
368 if (!count)
369 TRACE( "ImeToAsciiEx returned no messages\n" );
370 else if (count >= buffer.uMsgCount)
371 WARN( "ImeToAsciiEx returned %#x messages\n", count );
372 else if (!(himcc = ImmReSizeIMCC( ctx->hMsgBuf, (ctx->dwNumMsgBuf + count) * sizeof(*msgs) )))
373 WARN( "Failed to resize input context message buffer\n" );
374 else if (!(msgs = ImmLockIMCC( (ctx->hMsgBuf = himcc) )))
375 WARN( "Failed to lock input context message buffer\n" );
376 else
378 memcpy( msgs + ctx->dwNumMsgBuf, buffer.TransMsg, count * sizeof(*msgs) );
379 ImmUnlockIMCC( ctx->hMsgBuf );
380 ctx->dwNumMsgBuf += count;
383 ImmUnlockIMC( himc );
384 ImmGenerateMessage( himc );
386 return count;
389 static LRESULT ime_ui_notify( HIMC himc, HWND hwnd, WPARAM wparam, LPARAM lparam )
391 TRACE( "himc %p, hwnd %p, wparam %s, lparam %#Ix\n", hwnd, himc, debugstr_imn(wparam), lparam );
393 switch (wparam)
395 case IMN_WINE_SET_OPEN_STATUS:
396 return ImmSetOpenStatus( himc, lparam );
397 case IMN_WINE_SET_COMP_STRING:
398 return ime_set_comp_string( himc, lparam );
399 default:
400 return 0;
404 static LRESULT WINAPI ime_ui_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
406 HIMC himc = (HIMC)GetWindowLongPtrW( hwnd, IMMGWL_IMC );
408 TRACE( "hwnd %p, himc %p, msg %s, wparam %#Ix, lparam %#Ix\n",
409 hwnd, himc, debugstr_wm_ime(msg), wparam, lparam );
411 switch (msg)
413 case WM_CREATE:
414 return TRUE;
415 case WM_PAINT:
416 ime_ui_paint( himc, hwnd );
417 return FALSE;
418 case WM_SETFOCUS:
419 if (wparam) SetFocus( (HWND)wparam );
420 else FIXME( "Received focus, should never have focus\n" );
421 break;
422 case WM_IME_COMPOSITION:
423 ime_ui_composition( himc, hwnd, lparam );
424 break;
425 case WM_IME_STARTCOMPOSITION:
426 ime_ui_start_composition( himc, hwnd );
427 break;
428 case WM_IME_ENDCOMPOSITION:
429 ShowWindow( hwnd, SW_HIDE );
430 break;
431 case WM_IME_NOTIFY:
432 return ime_ui_notify( himc, hwnd, wparam, lparam );
433 case WM_IME_CONTROL:
434 FIXME( "hwnd %p, himc %p, msg %s, wparam %s, lparam %#Ix stub!\n", hwnd, himc,
435 debugstr_wm_ime(msg), debugstr_imc(wparam), lparam );
436 return 1;
439 return DefWindowProcW( hwnd, msg, wparam, lparam );
442 static WNDCLASSEXW ime_ui_class =
444 .cbSize = sizeof(WNDCLASSEXW),
445 .style = CS_GLOBALCLASS | CS_IME | CS_HREDRAW | CS_VREDRAW,
446 .lpfnWndProc = ime_ui_window_proc,
447 .cbWndExtra = 2 * sizeof(LONG_PTR),
448 .lpszClassName = L"Wine IME",
449 .hbrBackground = (HBRUSH)(COLOR_WINDOW + 1),
452 BOOL WINAPI ImeInquire( IMEINFO *info, WCHAR *ui_class, DWORD flags )
454 TRACE( "info %p, ui_class %p, flags %#lx\n", info, ui_class, flags );
456 ime_ui_class.hInstance = imm32_module;
457 ime_ui_class.hCursor = LoadCursorW( NULL, (LPWSTR)IDC_ARROW );
458 ime_ui_class.hIcon = LoadIconW( NULL, (LPWSTR)IDI_APPLICATION );
459 RegisterClassExW( &ime_ui_class );
461 wcscpy( ui_class, ime_ui_class.lpszClassName );
462 memset( info, 0, sizeof(*info) );
463 info->dwPrivateDataSize = sizeof(struct ime_private);
464 info->fdwProperty = IME_PROP_UNICODE | IME_PROP_AT_CARET;
465 info->fdwConversionCaps = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
466 info->fdwSentenceCaps = IME_SMODE_AUTOMATIC;
467 info->fdwUICaps = UI_CAP_2700;
468 /* Tell App we cannot accept ImeSetCompositionString calls */
469 info->fdwSCSCaps = 0;
470 info->fdwSelectCaps = SELECT_CAP_CONVERSION;
472 return TRUE;
475 BOOL WINAPI ImeDestroy( UINT force )
477 TRACE( "force %u\n", force );
478 UnregisterClassW( ime_ui_class.lpszClassName, imm32_module );
479 return TRUE;
482 BOOL WINAPI ImeSelect( HIMC himc, BOOL select )
484 struct ime_private *priv;
485 INPUTCONTEXT *ctx;
487 TRACE( "himc %p, select %u\n", himc, select );
489 if (!himc || !select) return TRUE;
490 if (!(ctx = ImmLockIMC( himc ))) return FALSE;
492 ImmSetOpenStatus( himc, FALSE );
494 if ((priv = ImmLockIMCC( ctx->hPrivate )))
496 memset( priv, 0, sizeof(*priv) );
497 ImmUnlockIMCC( ctx->hPrivate );
500 ImmUnlockIMC( himc );
501 return TRUE;
504 BOOL WINAPI ImeSetActiveContext( HIMC himc, BOOL flag )
506 TRACE( "himc %p, flag %#x stub!\n", himc, flag );
507 return TRUE;
510 BOOL WINAPI ImeProcessKey( HIMC himc, UINT vkey, LPARAM lparam, BYTE *state )
512 struct ime_driver_call_params params = {.himc = himc, .state = state};
513 INPUTCONTEXT *ctx;
514 LRESULT ret;
516 TRACE( "himc %p, vkey %#x, lparam %#Ix, state %p\n", himc, vkey, lparam, state );
518 if (!(ctx = ImmLockIMC( himc ))) return FALSE;
519 ret = NtUserMessageCall( ctx->hWnd, WINE_IME_PROCESS_KEY, vkey, lparam, &params,
520 NtUserImeDriverCall, FALSE );
521 ImmUnlockIMC( himc );
523 return ret;
526 UINT WINAPI ImeToAsciiEx( UINT vkey, UINT vsc, BYTE *state, TRANSMSGLIST *msgs, UINT flags, HIMC himc )
528 COMPOSITIONSTRING *compstr;
529 UINT size, count = 0;
530 INPUTCONTEXT *ctx;
531 NTSTATUS status;
533 TRACE( "vkey %#x, vsc %#x, state %p, msgs %p, flags %#x, himc %p\n",
534 vkey, vsc, state, msgs, flags, himc );
536 if (!(ctx = ImmLockIMC( himc ))) return 0;
537 if (!(compstr = ImmLockIMCC( ctx->hCompStr ))) goto done;
538 size = max( compstr->dwSize, sizeof(COMPOSITIONSTRING) );
542 struct ime_driver_call_params params = {.himc = himc, .state = state};
543 HIMCC himcc;
545 ImmUnlockIMCC( ctx->hCompStr );
546 if (!(himcc = ImmReSizeIMCC( ctx->hCompStr, size ))) goto done;
547 if (!(compstr = ImmLockIMCC( (ctx->hCompStr = himcc) ))) goto done;
549 params.compstr = compstr;
550 status = NtUserMessageCall( ctx->hWnd, WINE_IME_TO_ASCII_EX, vkey, vsc, &params,
551 NtUserImeDriverCall, FALSE );
552 size = compstr->dwSize;
553 } while (status == STATUS_BUFFER_TOO_SMALL);
555 if (status) WARN( "WINE_IME_TO_ASCII_EX returned status %#lx\n", status );
556 else
558 TRANSMSG status_msg = {.message = ime_set_composition_status( himc, !!compstr->dwCompStrOffset )};
559 if (status_msg.message) msgs->TransMsg[count++] = status_msg;
561 if (compstr->dwResultStrOffset)
563 const WCHAR *result = (WCHAR *)((BYTE *)compstr + compstr->dwResultStrOffset);
564 TRANSMSG msg = {.message = WM_IME_COMPOSITION, .wParam = result[0], .lParam = GCS_RESULTSTR};
565 if (compstr->dwResultClauseOffset) msg.lParam |= GCS_RESULTCLAUSE;
566 msgs->TransMsg[count++] = msg;
569 if (compstr->dwCompStrOffset)
571 const WCHAR *comp = (WCHAR *)((BYTE *)compstr + compstr->dwCompStrOffset);
572 TRANSMSG msg = {.message = WM_IME_COMPOSITION, .wParam = comp[0], .lParam = GCS_COMPSTR | GCS_CURSORPOS | GCS_DELTASTART};
573 if (compstr->dwCompAttrOffset) msg.lParam |= GCS_COMPATTR;
574 if (compstr->dwCompClauseOffset) msg.lParam |= GCS_COMPCLAUSE;
575 else msg.lParam |= CS_INSERTCHAR|CS_NOMOVECARET;
576 msgs->TransMsg[count++] = msg;
580 ImmUnlockIMCC( ctx->hCompStr );
582 done:
583 if (count >= msgs->uMsgCount) FIXME( "More than %u messages queued, messages possibly lost\n", msgs->uMsgCount );
584 else TRACE( "Returning %u messages queued\n", count );
585 ImmUnlockIMC( himc );
586 return count;
589 BOOL WINAPI ImeConfigure( HKL hkl, HWND hwnd, DWORD mode, void *data )
591 FIXME( "hkl %p, hwnd %p, mode %lu, data %p stub!\n", hkl, hwnd, mode, data );
592 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
593 return FALSE;
596 DWORD WINAPI ImeConversionList( HIMC himc, const WCHAR *source, CANDIDATELIST *dest, DWORD dest_len, UINT flag )
598 FIXME( "himc %p, source %s, dest %p, dest_len %lu, flag %#x stub!\n",
599 himc, debugstr_w(source), dest, dest_len, flag );
600 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
601 return 0;
604 BOOL WINAPI ImeSetCompositionString( HIMC himc, DWORD index, const void *comp, DWORD comp_len,
605 const void *read, DWORD read_len )
607 INPUTCONTEXT *ctx;
609 FIXME( "himc %p, index %lu, comp %p, comp_len %lu, read %p, read_len %lu semi-stub!\n",
610 himc, index, comp, comp_len, read, read_len );
611 if (read && read_len) FIXME( "Read string unimplemented\n" );
612 if (index != SCS_SETSTR && index != SCS_CHANGECLAUSE && index != SCS_CHANGEATTR) return FALSE;
614 if (!(ctx = ImmLockIMC( himc ))) return FALSE;
616 if (index != SCS_SETSTR)
617 FIXME( "index %#lx not implemented\n", index );
618 else
620 UINT msg, flags = GCS_COMPSTR | GCS_COMPCLAUSE | GCS_COMPATTR | GCS_DELTASTART | GCS_CURSORPOS;
621 WCHAR wparam = comp && comp_len >= sizeof(WCHAR) ? *(WCHAR *)comp : 0;
622 input_context_set_comp_str( ctx, comp, comp_len / sizeof(WCHAR) );
623 if ((msg = ime_set_composition_status( himc, TRUE ))) ime_send_message( himc, msg, 0, 0 );
624 ime_send_message( himc, WM_IME_COMPOSITION, wparam, flags );
627 ImmUnlockIMC( himc );
629 return TRUE;
632 BOOL WINAPI NotifyIME( HIMC himc, DWORD action, DWORD index, DWORD value )
634 struct ime_private *priv;
635 INPUTCONTEXT *ctx;
636 UINT msg;
638 TRACE( "himc %p, action %#lx, index %#lx, value %#lx stub!\n", himc, action, index, value );
640 if (!(ctx = ImmLockIMC( himc ))) return FALSE;
642 switch (action)
644 case NI_CONTEXTUPDATED:
645 switch (value)
647 case IMC_SETCOMPOSITIONFONT:
648 if ((priv = ImmLockIMCC( ctx->hPrivate )))
650 if (priv->hfont) DeleteObject( priv->hfont );
651 priv->hfont = CreateFontIndirectW( &ctx->lfFont.W );
652 ImmUnlockIMCC( ctx->hPrivate );
654 break;
655 case IMC_SETOPENSTATUS:
656 if (!ctx->fOpen)
658 input_context_set_comp_str( ctx, NULL, 0 );
659 if ((msg = ime_set_composition_status( himc, FALSE ))) ime_send_message( himc, msg, 0, 0 );
661 NtUserNotifyIMEStatus( ctx->hWnd, ctx->fOpen );
662 break;
664 break;
666 case NI_COMPOSITIONSTR:
667 switch (index)
669 case CPS_COMPLETE:
671 COMPOSITIONSTRING *compstr;
673 if (!(compstr = ImmLockIMCC( ctx->hCompStr )))
674 WARN( "Failed to lock input context composition string\n" );
675 else
677 WCHAR wchr = *(WCHAR *)((BYTE *)compstr + compstr->dwCompStrOffset);
678 COMPOSITIONSTRING tmp = *compstr;
679 UINT flags = 0;
681 memset( compstr, 0, sizeof(*compstr) );
682 compstr->dwSize = tmp.dwSize;
683 compstr->dwResultStrLen = tmp.dwCompStrLen;
684 compstr->dwResultStrOffset = tmp.dwCompStrOffset;
685 compstr->dwResultClauseLen = tmp.dwCompClauseLen;
686 compstr->dwResultClauseOffset = tmp.dwCompClauseOffset;
687 ImmUnlockIMCC( ctx->hCompStr );
689 if (tmp.dwCompStrLen) flags |= GCS_RESULTSTR;
690 if (tmp.dwCompClauseLen) flags |= GCS_RESULTCLAUSE;
691 if (flags) ime_send_message( himc, WM_IME_COMPOSITION, wchr, flags );
694 ImmSetOpenStatus( himc, FALSE );
695 break;
697 case CPS_CANCEL:
698 input_context_set_comp_str( ctx, NULL, 0 );
699 ImmSetOpenStatus( himc, FALSE );
700 break;
701 default:
702 FIXME( "himc %p, action %#lx, index %#lx, value %#lx stub!\n", himc, action, index, value );
703 break;
705 break;
707 default:
708 FIXME( "himc %p, action %#lx, index %#lx, value %#lx stub!\n", himc, action, index, value );
709 break;
712 ImmUnlockIMC( himc );
713 return TRUE;
716 LRESULT WINAPI ImeEscape( HIMC himc, UINT escape, void *data )
718 FIXME( "himc %p, escape %#x, data %p stub!\n", himc, escape, data );
719 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
720 return 0;
723 DWORD WINAPI ImeGetImeMenuItems( HIMC himc, DWORD flags, DWORD type, IMEMENUITEMINFOW *parent,
724 IMEMENUITEMINFOW *menu, DWORD size )
726 FIXME( "himc %p, flags %#lx, type %lu, parent %p, menu %p, size %#lx stub!\n",
727 himc, flags, type, parent, menu, size );
728 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
729 return 0;
732 BOOL WINAPI ImeRegisterWord( const WCHAR *reading, DWORD style, const WCHAR *string )
734 FIXME( "reading %s, style %lu, string %s stub!\n", debugstr_w(reading), style, debugstr_w(string) );
735 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
736 return FALSE;
739 UINT WINAPI ImeGetRegisterWordStyle( UINT item, STYLEBUFW *style )
741 FIXME( "item %u, style %p stub!\n", item, style );
742 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
743 return 0;
746 BOOL WINAPI ImeUnregisterWord( const WCHAR *reading, DWORD style, const WCHAR *string )
748 FIXME( "reading %s, style %lu, string %s stub!\n", debugstr_w(reading), style, debugstr_w(string) );
749 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
750 return FALSE;
753 UINT WINAPI ImeEnumRegisterWord( REGISTERWORDENUMPROCW proc, const WCHAR *reading, DWORD style,
754 const WCHAR *string, void *data )
756 FIXME( "proc %p, reading %s, style %lu, string %s, data %p stub!\n",
757 proc, debugstr_w(reading), style, debugstr_w(string), data );
758 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
759 return 0;