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);
243 if (old == NULL && compstr == NULL && len == 0)
248 olddata = ImmLockIMCC(old);
249 lpcs = (LPCOMPOSITIONSTRING)olddata;
252 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
253 len + sizeof(DWORD) * 2;
257 needed_size += lpcs->dwCompReadAttrLen;
258 needed_size += lpcs->dwCompReadClauseLen;
259 needed_size += lpcs->dwCompReadStrLen * sizeof(DWORD);
260 needed_size += lpcs->dwResultReadClauseLen;
261 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
262 needed_size += lpcs->dwResultClauseLen;
263 needed_size += lpcs->dwResultStrLen * sizeof(DWORD);
264 needed_size += lpcs->dwPrivateSize;
266 rc = ImmCreateIMCC(needed_size);
267 newdata = ImmLockIMCC(rc);
268 new_one = (LPCOMPOSITIONSTRING)newdata;
270 new_one->dwSize = needed_size;
271 current_offset = sizeof(COMPOSITIONSTRING);
274 current_offset = updateField(lpcs->dwCompReadAttrLen,
275 lpcs->dwCompReadAttrOffset,
276 current_offset, newdata, olddata,
277 &new_one->dwCompReadAttrLen,
278 &new_one->dwCompReadAttrOffset, FALSE);
280 current_offset = updateField(lpcs->dwCompReadClauseLen,
281 lpcs->dwCompReadClauseOffset,
282 current_offset, newdata, olddata,
283 &new_one->dwCompReadClauseLen,
284 &new_one->dwCompReadClauseOffset, FALSE);
286 current_offset = updateField(lpcs->dwCompReadStrLen,
287 lpcs->dwCompReadStrOffset,
288 current_offset, newdata, olddata,
289 &new_one->dwCompReadStrLen,
290 &new_one->dwCompReadStrOffset, TRUE);
292 /* new CompAttr, CompClause, CompStr, dwCursorPos */
293 new_one->dwDeltaStart = 0;
295 current_offset = updateField(lpcs->dwResultReadClauseLen,
296 lpcs->dwResultReadClauseOffset,
297 current_offset, newdata, olddata,
298 &new_one->dwResultReadClauseLen,
299 &new_one->dwResultReadClauseOffset, FALSE);
301 current_offset = updateField(lpcs->dwResultReadStrLen,
302 lpcs->dwResultReadStrOffset,
303 current_offset, newdata, olddata,
304 &new_one->dwResultReadStrLen,
305 &new_one->dwResultReadStrOffset, TRUE);
307 current_offset = updateField(lpcs->dwResultClauseLen,
308 lpcs->dwResultClauseOffset,
309 current_offset, newdata, olddata,
310 &new_one->dwResultClauseLen,
311 &new_one->dwResultClauseOffset, FALSE);
313 current_offset = updateField(lpcs->dwResultStrLen,
314 lpcs->dwResultStrOffset,
315 current_offset, newdata, olddata,
316 &new_one->dwResultStrLen,
317 &new_one->dwResultStrOffset, TRUE);
319 current_offset = updateField(lpcs->dwPrivateSize,
320 lpcs->dwPrivateOffset,
321 current_offset, newdata, olddata,
322 &new_one->dwPrivateSize,
323 &new_one->dwPrivateOffset, FALSE);
328 new_one->dwCompAttrLen = len;
331 new_one->dwCompAttrOffset = current_offset;
332 memset(&newdata[current_offset],ATTR_INPUT,len);
333 current_offset += len;
339 new_one->dwCompClauseLen = sizeof(DWORD) * 2;
340 new_one->dwCompClauseOffset = current_offset;
341 *(DWORD*)(&newdata[current_offset]) = 0;
342 current_offset += sizeof(DWORD);
343 *(DWORD*)(&newdata[current_offset]) = len;
344 current_offset += sizeof(DWORD);
348 new_one->dwCompStrLen = len;
351 new_one->dwCompStrOffset = current_offset;
352 memcpy(&newdata[current_offset],compstr,len*sizeof(WCHAR));
356 new_one->dwCursorPos = len;
365 static HIMCC updateResultStr(HIMCC old, LPWSTR resultstr, DWORD len)
367 /* we need to make sure the ResultStr and ResultClause fields are all
371 LPBYTE newdata = NULL;
372 LPBYTE olddata = NULL;
373 LPCOMPOSITIONSTRING new_one;
374 LPCOMPOSITIONSTRING lpcs = NULL;
375 INT current_offset = 0;
377 TRACE("%s, %i\n",debugstr_wn(resultstr,len),len);
379 if (old == NULL && resultstr == NULL && len == 0)
384 olddata = ImmLockIMCC(old);
385 lpcs = (LPCOMPOSITIONSTRING)olddata;
388 needed_size = sizeof(COMPOSITIONSTRING) + len * sizeof(WCHAR) +
393 needed_size += lpcs->dwCompReadAttrLen;
394 needed_size += lpcs->dwCompReadClauseLen;
395 needed_size += lpcs->dwCompReadStrLen * sizeof(DWORD);
396 needed_size += lpcs->dwCompAttrLen;
397 needed_size += lpcs->dwCompClauseLen;
398 needed_size += lpcs->dwCompStrLen * sizeof(DWORD);
399 needed_size += lpcs->dwResultReadClauseLen;
400 needed_size += lpcs->dwResultReadStrLen * sizeof(DWORD);
401 needed_size += lpcs->dwPrivateSize;
403 rc = ImmCreateIMCC(needed_size);
404 newdata = ImmLockIMCC(rc);
405 new_one = (LPCOMPOSITIONSTRING)newdata;
407 new_one->dwSize = needed_size;
408 current_offset = sizeof(COMPOSITIONSTRING);
411 current_offset = updateField(lpcs->dwCompReadAttrLen,
412 lpcs->dwCompReadAttrOffset,
413 current_offset, newdata, olddata,
414 &new_one->dwCompReadAttrLen,
415 &new_one->dwCompReadAttrOffset, FALSE);
417 current_offset = updateField(lpcs->dwCompReadClauseLen,
418 lpcs->dwCompReadClauseOffset,
419 current_offset, newdata, olddata,
420 &new_one->dwCompReadClauseLen,
421 &new_one->dwCompReadClauseOffset, FALSE);
423 current_offset = updateField(lpcs->dwCompReadStrLen,
424 lpcs->dwCompReadStrOffset,
425 current_offset, newdata, olddata,
426 &new_one->dwCompReadStrLen,
427 &new_one->dwCompReadStrOffset, TRUE);
429 current_offset = updateField(lpcs->dwCompAttrLen,
430 lpcs->dwCompAttrOffset,
431 current_offset, newdata, olddata,
432 &new_one->dwCompAttrLen,
433 &new_one->dwCompAttrOffset, FALSE);
435 current_offset = updateField(lpcs->dwCompClauseLen,
436 lpcs->dwCompClauseOffset,
437 current_offset, newdata, olddata,
438 &new_one->dwCompClauseLen,
439 &new_one->dwCompClauseOffset, FALSE);
441 current_offset = updateField(lpcs->dwCompStrLen,
442 lpcs->dwCompStrOffset,
443 current_offset, newdata, olddata,
444 &new_one->dwCompStrLen,
445 &new_one->dwCompStrOffset, TRUE);
447 new_one->dwCursorPos = lpcs->dwCursorPos;
448 new_one->dwDeltaStart = 0;
450 current_offset = updateField(lpcs->dwResultReadClauseLen,
451 lpcs->dwResultReadClauseOffset,
452 current_offset, newdata, olddata,
453 &new_one->dwResultReadClauseLen,
454 &new_one->dwResultReadClauseOffset, FALSE);
456 current_offset = updateField(lpcs->dwResultReadStrLen,
457 lpcs->dwResultReadStrOffset,
458 current_offset, newdata, olddata,
459 &new_one->dwResultReadStrLen,
460 &new_one->dwResultReadStrOffset, TRUE);
462 /* new ResultClause , ResultStr */
464 current_offset = updateField(lpcs->dwPrivateSize,
465 lpcs->dwPrivateOffset,
466 current_offset, newdata, olddata,
467 &new_one->dwPrivateSize,
468 &new_one->dwPrivateOffset, FALSE);
475 new_one->dwResultClauseLen = sizeof(DWORD) * 2;
476 new_one->dwResultClauseOffset = current_offset;
477 *(DWORD*)(&newdata[current_offset]) = 0;
478 current_offset += sizeof(DWORD);
479 *(DWORD*)(&newdata[current_offset]) = len;
480 current_offset += sizeof(DWORD);
484 new_one->dwResultStrLen = len;
487 new_one->dwResultStrOffset = current_offset;
488 memcpy(&newdata[current_offset],resultstr,len*sizeof(WCHAR));
499 /***********************************************************************
500 * ImmAssociateContext (IMM32.@)
502 HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
504 InputContextData *data = (InputContextData*)hIMC;
506 WARN("(%p, %p): semi-stub\n", hWnd, hIMC);
512 * WINE SPECIFIC! MAY CONFLICT
513 * associate the root context we have an XIM created
517 root_context = (InputContextData*)hIMC;
521 * If already associated just return
523 if (data->IMC.hWnd == hWnd)
526 if (IsWindow(data->IMC.hWnd))
529 * Post a message that your context is switching
531 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
534 data->IMC.hWnd = hWnd;
536 if (IsWindow(data->IMC.hWnd))
539 * Post a message that your context is switching
541 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
545 * TODO: We need to keep track of the old context associated
546 * with a window and return it for now we will return NULL;
551 /***********************************************************************
552 * ImmAssociateContextEx (IMM32.@)
554 BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
556 FIXME("(%p, %p, %d): stub\n", hWnd, hIMC, dwFlags);
557 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
561 /***********************************************************************
562 * ImmConfigureIMEA (IMM32.@)
564 BOOL WINAPI ImmConfigureIMEA(
565 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
567 FIXME("(%p, %p, %d, %p): stub\n",
568 hKL, hWnd, dwMode, lpData
570 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
574 /***********************************************************************
575 * ImmConfigureIMEW (IMM32.@)
577 BOOL WINAPI ImmConfigureIMEW(
578 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
580 FIXME("(%p, %p, %d, %p): stub\n",
581 hKL, hWnd, dwMode, lpData
583 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
587 /***********************************************************************
588 * ImmCreateContext (IMM32.@)
590 HIMC WINAPI ImmCreateContext(void)
592 InputContextData *new_context;
594 new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
596 return (HIMC)new_context;
599 /***********************************************************************
600 * ImmDestroyContext (IMM32.@)
602 BOOL WINAPI ImmDestroyContext(HIMC hIMC)
604 InputContextData *data = (InputContextData*)hIMC;
606 TRACE("Destroying %p\n",hIMC);
610 ImmDestroyIMCC(root_context->IMC.hCompStr);
611 ImmDestroyIMCC(root_context->IMC.hCandInfo);
612 ImmDestroyIMCC(root_context->IMC.hGuideLine);
613 ImmDestroyIMCC(root_context->IMC.hPrivate);
614 ImmDestroyIMCC(root_context->IMC.hMsgBuf);
618 DeleteObject(data->textfont);
619 data->textfont = NULL;
622 HeapFree(GetProcessHeap(),0,data);
627 /***********************************************************************
628 * ImmDisableIME (IMM32.@)
630 BOOL WINAPI ImmDisableIME(DWORD idThread)
632 FIXME("(%d): stub\n", idThread);
636 /***********************************************************************
637 * ImmEnumRegisterWordA (IMM32.@)
639 UINT WINAPI ImmEnumRegisterWordA(
640 HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
641 LPCSTR lpszReading, DWORD dwStyle,
642 LPCSTR lpszRegister, LPVOID lpData)
644 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
646 debugstr_a(lpszReading), dwStyle,
647 debugstr_a(lpszRegister), lpData
649 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
653 /***********************************************************************
654 * ImmEnumRegisterWordW (IMM32.@)
656 UINT WINAPI ImmEnumRegisterWordW(
657 HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
658 LPCWSTR lpszReading, DWORD dwStyle,
659 LPCWSTR lpszRegister, LPVOID lpData)
661 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
663 debugstr_w(lpszReading), dwStyle,
664 debugstr_w(lpszRegister), lpData
666 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
670 /***********************************************************************
671 * ImmEscapeA (IMM32.@)
673 LRESULT WINAPI ImmEscapeA(
675 UINT uEscape, LPVOID lpData)
677 FIXME("(%p, %p, %d, %p): stub\n",
678 hKL, hIMC, uEscape, lpData
680 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
684 /***********************************************************************
685 * ImmEscapeW (IMM32.@)
687 LRESULT WINAPI ImmEscapeW(
689 UINT uEscape, LPVOID lpData)
691 FIXME("(%p, %p, %d, %p): stub\n",
692 hKL, hIMC, uEscape, lpData
694 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
698 /***********************************************************************
699 * ImmGetCandidateListA (IMM32.@)
701 DWORD WINAPI ImmGetCandidateListA(
702 HIMC hIMC, DWORD deIndex,
703 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
705 FIXME("(%p, %d, %p, %d): stub\n",
709 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
713 /***********************************************************************
714 * ImmGetCandidateListCountA (IMM32.@)
716 DWORD WINAPI ImmGetCandidateListCountA(
717 HIMC hIMC, LPDWORD lpdwListCount)
719 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
720 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
724 /***********************************************************************
725 * ImmGetCandidateListCountW (IMM32.@)
727 DWORD WINAPI ImmGetCandidateListCountW(
728 HIMC hIMC, LPDWORD lpdwListCount)
730 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
731 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
735 /***********************************************************************
736 * ImmGetCandidateListW (IMM32.@)
738 DWORD WINAPI ImmGetCandidateListW(
739 HIMC hIMC, DWORD deIndex,
740 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
742 FIXME("(%p, %d, %p, %d): stub\n",
746 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
750 /***********************************************************************
751 * ImmGetCandidateWindow (IMM32.@)
753 BOOL WINAPI ImmGetCandidateWindow(
754 HIMC hIMC, DWORD dwBufLen, LPCANDIDATEFORM lpCandidate)
756 FIXME("(%p, %d, %p): stub\n", hIMC, dwBufLen, lpCandidate);
757 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
761 /***********************************************************************
762 * ImmGetCompositionFontA (IMM32.@)
764 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
766 FIXME("(%p, %p): stub\n", hIMC, lplf);
767 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
771 /***********************************************************************
772 * ImmGetCompositionFontW (IMM32.@)
774 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
776 FIXME("(%p, %p): stub\n", hIMC, lplf);
777 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
781 /***********************************************************************
782 * ImmGetCompositionStringA (IMM32.@)
784 LONG WINAPI ImmGetCompositionStringA(
785 HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
789 InputContextData *data = (InputContextData*)hIMC;
790 LPCOMPOSITIONSTRING compstr;
793 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
798 if (!data->IMC.hCompStr)
801 compdata = ImmLockIMCC(data->IMC.hCompStr);
802 compstr = (LPCOMPOSITIONSTRING)compdata;
804 if (dwIndex == GCS_RESULTSTR && compstr->dwResultStrLen > 0 &&
805 compstr->dwResultStrOffset > 0)
807 LPWSTR ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
809 TRACE("GSC_RESULTSTR %p %i\n",ResultStr,
810 compstr->dwResultStrLen);
812 buf = HeapAlloc( GetProcessHeap(), 0, compstr->dwResultStrLen * 3 );
813 rc = WideCharToMultiByte(CP_ACP, 0, ResultStr,
814 compstr->dwResultStrLen , buf,
815 compstr->dwResultStrLen * 3, NULL, NULL);
817 memcpy(lpBuf,buf,rc);
820 HeapFree( GetProcessHeap(), 0, buf );
822 else if (dwIndex == GCS_COMPSTR && compstr->dwCompStrLen > 0 &&
823 compstr->dwCompStrOffset > 0)
825 LPWSTR CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
827 TRACE("GSC_COMPSTR %p %i\n", CompString, compstr->dwCompStrLen);
829 buf = HeapAlloc( GetProcessHeap(), 0, compstr->dwCompStrLen * 3 );
830 rc = WideCharToMultiByte(CP_ACP, 0, CompString,
831 compstr->dwCompStrLen, buf,
832 compstr->dwCompStrLen * 3, NULL, NULL);
834 memcpy(lpBuf,buf,rc);
835 HeapFree( GetProcessHeap(), 0, buf );
837 else if (dwIndex == GCS_COMPATTR && compstr->dwCompAttrLen > 0 &&
838 compstr->dwCompAttrOffset > 0)
840 LPWSTR Compattr = (LPWSTR)(compdata + compstr->dwCompAttrOffset);
841 TRACE("GSC_COMPATTR %p %i\n", Compattr , compstr->dwCompAttrLen);
843 rc = compstr->dwCompAttrLen;
845 memcpy(lpBuf,Compattr,rc);
847 else if (dwIndex == GCS_COMPCLAUSE && compstr->dwCompClauseLen > 0 &&
848 compstr->dwCompClauseOffset > 0)
850 LPWSTR Compclause = (LPWSTR)(compdata + compstr->dwCompClauseOffset);
851 TRACE("GSC_COMPCLAUSE %p %i\n", Compclause, compstr->dwCompClauseLen);
853 rc = compstr->dwCompClauseLen;
854 if (dwBufLen >= compstr->dwCompClauseLen)
855 memcpy(lpBuf,Compclause,rc);
857 else if (dwIndex == GCS_RESULTCLAUSE && compstr->dwResultClauseLen > 0 &&
858 compstr->dwResultClauseOffset > 0)
860 LPWSTR Resultclause = (LPWSTR)(compdata + compstr->dwResultClauseOffset);
861 TRACE("GSC_RESULTCLAUSE %p %i\n", Resultclause, compstr->dwResultClauseLen);
863 rc = compstr->dwResultClauseLen;
864 if (dwBufLen >= compstr->dwResultClauseLen)
865 memcpy(lpBuf,Resultclause,rc);
867 else if (dwIndex == GCS_CURSORPOS)
869 TRACE("GSC_CURSORPOS\n");
870 rc = compstr->dwCursorPos;
872 else if (dwIndex == GCS_DELTASTART)
874 TRACE("GCS_DELTASTART\n");
875 rc = compstr->dwDeltaStart;
879 FIXME("Unhandled index 0x%x\n",dwIndex);
882 ImmUnlockIMCC(data->IMC.hCompStr);
887 /***********************************************************************
888 * ImmGetCompositionStringW (IMM32.@)
890 LONG WINAPI ImmGetCompositionStringW(
891 HIMC hIMC, DWORD dwIndex,
892 LPVOID lpBuf, DWORD dwBufLen)
895 InputContextData *data = (InputContextData*)hIMC;
896 LPCOMPOSITIONSTRING compstr;
899 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
904 if (!data->IMC.hCompStr)
907 compdata = ImmLockIMCC(data->IMC.hCompStr);
908 compstr = (LPCOMPOSITIONSTRING)compdata;
910 if (dwIndex == GCS_RESULTSTR && compstr->dwResultStrLen > 0 &&
911 compstr->dwResultStrOffset > 0)
913 LPWSTR ResultStr = (LPWSTR)(compdata + compstr->dwResultStrOffset);
915 rc = compstr->dwResultStrLen * sizeof(WCHAR);
918 memcpy(lpBuf,ResultStr,rc);
920 else if (dwIndex == GCS_RESULTREADSTR && compstr->dwResultReadStrLen > 0 &&
921 compstr->dwResultReadStrOffset > 0)
923 LPWSTR ResultReadString = (LPWSTR)(compdata + compstr->dwResultReadStrOffset);
925 rc = compstr->dwResultReadStrLen * sizeof(WCHAR);
927 memcpy(lpBuf,ResultReadString,rc);
929 else if (dwIndex == GCS_COMPSTR && compstr->dwCompStrLen > 0 &&
930 compstr->dwCompStrOffset > 0)
932 LPWSTR CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
933 rc = compstr->dwCompStrLen * sizeof(WCHAR);
935 memcpy(lpBuf,CompString,rc);
937 else if (dwIndex == GCS_COMPATTR && compstr->dwCompAttrLen > 0 &&
938 compstr->dwCompAttrOffset > 0)
941 LPWSTR Compattr = (LPWSTR)(compdata + compstr->dwCompAttrOffset);
943 rc = compstr->dwCompAttrLen;
945 memcpy(lpBuf,Compattr,rc);
947 else if (dwIndex == GCS_COMPCLAUSE && compstr->dwCompClauseLen > 0 &&
948 compstr->dwCompClauseOffset > 0)
950 LPWSTR Compclause = (LPWSTR)(compdata + compstr->dwCompClauseOffset);
952 rc = compstr->dwCompClauseLen;
953 if (dwBufLen >= compstr->dwCompClauseLen)
954 memcpy(lpBuf,Compclause,rc);
956 else if (dwIndex == GCS_COMPREADSTR && compstr->dwCompReadStrLen > 0 &&
957 compstr->dwCompReadStrOffset > 0)
959 LPWSTR CompReadString = (LPWSTR)(compdata + compstr->dwCompReadStrOffset);
961 rc = compstr->dwCompReadStrLen * sizeof(WCHAR);
964 memcpy(lpBuf,CompReadString,rc);
966 else if (dwIndex == GCS_CURSORPOS)
968 TRACE("GSC_CURSORPOS\n");
969 rc = compstr->dwCursorPos;
971 else if (dwIndex == GCS_DELTASTART)
973 TRACE("GCS_DELTASTART\n");
974 rc = compstr->dwDeltaStart;
978 FIXME("Unhandled index 0x%x\n",dwIndex);
981 ImmUnlockIMCC(data->IMC.hCompStr);
986 /***********************************************************************
987 * ImmGetCompositionWindow (IMM32.@)
989 BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
991 InputContextData *data = (InputContextData*)hIMC;
993 TRACE("(%p, %p)\n", hIMC, lpCompForm);
998 memcpy(lpCompForm,&(data->IMC.cfCompForm),sizeof(COMPOSITIONFORM));
1002 /***********************************************************************
1003 * ImmGetContext (IMM32.@)
1006 HIMC WINAPI ImmGetContext(HWND hWnd)
1008 TRACE("%p\n", hWnd);
1013 root_context->IMC.hWnd = hWnd;
1014 return (HIMC)root_context;
1017 /***********************************************************************
1018 * ImmGetConversionListA (IMM32.@)
1020 DWORD WINAPI ImmGetConversionListA(
1022 LPCSTR pSrc, LPCANDIDATELIST lpDst,
1023 DWORD dwBufLen, UINT uFlag)
1025 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
1026 hKL, hIMC, debugstr_a(pSrc), lpDst, dwBufLen, uFlag
1028 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1032 /***********************************************************************
1033 * ImmGetConversionListW (IMM32.@)
1035 DWORD WINAPI ImmGetConversionListW(
1037 LPCWSTR pSrc, LPCANDIDATELIST lpDst,
1038 DWORD dwBufLen, UINT uFlag)
1040 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
1041 hKL, hIMC, debugstr_w(pSrc), lpDst, dwBufLen, uFlag
1043 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1047 /***********************************************************************
1048 * ImmGetConversionStatus (IMM32.@)
1050 BOOL WINAPI ImmGetConversionStatus(
1051 HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
1053 TRACE("(%p, %p, %p): best guess\n", hIMC, lpfdwConversion, lpfdwSentence);
1054 if (lpfdwConversion)
1055 *lpfdwConversion = IME_CMODE_NATIVE;
1057 *lpfdwSentence = IME_SMODE_NONE;
1061 /***********************************************************************
1062 * ImmGetDefaultIMEWnd (IMM32.@)
1064 HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
1066 static int shown = 0;
1069 FIXME("(%p - %p %p ): semi-stub\n", hWnd,hwndDefault, root_context);
1073 if (hwndDefault == NULL)
1075 static const WCHAR the_name[] = {'I','M','E','\0'};
1078 hwndDefault = CreateWindowExW( WS_EX_TOOLWINDOW, WC_IMECLASSNAME,
1079 the_name, WS_POPUP, 0, 0, 1, 1, 0, 0,
1082 TRACE("Default created (%p)\n",hwndDefault);
1088 /***********************************************************************
1089 * ImmGetDescriptionA (IMM32.@)
1091 UINT WINAPI ImmGetDescriptionA(
1092 HKL hKL, LPSTR lpszDescription, UINT uBufLen)
1097 TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
1099 /* find out how many characters in the unicode buffer */
1100 len = ImmGetDescriptionW( hKL, NULL, 0 );
1102 /* allocate a buffer of that size */
1103 buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
1107 /* fetch the unicode buffer */
1108 len = ImmGetDescriptionW( hKL, buf, len + 1 );
1110 /* convert it back to ASCII */
1111 len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
1112 lpszDescription, uBufLen, NULL, NULL );
1114 HeapFree( GetProcessHeap(), 0, buf );
1119 /***********************************************************************
1120 * ImmGetDescriptionW (IMM32.@)
1122 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
1124 static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
1126 FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
1128 if (!uBufLen) return lstrlenW( name );
1129 lstrcpynW( lpszDescription, name, uBufLen );
1130 return lstrlenW( lpszDescription );
1133 /***********************************************************************
1134 * ImmGetGuideLineA (IMM32.@)
1136 DWORD WINAPI ImmGetGuideLineA(
1137 HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
1139 FIXME("(%p, %d, %s, %d): stub\n",
1140 hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
1142 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1146 /***********************************************************************
1147 * ImmGetGuideLineW (IMM32.@)
1149 DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
1151 FIXME("(%p, %d, %s, %d): stub\n",
1152 hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
1154 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1158 /***********************************************************************
1159 * ImmGetIMEFileNameA (IMM32.@)
1161 UINT WINAPI ImmGetIMEFileNameA(
1162 HKL hKL, LPSTR lpszFileName, UINT uBufLen)
1164 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
1165 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1169 /***********************************************************************
1170 * ImmGetIMEFileNameW (IMM32.@)
1172 UINT WINAPI ImmGetIMEFileNameW(
1173 HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
1175 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
1176 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1180 /***********************************************************************
1181 * ImmGetOpenStatus (IMM32.@)
1183 BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
1185 InputContextData *data = (InputContextData*)hIMC;
1189 FIXME("(%p): semi-stub\n", hIMC);
1191 return data->IMC.fOpen;
1194 /***********************************************************************
1195 * ImmGetProperty (IMM32.@)
1197 DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
1200 TRACE("(%p, %d)\n", hKL, fdwIndex);
1205 TRACE("(%s)\n", "IGP_PROPERTY");
1206 rc = IME_PROP_UNICODE | IME_PROP_AT_CARET;
1208 case IGP_CONVERSION:
1209 FIXME("(%s)\n", "IGP_CONVERSION");
1210 rc = IME_CMODE_NATIVE;
1213 FIXME("%s)\n", "IGP_SENTENCE");
1214 rc = IME_SMODE_AUTOMATIC;
1216 case IGP_SETCOMPSTR:
1217 TRACE("(%s)\n", "IGP_SETCOMPSTR");
1221 TRACE("(%s)\n", "IGP_SELECT");
1222 rc = SELECT_CAP_CONVERSION | SELECT_CAP_SENTENCE;
1224 case IGP_GETIMEVERSION:
1225 TRACE("(%s)\n", "IGP_GETIMEVERSION");
1229 TRACE("(%s)\n", "IGP_UI");
1238 /***********************************************************************
1239 * ImmGetRegisterWordStyleA (IMM32.@)
1241 UINT WINAPI ImmGetRegisterWordStyleA(
1242 HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
1244 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
1245 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1249 /***********************************************************************
1250 * ImmGetRegisterWordStyleW (IMM32.@)
1252 UINT WINAPI ImmGetRegisterWordStyleW(
1253 HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
1255 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
1256 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1260 /***********************************************************************
1261 * ImmGetStatusWindowPos (IMM32.@)
1263 BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1265 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
1266 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1270 /***********************************************************************
1271 * ImmGetVirtualKey (IMM32.@)
1273 UINT WINAPI ImmGetVirtualKey(HWND hWnd)
1275 OSVERSIONINFOA version;
1276 FIXME("(%p): stub\n", hWnd);
1277 GetVersionExA( &version );
1278 switch(version.dwPlatformId)
1280 case VER_PLATFORM_WIN32_WINDOWS:
1281 return VK_PROCESSKEY;
1282 case VER_PLATFORM_WIN32_NT:
1285 FIXME("%d not supported\n",version.dwPlatformId);
1286 return VK_PROCESSKEY;
1290 /***********************************************************************
1291 * ImmInstallIMEA (IMM32.@)
1293 HKL WINAPI ImmInstallIMEA(
1294 LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
1296 FIXME("(%s, %s): stub\n",
1297 debugstr_a(lpszIMEFileName), debugstr_a(lpszLayoutText)
1299 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1303 /***********************************************************************
1304 * ImmInstallIMEW (IMM32.@)
1306 HKL WINAPI ImmInstallIMEW(
1307 LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
1309 FIXME("(%s, %s): stub\n",
1310 debugstr_w(lpszIMEFileName), debugstr_w(lpszLayoutText)
1312 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1316 /***********************************************************************
1317 * ImmIsIME (IMM32.@)
1319 BOOL WINAPI ImmIsIME(HKL hKL)
1321 TRACE("(%p): semi-stub\n", hKL);
1323 * FIXME: Dead key locales will return TRUE here when they should not
1324 * There is probably a more proper way to check this.
1326 return (root_context != NULL);
1329 /***********************************************************************
1330 * ImmIsUIMessageA (IMM32.@)
1332 BOOL WINAPI ImmIsUIMessageA(
1333 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1337 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1338 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1339 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1340 (msg == WM_MSIME_SERVICE) ||
1341 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1342 (msg == WM_MSIME_MOUSE) ||
1343 (msg == WM_MSIME_RECONVERTREQUEST) ||
1344 (msg == WM_MSIME_RECONVERT) ||
1345 (msg == WM_MSIME_QUERYPOSITION) ||
1346 (msg == WM_MSIME_DOCUMENTFEED))
1350 ImmGetDefaultIMEWnd(NULL);
1352 if (hWndIME == NULL)
1353 PostMessageA(hwndDefault, msg, wParam, lParam);
1360 /***********************************************************************
1361 * ImmIsUIMessageW (IMM32.@)
1363 BOOL WINAPI ImmIsUIMessageW(
1364 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1367 TRACE("(%p, %d, %ld, %ld): stub\n", hWndIME, msg, wParam, lParam);
1368 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1369 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1370 (msg == WM_MSIME_SERVICE) ||
1371 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1372 (msg == WM_MSIME_MOUSE) ||
1373 (msg == WM_MSIME_RECONVERTREQUEST) ||
1374 (msg == WM_MSIME_RECONVERT) ||
1375 (msg == WM_MSIME_QUERYPOSITION) ||
1376 (msg == WM_MSIME_DOCUMENTFEED))
1381 /***********************************************************************
1382 * ImmNotifyIME (IMM32.@)
1384 BOOL WINAPI ImmNotifyIME(
1385 HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
1389 TRACE("(%p, %d, %d, %d)\n",
1390 hIMC, dwAction, dwIndex, dwValue);
1397 case NI_CHANGECANDIDATELIST:
1398 FIXME("%s\n","NI_CHANGECANDIDATELIST");
1400 case NI_CLOSECANDIDATE:
1401 FIXME("%s\n","NI_CLOSECANDIDATE");
1403 case NI_COMPOSITIONSTR:
1407 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL");
1411 if (pX11DRV_ForceXIMReset)
1412 pX11DRV_ForceXIMReset(root_context->IMC.hWnd);
1414 send = (root_context->IMC.hCompStr!=NULL);
1416 ImmDestroyIMCC(root_context->IMC.hCompStr);
1417 root_context->IMC.hCompStr = NULL;
1420 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1426 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_COMPLETE");
1427 if (hIMC != (HIMC)FROM_IME && pX11DRV_ForceXIMReset)
1428 pX11DRV_ForceXIMReset(root_context->IMC.hWnd);
1433 LPCOMPOSITIONSTRING cs = NULL;
1434 LPBYTE cdata = NULL;
1436 /* clear existing result */
1437 newCompStr = updateResultStr(root_context->IMC.hCompStr, NULL, 0);
1438 ImmDestroyIMCC(root_context->IMC.hCompStr);
1439 root_context->IMC.hCompStr = newCompStr;
1441 if (root_context->IMC.hCompStr)
1443 cdata = ImmLockIMCC(root_context->IMC.hCompStr);
1444 cs = (LPCOMPOSITIONSTRING)cdata;
1445 cplen = cs->dwCompStrLen;
1446 cpstr = (LPWSTR)&(cdata[cs->dwCompStrOffset]);
1447 ImmUnlockIMCC(root_context->IMC.hCompStr);
1451 WCHAR param = cpstr[0];
1452 newCompStr = updateResultStr(root_context->IMC.hCompStr, cpstr, cplen);
1453 ImmDestroyIMCC(root_context->IMC.hCompStr);
1454 root_context->IMC.hCompStr = newCompStr;
1455 newCompStr = updateCompStr(root_context->IMC.hCompStr, NULL, 0);
1456 ImmDestroyIMCC(root_context->IMC.hCompStr);
1457 root_context->IMC.hCompStr = newCompStr;
1459 root_context->bRead = FALSE;
1461 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1464 ImmInternalPostIMEMessage(WM_IME_COMPOSITION,
1466 GCS_RESULTSTR|GCS_RESULTCLAUSE);
1469 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION, 0, 0);
1470 root_context->bInComposition = FALSE;
1474 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_CONVERT");
1477 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_REVERT");
1480 ERR("%s - %s (%i)\n","NI_COMPOSITIONSTR","UNKNOWN",dwIndex);
1484 case NI_IMEMENUSELECTED:
1485 FIXME("%s\n", "NI_IMEMENUSELECTED");
1487 case NI_OPENCANDIDATE:
1488 FIXME("%s\n", "NI_OPENCANDIDATE");
1490 case NI_SELECTCANDIDATESTR:
1491 FIXME("%s\n", "NI_SELECTCANDIDATESTR");
1493 case NI_SETCANDIDATE_PAGESIZE:
1494 FIXME("%s\n", "NI_SETCANDIDATE_PAGESIZE");
1496 case NI_SETCANDIDATE_PAGESTART:
1497 FIXME("%s\n", "NI_SETCANDIDATE_PAGESTART");
1506 /***********************************************************************
1507 * ImmRegisterWordA (IMM32.@)
1509 BOOL WINAPI ImmRegisterWordA(
1510 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
1512 FIXME("(%p, %s, %d, %s): stub\n",
1513 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister)
1515 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1519 /***********************************************************************
1520 * ImmRegisterWordW (IMM32.@)
1522 BOOL WINAPI ImmRegisterWordW(
1523 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
1525 FIXME("(%p, %s, %d, %s): stub\n",
1526 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister)
1528 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1532 /***********************************************************************
1533 * ImmReleaseContext (IMM32.@)
1535 BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
1537 static int shown = 0;
1540 FIXME("(%p, %p): stub\n", hWnd, hIMC);
1546 /***********************************************************************
1547 * ImmSetCandidateWindow (IMM32.@)
1549 BOOL WINAPI ImmSetCandidateWindow(
1550 HIMC hIMC, LPCANDIDATEFORM lpCandidate)
1552 FIXME("(%p, %p): stub\n", hIMC, lpCandidate);
1553 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1557 /***********************************************************************
1558 * ImmSetCompositionFontA (IMM32.@)
1560 BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
1562 InputContextData *data = (InputContextData*)hIMC;
1563 TRACE("(%p, %p)\n", hIMC, lplf);
1568 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTA));
1569 MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->IMC.lfFont.W.lfFaceName,
1572 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1576 DeleteObject(data->textfont);
1577 data->textfont = NULL;
1580 data->textfont = CreateFontIndirectW(&data->IMC.lfFont.W);
1584 /***********************************************************************
1585 * ImmSetCompositionFontW (IMM32.@)
1587 BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
1589 InputContextData *data = (InputContextData*)hIMC;
1590 TRACE("(%p, %p)\n", hIMC, lplf);
1595 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTW));
1596 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1600 DeleteObject(data->textfont);
1601 data->textfont = NULL;
1603 data->textfont = CreateFontIndirectW(&data->IMC.lfFont.W);
1607 /***********************************************************************
1608 * ImmSetCompositionStringA (IMM32.@)
1610 BOOL WINAPI ImmSetCompositionStringA(
1611 HIMC hIMC, DWORD dwIndex,
1612 LPCVOID lpComp, DWORD dwCompLen,
1613 LPCVOID lpRead, DWORD dwReadLen)
1617 WCHAR *CompBuffer = NULL;
1618 WCHAR *ReadBuffer = NULL;
1621 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1622 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1624 comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
1627 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
1628 MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
1631 read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
1634 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
1635 MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
1638 rc = ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
1639 ReadBuffer, read_len);
1641 HeapFree(GetProcessHeap(), 0, CompBuffer);
1642 HeapFree(GetProcessHeap(), 0, ReadBuffer);
1647 /***********************************************************************
1648 * ImmSetCompositionStringW (IMM32.@)
1650 BOOL WINAPI ImmSetCompositionStringW(
1651 HIMC hIMC, DWORD dwIndex,
1652 LPCVOID lpComp, DWORD dwCompLen,
1653 LPCVOID lpRead, DWORD dwReadLen)
1658 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1659 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1662 if (hIMC != (HIMC)FROM_IME)
1663 FIXME("PROBLEM: This only sets the wine level string\n");
1667 * this sets the composition string in the imm32.dll level
1668 * of the composition buffer. we cannot manipulate the xim level
1669 * buffer, which means that once the xim level buffer changes again
1670 * any call to this function from the application will be lost
1673 if (lpRead && dwReadLen)
1674 FIXME("Reading string unimplemented\n");
1677 * app operating this api to also receive the message from xim
1680 if (dwIndex == SCS_SETSTR)
1683 if (!root_context->bInComposition)
1685 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION, 0, 0);
1686 root_context->bInComposition = TRUE;
1689 flags = GCS_COMPSTR;
1691 if (dwCompLen && lpComp)
1693 newCompStr = updateCompStr(root_context->IMC.hCompStr, (LPWSTR)lpComp, dwCompLen / sizeof(WCHAR));
1694 ImmDestroyIMCC(root_context->IMC.hCompStr);
1695 root_context->IMC.hCompStr = newCompStr;
1697 wParam = ((const WCHAR*)lpComp)[0];
1698 flags |= GCS_COMPCLAUSE | GCS_COMPATTR | GCS_DELTASTART;
1702 newCompStr = updateCompStr(root_context->IMC.hCompStr, NULL, 0);
1703 ImmDestroyIMCC(root_context->IMC.hCompStr);
1704 root_context->IMC.hCompStr = newCompStr;
1708 UpdateDataInDefaultIMEWindow(hwndDefault,FALSE);
1710 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, wParam, flags);
1715 /***********************************************************************
1716 * ImmSetCompositionWindow (IMM32.@)
1718 BOOL WINAPI ImmSetCompositionWindow(
1719 HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
1721 BOOL reshow = FALSE;
1722 InputContextData *data = (InputContextData*)hIMC;
1724 TRACE("(%p, %p)\n", hIMC, lpCompForm);
1725 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm->dwStyle,
1726 lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
1727 lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);
1732 memcpy(&data->IMC.cfCompForm,lpCompForm,sizeof(COMPOSITIONFORM));
1734 if (IsWindowVisible(hwndDefault))
1737 ShowWindow(hwndDefault,SW_HIDE);
1740 /* FIXME: this is a partial stub */
1743 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
1745 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONWINDOW, 0);
1749 /***********************************************************************
1750 * ImmSetConversionStatus (IMM32.@)
1752 BOOL WINAPI ImmSetConversionStatus(
1753 HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
1755 static int shown = 0;
1758 FIXME("(%p, %d, %d): stub\n",
1759 hIMC, fdwConversion, fdwSentence
1763 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1767 /***********************************************************************
1768 * ImmSetOpenStatus (IMM32.@)
1770 BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
1772 InputContextData *data = (InputContextData*)hIMC;
1774 TRACE("%p %d\n", hIMC, fOpen);
1776 if (hIMC == (HIMC)FROM_IME)
1778 ImmInternalSetOpenStatus(fOpen);
1779 ImmInternalSendIMENotify(IMN_SETOPENSTATUS, 0);
1786 if (fOpen != data->bInternalState)
1788 if (fOpen == FALSE && pX11DRV_ForceXIMReset)
1789 pX11DRV_ForceXIMReset(data->IMC.hWnd);
1792 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1794 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1796 ImmInternalSetOpenStatus(fOpen);
1797 ImmInternalSetOpenStatus(!fOpen);
1799 if (data->IMC.fOpen == FALSE)
1800 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1802 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1809 /***********************************************************************
1810 * ImmSetStatusWindowPos (IMM32.@)
1812 BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1814 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
1815 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1819 /***********************************************************************
1820 * ImmSimulateHotKey (IMM32.@)
1822 BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
1824 FIXME("(%p, %d): stub\n", hWnd, dwHotKeyID);
1825 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1829 /***********************************************************************
1830 * ImmUnregisterWordA (IMM32.@)
1832 BOOL WINAPI ImmUnregisterWordA(
1833 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
1835 FIXME("(%p, %s, %d, %s): stub\n",
1836 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszUnregister)
1838 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1842 /***********************************************************************
1843 * ImmUnregisterWordW (IMM32.@)
1845 BOOL WINAPI ImmUnregisterWordW(
1846 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
1848 FIXME("(%p, %s, %d, %s): stub\n",
1849 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszUnregister)
1851 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1855 /***********************************************************************
1856 * ImmGetImeMenuItemsA (IMM32.@)
1858 DWORD WINAPI ImmGetImeMenuItemsA( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1859 LPIMEMENUITEMINFOA lpImeParentMenu, LPIMEMENUITEMINFOA lpImeMenu,
1862 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1863 lpImeParentMenu, lpImeMenu, dwSize);
1867 /***********************************************************************
1868 * ImmGetImeMenuItemsW (IMM32.@)
1870 DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1871 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
1874 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1875 lpImeParentMenu, lpImeMenu, dwSize);
1879 /***********************************************************************
1880 * ImmLockIMC(IMM32.@)
1882 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
1884 InputContextData *data = (InputContextData*)hIMC;
1892 /***********************************************************************
1893 * ImmUnlockIMC(IMM32.@)
1895 BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
1897 InputContextData *data = (InputContextData*)hIMC;
1899 return (data->dwLock!=0);
1902 /***********************************************************************
1903 * ImmGetIMCLockCount(IMM32.@)
1905 DWORD WINAPI ImmGetIMCLockCount(HIMC hIMC)
1907 InputContextData *data = (InputContextData*)hIMC;
1908 return data->dwLock;
1911 /***********************************************************************
1912 * ImmCreateIMCC(IMM32.@)
1914 HIMCC WINAPI ImmCreateIMCC(DWORD size)
1916 IMCCInternal *internal;
1917 int real_size = size + sizeof(IMCCInternal);
1919 internal = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, real_size);
1920 if (internal == NULL)
1923 internal->dwSize = size;
1924 return (HIMCC)internal;
1927 /***********************************************************************
1928 * ImmDestroyIMCC(IMM32.@)
1930 HIMCC WINAPI ImmDestroyIMCC(HIMCC block)
1932 HeapFree(GetProcessHeap(),0,block);
1936 /***********************************************************************
1937 * ImmLockIMCC(IMM32.@)
1939 LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
1941 IMCCInternal *internal;
1942 internal = (IMCCInternal*) imcc;
1944 internal->dwLock ++;
1945 return internal + 1;
1948 /***********************************************************************
1949 * ImmUnlockIMCC(IMM32.@)
1951 BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
1953 IMCCInternal *internal;
1954 internal = (IMCCInternal*) imcc;
1956 internal->dwLock --;
1957 return (internal->dwLock!=0);
1960 /***********************************************************************
1961 * ImmGetIMCCLockCount(IMM32.@)
1963 DWORD WINAPI ImmGetIMCCLockCount(HIMCC imcc)
1965 IMCCInternal *internal;
1966 internal = (IMCCInternal*) imcc;
1968 return internal->dwLock;
1971 /***********************************************************************
1972 * ImmReSizeIMCC(IMM32.@)
1974 HIMCC WINAPI ImmReSizeIMCC(HIMCC imcc, DWORD size)
1976 IMCCInternal *internal,*newone;
1977 int real_size = size + sizeof(IMCCInternal);
1979 internal = (IMCCInternal*) imcc;
1981 newone = HeapReAlloc(GetProcessHeap(), 0, internal, real_size);
1982 newone->dwSize = size;
1987 /***********************************************************************
1988 * ImmGetIMCCSize(IMM32.@)
1990 DWORD WINAPI ImmGetIMCCSize(HIMCC imcc)
1992 IMCCInternal *internal;
1993 internal = (IMCCInternal*) imcc;
1995 return internal->dwSize;
1999 * Internal functions to help with IME window management
2001 static void PaintDefaultIMEWnd(HWND hwnd)
2005 HDC hdc = BeginPaint(hwnd,&ps);
2006 LPCOMPOSITIONSTRING compstr;
2007 LPBYTE compdata = NULL;
2009 MONITORINFO mon_info;
2012 GetClientRect(hwnd,&rect);
2013 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
2015 compdata = ImmLockIMCC(root_context->IMC.hCompStr);
2016 compstr = (LPCOMPOSITIONSTRING)compdata;
2018 if (compstr->dwCompStrLen && compstr->dwCompStrOffset)
2022 HFONT oldfont = NULL;
2025 CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset);
2026 if (root_context->textfont)
2027 oldfont = SelectObject(hdc,root_context->textfont);
2030 GetTextExtentPoint32W(hdc, CompString, compstr->dwCompStrLen, &size);
2036 * How this works based on tests on windows:
2037 * CFS_POINT: then we start our window at the point and grow it as large
2038 * as it needs to be for the string.
2039 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
2040 * window is only as large as we need for the string, but we do not
2041 * grow such that our window exceeds the given rect. Wrapping if
2042 * needed and possible. If our ptCurrentPos is outside of our rect
2043 * then no window is displayed.
2044 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
2045 * maybe becase the default MSIME does not do any IME adjusting.
2047 if (root_context->IMC.cfCompForm.dwStyle != CFS_DEFAULT)
2049 POINT cpt = root_context->IMC.cfCompForm.ptCurrentPos;
2050 ClientToScreen(root_context->IMC.hWnd,&cpt);
2053 rect.right = rect.left + pt.x;
2054 rect.bottom = rect.top + pt.y;
2056 monitor = MonitorFromPoint(cpt, MONITOR_DEFAULTTOPRIMARY);
2058 else /* CFS_DEFAULT */
2060 /* Windows places the default IME window in the bottom left */
2061 HWND target = root_context->IMC.hWnd;
2062 if (!target) target = GetFocus();
2064 GetWindowRect(target,&rect);
2065 rect.top = rect.bottom;
2066 rect.right = rect.left + pt.x + 20;
2067 rect.bottom = rect.top + pt.y + 20;
2069 monitor = MonitorFromWindow(target, MONITOR_DEFAULTTOPRIMARY);
2072 if (root_context->IMC.cfCompForm.dwStyle == CFS_RECT)
2075 client =root_context->IMC.cfCompForm.rcArea;
2076 MapWindowPoints( root_context->IMC.hWnd, 0, (POINT *)&client, 2 );
2077 IntersectRect(&rect,&rect,&client);
2078 /* TODO: Wrap the input if needed */
2081 if (root_context->IMC.cfCompForm.dwStyle == CFS_DEFAULT)
2083 /* make sure we are on the desktop */
2084 mon_info.cbSize = sizeof(mon_info);
2085 GetMonitorInfoW(monitor, &mon_info);
2087 if (rect.bottom > mon_info.rcWork.bottom)
2089 int shift = rect.bottom - mon_info.rcWork.bottom;
2091 rect.bottom -= shift;
2095 rect.right -= rect.left;
2098 if (rect.right > mon_info.rcWork.right)
2100 int shift = rect.right - mon_info.rcWork.right;
2102 rect.right -= shift;
2106 SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
2108 TextOutW(hdc, offX,offY, CompString, compstr->dwCompStrLen);
2111 SelectObject(hdc,oldfont);
2114 ImmUnlockIMCC(root_context->IMC.hCompStr);
2119 static void UpdateDataInDefaultIMEWindow(HWND hwnd, BOOL showable)
2121 LPCOMPOSITIONSTRING compstr;
2123 if (root_context->IMC.hCompStr)
2124 compstr = ImmLockIMCC(root_context->IMC.hCompStr);
2128 if (compstr == NULL || compstr->dwCompStrLen == 0)
2129 ShowWindow(hwndDefault,SW_HIDE);
2131 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
2133 RedrawWindow(hwnd,NULL,NULL,RDW_ERASENOW|RDW_INVALIDATE);
2135 if (compstr != NULL)
2136 ImmUnlockIMCC(root_context->IMC.hCompStr);
2140 * The window proc for the default IME window
2142 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
2147 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", msg, (UINT)wParam,
2153 PaintDefaultIMEWnd(hwnd);
2160 SetWindowTextA(hwnd,"Wine Ime Active");
2165 SetFocus((HWND)wParam);
2167 FIXME("Received focus, should never have focus\n");
2169 case WM_IME_COMPOSITION:
2170 TRACE("IME message %s, 0x%x, 0x%x (%i)\n",
2171 "WM_IME_COMPOSITION", (UINT)wParam, (UINT)lParam,
2172 root_context->bRead);
2173 if (lParam & GCS_RESULTSTR)
2174 IMM_PostResult(root_context);
2176 UpdateDataInDefaultIMEWindow(hwnd,TRUE);
2178 case WM_IME_STARTCOMPOSITION:
2179 TRACE("IME message %s, 0x%x, 0x%x\n",
2180 "WM_IME_STARTCOMPOSITION", (UINT)wParam, (UINT)lParam);
2181 root_context->IMC.hWnd = GetFocus();
2182 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
2184 case WM_IME_ENDCOMPOSITION:
2185 TRACE("IME message %s, 0x%x, 0x%x\n",
2186 "WM_IME_ENDCOMPOSITION", (UINT)wParam, (UINT)lParam);
2187 ShowWindow(hwndDefault,SW_HIDE);
2190 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_SELECT",
2191 (UINT)wParam, (UINT)lParam);
2193 case WM_IME_CONTROL:
2194 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_CONTROL",
2195 (UINT)wParam, (UINT)lParam);
2199 TRACE("!! IME NOTIFY\n");
2202 TRACE("Non-standard message 0x%x\n",msg);
2204 /* check the MSIME messages */
2205 if (msg == WM_MSIME_SERVICE)
2207 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_SERVICE",
2208 (UINT)wParam, (UINT)lParam);
2211 else if (msg == WM_MSIME_RECONVERTOPTIONS)
2213 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTOPTIONS",
2214 (UINT)wParam, (UINT)lParam);
2216 else if (msg == WM_MSIME_MOUSE)
2218 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_MOUSE",
2219 (UINT)wParam, (UINT)lParam);
2221 else if (msg == WM_MSIME_RECONVERTREQUEST)
2223 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTREQUEST",
2224 (UINT)wParam, (UINT)lParam);
2226 else if (msg == WM_MSIME_RECONVERT)
2228 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERT",
2229 (UINT)wParam, (UINT)lParam);
2231 else if (msg == WM_MSIME_QUERYPOSITION)
2233 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_QUERYPOSITION",
2234 (UINT)wParam, (UINT)lParam);
2236 else if (msg == WM_MSIME_DOCUMENTFEED)
2238 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_DOCUMENTFEED",
2239 (UINT)wParam, (UINT)lParam);
2241 /* DefWndProc if not an IME message */
2242 else if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
2243 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
2244 rc = DefWindowProcW(hwnd,msg,wParam,lParam);