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
30 #include "wine/debug.h"
35 #include "wine/list.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(imm);
39 typedef struct tagIMCCInternal
45 #define MAKE_FUNCPTR(f) typeof(f) * p##f
46 typedef struct _tagImmHkl{
51 WCHAR imeClassName[17]; /* 16 character max */
55 /* Function Pointers */
56 MAKE_FUNCPTR(ImeInquire);
57 MAKE_FUNCPTR(ImeConfigure);
58 MAKE_FUNCPTR(ImeDestroy);
59 MAKE_FUNCPTR(ImeEscape);
60 MAKE_FUNCPTR(ImeSelect);
61 MAKE_FUNCPTR(ImeSetActiveContext);
62 MAKE_FUNCPTR(ImeToAsciiEx);
63 MAKE_FUNCPTR(NotifyIME);
64 MAKE_FUNCPTR(ImeRegisterWord);
65 MAKE_FUNCPTR(ImeUnregisterWord);
66 MAKE_FUNCPTR(ImeEnumRegisterWord);
67 MAKE_FUNCPTR(ImeSetCompositionString);
68 MAKE_FUNCPTR(ImeConversionList);
69 MAKE_FUNCPTR(ImeProcessKey);
70 MAKE_FUNCPTR(ImeGetRegisterWordStyle);
71 MAKE_FUNCPTR(ImeGetImeMenuItems);
75 typedef struct tagInputContextData
84 typedef struct _tagTRANSMSG {
88 } TRANSMSG, *LPTRANSMSG;
90 typedef struct _tagIMMThreadData {
95 static DWORD tlsIndex = 0;
96 static struct list ImmHklList = LIST_INIT(ImmHklList);
99 static UINT WM_MSIME_SERVICE;
100 static UINT WM_MSIME_RECONVERTOPTIONS;
101 static UINT WM_MSIME_MOUSE;
102 static UINT WM_MSIME_RECONVERTREQUEST;
103 static UINT WM_MSIME_RECONVERT;
104 static UINT WM_MSIME_QUERYPOSITION;
105 static UINT WM_MSIME_DOCUMENTFEED;
107 static const WCHAR szwWineIMCProperty[] = {'W','i','n','e','I','m','m','H','I','M','C','P','r','o','p','e','r','t','y',0};
109 static const WCHAR szImeFileW[] = {'I','m','e',' ','F','i','l','e',0};
110 static const WCHAR szLayoutTextW[] = {'L','a','y','o','u','t',' ','T','e','x','t',0};
111 static const WCHAR szImeRegFmt[] = {'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','K','e','y','b','o','a','r','d',' ','L','a','y','o','u','t','s','\\','%','0','8','l','x',0};
113 static const WCHAR szwIME[] = {'I','M','E',0};
115 static LRESULT WINAPI DefIME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
118 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
119 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
121 static BOOL IMM_DestroyContext(HIMC hIMC);
123 static inline WCHAR *strdupAtoW( const char *str )
128 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
129 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
130 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
135 static inline CHAR *strdupWtoA( const WCHAR *str )
140 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
141 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
142 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
147 static DWORD convert_candidatelist_WtoA(
148 LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen)
152 ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] );
153 if ( lpDst && dwBufLen > 0 )
156 lpDst->dwOffset[0] = ret;
159 for ( i = 0; i < lpSrc->dwCount; i++)
161 LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i];
163 if ( lpDst && dwBufLen > 0 )
165 LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i];
167 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1,
168 (LPSTR)dest, dwBufLen, NULL, NULL);
170 if ( i + 1 < lpSrc->dwCount )
171 lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(char);
172 dwBufLen -= len * sizeof(char);
175 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1, NULL, 0, NULL, NULL);
177 ret += len * sizeof(char);
186 static DWORD convert_candidatelist_AtoW(
187 LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen)
191 ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] );
192 if ( lpDst && dwBufLen > 0 )
195 lpDst->dwOffset[0] = ret;
198 for ( i = 0; i < lpSrc->dwCount; i++)
200 LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i];
202 if ( lpDst && dwBufLen > 0 )
204 LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i];
206 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1,
207 (LPWSTR)dest, dwBufLen);
209 if ( i + 1 < lpSrc->dwCount )
210 lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(WCHAR);
211 dwBufLen -= len * sizeof(WCHAR);
214 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, NULL, 0);
216 ret += len * sizeof(WCHAR);
225 static IMMThreadData* IMM_GetThreadData(void)
227 IMMThreadData* data = TlsGetValue(tlsIndex);
230 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
231 sizeof(IMMThreadData));
232 TlsSetValue(tlsIndex,data);
233 TRACE("Thread Data Created\n");
238 static void IMM_FreeThreadData(void)
240 IMMThreadData* data = TlsGetValue(tlsIndex);
243 IMM_DestroyContext(data->defaultContext);
244 DestroyWindow(data->hwndDefault);
245 HeapFree(GetProcessHeap(),0,data);
246 TRACE("Thread Data Destroyed\n");
250 static HMODULE LoadDefaultWineIME(void)
252 char buffer[MAX_PATH], libname[32], *name, *next;
256 TRACE("Attempting to fall back to wine default IME\n");
258 strcpy( buffer, "x11" ); /* default value */
259 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
260 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
262 DWORD type, count = sizeof(buffer);
263 RegQueryValueExA( hkey, "Ime", 0, &type, (LPBYTE) buffer, &count );
270 next = strchr( name, ',' );
271 if (next) *next++ = 0;
273 snprintf( libname, sizeof(libname), "wine%s.drv", name );
274 if ((module = LoadLibraryA( libname )) != 0) break;
281 /* ImmHkl loading and freeing */
282 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
283 static ImmHkl *IMM_GetImmHkl(HKL hkl)
286 WCHAR filename[MAX_PATH];
288 TRACE("Seeking ime for keyboard %p\n",hkl);
290 LIST_FOR_EACH_ENTRY(ptr, &ImmHklList, ImmHkl, entry)
295 /* not found... create it */
297 ptr = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ImmHkl));
300 if (ImmGetIMEFileNameW(hkl, filename, MAX_PATH)) ptr->hIME = LoadLibraryW(filename);
302 ptr->hIME = LoadDefaultWineIME();
305 LOAD_FUNCPTR(ImeInquire);
306 if (!ptr->pImeInquire || !ptr->pImeInquire(&ptr->imeInfo, ptr->imeClassName, NULL))
308 FreeLibrary(ptr->hIME);
313 LOAD_FUNCPTR(ImeDestroy);
314 LOAD_FUNCPTR(ImeSelect);
315 if (!ptr->pImeSelect || !ptr->pImeDestroy)
317 FreeLibrary(ptr->hIME);
322 LOAD_FUNCPTR(ImeConfigure);
323 LOAD_FUNCPTR(ImeEscape);
324 LOAD_FUNCPTR(ImeSetActiveContext);
325 LOAD_FUNCPTR(ImeToAsciiEx);
326 LOAD_FUNCPTR(NotifyIME);
327 LOAD_FUNCPTR(ImeRegisterWord);
328 LOAD_FUNCPTR(ImeUnregisterWord);
329 LOAD_FUNCPTR(ImeEnumRegisterWord);
330 LOAD_FUNCPTR(ImeSetCompositionString);
331 LOAD_FUNCPTR(ImeConversionList);
332 LOAD_FUNCPTR(ImeProcessKey);
333 LOAD_FUNCPTR(ImeGetRegisterWordStyle);
334 LOAD_FUNCPTR(ImeGetImeMenuItems);
335 /* make sure our classname is WCHAR */
336 if (!is_kbd_ime_unicode(ptr))
339 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ptr->imeClassName,
341 lstrcpyW(ptr->imeClassName, bufW);
346 list_add_head(&ImmHklList,&ptr->entry);
352 static void IMM_FreeAllImmHkl(void)
354 ImmHkl *ptr,*cursor2;
356 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &ImmHklList, ImmHkl, entry)
358 list_remove(&ptr->entry);
362 FreeLibrary(ptr->hIME);
365 DestroyWindow(ptr->UIWnd);
366 HeapFree(GetProcessHeap(),0,ptr);
370 static void IMM_RegisterMessages(void)
372 WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
373 WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
374 WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
375 WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
376 WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
377 WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
378 WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
381 static void IMM_RegisterIMEClass(void)
385 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
387 wndClass.style = CS_GLOBALCLASS;
388 wndClass.lpfnWndProc = (WNDPROC) DefIME_WindowProc;
389 wndClass.cbWndExtra = 2 * sizeof(LONG_PTR);
390 wndClass.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
391 wndClass.lpszClassName = szwIME;
393 RegisterClassW(&wndClass);
396 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
398 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
401 case DLL_PROCESS_ATTACH:
402 IMM_RegisterMessages();
403 tlsIndex = TlsAlloc();
404 if (tlsIndex == TLS_OUT_OF_INDEXES)
406 IMM_RegisterIMEClass();
408 case DLL_THREAD_ATTACH:
410 case DLL_THREAD_DETACH:
411 IMM_FreeThreadData();
413 case DLL_PROCESS_DETACH:
414 IMM_FreeThreadData();
417 UnregisterClassW(szwIME, NULL);
423 /* for posting messages as the IME */
424 static void ImmInternalPostIMEMessage(InputContextData *data, UINT msg, WPARAM wParam, LPARAM lParam)
426 HWND target = GetFocus();
428 PostMessageW(data->IMC.hWnd,msg,wParam,lParam);
430 PostMessageW(target, msg, wParam, lParam);
433 static LRESULT ImmInternalSendIMENotify(InputContextData *data, WPARAM notify, LPARAM lParam)
437 target = data->IMC.hWnd;
438 if (!target) target = GetFocus();
441 return SendMessageW(target, WM_IME_NOTIFY, notify, lParam);
446 static HIMCC ImmCreateBlankCompStr(void)
449 LPCOMPOSITIONSTRING ptr;
450 rc = ImmCreateIMCC(sizeof(COMPOSITIONSTRING));
451 ptr = ImmLockIMCC(rc);
452 memset(ptr,0,sizeof(COMPOSITIONSTRING));
453 ptr->dwSize = sizeof(COMPOSITIONSTRING);
458 /***********************************************************************
459 * ImmAssociateContext (IMM32.@)
461 HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
464 InputContextData *data = hIMC;
466 TRACE("(%p, %p):\n", hWnd, hIMC);
468 if (!IMM_GetThreadData()->defaultContext)
469 IMM_GetThreadData()->defaultContext = ImmCreateContext();
472 * If already associated just return
474 if (hIMC && data->IMC.hWnd == hWnd)
479 old = RemovePropW(hWnd,szwWineIMCProperty);
482 old = IMM_GetThreadData()->defaultContext;
483 else if (old == (HIMC)-1)
486 if (hIMC != IMM_GetThreadData()->defaultContext)
488 if (hIMC == NULL) /* Meaning disable imm for that window*/
489 SetPropW(hWnd,szwWineIMCProperty,(HANDLE)-1);
491 SetPropW(hWnd,szwWineIMCProperty,hIMC);
496 InputContextData *old_data = old;
497 if (old_data->IMC.hWnd == hWnd)
498 old_data->IMC.hWnd = NULL;
505 if (IsWindow(data->IMC.hWnd))
508 * Post a message that your context is switching
510 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
513 data->IMC.hWnd = hWnd;
515 if (IsWindow(data->IMC.hWnd))
518 * Post a message that your context is switching
520 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
528 * Helper function for ImmAssociateContextEx
530 static BOOL CALLBACK _ImmAssociateContextExEnumProc(HWND hwnd, LPARAM lParam)
532 HIMC hImc = (HIMC)lParam;
533 ImmAssociateContext(hwnd,hImc);
537 /***********************************************************************
538 * ImmAssociateContextEx (IMM32.@)
540 BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
542 TRACE("(%p, %p, 0x%x):\n", hWnd, hIMC, dwFlags);
544 if (!IMM_GetThreadData()->defaultContext)
545 IMM_GetThreadData()->defaultContext = ImmCreateContext();
547 if (!hWnd) return FALSE;
552 ImmAssociateContext(hWnd,hIMC);
555 ImmAssociateContext(hWnd,IMM_GetThreadData()->defaultContext);
557 case IACE_IGNORENOCONTEXT:
558 if (GetPropW(hWnd,szwWineIMCProperty))
559 ImmAssociateContext(hWnd,hIMC);
562 EnumChildWindows(hWnd,_ImmAssociateContextExEnumProc,(LPARAM)hIMC);
565 FIXME("Unknown dwFlags 0x%x\n",dwFlags);
570 /***********************************************************************
571 * ImmConfigureIMEA (IMM32.@)
573 BOOL WINAPI ImmConfigureIMEA(
574 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
576 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
578 TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
580 if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
583 if (immHkl->hIME && immHkl->pImeConfigure)
585 if (dwMode != IME_CONFIG_REGISTERWORD || !is_kbd_ime_unicode(immHkl))
586 return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
590 REGISTERWORDA *rwa = lpData;
593 rww.lpReading = strdupAtoW(rwa->lpReading);
594 rww.lpWord = strdupAtoW(rwa->lpWord);
595 rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rww);
596 HeapFree(GetProcessHeap(),0,rww.lpReading);
597 HeapFree(GetProcessHeap(),0,rww.lpWord);
605 /***********************************************************************
606 * ImmConfigureIMEW (IMM32.@)
608 BOOL WINAPI ImmConfigureIMEW(
609 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
611 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
613 TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
615 if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
618 if (immHkl->hIME && immHkl->pImeConfigure)
620 if (dwMode != IME_CONFIG_REGISTERWORD || is_kbd_ime_unicode(immHkl))
621 return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
624 REGISTERWORDW *rww = lpData;
628 rwa.lpReading = strdupWtoA(rww->lpReading);
629 rwa.lpWord = strdupWtoA(rww->lpWord);
630 rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rwa);
631 HeapFree(GetProcessHeap(),0,rwa.lpReading);
632 HeapFree(GetProcessHeap(),0,rwa.lpWord);
640 /***********************************************************************
641 * ImmCreateContext (IMM32.@)
643 HIMC WINAPI ImmCreateContext(void)
645 InputContextData *new_context;
649 new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
652 new_context->immKbd = IMM_GetImmHkl(GetKeyboardLayout(0));
654 if (!new_context->immKbd->hIME)
656 TRACE("IME dll could not be loaded\n");
657 HeapFree(GetProcessHeap(),0,new_context);
661 /* the HIMCCs are never NULL */
662 new_context->IMC.hCompStr = ImmCreateBlankCompStr();
663 new_context->IMC.hMsgBuf = ImmCreateIMCC(0);
664 new_context->IMC.hCandInfo = ImmCreateIMCC(sizeof(CANDIDATEINFO));
665 ci = ImmLockIMCC(new_context->IMC.hCandInfo);
666 memset(ci,0,sizeof(CANDIDATEINFO));
667 ci->dwSize = sizeof(CANDIDATEINFO);
668 ImmUnlockIMCC(new_context->IMC.hCandInfo);
669 new_context->IMC.hGuideLine = ImmCreateIMCC(sizeof(GUIDELINE));
670 gl = ImmLockIMCC(new_context->IMC.hGuideLine);
671 memset(gl,0,sizeof(GUIDELINE));
672 gl->dwSize = sizeof(GUIDELINE);
673 ImmUnlockIMCC(new_context->IMC.hGuideLine);
675 /* Initialize the IME Private */
676 new_context->IMC.hPrivate = ImmCreateIMCC(new_context->immKbd->imeInfo.dwPrivateDataSize);
678 if (!new_context->immKbd->pImeSelect(new_context, TRUE))
680 TRACE("Selection of IME failed\n");
681 IMM_DestroyContext(new_context);
684 SendMessageW(GetFocus(), WM_IME_SELECT, TRUE, (LPARAM)GetKeyboardLayout(0));
686 new_context->immKbd->uSelected++;
687 TRACE("Created context %p\n",new_context);
692 static BOOL IMM_DestroyContext(HIMC hIMC)
694 InputContextData *data = hIMC;
696 TRACE("Destroying %p\n",hIMC);
700 data->immKbd->uSelected --;
701 data->immKbd->pImeSelect(hIMC, FALSE);
702 SendMessageW(data->IMC.hWnd, WM_IME_SELECT, FALSE, (LPARAM)GetKeyboardLayout(0));
704 ImmDestroyIMCC(data->IMC.hCompStr);
705 ImmDestroyIMCC(data->IMC.hCandInfo);
706 ImmDestroyIMCC(data->IMC.hGuideLine);
707 ImmDestroyIMCC(data->IMC.hPrivate);
708 ImmDestroyIMCC(data->IMC.hMsgBuf);
710 HeapFree(GetProcessHeap(),0,data);
715 /***********************************************************************
716 * ImmDestroyContext (IMM32.@)
718 BOOL WINAPI ImmDestroyContext(HIMC hIMC)
720 if (hIMC != IMM_GetThreadData()->defaultContext)
721 return IMM_DestroyContext(hIMC);
726 /***********************************************************************
727 * ImmDisableIME (IMM32.@)
729 BOOL WINAPI ImmDisableIME(DWORD idThread)
731 FIXME("(%d): stub\n", idThread);
735 /***********************************************************************
736 * ImmEnumRegisterWordA (IMM32.@)
738 UINT WINAPI ImmEnumRegisterWordA(
739 HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
740 LPCSTR lpszReading, DWORD dwStyle,
741 LPCSTR lpszRegister, LPVOID lpData)
743 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
744 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc,
745 debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister), lpData);
746 if (immHkl->hIME && immHkl->pImeEnumRegisterWord)
748 if (!is_kbd_ime_unicode(immHkl))
749 return immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc,
750 (LPCWSTR)lpszReading, dwStyle, (LPCWSTR)lpszRegister, lpData);
753 LPWSTR lpszwReading = strdupAtoW(lpszReading);
754 LPWSTR lpszwRegister = strdupAtoW(lpszRegister);
757 rc = immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc,
758 lpszwReading, dwStyle, lpszwRegister,
761 HeapFree(GetProcessHeap(),0,lpszwReading);
762 HeapFree(GetProcessHeap(),0,lpszwRegister);
770 /***********************************************************************
771 * ImmEnumRegisterWordW (IMM32.@)
773 UINT WINAPI ImmEnumRegisterWordW(
774 HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
775 LPCWSTR lpszReading, DWORD dwStyle,
776 LPCWSTR lpszRegister, LPVOID lpData)
778 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
779 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc,
780 debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister), lpData);
781 if (immHkl->hIME && immHkl->pImeEnumRegisterWord)
783 if (is_kbd_ime_unicode(immHkl))
784 return immHkl->pImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle,
785 lpszRegister, lpData);
788 LPSTR lpszaReading = strdupWtoA(lpszReading);
789 LPSTR lpszaRegister = strdupWtoA(lpszRegister);
792 rc = immHkl->pImeEnumRegisterWord(lpfnEnumProc, (LPCWSTR)lpszaReading,
793 dwStyle, (LPCWSTR)lpszaRegister, lpData);
795 HeapFree(GetProcessHeap(),0,lpszaReading);
796 HeapFree(GetProcessHeap(),0,lpszaRegister);
804 static inline BOOL EscapeRequiresWA(UINT uEscape)
806 if (uEscape == IME_ESC_GET_EUDC_DICTIONARY ||
807 uEscape == IME_ESC_SET_EUDC_DICTIONARY ||
808 uEscape == IME_ESC_IME_NAME ||
809 uEscape == IME_ESC_GETHELPFILENAME)
814 /***********************************************************************
815 * ImmEscapeA (IMM32.@)
817 LRESULT WINAPI ImmEscapeA(
819 UINT uEscape, LPVOID lpData)
821 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
822 TRACE("(%p, %p, %d, %p):\n", hKL, hIMC, uEscape, lpData);
824 if (immHkl->hIME && immHkl->pImeEscape)
826 if (!EscapeRequiresWA(uEscape) || !is_kbd_ime_unicode(immHkl))
827 return immHkl->pImeEscape(hIMC,uEscape,lpData);
830 WCHAR buffer[81]; /* largest required buffer should be 80 */
832 if (uEscape == IME_ESC_SET_EUDC_DICTIONARY)
834 MultiByteToWideChar(CP_ACP,0,lpData,-1,buffer,81);
835 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
839 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
840 WideCharToMultiByte(CP_ACP,0,buffer,-1,lpData,80, NULL, NULL);
849 /***********************************************************************
850 * ImmEscapeW (IMM32.@)
852 LRESULT WINAPI ImmEscapeW(
854 UINT uEscape, LPVOID lpData)
856 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
857 TRACE("(%p, %p, %d, %p):\n", hKL, hIMC, uEscape, lpData);
859 if (immHkl->hIME && immHkl->pImeEscape)
861 if (!EscapeRequiresWA(uEscape) || is_kbd_ime_unicode(immHkl))
862 return immHkl->pImeEscape(hIMC,uEscape,lpData);
865 CHAR buffer[81]; /* largest required buffer should be 80 */
867 if (uEscape == IME_ESC_SET_EUDC_DICTIONARY)
869 WideCharToMultiByte(CP_ACP,0,lpData,-1,buffer,81, NULL, NULL);
870 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
874 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
875 MultiByteToWideChar(CP_ACP,0,buffer,-1,lpData,80);
884 /***********************************************************************
885 * ImmGetCandidateListA (IMM32.@)
887 DWORD WINAPI ImmGetCandidateListA(
888 HIMC hIMC, DWORD dwIndex,
889 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
891 InputContextData *data = hIMC;
892 LPCANDIDATEINFO candinfo;
893 LPCANDIDATELIST candlist;
896 TRACE("%p, %d, %p, %d\n", hIMC, dwIndex, lpCandList, dwBufLen);
898 if (!data || !data->IMC.hCandInfo)
901 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
902 if ( dwIndex >= candinfo->dwCount ||
903 dwIndex >= (sizeof(candinfo->dwOffset) / sizeof(DWORD)) )
906 candlist = (LPCANDIDATELIST)((LPBYTE)candinfo + candinfo->dwOffset[dwIndex]);
907 if ( !candlist->dwSize || !candlist->dwCount )
910 if ( !is_himc_ime_unicode(data) )
912 ret = candlist->dwSize;
913 if ( lpCandList && dwBufLen >= ret )
914 memcpy(lpCandList, candlist, ret);
917 ret = convert_candidatelist_WtoA( candlist, lpCandList, dwBufLen);
920 ImmUnlockIMCC(data->IMC.hCandInfo);
924 /***********************************************************************
925 * ImmGetCandidateListCountA (IMM32.@)
927 DWORD WINAPI ImmGetCandidateListCountA(
928 HIMC hIMC, LPDWORD lpdwListCount)
930 InputContextData *data = hIMC;
931 LPCANDIDATEINFO candinfo;
934 TRACE("%p, %p\n", hIMC, lpdwListCount);
936 if (!data || !lpdwListCount || !data->IMC.hCandInfo)
939 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
941 *lpdwListCount = count = candinfo->dwCount;
943 if ( !is_himc_ime_unicode(data) )
944 ret = candinfo->dwSize;
947 ret = sizeof(CANDIDATEINFO);
949 ret += ImmGetCandidateListA(hIMC, count, NULL, 0);
952 ImmUnlockIMCC(data->IMC.hCandInfo);
956 /***********************************************************************
957 * ImmGetCandidateListCountW (IMM32.@)
959 DWORD WINAPI ImmGetCandidateListCountW(
960 HIMC hIMC, LPDWORD lpdwListCount)
962 InputContextData *data = hIMC;
963 LPCANDIDATEINFO candinfo;
966 TRACE("%p, %p\n", hIMC, lpdwListCount);
968 if (!data || !lpdwListCount || !data->IMC.hCandInfo)
971 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
973 *lpdwListCount = count = candinfo->dwCount;
975 if ( is_himc_ime_unicode(data) )
976 ret = candinfo->dwSize;
979 ret = sizeof(CANDIDATEINFO);
981 ret += ImmGetCandidateListW(hIMC, count, NULL, 0);
984 ImmUnlockIMCC(data->IMC.hCandInfo);
988 /***********************************************************************
989 * ImmGetCandidateListW (IMM32.@)
991 DWORD WINAPI ImmGetCandidateListW(
992 HIMC hIMC, DWORD dwIndex,
993 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
995 InputContextData *data = hIMC;
996 LPCANDIDATEINFO candinfo;
997 LPCANDIDATELIST candlist;
1000 TRACE("%p, %d, %p, %d\n", hIMC, dwIndex, lpCandList, dwBufLen);
1002 if (!data || !data->IMC.hCandInfo)
1005 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
1006 if ( dwIndex >= candinfo->dwCount ||
1007 dwIndex >= (sizeof(candinfo->dwOffset) / sizeof(DWORD)) )
1010 candlist = (LPCANDIDATELIST)((LPBYTE)candinfo + candinfo->dwOffset[dwIndex]);
1011 if ( !candlist->dwSize || !candlist->dwCount )
1014 if ( is_himc_ime_unicode(data) )
1016 ret = candlist->dwSize;
1017 if ( lpCandList && dwBufLen >= ret )
1018 memcpy(lpCandList, candlist, ret);
1021 ret = convert_candidatelist_AtoW( candlist, lpCandList, dwBufLen);
1024 ImmUnlockIMCC(data->IMC.hCandInfo);
1028 /***********************************************************************
1029 * ImmGetCandidateWindow (IMM32.@)
1031 BOOL WINAPI ImmGetCandidateWindow(
1032 HIMC hIMC, DWORD dwIndex, LPCANDIDATEFORM lpCandidate)
1034 InputContextData *data = hIMC;
1036 TRACE("%p, %d, %p\n", hIMC, dwIndex, lpCandidate);
1038 if (!data || !lpCandidate)
1041 if ( dwIndex >= (sizeof(data->IMC.cfCandForm) / sizeof(CANDIDATEFORM)) )
1044 *lpCandidate = data->IMC.cfCandForm[dwIndex];
1049 /***********************************************************************
1050 * ImmGetCompositionFontA (IMM32.@)
1052 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
1057 TRACE("(%p, %p):\n", hIMC, lplf);
1059 rc = ImmGetCompositionFontW(hIMC,&lfW);
1063 memcpy(lplf,&lfW,sizeof(LOGFONTA));
1064 WideCharToMultiByte(CP_ACP, 0, lfW.lfFaceName, -1, lplf->lfFaceName,
1065 LF_FACESIZE, NULL, NULL);
1069 /***********************************************************************
1070 * ImmGetCompositionFontW (IMM32.@)
1072 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
1074 InputContextData *data = hIMC;
1076 TRACE("(%p, %p):\n", hIMC, lplf);
1081 *lplf = data->IMC.lfFont.W;
1087 /* Helpers for the GetCompositionString functions */
1089 static INT CopyCompStringIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE target, INT tlen,
1094 if (is_himc_ime_unicode(data) && !unicode)
1095 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)source, slen, (LPSTR)target, tlen, NULL, NULL);
1096 else if (!is_himc_ime_unicode(data) && unicode)
1097 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)source, slen, (LPWSTR)target, tlen) * sizeof(WCHAR);
1100 int dlen = (unicode)?sizeof(WCHAR):sizeof(CHAR);
1101 memcpy( target, source, min(slen,tlen)*dlen);
1108 static INT CopyCompAttrIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE ssource, INT sslen,
1109 LPBYTE target, INT tlen, BOOL unicode )
1113 if (is_himc_ime_unicode(data) && !unicode)
1115 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource, sslen, NULL, 0, NULL, NULL);
1118 const BYTE *src = source;
1119 LPBYTE dst = target;
1120 int i, j = 0, k = 0;
1124 for (i = 0; i < sslen; ++i)
1128 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)ssource + i, 1,
1129 NULL, 0, NULL, NULL);
1130 for (; len > 0; --len)
1143 else if (!is_himc_ime_unicode(data) && unicode)
1145 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource, sslen, NULL, 0);
1148 const BYTE *src = source;
1149 LPBYTE dst = target;
1154 for (i = 0; i < sslen; ++i)
1156 if (IsDBCSLeadByte(((LPSTR)ssource)[i]))
1169 memcpy( target, source, min(slen,tlen));
1176 static INT CopyCompClauseIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE ssource,
1177 LPBYTE target, INT tlen, BOOL unicode )
1181 if (is_himc_ime_unicode(data) && !unicode)
1189 tlen /= sizeof (DWORD);
1190 for (i = 0; i < tlen; ++i)
1192 ((DWORD *)target)[i] = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource,
1193 ((DWORD *)source)[i],
1197 rc = sizeof (DWORD) * i;
1202 else if (!is_himc_ime_unicode(data) && unicode)
1210 tlen /= sizeof (DWORD);
1211 for (i = 0; i < tlen; ++i)
1213 ((DWORD *)target)[i] = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource,
1214 ((DWORD *)source)[i],
1217 rc = sizeof (DWORD) * i;
1224 memcpy( target, source, min(slen,tlen));
1231 static INT CopyCompOffsetIMEtoClient(InputContextData *data, DWORD offset, LPBYTE ssource, BOOL unicode)
1235 if (is_himc_ime_unicode(data) && !unicode)
1237 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource, offset, NULL, 0, NULL, NULL);
1239 else if (!is_himc_ime_unicode(data) && unicode)
1241 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource, offset, NULL, 0);
1249 static LONG ImmGetCompositionStringT( HIMC hIMC, DWORD dwIndex, LPVOID lpBuf,
1250 DWORD dwBufLen, BOOL unicode)
1253 InputContextData *data = hIMC;
1254 LPCOMPOSITIONSTRING compstr;
1257 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
1262 if (!data->IMC.hCompStr)
1265 compdata = ImmLockIMCC(data->IMC.hCompStr);
1266 compstr = (LPCOMPOSITIONSTRING)compdata;
1271 TRACE("GCS_RESULTSTR\n");
1272 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwResultStrOffset, compstr->dwResultStrLen, lpBuf, dwBufLen, unicode);
1275 TRACE("GCS_COMPSTR\n");
1276 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwCompStrOffset, compstr->dwCompStrLen, lpBuf, dwBufLen, unicode);
1279 TRACE("GCS_COMPATTR\n");
1280 rc = CopyCompAttrIMEtoClient(data, compdata + compstr->dwCompAttrOffset, compstr->dwCompAttrLen,
1281 compdata + compstr->dwCompStrOffset, compstr->dwCompStrLen,
1282 lpBuf, dwBufLen, unicode);
1284 case GCS_COMPCLAUSE:
1285 TRACE("GCS_COMPCLAUSE\n");
1286 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwCompClauseOffset,compstr->dwCompClauseLen,
1287 compdata + compstr->dwCompStrOffset,
1288 lpBuf, dwBufLen, unicode);
1290 case GCS_RESULTCLAUSE:
1291 TRACE("GCS_RESULTCLAUSE\n");
1292 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwResultClauseOffset,compstr->dwResultClauseLen,
1293 compdata + compstr->dwResultStrOffset,
1294 lpBuf, dwBufLen, unicode);
1296 case GCS_RESULTREADSTR:
1297 TRACE("GCS_RESULTREADSTR\n");
1298 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwResultReadStrOffset, compstr->dwResultReadStrLen, lpBuf, dwBufLen, unicode);
1300 case GCS_RESULTREADCLAUSE:
1301 TRACE("GCS_RESULTREADCLAUSE\n");
1302 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwResultReadClauseOffset,compstr->dwResultReadClauseLen,
1303 compdata + compstr->dwResultStrOffset,
1304 lpBuf, dwBufLen, unicode);
1306 case GCS_COMPREADSTR:
1307 TRACE("GCS_COMPREADSTR\n");
1308 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwCompReadStrOffset, compstr->dwCompReadStrLen, lpBuf, dwBufLen, unicode);
1310 case GCS_COMPREADATTR:
1311 TRACE("GCS_COMPREADATTR\n");
1312 rc = CopyCompAttrIMEtoClient(data, compdata + compstr->dwCompReadAttrOffset, compstr->dwCompReadAttrLen,
1313 compdata + compstr->dwCompReadStrOffset, compstr->dwCompReadStrLen,
1314 lpBuf, dwBufLen, unicode);
1316 case GCS_COMPREADCLAUSE:
1317 TRACE("GCS_COMPREADCLAUSE\n");
1318 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwCompReadClauseOffset,compstr->dwCompReadClauseLen,
1319 compdata + compstr->dwCompStrOffset,
1320 lpBuf, dwBufLen, unicode);
1323 TRACE("GCS_CURSORPOS\n");
1324 rc = CopyCompOffsetIMEtoClient(data, compstr->dwCursorPos, compdata + compstr->dwCompStrOffset, unicode);
1326 case GCS_DELTASTART:
1327 TRACE("GCS_DELTASTART\n");
1328 rc = CopyCompOffsetIMEtoClient(data, compstr->dwDeltaStart, compdata + compstr->dwCompStrOffset, unicode);
1331 FIXME("Unhandled index 0x%x\n",dwIndex);
1335 ImmUnlockIMCC(data->IMC.hCompStr);
1340 /***********************************************************************
1341 * ImmGetCompositionStringA (IMM32.@)
1343 LONG WINAPI ImmGetCompositionStringA(
1344 HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
1346 return ImmGetCompositionStringT(hIMC, dwIndex, lpBuf, dwBufLen, FALSE);
1350 /***********************************************************************
1351 * ImmGetCompositionStringW (IMM32.@)
1353 LONG WINAPI ImmGetCompositionStringW(
1354 HIMC hIMC, DWORD dwIndex,
1355 LPVOID lpBuf, DWORD dwBufLen)
1357 return ImmGetCompositionStringT(hIMC, dwIndex, lpBuf, dwBufLen, TRUE);
1360 /***********************************************************************
1361 * ImmGetCompositionWindow (IMM32.@)
1363 BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
1365 InputContextData *data = hIMC;
1367 TRACE("(%p, %p)\n", hIMC, lpCompForm);
1372 *lpCompForm = data->IMC.cfCompForm;
1376 /***********************************************************************
1377 * ImmGetContext (IMM32.@)
1380 HIMC WINAPI ImmGetContext(HWND hWnd)
1384 TRACE("%p\n", hWnd);
1386 if (!IsWindow(hWnd))
1388 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1391 if (!IMM_GetThreadData()->defaultContext)
1392 IMM_GetThreadData()->defaultContext = ImmCreateContext();
1394 rc = GetPropW(hWnd,szwWineIMCProperty);
1397 else if (rc == NULL)
1398 rc = IMM_GetThreadData()->defaultContext;
1402 InputContextData *data = rc;
1403 data->IMC.hWnd = hWnd;
1405 TRACE("returning %p\n", rc);
1410 /***********************************************************************
1411 * ImmGetConversionListA (IMM32.@)
1413 DWORD WINAPI ImmGetConversionListA(
1415 LPCSTR pSrc, LPCANDIDATELIST lpDst,
1416 DWORD dwBufLen, UINT uFlag)
1418 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1419 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_a(pSrc), lpDst,
1421 if (immHkl->hIME && immHkl->pImeConversionList)
1423 if (!is_kbd_ime_unicode(immHkl))
1424 return immHkl->pImeConversionList(hIMC,(LPCWSTR)pSrc,lpDst,dwBufLen,uFlag);
1427 LPCANDIDATELIST lpwDst;
1429 LPWSTR pwSrc = strdupAtoW(pSrc);
1431 len = immHkl->pImeConversionList(hIMC, pwSrc, NULL, 0, uFlag);
1432 lpwDst = HeapAlloc(GetProcessHeap(), 0, len);
1435 immHkl->pImeConversionList(hIMC, pwSrc, lpwDst, len, uFlag);
1436 ret = convert_candidatelist_WtoA( lpwDst, lpDst, dwBufLen);
1437 HeapFree(GetProcessHeap(), 0, lpwDst);
1439 HeapFree(GetProcessHeap(), 0, pwSrc);
1448 /***********************************************************************
1449 * ImmGetConversionListW (IMM32.@)
1451 DWORD WINAPI ImmGetConversionListW(
1453 LPCWSTR pSrc, LPCANDIDATELIST lpDst,
1454 DWORD dwBufLen, UINT uFlag)
1456 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1457 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_w(pSrc), lpDst,
1459 if (immHkl->hIME && immHkl->pImeConversionList)
1461 if (is_kbd_ime_unicode(immHkl))
1462 return immHkl->pImeConversionList(hIMC,pSrc,lpDst,dwBufLen,uFlag);
1465 LPCANDIDATELIST lpaDst;
1467 LPSTR paSrc = strdupWtoA(pSrc);
1469 len = immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, NULL, 0, uFlag);
1470 lpaDst = HeapAlloc(GetProcessHeap(), 0, len);
1473 immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, lpaDst, len, uFlag);
1474 ret = convert_candidatelist_AtoW( lpaDst, lpDst, dwBufLen);
1475 HeapFree(GetProcessHeap(), 0, lpaDst);
1477 HeapFree(GetProcessHeap(), 0, paSrc);
1486 /***********************************************************************
1487 * ImmGetConversionStatus (IMM32.@)
1489 BOOL WINAPI ImmGetConversionStatus(
1490 HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
1492 InputContextData *data = hIMC;
1494 TRACE("%p %p %p\n", hIMC, lpfdwConversion, lpfdwSentence);
1499 if (lpfdwConversion)
1500 *lpfdwConversion = data->IMC.fdwConversion;
1502 *lpfdwSentence = data->IMC.fdwSentence;
1507 /***********************************************************************
1508 * ImmGetDefaultIMEWnd (IMM32.@)
1510 HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
1512 if (IMM_GetThreadData()->hwndDefault == NULL)
1513 IMM_GetThreadData()->hwndDefault = CreateWindowExW( WS_EX_TOOLWINDOW,
1514 szwIME, NULL, WS_POPUP, 0, 0, 1, 1, 0, 0, 0, 0);
1515 TRACE("Default is %p\n",IMM_GetThreadData()->hwndDefault);
1516 return IMM_GetThreadData()->hwndDefault;
1519 /***********************************************************************
1520 * ImmGetDescriptionA (IMM32.@)
1522 UINT WINAPI ImmGetDescriptionA(
1523 HKL hKL, LPSTR lpszDescription, UINT uBufLen)
1528 TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
1530 /* find out how many characters in the unicode buffer */
1531 len = ImmGetDescriptionW( hKL, NULL, 0 );
1533 /* allocate a buffer of that size */
1534 buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
1538 /* fetch the unicode buffer */
1539 len = ImmGetDescriptionW( hKL, buf, len + 1 );
1541 /* convert it back to ASCII */
1542 len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
1543 lpszDescription, uBufLen, NULL, NULL );
1545 HeapFree( GetProcessHeap(), 0, buf );
1550 /***********************************************************************
1551 * ImmGetDescriptionW (IMM32.@)
1553 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
1555 static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
1557 FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
1559 if (!uBufLen) return lstrlenW( name );
1560 lstrcpynW( lpszDescription, name, uBufLen );
1561 return lstrlenW( lpszDescription );
1564 /***********************************************************************
1565 * ImmGetGuideLineA (IMM32.@)
1567 DWORD WINAPI ImmGetGuideLineA(
1568 HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
1570 FIXME("(%p, %d, %s, %d): stub\n",
1571 hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
1573 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1577 /***********************************************************************
1578 * ImmGetGuideLineW (IMM32.@)
1580 DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
1582 FIXME("(%p, %d, %s, %d): stub\n",
1583 hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
1585 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1589 /***********************************************************************
1590 * ImmGetIMEFileNameA (IMM32.@)
1592 UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen)
1595 UINT wBufLen = uBufLen;
1598 if (uBufLen && lpszFileName)
1599 bufW = HeapAlloc(GetProcessHeap(),0,uBufLen * sizeof(WCHAR));
1600 else /* We need this to get the number of byte required */
1602 bufW = HeapAlloc(GetProcessHeap(),0,MAX_PATH * sizeof(WCHAR));
1606 rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen);
1610 if (uBufLen && lpszFileName)
1611 rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName,
1612 uBufLen, NULL, NULL);
1613 else /* get the length */
1614 rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL,
1618 HeapFree(GetProcessHeap(),0,bufW);
1622 /***********************************************************************
1623 * ImmGetIMEFileNameW (IMM32.@)
1625 UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
1630 WCHAR regKey[sizeof(szImeRegFmt)/sizeof(WCHAR)+8];
1632 wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hKL );
1633 rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
1634 if (rc != ERROR_SUCCESS)
1641 rc = RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, NULL, &length);
1643 if (rc != ERROR_SUCCESS)
1649 if (length > uBufLen * sizeof(WCHAR) || !lpszFileName)
1654 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1658 return length / sizeof(WCHAR);
1661 RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, lpszFileName, &length);
1665 return length / sizeof(WCHAR);
1668 /***********************************************************************
1669 * ImmGetOpenStatus (IMM32.@)
1671 BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
1673 InputContextData *data = hIMC;
1679 TRACE("(%p): semi-stub\n", hIMC);
1682 FIXME("(%p): semi-stub\n", hIMC);
1684 return data->IMC.fOpen;
1687 /***********************************************************************
1688 * ImmGetProperty (IMM32.@)
1690 DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
1695 TRACE("(%p, %d)\n", hKL, fdwIndex);
1696 kbd = IMM_GetImmHkl(hKL);
1698 if (kbd && kbd->hIME)
1702 case IGP_PROPERTY: rc = kbd->imeInfo.fdwProperty; break;
1703 case IGP_CONVERSION: rc = kbd->imeInfo.fdwConversionCaps; break;
1704 case IGP_SENTENCE: rc = kbd->imeInfo.fdwSentenceCaps; break;
1705 case IGP_SETCOMPSTR: rc = kbd->imeInfo.fdwSCSCaps; break;
1706 case IGP_SELECT: rc = kbd->imeInfo.fdwSelectCaps; break;
1707 case IGP_GETIMEVERSION: rc = IMEVER_0400; break;
1708 case IGP_UI: rc = 0; break;
1715 /***********************************************************************
1716 * ImmGetRegisterWordStyleA (IMM32.@)
1718 UINT WINAPI ImmGetRegisterWordStyleA(
1719 HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
1721 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1722 TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
1723 if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
1725 if (!is_kbd_ime_unicode(immHkl))
1726 return immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)lpStyleBuf);
1732 rc = immHkl->pImeGetRegisterWordStyle(nItem,&sbw);
1733 WideCharToMultiByte(CP_ACP, 0, sbw.szDescription, -1,
1734 lpStyleBuf->szDescription, 32, NULL, NULL);
1735 lpStyleBuf->dwStyle = sbw.dwStyle;
1743 /***********************************************************************
1744 * ImmGetRegisterWordStyleW (IMM32.@)
1746 UINT WINAPI ImmGetRegisterWordStyleW(
1747 HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
1749 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1750 TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
1751 if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
1753 if (is_kbd_ime_unicode(immHkl))
1754 return immHkl->pImeGetRegisterWordStyle(nItem,lpStyleBuf);
1760 rc = immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)&sba);
1761 MultiByteToWideChar(CP_ACP, 0, sba.szDescription, -1,
1762 lpStyleBuf->szDescription, 32);
1763 lpStyleBuf->dwStyle = sba.dwStyle;
1771 /***********************************************************************
1772 * ImmGetStatusWindowPos (IMM32.@)
1774 BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1776 InputContextData *data = hIMC;
1778 TRACE("(%p, %p)\n", hIMC, lpptPos);
1780 if (!data || !lpptPos)
1783 *lpptPos = data->IMC.ptStatusWndPos;
1788 /***********************************************************************
1789 * ImmGetVirtualKey (IMM32.@)
1791 UINT WINAPI ImmGetVirtualKey(HWND hWnd)
1793 OSVERSIONINFOA version;
1794 InputContextData *data = ImmGetContext( hWnd );
1795 TRACE("%p\n", hWnd);
1798 return data->lastVK;
1800 version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
1801 GetVersionExA( &version );
1802 switch(version.dwPlatformId)
1804 case VER_PLATFORM_WIN32_WINDOWS:
1805 return VK_PROCESSKEY;
1806 case VER_PLATFORM_WIN32_NT:
1809 FIXME("%d not supported\n",version.dwPlatformId);
1810 return VK_PROCESSKEY;
1814 /***********************************************************************
1815 * ImmInstallIMEA (IMM32.@)
1817 HKL WINAPI ImmInstallIMEA(
1818 LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
1820 LPWSTR lpszwIMEFileName;
1821 LPWSTR lpszwLayoutText;
1824 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName),
1825 debugstr_a(lpszLayoutText));
1827 lpszwIMEFileName = strdupAtoW(lpszIMEFileName);
1828 lpszwLayoutText = strdupAtoW(lpszLayoutText);
1830 hkl = ImmInstallIMEW(lpszwIMEFileName, lpszwLayoutText);
1832 HeapFree(GetProcessHeap(),0,lpszwIMEFileName);
1833 HeapFree(GetProcessHeap(),0,lpszwLayoutText);
1837 /***********************************************************************
1838 * ImmInstallIMEW (IMM32.@)
1840 HKL WINAPI ImmInstallIMEW(
1841 LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
1843 INT lcid = GetUserDefaultLCID();
1848 WCHAR regKey[sizeof(szImeRegFmt)/sizeof(WCHAR)+8];
1850 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName),
1851 debugstr_w(lpszLayoutText));
1853 /* Start with 2. e001 will be blank and so default to the wine internal IME */
1856 while (count < 0xfff)
1858 DWORD disposition = 0;
1860 hkl = (HKL)MAKELPARAM( lcid, 0xe000 | count );
1861 wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hkl);
1863 rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, regKey, 0, NULL, 0, KEY_WRITE, NULL, &hkey, &disposition);
1864 if (rc == ERROR_SUCCESS && disposition == REG_CREATED_NEW_KEY)
1866 else if (rc == ERROR_SUCCESS)
1874 WARN("Unable to find slot to install IME\n");
1878 if (rc == ERROR_SUCCESS)
1880 rc = RegSetValueExW(hkey, szImeFileW, 0, REG_SZ, (const BYTE*)lpszIMEFileName,
1881 (lstrlenW(lpszIMEFileName) + 1) * sizeof(WCHAR));
1882 if (rc == ERROR_SUCCESS)
1883 rc = RegSetValueExW(hkey, szLayoutTextW, 0, REG_SZ, (const BYTE*)lpszLayoutText,
1884 (lstrlenW(lpszLayoutText) + 1) * sizeof(WCHAR));
1890 WARN("Unable to set IME registry values\n");
1895 /***********************************************************************
1896 * ImmIsIME (IMM32.@)
1898 BOOL WINAPI ImmIsIME(HKL hKL)
1901 TRACE("(%p):\n", hKL);
1902 ptr = IMM_GetImmHkl(hKL);
1903 return (ptr && ptr->hIME);
1906 /***********************************************************************
1907 * ImmIsUIMessageA (IMM32.@)
1909 BOOL WINAPI ImmIsUIMessageA(
1910 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1914 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1915 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1916 (msg == WM_IME_SETCONTEXT) ||
1917 (msg == WM_IME_NOTIFY) ||
1918 (msg == WM_IME_COMPOSITIONFULL) ||
1919 (msg == WM_IME_SELECT) ||
1920 (msg == 0x287 /* FIXME: WM_IME_SYSTEM */) ||
1921 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1922 (msg == WM_MSIME_MOUSE) ||
1923 (msg == WM_MSIME_RECONVERTREQUEST) ||
1924 (msg == WM_MSIME_RECONVERT) ||
1925 (msg == WM_MSIME_QUERYPOSITION) ||
1926 (msg == WM_MSIME_DOCUMENTFEED))
1929 SendMessageA(hWndIME, msg, wParam, lParam);
1936 /***********************************************************************
1937 * ImmIsUIMessageW (IMM32.@)
1939 BOOL WINAPI ImmIsUIMessageW(
1940 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1944 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1945 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1946 (msg == WM_IME_SETCONTEXT) ||
1947 (msg == WM_IME_NOTIFY) ||
1948 (msg == WM_IME_COMPOSITIONFULL) ||
1949 (msg == WM_IME_SELECT) ||
1950 (msg == 0x287 /* FIXME: WM_IME_SYSTEM */) ||
1951 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1952 (msg == WM_MSIME_MOUSE) ||
1953 (msg == WM_MSIME_RECONVERTREQUEST) ||
1954 (msg == WM_MSIME_RECONVERT) ||
1955 (msg == WM_MSIME_QUERYPOSITION) ||
1956 (msg == WM_MSIME_DOCUMENTFEED))
1959 SendMessageW(hWndIME, msg, wParam, lParam);
1966 /***********************************************************************
1967 * ImmNotifyIME (IMM32.@)
1969 BOOL WINAPI ImmNotifyIME(
1970 HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
1972 InputContextData *data = hIMC;
1974 TRACE("(%p, %d, %d, %d)\n",
1975 hIMC, dwAction, dwIndex, dwValue);
1977 if (!data || ! data->immKbd->pNotifyIME)
1980 return data->immKbd->pNotifyIME(hIMC,dwAction,dwIndex,dwValue);
1983 /***********************************************************************
1984 * ImmRegisterWordA (IMM32.@)
1986 BOOL WINAPI ImmRegisterWordA(
1987 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
1989 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1990 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_a(lpszReading), dwStyle,
1991 debugstr_a(lpszRegister));
1992 if (immHkl->hIME && immHkl->pImeRegisterWord)
1994 if (!is_kbd_ime_unicode(immHkl))
1995 return immHkl->pImeRegisterWord((LPCWSTR)lpszReading,dwStyle,
1996 (LPCWSTR)lpszRegister);
1999 LPWSTR lpszwReading = strdupAtoW(lpszReading);
2000 LPWSTR lpszwRegister = strdupAtoW(lpszRegister);
2003 rc = immHkl->pImeRegisterWord(lpszwReading,dwStyle,lpszwRegister);
2004 HeapFree(GetProcessHeap(),0,lpszwReading);
2005 HeapFree(GetProcessHeap(),0,lpszwRegister);
2013 /***********************************************************************
2014 * ImmRegisterWordW (IMM32.@)
2016 BOOL WINAPI ImmRegisterWordW(
2017 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
2019 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
2020 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_w(lpszReading), dwStyle,
2021 debugstr_w(lpszRegister));
2022 if (immHkl->hIME && immHkl->pImeRegisterWord)
2024 if (is_kbd_ime_unicode(immHkl))
2025 return immHkl->pImeRegisterWord(lpszReading,dwStyle,lpszRegister);
2028 LPSTR lpszaReading = strdupWtoA(lpszReading);
2029 LPSTR lpszaRegister = strdupWtoA(lpszRegister);
2032 rc = immHkl->pImeRegisterWord((LPCWSTR)lpszaReading,dwStyle,
2033 (LPCWSTR)lpszaRegister);
2034 HeapFree(GetProcessHeap(),0,lpszaReading);
2035 HeapFree(GetProcessHeap(),0,lpszaRegister);
2043 /***********************************************************************
2044 * ImmReleaseContext (IMM32.@)
2046 BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
2048 static int shown = 0;
2051 FIXME("(%p, %p): stub\n", hWnd, hIMC);
2057 /***********************************************************************
2058 * ImmRequestMessageA(IMM32.@)
2060 LRESULT WINAPI ImmRequestMessageA(HIMC hIMC, WPARAM wParam, LPARAM lParam)
2062 InputContextData *data = hIMC;
2064 TRACE("%p %ld %ld\n", hIMC, wParam, wParam);
2066 if (data && IsWindow(data->IMC.hWnd))
2067 return SendMessageA(data->IMC.hWnd, WM_IME_REQUEST, wParam, lParam);
2072 /***********************************************************************
2073 * ImmRequestMessageW(IMM32.@)
2075 LRESULT WINAPI ImmRequestMessageW(HIMC hIMC, WPARAM wParam, LPARAM lParam)
2077 InputContextData *data = hIMC;
2079 TRACE("%p %ld %ld\n", hIMC, wParam, wParam);
2081 if (data && IsWindow(data->IMC.hWnd))
2082 return SendMessageW(data->IMC.hWnd, WM_IME_REQUEST, wParam, lParam);
2087 /***********************************************************************
2088 * ImmSetCandidateWindow (IMM32.@)
2090 BOOL WINAPI ImmSetCandidateWindow(
2091 HIMC hIMC, LPCANDIDATEFORM lpCandidate)
2093 InputContextData *data = hIMC;
2095 TRACE("(%p, %p)\n", hIMC, lpCandidate);
2097 if (!data || !lpCandidate)
2100 TRACE("\t%x, %x, (%i,%i), (%i,%i - %i,%i)\n",
2101 lpCandidate->dwIndex, lpCandidate->dwStyle,
2102 lpCandidate->ptCurrentPos.x, lpCandidate->ptCurrentPos.y,
2103 lpCandidate->rcArea.top, lpCandidate->rcArea.left,
2104 lpCandidate->rcArea.bottom, lpCandidate->rcArea.right);
2106 if ( lpCandidate->dwIndex >= (sizeof(data->IMC.cfCandForm) / sizeof(CANDIDATEFORM)) )
2109 data->IMC.cfCandForm[lpCandidate->dwIndex] = *lpCandidate;
2110 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCANDIDATEPOS);
2111 ImmInternalSendIMENotify(data, IMN_SETCANDIDATEPOS, 1 << lpCandidate->dwIndex);
2116 /***********************************************************************
2117 * ImmSetCompositionFontA (IMM32.@)
2119 BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
2121 InputContextData *data = hIMC;
2122 TRACE("(%p, %p)\n", hIMC, lplf);
2127 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTA));
2128 MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->IMC.lfFont.W.lfFaceName,
2130 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCOMPOSITIONFONT);
2131 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONFONT, 0);
2136 /***********************************************************************
2137 * ImmSetCompositionFontW (IMM32.@)
2139 BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
2141 InputContextData *data = hIMC;
2142 TRACE("(%p, %p)\n", hIMC, lplf);
2147 data->IMC.lfFont.W = *lplf;
2148 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCOMPOSITIONFONT);
2149 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONFONT, 0);
2154 /***********************************************************************
2155 * ImmSetCompositionStringA (IMM32.@)
2157 BOOL WINAPI ImmSetCompositionStringA(
2158 HIMC hIMC, DWORD dwIndex,
2159 LPCVOID lpComp, DWORD dwCompLen,
2160 LPCVOID lpRead, DWORD dwReadLen)
2164 WCHAR *CompBuffer = NULL;
2165 WCHAR *ReadBuffer = NULL;
2167 InputContextData *data = hIMC;
2169 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2170 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
2175 if (!(dwIndex == SCS_SETSTR ||
2176 dwIndex == SCS_CHANGEATTR ||
2177 dwIndex == SCS_CHANGECLAUSE ||
2178 dwIndex == SCS_SETRECONVERTSTRING ||
2179 dwIndex == SCS_QUERYRECONVERTSTRING))
2182 if (!is_himc_ime_unicode(data))
2183 return data->immKbd->pImeSetCompositionString(hIMC, dwIndex, lpComp,
2184 dwCompLen, lpRead, dwReadLen);
2186 comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
2189 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
2190 MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
2193 read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
2196 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
2197 MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
2200 rc = ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
2201 ReadBuffer, read_len);
2203 HeapFree(GetProcessHeap(), 0, CompBuffer);
2204 HeapFree(GetProcessHeap(), 0, ReadBuffer);
2209 /***********************************************************************
2210 * ImmSetCompositionStringW (IMM32.@)
2212 BOOL WINAPI ImmSetCompositionStringW(
2213 HIMC hIMC, DWORD dwIndex,
2214 LPCVOID lpComp, DWORD dwCompLen,
2215 LPCVOID lpRead, DWORD dwReadLen)
2219 CHAR *CompBuffer = NULL;
2220 CHAR *ReadBuffer = NULL;
2222 InputContextData *data = hIMC;
2224 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2225 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
2230 if (!(dwIndex == SCS_SETSTR ||
2231 dwIndex == SCS_CHANGEATTR ||
2232 dwIndex == SCS_CHANGECLAUSE ||
2233 dwIndex == SCS_SETRECONVERTSTRING ||
2234 dwIndex == SCS_QUERYRECONVERTSTRING))
2237 if (is_himc_ime_unicode(data))
2238 return data->immKbd->pImeSetCompositionString(hIMC, dwIndex, lpComp,
2239 dwCompLen, lpRead, dwReadLen);
2241 comp_len = WideCharToMultiByte(CP_ACP, 0, lpComp, dwCompLen, NULL, 0, NULL,
2245 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len);
2246 WideCharToMultiByte(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len,
2250 read_len = WideCharToMultiByte(CP_ACP, 0, lpRead, dwReadLen, NULL, 0, NULL,
2254 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len);
2255 WideCharToMultiByte(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len,
2259 rc = ImmSetCompositionStringA(hIMC, dwIndex, CompBuffer, comp_len,
2260 ReadBuffer, read_len);
2262 HeapFree(GetProcessHeap(), 0, CompBuffer);
2263 HeapFree(GetProcessHeap(), 0, ReadBuffer);
2268 /***********************************************************************
2269 * ImmSetCompositionWindow (IMM32.@)
2271 BOOL WINAPI ImmSetCompositionWindow(
2272 HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
2274 BOOL reshow = FALSE;
2275 InputContextData *data = hIMC;
2277 TRACE("(%p, %p)\n", hIMC, lpCompForm);
2278 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm->dwStyle,
2279 lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
2280 lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);
2285 data->IMC.cfCompForm = *lpCompForm;
2287 if (IsWindowVisible(data->immKbd->UIWnd))
2290 ShowWindow(data->immKbd->UIWnd,SW_HIDE);
2293 /* FIXME: this is a partial stub */
2296 ShowWindow(data->immKbd->UIWnd,SW_SHOWNOACTIVATE);
2298 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONWINDOW, 0);
2302 /***********************************************************************
2303 * ImmSetConversionStatus (IMM32.@)
2305 BOOL WINAPI ImmSetConversionStatus(
2306 HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
2308 DWORD oldConversion, oldSentence;
2309 InputContextData *data = hIMC;
2311 TRACE("%p %d %d\n", hIMC, fdwConversion, fdwSentence);
2316 if ( fdwConversion != data->IMC.fdwConversion )
2318 oldConversion = data->IMC.fdwConversion;
2319 data->IMC.fdwConversion = fdwConversion;
2320 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, oldConversion, IMC_SETCONVERSIONMODE);
2321 ImmInternalSendIMENotify(data, IMN_SETCONVERSIONMODE, 0);
2323 if ( fdwSentence != data->IMC.fdwSentence )
2325 oldSentence = data->IMC.fdwSentence;
2326 data->IMC.fdwSentence = fdwSentence;
2327 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, oldSentence, IMC_SETSENTENCEMODE);
2328 ImmInternalSendIMENotify(data, IMN_SETSENTENCEMODE, 0);
2334 /***********************************************************************
2335 * ImmSetOpenStatus (IMM32.@)
2337 BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
2339 InputContextData *data = hIMC;
2341 TRACE("%p %d\n", hIMC, fOpen);
2346 if (data->immKbd->UIWnd == NULL)
2348 /* create the ime window */
2349 data->immKbd->UIWnd = CreateWindowExW( WS_EX_TOOLWINDOW,
2350 data->immKbd->imeClassName, NULL, WS_POPUP, 0, 0, 1, 1, 0,
2351 0, data->immKbd->hIME, 0);
2352 SetWindowLongPtrW(data->immKbd->UIWnd, IMMGWL_IMC, (LONG_PTR)data);
2355 SetWindowLongPtrW(data->immKbd->UIWnd, IMMGWL_IMC, (LONG_PTR)data);
2357 if (!fOpen != !data->IMC.fOpen)
2359 data->IMC.fOpen = fOpen;
2360 ImmNotifyIME( hIMC, NI_CONTEXTUPDATED, 0, IMC_SETOPENSTATUS);
2361 ImmInternalSendIMENotify(data, IMN_SETOPENSTATUS, 0);
2367 /***********************************************************************
2368 * ImmSetStatusWindowPos (IMM32.@)
2370 BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
2372 InputContextData *data = hIMC;
2374 TRACE("(%p, %p)\n", hIMC, lpptPos);
2376 if (!data || !lpptPos)
2379 TRACE("\t(%i,%i)\n", lpptPos->x, lpptPos->y);
2381 data->IMC.ptStatusWndPos = *lpptPos;
2382 ImmNotifyIME( hIMC, NI_CONTEXTUPDATED, 0, IMC_SETSTATUSWINDOWPOS);
2383 ImmInternalSendIMENotify(data, IMN_SETSTATUSWINDOWPOS, 0);
2388 /***********************************************************************
2389 * ImmCreateSoftKeyboard(IMM32.@)
2391 HWND WINAPI ImmCreateSoftKeyboard(UINT uType, UINT hOwner, int x, int y)
2393 FIXME("(%d, %d, %d, %d): stub\n", uType, hOwner, x, y);
2394 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2398 /***********************************************************************
2399 * ImmDestroySoftKeyboard(IMM32.@)
2401 BOOL WINAPI ImmDestroySoftKeyboard(HWND hSoftWnd)
2403 FIXME("(%p): stub\n", hSoftWnd);
2404 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2408 /***********************************************************************
2409 * ImmShowSoftKeyboard(IMM32.@)
2411 BOOL WINAPI ImmShowSoftKeyboard(HWND hSoftWnd, int nCmdShow)
2413 FIXME("(%p, %d): stub\n", hSoftWnd, nCmdShow);
2414 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2418 /***********************************************************************
2419 * ImmSimulateHotKey (IMM32.@)
2421 BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
2423 FIXME("(%p, %d): stub\n", hWnd, dwHotKeyID);
2424 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2428 /***********************************************************************
2429 * ImmUnregisterWordA (IMM32.@)
2431 BOOL WINAPI ImmUnregisterWordA(
2432 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
2434 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
2435 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_a(lpszReading), dwStyle,
2436 debugstr_a(lpszUnregister));
2437 if (immHkl->hIME && immHkl->pImeUnregisterWord)
2439 if (!is_kbd_ime_unicode(immHkl))
2440 return immHkl->pImeUnregisterWord((LPCWSTR)lpszReading,dwStyle,
2441 (LPCWSTR)lpszUnregister);
2444 LPWSTR lpszwReading = strdupAtoW(lpszReading);
2445 LPWSTR lpszwUnregister = strdupAtoW(lpszUnregister);
2448 rc = immHkl->pImeUnregisterWord(lpszwReading,dwStyle,lpszwUnregister);
2449 HeapFree(GetProcessHeap(),0,lpszwReading);
2450 HeapFree(GetProcessHeap(),0,lpszwUnregister);
2458 /***********************************************************************
2459 * ImmUnregisterWordW (IMM32.@)
2461 BOOL WINAPI ImmUnregisterWordW(
2462 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
2464 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
2465 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_w(lpszReading), dwStyle,
2466 debugstr_w(lpszUnregister));
2467 if (immHkl->hIME && immHkl->pImeUnregisterWord)
2469 if (is_kbd_ime_unicode(immHkl))
2470 return immHkl->pImeUnregisterWord(lpszReading,dwStyle,lpszUnregister);
2473 LPSTR lpszaReading = strdupWtoA(lpszReading);
2474 LPSTR lpszaUnregister = strdupWtoA(lpszUnregister);
2477 rc = immHkl->pImeUnregisterWord((LPCWSTR)lpszaReading,dwStyle,
2478 (LPCWSTR)lpszaUnregister);
2479 HeapFree(GetProcessHeap(),0,lpszaReading);
2480 HeapFree(GetProcessHeap(),0,lpszaUnregister);
2488 /***********************************************************************
2489 * ImmGetImeMenuItemsA (IMM32.@)
2491 DWORD WINAPI ImmGetImeMenuItemsA( HIMC hIMC, DWORD dwFlags, DWORD dwType,
2492 LPIMEMENUITEMINFOA lpImeParentMenu, LPIMEMENUITEMINFOA lpImeMenu,
2495 InputContextData *data = hIMC;
2496 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC, dwFlags, dwType,
2497 lpImeParentMenu, lpImeMenu, dwSize);
2498 if (data->immKbd->hIME && data->immKbd->pImeGetImeMenuItems)
2500 if (!is_himc_ime_unicode(data) || (!lpImeParentMenu && !lpImeMenu))
2501 return data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2502 (IMEMENUITEMINFOW*)lpImeParentMenu,
2503 (IMEMENUITEMINFOW*)lpImeMenu, dwSize);
2506 IMEMENUITEMINFOW lpImeParentMenuW;
2507 IMEMENUITEMINFOW *lpImeMenuW, *parent = NULL;
2510 if (lpImeParentMenu)
2511 parent = &lpImeParentMenuW;
2514 int count = dwSize / sizeof(LPIMEMENUITEMINFOA);
2515 dwSize = count * sizeof(IMEMENUITEMINFOW);
2516 lpImeMenuW = HeapAlloc(GetProcessHeap(), 0, dwSize);
2521 rc = data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2522 parent, lpImeMenuW, dwSize);
2524 if (lpImeParentMenu)
2526 memcpy(lpImeParentMenu,&lpImeParentMenuW,sizeof(IMEMENUITEMINFOA));
2527 lpImeParentMenu->hbmpItem = lpImeParentMenuW.hbmpItem;
2528 WideCharToMultiByte(CP_ACP, 0, lpImeParentMenuW.szString,
2529 -1, lpImeParentMenu->szString, IMEMENUITEM_STRING_SIZE,
2532 if (lpImeMenu && rc)
2535 for (i = 0; i < rc; i++)
2537 memcpy(&lpImeMenu[i],&lpImeMenuW[1],sizeof(IMEMENUITEMINFOA));
2538 lpImeMenu[i].hbmpItem = lpImeMenuW[i].hbmpItem;
2539 WideCharToMultiByte(CP_ACP, 0, lpImeMenuW[i].szString,
2540 -1, lpImeMenu[i].szString, IMEMENUITEM_STRING_SIZE,
2544 HeapFree(GetProcessHeap(),0,lpImeMenuW);
2552 /***********************************************************************
2553 * ImmGetImeMenuItemsW (IMM32.@)
2555 DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType,
2556 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
2559 InputContextData *data = hIMC;
2560 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC, dwFlags, dwType,
2561 lpImeParentMenu, lpImeMenu, dwSize);
2562 if (data->immKbd->hIME && data->immKbd->pImeGetImeMenuItems)
2564 if (is_himc_ime_unicode(data) || (!lpImeParentMenu && !lpImeMenu))
2565 return data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2566 lpImeParentMenu, lpImeMenu, dwSize);
2569 IMEMENUITEMINFOA lpImeParentMenuA;
2570 IMEMENUITEMINFOA *lpImeMenuA, *parent = NULL;
2573 if (lpImeParentMenu)
2574 parent = &lpImeParentMenuA;
2577 int count = dwSize / sizeof(LPIMEMENUITEMINFOW);
2578 dwSize = count * sizeof(IMEMENUITEMINFOA);
2579 lpImeMenuA = HeapAlloc(GetProcessHeap(), 0, dwSize);
2584 rc = data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2585 (IMEMENUITEMINFOW*)parent,
2586 (IMEMENUITEMINFOW*)lpImeMenuA, dwSize);
2588 if (lpImeParentMenu)
2590 memcpy(lpImeParentMenu,&lpImeParentMenuA,sizeof(IMEMENUITEMINFOA));
2591 lpImeParentMenu->hbmpItem = lpImeParentMenuA.hbmpItem;
2592 MultiByteToWideChar(CP_ACP, 0, lpImeParentMenuA.szString,
2593 -1, lpImeParentMenu->szString, IMEMENUITEM_STRING_SIZE);
2595 if (lpImeMenu && rc)
2598 for (i = 0; i < rc; i++)
2600 memcpy(&lpImeMenu[i],&lpImeMenuA[1],sizeof(IMEMENUITEMINFOA));
2601 lpImeMenu[i].hbmpItem = lpImeMenuA[i].hbmpItem;
2602 MultiByteToWideChar(CP_ACP, 0, lpImeMenuA[i].szString,
2603 -1, lpImeMenu[i].szString, IMEMENUITEM_STRING_SIZE);
2606 HeapFree(GetProcessHeap(),0,lpImeMenuA);
2614 /***********************************************************************
2615 * ImmLockIMC(IMM32.@)
2617 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
2619 InputContextData *data = hIMC;
2627 /***********************************************************************
2628 * ImmUnlockIMC(IMM32.@)
2630 BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
2632 InputContextData *data = hIMC;
2634 return (data->dwLock!=0);
2637 /***********************************************************************
2638 * ImmGetIMCLockCount(IMM32.@)
2640 DWORD WINAPI ImmGetIMCLockCount(HIMC hIMC)
2642 InputContextData *data = hIMC;
2643 return data->dwLock;
2646 /***********************************************************************
2647 * ImmCreateIMCC(IMM32.@)
2649 HIMCC WINAPI ImmCreateIMCC(DWORD size)
2651 IMCCInternal *internal;
2652 int real_size = size + sizeof(IMCCInternal);
2654 internal = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, real_size);
2655 if (internal == NULL)
2658 internal->dwSize = size;
2662 /***********************************************************************
2663 * ImmDestroyIMCC(IMM32.@)
2665 HIMCC WINAPI ImmDestroyIMCC(HIMCC block)
2667 HeapFree(GetProcessHeap(),0,block);
2671 /***********************************************************************
2672 * ImmLockIMCC(IMM32.@)
2674 LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
2676 IMCCInternal *internal;
2679 internal->dwLock ++;
2680 return internal + 1;
2683 /***********************************************************************
2684 * ImmUnlockIMCC(IMM32.@)
2686 BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
2688 IMCCInternal *internal;
2691 internal->dwLock --;
2692 return (internal->dwLock!=0);
2695 /***********************************************************************
2696 * ImmGetIMCCLockCount(IMM32.@)
2698 DWORD WINAPI ImmGetIMCCLockCount(HIMCC imcc)
2700 IMCCInternal *internal;
2703 return internal->dwLock;
2706 /***********************************************************************
2707 * ImmReSizeIMCC(IMM32.@)
2709 HIMCC WINAPI ImmReSizeIMCC(HIMCC imcc, DWORD size)
2711 IMCCInternal *internal,*newone;
2712 int real_size = size + sizeof(IMCCInternal);
2716 newone = HeapReAlloc(GetProcessHeap(), 0, internal, real_size);
2717 newone->dwSize = size;
2722 /***********************************************************************
2723 * ImmGetIMCCSize(IMM32.@)
2725 DWORD WINAPI ImmGetIMCCSize(HIMCC imcc)
2727 IMCCInternal *internal;
2730 return internal->dwSize;
2733 /***********************************************************************
2734 * ImmGenerateMessage(IMM32.@)
2736 BOOL WINAPI ImmGenerateMessage(HIMC hIMC)
2738 InputContextData *data = hIMC;
2740 TRACE("%i messages queued\n",data->IMC.dwNumMsgBuf);
2741 if (data->IMC.dwNumMsgBuf > 0)
2743 LPTRANSMSG lpTransMsg;
2746 lpTransMsg = ImmLockIMCC(data->IMC.hMsgBuf);
2747 for (i = 0; i < data->IMC.dwNumMsgBuf; i++)
2748 ImmInternalPostIMEMessage(data, lpTransMsg[i].message, lpTransMsg[i].wParam, lpTransMsg[i].lParam);
2750 ImmUnlockIMCC(data->IMC.hMsgBuf);
2752 data->IMC.dwNumMsgBuf = 0;
2758 /***********************************************************************
2759 * ImmTranslateMessage(IMM32.@)
2760 * ( Undocumented, call internally and from user32.dll )
2762 BOOL WINAPI ImmTranslateMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lKeyData)
2764 InputContextData *data;
2765 HIMC imc = ImmGetContext(hwnd);
2771 static const DWORD list_count = 10;
2773 TRACE("%p %x %x %x\n",hwnd, msg, (UINT)wParam, (UINT)lKeyData);
2780 if (!data->immKbd->hIME || !data->immKbd->pImeToAsciiEx)
2783 GetKeyboardState(state);
2784 scancode = lKeyData >> 0x10 & 0xff;
2786 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list_count * sizeof(TRANSMSG) + sizeof(DWORD));
2787 ((DWORD*)list)[0] = list_count;
2789 if (data->immKbd->imeInfo.fdwProperty & IME_PROP_KBD_CHAR_FIRST)
2793 if (!is_himc_ime_unicode(data))
2794 ToAscii(data->lastVK, scancode, state, &chr, 0);
2796 ToUnicodeEx(data->lastVK, scancode, state, &chr, 1, 0, GetKeyboardLayout(0));
2797 uVirtKey = MAKELONG(data->lastVK,chr);
2800 uVirtKey = data->lastVK;
2802 msg_count = data->immKbd->pImeToAsciiEx(uVirtKey, scancode, state, list, 0, imc);
2803 TRACE("%i messages generated\n",msg_count);
2804 if (msg_count && msg_count <= list_count)
2807 LPTRANSMSG msgs = (LPTRANSMSG)((LPBYTE)list + sizeof(DWORD));
2809 for (i = 0; i < msg_count; i++)
2810 ImmInternalPostIMEMessage(data, msgs[i].message, msgs[i].wParam, msgs[i].lParam);
2812 else if (msg_count > list_count)
2813 ImmGenerateMessage(imc);
2815 HeapFree(GetProcessHeap(),0,list);
2817 data->lastVK = VK_PROCESSKEY;
2819 return (msg_count > 0);
2822 /***********************************************************************
2823 * ImmProcessKey(IMM32.@)
2824 * ( Undocumented, called from user32.dll )
2826 BOOL WINAPI ImmProcessKey(HWND hwnd, HKL hKL, UINT vKey, LPARAM lKeyData, DWORD unknown)
2828 InputContextData *data;
2829 HIMC imc = ImmGetContext(hwnd);
2832 TRACE("%p %p %x %x %x\n",hwnd, hKL, vKey, (UINT)lKeyData, unknown);
2839 if (!data->immKbd->hIME || !data->immKbd->pImeProcessKey)
2842 GetKeyboardState(state);
2843 if (data->immKbd->pImeProcessKey(imc, vKey, lKeyData, state))
2845 data->lastVK = vKey;
2849 data->lastVK = VK_PROCESSKEY;
2853 /***********************************************************************
2854 * ImmDisableTextFrameService(IMM32.@)
2856 BOOL WINAPI ImmDisableTextFrameService(DWORD idThread)
2862 /***********************************************************************
2863 * ImmEnumInputContext(IMM32.@)
2866 BOOL WINAPI ImmEnumInputContext(DWORD idThread, IMCENUMPROC lpfn, LPARAM lParam)
2872 /***********************************************************************
2873 * ImmGetHotKey(IMM32.@)
2876 BOOL WINAPI ImmGetHotKey(DWORD hotkey, UINT *modifiers, UINT *key, HKL hkl)
2878 FIXME("%x, %p, %p, %p: stub\n", hotkey, modifiers, key, hkl);
2884 * Window Proc for the Default IME window class
2886 static LRESULT WINAPI DefIME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
2894 case WM_IME_STARTCOMPOSITION:
2895 case WM_IME_ENDCOMPOSITION:
2896 case WM_IME_COMPOSITION:
2897 case WM_IME_SETCONTEXT:
2899 case WM_IME_CONTROL:
2900 case WM_IME_COMPOSITIONFULL:
2903 case WM_IME_REQUEST:
2904 case WM_IME_KEYDOWN:
2907 ImmHkl *immHkl = IMM_GetImmHkl(GetKeyboardLayout(0));
2909 PostMessageW(immHkl->UIWnd,uMsg,wParam,lParam);
2913 if ((uMsg == WM_MSIME_RECONVERTOPTIONS) ||
2914 (uMsg == WM_MSIME_SERVICE) ||
2915 (uMsg == WM_MSIME_MOUSE) ||
2916 (uMsg == WM_MSIME_RECONVERTREQUEST) ||
2917 (uMsg == WM_MSIME_RECONVERT) ||
2918 (uMsg == WM_MSIME_QUERYPOSITION) ||
2919 (uMsg == WM_MSIME_DOCUMENTFEED))
2921 ImmHkl *immHkl = IMM_GetImmHkl(GetKeyboardLayout(0));
2923 PostMessageW(immHkl->UIWnd,uMsg,wParam,lParam);
2926 return DefWindowProcW(hwnd, uMsg, wParam, lParam);