widl: Generate helper macros for WinRT implementation.
[wine/zf.git] / dlls / winex11.drv / ime.c
blobdfeed2cb1e6436781df2362a4160884b698738c8
1 /*
2 * The IME for interfacing with XIM
4 * Copyright 2008 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Notes:
23 * The normal flow for IMM/IME Processing is as follows.
24 * 1) The Keyboard Driver generates key messages which are first passed to
25 * the IMM and then to IME via ImeProcessKey. If the IME returns 0 then
26 * it does not want the key and the keyboard driver then generates the
27 * WM_KEYUP/WM_KEYDOWN messages. However if the IME is going to process the
28 * key it returns non-zero.
29 * 2) If the IME is going to process the key then the IMM calls ImeToAsciiEx to
30 * process the key. the IME modifies the HIMC structure to reflect the
31 * current state and generates any messages it needs the IMM to process.
32 * 3) IMM checks the messages and send them to the application in question. From
33 * here the IMM level deals with if the application is IME aware or not.
35 * This flow does not work well for the X11 driver and XIM.
36 * (It works fine for Mac)
37 * As such we will have to reroute step 1. Instead the x11drv driver will
38 * generate an XIM events and call directly into this IME implementation.
39 * As such we will have to use the alternative ImmGenerateMessage path to be
40 * generate the messages that we want the IMM layer to send to the application.
43 #include "config.h"
45 #include <stdarg.h>
46 #include "windef.h"
47 #include "winbase.h"
48 #include "wingdi.h"
49 #include "winuser.h"
50 #include "winerror.h"
51 #include "wine/debug.h"
52 #include "imm.h"
53 #include "ddk/imm.h"
54 #include "winnls.h"
55 #include "x11drv.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(imm);
59 #define FROM_X11 ((HIMC)0xcafe1337)
61 typedef struct _IMEPRIVATE {
62 BOOL bInComposition;
63 BOOL bInternalState;
64 HFONT textfont;
65 HWND hwndDefault;
66 } IMEPRIVATE, *LPIMEPRIVATE;
68 typedef struct _tagTRANSMSG {
69 UINT message;
70 WPARAM wParam;
71 LPARAM lParam;
72 } TRANSMSG, *LPTRANSMSG;
74 static const WCHAR UI_CLASS_NAME[] = {'W','i','n','e','X','1','1','I','M','E',0};
76 static HIMC *hSelectedFrom = NULL;
77 static INT hSelectedCount = 0;
79 /* MSIME messages */
80 static UINT WM_MSIME_SERVICE;
81 static UINT WM_MSIME_RECONVERTOPTIONS;
82 static UINT WM_MSIME_MOUSE;
83 static UINT WM_MSIME_RECONVERTREQUEST;
84 static UINT WM_MSIME_RECONVERT;
85 static UINT WM_MSIME_QUERYPOSITION;
86 static UINT WM_MSIME_DOCUMENTFEED;
88 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
89 LPARAM lParam);
91 static HIMC RealIMC(HIMC hIMC)
93 if (hIMC == FROM_X11)
95 INT i;
96 HWND wnd = GetFocus();
97 HIMC winHimc = ImmGetContext(wnd);
98 for (i = 0; i < hSelectedCount; i++)
99 if (winHimc == hSelectedFrom[i])
100 return winHimc;
101 return NULL;
103 else
104 return hIMC;
107 static LPINPUTCONTEXT LockRealIMC(HIMC hIMC)
109 HIMC real_imc = RealIMC(hIMC);
110 if (real_imc)
111 return ImmLockIMC(real_imc);
112 else
113 return NULL;
116 static BOOL UnlockRealIMC(HIMC hIMC)
118 HIMC real_imc = RealIMC(hIMC);
119 if (real_imc)
120 return ImmUnlockIMC(real_imc);
121 else
122 return FALSE;
125 static BOOL WINAPI register_classes( INIT_ONCE *once, void *param, void **context )
127 WNDCLASSW wndClass;
129 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
130 wndClass.style = CS_GLOBALCLASS | CS_IME | CS_HREDRAW | CS_VREDRAW;
131 wndClass.lpfnWndProc = IME_WindowProc;
132 wndClass.cbClsExtra = 0;
133 wndClass.cbWndExtra = 2 * sizeof(LONG_PTR);
134 wndClass.hInstance = x11drv_module;
135 wndClass.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
136 wndClass.hIcon = LoadIconW(NULL, (LPWSTR)IDI_APPLICATION);
137 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
138 wndClass.lpszMenuName = 0;
139 wndClass.lpszClassName = UI_CLASS_NAME;
141 RegisterClassW(&wndClass);
143 WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
144 WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
145 WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
146 WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
147 WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
148 WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
149 WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
150 return TRUE;
153 static HIMCC ImeCreateBlankCompStr(void)
155 HIMCC rc;
156 LPCOMPOSITIONSTRING ptr;
157 rc = ImmCreateIMCC(sizeof(COMPOSITIONSTRING));
158 ptr = ImmLockIMCC(rc);
159 memset(ptr,0,sizeof(COMPOSITIONSTRING));
160 ptr->dwSize = sizeof(COMPOSITIONSTRING);
161 ImmUnlockIMCC(rc);
162 return rc;
165 static int updateField(DWORD origLen, DWORD origOffset, DWORD currentOffset,
166 LPBYTE target, LPBYTE source, DWORD* lenParam,
167 DWORD* offsetParam, BOOL wchars )
169 if (origLen > 0 && origOffset > 0)
171 int truelen = origLen;
172 if (wchars)
173 truelen *= sizeof(WCHAR);
175 memcpy(&target[currentOffset], &source[origOffset], truelen);
177 *lenParam = origLen;
178 *offsetParam = currentOffset;
179 currentOffset += truelen;
181 return currentOffset;
184 static HIMCC updateCompStr(HIMCC old, LPCWSTR compstr, DWORD len)
186 /* We need to make sure the CompStr, CompClause and CompAttr fields are all
187 * set and correct. */
188 int needed_size;
189 HIMCC rc;
190 LPBYTE newdata = NULL;
191 LPBYTE olddata = NULL;
192 LPCOMPOSITIONSTRING new_one;
193 LPCOMPOSITIONSTRING lpcs = NULL;
194 INT current_offset = 0;
196 TRACE("%s, %i\n",debugstr_wn(compstr,len),len);
198 if (old == NULL && compstr == NULL && len == 0)
199 return NULL;
201 if (compstr == NULL && len != 0)
203 ERR("compstr is NULL however we have a len! Please report\n");
204 len = 0;
207 if (old != NULL)
209 olddata = ImmLockIMCC(old);
210 lpcs = (LPCOMPOSITIONSTRING)olddata;
213 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
214 len + sizeof(DWORD) * 2;
216 if (lpcs != NULL)
218 needed_size += lpcs->dwCompReadAttrLen;
219 needed_size += lpcs->dwCompReadClauseLen;
220 needed_size += lpcs->dwCompReadStrLen * sizeof(WCHAR);
221 needed_size += lpcs->dwResultReadClauseLen;
222 needed_size += lpcs->dwResultReadStrLen * sizeof(WCHAR);
223 needed_size += lpcs->dwResultClauseLen;
224 needed_size += lpcs->dwResultStrLen * sizeof(WCHAR);
225 needed_size += lpcs->dwPrivateSize;
227 rc = ImmCreateIMCC(needed_size);
228 newdata = ImmLockIMCC(rc);
229 new_one = (LPCOMPOSITIONSTRING)newdata;
231 new_one->dwSize = needed_size;
232 current_offset = sizeof(COMPOSITIONSTRING);
233 if (lpcs != NULL)
235 current_offset = updateField(lpcs->dwCompReadAttrLen,
236 lpcs->dwCompReadAttrOffset,
237 current_offset, newdata, olddata,
238 &new_one->dwCompReadAttrLen,
239 &new_one->dwCompReadAttrOffset, FALSE);
241 current_offset = updateField(lpcs->dwCompReadClauseLen,
242 lpcs->dwCompReadClauseOffset,
243 current_offset, newdata, olddata,
244 &new_one->dwCompReadClauseLen,
245 &new_one->dwCompReadClauseOffset, FALSE);
247 current_offset = updateField(lpcs->dwCompReadStrLen,
248 lpcs->dwCompReadStrOffset,
249 current_offset, newdata, olddata,
250 &new_one->dwCompReadStrLen,
251 &new_one->dwCompReadStrOffset, TRUE);
253 /* new CompAttr, CompClause, CompStr, dwCursorPos */
254 new_one->dwDeltaStart = 0;
256 current_offset = updateField(lpcs->dwResultReadClauseLen,
257 lpcs->dwResultReadClauseOffset,
258 current_offset, newdata, olddata,
259 &new_one->dwResultReadClauseLen,
260 &new_one->dwResultReadClauseOffset, FALSE);
262 current_offset = updateField(lpcs->dwResultReadStrLen,
263 lpcs->dwResultReadStrOffset,
264 current_offset, newdata, olddata,
265 &new_one->dwResultReadStrLen,
266 &new_one->dwResultReadStrOffset, TRUE);
268 current_offset = updateField(lpcs->dwResultClauseLen,
269 lpcs->dwResultClauseOffset,
270 current_offset, newdata, olddata,
271 &new_one->dwResultClauseLen,
272 &new_one->dwResultClauseOffset, FALSE);
274 current_offset = updateField(lpcs->dwResultStrLen,
275 lpcs->dwResultStrOffset,
276 current_offset, newdata, olddata,
277 &new_one->dwResultStrLen,
278 &new_one->dwResultStrOffset, TRUE);
280 current_offset = updateField(lpcs->dwPrivateSize,
281 lpcs->dwPrivateOffset,
282 current_offset, newdata, olddata,
283 &new_one->dwPrivateSize,
284 &new_one->dwPrivateOffset, FALSE);
287 /* set new data */
288 /* CompAttr */
289 new_one->dwCompAttrLen = len;
290 if (len > 0)
292 new_one->dwCompAttrOffset = current_offset;
293 memset(&newdata[current_offset],ATTR_INPUT,len);
294 current_offset += len;
297 /* CompClause */
298 if (len > 0)
300 new_one->dwCompClauseLen = sizeof(DWORD) * 2;
301 new_one->dwCompClauseOffset = current_offset;
302 *(DWORD*)(&newdata[current_offset]) = 0;
303 current_offset += sizeof(DWORD);
304 *(DWORD*)(&newdata[current_offset]) = len;
305 current_offset += sizeof(DWORD);
307 else
308 new_one->dwCompClauseLen = 0;
310 /* CompStr */
311 new_one->dwCompStrLen = len;
312 if (len > 0)
314 new_one->dwCompStrOffset = current_offset;
315 memcpy(&newdata[current_offset],compstr,len*sizeof(WCHAR));
318 /* CursorPos */
319 new_one->dwCursorPos = len;
321 ImmUnlockIMCC(rc);
322 if (lpcs)
323 ImmUnlockIMCC(old);
325 return rc;
328 static HIMCC updateResultStr(HIMCC old, LPWSTR resultstr, DWORD len)
330 /* we need to make sure the ResultStr and ResultClause fields are all
331 * set and correct */
332 int needed_size;
333 HIMCC rc;
334 LPBYTE newdata = NULL;
335 LPBYTE olddata = NULL;
336 LPCOMPOSITIONSTRING new_one;
337 LPCOMPOSITIONSTRING lpcs = NULL;
338 INT current_offset = 0;
340 TRACE("%s, %i\n",debugstr_wn(resultstr,len),len);
342 if (old == NULL && resultstr == NULL && len == 0)
343 return NULL;
345 if (resultstr == NULL && len != 0)
347 ERR("resultstr is NULL however we have a len! Please report\n");
348 len = 0;
351 if (old != NULL)
353 olddata = ImmLockIMCC(old);
354 lpcs = (LPCOMPOSITIONSTRING)olddata;
357 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
358 sizeof(DWORD) * 2;
360 if (lpcs != NULL)
362 needed_size += lpcs->dwCompReadAttrLen;
363 needed_size += lpcs->dwCompReadClauseLen;
364 needed_size += lpcs->dwCompReadStrLen * sizeof(WCHAR);
365 needed_size += lpcs->dwCompAttrLen;
366 needed_size += lpcs->dwCompClauseLen;
367 needed_size += lpcs->dwCompStrLen * sizeof(WCHAR);
368 needed_size += lpcs->dwResultReadClauseLen;
369 needed_size += lpcs->dwResultReadStrLen * sizeof(WCHAR);
370 needed_size += lpcs->dwPrivateSize;
372 rc = ImmCreateIMCC(needed_size);
373 newdata = ImmLockIMCC(rc);
374 new_one = (LPCOMPOSITIONSTRING)newdata;
376 new_one->dwSize = needed_size;
377 current_offset = sizeof(COMPOSITIONSTRING);
378 if (lpcs != NULL)
380 current_offset = updateField(lpcs->dwCompReadAttrLen,
381 lpcs->dwCompReadAttrOffset,
382 current_offset, newdata, olddata,
383 &new_one->dwCompReadAttrLen,
384 &new_one->dwCompReadAttrOffset, FALSE);
386 current_offset = updateField(lpcs->dwCompReadClauseLen,
387 lpcs->dwCompReadClauseOffset,
388 current_offset, newdata, olddata,
389 &new_one->dwCompReadClauseLen,
390 &new_one->dwCompReadClauseOffset, FALSE);
392 current_offset = updateField(lpcs->dwCompReadStrLen,
393 lpcs->dwCompReadStrOffset,
394 current_offset, newdata, olddata,
395 &new_one->dwCompReadStrLen,
396 &new_one->dwCompReadStrOffset, TRUE);
398 current_offset = updateField(lpcs->dwCompAttrLen,
399 lpcs->dwCompAttrOffset,
400 current_offset, newdata, olddata,
401 &new_one->dwCompAttrLen,
402 &new_one->dwCompAttrOffset, FALSE);
404 current_offset = updateField(lpcs->dwCompClauseLen,
405 lpcs->dwCompClauseOffset,
406 current_offset, newdata, olddata,
407 &new_one->dwCompClauseLen,
408 &new_one->dwCompClauseOffset, FALSE);
410 current_offset = updateField(lpcs->dwCompStrLen,
411 lpcs->dwCompStrOffset,
412 current_offset, newdata, olddata,
413 &new_one->dwCompStrLen,
414 &new_one->dwCompStrOffset, TRUE);
416 new_one->dwCursorPos = lpcs->dwCursorPos;
417 new_one->dwDeltaStart = 0;
419 current_offset = updateField(lpcs->dwResultReadClauseLen,
420 lpcs->dwResultReadClauseOffset,
421 current_offset, newdata, olddata,
422 &new_one->dwResultReadClauseLen,
423 &new_one->dwResultReadClauseOffset, FALSE);
425 current_offset = updateField(lpcs->dwResultReadStrLen,
426 lpcs->dwResultReadStrOffset,
427 current_offset, newdata, olddata,
428 &new_one->dwResultReadStrLen,
429 &new_one->dwResultReadStrOffset, TRUE);
431 /* new ResultClause , ResultStr */
433 current_offset = updateField(lpcs->dwPrivateSize,
434 lpcs->dwPrivateOffset,
435 current_offset, newdata, olddata,
436 &new_one->dwPrivateSize,
437 &new_one->dwPrivateOffset, FALSE);
440 /* set new data */
441 /* ResultClause */
442 if (len > 0)
444 new_one->dwResultClauseLen = sizeof(DWORD) * 2;
445 new_one->dwResultClauseOffset = current_offset;
446 *(DWORD*)(&newdata[current_offset]) = 0;
447 current_offset += sizeof(DWORD);
448 *(DWORD*)(&newdata[current_offset]) = len;
449 current_offset += sizeof(DWORD);
451 else
452 new_one->dwResultClauseLen = 0;
454 /* ResultStr */
455 new_one->dwResultStrLen = len;
456 if (len > 0)
458 new_one->dwResultStrOffset = current_offset;
459 memcpy(&newdata[current_offset],resultstr,len*sizeof(WCHAR));
461 ImmUnlockIMCC(rc);
462 if (lpcs)
463 ImmUnlockIMCC(old);
465 return rc;
468 static void GenerateIMEMessage(HIMC hIMC, UINT msg, WPARAM wParam,
469 LPARAM lParam)
471 LPINPUTCONTEXT lpIMC;
472 LPTRANSMSG lpTransMsg;
474 lpIMC = LockRealIMC(hIMC);
475 if (lpIMC == NULL)
476 return;
478 lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf, (lpIMC->dwNumMsgBuf + 1) *
479 sizeof(TRANSMSG));
480 if (!lpIMC->hMsgBuf)
481 return;
483 lpTransMsg = ImmLockIMCC(lpIMC->hMsgBuf);
484 if (!lpTransMsg)
485 return;
487 lpTransMsg += lpIMC->dwNumMsgBuf;
488 lpTransMsg->message = msg;
489 lpTransMsg->wParam = wParam;
490 lpTransMsg->lParam = lParam;
492 ImmUnlockIMCC(lpIMC->hMsgBuf);
493 lpIMC->dwNumMsgBuf++;
495 ImmGenerateMessage(RealIMC(hIMC));
496 UnlockRealIMC(hIMC);
499 static BOOL IME_RemoveFromSelected(HIMC hIMC)
501 int i;
502 for (i = 0; i < hSelectedCount; i++)
503 if (hSelectedFrom[i] == hIMC)
505 if (i < hSelectedCount - 1)
506 memmove(&hSelectedFrom[i], &hSelectedFrom[i+1], (hSelectedCount - i - 1)*sizeof(HIMC));
507 hSelectedCount --;
508 return TRUE;
510 return FALSE;
513 static void IME_AddToSelected(HIMC hIMC)
515 hSelectedCount++;
516 if (hSelectedFrom)
517 hSelectedFrom = HeapReAlloc(GetProcessHeap(), 0, hSelectedFrom, hSelectedCount*sizeof(HIMC));
518 else
519 hSelectedFrom = HeapAlloc(GetProcessHeap(), 0, sizeof(HIMC));
520 hSelectedFrom[hSelectedCount-1] = hIMC;
523 BOOL WINAPI ImeInquire(LPIMEINFO lpIMEInfo, LPWSTR lpszUIClass,
524 LPCWSTR lpszOption)
526 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
528 TRACE("\n");
529 InitOnceExecuteOnce( &init_once, register_classes, NULL, NULL );
530 lpIMEInfo->dwPrivateDataSize = sizeof (IMEPRIVATE);
531 lpIMEInfo->fdwProperty = IME_PROP_UNICODE | IME_PROP_AT_CARET;
532 lpIMEInfo->fdwConversionCaps = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
533 lpIMEInfo->fdwSentenceCaps = IME_SMODE_AUTOMATIC;
534 lpIMEInfo->fdwUICaps = UI_CAP_2700;
535 /* Tell App we cannot accept ImeSetCompositionString calls */
536 lpIMEInfo->fdwSCSCaps = 0;
537 lpIMEInfo->fdwSelectCaps = SELECT_CAP_CONVERSION;
539 lstrcpyW(lpszUIClass,UI_CLASS_NAME);
541 return TRUE;
544 BOOL WINAPI ImeConfigure(HKL hKL,HWND hWnd, DWORD dwMode, LPVOID lpData)
546 FIXME("(%p, %p, %d, %p): stub\n", hKL, hWnd, dwMode, lpData);
547 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
548 return FALSE;
551 DWORD WINAPI ImeConversionList(HIMC hIMC, LPCWSTR lpSource,
552 LPCANDIDATELIST lpCandList, DWORD dwBufLen, UINT uFlag)
555 FIXME("(%p, %s, %p, %d, %d): stub\n", hIMC, debugstr_w(lpSource),
556 lpCandList, dwBufLen, uFlag);
557 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
558 return 0;
561 BOOL WINAPI ImeDestroy(UINT uForce)
563 TRACE("\n");
564 HeapFree(GetProcessHeap(),0,hSelectedFrom);
565 hSelectedFrom = NULL;
566 hSelectedCount = 0;
567 return TRUE;
570 LRESULT WINAPI ImeEscape(HIMC hIMC, UINT uSubFunc, LPVOID lpData)
572 FIXME("(%p, %d, %p): stub\n", hIMC, uSubFunc, lpData);
573 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
574 return 0;
577 BOOL WINAPI ImeProcessKey(HIMC hIMC, UINT vKey, LPARAM lKeyData, const LPBYTE lpbKeyState)
579 /* See the comment at the head of this file */
580 TRACE("We do no processing via this route\n");
581 return FALSE;
584 BOOL WINAPI ImeSelect(HIMC hIMC, BOOL fSelect)
586 LPINPUTCONTEXT lpIMC;
587 TRACE("%p %s\n",hIMC,(fSelect)?"TRUE":"FALSE");
589 if (hIMC == FROM_X11)
591 ERR("ImeSelect should never be called from X11\n");
592 return FALSE;
595 if (!hIMC)
596 return TRUE;
598 /* not selected */
599 if (!fSelect)
600 return IME_RemoveFromSelected(hIMC);
602 IME_AddToSelected(hIMC);
604 /* Initialize our structures */
605 lpIMC = LockRealIMC(hIMC);
606 if (lpIMC != NULL)
608 LPIMEPRIVATE myPrivate;
609 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
610 myPrivate->bInComposition = FALSE;
611 myPrivate->bInternalState = FALSE;
612 myPrivate->textfont = NULL;
613 myPrivate->hwndDefault = NULL;
614 ImmUnlockIMCC(lpIMC->hPrivate);
615 UnlockRealIMC(hIMC);
618 return TRUE;
621 BOOL WINAPI ImeSetActiveContext(HIMC hIMC,BOOL fFlag)
623 FIXME("(%p, %x): stub\n", hIMC, fFlag);
624 return TRUE;
627 UINT WINAPI ImeToAsciiEx (UINT uVKey, UINT uScanCode, const LPBYTE lpbKeyState,
628 LPDWORD lpdwTransKey, UINT fuState, HIMC hIMC)
630 /* See the comment at the head of this file */
631 TRACE("We do no processing via this route\n");
632 return 0;
635 BOOL WINAPI NotifyIME(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
637 BOOL bRet = FALSE;
638 LPINPUTCONTEXT lpIMC;
640 TRACE("%p %i %i %i\n",hIMC,dwAction,dwIndex,dwValue);
642 lpIMC = LockRealIMC(hIMC);
643 if (lpIMC == NULL)
644 return FALSE;
646 switch (dwAction)
648 case NI_OPENCANDIDATE: FIXME("NI_OPENCANDIDATE\n"); break;
649 case NI_CLOSECANDIDATE: FIXME("NI_CLOSECANDIDATE\n"); break;
650 case NI_SELECTCANDIDATESTR: FIXME("NI_SELECTCANDIDATESTR\n"); break;
651 case NI_CHANGECANDIDATELIST: FIXME("NI_CHANGECANDIDATELIST\n"); break;
652 case NI_SETCANDIDATE_PAGESTART: FIXME("NI_SETCANDIDATE_PAGESTART\n"); break;
653 case NI_SETCANDIDATE_PAGESIZE: FIXME("NI_SETCANDIDATE_PAGESIZE\n"); break;
654 case NI_CONTEXTUPDATED:
655 switch (dwValue)
657 case IMC_SETCOMPOSITIONWINDOW: FIXME("IMC_SETCOMPOSITIONWINDOW\n"); break;
658 case IMC_SETCONVERSIONMODE: FIXME("IMC_SETCONVERSIONMODE\n"); break;
659 case IMC_SETSENTENCEMODE: FIXME("IMC_SETSENTENCEMODE\n"); break;
660 case IMC_SETCANDIDATEPOS: FIXME("IMC_SETCANDIDATEPOS\n"); break;
661 case IMC_SETCOMPOSITIONFONT:
663 LPIMEPRIVATE myPrivate;
664 TRACE("IMC_SETCOMPOSITIONFONT\n");
666 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
667 if (myPrivate->textfont)
669 DeleteObject(myPrivate->textfont);
670 myPrivate->textfont = NULL;
672 myPrivate->textfont = CreateFontIndirectW(&lpIMC->lfFont.W);
673 ImmUnlockIMCC(lpIMC->hPrivate);
675 break;
676 case IMC_SETOPENSTATUS:
677 TRACE("IMC_SETOPENSTATUS\n");
679 bRet = TRUE;
680 X11DRV_SetPreeditState(lpIMC->hWnd, lpIMC->fOpen);
681 if (!lpIMC->fOpen)
683 LPIMEPRIVATE myPrivate;
685 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
686 if (myPrivate->bInComposition)
688 X11DRV_ForceXIMReset(lpIMC->hWnd);
689 GenerateIMEMessage(hIMC, WM_IME_ENDCOMPOSITION, 0, 0);
690 myPrivate->bInComposition = FALSE;
692 ImmUnlockIMCC(lpIMC->hPrivate);
695 break;
696 default: FIXME("Unknown\n"); break;
698 break;
699 case NI_COMPOSITIONSTR:
700 switch (dwIndex)
702 case CPS_COMPLETE:
704 HIMCC newCompStr;
705 DWORD cplen = 0;
706 LPWSTR cpstr;
707 LPCOMPOSITIONSTRING cs = NULL;
708 LPBYTE cdata = NULL;
709 LPIMEPRIVATE myPrivate;
711 TRACE("CPS_COMPLETE\n");
713 /* clear existing result */
714 newCompStr = updateResultStr(lpIMC->hCompStr, NULL, 0);
716 ImmDestroyIMCC(lpIMC->hCompStr);
717 lpIMC->hCompStr = newCompStr;
719 if (lpIMC->hCompStr)
721 cdata = ImmLockIMCC(lpIMC->hCompStr);
722 cs = (LPCOMPOSITIONSTRING)cdata;
723 cplen = cs->dwCompStrLen;
724 cpstr = (LPWSTR)&(cdata[cs->dwCompStrOffset]);
725 ImmUnlockIMCC(lpIMC->hCompStr);
727 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
728 if (cplen > 0)
730 WCHAR param = cpstr[0];
732 newCompStr = updateResultStr(lpIMC->hCompStr, cpstr, cplen);
733 ImmDestroyIMCC(lpIMC->hCompStr);
734 lpIMC->hCompStr = newCompStr;
735 newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0);
736 ImmDestroyIMCC(lpIMC->hCompStr);
737 lpIMC->hCompStr = newCompStr;
739 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, 0,
740 GCS_COMPSTR);
742 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, param,
743 GCS_RESULTSTR|GCS_RESULTCLAUSE);
745 GenerateIMEMessage(hIMC,WM_IME_ENDCOMPOSITION, 0, 0);
747 else if (myPrivate->bInComposition)
748 GenerateIMEMessage(hIMC,WM_IME_ENDCOMPOSITION, 0, 0);
750 myPrivate->bInComposition = FALSE;
751 ImmUnlockIMCC(lpIMC->hPrivate);
753 bRet = TRUE;
755 break;
756 case CPS_CONVERT: FIXME("CPS_CONVERT\n"); break;
757 case CPS_REVERT: FIXME("CPS_REVERT\n"); break;
758 case CPS_CANCEL:
760 LPIMEPRIVATE myPrivate;
762 TRACE("CPS_CANCEL\n");
764 X11DRV_ForceXIMReset(lpIMC->hWnd);
766 if (lpIMC->hCompStr)
767 ImmDestroyIMCC(lpIMC->hCompStr);
768 lpIMC->hCompStr = ImeCreateBlankCompStr();
770 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
771 if (myPrivate->bInComposition)
773 GenerateIMEMessage(hIMC, WM_IME_ENDCOMPOSITION, 0, 0);
774 myPrivate->bInComposition = FALSE;
776 ImmUnlockIMCC(lpIMC->hPrivate);
777 bRet = TRUE;
779 break;
780 default: FIXME("Unknown\n"); break;
782 break;
783 default: FIXME("Unknown Message\n"); break;
786 UnlockRealIMC(hIMC);
787 return bRet;
790 BOOL WINAPI ImeRegisterWord(LPCWSTR lpszReading, DWORD dwStyle,
791 LPCWSTR lpszRegister)
793 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading), dwStyle,
794 debugstr_w(lpszRegister));
795 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
796 return FALSE;
799 BOOL WINAPI ImeUnregisterWord(LPCWSTR lpszReading, DWORD dwStyle,
800 LPCWSTR lpszUnregister)
802 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading), dwStyle,
803 debugstr_w(lpszUnregister));
804 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
805 return FALSE;
808 UINT WINAPI ImeGetRegisterWordStyle(UINT nItem, LPSTYLEBUFW lpStyleBuf)
810 FIXME("(%d, %p): stub\n", nItem, lpStyleBuf);
811 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
812 return 0;
815 UINT WINAPI ImeEnumRegisterWord(REGISTERWORDENUMPROCW lpfnEnumProc,
816 LPCWSTR lpszReading, DWORD dwStyle,
817 LPCWSTR lpszRegister, LPVOID lpData)
819 FIXME("(%p, %s, %d, %s, %p): stub\n", lpfnEnumProc,
820 debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister),
821 lpData);
822 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
823 return 0;
826 BOOL WINAPI ImeSetCompositionString(HIMC hIMC, DWORD dwIndex, LPCVOID lpComp,
827 DWORD dwCompLen, LPCVOID lpRead,
828 DWORD dwReadLen)
830 LPINPUTCONTEXT lpIMC;
831 DWORD flags = 0;
832 WCHAR wParam = 0;
833 LPIMEPRIVATE myPrivate;
835 TRACE("(%p, %d, %p, %d, %p, %d):\n",
836 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
839 if (hIMC != FROM_X11)
840 FIXME("PROBLEM: This only sets the wine level string\n");
843 * Explanation:
844 * this sets the composition string in the imm32.dll level
845 * of the composition buffer. we cannot manipulate the xim level
846 * buffer, which means that once the xim level buffer changes again
847 * any call to this function from the application will be lost
850 if (lpRead && dwReadLen)
851 FIXME("Reading string unimplemented\n");
853 lpIMC = LockRealIMC(hIMC);
855 if (lpIMC == NULL)
856 return FALSE;
858 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
860 if (dwIndex == SCS_SETSTR)
862 HIMCC newCompStr;
864 if (!myPrivate->bInComposition)
866 GenerateIMEMessage(hIMC, WM_IME_STARTCOMPOSITION, 0, 0);
867 myPrivate->bInComposition = TRUE;
870 /* clear existing result */
871 newCompStr = updateResultStr(lpIMC->hCompStr, NULL, 0);
872 ImmDestroyIMCC(lpIMC->hCompStr);
873 lpIMC->hCompStr = newCompStr;
875 flags = GCS_COMPSTR;
877 if (dwCompLen && lpComp)
879 newCompStr = updateCompStr(lpIMC->hCompStr, (LPCWSTR)lpComp, dwCompLen / sizeof(WCHAR));
880 ImmDestroyIMCC(lpIMC->hCompStr);
881 lpIMC->hCompStr = newCompStr;
883 wParam = ((const WCHAR*)lpComp)[0];
884 flags |= GCS_COMPCLAUSE | GCS_COMPATTR | GCS_DELTASTART;
886 else
888 newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0);
889 ImmDestroyIMCC(lpIMC->hCompStr);
890 lpIMC->hCompStr = newCompStr;
894 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, wParam, flags);
895 ImmUnlockIMCC(lpIMC->hPrivate);
896 UnlockRealIMC(hIMC);
898 return TRUE;
901 DWORD WINAPI ImeGetImeMenuItems(HIMC hIMC, DWORD dwFlags, DWORD dwType,
902 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
903 DWORD dwSize)
905 FIXME("(%p, %x %x %p %p %x): stub\n", hIMC, dwFlags, dwType,
906 lpImeParentMenu, lpImeMenu, dwSize);
907 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
908 return 0;
911 /* Interfaces to XIM and other parts of winex11drv */
913 void IME_SetOpenStatus(BOOL fOpen)
915 HIMC imc;
917 imc = RealIMC(FROM_X11);
918 ImmSetOpenStatus(imc, fOpen);
921 void IME_SetCompositionStatus(BOOL fOpen)
923 HIMC imc;
924 LPINPUTCONTEXT lpIMC;
925 LPIMEPRIVATE myPrivate;
927 imc = RealIMC(FROM_X11);
928 lpIMC = ImmLockIMC(imc);
929 if (lpIMC == NULL)
930 return;
932 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
934 if (fOpen && !myPrivate->bInComposition)
936 GenerateIMEMessage(imc, WM_IME_STARTCOMPOSITION, 0, 0);
938 else if (!fOpen && myPrivate->bInComposition)
940 ShowWindow(myPrivate->hwndDefault, SW_HIDE);
941 ImmDestroyIMCC(lpIMC->hCompStr);
942 lpIMC->hCompStr = ImeCreateBlankCompStr();
943 GenerateIMEMessage(imc, WM_IME_ENDCOMPOSITION, 0, 0);
945 myPrivate->bInComposition = fOpen;
947 ImmUnlockIMCC(lpIMC->hPrivate);
948 ImmUnlockIMC(imc);
951 INT IME_GetCursorPos(void)
953 LPINPUTCONTEXT lpIMC;
954 INT rc = 0;
955 LPCOMPOSITIONSTRING compstr;
957 if (!hSelectedFrom)
958 return rc;
960 lpIMC = LockRealIMC(FROM_X11);
961 if (lpIMC)
963 compstr = ImmLockIMCC(lpIMC->hCompStr);
964 rc = compstr->dwCursorPos;
965 ImmUnlockIMCC(lpIMC->hCompStr);
967 UnlockRealIMC(FROM_X11);
968 return rc;
971 void IME_SetCursorPos(DWORD pos)
973 LPINPUTCONTEXT lpIMC;
974 LPCOMPOSITIONSTRING compstr;
976 if (!hSelectedFrom)
977 return;
979 lpIMC = LockRealIMC(FROM_X11);
980 if (!lpIMC)
981 return;
983 compstr = ImmLockIMCC(lpIMC->hCompStr);
984 if (!compstr)
986 UnlockRealIMC(FROM_X11);
987 return;
990 compstr->dwCursorPos = pos;
991 ImmUnlockIMCC(lpIMC->hCompStr);
992 UnlockRealIMC(FROM_X11);
993 GenerateIMEMessage(FROM_X11, WM_IME_COMPOSITION, pos, GCS_CURSORPOS);
994 return;
997 void IME_UpdateAssociation(HWND focus)
999 ImmGetContext(focus);
1001 if (!focus || !hSelectedFrom)
1002 return;
1004 ImmAssociateContext(focus,RealIMC(FROM_X11));
1008 BOOL IME_SetCompositionString(DWORD dwIndex, LPCVOID lpComp, DWORD dwCompLen,
1009 LPCVOID lpRead, DWORD dwReadLen)
1011 return ImeSetCompositionString(FROM_X11, dwIndex, lpComp, dwCompLen,
1012 lpRead, dwReadLen);
1015 void IME_SetResultString(LPWSTR lpResult, DWORD dwResultLen)
1017 HIMC imc;
1018 LPINPUTCONTEXT lpIMC;
1019 HIMCC newCompStr;
1020 LPIMEPRIVATE myPrivate;
1021 BOOL inComp;
1023 imc = RealIMC(FROM_X11);
1024 lpIMC = ImmLockIMC(imc);
1025 if (lpIMC == NULL)
1026 return;
1028 newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0);
1029 ImmDestroyIMCC(lpIMC->hCompStr);
1030 lpIMC->hCompStr = newCompStr;
1032 newCompStr = updateResultStr(lpIMC->hCompStr, lpResult, dwResultLen);
1033 ImmDestroyIMCC(lpIMC->hCompStr);
1034 lpIMC->hCompStr = newCompStr;
1036 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1037 inComp = myPrivate->bInComposition;
1038 ImmUnlockIMCC(lpIMC->hPrivate);
1040 if (!inComp)
1042 ImmSetOpenStatus(imc, TRUE);
1043 GenerateIMEMessage(imc, WM_IME_STARTCOMPOSITION, 0, 0);
1046 GenerateIMEMessage(imc, WM_IME_COMPOSITION, 0, GCS_COMPSTR);
1047 GenerateIMEMessage(imc, WM_IME_COMPOSITION, lpResult[0], GCS_RESULTSTR|GCS_RESULTCLAUSE);
1048 GenerateIMEMessage(imc, WM_IME_ENDCOMPOSITION, 0, 0);
1050 if (!inComp)
1051 ImmSetOpenStatus(imc, FALSE);
1053 ImmUnlockIMC(imc);
1056 /*****
1057 * Internal functions to help with IME window management
1059 static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
1061 PAINTSTRUCT ps;
1062 RECT rect;
1063 HDC hdc;
1064 LPCOMPOSITIONSTRING compstr;
1065 LPBYTE compdata = NULL;
1066 HMONITOR monitor;
1067 MONITORINFO mon_info;
1068 INT offX=0, offY=0;
1069 LPINPUTCONTEXT lpIMC;
1071 lpIMC = LockRealIMC(hIMC);
1072 if (lpIMC == NULL)
1073 return;
1075 hdc = BeginPaint(hwnd,&ps);
1077 GetClientRect(hwnd,&rect);
1078 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
1080 compdata = ImmLockIMCC(lpIMC->hCompStr);
1081 compstr = (LPCOMPOSITIONSTRING)compdata;
1083 if (compstr->dwCompStrLen && compstr->dwCompStrOffset)
1085 SIZE size;
1086 POINT pt;
1087 HFONT oldfont = NULL;
1088 LPWSTR CompString;
1089 LPIMEPRIVATE myPrivate;
1091 CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
1092 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1094 if (myPrivate->textfont)
1095 oldfont = SelectObject(hdc,myPrivate->textfont);
1097 ImmUnlockIMCC(lpIMC->hPrivate);
1099 GetTextExtentPoint32W(hdc, CompString, compstr->dwCompStrLen, &size);
1100 pt.x = size.cx;
1101 pt.y = size.cy;
1102 LPtoDP(hdc,&pt,1);
1105 * How this works based on tests on windows:
1106 * CFS_POINT: then we start our window at the point and grow it as large
1107 * as it needs to be for the string.
1108 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
1109 * window is only as large as we need for the string, but we do not
1110 * grow such that our window exceeds the given rect. Wrapping if
1111 * needed and possible. If our ptCurrentPos is outside of our rect
1112 * then no window is displayed.
1113 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
1114 * maybe because the default MSIME does not do any IME adjusting.
1116 if (lpIMC->cfCompForm.dwStyle != CFS_DEFAULT)
1118 POINT cpt = lpIMC->cfCompForm.ptCurrentPos;
1119 ClientToScreen(lpIMC->hWnd,&cpt);
1120 rect.left = cpt.x;
1121 rect.top = cpt.y;
1122 rect.right = rect.left + pt.x;
1123 rect.bottom = rect.top + pt.y;
1124 monitor = MonitorFromPoint(cpt, MONITOR_DEFAULTTOPRIMARY);
1126 else /* CFS_DEFAULT */
1128 /* Windows places the default IME window in the bottom left */
1129 HWND target = lpIMC->hWnd;
1130 if (!target) target = GetFocus();
1132 GetWindowRect(target,&rect);
1133 rect.top = rect.bottom;
1134 rect.right = rect.left + pt.x + 20;
1135 rect.bottom = rect.top + pt.y + 20;
1136 offX=offY=10;
1137 monitor = MonitorFromWindow(target, MONITOR_DEFAULTTOPRIMARY);
1140 if (lpIMC->cfCompForm.dwStyle == CFS_RECT)
1142 RECT client;
1143 client =lpIMC->cfCompForm.rcArea;
1144 MapWindowPoints( lpIMC->hWnd, 0, (POINT *)&client, 2 );
1145 IntersectRect(&rect,&rect,&client);
1146 /* TODO: Wrap the input if needed */
1149 if (lpIMC->cfCompForm.dwStyle == CFS_DEFAULT)
1151 /* make sure we are on the desktop */
1152 mon_info.cbSize = sizeof(mon_info);
1153 GetMonitorInfoW(monitor, &mon_info);
1155 if (rect.bottom > mon_info.rcWork.bottom)
1157 int shift = rect.bottom - mon_info.rcWork.bottom;
1158 rect.top -= shift;
1159 rect.bottom -= shift;
1161 if (rect.left < 0)
1163 rect.right -= rect.left;
1164 rect.left = 0;
1166 if (rect.right > mon_info.rcWork.right)
1168 int shift = rect.right - mon_info.rcWork.right;
1169 rect.left -= shift;
1170 rect.right -= shift;
1174 SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
1176 TextOutW(hdc, offX,offY, CompString, compstr->dwCompStrLen);
1178 if (oldfont)
1179 SelectObject(hdc,oldfont);
1182 ImmUnlockIMCC(lpIMC->hCompStr);
1184 EndPaint(hwnd,&ps);
1185 UnlockRealIMC(hIMC);
1188 static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd)
1190 LPCOMPOSITIONSTRING compstr;
1191 LPINPUTCONTEXT lpIMC;
1193 lpIMC = LockRealIMC(hIMC);
1194 if (lpIMC == NULL)
1195 return;
1197 if (lpIMC->hCompStr)
1198 compstr = ImmLockIMCC(lpIMC->hCompStr);
1199 else
1200 compstr = NULL;
1202 if (compstr == NULL || compstr->dwCompStrLen == 0)
1203 ShowWindow(hwnd,SW_HIDE);
1204 else
1206 ShowWindow(hwnd,SW_SHOWNOACTIVATE);
1207 RedrawWindow(hwnd, NULL, NULL, RDW_ERASENOW | RDW_INVALIDATE);
1210 if (compstr != NULL)
1211 ImmUnlockIMCC(lpIMC->hCompStr);
1213 lpIMC->hWnd = GetFocus();
1214 UnlockRealIMC(hIMC);
1217 static void DefaultIMEComposition(HIMC hIMC, HWND hwnd, LPARAM lParam)
1219 TRACE("IME message WM_IME_COMPOSITION 0x%lx\n", lParam);
1220 if (!(lParam & GCS_RESULTSTR))
1221 UpdateDefaultIMEWindow(hIMC, hwnd);
1224 static void DefaultIMEStartComposition(HIMC hIMC, HWND hwnd )
1226 TRACE("IME message WM_IME_STARTCOMPOSITION\n");
1227 UpdateDefaultIMEWindow(hIMC, hwnd);
1230 static LRESULT ImeHandleNotify(HIMC hIMC, HWND hwnd, UINT msg, WPARAM wParam,
1231 LPARAM lParam)
1233 switch (wParam)
1235 case IMN_OPENSTATUSWINDOW:
1236 FIXME("WM_IME_NOTIFY:IMN_OPENSTATUSWINDOW\n");
1237 break;
1238 case IMN_CLOSESTATUSWINDOW:
1239 FIXME("WM_IME_NOTIFY:IMN_CLOSESTATUSWINDOW\n");
1240 break;
1241 case IMN_OPENCANDIDATE:
1242 FIXME("WM_IME_NOTIFY:IMN_OPENCANDIDATE\n");
1243 break;
1244 case IMN_CHANGECANDIDATE:
1245 FIXME("WM_IME_NOTIFY:IMN_CHANGECANDIDATE\n");
1246 break;
1247 case IMN_CLOSECANDIDATE:
1248 FIXME("WM_IME_NOTIFY:IMN_CLOSECANDIDATE\n");
1249 break;
1250 case IMN_SETCONVERSIONMODE:
1251 FIXME("WM_IME_NOTIFY:IMN_SETCONVERSIONMODE\n");
1252 break;
1253 case IMN_SETSENTENCEMODE:
1254 FIXME("WM_IME_NOTIFY:IMN_SETSENTENCEMODE\n");
1255 break;
1256 case IMN_SETOPENSTATUS:
1257 TRACE("WM_IME_NOTIFY:IMN_SETOPENSTATUS\n");
1258 break;
1259 case IMN_SETCANDIDATEPOS:
1260 FIXME("WM_IME_NOTIFY:IMN_SETCANDIDATEPOS\n");
1261 break;
1262 case IMN_SETCOMPOSITIONFONT:
1263 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONFONT\n");
1264 break;
1265 case IMN_SETCOMPOSITIONWINDOW:
1266 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONWINDOW\n");
1267 break;
1268 case IMN_GUIDELINE:
1269 FIXME("WM_IME_NOTIFY:IMN_GUIDELINE\n");
1270 break;
1271 case IMN_SETSTATUSWINDOWPOS:
1272 FIXME("WM_IME_NOTIFY:IMN_SETSTATUSWINDOWPOS\n");
1273 break;
1274 default:
1275 FIXME("WM_IME_NOTIFY:<Unknown 0x%lx>\n",wParam);
1276 break;
1278 return 0;
1281 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
1282 LPARAM lParam)
1284 LRESULT rc = 0;
1285 HIMC hIMC;
1287 TRACE("Incoming Message 0x%x (0x%08lx, 0x%08lx)\n", msg, wParam, lParam);
1290 * Each UI window contains the current Input Context.
1291 * This Input Context can be obtained by calling GetWindowLong
1292 * with IMMGWL_IMC when the UI window receives a WM_IME_xxx message.
1293 * The UI window can refer to this Input Context and handles the
1294 * messages.
1297 hIMC = (HIMC)GetWindowLongPtrW(hwnd,IMMGWL_IMC);
1298 if (!hIMC)
1299 hIMC = RealIMC(FROM_X11);
1301 /* if we have no hIMC there are many messages we cannot process */
1302 if (hIMC == NULL)
1304 switch (msg) {
1305 case WM_IME_STARTCOMPOSITION:
1306 case WM_IME_ENDCOMPOSITION:
1307 case WM_IME_COMPOSITION:
1308 case WM_IME_NOTIFY:
1309 case WM_IME_CONTROL:
1310 case WM_IME_COMPOSITIONFULL:
1311 case WM_IME_SELECT:
1312 case WM_IME_CHAR:
1313 return 0L;
1314 default:
1315 break;
1319 switch(msg)
1321 case WM_CREATE:
1323 LPIMEPRIVATE myPrivate;
1324 LPINPUTCONTEXT lpIMC;
1326 SetWindowTextA(hwnd,"Wine Ime Active");
1328 lpIMC = LockRealIMC(hIMC);
1329 if (lpIMC)
1331 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1332 myPrivate->hwndDefault = hwnd;
1333 ImmUnlockIMCC(lpIMC->hPrivate);
1335 UnlockRealIMC(hIMC);
1337 return TRUE;
1339 case WM_PAINT:
1340 PaintDefaultIMEWnd(hIMC, hwnd);
1341 return FALSE;
1343 case WM_NCCREATE:
1344 return TRUE;
1346 case WM_SETFOCUS:
1347 if (wParam)
1348 SetFocus((HWND)wParam);
1349 else
1350 FIXME("Received focus, should never have focus\n");
1351 break;
1352 case WM_IME_COMPOSITION:
1353 DefaultIMEComposition(hIMC, hwnd, lParam);
1354 break;
1355 case WM_IME_STARTCOMPOSITION:
1356 DefaultIMEStartComposition(hIMC, hwnd);
1357 break;
1358 case WM_IME_ENDCOMPOSITION:
1359 TRACE("IME message %s, 0x%lx, 0x%lx\n",
1360 "WM_IME_ENDCOMPOSITION", wParam, lParam);
1361 ShowWindow(hwnd,SW_HIDE);
1362 break;
1363 case WM_IME_SELECT:
1364 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_IME_SELECT", wParam, lParam);
1365 break;
1366 case WM_IME_CONTROL:
1367 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_IME_CONTROL", wParam, lParam);
1368 rc = 1;
1369 break;
1370 case WM_IME_NOTIFY:
1371 rc = ImeHandleNotify(hIMC,hwnd,msg,wParam,lParam);
1372 break;
1373 default:
1374 TRACE("Non-standard message 0x%x\n",msg);
1376 /* check the MSIME messages */
1377 if (msg == WM_MSIME_SERVICE)
1379 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_SERVICE", wParam, lParam);
1380 rc = FALSE;
1382 else if (msg == WM_MSIME_RECONVERTOPTIONS)
1384 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERTOPTIONS", wParam, lParam);
1386 else if (msg == WM_MSIME_MOUSE)
1388 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_MOUSE", wParam, lParam);
1390 else if (msg == WM_MSIME_RECONVERTREQUEST)
1392 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERTREQUEST", wParam, lParam);
1394 else if (msg == WM_MSIME_RECONVERT)
1396 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERT", wParam, lParam);
1398 else if (msg == WM_MSIME_QUERYPOSITION)
1400 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_QUERYPOSITION", wParam, lParam);
1402 else if (msg == WM_MSIME_DOCUMENTFEED)
1404 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_DOCUMENTFEED", wParam, lParam);
1406 /* DefWndProc if not an IME message */
1407 if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1408 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
1409 rc = DefWindowProcW(hwnd,msg,wParam,lParam);
1411 return rc;