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 */
54 /* Function Pointers */
55 MAKE_FUNCPTR(ImeInquire);
56 MAKE_FUNCPTR(ImeConfigure);
57 MAKE_FUNCPTR(ImeDestroy);
58 MAKE_FUNCPTR(ImeEscape);
59 MAKE_FUNCPTR(ImeSelect);
60 MAKE_FUNCPTR(ImeSetActiveContext);
61 MAKE_FUNCPTR(ImeToAsciiEx);
62 MAKE_FUNCPTR(NotifyIME);
63 MAKE_FUNCPTR(ImeRegisterWord);
64 MAKE_FUNCPTR(ImeUnregisterWord);
65 MAKE_FUNCPTR(ImeEnumRegisterWord);
66 MAKE_FUNCPTR(ImeSetCompositionString);
67 MAKE_FUNCPTR(ImeConversionList);
68 MAKE_FUNCPTR(ImeProcessKey);
69 MAKE_FUNCPTR(ImeGetRegisterWordStyle);
70 MAKE_FUNCPTR(ImeGetImeMenuItems);
74 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};
114 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
115 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
117 static BOOL IMM_DestroyContext(HIMC hIMC);
119 static inline WCHAR *strdupAtoW( const char *str )
124 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
125 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
126 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
131 static inline CHAR *strdupWtoA( const WCHAR *str )
136 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
137 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
138 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
143 static DWORD convert_candidatelist_WtoA(
144 LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen)
148 ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] );
149 if ( lpDst && dwBufLen > 0 )
152 lpDst->dwOffset[0] = ret;
155 for ( i = 0; i < lpSrc->dwCount; i++)
157 LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i];
159 if ( lpDst && dwBufLen > 0 )
161 LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i];
163 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1,
164 (LPSTR)dest, dwBufLen, NULL, NULL);
166 if ( i + 1 < lpSrc->dwCount )
167 lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(char);
168 dwBufLen -= len * sizeof(char);
171 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1, NULL, 0, NULL, NULL);
173 ret += len * sizeof(char);
182 static DWORD convert_candidatelist_AtoW(
183 LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen)
187 ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] );
188 if ( lpDst && dwBufLen > 0 )
191 lpDst->dwOffset[0] = ret;
194 for ( i = 0; i < lpSrc->dwCount; i++)
196 LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i];
198 if ( lpDst && dwBufLen > 0 )
200 LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i];
202 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1,
203 (LPWSTR)dest, dwBufLen);
205 if ( i + 1 < lpSrc->dwCount )
206 lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(WCHAR);
207 dwBufLen -= len * sizeof(WCHAR);
210 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, NULL, 0);
212 ret += len * sizeof(WCHAR);
221 static IMMThreadData* IMM_GetThreadData(void)
223 IMMThreadData* data = TlsGetValue(tlsIndex);
226 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
227 sizeof(IMMThreadData));
228 TlsSetValue(tlsIndex,data);
229 TRACE("Thread Data Created\n");
234 static void IMM_FreeThreadData(void)
236 IMMThreadData* data = TlsGetValue(tlsIndex);
239 IMM_DestroyContext(data->defaultContext);
240 DestroyWindow(data->hwndDefault);
241 HeapFree(GetProcessHeap(),0,data);
242 TRACE("Thread Data Destroyed\n");
246 static HMODULE LoadDefaultWineIME(void)
248 char buffer[MAX_PATH], libname[32], *name, *next;
252 TRACE("Attempting to fall back to wine default IME\n");
254 strcpy( buffer, "x11" ); /* default value */
255 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
256 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
258 DWORD type, count = sizeof(buffer);
259 RegQueryValueExA( hkey, "Ime", 0, &type, (LPBYTE) buffer, &count );
266 next = strchr( name, ',' );
267 if (next) *next++ = 0;
269 snprintf( libname, sizeof(libname), "wine%s.drv", name );
270 if ((module = LoadLibraryA( libname )) != 0) break;
277 /* ImmHkl loading and freeing */
278 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
279 static ImmHkl *IMM_GetImmHkl(HKL hkl)
282 WCHAR filename[MAX_PATH];
284 TRACE("Seeking ime for keyboard %p\n",hkl);
286 LIST_FOR_EACH_ENTRY(ptr, &ImmHklList, ImmHkl, entry)
291 /* not found... create it */
293 ptr = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ImmHkl));
296 if (ImmGetIMEFileNameW(hkl, filename, MAX_PATH)) ptr->hIME = LoadLibraryW(filename);
298 ptr->hIME = LoadDefaultWineIME();
301 LOAD_FUNCPTR(ImeInquire);
302 if (!ptr->pImeInquire || !ptr->pImeInquire(&ptr->imeInfo, ptr->imeClassName, NULL))
304 FreeLibrary(ptr->hIME);
309 LOAD_FUNCPTR(ImeDestroy);
310 LOAD_FUNCPTR(ImeSelect);
311 if (!ptr->pImeSelect || !ptr->pImeDestroy)
313 FreeLibrary(ptr->hIME);
318 LOAD_FUNCPTR(ImeConfigure);
319 LOAD_FUNCPTR(ImeEscape);
320 LOAD_FUNCPTR(ImeSetActiveContext);
321 LOAD_FUNCPTR(ImeToAsciiEx);
322 LOAD_FUNCPTR(NotifyIME);
323 LOAD_FUNCPTR(ImeRegisterWord);
324 LOAD_FUNCPTR(ImeUnregisterWord);
325 LOAD_FUNCPTR(ImeEnumRegisterWord);
326 LOAD_FUNCPTR(ImeSetCompositionString);
327 LOAD_FUNCPTR(ImeConversionList);
328 LOAD_FUNCPTR(ImeProcessKey);
329 LOAD_FUNCPTR(ImeGetRegisterWordStyle);
330 LOAD_FUNCPTR(ImeGetImeMenuItems);
331 /* make sure our classname is WCHAR */
332 if (!is_kbd_ime_unicode(ptr))
335 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ptr->imeClassName,
337 lstrcpyW(ptr->imeClassName, bufW);
342 list_add_head(&ImmHklList,&ptr->entry);
348 static void IMM_FreeAllImmHkl(void)
350 ImmHkl *ptr,*cursor2;
352 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &ImmHklList, ImmHkl, entry)
354 list_remove(&ptr->entry);
358 FreeLibrary(ptr->hIME);
360 HeapFree(GetProcessHeap(),0,ptr);
364 static void IMM_RegisterMessages(void)
366 WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
367 WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
368 WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
369 WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
370 WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
371 WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
372 WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
375 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
377 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
380 case DLL_PROCESS_ATTACH:
381 IMM_RegisterMessages();
382 tlsIndex = TlsAlloc();
383 if (tlsIndex == TLS_OUT_OF_INDEXES)
386 case DLL_THREAD_ATTACH:
388 case DLL_THREAD_DETACH:
389 IMM_FreeThreadData();
391 case DLL_PROCESS_DETACH:
392 IMM_FreeThreadData();
400 /* for posting messages as the IME */
401 static void ImmInternalPostIMEMessage(InputContextData *data, UINT msg, WPARAM wParam, LPARAM lParam)
403 HWND target = GetFocus();
405 PostMessageW(data->IMC.hWnd,msg,wParam,lParam);
407 PostMessageW(target, msg, wParam, lParam);
410 static LRESULT ImmInternalSendIMENotify(InputContextData *data, WPARAM notify, LPARAM lParam)
414 target = data->IMC.hWnd;
415 if (!target) target = GetFocus();
418 return SendMessageW(target, WM_IME_NOTIFY, notify, lParam);
423 static HIMCC ImmCreateBlankCompStr(void)
426 LPCOMPOSITIONSTRING ptr;
427 rc = ImmCreateIMCC(sizeof(COMPOSITIONSTRING));
428 ptr = ImmLockIMCC(rc);
429 memset(ptr,0,sizeof(COMPOSITIONSTRING));
430 ptr->dwSize = sizeof(COMPOSITIONSTRING);
435 /***********************************************************************
436 * ImmAssociateContext (IMM32.@)
438 HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
441 InputContextData *data = hIMC;
443 TRACE("(%p, %p):\n", hWnd, hIMC);
445 if (!IMM_GetThreadData()->defaultContext)
446 IMM_GetThreadData()->defaultContext = ImmCreateContext();
449 * If already associated just return
451 if (hIMC && data->IMC.hWnd == hWnd)
456 old = RemovePropW(hWnd,szwWineIMCProperty);
459 old = IMM_GetThreadData()->defaultContext;
460 else if (old == (HIMC)-1)
463 if (hIMC != IMM_GetThreadData()->defaultContext)
465 if (hIMC == NULL) /* Meaning disable imm for that window*/
466 SetPropW(hWnd,szwWineIMCProperty,(HANDLE)-1);
468 SetPropW(hWnd,szwWineIMCProperty,hIMC);
473 InputContextData *old_data = old;
474 if (old_data->IMC.hWnd == hWnd)
475 old_data->IMC.hWnd = NULL;
482 if (IsWindow(data->IMC.hWnd))
485 * Post a message that your context is switching
487 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
490 data->IMC.hWnd = hWnd;
492 if (IsWindow(data->IMC.hWnd))
495 * Post a message that your context is switching
497 SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
505 * Helper function for ImmAssociateContextEx
507 static BOOL CALLBACK _ImmAssociateContextExEnumProc(HWND hwnd, LPARAM lParam)
509 HIMC hImc = (HIMC)lParam;
510 ImmAssociateContext(hwnd,hImc);
514 /***********************************************************************
515 * ImmAssociateContextEx (IMM32.@)
517 BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
519 TRACE("(%p, %p, 0x%x):\n", hWnd, hIMC, dwFlags);
521 if (!IMM_GetThreadData()->defaultContext)
522 IMM_GetThreadData()->defaultContext = ImmCreateContext();
524 if (!hWnd) return FALSE;
529 ImmAssociateContext(hWnd,hIMC);
532 ImmAssociateContext(hWnd,IMM_GetThreadData()->defaultContext);
534 case IACE_IGNORENOCONTEXT:
535 if (GetPropW(hWnd,szwWineIMCProperty))
536 ImmAssociateContext(hWnd,hIMC);
539 EnumChildWindows(hWnd,_ImmAssociateContextExEnumProc,(LPARAM)hIMC);
542 FIXME("Unknown dwFlags 0x%x\n",dwFlags);
547 /***********************************************************************
548 * ImmConfigureIMEA (IMM32.@)
550 BOOL WINAPI ImmConfigureIMEA(
551 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
553 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
555 TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
557 if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
560 if (immHkl->hIME && immHkl->pImeConfigure)
562 if (dwMode != IME_CONFIG_REGISTERWORD || !is_kbd_ime_unicode(immHkl))
563 return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
567 REGISTERWORDA *rwa = lpData;
570 rww.lpReading = strdupAtoW(rwa->lpReading);
571 rww.lpWord = strdupAtoW(rwa->lpWord);
572 rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rww);
573 HeapFree(GetProcessHeap(),0,rww.lpReading);
574 HeapFree(GetProcessHeap(),0,rww.lpWord);
582 /***********************************************************************
583 * ImmConfigureIMEW (IMM32.@)
585 BOOL WINAPI ImmConfigureIMEW(
586 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
588 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
590 TRACE("(%p, %p, %d, %p):\n", hKL, hWnd, dwMode, lpData);
592 if (dwMode == IME_CONFIG_REGISTERWORD && !lpData)
595 if (immHkl->hIME && immHkl->pImeConfigure)
597 if (dwMode != IME_CONFIG_REGISTERWORD || is_kbd_ime_unicode(immHkl))
598 return immHkl->pImeConfigure(hKL,hWnd,dwMode,lpData);
601 REGISTERWORDW *rww = lpData;
605 rwa.lpReading = strdupWtoA(rww->lpReading);
606 rwa.lpWord = strdupWtoA(rww->lpWord);
607 rc = immHkl->pImeConfigure(hKL,hWnd,dwMode,&rwa);
608 HeapFree(GetProcessHeap(),0,rwa.lpReading);
609 HeapFree(GetProcessHeap(),0,rwa.lpWord);
617 /***********************************************************************
618 * ImmCreateContext (IMM32.@)
620 HIMC WINAPI ImmCreateContext(void)
622 InputContextData *new_context;
626 new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
629 new_context->immKbd = IMM_GetImmHkl(GetKeyboardLayout(0));
631 if (!new_context->immKbd->hIME)
633 TRACE("IME dll could not be loaded\n");
634 HeapFree(GetProcessHeap(),0,new_context);
638 /* the HIMCCs are never NULL */
639 new_context->IMC.hCompStr = ImmCreateBlankCompStr();
640 new_context->IMC.hMsgBuf = ImmCreateIMCC(0);
641 new_context->IMC.hCandInfo = ImmCreateIMCC(sizeof(CANDIDATEINFO));
642 ci = ImmLockIMCC(new_context->IMC.hCandInfo);
643 memset(ci,0,sizeof(CANDIDATEINFO));
644 ci->dwSize = sizeof(CANDIDATEINFO);
645 ImmUnlockIMCC(new_context->IMC.hCandInfo);
646 new_context->IMC.hGuideLine = ImmCreateIMCC(sizeof(GUIDELINE));
647 gl = ImmLockIMCC(new_context->IMC.hGuideLine);
648 memset(gl,0,sizeof(GUIDELINE));
649 gl->dwSize = sizeof(GUIDELINE);
650 ImmUnlockIMCC(new_context->IMC.hGuideLine);
652 /* Initialize the IME Private */
653 new_context->IMC.hPrivate = ImmCreateIMCC(new_context->immKbd->imeInfo.dwPrivateDataSize);
655 if (!new_context->immKbd->pImeSelect(new_context, TRUE))
657 TRACE("Selection of IME failed\n");
658 IMM_DestroyContext(new_context);
661 SendMessageW(GetFocus(), WM_IME_SELECT, TRUE, (LPARAM)GetKeyboardLayout(0));
663 new_context->immKbd->uSelected++;
664 TRACE("Created context %p\n",new_context);
669 static BOOL IMM_DestroyContext(HIMC hIMC)
671 InputContextData *data = hIMC;
673 TRACE("Destroying %p\n",hIMC);
677 data->immKbd->uSelected --;
678 data->immKbd->pImeSelect(hIMC, FALSE);
679 SendMessageW(data->IMC.hWnd, WM_IME_SELECT, FALSE, (LPARAM)GetKeyboardLayout(0));
681 if (IMM_GetThreadData()->hwndDefault == data->imeWnd)
682 IMM_GetThreadData()->hwndDefault = NULL;
683 DestroyWindow(data->imeWnd);
685 ImmDestroyIMCC(data->IMC.hCompStr);
686 ImmDestroyIMCC(data->IMC.hCandInfo);
687 ImmDestroyIMCC(data->IMC.hGuideLine);
688 ImmDestroyIMCC(data->IMC.hPrivate);
689 ImmDestroyIMCC(data->IMC.hMsgBuf);
691 HeapFree(GetProcessHeap(),0,data);
696 /***********************************************************************
697 * ImmDestroyContext (IMM32.@)
699 BOOL WINAPI ImmDestroyContext(HIMC hIMC)
701 if (hIMC != IMM_GetThreadData()->defaultContext)
702 return IMM_DestroyContext(hIMC);
707 /***********************************************************************
708 * ImmDisableIME (IMM32.@)
710 BOOL WINAPI ImmDisableIME(DWORD idThread)
712 FIXME("(%d): stub\n", idThread);
716 /***********************************************************************
717 * ImmEnumRegisterWordA (IMM32.@)
719 UINT WINAPI ImmEnumRegisterWordA(
720 HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
721 LPCSTR lpszReading, DWORD dwStyle,
722 LPCSTR lpszRegister, LPVOID lpData)
724 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
725 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc,
726 debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister), lpData);
727 if (immHkl->hIME && immHkl->pImeEnumRegisterWord)
729 if (!is_kbd_ime_unicode(immHkl))
730 return immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc,
731 (LPCWSTR)lpszReading, dwStyle, (LPCWSTR)lpszRegister, lpData);
734 LPWSTR lpszwReading = strdupAtoW(lpszReading);
735 LPWSTR lpszwRegister = strdupAtoW(lpszRegister);
738 rc = immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc,
739 lpszwReading, dwStyle, lpszwRegister,
742 HeapFree(GetProcessHeap(),0,lpszwReading);
743 HeapFree(GetProcessHeap(),0,lpszwRegister);
751 /***********************************************************************
752 * ImmEnumRegisterWordW (IMM32.@)
754 UINT WINAPI ImmEnumRegisterWordW(
755 HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
756 LPCWSTR lpszReading, DWORD dwStyle,
757 LPCWSTR lpszRegister, LPVOID lpData)
759 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
760 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc,
761 debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister), lpData);
762 if (immHkl->hIME && immHkl->pImeEnumRegisterWord)
764 if (is_kbd_ime_unicode(immHkl))
765 return immHkl->pImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle,
766 lpszRegister, lpData);
769 LPSTR lpszaReading = strdupWtoA(lpszReading);
770 LPSTR lpszaRegister = strdupWtoA(lpszRegister);
773 rc = immHkl->pImeEnumRegisterWord(lpfnEnumProc, (LPCWSTR)lpszaReading,
774 dwStyle, (LPCWSTR)lpszaRegister, lpData);
776 HeapFree(GetProcessHeap(),0,lpszaReading);
777 HeapFree(GetProcessHeap(),0,lpszaRegister);
785 static inline BOOL EscapeRequiresWA(UINT uEscape)
787 if (uEscape == IME_ESC_GET_EUDC_DICTIONARY ||
788 uEscape == IME_ESC_SET_EUDC_DICTIONARY ||
789 uEscape == IME_ESC_IME_NAME ||
790 uEscape == IME_ESC_GETHELPFILENAME)
795 /***********************************************************************
796 * ImmEscapeA (IMM32.@)
798 LRESULT WINAPI ImmEscapeA(
800 UINT uEscape, LPVOID lpData)
802 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
803 TRACE("(%p, %p, %d, %p):\n", hKL, hIMC, uEscape, lpData);
805 if (immHkl->hIME && immHkl->pImeEscape)
807 if (!EscapeRequiresWA(uEscape) || !is_kbd_ime_unicode(immHkl))
808 return immHkl->pImeEscape(hIMC,uEscape,lpData);
811 WCHAR buffer[81]; /* largest required buffer should be 80 */
813 if (uEscape == IME_ESC_SET_EUDC_DICTIONARY)
815 MultiByteToWideChar(CP_ACP,0,lpData,-1,buffer,81);
816 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
820 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
821 WideCharToMultiByte(CP_ACP,0,buffer,-1,lpData,80, NULL, NULL);
830 /***********************************************************************
831 * ImmEscapeW (IMM32.@)
833 LRESULT WINAPI ImmEscapeW(
835 UINT uEscape, LPVOID lpData)
837 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
838 TRACE("(%p, %p, %d, %p):\n", hKL, hIMC, uEscape, lpData);
840 if (immHkl->hIME && immHkl->pImeEscape)
842 if (!EscapeRequiresWA(uEscape) || is_kbd_ime_unicode(immHkl))
843 return immHkl->pImeEscape(hIMC,uEscape,lpData);
846 CHAR buffer[81]; /* largest required buffer should be 80 */
848 if (uEscape == IME_ESC_SET_EUDC_DICTIONARY)
850 WideCharToMultiByte(CP_ACP,0,lpData,-1,buffer,81, NULL, NULL);
851 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
855 rc = immHkl->pImeEscape(hIMC,uEscape,buffer);
856 MultiByteToWideChar(CP_ACP,0,buffer,-1,lpData,80);
865 /***********************************************************************
866 * ImmGetCandidateListA (IMM32.@)
868 DWORD WINAPI ImmGetCandidateListA(
869 HIMC hIMC, DWORD dwIndex,
870 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
872 InputContextData *data = hIMC;
873 LPCANDIDATEINFO candinfo;
874 LPCANDIDATELIST candlist;
877 TRACE("%p, %d, %p, %d\n", hIMC, dwIndex, lpCandList, dwBufLen);
879 if (!data || !data->IMC.hCandInfo)
882 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
883 if ( dwIndex >= candinfo->dwCount ||
884 dwIndex >= (sizeof(candinfo->dwOffset) / sizeof(DWORD)) )
887 candlist = (LPCANDIDATELIST)((LPBYTE)candinfo + candinfo->dwOffset[dwIndex]);
888 if ( !candlist->dwSize || !candlist->dwCount )
891 if ( !is_himc_ime_unicode(data) )
893 ret = candlist->dwSize;
894 if ( lpCandList && dwBufLen >= ret )
895 memcpy(lpCandList, candlist, ret);
898 ret = convert_candidatelist_WtoA( candlist, lpCandList, dwBufLen);
901 ImmUnlockIMCC(data->IMC.hCandInfo);
905 /***********************************************************************
906 * ImmGetCandidateListCountA (IMM32.@)
908 DWORD WINAPI ImmGetCandidateListCountA(
909 HIMC hIMC, LPDWORD lpdwListCount)
911 InputContextData *data = hIMC;
912 LPCANDIDATEINFO candinfo;
915 TRACE("%p, %p\n", hIMC, lpdwListCount);
917 if (!data || !lpdwListCount || !data->IMC.hCandInfo)
920 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
922 *lpdwListCount = count = candinfo->dwCount;
924 if ( !is_himc_ime_unicode(data) )
925 ret = candinfo->dwSize;
928 ret = sizeof(CANDIDATEINFO);
930 ret += ImmGetCandidateListA(hIMC, count, NULL, 0);
933 ImmUnlockIMCC(data->IMC.hCandInfo);
937 /***********************************************************************
938 * ImmGetCandidateListCountW (IMM32.@)
940 DWORD WINAPI ImmGetCandidateListCountW(
941 HIMC hIMC, LPDWORD lpdwListCount)
943 InputContextData *data = hIMC;
944 LPCANDIDATEINFO candinfo;
947 TRACE("%p, %p\n", hIMC, lpdwListCount);
949 if (!data || !lpdwListCount || !data->IMC.hCandInfo)
952 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
954 *lpdwListCount = count = candinfo->dwCount;
956 if ( is_himc_ime_unicode(data) )
957 ret = candinfo->dwSize;
960 ret = sizeof(CANDIDATEINFO);
962 ret += ImmGetCandidateListW(hIMC, count, NULL, 0);
965 ImmUnlockIMCC(data->IMC.hCandInfo);
969 /***********************************************************************
970 * ImmGetCandidateListW (IMM32.@)
972 DWORD WINAPI ImmGetCandidateListW(
973 HIMC hIMC, DWORD dwIndex,
974 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
976 InputContextData *data = hIMC;
977 LPCANDIDATEINFO candinfo;
978 LPCANDIDATELIST candlist;
981 TRACE("%p, %d, %p, %d\n", hIMC, dwIndex, lpCandList, dwBufLen);
983 if (!data || !data->IMC.hCandInfo)
986 candinfo = ImmLockIMCC(data->IMC.hCandInfo);
987 if ( dwIndex >= candinfo->dwCount ||
988 dwIndex >= (sizeof(candinfo->dwOffset) / sizeof(DWORD)) )
991 candlist = (LPCANDIDATELIST)((LPBYTE)candinfo + candinfo->dwOffset[dwIndex]);
992 if ( !candlist->dwSize || !candlist->dwCount )
995 if ( is_himc_ime_unicode(data) )
997 ret = candlist->dwSize;
998 if ( lpCandList && dwBufLen >= ret )
999 memcpy(lpCandList, candlist, ret);
1002 ret = convert_candidatelist_AtoW( candlist, lpCandList, dwBufLen);
1005 ImmUnlockIMCC(data->IMC.hCandInfo);
1009 /***********************************************************************
1010 * ImmGetCandidateWindow (IMM32.@)
1012 BOOL WINAPI ImmGetCandidateWindow(
1013 HIMC hIMC, DWORD dwIndex, LPCANDIDATEFORM lpCandidate)
1015 InputContextData *data = hIMC;
1017 TRACE("%p, %d, %p\n", hIMC, dwIndex, lpCandidate);
1019 if (!data || !lpCandidate)
1022 if ( dwIndex >= (sizeof(data->IMC.cfCandForm) / sizeof(CANDIDATEFORM)) )
1025 *lpCandidate = data->IMC.cfCandForm[dwIndex];
1030 /***********************************************************************
1031 * ImmGetCompositionFontA (IMM32.@)
1033 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
1038 TRACE("(%p, %p):\n", hIMC, lplf);
1040 rc = ImmGetCompositionFontW(hIMC,&lfW);
1044 memcpy(lplf,&lfW,sizeof(LOGFONTA));
1045 WideCharToMultiByte(CP_ACP, 0, lfW.lfFaceName, -1, lplf->lfFaceName,
1046 LF_FACESIZE, NULL, NULL);
1050 /***********************************************************************
1051 * ImmGetCompositionFontW (IMM32.@)
1053 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
1055 InputContextData *data = hIMC;
1057 TRACE("(%p, %p):\n", hIMC, lplf);
1062 *lplf = data->IMC.lfFont.W;
1068 /* Helpers for the GetCompositionString functions */
1070 static INT CopyCompStringIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE target, INT tlen,
1075 if (is_himc_ime_unicode(data) && !unicode)
1076 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)source, slen, (LPSTR)target, tlen, NULL, NULL);
1077 else if (!is_himc_ime_unicode(data) && unicode)
1078 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)source, slen, (LPWSTR)target, tlen) * sizeof(WCHAR);
1081 int dlen = (unicode)?sizeof(WCHAR):sizeof(CHAR);
1082 memcpy( target, source, min(slen,tlen)*dlen);
1089 static INT CopyCompAttrIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE ssource, INT sslen,
1090 LPBYTE target, INT tlen, BOOL unicode )
1094 if (is_himc_ime_unicode(data) && !unicode)
1096 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource, sslen, NULL, 0, NULL, NULL);
1099 const BYTE *src = source;
1100 LPBYTE dst = target;
1101 int i, j = 0, k = 0;
1105 for (i = 0; i < sslen; ++i)
1109 len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)ssource + i, 1,
1110 NULL, 0, NULL, NULL);
1111 for (; len > 0; --len)
1124 else if (!is_himc_ime_unicode(data) && unicode)
1126 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource, sslen, NULL, 0);
1129 const BYTE *src = source;
1130 LPBYTE dst = target;
1135 for (i = 0; i < sslen; ++i)
1137 if (IsDBCSLeadByte(((LPSTR)ssource)[i]))
1150 memcpy( target, source, min(slen,tlen));
1157 static INT CopyCompClauseIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE ssource,
1158 LPBYTE target, INT tlen, BOOL unicode )
1162 if (is_himc_ime_unicode(data) && !unicode)
1170 tlen /= sizeof (DWORD);
1171 for (i = 0; i < tlen; ++i)
1173 ((DWORD *)target)[i] = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource,
1174 ((DWORD *)source)[i],
1178 rc = sizeof (DWORD) * i;
1183 else if (!is_himc_ime_unicode(data) && unicode)
1191 tlen /= sizeof (DWORD);
1192 for (i = 0; i < tlen; ++i)
1194 ((DWORD *)target)[i] = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource,
1195 ((DWORD *)source)[i],
1198 rc = sizeof (DWORD) * i;
1205 memcpy( target, source, min(slen,tlen));
1212 static INT CopyCompOffsetIMEtoClient(InputContextData *data, DWORD offset, LPBYTE ssource, BOOL unicode)
1216 if (is_himc_ime_unicode(data) && !unicode)
1218 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource, offset, NULL, 0, NULL, NULL);
1220 else if (!is_himc_ime_unicode(data) && unicode)
1222 rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource, offset, NULL, 0);
1230 static LONG ImmGetCompositionStringT( HIMC hIMC, DWORD dwIndex, LPVOID lpBuf,
1231 DWORD dwBufLen, BOOL unicode)
1234 InputContextData *data = hIMC;
1235 LPCOMPOSITIONSTRING compstr;
1238 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
1243 if (!data->IMC.hCompStr)
1246 compdata = ImmLockIMCC(data->IMC.hCompStr);
1247 compstr = (LPCOMPOSITIONSTRING)compdata;
1252 TRACE("GCS_RESULTSTR\n");
1253 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwResultStrOffset, compstr->dwResultStrLen, lpBuf, dwBufLen, unicode);
1256 TRACE("GCS_COMPSTR\n");
1257 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwCompStrOffset, compstr->dwCompStrLen, lpBuf, dwBufLen, unicode);
1260 TRACE("GCS_COMPATTR\n");
1261 rc = CopyCompAttrIMEtoClient(data, compdata + compstr->dwCompAttrOffset, compstr->dwCompAttrLen,
1262 compdata + compstr->dwCompStrOffset, compstr->dwCompStrLen,
1263 lpBuf, dwBufLen, unicode);
1265 case GCS_COMPCLAUSE:
1266 TRACE("GCS_COMPCLAUSE\n");
1267 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwCompClauseOffset,compstr->dwCompClauseLen,
1268 compdata + compstr->dwCompStrOffset,
1269 lpBuf, dwBufLen, unicode);
1271 case GCS_RESULTCLAUSE:
1272 TRACE("GCS_RESULTCLAUSE\n");
1273 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwResultClauseOffset,compstr->dwResultClauseLen,
1274 compdata + compstr->dwResultStrOffset,
1275 lpBuf, dwBufLen, unicode);
1277 case GCS_RESULTREADSTR:
1278 TRACE("GCS_RESULTREADSTR\n");
1279 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwResultReadStrOffset, compstr->dwResultReadStrLen, lpBuf, dwBufLen, unicode);
1281 case GCS_RESULTREADCLAUSE:
1282 TRACE("GCS_RESULTREADCLAUSE\n");
1283 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwResultReadClauseOffset,compstr->dwResultReadClauseLen,
1284 compdata + compstr->dwResultStrOffset,
1285 lpBuf, dwBufLen, unicode);
1287 case GCS_COMPREADSTR:
1288 TRACE("GCS_COMPREADSTR\n");
1289 rc = CopyCompStringIMEtoClient(data, compdata + compstr->dwCompReadStrOffset, compstr->dwCompReadStrLen, lpBuf, dwBufLen, unicode);
1291 case GCS_COMPREADATTR:
1292 TRACE("GCS_COMPREADATTR\n");
1293 rc = CopyCompAttrIMEtoClient(data, compdata + compstr->dwCompReadAttrOffset, compstr->dwCompReadAttrLen,
1294 compdata + compstr->dwCompReadStrOffset, compstr->dwCompReadStrLen,
1295 lpBuf, dwBufLen, unicode);
1297 case GCS_COMPREADCLAUSE:
1298 TRACE("GCS_COMPREADCLAUSE\n");
1299 rc = CopyCompClauseIMEtoClient(data, compdata + compstr->dwCompReadClauseOffset,compstr->dwCompReadClauseLen,
1300 compdata + compstr->dwCompStrOffset,
1301 lpBuf, dwBufLen, unicode);
1304 TRACE("GCS_CURSORPOS\n");
1305 rc = CopyCompOffsetIMEtoClient(data, compstr->dwCursorPos, compdata + compstr->dwCompStrOffset, unicode);
1307 case GCS_DELTASTART:
1308 TRACE("GCS_DELTASTART\n");
1309 rc = CopyCompOffsetIMEtoClient(data, compstr->dwDeltaStart, compdata + compstr->dwCompStrOffset, unicode);
1312 FIXME("Unhandled index 0x%x\n",dwIndex);
1316 ImmUnlockIMCC(data->IMC.hCompStr);
1321 /***********************************************************************
1322 * ImmGetCompositionStringA (IMM32.@)
1324 LONG WINAPI ImmGetCompositionStringA(
1325 HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
1327 return ImmGetCompositionStringT(hIMC, dwIndex, lpBuf, dwBufLen, FALSE);
1331 /***********************************************************************
1332 * ImmGetCompositionStringW (IMM32.@)
1334 LONG WINAPI ImmGetCompositionStringW(
1335 HIMC hIMC, DWORD dwIndex,
1336 LPVOID lpBuf, DWORD dwBufLen)
1338 return ImmGetCompositionStringT(hIMC, dwIndex, lpBuf, dwBufLen, TRUE);
1341 /***********************************************************************
1342 * ImmGetCompositionWindow (IMM32.@)
1344 BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
1346 InputContextData *data = hIMC;
1348 TRACE("(%p, %p)\n", hIMC, lpCompForm);
1353 *lpCompForm = data->IMC.cfCompForm;
1357 /***********************************************************************
1358 * ImmGetContext (IMM32.@)
1361 HIMC WINAPI ImmGetContext(HWND hWnd)
1365 TRACE("%p\n", hWnd);
1367 if (!IsWindow(hWnd))
1369 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1372 if (!IMM_GetThreadData()->defaultContext)
1373 IMM_GetThreadData()->defaultContext = ImmCreateContext();
1375 rc = GetPropW(hWnd,szwWineIMCProperty);
1378 else if (rc == NULL)
1379 rc = IMM_GetThreadData()->defaultContext;
1383 InputContextData *data = rc;
1384 data->IMC.hWnd = hWnd;
1386 TRACE("returning %p\n", rc);
1391 /***********************************************************************
1392 * ImmGetConversionListA (IMM32.@)
1394 DWORD WINAPI ImmGetConversionListA(
1396 LPCSTR pSrc, LPCANDIDATELIST lpDst,
1397 DWORD dwBufLen, UINT uFlag)
1399 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1400 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_a(pSrc), lpDst,
1402 if (immHkl->hIME && immHkl->pImeConversionList)
1404 if (!is_kbd_ime_unicode(immHkl))
1405 return immHkl->pImeConversionList(hIMC,(LPCWSTR)pSrc,lpDst,dwBufLen,uFlag);
1408 LPCANDIDATELIST lpwDst;
1410 LPWSTR pwSrc = strdupAtoW(pSrc);
1412 len = immHkl->pImeConversionList(hIMC, pwSrc, NULL, 0, uFlag);
1413 lpwDst = HeapAlloc(GetProcessHeap(), 0, len);
1416 immHkl->pImeConversionList(hIMC, pwSrc, lpwDst, len, uFlag);
1417 ret = convert_candidatelist_WtoA( lpwDst, lpDst, dwBufLen);
1418 HeapFree(GetProcessHeap(), 0, lpwDst);
1420 HeapFree(GetProcessHeap(), 0, pwSrc);
1429 /***********************************************************************
1430 * ImmGetConversionListW (IMM32.@)
1432 DWORD WINAPI ImmGetConversionListW(
1434 LPCWSTR pSrc, LPCANDIDATELIST lpDst,
1435 DWORD dwBufLen, UINT uFlag)
1437 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1438 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_w(pSrc), lpDst,
1440 if (immHkl->hIME && immHkl->pImeConversionList)
1442 if (is_kbd_ime_unicode(immHkl))
1443 return immHkl->pImeConversionList(hIMC,pSrc,lpDst,dwBufLen,uFlag);
1446 LPCANDIDATELIST lpaDst;
1448 LPSTR paSrc = strdupWtoA(pSrc);
1450 len = immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, NULL, 0, uFlag);
1451 lpaDst = HeapAlloc(GetProcessHeap(), 0, len);
1454 immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, lpaDst, len, uFlag);
1455 ret = convert_candidatelist_AtoW( lpaDst, lpDst, dwBufLen);
1456 HeapFree(GetProcessHeap(), 0, lpaDst);
1458 HeapFree(GetProcessHeap(), 0, paSrc);
1467 /***********************************************************************
1468 * ImmGetConversionStatus (IMM32.@)
1470 BOOL WINAPI ImmGetConversionStatus(
1471 HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
1473 InputContextData *data = hIMC;
1475 TRACE("%p %p %p\n", hIMC, lpfdwConversion, lpfdwSentence);
1480 if (lpfdwConversion)
1481 *lpfdwConversion = data->IMC.fdwConversion;
1483 *lpfdwSentence = data->IMC.fdwSentence;
1488 /***********************************************************************
1489 * ImmGetDefaultIMEWnd (IMM32.@)
1491 HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
1493 TRACE("Default is %p\n",IMM_GetThreadData()->hwndDefault);
1494 return IMM_GetThreadData()->hwndDefault;
1497 /***********************************************************************
1498 * ImmGetDescriptionA (IMM32.@)
1500 UINT WINAPI ImmGetDescriptionA(
1501 HKL hKL, LPSTR lpszDescription, UINT uBufLen)
1506 TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
1508 /* find out how many characters in the unicode buffer */
1509 len = ImmGetDescriptionW( hKL, NULL, 0 );
1511 /* allocate a buffer of that size */
1512 buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
1516 /* fetch the unicode buffer */
1517 len = ImmGetDescriptionW( hKL, buf, len + 1 );
1519 /* convert it back to ASCII */
1520 len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
1521 lpszDescription, uBufLen, NULL, NULL );
1523 HeapFree( GetProcessHeap(), 0, buf );
1528 /***********************************************************************
1529 * ImmGetDescriptionW (IMM32.@)
1531 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
1533 static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
1535 FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
1537 if (!uBufLen) return lstrlenW( name );
1538 lstrcpynW( lpszDescription, name, uBufLen );
1539 return lstrlenW( lpszDescription );
1542 /***********************************************************************
1543 * ImmGetGuideLineA (IMM32.@)
1545 DWORD WINAPI ImmGetGuideLineA(
1546 HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
1548 FIXME("(%p, %d, %s, %d): stub\n",
1549 hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
1551 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1555 /***********************************************************************
1556 * ImmGetGuideLineW (IMM32.@)
1558 DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
1560 FIXME("(%p, %d, %s, %d): stub\n",
1561 hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
1563 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1567 /***********************************************************************
1568 * ImmGetIMEFileNameA (IMM32.@)
1570 UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen)
1573 UINT wBufLen = uBufLen;
1576 if (uBufLen && lpszFileName)
1577 bufW = HeapAlloc(GetProcessHeap(),0,uBufLen * sizeof(WCHAR));
1578 else /* We need this to get the number of byte required */
1580 bufW = HeapAlloc(GetProcessHeap(),0,MAX_PATH * sizeof(WCHAR));
1584 rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen);
1588 if (uBufLen && lpszFileName)
1589 rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName,
1590 uBufLen, NULL, NULL);
1591 else /* get the length */
1592 rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL,
1596 HeapFree(GetProcessHeap(),0,bufW);
1600 /***********************************************************************
1601 * ImmGetIMEFileNameW (IMM32.@)
1603 UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
1608 WCHAR regKey[sizeof(szImeRegFmt)/sizeof(WCHAR)+8];
1610 wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hKL );
1611 rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
1612 if (rc != ERROR_SUCCESS)
1619 rc = RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, NULL, &length);
1621 if (rc != ERROR_SUCCESS)
1627 if (length > uBufLen * sizeof(WCHAR) || !lpszFileName)
1632 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1636 return length / sizeof(WCHAR);
1639 RegGetValueW(hkey, NULL, szImeFileW, RRF_RT_REG_SZ, NULL, lpszFileName, &length);
1643 return length / sizeof(WCHAR);
1646 /***********************************************************************
1647 * ImmGetOpenStatus (IMM32.@)
1649 BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
1651 InputContextData *data = hIMC;
1657 TRACE("(%p): semi-stub\n", hIMC);
1660 FIXME("(%p): semi-stub\n", hIMC);
1662 return data->IMC.fOpen;
1665 /***********************************************************************
1666 * ImmGetProperty (IMM32.@)
1668 DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
1673 TRACE("(%p, %d)\n", hKL, fdwIndex);
1674 kbd = IMM_GetImmHkl(hKL);
1676 if (kbd && kbd->hIME)
1680 case IGP_PROPERTY: rc = kbd->imeInfo.fdwProperty; break;
1681 case IGP_CONVERSION: rc = kbd->imeInfo.fdwConversionCaps; break;
1682 case IGP_SENTENCE: rc = kbd->imeInfo.fdwSentenceCaps; break;
1683 case IGP_SETCOMPSTR: rc = kbd->imeInfo.fdwSCSCaps; break;
1684 case IGP_SELECT: rc = kbd->imeInfo.fdwSelectCaps; break;
1685 case IGP_GETIMEVERSION: rc = IMEVER_0400; break;
1686 case IGP_UI: rc = 0; break;
1693 /***********************************************************************
1694 * ImmGetRegisterWordStyleA (IMM32.@)
1696 UINT WINAPI ImmGetRegisterWordStyleA(
1697 HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
1699 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1700 TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
1701 if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
1703 if (!is_kbd_ime_unicode(immHkl))
1704 return immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)lpStyleBuf);
1710 rc = immHkl->pImeGetRegisterWordStyle(nItem,&sbw);
1711 WideCharToMultiByte(CP_ACP, 0, sbw.szDescription, -1,
1712 lpStyleBuf->szDescription, 32, NULL, NULL);
1713 lpStyleBuf->dwStyle = sbw.dwStyle;
1721 /***********************************************************************
1722 * ImmGetRegisterWordStyleW (IMM32.@)
1724 UINT WINAPI ImmGetRegisterWordStyleW(
1725 HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
1727 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1728 TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf);
1729 if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle)
1731 if (is_kbd_ime_unicode(immHkl))
1732 return immHkl->pImeGetRegisterWordStyle(nItem,lpStyleBuf);
1738 rc = immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)&sba);
1739 MultiByteToWideChar(CP_ACP, 0, sba.szDescription, -1,
1740 lpStyleBuf->szDescription, 32);
1741 lpStyleBuf->dwStyle = sba.dwStyle;
1749 /***********************************************************************
1750 * ImmGetStatusWindowPos (IMM32.@)
1752 BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1754 InputContextData *data = hIMC;
1756 TRACE("(%p, %p)\n", hIMC, lpptPos);
1758 if (!data || !lpptPos)
1761 *lpptPos = data->IMC.ptStatusWndPos;
1766 /***********************************************************************
1767 * ImmGetVirtualKey (IMM32.@)
1769 UINT WINAPI ImmGetVirtualKey(HWND hWnd)
1771 OSVERSIONINFOA version;
1772 InputContextData *data = ImmGetContext( hWnd );
1773 TRACE("%p\n", hWnd);
1776 return data->lastVK;
1778 version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
1779 GetVersionExA( &version );
1780 switch(version.dwPlatformId)
1782 case VER_PLATFORM_WIN32_WINDOWS:
1783 return VK_PROCESSKEY;
1784 case VER_PLATFORM_WIN32_NT:
1787 FIXME("%d not supported\n",version.dwPlatformId);
1788 return VK_PROCESSKEY;
1792 /***********************************************************************
1793 * ImmInstallIMEA (IMM32.@)
1795 HKL WINAPI ImmInstallIMEA(
1796 LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
1798 LPWSTR lpszwIMEFileName;
1799 LPWSTR lpszwLayoutText;
1802 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName),
1803 debugstr_a(lpszLayoutText));
1805 lpszwIMEFileName = strdupAtoW(lpszIMEFileName);
1806 lpszwLayoutText = strdupAtoW(lpszLayoutText);
1808 hkl = ImmInstallIMEW(lpszwIMEFileName, lpszwLayoutText);
1810 HeapFree(GetProcessHeap(),0,lpszwIMEFileName);
1811 HeapFree(GetProcessHeap(),0,lpszwLayoutText);
1815 /***********************************************************************
1816 * ImmInstallIMEW (IMM32.@)
1818 HKL WINAPI ImmInstallIMEW(
1819 LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
1821 INT lcid = GetUserDefaultLCID();
1826 WCHAR regKey[sizeof(szImeRegFmt)/sizeof(WCHAR)+8];
1828 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName),
1829 debugstr_w(lpszLayoutText));
1831 /* Start with 2. e001 will be blank and so default to the wine internal IME */
1834 while (count < 0xfff)
1836 DWORD disposition = 0;
1838 hkl = (HKL)MAKELPARAM( lcid, 0xe000 | count );
1839 wsprintfW( regKey, szImeRegFmt, (ULONG_PTR)hkl);
1841 rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, regKey, 0, NULL, 0, KEY_WRITE, NULL, &hkey, &disposition);
1842 if (rc == ERROR_SUCCESS && disposition == REG_CREATED_NEW_KEY)
1844 else if (rc == ERROR_SUCCESS)
1852 WARN("Unable to find slot to install IME\n");
1856 if (rc == ERROR_SUCCESS)
1858 rc = RegSetValueExW(hkey, szImeFileW, 0, REG_SZ, (const BYTE*)lpszIMEFileName,
1859 (lstrlenW(lpszIMEFileName) + 1) * sizeof(WCHAR));
1860 if (rc == ERROR_SUCCESS)
1861 rc = RegSetValueExW(hkey, szLayoutTextW, 0, REG_SZ, (const BYTE*)lpszLayoutText,
1862 (lstrlenW(lpszLayoutText) + 1) * sizeof(WCHAR));
1868 WARN("Unable to set IME registry values\n");
1873 /***********************************************************************
1874 * ImmIsIME (IMM32.@)
1876 BOOL WINAPI ImmIsIME(HKL hKL)
1879 TRACE("(%p):\n", hKL);
1880 ptr = IMM_GetImmHkl(hKL);
1881 return (ptr && ptr->hIME);
1884 /***********************************************************************
1885 * ImmIsUIMessageA (IMM32.@)
1887 BOOL WINAPI ImmIsUIMessageA(
1888 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1892 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1893 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1894 (msg == WM_IME_SETCONTEXT) ||
1895 (msg == WM_IME_NOTIFY) ||
1896 (msg == WM_IME_COMPOSITIONFULL) ||
1897 (msg == WM_IME_SELECT) ||
1898 (msg == 0x287 /* FIXME: WM_IME_SYSTEM */) ||
1899 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1900 (msg == WM_MSIME_MOUSE) ||
1901 (msg == WM_MSIME_RECONVERTREQUEST) ||
1902 (msg == WM_MSIME_RECONVERT) ||
1903 (msg == WM_MSIME_QUERYPOSITION) ||
1904 (msg == WM_MSIME_DOCUMENTFEED))
1907 SendMessageA(hWndIME, msg, wParam, lParam);
1914 /***********************************************************************
1915 * ImmIsUIMessageW (IMM32.@)
1917 BOOL WINAPI ImmIsUIMessageW(
1918 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1922 TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam);
1923 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1924 (msg == WM_IME_SETCONTEXT) ||
1925 (msg == WM_IME_NOTIFY) ||
1926 (msg == WM_IME_COMPOSITIONFULL) ||
1927 (msg == WM_IME_SELECT) ||
1928 (msg == 0x287 /* FIXME: WM_IME_SYSTEM */) ||
1929 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1930 (msg == WM_MSIME_MOUSE) ||
1931 (msg == WM_MSIME_RECONVERTREQUEST) ||
1932 (msg == WM_MSIME_RECONVERT) ||
1933 (msg == WM_MSIME_QUERYPOSITION) ||
1934 (msg == WM_MSIME_DOCUMENTFEED))
1937 SendMessageW(hWndIME, msg, wParam, lParam);
1944 /***********************************************************************
1945 * ImmNotifyIME (IMM32.@)
1947 BOOL WINAPI ImmNotifyIME(
1948 HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
1950 InputContextData *data = hIMC;
1952 TRACE("(%p, %d, %d, %d)\n",
1953 hIMC, dwAction, dwIndex, dwValue);
1955 if (!data || ! data->immKbd->pNotifyIME)
1958 return data->immKbd->pNotifyIME(hIMC,dwAction,dwIndex,dwValue);
1961 /***********************************************************************
1962 * ImmRegisterWordA (IMM32.@)
1964 BOOL WINAPI ImmRegisterWordA(
1965 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
1967 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1968 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_a(lpszReading), dwStyle,
1969 debugstr_a(lpszRegister));
1970 if (immHkl->hIME && immHkl->pImeRegisterWord)
1972 if (!is_kbd_ime_unicode(immHkl))
1973 return immHkl->pImeRegisterWord((LPCWSTR)lpszReading,dwStyle,
1974 (LPCWSTR)lpszRegister);
1977 LPWSTR lpszwReading = strdupAtoW(lpszReading);
1978 LPWSTR lpszwRegister = strdupAtoW(lpszRegister);
1981 rc = immHkl->pImeRegisterWord(lpszwReading,dwStyle,lpszwRegister);
1982 HeapFree(GetProcessHeap(),0,lpszwReading);
1983 HeapFree(GetProcessHeap(),0,lpszwRegister);
1991 /***********************************************************************
1992 * ImmRegisterWordW (IMM32.@)
1994 BOOL WINAPI ImmRegisterWordW(
1995 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
1997 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
1998 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_w(lpszReading), dwStyle,
1999 debugstr_w(lpszRegister));
2000 if (immHkl->hIME && immHkl->pImeRegisterWord)
2002 if (is_kbd_ime_unicode(immHkl))
2003 return immHkl->pImeRegisterWord(lpszReading,dwStyle,lpszRegister);
2006 LPSTR lpszaReading = strdupWtoA(lpszReading);
2007 LPSTR lpszaRegister = strdupWtoA(lpszRegister);
2010 rc = immHkl->pImeRegisterWord((LPCWSTR)lpszaReading,dwStyle,
2011 (LPCWSTR)lpszaRegister);
2012 HeapFree(GetProcessHeap(),0,lpszaReading);
2013 HeapFree(GetProcessHeap(),0,lpszaRegister);
2021 /***********************************************************************
2022 * ImmReleaseContext (IMM32.@)
2024 BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
2026 static int shown = 0;
2029 FIXME("(%p, %p): stub\n", hWnd, hIMC);
2035 /***********************************************************************
2036 * ImmRequestMessageA(IMM32.@)
2038 LRESULT WINAPI ImmRequestMessageA(HIMC hIMC, WPARAM wParam, LPARAM lParam)
2040 InputContextData *data = hIMC;
2042 TRACE("%p %ld %ld\n", hIMC, wParam, wParam);
2044 if (data && IsWindow(data->IMC.hWnd))
2045 return SendMessageA(data->IMC.hWnd, WM_IME_REQUEST, wParam, lParam);
2050 /***********************************************************************
2051 * ImmRequestMessageW(IMM32.@)
2053 LRESULT WINAPI ImmRequestMessageW(HIMC hIMC, WPARAM wParam, LPARAM lParam)
2055 InputContextData *data = hIMC;
2057 TRACE("%p %ld %ld\n", hIMC, wParam, wParam);
2059 if (data && IsWindow(data->IMC.hWnd))
2060 return SendMessageW(data->IMC.hWnd, WM_IME_REQUEST, wParam, lParam);
2065 /***********************************************************************
2066 * ImmSetCandidateWindow (IMM32.@)
2068 BOOL WINAPI ImmSetCandidateWindow(
2069 HIMC hIMC, LPCANDIDATEFORM lpCandidate)
2071 InputContextData *data = hIMC;
2073 TRACE("(%p, %p)\n", hIMC, lpCandidate);
2075 if (!data || !lpCandidate)
2078 TRACE("\t%x, %x, (%i,%i), (%i,%i - %i,%i)\n",
2079 lpCandidate->dwIndex, lpCandidate->dwStyle,
2080 lpCandidate->ptCurrentPos.x, lpCandidate->ptCurrentPos.y,
2081 lpCandidate->rcArea.top, lpCandidate->rcArea.left,
2082 lpCandidate->rcArea.bottom, lpCandidate->rcArea.right);
2084 if ( lpCandidate->dwIndex >= (sizeof(data->IMC.cfCandForm) / sizeof(CANDIDATEFORM)) )
2087 data->IMC.cfCandForm[lpCandidate->dwIndex] = *lpCandidate;
2088 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCANDIDATEPOS);
2089 ImmInternalSendIMENotify(data, IMN_SETCANDIDATEPOS, 1 << lpCandidate->dwIndex);
2094 /***********************************************************************
2095 * ImmSetCompositionFontA (IMM32.@)
2097 BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
2099 InputContextData *data = hIMC;
2100 TRACE("(%p, %p)\n", hIMC, lplf);
2105 memcpy(&data->IMC.lfFont.W,lplf,sizeof(LOGFONTA));
2106 MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->IMC.lfFont.W.lfFaceName,
2108 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCOMPOSITIONFONT);
2109 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONFONT, 0);
2114 /***********************************************************************
2115 * ImmSetCompositionFontW (IMM32.@)
2117 BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
2119 InputContextData *data = hIMC;
2120 TRACE("(%p, %p)\n", hIMC, lplf);
2125 data->IMC.lfFont.W = *lplf;
2126 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, 0, IMC_SETCOMPOSITIONFONT);
2127 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONFONT, 0);
2132 /***********************************************************************
2133 * ImmSetCompositionStringA (IMM32.@)
2135 BOOL WINAPI ImmSetCompositionStringA(
2136 HIMC hIMC, DWORD dwIndex,
2137 LPCVOID lpComp, DWORD dwCompLen,
2138 LPCVOID lpRead, DWORD dwReadLen)
2142 WCHAR *CompBuffer = NULL;
2143 WCHAR *ReadBuffer = NULL;
2145 InputContextData *data = hIMC;
2147 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2148 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
2153 if (!(dwIndex == SCS_SETSTR ||
2154 dwIndex == SCS_CHANGEATTR ||
2155 dwIndex == SCS_CHANGECLAUSE ||
2156 dwIndex == SCS_SETRECONVERTSTRING ||
2157 dwIndex == SCS_QUERYRECONVERTSTRING))
2160 if (!is_himc_ime_unicode(data))
2161 return data->immKbd->pImeSetCompositionString(hIMC, dwIndex, lpComp,
2162 dwCompLen, lpRead, dwReadLen);
2164 comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
2167 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
2168 MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
2171 read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
2174 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
2175 MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
2178 rc = ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
2179 ReadBuffer, read_len);
2181 HeapFree(GetProcessHeap(), 0, CompBuffer);
2182 HeapFree(GetProcessHeap(), 0, ReadBuffer);
2187 /***********************************************************************
2188 * ImmSetCompositionStringW (IMM32.@)
2190 BOOL WINAPI ImmSetCompositionStringW(
2191 HIMC hIMC, DWORD dwIndex,
2192 LPCVOID lpComp, DWORD dwCompLen,
2193 LPCVOID lpRead, DWORD dwReadLen)
2197 CHAR *CompBuffer = NULL;
2198 CHAR *ReadBuffer = NULL;
2200 InputContextData *data = hIMC;
2202 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2203 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
2208 if (!(dwIndex == SCS_SETSTR ||
2209 dwIndex == SCS_CHANGEATTR ||
2210 dwIndex == SCS_CHANGECLAUSE ||
2211 dwIndex == SCS_SETRECONVERTSTRING ||
2212 dwIndex == SCS_QUERYRECONVERTSTRING))
2215 if (is_himc_ime_unicode(data))
2216 return data->immKbd->pImeSetCompositionString(hIMC, dwIndex, lpComp,
2217 dwCompLen, lpRead, dwReadLen);
2219 comp_len = WideCharToMultiByte(CP_ACP, 0, lpComp, dwCompLen, NULL, 0, NULL,
2223 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len);
2224 WideCharToMultiByte(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len,
2228 read_len = WideCharToMultiByte(CP_ACP, 0, lpRead, dwReadLen, NULL, 0, NULL,
2232 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len);
2233 WideCharToMultiByte(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len,
2237 rc = ImmSetCompositionStringA(hIMC, dwIndex, CompBuffer, comp_len,
2238 ReadBuffer, read_len);
2240 HeapFree(GetProcessHeap(), 0, CompBuffer);
2241 HeapFree(GetProcessHeap(), 0, ReadBuffer);
2246 /***********************************************************************
2247 * ImmSetCompositionWindow (IMM32.@)
2249 BOOL WINAPI ImmSetCompositionWindow(
2250 HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
2252 BOOL reshow = FALSE;
2253 InputContextData *data = hIMC;
2255 TRACE("(%p, %p)\n", hIMC, lpCompForm);
2256 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm->dwStyle,
2257 lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
2258 lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);
2263 data->IMC.cfCompForm = *lpCompForm;
2265 if (IsWindowVisible(IMM_GetThreadData()->hwndDefault))
2268 ShowWindow(IMM_GetThreadData()->hwndDefault,SW_HIDE);
2271 /* FIXME: this is a partial stub */
2274 ShowWindow(IMM_GetThreadData()->hwndDefault,SW_SHOWNOACTIVATE);
2276 ImmInternalSendIMENotify(data, IMN_SETCOMPOSITIONWINDOW, 0);
2280 /***********************************************************************
2281 * ImmSetConversionStatus (IMM32.@)
2283 BOOL WINAPI ImmSetConversionStatus(
2284 HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
2286 DWORD oldConversion, oldSentence;
2287 InputContextData *data = hIMC;
2289 TRACE("%p %d %d\n", hIMC, fdwConversion, fdwSentence);
2294 if ( fdwConversion != data->IMC.fdwConversion )
2296 oldConversion = data->IMC.fdwConversion;
2297 data->IMC.fdwConversion = fdwConversion;
2298 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, oldConversion, IMC_SETCONVERSIONMODE);
2299 ImmInternalSendIMENotify(data, IMN_SETCONVERSIONMODE, 0);
2301 if ( fdwSentence != data->IMC.fdwSentence )
2303 oldSentence = data->IMC.fdwSentence;
2304 data->IMC.fdwSentence = fdwSentence;
2305 ImmNotifyIME(hIMC, NI_CONTEXTUPDATED, oldSentence, IMC_SETSENTENCEMODE);
2306 ImmInternalSendIMENotify(data, IMN_SETSENTENCEMODE, 0);
2312 /***********************************************************************
2313 * ImmSetOpenStatus (IMM32.@)
2315 BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
2317 InputContextData *data = hIMC;
2319 TRACE("%p %d\n", hIMC, fOpen);
2324 if (data->imeWnd == NULL)
2326 /* create the ime window */
2327 data->imeWnd = CreateWindowExW( WS_EX_TOOLWINDOW,
2328 data->immKbd->imeClassName, NULL, WS_POPUP, 0, 0, 1, 1, 0,
2329 0, data->immKbd->hIME, 0);
2330 SetWindowLongPtrW(data->imeWnd, IMMGWL_IMC, (LONG_PTR)data);
2331 IMM_GetThreadData()->hwndDefault = data->imeWnd;
2334 if (!fOpen != !data->IMC.fOpen)
2336 data->IMC.fOpen = fOpen;
2337 ImmNotifyIME( hIMC, NI_CONTEXTUPDATED, 0, IMC_SETOPENSTATUS);
2338 ImmInternalSendIMENotify(data, IMN_SETOPENSTATUS, 0);
2344 /***********************************************************************
2345 * ImmSetStatusWindowPos (IMM32.@)
2347 BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
2349 InputContextData *data = hIMC;
2351 TRACE("(%p, %p)\n", hIMC, lpptPos);
2353 if (!data || !lpptPos)
2356 TRACE("\t(%i,%i)\n", lpptPos->x, lpptPos->y);
2358 data->IMC.ptStatusWndPos = *lpptPos;
2359 ImmNotifyIME( hIMC, NI_CONTEXTUPDATED, 0, IMC_SETSTATUSWINDOWPOS);
2360 ImmInternalSendIMENotify(data, IMN_SETSTATUSWINDOWPOS, 0);
2365 /***********************************************************************
2366 * ImmCreateSoftKeyboard(IMM32.@)
2368 HWND WINAPI ImmCreateSoftKeyboard(UINT uType, UINT hOwner, int x, int y)
2370 FIXME("(%d, %d, %d, %d): stub\n", uType, hOwner, x, y);
2371 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2375 /***********************************************************************
2376 * ImmDestroySoftKeyboard(IMM32.@)
2378 BOOL WINAPI ImmDestroySoftKeyboard(HWND hSoftWnd)
2380 FIXME("(%p): stub\n", hSoftWnd);
2381 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2385 /***********************************************************************
2386 * ImmShowSoftKeyboard(IMM32.@)
2388 BOOL WINAPI ImmShowSoftKeyboard(HWND hSoftWnd, int nCmdShow)
2390 FIXME("(%p, %d): stub\n", hSoftWnd, nCmdShow);
2391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2395 /***********************************************************************
2396 * ImmSimulateHotKey (IMM32.@)
2398 BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
2400 FIXME("(%p, %d): stub\n", hWnd, dwHotKeyID);
2401 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2405 /***********************************************************************
2406 * ImmUnregisterWordA (IMM32.@)
2408 BOOL WINAPI ImmUnregisterWordA(
2409 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
2411 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
2412 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_a(lpszReading), dwStyle,
2413 debugstr_a(lpszUnregister));
2414 if (immHkl->hIME && immHkl->pImeUnregisterWord)
2416 if (!is_kbd_ime_unicode(immHkl))
2417 return immHkl->pImeUnregisterWord((LPCWSTR)lpszReading,dwStyle,
2418 (LPCWSTR)lpszUnregister);
2421 LPWSTR lpszwReading = strdupAtoW(lpszReading);
2422 LPWSTR lpszwUnregister = strdupAtoW(lpszUnregister);
2425 rc = immHkl->pImeUnregisterWord(lpszwReading,dwStyle,lpszwUnregister);
2426 HeapFree(GetProcessHeap(),0,lpszwReading);
2427 HeapFree(GetProcessHeap(),0,lpszwUnregister);
2435 /***********************************************************************
2436 * ImmUnregisterWordW (IMM32.@)
2438 BOOL WINAPI ImmUnregisterWordW(
2439 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
2441 ImmHkl *immHkl = IMM_GetImmHkl(hKL);
2442 TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_w(lpszReading), dwStyle,
2443 debugstr_w(lpszUnregister));
2444 if (immHkl->hIME && immHkl->pImeUnregisterWord)
2446 if (is_kbd_ime_unicode(immHkl))
2447 return immHkl->pImeUnregisterWord(lpszReading,dwStyle,lpszUnregister);
2450 LPSTR lpszaReading = strdupWtoA(lpszReading);
2451 LPSTR lpszaUnregister = strdupWtoA(lpszUnregister);
2454 rc = immHkl->pImeUnregisterWord((LPCWSTR)lpszaReading,dwStyle,
2455 (LPCWSTR)lpszaUnregister);
2456 HeapFree(GetProcessHeap(),0,lpszaReading);
2457 HeapFree(GetProcessHeap(),0,lpszaUnregister);
2465 /***********************************************************************
2466 * ImmGetImeMenuItemsA (IMM32.@)
2468 DWORD WINAPI ImmGetImeMenuItemsA( HIMC hIMC, DWORD dwFlags, DWORD dwType,
2469 LPIMEMENUITEMINFOA lpImeParentMenu, LPIMEMENUITEMINFOA lpImeMenu,
2472 InputContextData *data = hIMC;
2473 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC, dwFlags, dwType,
2474 lpImeParentMenu, lpImeMenu, dwSize);
2475 if (data->immKbd->hIME && data->immKbd->pImeGetImeMenuItems)
2477 if (!is_himc_ime_unicode(data) || (!lpImeParentMenu && !lpImeMenu))
2478 return data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2479 (IMEMENUITEMINFOW*)lpImeParentMenu,
2480 (IMEMENUITEMINFOW*)lpImeMenu, dwSize);
2483 IMEMENUITEMINFOW lpImeParentMenuW;
2484 IMEMENUITEMINFOW *lpImeMenuW, *parent = NULL;
2487 if (lpImeParentMenu)
2488 parent = &lpImeParentMenuW;
2491 int count = dwSize / sizeof(LPIMEMENUITEMINFOA);
2492 dwSize = count * sizeof(IMEMENUITEMINFOW);
2493 lpImeMenuW = HeapAlloc(GetProcessHeap(), 0, dwSize);
2498 rc = data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2499 parent, lpImeMenuW, dwSize);
2501 if (lpImeParentMenu)
2503 memcpy(lpImeParentMenu,&lpImeParentMenuW,sizeof(IMEMENUITEMINFOA));
2504 lpImeParentMenu->hbmpItem = lpImeParentMenuW.hbmpItem;
2505 WideCharToMultiByte(CP_ACP, 0, lpImeParentMenuW.szString,
2506 -1, lpImeParentMenu->szString, IMEMENUITEM_STRING_SIZE,
2509 if (lpImeMenu && rc)
2512 for (i = 0; i < rc; i++)
2514 memcpy(&lpImeMenu[i],&lpImeMenuW[1],sizeof(IMEMENUITEMINFOA));
2515 lpImeMenu[i].hbmpItem = lpImeMenuW[i].hbmpItem;
2516 WideCharToMultiByte(CP_ACP, 0, lpImeMenuW[i].szString,
2517 -1, lpImeMenu[i].szString, IMEMENUITEM_STRING_SIZE,
2521 HeapFree(GetProcessHeap(),0,lpImeMenuW);
2529 /***********************************************************************
2530 * ImmGetImeMenuItemsW (IMM32.@)
2532 DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType,
2533 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
2536 InputContextData *data = hIMC;
2537 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC, dwFlags, dwType,
2538 lpImeParentMenu, lpImeMenu, dwSize);
2539 if (data->immKbd->hIME && data->immKbd->pImeGetImeMenuItems)
2541 if (is_himc_ime_unicode(data) || (!lpImeParentMenu && !lpImeMenu))
2542 return data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2543 lpImeParentMenu, lpImeMenu, dwSize);
2546 IMEMENUITEMINFOA lpImeParentMenuA;
2547 IMEMENUITEMINFOA *lpImeMenuA, *parent = NULL;
2550 if (lpImeParentMenu)
2551 parent = &lpImeParentMenuA;
2554 int count = dwSize / sizeof(LPIMEMENUITEMINFOW);
2555 dwSize = count * sizeof(IMEMENUITEMINFOA);
2556 lpImeMenuA = HeapAlloc(GetProcessHeap(), 0, dwSize);
2561 rc = data->immKbd->pImeGetImeMenuItems(hIMC, dwFlags, dwType,
2562 (IMEMENUITEMINFOW*)parent,
2563 (IMEMENUITEMINFOW*)lpImeMenuA, dwSize);
2565 if (lpImeParentMenu)
2567 memcpy(lpImeParentMenu,&lpImeParentMenuA,sizeof(IMEMENUITEMINFOA));
2568 lpImeParentMenu->hbmpItem = lpImeParentMenuA.hbmpItem;
2569 MultiByteToWideChar(CP_ACP, 0, lpImeParentMenuA.szString,
2570 -1, lpImeParentMenu->szString, IMEMENUITEM_STRING_SIZE);
2572 if (lpImeMenu && rc)
2575 for (i = 0; i < rc; i++)
2577 memcpy(&lpImeMenu[i],&lpImeMenuA[1],sizeof(IMEMENUITEMINFOA));
2578 lpImeMenu[i].hbmpItem = lpImeMenuA[i].hbmpItem;
2579 MultiByteToWideChar(CP_ACP, 0, lpImeMenuA[i].szString,
2580 -1, lpImeMenu[i].szString, IMEMENUITEM_STRING_SIZE);
2583 HeapFree(GetProcessHeap(),0,lpImeMenuA);
2591 /***********************************************************************
2592 * ImmLockIMC(IMM32.@)
2594 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
2596 InputContextData *data = hIMC;
2604 /***********************************************************************
2605 * ImmUnlockIMC(IMM32.@)
2607 BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
2609 InputContextData *data = hIMC;
2611 return (data->dwLock!=0);
2614 /***********************************************************************
2615 * ImmGetIMCLockCount(IMM32.@)
2617 DWORD WINAPI ImmGetIMCLockCount(HIMC hIMC)
2619 InputContextData *data = hIMC;
2620 return data->dwLock;
2623 /***********************************************************************
2624 * ImmCreateIMCC(IMM32.@)
2626 HIMCC WINAPI ImmCreateIMCC(DWORD size)
2628 IMCCInternal *internal;
2629 int real_size = size + sizeof(IMCCInternal);
2631 internal = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, real_size);
2632 if (internal == NULL)
2635 internal->dwSize = size;
2639 /***********************************************************************
2640 * ImmDestroyIMCC(IMM32.@)
2642 HIMCC WINAPI ImmDestroyIMCC(HIMCC block)
2644 HeapFree(GetProcessHeap(),0,block);
2648 /***********************************************************************
2649 * ImmLockIMCC(IMM32.@)
2651 LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
2653 IMCCInternal *internal;
2656 internal->dwLock ++;
2657 return internal + 1;
2660 /***********************************************************************
2661 * ImmUnlockIMCC(IMM32.@)
2663 BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
2665 IMCCInternal *internal;
2668 internal->dwLock --;
2669 return (internal->dwLock!=0);
2672 /***********************************************************************
2673 * ImmGetIMCCLockCount(IMM32.@)
2675 DWORD WINAPI ImmGetIMCCLockCount(HIMCC imcc)
2677 IMCCInternal *internal;
2680 return internal->dwLock;
2683 /***********************************************************************
2684 * ImmReSizeIMCC(IMM32.@)
2686 HIMCC WINAPI ImmReSizeIMCC(HIMCC imcc, DWORD size)
2688 IMCCInternal *internal,*newone;
2689 int real_size = size + sizeof(IMCCInternal);
2693 newone = HeapReAlloc(GetProcessHeap(), 0, internal, real_size);
2694 newone->dwSize = size;
2699 /***********************************************************************
2700 * ImmGetIMCCSize(IMM32.@)
2702 DWORD WINAPI ImmGetIMCCSize(HIMCC imcc)
2704 IMCCInternal *internal;
2707 return internal->dwSize;
2710 /***********************************************************************
2711 * ImmGenerateMessage(IMM32.@)
2713 BOOL WINAPI ImmGenerateMessage(HIMC hIMC)
2715 InputContextData *data = hIMC;
2717 TRACE("%i messages queued\n",data->IMC.dwNumMsgBuf);
2718 if (data->IMC.dwNumMsgBuf > 0)
2720 LPTRANSMSG lpTransMsg;
2723 lpTransMsg = ImmLockIMCC(data->IMC.hMsgBuf);
2724 for (i = 0; i < data->IMC.dwNumMsgBuf; i++)
2725 ImmInternalPostIMEMessage(data, lpTransMsg[i].message, lpTransMsg[i].wParam, lpTransMsg[i].lParam);
2727 ImmUnlockIMCC(data->IMC.hMsgBuf);
2729 data->IMC.dwNumMsgBuf = 0;
2735 /***********************************************************************
2736 * ImmTranslateMessage(IMM32.@)
2737 * ( Undocumented, call internally and from user32.dll )
2739 BOOL WINAPI ImmTranslateMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lKeyData)
2741 InputContextData *data;
2742 HIMC imc = ImmGetContext(hwnd);
2748 static const DWORD list_count = 10;
2750 TRACE("%p %x %x %x\n",hwnd, msg, (UINT)wParam, (UINT)lKeyData);
2757 if (!data->immKbd->hIME || !data->immKbd->pImeToAsciiEx)
2760 GetKeyboardState(state);
2761 scancode = lKeyData >> 0x10 & 0xff;
2763 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list_count * sizeof(TRANSMSG) + sizeof(DWORD));
2764 ((DWORD*)list)[0] = list_count;
2766 if (data->immKbd->imeInfo.fdwProperty & IME_PROP_KBD_CHAR_FIRST)
2770 if (!is_himc_ime_unicode(data))
2771 ToAscii(data->lastVK, scancode, state, &chr, 0);
2773 ToUnicodeEx(data->lastVK, scancode, state, &chr, 1, 0, GetKeyboardLayout(0));
2774 uVirtKey = MAKELONG(data->lastVK,chr);
2777 uVirtKey = data->lastVK;
2779 msg_count = data->immKbd->pImeToAsciiEx(uVirtKey, scancode, state, list, 0, imc);
2780 TRACE("%i messages generated\n",msg_count);
2781 if (msg_count && msg_count <= list_count)
2784 LPTRANSMSG msgs = (LPTRANSMSG)((LPBYTE)list + sizeof(DWORD));
2786 for (i = 0; i < msg_count; i++)
2787 ImmInternalPostIMEMessage(data, msgs[i].message, msgs[i].wParam, msgs[i].lParam);
2789 else if (msg_count > list_count)
2790 ImmGenerateMessage(imc);
2792 HeapFree(GetProcessHeap(),0,list);
2794 data->lastVK = VK_PROCESSKEY;
2796 return (msg_count > 0);
2799 /***********************************************************************
2800 * ImmProcessKey(IMM32.@)
2801 * ( Undocumented, called from user32.dll )
2803 BOOL WINAPI ImmProcessKey(HWND hwnd, HKL hKL, UINT vKey, LPARAM lKeyData, DWORD unknown)
2805 InputContextData *data;
2806 HIMC imc = ImmGetContext(hwnd);
2809 TRACE("%p %p %x %x %x\n",hwnd, hKL, vKey, (UINT)lKeyData, unknown);
2816 if (!data->immKbd->hIME || !data->immKbd->pImeProcessKey)
2819 GetKeyboardState(state);
2820 if (data->immKbd->pImeProcessKey(imc, vKey, lKeyData, state))
2822 data->lastVK = vKey;
2826 data->lastVK = VK_PROCESSKEY;
2830 /***********************************************************************
2831 * ImmDisableTextFrameService(IMM32.@)
2833 BOOL WINAPI ImmDisableTextFrameService(DWORD idThread)
2839 /***********************************************************************
2840 * ImmEnumInputContext(IMM32.@)
2843 BOOL WINAPI ImmEnumInputContext(DWORD idThread, IMCENUMPROC lpfn, LPARAM lParam)
2849 /***********************************************************************
2850 * ImmGetHotKey(IMM32.@)
2853 BOOL WINAPI ImmGetHotKey(DWORD hotkey, UINT *modifiers, UINT *key, HKL hkl)
2855 FIXME("%x, %p, %p, %p: stub\n", hotkey, modifiers, key, hkl);