TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / winex11.drv / ime.c
blob22698cf016863f8bc3aefc7d269042980cfd8af7
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, CompClaus 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(DWORD);
221 needed_size += lpcs->dwResultReadClauseLen;
222 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
223 needed_size += lpcs->dwResultClauseLen;
224 needed_size += lpcs->dwResultStrLen * sizeof(DWORD);
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);
308 /* CompStr */
309 new_one->dwCompStrLen = len;
310 if (len > 0)
312 new_one->dwCompStrOffset = current_offset;
313 memcpy(&newdata[current_offset],compstr,len*sizeof(WCHAR));
316 /* CursorPos */
317 new_one->dwCursorPos = len;
319 ImmUnlockIMCC(rc);
320 if (lpcs)
321 ImmUnlockIMCC(old);
323 return rc;
326 static HIMCC updateResultStr(HIMCC old, LPWSTR resultstr, DWORD len)
328 /* we need to make sure the ResultStr and ResultClause fields are all
329 * set and correct */
330 int needed_size;
331 HIMCC rc;
332 LPBYTE newdata = NULL;
333 LPBYTE olddata = NULL;
334 LPCOMPOSITIONSTRING new_one;
335 LPCOMPOSITIONSTRING lpcs = NULL;
336 INT current_offset = 0;
338 TRACE("%s, %i\n",debugstr_wn(resultstr,len),len);
340 if (old == NULL && resultstr == NULL && len == 0)
341 return NULL;
343 if (resultstr == NULL && len != 0)
345 ERR("resultstr is NULL however we have a len! Please report\n");
346 len = 0;
349 if (old != NULL)
351 olddata = ImmLockIMCC(old);
352 lpcs = (LPCOMPOSITIONSTRING)olddata;
355 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
356 sizeof(DWORD) * 2;
358 if (lpcs != NULL)
360 needed_size += lpcs->dwCompReadAttrLen;
361 needed_size += lpcs->dwCompReadClauseLen;
362 needed_size += lpcs->dwCompReadStrLen * sizeof(DWORD);
363 needed_size += lpcs->dwCompAttrLen;
364 needed_size += lpcs->dwCompClauseLen;
365 needed_size += lpcs->dwCompStrLen * sizeof(DWORD);
366 needed_size += lpcs->dwResultReadClauseLen;
367 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
368 needed_size += lpcs->dwPrivateSize;
370 rc = ImmCreateIMCC(needed_size);
371 newdata = ImmLockIMCC(rc);
372 new_one = (LPCOMPOSITIONSTRING)newdata;
374 new_one->dwSize = needed_size;
375 current_offset = sizeof(COMPOSITIONSTRING);
376 if (lpcs != NULL)
378 current_offset = updateField(lpcs->dwCompReadAttrLen,
379 lpcs->dwCompReadAttrOffset,
380 current_offset, newdata, olddata,
381 &new_one->dwCompReadAttrLen,
382 &new_one->dwCompReadAttrOffset, FALSE);
384 current_offset = updateField(lpcs->dwCompReadClauseLen,
385 lpcs->dwCompReadClauseOffset,
386 current_offset, newdata, olddata,
387 &new_one->dwCompReadClauseLen,
388 &new_one->dwCompReadClauseOffset, FALSE);
390 current_offset = updateField(lpcs->dwCompReadStrLen,
391 lpcs->dwCompReadStrOffset,
392 current_offset, newdata, olddata,
393 &new_one->dwCompReadStrLen,
394 &new_one->dwCompReadStrOffset, TRUE);
396 current_offset = updateField(lpcs->dwCompAttrLen,
397 lpcs->dwCompAttrOffset,
398 current_offset, newdata, olddata,
399 &new_one->dwCompAttrLen,
400 &new_one->dwCompAttrOffset, FALSE);
402 current_offset = updateField(lpcs->dwCompClauseLen,
403 lpcs->dwCompClauseOffset,
404 current_offset, newdata, olddata,
405 &new_one->dwCompClauseLen,
406 &new_one->dwCompClauseOffset, FALSE);
408 current_offset = updateField(lpcs->dwCompStrLen,
409 lpcs->dwCompStrOffset,
410 current_offset, newdata, olddata,
411 &new_one->dwCompStrLen,
412 &new_one->dwCompStrOffset, TRUE);
414 new_one->dwCursorPos = lpcs->dwCursorPos;
415 new_one->dwDeltaStart = 0;
417 current_offset = updateField(lpcs->dwResultReadClauseLen,
418 lpcs->dwResultReadClauseOffset,
419 current_offset, newdata, olddata,
420 &new_one->dwResultReadClauseLen,
421 &new_one->dwResultReadClauseOffset, FALSE);
423 current_offset = updateField(lpcs->dwResultReadStrLen,
424 lpcs->dwResultReadStrOffset,
425 current_offset, newdata, olddata,
426 &new_one->dwResultReadStrLen,
427 &new_one->dwResultReadStrOffset, TRUE);
429 /* new ResultClause , ResultStr */
431 current_offset = updateField(lpcs->dwPrivateSize,
432 lpcs->dwPrivateOffset,
433 current_offset, newdata, olddata,
434 &new_one->dwPrivateSize,
435 &new_one->dwPrivateOffset, FALSE);
438 /* set new data */
439 /* ResultClause */
440 if (len > 0)
442 new_one->dwResultClauseLen = sizeof(DWORD) * 2;
443 new_one->dwResultClauseOffset = current_offset;
444 *(DWORD*)(&newdata[current_offset]) = 0;
445 current_offset += sizeof(DWORD);
446 *(DWORD*)(&newdata[current_offset]) = len;
447 current_offset += sizeof(DWORD);
450 /* ResultStr */
451 new_one->dwResultStrLen = len;
452 if (len > 0)
454 new_one->dwResultStrOffset = current_offset;
455 memcpy(&newdata[current_offset],resultstr,len*sizeof(WCHAR));
457 ImmUnlockIMCC(rc);
458 if (lpcs)
459 ImmUnlockIMCC(old);
461 return rc;
464 static void GenerateIMEMessage(HIMC hIMC, UINT msg, WPARAM wParam,
465 LPARAM lParam)
467 LPINPUTCONTEXT lpIMC;
468 LPTRANSMSG lpTransMsg;
470 lpIMC = LockRealIMC(hIMC);
471 if (lpIMC == NULL)
472 return;
474 lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf, (lpIMC->dwNumMsgBuf + 1) *
475 sizeof(TRANSMSG));
476 if (!lpIMC->hMsgBuf)
477 return;
479 lpTransMsg = ImmLockIMCC(lpIMC->hMsgBuf);
480 if (!lpTransMsg)
481 return;
483 lpTransMsg += lpIMC->dwNumMsgBuf;
484 lpTransMsg->message = msg;
485 lpTransMsg->wParam = wParam;
486 lpTransMsg->lParam = lParam;
488 ImmUnlockIMCC(lpIMC->hMsgBuf);
489 lpIMC->dwNumMsgBuf++;
491 ImmGenerateMessage(RealIMC(hIMC));
492 UnlockRealIMC(hIMC);
495 static void GenerateIMECHARMessages(HIMC hIMC, LPWSTR String, DWORD length)
497 LPINPUTCONTEXT lpIMC;
498 LPTRANSMSG lpTransMsg;
499 DWORD i;
501 if (length <= 0)
502 return;
504 lpIMC = LockRealIMC(hIMC);
505 if (lpIMC == NULL)
506 return;
508 lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
509 (lpIMC->dwNumMsgBuf + length) *
510 sizeof(TRANSMSG));
511 if (!lpIMC->hMsgBuf)
512 return;
514 lpTransMsg = ImmLockIMCC(lpIMC->hMsgBuf);
515 if (!lpTransMsg)
516 return;
518 lpTransMsg += lpIMC->dwNumMsgBuf;
519 for (i = 0; i < length; i++)
521 lpTransMsg->message = WM_IME_CHAR;
522 lpTransMsg->wParam = String[i];
523 lpTransMsg->lParam = 1;
524 lpTransMsg ++;
527 ImmUnlockIMCC(lpIMC->hMsgBuf);
528 lpIMC->dwNumMsgBuf+=length;
530 ImmGenerateMessage(RealIMC(hIMC));
531 UnlockRealIMC(hIMC);
534 static BOOL IME_RemoveFromSelected(HIMC hIMC)
536 int i;
537 for (i = 0; i < hSelectedCount; i++)
538 if (hSelectedFrom[i] == hIMC)
540 if (i < hSelectedCount - 1)
541 memmove(&hSelectedFrom[i], &hSelectedFrom[i+1], (hSelectedCount - i - 1)*sizeof(HIMC));
542 hSelectedCount --;
543 return TRUE;
545 return FALSE;
548 static void IME_AddToSelected(HIMC hIMC)
550 hSelectedCount++;
551 if (hSelectedFrom)
552 hSelectedFrom = HeapReAlloc(GetProcessHeap(), 0, hSelectedFrom, hSelectedCount*sizeof(HIMC));
553 else
554 hSelectedFrom = HeapAlloc(GetProcessHeap(), 0, sizeof(HIMC));
555 hSelectedFrom[hSelectedCount-1] = hIMC;
558 BOOL WINAPI ImeInquire(LPIMEINFO lpIMEInfo, LPWSTR lpszUIClass,
559 LPCWSTR lpszOption)
561 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
563 TRACE("\n");
564 InitOnceExecuteOnce( &init_once, register_classes, NULL, NULL );
565 lpIMEInfo->dwPrivateDataSize = sizeof (IMEPRIVATE);
566 lpIMEInfo->fdwProperty = IME_PROP_UNICODE | IME_PROP_AT_CARET;
567 lpIMEInfo->fdwConversionCaps = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
568 lpIMEInfo->fdwSentenceCaps = IME_SMODE_AUTOMATIC;
569 lpIMEInfo->fdwUICaps = UI_CAP_2700;
570 /* Tell App we cannot accept ImeSetCompositionString calls */
571 lpIMEInfo->fdwSCSCaps = 0;
572 lpIMEInfo->fdwSelectCaps = SELECT_CAP_CONVERSION;
574 lstrcpyW(lpszUIClass,UI_CLASS_NAME);
576 return TRUE;
579 BOOL WINAPI ImeConfigure(HKL hKL,HWND hWnd, DWORD dwMode, LPVOID lpData)
581 FIXME("(%p, %p, %d, %p): stub\n", hKL, hWnd, dwMode, lpData);
582 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
583 return FALSE;
586 DWORD WINAPI ImeConversionList(HIMC hIMC, LPCWSTR lpSource,
587 LPCANDIDATELIST lpCandList, DWORD dwBufLen, UINT uFlag)
590 FIXME("(%p, %s, %p, %d, %d): stub\n", hIMC, debugstr_w(lpSource),
591 lpCandList, dwBufLen, uFlag);
592 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
593 return 0;
596 BOOL WINAPI ImeDestroy(UINT uForce)
598 TRACE("\n");
599 HeapFree(GetProcessHeap(),0,hSelectedFrom);
600 hSelectedFrom = NULL;
601 hSelectedCount = 0;
602 return TRUE;
605 LRESULT WINAPI ImeEscape(HIMC hIMC, UINT uSubFunc, LPVOID lpData)
607 FIXME("(%p, %d, %p): stub\n", hIMC, uSubFunc, lpData);
608 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
609 return 0;
612 BOOL WINAPI ImeProcessKey(HIMC hIMC, UINT vKey, LPARAM lKeyData, const LPBYTE lpbKeyState)
614 /* See the comment at the head of this file */
615 TRACE("We do no processing via this route\n");
616 return FALSE;
619 BOOL WINAPI ImeSelect(HIMC hIMC, BOOL fSelect)
621 LPINPUTCONTEXT lpIMC;
622 TRACE("%p %s\n",hIMC,(fSelect)?"TRUE":"FALSE");
624 if (hIMC == FROM_X11)
626 ERR("ImeSelect should never be called from X11\n");
627 return FALSE;
630 if (!hIMC)
631 return TRUE;
633 /* not selected */
634 if (!fSelect)
635 return IME_RemoveFromSelected(hIMC);
637 IME_AddToSelected(hIMC);
639 /* Initialize our structures */
640 lpIMC = LockRealIMC(hIMC);
641 if (lpIMC != NULL)
643 LPIMEPRIVATE myPrivate;
644 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
645 myPrivate->bInComposition = FALSE;
646 myPrivate->bInternalState = FALSE;
647 myPrivate->textfont = NULL;
648 myPrivate->hwndDefault = NULL;
649 ImmUnlockIMCC(lpIMC->hPrivate);
650 UnlockRealIMC(hIMC);
653 return TRUE;
656 BOOL WINAPI ImeSetActiveContext(HIMC hIMC,BOOL fFlag)
658 FIXME("(%p, %x): stub\n", hIMC, fFlag);
659 return TRUE;
662 UINT WINAPI ImeToAsciiEx (UINT uVKey, UINT uScanCode, const LPBYTE lpbKeyState,
663 LPDWORD lpdwTransKey, UINT fuState, HIMC hIMC)
665 /* See the comment at the head of this file */
666 TRACE("We do no processing via this route\n");
667 return 0;
670 BOOL WINAPI NotifyIME(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
672 BOOL bRet = FALSE;
673 LPINPUTCONTEXT lpIMC;
675 TRACE("%p %i %i %i\n",hIMC,dwAction,dwIndex,dwValue);
677 lpIMC = LockRealIMC(hIMC);
678 if (lpIMC == NULL)
679 return FALSE;
681 switch (dwAction)
683 case NI_OPENCANDIDATE: FIXME("NI_OPENCANDIDATE\n"); break;
684 case NI_CLOSECANDIDATE: FIXME("NI_CLOSECANDIDATE\n"); break;
685 case NI_SELECTCANDIDATESTR: FIXME("NI_SELECTCANDIDATESTR\n"); break;
686 case NI_CHANGECANDIDATELIST: FIXME("NI_CHANGECANDIDATELIST\n"); break;
687 case NI_SETCANDIDATE_PAGESTART: FIXME("NI_SETCANDIDATE_PAGESTART\n"); break;
688 case NI_SETCANDIDATE_PAGESIZE: FIXME("NI_SETCANDIDATE_PAGESIZE\n"); break;
689 case NI_CONTEXTUPDATED:
690 switch (dwValue)
692 case IMC_SETCOMPOSITIONWINDOW: FIXME("IMC_SETCOMPOSITIONWINDOW\n"); break;
693 case IMC_SETCONVERSIONMODE: FIXME("IMC_SETCONVERSIONMODE\n"); break;
694 case IMC_SETSENTENCEMODE: FIXME("IMC_SETSENTENCEMODE\n"); break;
695 case IMC_SETCANDIDATEPOS: FIXME("IMC_SETCANDIDATEPOS\n"); break;
696 case IMC_SETCOMPOSITIONFONT:
698 LPIMEPRIVATE myPrivate;
699 TRACE("IMC_SETCOMPOSITIONFONT\n");
701 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
702 if (myPrivate->textfont)
704 DeleteObject(myPrivate->textfont);
705 myPrivate->textfont = NULL;
707 myPrivate->textfont = CreateFontIndirectW(&lpIMC->lfFont.W);
708 ImmUnlockIMCC(lpIMC->hPrivate);
710 break;
711 case IMC_SETOPENSTATUS:
712 TRACE("IMC_SETOPENSTATUS\n");
714 bRet = TRUE;
715 X11DRV_SetPreeditState(lpIMC->hWnd, lpIMC->fOpen);
716 if (!lpIMC->fOpen)
718 LPIMEPRIVATE myPrivate;
720 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
721 if (myPrivate->bInComposition)
723 X11DRV_ForceXIMReset(lpIMC->hWnd);
724 GenerateIMEMessage(hIMC, WM_IME_ENDCOMPOSITION, 0, 0);
725 myPrivate->bInComposition = FALSE;
727 ImmUnlockIMCC(lpIMC->hPrivate);
730 break;
731 default: FIXME("Unknown\n"); break;
733 break;
734 case NI_COMPOSITIONSTR:
735 switch (dwIndex)
737 case CPS_COMPLETE:
739 HIMCC newCompStr;
740 DWORD cplen = 0;
741 LPWSTR cpstr;
742 LPCOMPOSITIONSTRING cs = NULL;
743 LPBYTE cdata = NULL;
744 LPIMEPRIVATE myPrivate;
746 TRACE("CPS_COMPLETE\n");
748 /* clear existing result */
749 newCompStr = updateResultStr(lpIMC->hCompStr, NULL, 0);
751 ImmDestroyIMCC(lpIMC->hCompStr);
752 lpIMC->hCompStr = newCompStr;
754 if (lpIMC->hCompStr)
756 cdata = ImmLockIMCC(lpIMC->hCompStr);
757 cs = (LPCOMPOSITIONSTRING)cdata;
758 cplen = cs->dwCompStrLen;
759 cpstr = (LPWSTR)&(cdata[cs->dwCompStrOffset]);
760 ImmUnlockIMCC(lpIMC->hCompStr);
762 if (cplen > 0)
764 WCHAR param = cpstr[0];
766 newCompStr = updateResultStr(lpIMC->hCompStr, cpstr, cplen);
767 ImmDestroyIMCC(lpIMC->hCompStr);
768 lpIMC->hCompStr = newCompStr;
769 newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0);
770 ImmDestroyIMCC(lpIMC->hCompStr);
771 lpIMC->hCompStr = newCompStr;
773 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, 0,
774 GCS_COMPSTR);
776 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, param,
777 GCS_RESULTSTR|GCS_RESULTCLAUSE);
780 GenerateIMEMessage(hIMC,WM_IME_ENDCOMPOSITION, 0, 0);
782 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
783 myPrivate->bInComposition = FALSE;
784 ImmUnlockIMCC(lpIMC->hPrivate);
786 bRet = TRUE;
788 break;
789 case CPS_CONVERT: FIXME("CPS_CONVERT\n"); break;
790 case CPS_REVERT: FIXME("CPS_REVERT\n"); break;
791 case CPS_CANCEL:
793 LPIMEPRIVATE myPrivate;
795 TRACE("CPS_CANCEL\n");
797 X11DRV_ForceXIMReset(lpIMC->hWnd);
799 if (lpIMC->hCompStr)
800 ImmDestroyIMCC(lpIMC->hCompStr);
801 lpIMC->hCompStr = ImeCreateBlankCompStr();
803 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
804 if (myPrivate->bInComposition)
806 GenerateIMEMessage(hIMC, WM_IME_ENDCOMPOSITION, 0, 0);
807 myPrivate->bInComposition = FALSE;
809 ImmUnlockIMCC(lpIMC->hPrivate);
810 bRet = TRUE;
812 break;
813 default: FIXME("Unknown\n"); break;
815 break;
816 default: FIXME("Unknown Message\n"); break;
819 UnlockRealIMC(hIMC);
820 return bRet;
823 BOOL WINAPI ImeRegisterWord(LPCWSTR lpszReading, DWORD dwStyle,
824 LPCWSTR lpszRegister)
826 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading), dwStyle,
827 debugstr_w(lpszRegister));
828 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
829 return FALSE;
832 BOOL WINAPI ImeUnregisterWord(LPCWSTR lpszReading, DWORD dwStyle,
833 LPCWSTR lpszUnregister)
835 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading), dwStyle,
836 debugstr_w(lpszUnregister));
837 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
838 return FALSE;
841 UINT WINAPI ImeGetRegisterWordStyle(UINT nItem, LPSTYLEBUFW lpStyleBuf)
843 FIXME("(%d, %p): stub\n", nItem, lpStyleBuf);
844 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
845 return 0;
848 UINT WINAPI ImeEnumRegisterWord(REGISTERWORDENUMPROCW lpfnEnumProc,
849 LPCWSTR lpszReading, DWORD dwStyle,
850 LPCWSTR lpszRegister, LPVOID lpData)
852 FIXME("(%p, %s, %d, %s, %p): stub\n", lpfnEnumProc,
853 debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister),
854 lpData);
855 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
856 return 0;
859 BOOL WINAPI ImeSetCompositionString(HIMC hIMC, DWORD dwIndex, LPCVOID lpComp,
860 DWORD dwCompLen, LPCVOID lpRead,
861 DWORD dwReadLen)
863 LPINPUTCONTEXT lpIMC;
864 DWORD flags = 0;
865 WCHAR wParam = 0;
866 LPIMEPRIVATE myPrivate;
868 TRACE("(%p, %d, %p, %d, %p, %d):\n",
869 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
872 if (hIMC != FROM_X11)
873 FIXME("PROBLEM: This only sets the wine level string\n");
876 * Explanation:
877 * this sets the composition string in the imm32.dll level
878 * of the composition buffer. we cannot manipulate the xim level
879 * buffer, which means that once the xim level buffer changes again
880 * any call to this function from the application will be lost
883 if (lpRead && dwReadLen)
884 FIXME("Reading string unimplemented\n");
886 lpIMC = LockRealIMC(hIMC);
888 if (lpIMC == NULL)
889 return FALSE;
891 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
893 if (dwIndex == SCS_SETSTR)
895 HIMCC newCompStr;
897 if (!myPrivate->bInComposition)
899 GenerateIMEMessage(hIMC, WM_IME_STARTCOMPOSITION, 0, 0);
900 myPrivate->bInComposition = TRUE;
903 flags = GCS_COMPSTR;
905 if (dwCompLen && lpComp)
907 newCompStr = updateCompStr(lpIMC->hCompStr, (LPCWSTR)lpComp, dwCompLen / sizeof(WCHAR));
908 ImmDestroyIMCC(lpIMC->hCompStr);
909 lpIMC->hCompStr = newCompStr;
911 wParam = ((const WCHAR*)lpComp)[0];
912 flags |= GCS_COMPCLAUSE | GCS_COMPATTR | GCS_DELTASTART;
914 else
916 newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0);
917 ImmDestroyIMCC(lpIMC->hCompStr);
918 lpIMC->hCompStr = newCompStr;
922 GenerateIMEMessage(hIMC, WM_IME_COMPOSITION, wParam, flags);
923 ImmUnlockIMCC(lpIMC->hPrivate);
924 UnlockRealIMC(hIMC);
926 return TRUE;
929 DWORD WINAPI ImeGetImeMenuItems(HIMC hIMC, DWORD dwFlags, DWORD dwType,
930 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
931 DWORD dwSize)
933 FIXME("(%p, %x %x %p %p %x): stub\n", hIMC, dwFlags, dwType,
934 lpImeParentMenu, lpImeMenu, dwSize);
935 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
936 return 0;
939 /* Interfaces to XIM and other parts of winex11drv */
941 void IME_SetOpenStatus(BOOL fOpen)
943 HIMC imc;
945 imc = RealIMC(FROM_X11);
946 ImmSetOpenStatus(imc, fOpen);
949 void IME_SetCompositionStatus(BOOL fOpen)
951 HIMC imc;
952 LPINPUTCONTEXT lpIMC;
953 LPIMEPRIVATE myPrivate;
955 imc = RealIMC(FROM_X11);
956 lpIMC = ImmLockIMC(imc);
957 if (lpIMC == NULL)
958 return;
960 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
962 if (fOpen && !myPrivate->bInComposition)
964 GenerateIMEMessage(imc, WM_IME_STARTCOMPOSITION, 0, 0);
966 else if (!fOpen && myPrivate->bInComposition)
968 ShowWindow(myPrivate->hwndDefault, SW_HIDE);
969 ImmDestroyIMCC(lpIMC->hCompStr);
970 lpIMC->hCompStr = ImeCreateBlankCompStr();
971 GenerateIMEMessage(imc, WM_IME_ENDCOMPOSITION, 0, 0);
973 myPrivate->bInComposition = fOpen;
975 ImmUnlockIMCC(lpIMC->hPrivate);
976 ImmUnlockIMC(imc);
979 INT IME_GetCursorPos(void)
981 LPINPUTCONTEXT lpIMC;
982 INT rc = 0;
983 LPCOMPOSITIONSTRING compstr;
985 if (!hSelectedFrom)
986 return rc;
988 lpIMC = LockRealIMC(FROM_X11);
989 if (lpIMC)
991 compstr = ImmLockIMCC(lpIMC->hCompStr);
992 rc = compstr->dwCursorPos;
993 ImmUnlockIMCC(lpIMC->hCompStr);
995 UnlockRealIMC(FROM_X11);
996 return rc;
999 void IME_SetCursorPos(DWORD pos)
1001 LPINPUTCONTEXT lpIMC;
1002 LPCOMPOSITIONSTRING compstr;
1004 if (!hSelectedFrom)
1005 return;
1007 lpIMC = LockRealIMC(FROM_X11);
1008 if (!lpIMC)
1009 return;
1011 compstr = ImmLockIMCC(lpIMC->hCompStr);
1012 if (!compstr)
1014 UnlockRealIMC(FROM_X11);
1015 return;
1018 compstr->dwCursorPos = pos;
1019 ImmUnlockIMCC(lpIMC->hCompStr);
1020 UnlockRealIMC(FROM_X11);
1021 GenerateIMEMessage(FROM_X11, WM_IME_COMPOSITION, pos, GCS_CURSORPOS);
1022 return;
1025 void IME_UpdateAssociation(HWND focus)
1027 ImmGetContext(focus);
1029 if (!focus || !hSelectedFrom)
1030 return;
1032 ImmAssociateContext(focus,RealIMC(FROM_X11));
1036 BOOL IME_SetCompositionString(DWORD dwIndex, LPCVOID lpComp, DWORD dwCompLen,
1037 LPCVOID lpRead, DWORD dwReadLen)
1039 return ImeSetCompositionString(FROM_X11, dwIndex, lpComp, dwCompLen,
1040 lpRead, dwReadLen);
1043 void IME_SetResultString(LPWSTR lpResult, DWORD dwResultLen)
1045 HIMC imc;
1046 LPINPUTCONTEXT lpIMC;
1047 HIMCC newCompStr;
1048 LPIMEPRIVATE myPrivate;
1050 imc = RealIMC(FROM_X11);
1051 lpIMC = ImmLockIMC(imc);
1052 if (lpIMC == NULL)
1053 return;
1055 newCompStr = updateResultStr(lpIMC->hCompStr, lpResult, dwResultLen);
1056 ImmDestroyIMCC(lpIMC->hCompStr);
1057 lpIMC->hCompStr = newCompStr;
1059 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1060 if (!myPrivate->bInComposition)
1061 GenerateIMEMessage(imc, WM_IME_STARTCOMPOSITION, 0, 0);
1062 GenerateIMEMessage(imc, WM_IME_COMPOSITION, 0, GCS_RESULTSTR);
1063 if (!myPrivate->bInComposition)
1064 GenerateIMEMessage(imc, WM_IME_ENDCOMPOSITION, 0, 0);
1065 ImmUnlockIMCC(lpIMC->hPrivate);
1067 ImmUnlockIMC(imc);
1070 /*****
1071 * Internal functions to help with IME window management
1073 static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
1075 PAINTSTRUCT ps;
1076 RECT rect;
1077 HDC hdc;
1078 LPCOMPOSITIONSTRING compstr;
1079 LPBYTE compdata = NULL;
1080 HMONITOR monitor;
1081 MONITORINFO mon_info;
1082 INT offX=0, offY=0;
1083 LPINPUTCONTEXT lpIMC;
1085 lpIMC = LockRealIMC(hIMC);
1086 if (lpIMC == NULL)
1087 return;
1089 hdc = BeginPaint(hwnd,&ps);
1091 GetClientRect(hwnd,&rect);
1092 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
1094 compdata = ImmLockIMCC(lpIMC->hCompStr);
1095 compstr = (LPCOMPOSITIONSTRING)compdata;
1097 if (compstr->dwCompStrLen && compstr->dwCompStrOffset)
1099 SIZE size;
1100 POINT pt;
1101 HFONT oldfont = NULL;
1102 LPWSTR CompString;
1103 LPIMEPRIVATE myPrivate;
1105 CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
1106 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1108 if (myPrivate->textfont)
1109 oldfont = SelectObject(hdc,myPrivate->textfont);
1111 ImmUnlockIMCC(lpIMC->hPrivate);
1113 GetTextExtentPoint32W(hdc, CompString, compstr->dwCompStrLen, &size);
1114 pt.x = size.cx;
1115 pt.y = size.cy;
1116 LPtoDP(hdc,&pt,1);
1119 * How this works based on tests on windows:
1120 * CFS_POINT: then we start our window at the point and grow it as large
1121 * as it needs to be for the string.
1122 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
1123 * window is only as large as we need for the string, but we do not
1124 * grow such that our window exceeds the given rect. Wrapping if
1125 * needed and possible. If our ptCurrentPos is outside of our rect
1126 * then no window is displayed.
1127 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
1128 * maybe because the default MSIME does not do any IME adjusting.
1130 if (lpIMC->cfCompForm.dwStyle != CFS_DEFAULT)
1132 POINT cpt = lpIMC->cfCompForm.ptCurrentPos;
1133 ClientToScreen(lpIMC->hWnd,&cpt);
1134 rect.left = cpt.x;
1135 rect.top = cpt.y;
1136 rect.right = rect.left + pt.x;
1137 rect.bottom = rect.top + pt.y;
1138 monitor = MonitorFromPoint(cpt, MONITOR_DEFAULTTOPRIMARY);
1140 else /* CFS_DEFAULT */
1142 /* Windows places the default IME window in the bottom left */
1143 HWND target = lpIMC->hWnd;
1144 if (!target) target = GetFocus();
1146 GetWindowRect(target,&rect);
1147 rect.top = rect.bottom;
1148 rect.right = rect.left + pt.x + 20;
1149 rect.bottom = rect.top + pt.y + 20;
1150 offX=offY=10;
1151 monitor = MonitorFromWindow(target, MONITOR_DEFAULTTOPRIMARY);
1154 if (lpIMC->cfCompForm.dwStyle == CFS_RECT)
1156 RECT client;
1157 client =lpIMC->cfCompForm.rcArea;
1158 MapWindowPoints( lpIMC->hWnd, 0, (POINT *)&client, 2 );
1159 IntersectRect(&rect,&rect,&client);
1160 /* TODO: Wrap the input if needed */
1163 if (lpIMC->cfCompForm.dwStyle == CFS_DEFAULT)
1165 /* make sure we are on the desktop */
1166 mon_info.cbSize = sizeof(mon_info);
1167 GetMonitorInfoW(monitor, &mon_info);
1169 if (rect.bottom > mon_info.rcWork.bottom)
1171 int shift = rect.bottom - mon_info.rcWork.bottom;
1172 rect.top -= shift;
1173 rect.bottom -= shift;
1175 if (rect.left < 0)
1177 rect.right -= rect.left;
1178 rect.left = 0;
1180 if (rect.right > mon_info.rcWork.right)
1182 int shift = rect.right - mon_info.rcWork.right;
1183 rect.left -= shift;
1184 rect.right -= shift;
1188 SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
1190 TextOutW(hdc, offX,offY, CompString, compstr->dwCompStrLen);
1192 if (oldfont)
1193 SelectObject(hdc,oldfont);
1196 ImmUnlockIMCC(lpIMC->hCompStr);
1198 EndPaint(hwnd,&ps);
1199 UnlockRealIMC(hIMC);
1202 static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd)
1204 LPCOMPOSITIONSTRING compstr;
1205 LPINPUTCONTEXT lpIMC;
1207 lpIMC = LockRealIMC(hIMC);
1208 if (lpIMC == NULL)
1209 return;
1211 if (lpIMC->hCompStr)
1212 compstr = ImmLockIMCC(lpIMC->hCompStr);
1213 else
1214 compstr = NULL;
1216 if (compstr == NULL || compstr->dwCompStrLen == 0)
1217 ShowWindow(hwnd,SW_HIDE);
1218 else
1220 ShowWindow(hwnd,SW_SHOWNOACTIVATE);
1221 RedrawWindow(hwnd, NULL, NULL, RDW_ERASENOW | RDW_INVALIDATE);
1224 if (compstr != NULL)
1225 ImmUnlockIMCC(lpIMC->hCompStr);
1227 lpIMC->hWnd = GetFocus();
1228 UnlockRealIMC(hIMC);
1231 static void DefaultIMEComposition(HIMC hIMC, HWND hwnd, LPARAM lParam)
1233 TRACE("IME message WM_IME_COMPOSITION 0x%lx\n", lParam);
1234 if (lParam & GCS_RESULTSTR)
1236 LPCOMPOSITIONSTRING compstr;
1237 LPBYTE compdata;
1238 LPWSTR ResultStr;
1239 HIMCC newCompStr;
1240 LPINPUTCONTEXT lpIMC;
1242 lpIMC = LockRealIMC(hIMC);
1243 if (lpIMC == NULL)
1244 return;
1246 TRACE("Posting result as IME_CHAR\n");
1247 compdata = ImmLockIMCC(lpIMC->hCompStr);
1248 compstr = (LPCOMPOSITIONSTRING)compdata;
1249 ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
1250 GenerateIMECHARMessages(hIMC, ResultStr, compstr->dwResultStrLen);
1251 ImmUnlockIMCC(lpIMC->hCompStr);
1253 /* clear the buffer */
1254 newCompStr = updateResultStr(lpIMC->hCompStr, NULL, 0);
1255 ImmDestroyIMCC(lpIMC->hCompStr);
1256 lpIMC->hCompStr = newCompStr;
1257 UnlockRealIMC(hIMC);
1259 else
1260 UpdateDefaultIMEWindow(hIMC, hwnd);
1263 static void DefaultIMEStartComposition(HIMC hIMC, HWND hwnd )
1265 TRACE("IME message WM_IME_STARTCOMPOSITION\n");
1266 UpdateDefaultIMEWindow(hIMC, hwnd);
1269 static LRESULT ImeHandleNotify(HIMC hIMC, HWND hwnd, UINT msg, WPARAM wParam,
1270 LPARAM lParam)
1272 switch (wParam)
1274 case IMN_OPENSTATUSWINDOW:
1275 FIXME("WM_IME_NOTIFY:IMN_OPENSTATUSWINDOW\n");
1276 break;
1277 case IMN_CLOSESTATUSWINDOW:
1278 FIXME("WM_IME_NOTIFY:IMN_CLOSESTATUSWINDOW\n");
1279 break;
1280 case IMN_OPENCANDIDATE:
1281 FIXME("WM_IME_NOTIFY:IMN_OPENCANDIDATE\n");
1282 break;
1283 case IMN_CHANGECANDIDATE:
1284 FIXME("WM_IME_NOTIFY:IMN_CHANGECANDIDATE\n");
1285 break;
1286 case IMN_CLOSECANDIDATE:
1287 FIXME("WM_IME_NOTIFY:IMN_CLOSECANDIDATE\n");
1288 break;
1289 case IMN_SETCONVERSIONMODE:
1290 FIXME("WM_IME_NOTIFY:IMN_SETCONVERSIONMODE\n");
1291 break;
1292 case IMN_SETSENTENCEMODE:
1293 FIXME("WM_IME_NOTIFY:IMN_SETSENTENCEMODE\n");
1294 break;
1295 case IMN_SETOPENSTATUS:
1296 TRACE("WM_IME_NOTIFY:IMN_SETOPENSTATUS\n");
1297 break;
1298 case IMN_SETCANDIDATEPOS:
1299 FIXME("WM_IME_NOTIFY:IMN_SETCANDIDATEPOS\n");
1300 break;
1301 case IMN_SETCOMPOSITIONFONT:
1302 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONFONT\n");
1303 break;
1304 case IMN_SETCOMPOSITIONWINDOW:
1305 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONWINDOW\n");
1306 break;
1307 case IMN_GUIDELINE:
1308 FIXME("WM_IME_NOTIFY:IMN_GUIDELINE\n");
1309 break;
1310 case IMN_SETSTATUSWINDOWPOS:
1311 FIXME("WM_IME_NOTIFY:IMN_SETSTATUSWINDOWPOS\n");
1312 break;
1313 default:
1314 FIXME("WM_IME_NOTIFY:<Unknown 0x%lx>\n",wParam);
1315 break;
1317 return 0;
1320 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
1321 LPARAM lParam)
1323 LRESULT rc = 0;
1324 HIMC hIMC;
1326 TRACE("Incoming Message 0x%x (0x%08lx, 0x%08lx)\n", msg, wParam, lParam);
1329 * Each UI window contains the current Input Context.
1330 * This Input Context can be obtained by calling GetWindowLong
1331 * with IMMGWL_IMC when the UI window receives a WM_IME_xxx message.
1332 * The UI window can refer to this Input Context and handles the
1333 * messages.
1336 hIMC = (HIMC)GetWindowLongPtrW(hwnd,IMMGWL_IMC);
1337 if (!hIMC)
1338 hIMC = RealIMC(FROM_X11);
1340 /* if we have no hIMC there are many messages we cannot process */
1341 if (hIMC == NULL)
1343 switch (msg) {
1344 case WM_IME_STARTCOMPOSITION:
1345 case WM_IME_ENDCOMPOSITION:
1346 case WM_IME_COMPOSITION:
1347 case WM_IME_NOTIFY:
1348 case WM_IME_CONTROL:
1349 case WM_IME_COMPOSITIONFULL:
1350 case WM_IME_SELECT:
1351 case WM_IME_CHAR:
1352 return 0L;
1353 default:
1354 break;
1358 switch(msg)
1360 case WM_CREATE:
1362 LPIMEPRIVATE myPrivate;
1363 LPINPUTCONTEXT lpIMC;
1365 SetWindowTextA(hwnd,"Wine Ime Active");
1367 lpIMC = LockRealIMC(hIMC);
1368 if (lpIMC)
1370 myPrivate = ImmLockIMCC(lpIMC->hPrivate);
1371 myPrivate->hwndDefault = hwnd;
1372 ImmUnlockIMCC(lpIMC->hPrivate);
1374 UnlockRealIMC(hIMC);
1376 return TRUE;
1378 case WM_PAINT:
1379 PaintDefaultIMEWnd(hIMC, hwnd);
1380 return FALSE;
1382 case WM_NCCREATE:
1383 return TRUE;
1385 case WM_SETFOCUS:
1386 if (wParam)
1387 SetFocus((HWND)wParam);
1388 else
1389 FIXME("Received focus, should never have focus\n");
1390 break;
1391 case WM_IME_COMPOSITION:
1392 DefaultIMEComposition(hIMC, hwnd, lParam);
1393 break;
1394 case WM_IME_STARTCOMPOSITION:
1395 DefaultIMEStartComposition(hIMC, hwnd);
1396 break;
1397 case WM_IME_ENDCOMPOSITION:
1398 TRACE("IME message %s, 0x%lx, 0x%lx\n",
1399 "WM_IME_ENDCOMPOSITION", wParam, lParam);
1400 ShowWindow(hwnd,SW_HIDE);
1401 break;
1402 case WM_IME_SELECT:
1403 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_IME_SELECT", wParam, lParam);
1404 break;
1405 case WM_IME_CONTROL:
1406 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_IME_CONTROL", wParam, lParam);
1407 rc = 1;
1408 break;
1409 case WM_IME_NOTIFY:
1410 rc = ImeHandleNotify(hIMC,hwnd,msg,wParam,lParam);
1411 break;
1412 default:
1413 TRACE("Non-standard message 0x%x\n",msg);
1415 /* check the MSIME messages */
1416 if (msg == WM_MSIME_SERVICE)
1418 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_SERVICE", wParam, lParam);
1419 rc = FALSE;
1421 else if (msg == WM_MSIME_RECONVERTOPTIONS)
1423 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERTOPTIONS", wParam, lParam);
1425 else if (msg == WM_MSIME_MOUSE)
1427 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_MOUSE", wParam, lParam);
1429 else if (msg == WM_MSIME_RECONVERTREQUEST)
1431 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERTREQUEST", wParam, lParam);
1433 else if (msg == WM_MSIME_RECONVERT)
1435 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_RECONVERT", wParam, lParam);
1437 else if (msg == WM_MSIME_QUERYPOSITION)
1439 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_QUERYPOSITION", wParam, lParam);
1441 else if (msg == WM_MSIME_DOCUMENTFEED)
1443 TRACE("IME message %s, 0x%lx, 0x%lx\n","WM_MSIME_DOCUMENTFEED", wParam, lParam);
1445 /* DefWndProc if not an IME message */
1446 if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1447 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
1448 rc = DefWindowProcW(hwnd,msg,wParam,lParam);
1450 return rc;