4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2002, 2003, 2007 CodeWeavers, Aric Stewart
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(imm);
36 #define FROM_IME 0xcafe1337
38 static void (*pX11DRV_ForceXIMReset)(HWND);
40 typedef struct tagIMCCInternal
46 typedef struct tagInputContextData
57 static InputContextData *root_context = NULL;
58 static HWND hwndDefault = NULL;
59 static HANDLE hImeInst;
60 static const WCHAR WC_IMECLASSNAME[] = {'I','M','E',0};
61 static ATOM atIMEClass = 0;
64 static UINT WM_MSIME_SERVICE;
65 static UINT WM_MSIME_RECONVERTOPTIONS;
66 static UINT WM_MSIME_MOUSE;
67 static UINT WM_MSIME_RECONVERTREQUEST;
68 static UINT WM_MSIME_RECONVERT;
69 static UINT WM_MSIME_QUERYPOSITION;
70 static UINT WM_MSIME_DOCUMENTFEED;
75 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
77 static void UpdateDataInDefaultIMEWindow(HWND hwnd, BOOL showable);
78 static void ImmInternalPostIMEMessage(UINT, WPARAM, LPARAM);
79 static void ImmInternalSetOpenStatus(BOOL fOpen);
80 static HIMCC updateResultStr(HIMCC old, LPWSTR resultstr, DWORD len);
82 static VOID IMM_PostResult(InputContextData *data)
85 LPCOMPOSITIONSTRING compstr;
90 TRACE("Posting result as IME_CHAR\n");
91 compdata = ImmLockIMCC(root_context->IMC.hCompStr);
92 compstr = (LPCOMPOSITIONSTRING)compdata;
93 ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
95 for (i = 0; i < compstr->dwResultStrLen; i++)
96 ImmInternalPostIMEMessage (WM_IME_CHAR, ResultStr[i], 1);
98 ImmUnlockIMCC(root_context->IMC.hCompStr);
100 /* clear the buffer */
101 newCompStr = updateResultStr(root_context->IMC.hCompStr, NULL, 0);
102 ImmDestroyIMCC(root_context->IMC.hCompStr);
103 root_context->IMC.hCompStr = newCompStr;
106 static void IMM_Register(void)
109 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
110 wndClass.style = CS_GLOBALCLASS | CS_IME | CS_HREDRAW | CS_VREDRAW;
111 wndClass.lpfnWndProc = (WNDPROC) IME_WindowProc;
112 wndClass.cbClsExtra = 0;
113 wndClass.cbWndExtra = 0;
114 wndClass.hInstance = hImeInst;
115 wndClass.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
116 wndClass.hIcon = NULL;
117 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
118 wndClass.lpszMenuName = 0;
119 wndClass.lpszClassName = WC_IMECLASSNAME;
120 atIMEClass = RegisterClassW(&wndClass);
123 static void IMM_Unregister(void)
126 UnregisterClassW(WC_IMECLASSNAME, NULL);
130 static void IMM_RegisterMessages(void)
132 WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
133 WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
134 WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
135 WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
136 WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
137 WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
138 WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
142 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
146 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
149 case DLL_PROCESS_ATTACH:
150 DisableThreadLibraryCalls(hInstDLL);
152 IMM_RegisterMessages();
153 x11drv = GetModuleHandleA("winex11.drv");
154 if (x11drv) pX11DRV_ForceXIMReset = (void *)GetProcAddress( x11drv, "ForceXIMReset");
156 case DLL_PROCESS_DETACH:
159 DestroyWindow(hwndDefault);
168 /* for posting messages as the IME */
169 static void ImmInternalPostIMEMessage(UINT msg, WPARAM wParam, LPARAM lParam)
171 HWND target = GetFocus();
173 PostMessageW(root_context->IMC.hWnd,msg,wParam,lParam);
175 PostMessageW(target, msg, wParam, lParam);
178 static LRESULT ImmInternalSendIMENotify(WPARAM notify, LPARAM lParam)
182 target = root_context->IMC.hWnd;
183 if (!target) target = GetFocus();
186 return SendMessageW(target, WM_IME_NOTIFY, notify, lParam);
191 static void ImmInternalSetOpenStatus(BOOL fOpen)
193 TRACE("Setting internal state to %s\n",(fOpen)?"OPEN":"CLOSED");
195 root_context->IMC.fOpen = fOpen;
196 root_context->bInternalState = fOpen;
200 ShowWindow(hwndDefault,SW_HIDE);
201 ImmDestroyIMCC(root_context->IMC.hCompStr);
202 root_context->IMC.hCompStr = NULL;
205 ShowWindow(hwndDefault, SW_SHOWNOACTIVATE);
207 ImmInternalSendIMENotify(IMN_SETOPENSTATUS, 0);
210 static int updateField(DWORD origLen, DWORD origOffset, DWORD currentOffset,
211 LPBYTE target, LPBYTE source, DWORD* lenParam,
212 DWORD* offsetParam, BOOL wchars )
214 if (origLen > 0 && origOffset > 0)
216 int truelen = origLen;
218 truelen *= sizeof(WCHAR);
220 memcpy(&target[currentOffset], &source[origOffset], truelen);
223 *offsetParam = currentOffset;
224 currentOffset += truelen;
226 return currentOffset;
229 static HIMCC updateCompStr(HIMCC old, LPWSTR compstr, DWORD len)
231 /* we need to make sure the CompStr, CompClaus and CompAttr fields are all
235 LPBYTE newdata = NULL;
236 LPBYTE olddata = NULL;
237 LPCOMPOSITIONSTRING new_one;
238 LPCOMPOSITIONSTRING lpcs = NULL;
239 INT current_offset = 0;
241 TRACE("%s, %i\n",debugstr_wn(compstr,len),len);
245 olddata = ImmLockIMCC(old);
246 lpcs = (LPCOMPOSITIONSTRING)olddata;
249 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
250 len + sizeof(DWORD) * 2;
254 needed_size += lpcs->dwCompReadAttrLen;
255 needed_size += lpcs->dwCompReadClauseLen;
256 needed_size += lpcs->dwCompReadStrLen * sizeof(DWORD);
257 needed_size += lpcs->dwResultReadClauseLen;
258 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
259 needed_size += lpcs->dwResultClauseLen;
260 needed_size += lpcs->dwResultStrLen * sizeof(DWORD);
261 needed_size += lpcs->dwPrivateSize;
263 rc = ImmCreateIMCC(needed_size);
264 newdata = ImmLockIMCC(rc);
265 new_one = (LPCOMPOSITIONSTRING)newdata;
267 new_one->dwSize = needed_size;
268 current_offset = sizeof(COMPOSITIONSTRING);
271 current_offset = updateField(lpcs->dwCompReadAttrLen,
272 lpcs->dwCompReadAttrOffset,
273 current_offset, newdata, olddata,
274 &new_one->dwCompReadAttrLen,
275 &new_one->dwCompReadAttrOffset, FALSE);
277 current_offset = updateField(lpcs->dwCompReadClauseLen,
278 lpcs->dwCompReadClauseOffset,
279 current_offset, newdata, olddata,
280 &new_one->dwCompReadClauseLen,
281 &new_one->dwCompReadClauseOffset, FALSE);
283 current_offset = updateField(lpcs->dwCompReadStrLen,
284 lpcs->dwCompReadStrOffset,
285 current_offset, newdata, olddata,
286 &new_one->dwCompReadStrLen,
287 &new_one->dwCompReadStrOffset, TRUE);
289 /* new CompAttr, CompClause, CompStr, dwCursorPos */
290 new_one->dwDeltaStart = 0;
292 current_offset = updateField(lpcs->dwResultReadClauseLen,
293 lpcs->dwResultReadClauseOffset,
294 current_offset, newdata, olddata,
295 &new_one->dwResultReadClauseLen,
296 &new_one->dwResultReadClauseOffset, FALSE);
298 current_offset = updateField(lpcs->dwResultReadStrLen,
299 lpcs->dwResultReadStrOffset,
300 current_offset, newdata, olddata,
301 &new_one->dwResultReadStrLen,
302 &new_one->dwResultReadStrOffset, TRUE);
304 current_offset = updateField(lpcs->dwResultClauseLen,
305 lpcs->dwResultClauseOffset,
306 current_offset, newdata, olddata,
307 &new_one->dwResultClauseLen,
308 &new_one->dwResultClauseOffset, FALSE);
310 current_offset = updateField(lpcs->dwResultStrLen,
311 lpcs->dwResultStrOffset,
312 current_offset, newdata, olddata,
313 &new_one->dwResultStrLen,
314 &new_one->dwResultStrOffset, TRUE);
316 current_offset = updateField(lpcs->dwPrivateSize,
317 lpcs->dwPrivateOffset,
318 current_offset, newdata, olddata,
319 &new_one->dwPrivateSize,
320 &new_one->dwPrivateOffset, FALSE);
325 new_one->dwCompAttrLen = len;
328 new_one->dwCompAttrOffset = current_offset;
329 memset(&newdata[current_offset],ATTR_INPUT,len);
330 current_offset += len;
336 new_one->dwCompClauseLen = sizeof(DWORD) * 2;
337 new_one->dwCompClauseOffset = current_offset;
338 *(DWORD*)(&newdata[current_offset]) = 0;
339 current_offset += sizeof(DWORD);
340 *(DWORD*)(&newdata[current_offset]) = len;
341 current_offset += sizeof(DWORD);
345 new_one->dwCompStrLen = len;
348 new_one->dwCompStrOffset = current_offset;
349 memcpy(&newdata[current_offset],compstr,len*sizeof(WCHAR));
353 new_one->dwCursorPos = len;
362 static HIMCC updateResultStr(HIMCC old, LPWSTR resultstr, DWORD len)
364 /* we need to make sure the ResultStr and ResultClause fields are all
368 LPBYTE newdata = NULL;
369 LPBYTE olddata = NULL;
370 LPCOMPOSITIONSTRING new_one;
371 LPCOMPOSITIONSTRING lpcs = NULL;
372 INT current_offset = 0;
374 TRACE("%s, %i\n",debugstr_wn(resultstr,len),len);
378 olddata = ImmLockIMCC(old);
379 lpcs = (LPCOMPOSITIONSTRING)olddata;
382 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
387 needed_size += lpcs->dwCompReadAttrLen;
388 needed_size += lpcs->dwCompReadClauseLen;
389 needed_size += lpcs->dwCompReadStrLen * sizeof(DWORD);
390 needed_size += lpcs->dwCompAttrLen;
391 needed_size += lpcs->dwCompClauseLen;
392 needed_size += lpcs->dwCompStrLen * sizeof(DWORD);
393 needed_size += lpcs->dwResultReadClauseLen;
394 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
395 needed_size += lpcs->dwPrivateSize;
397 rc = ImmCreateIMCC(needed_size);
398 newdata = ImmLockIMCC(rc);
399 new_one = (LPCOMPOSITIONSTRING)newdata;
401 new_one->dwSize = needed_size;
402 current_offset = sizeof(COMPOSITIONSTRING);
405 current_offset = updateField(lpcs->dwCompReadAttrLen,
406 lpcs->dwCompReadAttrOffset,
407 current_offset, newdata, olddata,
408 &new_one->dwCompReadAttrLen,
409 &new_one->dwCompReadAttrOffset, FALSE);
411 current_offset = updateField(lpcs->dwCompReadClauseLen,
412 lpcs->dwCompReadClauseOffset,
413 current_offset, newdata, olddata,
414 &new_one->dwCompReadClauseLen,
415 &new_one->dwCompReadClauseOffset, FALSE);
417 current_offset = updateField(lpcs->dwCompReadStrLen,
418 lpcs->dwCompReadStrOffset,
419 current_offset, newdata, olddata,
420 &new_one->dwCompReadStrLen,
421 &new_one->dwCompReadStrOffset, TRUE);
423 current_offset = updateField(lpcs->dwCompAttrLen,
424 lpcs->dwCompAttrOffset,
425 current_offset, newdata, olddata,
426 &new_one->dwCompAttrLen,
427 &new_one->dwCompAttrOffset, FALSE);
429 current_offset = updateField(lpcs->dwCompClauseLen,
430 lpcs->dwCompClauseOffset,
431 current_offset, newdata, olddata,
432 &new_one->dwCompClauseLen,
433 &new_one->dwCompClauseOffset, FALSE);
435 current_offset = updateField(lpcs->dwCompStrLen,
436 lpcs->dwCompStrOffset,
437 current_offset, newdata, olddata,
438 &new_one->dwCompStrLen,
439 &new_one->dwCompStrOffset, TRUE);
441 new_one->dwCursorPos = lpcs->dwCursorPos;
442 new_one->dwDeltaStart = 0;
444 current_offset = updateField(lpcs->dwResultReadClauseLen,
445 lpcs->dwResultReadClauseOffset,
446 current_offset, newdata, olddata,
447 &new_one->dwResultReadClauseLen,
448 &new_one->dwResultReadClauseOffset, FALSE);
450 current_offset = updateField(lpcs->dwResultReadStrLen,
451 lpcs->dwResultReadStrOffset,
452 current_offset, newdata, olddata,
453 &new_one->dwResultReadStrLen,
454 &new_one->dwResultReadStrOffset, TRUE);
456 /* new ResultClause , ResultStr */
458 current_offset = updateField(lpcs->dwPrivateSize,
459 lpcs->dwPrivateOffset,
460 current_offset, newdata, olddata,
461 &new_one->dwPrivateSize,
462 &new_one->dwPrivateOffset, FALSE);
469 new_one->dwResultClauseLen = sizeof(DWORD) * 2;
470 new_one->dwResultClauseOffset = current_offset;
471 *(DWORD*)(&newdata[current_offset]) = 0;
472 current_offset += sizeof(DWORD);
473 *(DWORD*)(&newdata[current_offset]) = len;
474 current_offset += sizeof(DWORD);
478 new_one->dwResultStrLen = len;
481 new_one->dwResultStrOffset = current_offset;
482 memcpy(&newdata[current_offset],resultstr,len*sizeof(WCHAR));
493 /***********************************************************************
494 * ImmAssociateContext (IMM32.@)
496 HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
498 InputContextData *data = (InputContextData*)hIMC;
500 WARN("(%p, %p): semi-stub\n", hWnd, hIMC);
506 * WINE SPECIFIC! MAY CONFLICT
507 * associate the root context we have an XIM created
511 root_context = (InputContextData*)hIMC;
515 * If already associated just return
517 if (data->IMC.hWnd == hWnd)
520 if (IsWindow(data->IMC.hWnd))
523 * Post a message that your context is switching
525 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
528 data->IMC.hWnd = hWnd;
530 if (IsWindow(data->IMC.hWnd))
533 * Post a message that your context is switching
535 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
539 * TODO: We need to keep track of the old context associated
540 * with a window and return it for now we will return NULL;
545 /***********************************************************************
546 * ImmAssociateContextEx (IMM32.@)
548 BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
550 FIXME("(%p, %p, %d): stub\n", hWnd, hIMC, dwFlags);
551 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
555 /***********************************************************************
556 * ImmConfigureIMEA (IMM32.@)
558 BOOL WINAPI ImmConfigureIMEA(
559 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
561 FIXME("(%p, %p, %d, %p): stub\n",
562 hKL, hWnd, dwMode, lpData
564 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
568 /***********************************************************************
569 * ImmConfigureIMEW (IMM32.@)
571 BOOL WINAPI ImmConfigureIMEW(
572 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
574 FIXME("(%p, %p, %d, %p): stub\n",
575 hKL, hWnd, dwMode, lpData
577 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
581 /***********************************************************************
582 * ImmCreateContext (IMM32.@)
584 HIMC WINAPI ImmCreateContext(void)
586 InputContextData *new_context;
588 new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
590 return (HIMC)new_context;
593 /***********************************************************************
594 * ImmDestroyContext (IMM32.@)
596 BOOL WINAPI ImmDestroyContext(HIMC hIMC)
598 InputContextData *data = (InputContextData*)hIMC;
600 TRACE("Destroying %p\n",hIMC);
604 ImmDestroyIMCC(root_context->IMC.hCompStr);
605 ImmDestroyIMCC(root_context->IMC.hCandInfo);
606 ImmDestroyIMCC(root_context->IMC.hGuideLine);
607 ImmDestroyIMCC(root_context->IMC.hPrivate);
608 ImmDestroyIMCC(root_context->IMC.hMsgBuf);
612 DeleteObject(data->textfont);
613 data->textfont = NULL;
616 HeapFree(GetProcessHeap(),0,data);
621 /***********************************************************************
622 * ImmDisableIME (IMM32.@)
624 BOOL WINAPI ImmDisableIME(DWORD idThread)
626 FIXME("(%d): stub\n", idThread);
630 /***********************************************************************
631 * ImmEnumRegisterWordA (IMM32.@)
633 UINT WINAPI ImmEnumRegisterWordA(
634 HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
635 LPCSTR lpszReading, DWORD dwStyle,
636 LPCSTR lpszRegister, LPVOID lpData)
638 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
640 debugstr_a(lpszReading), dwStyle,
641 debugstr_a(lpszRegister), lpData
643 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
647 /***********************************************************************
648 * ImmEnumRegisterWordW (IMM32.@)
650 UINT WINAPI ImmEnumRegisterWordW(
651 HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
652 LPCWSTR lpszReading, DWORD dwStyle,
653 LPCWSTR lpszRegister, LPVOID lpData)
655 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
657 debugstr_w(lpszReading), dwStyle,
658 debugstr_w(lpszRegister), lpData
660 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
664 /***********************************************************************
665 * ImmEscapeA (IMM32.@)
667 LRESULT WINAPI ImmEscapeA(
669 UINT uEscape, LPVOID lpData)
671 FIXME("(%p, %p, %d, %p): stub\n",
672 hKL, hIMC, uEscape, lpData
674 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
678 /***********************************************************************
679 * ImmEscapeW (IMM32.@)
681 LRESULT WINAPI ImmEscapeW(
683 UINT uEscape, LPVOID lpData)
685 FIXME("(%p, %p, %d, %p): stub\n",
686 hKL, hIMC, uEscape, lpData
688 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
692 /***********************************************************************
693 * ImmGetCandidateListA (IMM32.@)
695 DWORD WINAPI ImmGetCandidateListA(
696 HIMC hIMC, DWORD deIndex,
697 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
699 FIXME("(%p, %d, %p, %d): stub\n",
703 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
707 /***********************************************************************
708 * ImmGetCandidateListCountA (IMM32.@)
710 DWORD WINAPI ImmGetCandidateListCountA(
711 HIMC hIMC, LPDWORD lpdwListCount)
713 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
714 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
718 /***********************************************************************
719 * ImmGetCandidateListCountW (IMM32.@)
721 DWORD WINAPI ImmGetCandidateListCountW(
722 HIMC hIMC, LPDWORD lpdwListCount)
724 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
725 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
729 /***********************************************************************
730 * ImmGetCandidateListW (IMM32.@)
732 DWORD WINAPI ImmGetCandidateListW(
733 HIMC hIMC, DWORD deIndex,
734 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
736 FIXME("(%p, %d, %p, %d): stub\n",
740 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
744 /***********************************************************************
745 * ImmGetCandidateWindow (IMM32.@)
747 BOOL WINAPI ImmGetCandidateWindow(
748 HIMC hIMC, DWORD dwBufLen, LPCANDIDATEFORM lpCandidate)
750 FIXME("(%p, %d, %p): stub\n", hIMC, dwBufLen, lpCandidate);
751 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
755 /***********************************************************************
756 * ImmGetCompositionFontA (IMM32.@)
758 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
760 FIXME("(%p, %p): stub\n", hIMC, lplf);
761 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
765 /***********************************************************************
766 * ImmGetCompositionFontW (IMM32.@)
768 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
770 FIXME("(%p, %p): stub\n", hIMC, lplf);
771 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
775 /***********************************************************************
776 * ImmGetCompositionStringA (IMM32.@)
778 LONG WINAPI ImmGetCompositionStringA(
779 HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
783 InputContextData *data = (InputContextData*)hIMC;
784 LPCOMPOSITIONSTRING compstr;
787 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
792 if (!data->IMC.hCompStr)
795 compdata = ImmLockIMCC(data->IMC.hCompStr);
796 compstr = (LPCOMPOSITIONSTRING)compdata;
798 if (dwIndex == GCS_RESULTSTR && compstr->dwResultStrLen > 0 &&
799 compstr->dwResultStrOffset > 0)
801 LPWSTR ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
803 TRACE("GSC_RESULTSTR %p %i\n",ResultStr,
804 compstr->dwResultStrLen);
806 buf = HeapAlloc( GetProcessHeap(), 0, compstr->dwResultStrLen * 3 );
807 rc = WideCharToMultiByte(CP_ACP, 0, ResultStr,
808 compstr->dwResultStrLen , buf,
809 compstr->dwResultStrLen * 3, NULL, NULL);
811 memcpy(lpBuf,buf,rc);
814 HeapFree( GetProcessHeap(), 0, buf );
816 else if (dwIndex == GCS_COMPSTR && compstr->dwCompStrLen > 0 &&
817 compstr->dwCompStrOffset > 0)
819 LPWSTR CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
821 TRACE("GSC_COMPSTR %p %i\n", CompString, compstr->dwCompStrLen);
823 buf = HeapAlloc( GetProcessHeap(), 0, compstr->dwCompStrLen * 3 );
824 rc = WideCharToMultiByte(CP_ACP, 0, CompString,
825 compstr->dwCompStrLen, buf,
826 compstr->dwCompStrLen * 3, NULL, NULL);
828 memcpy(lpBuf,buf,rc);
829 HeapFree( GetProcessHeap(), 0, buf );
831 else if (dwIndex == GCS_COMPATTR && compstr->dwCompAttrLen > 0 &&
832 compstr->dwCompAttrOffset > 0)
834 LPWSTR Compattr = (LPWSTR)(compdata + compstr->dwCompAttrOffset);
835 TRACE("GSC_COMPATTR %p %i\n", Compattr , compstr->dwCompAttrLen);
837 rc = compstr->dwCompAttrLen;
839 memcpy(lpBuf,Compattr,rc);
841 else if (dwIndex == GCS_COMPCLAUSE && compstr->dwCompClauseLen > 0 &&
842 compstr->dwCompClauseOffset > 0)
844 LPWSTR Compclause = (LPWSTR)(compdata + compstr->dwCompClauseOffset);
845 TRACE("GSC_COMPCLAUSE %p %i\n", Compclause, compstr->dwCompClauseLen);
847 rc = compstr->dwCompClauseLen;
848 if (dwBufLen >= compstr->dwCompClauseLen)
849 memcpy(lpBuf,Compclause,rc);
851 else if (dwIndex == GCS_RESULTCLAUSE && compstr->dwResultClauseLen > 0 &&
852 compstr->dwResultClauseOffset > 0)
854 LPWSTR Resultclause = (LPWSTR)(compdata + compstr->dwResultClauseOffset);
855 TRACE("GSC_RESULTCLAUSE %p %i\n", Resultclause, compstr->dwResultClauseLen);
857 rc = compstr->dwResultClauseLen;
858 if (dwBufLen >= compstr->dwResultClauseLen)
859 memcpy(lpBuf,Resultclause,rc);
861 else if (dwIndex == GCS_CURSORPOS)
863 TRACE("GSC_CURSORPOS\n");
864 rc = compstr->dwCursorPos;
866 else if (dwIndex == GCS_DELTASTART)
868 TRACE("GCS_DELTASTART\n");
869 rc = compstr->dwDeltaStart;
873 FIXME("Unhandled index 0x%x\n",dwIndex);
876 ImmUnlockIMCC(data->IMC.hCompStr);
881 /***********************************************************************
882 * ImmGetCompositionStringW (IMM32.@)
884 LONG WINAPI ImmGetCompositionStringW(
885 HIMC hIMC, DWORD dwIndex,
886 LPVOID lpBuf, DWORD dwBufLen)
889 InputContextData *data = (InputContextData*)hIMC;
890 LPCOMPOSITIONSTRING compstr;
893 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
898 if (!data->IMC.hCompStr)
901 compdata = ImmLockIMCC(data->IMC.hCompStr);
902 compstr = (LPCOMPOSITIONSTRING)compdata;
904 if (dwIndex == GCS_RESULTSTR && compstr->dwResultStrLen > 0 &&
905 compstr->dwResultStrOffset > 0)
907 LPWSTR ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
909 rc = compstr->dwResultStrLen * sizeof(WCHAR);
912 memcpy(lpBuf,ResultStr,rc);
914 else if (dwIndex == GCS_RESULTREADSTR && compstr->dwResultReadStrLen > 0 &&
915 compstr->dwResultReadStrOffset > 0)
917 LPWSTR ResultReadString = (LPWSTR)(compdata + compstr->dwResultReadStrOffset);
919 rc = compstr->dwResultReadStrLen * sizeof(WCHAR);
921 memcpy(lpBuf,ResultReadString,rc);
923 else if (dwIndex == GCS_COMPSTR && compstr->dwCompStrLen > 0 &&
924 compstr->dwCompStrOffset > 0)
926 LPWSTR CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
927 rc = compstr->dwCompStrLen * sizeof(WCHAR);
929 memcpy(lpBuf,CompString,rc);
931 else if (dwIndex == GCS_COMPATTR && compstr->dwCompAttrLen > 0 &&
932 compstr->dwCompAttrOffset > 0)
935 LPWSTR Compattr = (LPWSTR)(compdata + compstr->dwCompAttrOffset);
937 rc = compstr->dwCompAttrLen;
939 memcpy(lpBuf,Compattr,rc);
941 else if (dwIndex == GCS_COMPCLAUSE && compstr->dwCompClauseLen > 0 &&
942 compstr->dwCompClauseOffset > 0)
944 LPWSTR Compclause = (LPWSTR)(compdata + compstr->dwCompClauseOffset);
946 rc = compstr->dwCompClauseLen;
947 if (dwBufLen >= compstr->dwCompClauseLen)
948 memcpy(lpBuf,Compclause,rc);
950 else if (dwIndex == GCS_COMPREADSTR && compstr->dwCompReadStrLen > 0 &&
951 compstr->dwCompReadStrOffset > 0)
953 LPWSTR CompReadString = (LPWSTR)(compdata + compstr->dwCompReadStrOffset);
955 rc = compstr->dwCompReadStrLen * sizeof(WCHAR);
958 memcpy(lpBuf,CompReadString,rc);
960 else if (dwIndex == GCS_CURSORPOS)
962 TRACE("GSC_CURSORPOS\n");
963 rc = compstr->dwCursorPos;
965 else if (dwIndex == GCS_DELTASTART)
967 TRACE("GCS_DELTASTART\n");
968 rc = compstr->dwDeltaStart;
972 FIXME("Unhandled index 0x%x\n",dwIndex);
975 ImmUnlockIMCC(data->IMC.hCompStr);
980 /***********************************************************************
981 * ImmGetCompositionWindow (IMM32.@)
983 BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
985 InputContextData *data = (InputContextData*)hIMC;
987 TRACE("(%p, %p)\n", hIMC, lpCompForm);
992 memcpy(lpCompForm,&(data->IMC.cfCompForm),sizeof(COMPOSITIONFORM));
996 /***********************************************************************
997 * ImmGetContext (IMM32.@)
1000 HIMC WINAPI ImmGetContext(HWND hWnd)
1002 TRACE("%p\n", hWnd);
1007 root_context->IMC.hWnd = hWnd;
1008 return (HIMC)root_context;
1011 /***********************************************************************
1012 * ImmGetConversionListA (IMM32.@)
1014 DWORD WINAPI ImmGetConversionListA(
1016 LPCSTR pSrc, LPCANDIDATELIST lpDst,
1017 DWORD dwBufLen, UINT uFlag)
1019 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
1020 hKL, hIMC, debugstr_a(pSrc), lpDst, dwBufLen, uFlag
1022 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1026 /***********************************************************************
1027 * ImmGetConversionListW (IMM32.@)
1029 DWORD WINAPI ImmGetConversionListW(
1031 LPCWSTR pSrc, LPCANDIDATELIST lpDst,
1032 DWORD dwBufLen, UINT uFlag)
1034 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
1035 hKL, hIMC, debugstr_w(pSrc), lpDst, dwBufLen, uFlag
1037 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1041 /***********************************************************************
1042 * ImmGetConversionStatus (IMM32.@)
1044 BOOL WINAPI ImmGetConversionStatus(
1045 HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
1047 TRACE("(%p, %p, %p): best guess\n", hIMC, lpfdwConversion, lpfdwSentence);
1048 if (lpfdwConversion)
1049 *lpfdwConversion = IME_CMODE_NATIVE;
1051 *lpfdwSentence = IME_SMODE_NONE;
1055 /***********************************************************************
1056 * ImmGetDefaultIMEWnd (IMM32.@)
1058 HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
1060 static int shown = 0;
1063 FIXME("(%p - %p %p ): semi-stub\n", hWnd,hwndDefault, root_context);
1067 if (hwndDefault == NULL)
1069 static const WCHAR the_name[] = {'I','M','E','\0'};
1072 hwndDefault = CreateWindowExW( WS_EX_TOOLWINDOW, WC_IMECLASSNAME,
1073 the_name, WS_POPUP, 0, 0, 1, 1, 0, 0,
1076 TRACE("Default created (%p)\n",hwndDefault);
1079 return (HWND)hwndDefault;
1082 /***********************************************************************
1083 * ImmGetDescriptionA (IMM32.@)
1085 UINT WINAPI ImmGetDescriptionA(
1086 HKL hKL, LPSTR lpszDescription, UINT uBufLen)
1091 TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
1093 /* find out how many characters in the unicode buffer */
1094 len = ImmGetDescriptionW( hKL, NULL, 0 );
1096 /* allocate a buffer of that size */
1097 buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
1101 /* fetch the unicode buffer */
1102 len = ImmGetDescriptionW( hKL, buf, len + 1 );
1104 /* convert it back to ASCII */
1105 len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
1106 lpszDescription, uBufLen, NULL, NULL );
1108 HeapFree( GetProcessHeap(), 0, buf );
1113 /***********************************************************************
1114 * ImmGetDescriptionW (IMM32.@)
1116 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
1118 static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
1120 FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
1122 if (!uBufLen) return lstrlenW( name );
1123 lstrcpynW( lpszDescription, name, uBufLen );
1124 return lstrlenW( lpszDescription );
1127 /***********************************************************************
1128 * ImmGetGuideLineA (IMM32.@)
1130 DWORD WINAPI ImmGetGuideLineA(
1131 HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
1133 FIXME("(%p, %d, %s, %d): stub\n",
1134 hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
1136 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1140 /***********************************************************************
1141 * ImmGetGuideLineW (IMM32.@)
1143 DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
1145 FIXME("(%p, %d, %s, %d): stub\n",
1146 hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
1148 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1152 /***********************************************************************
1153 * ImmGetIMEFileNameA (IMM32.@)
1155 UINT WINAPI ImmGetIMEFileNameA(
1156 HKL hKL, LPSTR lpszFileName, UINT uBufLen)
1158 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
1159 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1163 /***********************************************************************
1164 * ImmGetIMEFileNameW (IMM32.@)
1166 UINT WINAPI ImmGetIMEFileNameW(
1167 HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
1169 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
1170 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1174 /***********************************************************************
1175 * ImmGetOpenStatus (IMM32.@)
1177 BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
1179 InputContextData *data = (InputContextData*)hIMC;
1183 FIXME("(%p): semi-stub\n", hIMC);
1185 return data->IMC.fOpen;
1188 /***********************************************************************
1189 * ImmGetProperty (IMM32.@)
1191 DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
1194 TRACE("(%p, %d)\n", hKL, fdwIndex);
1199 TRACE("(%s)\n", "IGP_PROPERTY");
1200 rc = IME_PROP_UNICODE | IME_PROP_AT_CARET;
1202 case IGP_CONVERSION:
1203 FIXME("(%s)\n", "IGP_CONVERSION");
1204 rc = IME_CMODE_NATIVE;
1207 FIXME("%s)\n", "IGP_SENTENCE");
1208 rc = IME_SMODE_AUTOMATIC;
1210 case IGP_SETCOMPSTR:
1211 TRACE("(%s)\n", "IGP_SETCOMPSTR");
1215 TRACE("(%s)\n", "IGP_SELECT");
1216 rc = SELECT_CAP_CONVERSION | SELECT_CAP_SENTENCE;
1218 case IGP_GETIMEVERSION:
1219 TRACE("(%s)\n", "IGP_GETIMEVERSION");
1223 TRACE("(%s)\n", "IGP_UI");
1232 /***********************************************************************
1233 * ImmGetRegisterWordStyleA (IMM32.@)
1235 UINT WINAPI ImmGetRegisterWordStyleA(
1236 HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
1238 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
1239 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1243 /***********************************************************************
1244 * ImmGetRegisterWordStyleW (IMM32.@)
1246 UINT WINAPI ImmGetRegisterWordStyleW(
1247 HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
1249 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
1250 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1254 /***********************************************************************
1255 * ImmGetStatusWindowPos (IMM32.@)
1257 BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1259 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
1260 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1264 /***********************************************************************
1265 * ImmGetVirtualKey (IMM32.@)
1267 UINT WINAPI ImmGetVirtualKey(HWND hWnd)
1269 OSVERSIONINFOA version;
1270 FIXME("(%p): stub\n", hWnd);
1271 GetVersionExA( &version );
1272 switch(version.dwPlatformId)
1274 case VER_PLATFORM_WIN32_WINDOWS:
1275 return VK_PROCESSKEY;
1276 case VER_PLATFORM_WIN32_NT:
1279 FIXME("%d not supported\n",version.dwPlatformId);
1280 return VK_PROCESSKEY;
1284 /***********************************************************************
1285 * ImmInstallIMEA (IMM32.@)
1287 HKL WINAPI ImmInstallIMEA(
1288 LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
1290 FIXME("(%s, %s): stub\n",
1291 debugstr_a(lpszIMEFileName), debugstr_a(lpszLayoutText)
1293 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1297 /***********************************************************************
1298 * ImmInstallIMEW (IMM32.@)
1300 HKL WINAPI ImmInstallIMEW(
1301 LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
1303 FIXME("(%s, %s): stub\n",
1304 debugstr_w(lpszIMEFileName), debugstr_w(lpszLayoutText)
1306 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1310 /***********************************************************************
1311 * ImmIsIME (IMM32.@)
1313 BOOL WINAPI ImmIsIME(HKL hKL)
1315 TRACE("(%p): semi-stub\n", hKL);
1317 * FIXME: Dead key locales will return TRUE here when they should not
1318 * There is probably a more proper way to check this.
1320 return (root_context != NULL);
1323 /***********************************************************************
1324 * ImmIsUIMessageA (IMM32.@)
1326 BOOL WINAPI ImmIsUIMessageA(
1327 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1331 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1332 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1333 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1334 (msg == WM_MSIME_SERVICE) ||
1335 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1336 (msg == WM_MSIME_MOUSE) ||
1337 (msg == WM_MSIME_RECONVERTREQUEST) ||
1338 (msg == WM_MSIME_RECONVERT) ||
1339 (msg == WM_MSIME_QUERYPOSITION) ||
1340 (msg == WM_MSIME_DOCUMENTFEED))
1344 ImmGetDefaultIMEWnd(NULL);
1346 if (hWndIME == NULL)
1347 PostMessageA(hwndDefault, msg, wParam, lParam);
1354 /***********************************************************************
1355 * ImmIsUIMessageW (IMM32.@)
1357 BOOL WINAPI ImmIsUIMessageW(
1358 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1361 TRACE("(%p, %d, %ld, %ld): stub\n", hWndIME, msg, wParam, lParam);
1362 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1363 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1364 (msg == WM_MSIME_SERVICE) ||
1365 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1366 (msg == WM_MSIME_MOUSE) ||
1367 (msg == WM_MSIME_RECONVERTREQUEST) ||
1368 (msg == WM_MSIME_RECONVERT) ||
1369 (msg == WM_MSIME_QUERYPOSITION) ||
1370 (msg == WM_MSIME_DOCUMENTFEED))
1375 /***********************************************************************
1376 * ImmNotifyIME (IMM32.@)
1378 BOOL WINAPI ImmNotifyIME(
1379 HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
1383 TRACE("(%p, %d, %d, %d)\n",
1384 hIMC, dwAction, dwIndex, dwValue);
1391 case NI_CHANGECANDIDATELIST:
1392 FIXME("%s\n","NI_CHANGECANDIDATELIST");
1394 case NI_CLOSECANDIDATE:
1395 FIXME("%s\n","NI_CLOSECANDIDATE");
1397 case NI_COMPOSITIONSTR:
1401 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL");
1404 if (pX11DRV_ForceXIMReset)
1405 pX11DRV_ForceXIMReset(root_context->IMC.hWnd);
1407 newCompStr = updateCompStr(root_context->IMC.hCompStr, NULL, 0);
1408 ImmDestroyIMCC(root_context->IMC.hCompStr);
1409 root_context->IMC.hCompStr = newCompStr;
1411 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1417 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_COMPLETE");
1418 if (hIMC != (HIMC)FROM_IME && pX11DRV_ForceXIMReset)
1419 pX11DRV_ForceXIMReset(root_context->IMC.hWnd);
1424 LPCOMPOSITIONSTRING cs = NULL;
1425 LPBYTE cdata = NULL;
1427 /* clear existing result */
1428 newCompStr = updateResultStr(root_context->IMC.hCompStr, NULL, 0);
1429 ImmDestroyIMCC(root_context->IMC.hCompStr);
1430 root_context->IMC.hCompStr = newCompStr;
1432 cdata = ImmLockIMCC(root_context->IMC.hCompStr);
1433 cs = (LPCOMPOSITIONSTRING)cdata;
1434 cplen = cs->dwCompStrLen;
1435 cpstr = (LPWSTR)&(cdata[cs->dwCompStrOffset]);
1436 ImmUnlockIMCC(root_context->IMC.hCompStr);
1439 WCHAR param = cpstr[0];
1440 newCompStr = updateResultStr(root_context->IMC.hCompStr, cpstr, cplen);
1441 ImmDestroyIMCC(root_context->IMC.hCompStr);
1442 root_context->IMC.hCompStr = newCompStr;
1443 newCompStr = updateCompStr(root_context->IMC.hCompStr, NULL, 0);
1444 ImmDestroyIMCC(root_context->IMC.hCompStr);
1445 root_context->IMC.hCompStr = newCompStr;
1447 root_context->bRead = FALSE;
1449 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1452 ImmInternalPostIMEMessage(WM_IME_COMPOSITION,
1454 GCS_RESULTSTR|GCS_RESULTCLAUSE);
1457 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION, 0, 0);
1458 root_context->bInComposition = FALSE;
1462 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_CONVERT");
1465 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_REVERT");
1468 ERR("%s - %s (%i)\n","NI_COMPOSITIONSTR","UNKNOWN",dwIndex);
1472 case NI_IMEMENUSELECTED:
1473 FIXME("%s\n", "NI_IMEMENUSELECTED");
1475 case NI_OPENCANDIDATE:
1476 FIXME("%s\n", "NI_OPENCANDIDATE");
1478 case NI_SELECTCANDIDATESTR:
1479 FIXME("%s\n", "NI_SELECTCANDIDATESTR");
1481 case NI_SETCANDIDATE_PAGESIZE:
1482 FIXME("%s\n", "NI_SETCANDIDATE_PAGESIZE");
1484 case NI_SETCANDIDATE_PAGESTART:
1485 FIXME("%s\n", "NI_SETCANDIDATE_PAGESTART");
1494 /***********************************************************************
1495 * ImmRegisterWordA (IMM32.@)
1497 BOOL WINAPI ImmRegisterWordA(
1498 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
1500 FIXME("(%p, %s, %d, %s): stub\n",
1501 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister)
1503 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1507 /***********************************************************************
1508 * ImmRegisterWordW (IMM32.@)
1510 BOOL WINAPI ImmRegisterWordW(
1511 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
1513 FIXME("(%p, %s, %d, %s): stub\n",
1514 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister)
1516 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1520 /***********************************************************************
1521 * ImmReleaseContext (IMM32.@)
1523 BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
1525 static int shown = 0;
1528 FIXME("(%p, %p): stub\n", hWnd, hIMC);
1534 /***********************************************************************
1535 * ImmSetCandidateWindow (IMM32.@)
1537 BOOL WINAPI ImmSetCandidateWindow(
1538 HIMC hIMC, LPCANDIDATEFORM lpCandidate)
1540 FIXME("(%p, %p): stub\n", hIMC, lpCandidate);
1541 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1545 /***********************************************************************
1546 * ImmSetCompositionFontA (IMM32.@)
1548 BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
1550 InputContextData *data = (InputContextData*)hIMC;
1551 TRACE("(%p, %p)\n", hIMC, lplf);
1556 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTA));
1557 MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->IMC.lfFont.W.lfFaceName,
1560 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1564 DeleteObject(data->textfont);
1565 data->textfont = NULL;
1568 data->textfont = CreateFontIndirectW(&data->IMC.lfFont.W);
1572 /***********************************************************************
1573 * ImmSetCompositionFontW (IMM32.@)
1575 BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
1577 InputContextData *data = (InputContextData*)hIMC;
1578 TRACE("(%p, %p)\n", hIMC, lplf);
1583 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTW));
1584 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1588 DeleteObject(data->textfont);
1589 data->textfont = NULL;
1591 data->textfont = CreateFontIndirectW(&data->IMC.lfFont.W);
1595 /***********************************************************************
1596 * ImmSetCompositionStringA (IMM32.@)
1598 BOOL WINAPI ImmSetCompositionStringA(
1599 HIMC hIMC, DWORD dwIndex,
1600 LPCVOID lpComp, DWORD dwCompLen,
1601 LPCVOID lpRead, DWORD dwReadLen)
1605 WCHAR *CompBuffer = NULL;
1606 WCHAR *ReadBuffer = NULL;
1609 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1610 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1612 comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
1615 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
1616 MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
1619 read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
1622 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
1623 MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
1626 rc = ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
1627 ReadBuffer, read_len);
1629 HeapFree(GetProcessHeap(), 0, CompBuffer);
1630 HeapFree(GetProcessHeap(), 0, ReadBuffer);
1635 /***********************************************************************
1636 * ImmSetCompositionStringW (IMM32.@)
1638 BOOL WINAPI ImmSetCompositionStringW(
1639 HIMC hIMC, DWORD dwIndex,
1640 LPCVOID lpComp, DWORD dwCompLen,
1641 LPCVOID lpRead, DWORD dwReadLen)
1646 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1647 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1650 if (hIMC != (HIMC)FROM_IME)
1651 FIXME("PROBLEM: This only sets the wine level string\n");
1655 * this sets the composition string in the imm32.dll level
1656 * of the composition buffer. we cannot manipulate the xim level
1657 * buffer, which means that once the xim level buffer changes again
1658 * any call to this function from the application will be lost
1661 if (lpRead && dwReadLen)
1662 FIXME("Reading string unimplemented\n");
1665 * app operating this api to also receive the message from xim
1668 if (dwIndex == SCS_SETSTR)
1671 if (!root_context->bInComposition)
1673 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION, 0, 0);
1674 root_context->bInComposition = TRUE;
1677 flags = GCS_COMPSTR;
1679 if (dwCompLen && lpComp)
1681 newCompStr = updateCompStr(root_context->IMC.hCompStr, (LPWSTR)lpComp, dwCompLen / sizeof(WCHAR));
1682 ImmDestroyIMCC(root_context->IMC.hCompStr);
1683 root_context->IMC.hCompStr = newCompStr;
1685 wParam = ((const WCHAR*)lpComp)[0];
1686 flags |= GCS_COMPCLAUSE | GCS_COMPATTR | GCS_DELTASTART;
1690 newCompStr = updateCompStr(root_context->IMC.hCompStr, NULL, 0);
1691 ImmDestroyIMCC(root_context->IMC.hCompStr);
1692 root_context->IMC.hCompStr = newCompStr;
1696 UpdateDataInDefaultIMEWindow(hwndDefault,FALSE);
1698 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, wParam, flags);
1703 /***********************************************************************
1704 * ImmSetCompositionWindow (IMM32.@)
1706 BOOL WINAPI ImmSetCompositionWindow(
1707 HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
1709 BOOL reshow = FALSE;
1710 InputContextData *data = (InputContextData*)hIMC;
1712 TRACE("(%p, %p)\n", hIMC, lpCompForm);
1713 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm->dwStyle,
1714 lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
1715 lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);
1720 memcpy(&data->IMC.cfCompForm,lpCompForm,sizeof(COMPOSITIONFORM));
1722 if (IsWindowVisible(hwndDefault))
1725 ShowWindow(hwndDefault,SW_HIDE);
1728 /* FIXME: this is a partial stub */
1731 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
1733 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONWINDOW, 0);
1737 /***********************************************************************
1738 * ImmSetConversionStatus (IMM32.@)
1740 BOOL WINAPI ImmSetConversionStatus(
1741 HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
1743 static int shown = 0;
1746 FIXME("(%p, %d, %d): stub\n",
1747 hIMC, fdwConversion, fdwSentence
1751 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1755 /***********************************************************************
1756 * ImmSetOpenStatus (IMM32.@)
1758 BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
1760 InputContextData *data = (InputContextData*)hIMC;
1762 TRACE("%p %d\n", hIMC, fOpen);
1764 if (hIMC == (HIMC)FROM_IME)
1766 ImmInternalSetOpenStatus(fOpen);
1767 ImmInternalSendIMENotify(IMN_SETOPENSTATUS, 0);
1774 if (fOpen != data->bInternalState)
1776 if (fOpen == FALSE && pX11DRV_ForceXIMReset)
1777 pX11DRV_ForceXIMReset(data->IMC.hWnd);
1780 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1782 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1784 ImmInternalSetOpenStatus(fOpen);
1785 ImmInternalSetOpenStatus(!fOpen);
1787 if (data->IMC.fOpen == FALSE)
1788 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1790 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1797 /***********************************************************************
1798 * ImmSetStatusWindowPos (IMM32.@)
1800 BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1802 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
1803 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1807 /***********************************************************************
1808 * ImmSimulateHotKey (IMM32.@)
1810 BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
1812 FIXME("(%p, %d): stub\n", hWnd, dwHotKeyID);
1813 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1817 /***********************************************************************
1818 * ImmUnregisterWordA (IMM32.@)
1820 BOOL WINAPI ImmUnregisterWordA(
1821 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
1823 FIXME("(%p, %s, %d, %s): stub\n",
1824 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszUnregister)
1826 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1830 /***********************************************************************
1831 * ImmUnregisterWordW (IMM32.@)
1833 BOOL WINAPI ImmUnregisterWordW(
1834 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
1836 FIXME("(%p, %s, %d, %s): stub\n",
1837 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszUnregister)
1839 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1843 /***********************************************************************
1844 * ImmGetImeMenuItemsA (IMM32.@)
1846 DWORD WINAPI ImmGetImeMenuItemsA( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1847 LPIMEMENUITEMINFOA lpImeParentMenu, LPIMEMENUITEMINFOA lpImeMenu,
1850 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1851 lpImeParentMenu, lpImeMenu, dwSize);
1855 /***********************************************************************
1856 * ImmGetImeMenuItemsW (IMM32.@)
1858 DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1859 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
1862 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1863 lpImeParentMenu, lpImeMenu, dwSize);
1867 /***********************************************************************
1868 * ImmLockIMC(IMM32.@)
1870 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
1872 InputContextData *data = (InputContextData*)hIMC;
1880 /***********************************************************************
1881 * ImmUnlockIMC(IMM32.@)
1883 BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
1885 InputContextData *data = (InputContextData*)hIMC;
1887 return (data->dwLock!=0);
1890 /***********************************************************************
1891 * ImmGetIMCLockCount(IMM32.@)
1893 DWORD WINAPI ImmGetIMCLockCount(HIMC hIMC)
1895 InputContextData *data = (InputContextData*)hIMC;
1896 return data->dwLock;
1899 /***********************************************************************
1900 * ImmCreateIMCC(IMM32.@)
1902 HIMCC WINAPI ImmCreateIMCC(DWORD size)
1904 IMCCInternal *internal;
1905 int real_size = size + sizeof(IMCCInternal);
1907 internal = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, real_size);
1908 if (internal == NULL)
1911 internal->dwSize = size;
1912 return (HIMCC)internal;
1915 /***********************************************************************
1916 * ImmDestroyIMCC(IMM32.@)
1918 HIMCC WINAPI ImmDestroyIMCC(HIMCC block)
1920 HeapFree(GetProcessHeap(),0,block);
1924 /***********************************************************************
1925 * ImmLockIMCC(IMM32.@)
1927 LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
1929 IMCCInternal *internal;
1930 internal = (IMCCInternal*) imcc;
1932 internal->dwLock ++;
1933 return internal + 1;
1936 /***********************************************************************
1937 * ImmUnlockIMCC(IMM32.@)
1939 BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
1941 IMCCInternal *internal;
1942 internal = (IMCCInternal*) imcc;
1944 internal->dwLock --;
1945 return (internal->dwLock!=0);
1948 /***********************************************************************
1949 * ImmGetIMCCLockCount(IMM32.@)
1951 DWORD WINAPI ImmGetIMCCLockCount(HIMCC imcc)
1953 IMCCInternal *internal;
1954 internal = (IMCCInternal*) imcc;
1956 return internal->dwLock;
1959 /***********************************************************************
1960 * ImmReSizeIMCC(IMM32.@)
1962 HIMCC WINAPI ImmReSizeIMCC(HIMCC imcc, DWORD size)
1964 IMCCInternal *internal,*newone;
1965 int real_size = size + sizeof(IMCCInternal);
1967 internal = (IMCCInternal*) imcc;
1969 newone = HeapReAlloc(GetProcessHeap(), 0, internal, real_size);
1970 newone->dwSize = size;
1975 /***********************************************************************
1976 * ImmGetIMCCSize(IMM32.@)
1978 DWORD WINAPI ImmGetIMCCSize(HIMCC imcc)
1980 IMCCInternal *internal;
1981 internal = (IMCCInternal*) imcc;
1983 return internal->dwSize;
1987 * Internal functions to help with IME window management
1989 static void PaintDefaultIMEWnd(HWND hwnd)
1993 HDC hdc = BeginPaint(hwnd,&ps);
1994 LPCOMPOSITIONSTRING compstr;
1995 LPBYTE compdata = NULL;
1997 MONITORINFO mon_info;
2000 GetClientRect(hwnd,&rect);
2001 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
2003 compdata = ImmLockIMCC(root_context->IMC.hCompStr);
2004 compstr = (LPCOMPOSITIONSTRING)compdata;
2006 if (compstr->dwCompStrLen && compstr->dwCompStrOffset)
2010 HFONT oldfont = NULL;
2013 CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
2014 if (root_context->textfont)
2015 oldfont = SelectObject(hdc,root_context->textfont);
2018 GetTextExtentPoint32W(hdc, CompString, compstr->dwCompStrLen, &size);
2024 * How this works based on tests on windows:
2025 * CFS_POINT: then we start our window at the point and grow it as large
2026 * as it needs to be for the string.
2027 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
2028 * window is only as large as we need for the string, but we do not
2029 * grow such that our window exceeds the given rect. Wrapping if
2030 * needed and possible. If our ptCurrentPos is outside of our rect
2031 * then no window is displayed.
2032 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
2033 * maybe becase the default MSIME does not do any IME adjusting.
2035 if (root_context->IMC.cfCompForm.dwStyle != CFS_DEFAULT)
2037 POINT cpt = root_context->IMC.cfCompForm.ptCurrentPos;
2038 ClientToScreen(root_context->IMC.hWnd,&cpt);
2041 rect.right = rect.left + pt.x;
2042 rect.bottom = rect.top + pt.y;
2044 monitor = MonitorFromPoint(cpt, MONITOR_DEFAULTTOPRIMARY);
2046 else /* CFS_DEFAULT */
2048 /* Windows places the default IME window in the bottom left */
2049 HWND target = root_context->IMC.hWnd;
2050 if (!target) target = GetFocus();
2052 GetWindowRect(target,&rect);
2053 rect.top = rect.bottom;
2054 rect.right = rect.left + pt.x + 20;
2055 rect.bottom = rect.top + pt.y + 20;
2057 monitor = MonitorFromWindow(target, MONITOR_DEFAULTTOPRIMARY);
2060 if (root_context->IMC.cfCompForm.dwStyle == CFS_RECT)
2063 client =root_context->IMC.cfCompForm.rcArea;
2064 MapWindowPoints( root_context->IMC.hWnd, 0, (POINT *)&client, 2 );
2065 IntersectRect(&rect,&rect,&client);
2066 /* TODO: Wrap the input if needed */
2069 if (root_context->IMC.cfCompForm.dwStyle == CFS_DEFAULT)
2071 /* make sure we are on the desktop */
2072 mon_info.cbSize = sizeof(mon_info);
2073 GetMonitorInfoW(monitor, &mon_info);
2075 if (rect.bottom > mon_info.rcWork.bottom)
2077 int shift = rect.bottom - mon_info.rcWork.bottom;
2079 rect.bottom -= shift;
2083 rect.right -= rect.left;
2086 if (rect.right > mon_info.rcWork.right)
2088 int shift = rect.right - mon_info.rcWork.right;
2090 rect.right -= shift;
2094 SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
2096 TextOutW(hdc, offX,offY, CompString, compstr->dwCompStrLen);
2099 SelectObject(hdc,oldfont);
2102 ImmUnlockIMCC(root_context->IMC.hCompStr);
2107 static void UpdateDataInDefaultIMEWindow(HWND hwnd, BOOL showable)
2109 LPCOMPOSITIONSTRING compstr;
2111 if (root_context->IMC.hCompStr)
2112 compstr = ImmLockIMCC(root_context->IMC.hCompStr);
2116 if (compstr == NULL || compstr->dwCompStrLen == 0)
2117 ShowWindow(hwndDefault,SW_HIDE);
2119 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
2121 RedrawWindow(hwnd,NULL,NULL,RDW_ERASENOW|RDW_INVALIDATE);
2123 if (compstr != NULL)
2124 ImmUnlockIMCC(root_context->IMC.hCompStr);
2128 * The window proc for the default IME window
2130 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
2135 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", msg, (UINT)wParam,
2141 PaintDefaultIMEWnd(hwnd);
2148 SetWindowTextA(hwnd,"Wine Ime Active");
2153 SetFocus((HWND)wParam);
2155 FIXME("Received focus, should never have focus\n");
2157 case WM_IME_COMPOSITION:
2158 TRACE("IME message %s, 0x%x, 0x%x (%i)\n",
2159 "WM_IME_COMPOSITION", (UINT)wParam, (UINT)lParam,
2160 root_context->bRead);
2161 if (lParam & GCS_RESULTSTR)
2162 IMM_PostResult(root_context);
2164 UpdateDataInDefaultIMEWindow(hwnd,TRUE);
2166 case WM_IME_STARTCOMPOSITION:
2167 TRACE("IME message %s, 0x%x, 0x%x\n",
2168 "WM_IME_STARTCOMPOSITION", (UINT)wParam, (UINT)lParam);
2169 root_context->IMC.hWnd = GetFocus();
2170 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
2172 case WM_IME_ENDCOMPOSITION:
2173 TRACE("IME message %s, 0x%x, 0x%x\n",
2174 "WM_IME_ENDCOMPOSITION", (UINT)wParam, (UINT)lParam);
2175 ShowWindow(hwndDefault,SW_HIDE);
2178 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_SELECT",
2179 (UINT)wParam, (UINT)lParam);
2181 case WM_IME_CONTROL:
2182 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_CONTROL",
2183 (UINT)wParam, (UINT)lParam);
2187 TRACE("!! IME NOTIFY\n");
2190 TRACE("Non-standard message 0x%x\n",msg);
2192 /* check the MSIME messages */
2193 if (msg == WM_MSIME_SERVICE)
2195 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_SERVICE",
2196 (UINT)wParam, (UINT)lParam);
2199 else if (msg == WM_MSIME_RECONVERTOPTIONS)
2201 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTOPTIONS",
2202 (UINT)wParam, (UINT)lParam);
2204 else if (msg == WM_MSIME_MOUSE)
2206 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_MOUSE",
2207 (UINT)wParam, (UINT)lParam);
2209 else if (msg == WM_MSIME_RECONVERTREQUEST)
2211 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTREQUEST",
2212 (UINT)wParam, (UINT)lParam);
2214 else if (msg == WM_MSIME_RECONVERT)
2216 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERT",
2217 (UINT)wParam, (UINT)lParam);
2219 else if (msg == WM_MSIME_QUERYPOSITION)
2221 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_QUERYPOSITION",
2222 (UINT)wParam, (UINT)lParam);
2224 else if (msg == WM_MSIME_DOCUMENTFEED)
2226 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_DOCUMENTFEED",
2227 (UINT)wParam, (UINT)lParam);
2229 /* DefWndProc if not an IME message */
2230 else if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
2231 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
2232 rc = DefWindowProcW(hwnd,msg,wParam,lParam);