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"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(imm
);
40 #define IMM_INIT_MAGIC 0x19650412
41 BOOL WINAPI
User32InitializeImmEntryTable(DWORD
);
43 #define MAKE_FUNCPTR(f) typeof(f) * p##f
44 typedef struct _tagImmHkl
{
49 WCHAR imeClassName
[17]; /* 16 character max */
53 /* Function Pointers */
54 MAKE_FUNCPTR(ImeInquire
);
55 MAKE_FUNCPTR(ImeConfigure
);
56 MAKE_FUNCPTR(ImeDestroy
);
57 MAKE_FUNCPTR(ImeEscape
);
58 MAKE_FUNCPTR(ImeSelect
);
59 MAKE_FUNCPTR(ImeSetActiveContext
);
60 MAKE_FUNCPTR(ImeToAsciiEx
);
61 MAKE_FUNCPTR(NotifyIME
);
62 MAKE_FUNCPTR(ImeRegisterWord
);
63 MAKE_FUNCPTR(ImeUnregisterWord
);
64 MAKE_FUNCPTR(ImeEnumRegisterWord
);
65 MAKE_FUNCPTR(ImeSetCompositionString
);
66 MAKE_FUNCPTR(ImeConversionList
);
67 MAKE_FUNCPTR(ImeProcessKey
);
68 MAKE_FUNCPTR(ImeGetRegisterWordStyle
);
69 MAKE_FUNCPTR(ImeGetImeMenuItems
);
73 typedef struct tagInputContextData
85 #define WINE_IMC_VALID_MAGIC 0x56434D49
87 typedef struct _tagTRANSMSG
{
91 } TRANSMSG
, *LPTRANSMSG
;
93 typedef struct _tagIMMThreadData
{
100 static struct list ImmHklList
= LIST_INIT(ImmHklList
);
101 static struct list ImmThreadDataList
= LIST_INIT(ImmThreadDataList
);
103 static const WCHAR szwWineIMCProperty
[] = {'W','i','n','e','I','m','m','H','I','M','C','P','r','o','p','e','r','t','y',0};
105 static const WCHAR szImeFileW
[] = {'I','m','e',' ','F','i','l','e',0};
106 static const WCHAR szLayoutTextW
[] = {'L','a','y','o','u','t',' ','T','e','x','t',0};
107 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};
109 static const WCHAR szwIME
[] = {'I','M','E',0};
111 static CRITICAL_SECTION threaddata_cs
;
112 static CRITICAL_SECTION_DEBUG critsect_debug
=
114 0, 0, &threaddata_cs
,
115 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
116 0, 0, { (DWORD_PTR
)(__FILE__
": threaddata_cs") }
118 static CRITICAL_SECTION threaddata_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
120 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
121 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
123 static BOOL
IMM_DestroyContext(HIMC hIMC
);
124 static InputContextData
* get_imc_data(HIMC hIMC
);
126 static inline WCHAR
*strdupAtoW( const char *str
)
131 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
132 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
133 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
138 static inline CHAR
*strdupWtoA( const WCHAR
*str
)
143 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
144 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
145 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
150 static DWORD
convert_candidatelist_WtoA(
151 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
155 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
156 if ( lpDst
&& dwBufLen
> 0 )
159 lpDst
->dwOffset
[0] = ret
;
162 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
164 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
166 if ( lpDst
&& dwBufLen
> 0 )
168 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
170 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1,
171 (LPSTR
)dest
, dwBufLen
, NULL
, NULL
);
173 if ( i
+ 1 < lpSrc
->dwCount
)
174 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(char);
175 dwBufLen
-= len
* sizeof(char);
178 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1, NULL
, 0, NULL
, NULL
);
180 ret
+= len
* sizeof(char);
189 static DWORD
convert_candidatelist_AtoW(
190 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
194 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
195 if ( lpDst
&& dwBufLen
> 0 )
198 lpDst
->dwOffset
[0] = ret
;
201 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
203 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
205 if ( lpDst
&& dwBufLen
> 0 )
207 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
209 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1,
210 (LPWSTR
)dest
, dwBufLen
);
212 if ( i
+ 1 < lpSrc
->dwCount
)
213 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(WCHAR
);
214 dwBufLen
-= len
* sizeof(WCHAR
);
217 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, NULL
, 0);
219 ret
+= len
* sizeof(WCHAR
);
228 static IMMThreadData
*IMM_GetThreadData(HWND hwnd
)
231 DWORD process
, thread
;
235 if (!(thread
= GetWindowThreadProcessId(hwnd
, &process
))) return NULL
;
236 if (process
!= GetCurrentProcessId()) return NULL
;
238 else thread
= GetCurrentThreadId();
240 EnterCriticalSection(&threaddata_cs
);
241 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
242 if (data
->threadID
== thread
) return data
;
244 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
));
245 data
->threadID
= thread
;
246 list_add_head(&ImmThreadDataList
,&data
->entry
);
247 TRACE("Thread Data Created (%x)\n",thread
);
251 static BOOL
IMM_IsDefaultContext(HIMC imc
)
253 InputContextData
*data
= get_imc_data(imc
);
258 return data
->threadDefault
;
261 static void IMM_FreeThreadData(void)
265 EnterCriticalSection(&threaddata_cs
);
266 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
268 if (data
->threadID
== GetCurrentThreadId())
270 list_remove(&data
->entry
);
271 LeaveCriticalSection(&threaddata_cs
);
272 IMM_DestroyContext(data
->defaultContext
);
273 HeapFree(GetProcessHeap(),0,data
);
274 TRACE("Thread Data Destroyed\n");
278 LeaveCriticalSection(&threaddata_cs
);
281 static HMODULE
load_graphics_driver(void)
283 static const WCHAR display_device_guid_propW
[] = {
284 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
285 'd','e','v','i','c','e','_','g','u','i','d',0 };
286 static const WCHAR key_pathW
[] = {
287 'S','y','s','t','e','m','\\',
288 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
289 'C','o','n','t','r','o','l','\\',
290 'V','i','d','e','o','\\','{',0};
291 static const WCHAR displayW
[] = {'}','\\','0','0','0','0',0};
292 static const WCHAR driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
297 WCHAR path
[MAX_PATH
];
298 WCHAR key
[(sizeof(key_pathW
) + sizeof(displayW
)) / sizeof(WCHAR
) + 40];
299 UINT guid_atom
= HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW
));
301 if (!guid_atom
) return 0;
302 memcpy( key
, key_pathW
, sizeof(key_pathW
) );
303 if (!GlobalGetAtomNameW( guid_atom
, key
+ strlenW(key
), 40 )) return 0;
304 strcatW( key
, displayW
);
305 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, key
, &hkey
)) return 0;
307 if (!RegQueryValueExW( hkey
, driverW
, NULL
, NULL
, (BYTE
*)path
, &size
)) ret
= LoadLibraryW( path
);
309 TRACE( "%s %p\n", debugstr_w(path
), ret
);
313 /* ImmHkl loading and freeing */
314 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
315 static ImmHkl
*IMM_GetImmHkl(HKL hkl
)
318 WCHAR filename
[MAX_PATH
];
320 TRACE("Seeking ime for keyboard %p\n",hkl
);
322 LIST_FOR_EACH_ENTRY(ptr
, &ImmHklList
, ImmHkl
, entry
)
327 /* not found... create it */
329 ptr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ImmHkl
));
332 if (ImmGetIMEFileNameW(hkl
, filename
, MAX_PATH
)) ptr
->hIME
= LoadLibraryW(filename
);
333 if (!ptr
->hIME
) ptr
->hIME
= load_graphics_driver();
336 LOAD_FUNCPTR(ImeInquire
);
337 if (!ptr
->pImeInquire
|| !ptr
->pImeInquire(&ptr
->imeInfo
, ptr
->imeClassName
, NULL
))
339 FreeLibrary(ptr
->hIME
);
344 LOAD_FUNCPTR(ImeDestroy
);
345 LOAD_FUNCPTR(ImeSelect
);
346 if (!ptr
->pImeSelect
|| !ptr
->pImeDestroy
)
348 FreeLibrary(ptr
->hIME
);
353 LOAD_FUNCPTR(ImeConfigure
);
354 LOAD_FUNCPTR(ImeEscape
);
355 LOAD_FUNCPTR(ImeSetActiveContext
);
356 LOAD_FUNCPTR(ImeToAsciiEx
);
357 LOAD_FUNCPTR(NotifyIME
);
358 LOAD_FUNCPTR(ImeRegisterWord
);
359 LOAD_FUNCPTR(ImeUnregisterWord
);
360 LOAD_FUNCPTR(ImeEnumRegisterWord
);
361 LOAD_FUNCPTR(ImeSetCompositionString
);
362 LOAD_FUNCPTR(ImeConversionList
);
363 LOAD_FUNCPTR(ImeProcessKey
);
364 LOAD_FUNCPTR(ImeGetRegisterWordStyle
);
365 LOAD_FUNCPTR(ImeGetImeMenuItems
);
366 /* make sure our classname is WCHAR */
367 if (!is_kbd_ime_unicode(ptr
))
370 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ptr
->imeClassName
,
372 lstrcpyW(ptr
->imeClassName
, bufW
);
377 list_add_head(&ImmHklList
,&ptr
->entry
);
383 HWND WINAPI
__wine_get_ui_window(HKL hkl
)
385 ImmHkl
*immHkl
= IMM_GetImmHkl(hkl
);
386 return immHkl
->UIWnd
;
389 static void IMM_FreeAllImmHkl(void)
391 ImmHkl
*ptr
,*cursor2
;
393 LIST_FOR_EACH_ENTRY_SAFE(ptr
, cursor2
, &ImmHklList
, ImmHkl
, entry
)
395 list_remove(&ptr
->entry
);
399 FreeLibrary(ptr
->hIME
);
402 DestroyWindow(ptr
->UIWnd
);
403 HeapFree(GetProcessHeap(),0,ptr
);
407 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
409 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
412 case DLL_PROCESS_ATTACH
:
413 if (!User32InitializeImmEntryTable(IMM_INIT_MAGIC
))
418 case DLL_THREAD_ATTACH
:
420 case DLL_THREAD_DETACH
:
421 IMM_FreeThreadData();
423 case DLL_PROCESS_DETACH
:
424 if (lpReserved
) break;
425 IMM_FreeThreadData();
432 /* for posting messages as the IME */
433 static void ImmInternalPostIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
435 HWND target
= GetFocus();
437 PostMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
439 PostMessageW(target
, msg
, wParam
, lParam
);
442 /* for sending messages as the IME */
443 static void ImmInternalSendIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
445 HWND target
= GetFocus();
447 SendMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
449 SendMessageW(target
, msg
, wParam
, lParam
);
452 static LRESULT
ImmInternalSendIMENotify(InputContextData
*data
, WPARAM notify
, LPARAM lParam
)
456 target
= data
->IMC
.hWnd
;
457 if (!target
) target
= GetFocus();
460 return SendMessageW(target
, WM_IME_NOTIFY
, notify
, lParam
);
465 static HIMCC
ImmCreateBlankCompStr(void)
468 LPCOMPOSITIONSTRING ptr
;
469 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
470 ptr
= ImmLockIMCC(rc
);
471 memset(ptr
,0,sizeof(COMPOSITIONSTRING
));
472 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
477 static InputContextData
* get_imc_data(HIMC hIMC
)
479 InputContextData
*data
= hIMC
;
484 if(IsBadReadPtr(data
, sizeof(InputContextData
)) || data
->magic
!= WINE_IMC_VALID_MAGIC
)
486 SetLastError(ERROR_INVALID_HANDLE
);
492 static HIMC
get_default_context( HWND hwnd
)
495 IMMThreadData
* thread_data
= IMM_GetThreadData( hwnd
);
497 if (!thread_data
) return 0;
499 if (thread_data
->defaultContext
)
501 ret
= thread_data
->defaultContext
;
502 LeaveCriticalSection(&threaddata_cs
);
506 /* can't create a default context in another thread */
507 if (thread_data
->threadID
!= GetCurrentThreadId())
509 LeaveCriticalSection(&threaddata_cs
);
513 LeaveCriticalSection(&threaddata_cs
);
515 ret
= ImmCreateContext();
517 ((InputContextData
*)ret
)->threadDefault
= TRUE
;
519 /* thread_data is in the current thread so we can assume it's still valid */
520 EnterCriticalSection(&threaddata_cs
);
522 if (thread_data
->defaultContext
) /* someone beat us */
524 IMM_DestroyContext( ret
);
525 ret
= thread_data
->defaultContext
;
527 else thread_data
->defaultContext
= ret
;
529 LeaveCriticalSection(&threaddata_cs
);
533 static BOOL
IMM_IsCrossThreadAccess(HWND hWnd
, HIMC hIMC
)
535 InputContextData
*data
;
539 DWORD thread
= GetWindowThreadProcessId(hWnd
, NULL
);
540 if (thread
!= GetCurrentThreadId()) return TRUE
;
542 data
= get_imc_data(hIMC
);
543 if (data
&& data
->threadID
!= GetCurrentThreadId())
549 /***********************************************************************
550 * ImmAssociateContext (IMM32.@)
552 HIMC WINAPI
ImmAssociateContext(HWND hWnd
, HIMC hIMC
)
555 InputContextData
*data
= get_imc_data(hIMC
);
557 TRACE("(%p, %p):\n", hWnd
, hIMC
);
563 * If already associated just return
565 if (hIMC
&& data
->IMC
.hWnd
== hWnd
)
568 if (hIMC
&& IMM_IsCrossThreadAccess(hWnd
, hIMC
))
573 HIMC defaultContext
= get_default_context( hWnd
);
574 old
= RemovePropW(hWnd
,szwWineIMCProperty
);
577 old
= defaultContext
;
578 else if (old
== (HIMC
)-1)
581 if (hIMC
!= defaultContext
)
583 if (hIMC
== NULL
) /* Meaning disable imm for that window*/
584 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)-1);
586 SetPropW(hWnd
,szwWineIMCProperty
,hIMC
);
591 InputContextData
*old_data
= old
;
592 if (old_data
->IMC
.hWnd
== hWnd
)
593 old_data
->IMC
.hWnd
= NULL
;
600 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, FALSE
, ISC_SHOWUIALL
);
601 data
->IMC
.hWnd
= hWnd
;
602 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, TRUE
, ISC_SHOWUIALL
);
609 * Helper function for ImmAssociateContextEx
611 static BOOL CALLBACK
_ImmAssociateContextExEnumProc(HWND hwnd
, LPARAM lParam
)
613 HIMC hImc
= (HIMC
)lParam
;
614 ImmAssociateContext(hwnd
,hImc
);
618 /***********************************************************************
619 * ImmAssociateContextEx (IMM32.@)
621 BOOL WINAPI
ImmAssociateContextEx(HWND hWnd
, HIMC hIMC
, DWORD dwFlags
)
623 TRACE("(%p, %p, 0x%x):\n", hWnd
, hIMC
, dwFlags
);
631 ImmAssociateContext(hWnd
,hIMC
);
635 HIMC defaultContext
= get_default_context( hWnd
);
636 if (!defaultContext
) return FALSE
;
637 ImmAssociateContext(hWnd
,defaultContext
);
640 case IACE_IGNORENOCONTEXT
:
641 if (GetPropW(hWnd
,szwWineIMCProperty
))
642 ImmAssociateContext(hWnd
,hIMC
);
645 EnumChildWindows(hWnd
,_ImmAssociateContextExEnumProc
,(LPARAM
)hIMC
);
648 FIXME("Unknown dwFlags 0x%x\n",dwFlags
);
653 /***********************************************************************
654 * ImmConfigureIMEA (IMM32.@)
656 BOOL WINAPI
ImmConfigureIMEA(
657 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
659 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
661 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
663 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
666 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
668 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| !is_kbd_ime_unicode(immHkl
))
669 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
673 REGISTERWORDA
*rwa
= lpData
;
676 rww
.lpReading
= strdupAtoW(rwa
->lpReading
);
677 rww
.lpWord
= strdupAtoW(rwa
->lpWord
);
678 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rww
);
679 HeapFree(GetProcessHeap(),0,rww
.lpReading
);
680 HeapFree(GetProcessHeap(),0,rww
.lpWord
);
688 /***********************************************************************
689 * ImmConfigureIMEW (IMM32.@)
691 BOOL WINAPI
ImmConfigureIMEW(
692 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
694 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
696 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
698 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
701 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
703 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| is_kbd_ime_unicode(immHkl
))
704 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
707 REGISTERWORDW
*rww
= lpData
;
711 rwa
.lpReading
= strdupWtoA(rww
->lpReading
);
712 rwa
.lpWord
= strdupWtoA(rww
->lpWord
);
713 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rwa
);
714 HeapFree(GetProcessHeap(),0,rwa
.lpReading
);
715 HeapFree(GetProcessHeap(),0,rwa
.lpWord
);
723 /***********************************************************************
724 * ImmCreateContext (IMM32.@)
726 HIMC WINAPI
ImmCreateContext(void)
728 InputContextData
*new_context
;
733 new_context
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputContextData
));
736 new_context
->immKbd
= IMM_GetImmHkl(GetKeyboardLayout(0));
738 if (!new_context
->immKbd
->hIME
)
740 TRACE("IME dll could not be loaded\n");
741 HeapFree(GetProcessHeap(),0,new_context
);
745 /* the HIMCCs are never NULL */
746 new_context
->IMC
.hCompStr
= ImmCreateBlankCompStr();
747 new_context
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
748 new_context
->IMC
.hCandInfo
= ImmCreateIMCC(sizeof(CANDIDATEINFO
));
749 ci
= ImmLockIMCC(new_context
->IMC
.hCandInfo
);
750 memset(ci
,0,sizeof(CANDIDATEINFO
));
751 ci
->dwSize
= sizeof(CANDIDATEINFO
);
752 ImmUnlockIMCC(new_context
->IMC
.hCandInfo
);
753 new_context
->IMC
.hGuideLine
= ImmCreateIMCC(sizeof(GUIDELINE
));
754 gl
= ImmLockIMCC(new_context
->IMC
.hGuideLine
);
755 memset(gl
,0,sizeof(GUIDELINE
));
756 gl
->dwSize
= sizeof(GUIDELINE
);
757 ImmUnlockIMCC(new_context
->IMC
.hGuideLine
);
759 for (i
= 0; i
< sizeof(new_context
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
); i
++)
760 new_context
->IMC
.cfCandForm
[i
].dwIndex
= ~0u;
762 /* Initialize the IME Private */
763 new_context
->IMC
.hPrivate
= ImmCreateIMCC(new_context
->immKbd
->imeInfo
.dwPrivateDataSize
);
765 new_context
->IMC
.fdwConversion
= new_context
->immKbd
->imeInfo
.fdwConversionCaps
;
766 new_context
->IMC
.fdwSentence
= new_context
->immKbd
->imeInfo
.fdwSentenceCaps
;
768 if (!new_context
->immKbd
->pImeSelect(new_context
, TRUE
))
770 TRACE("Selection of IME failed\n");
771 IMM_DestroyContext(new_context
);
774 new_context
->threadID
= GetCurrentThreadId();
775 SendMessageW(GetFocus(), WM_IME_SELECT
, TRUE
, (LPARAM
)new_context
->immKbd
);
777 new_context
->immKbd
->uSelected
++;
778 TRACE("Created context %p\n",new_context
);
780 new_context
->magic
= WINE_IMC_VALID_MAGIC
;
784 static BOOL
IMM_DestroyContext(HIMC hIMC
)
786 InputContextData
*data
= get_imc_data(hIMC
);
788 TRACE("Destroying %p\n",hIMC
);
793 data
->immKbd
->uSelected
--;
794 data
->immKbd
->pImeSelect(hIMC
, FALSE
);
795 SendMessageW(data
->IMC
.hWnd
, WM_IME_SELECT
, FALSE
, (LPARAM
)data
->immKbd
);
797 ImmDestroyIMCC(data
->IMC
.hCompStr
);
798 ImmDestroyIMCC(data
->IMC
.hCandInfo
);
799 ImmDestroyIMCC(data
->IMC
.hGuideLine
);
800 ImmDestroyIMCC(data
->IMC
.hPrivate
);
801 ImmDestroyIMCC(data
->IMC
.hMsgBuf
);
804 HeapFree(GetProcessHeap(),0,data
);
809 /***********************************************************************
810 * ImmDestroyContext (IMM32.@)
812 BOOL WINAPI
ImmDestroyContext(HIMC hIMC
)
814 if (!IMM_IsDefaultContext(hIMC
) && !IMM_IsCrossThreadAccess(NULL
, hIMC
))
815 return IMM_DestroyContext(hIMC
);
820 /***********************************************************************
821 * ImmDisableIME (IMM32.@)
823 BOOL WINAPI
ImmDisableIME(DWORD idThread
)
825 FIXME("(%d): stub\n", idThread
);
829 /***********************************************************************
830 * ImmEnumRegisterWordA (IMM32.@)
832 UINT WINAPI
ImmEnumRegisterWordA(
833 HKL hKL
, REGISTERWORDENUMPROCA lpfnEnumProc
,
834 LPCSTR lpszReading
, DWORD dwStyle
,
835 LPCSTR lpszRegister
, LPVOID lpData
)
837 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
838 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
839 debugstr_a(lpszReading
), dwStyle
, debugstr_a(lpszRegister
), lpData
);
840 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
842 if (!is_kbd_ime_unicode(immHkl
))
843 return immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
844 (LPCWSTR
)lpszReading
, dwStyle
, (LPCWSTR
)lpszRegister
, lpData
);
847 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
848 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
851 rc
= immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
852 lpszwReading
, dwStyle
, lpszwRegister
,
855 HeapFree(GetProcessHeap(),0,lpszwReading
);
856 HeapFree(GetProcessHeap(),0,lpszwRegister
);
864 /***********************************************************************
865 * ImmEnumRegisterWordW (IMM32.@)
867 UINT WINAPI
ImmEnumRegisterWordW(
868 HKL hKL
, REGISTERWORDENUMPROCW lpfnEnumProc
,
869 LPCWSTR lpszReading
, DWORD dwStyle
,
870 LPCWSTR lpszRegister
, LPVOID lpData
)
872 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
873 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
874 debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
), lpData
);
875 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
877 if (is_kbd_ime_unicode(immHkl
))
878 return immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, lpszReading
, dwStyle
,
879 lpszRegister
, lpData
);
882 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
883 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
886 rc
= immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, (LPCWSTR
)lpszaReading
,
887 dwStyle
, (LPCWSTR
)lpszaRegister
, lpData
);
889 HeapFree(GetProcessHeap(),0,lpszaReading
);
890 HeapFree(GetProcessHeap(),0,lpszaRegister
);
898 static inline BOOL
EscapeRequiresWA(UINT uEscape
)
900 if (uEscape
== IME_ESC_GET_EUDC_DICTIONARY
||
901 uEscape
== IME_ESC_SET_EUDC_DICTIONARY
||
902 uEscape
== IME_ESC_IME_NAME
||
903 uEscape
== IME_ESC_GETHELPFILENAME
)
908 /***********************************************************************
909 * ImmEscapeA (IMM32.@)
911 LRESULT WINAPI
ImmEscapeA(
913 UINT uEscape
, LPVOID lpData
)
915 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
916 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
918 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
920 if (!EscapeRequiresWA(uEscape
) || !is_kbd_ime_unicode(immHkl
))
921 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
924 WCHAR buffer
[81]; /* largest required buffer should be 80 */
926 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
928 MultiByteToWideChar(CP_ACP
,0,lpData
,-1,buffer
,81);
929 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
933 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
934 WideCharToMultiByte(CP_ACP
,0,buffer
,-1,lpData
,80, NULL
, NULL
);
943 /***********************************************************************
944 * ImmEscapeW (IMM32.@)
946 LRESULT WINAPI
ImmEscapeW(
948 UINT uEscape
, LPVOID lpData
)
950 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
951 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
953 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
955 if (!EscapeRequiresWA(uEscape
) || is_kbd_ime_unicode(immHkl
))
956 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
959 CHAR buffer
[81]; /* largest required buffer should be 80 */
961 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
963 WideCharToMultiByte(CP_ACP
,0,lpData
,-1,buffer
,81, NULL
, NULL
);
964 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
968 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
969 MultiByteToWideChar(CP_ACP
,0,buffer
,-1,lpData
,80);
978 /***********************************************************************
979 * ImmGetCandidateListA (IMM32.@)
981 DWORD WINAPI
ImmGetCandidateListA(
982 HIMC hIMC
, DWORD dwIndex
,
983 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
985 InputContextData
*data
= get_imc_data(hIMC
);
986 LPCANDIDATEINFO candinfo
;
987 LPCANDIDATELIST candlist
;
990 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
992 if (!data
|| !data
->IMC
.hCandInfo
)
995 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
996 if ( dwIndex
>= candinfo
->dwCount
||
997 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1000 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1001 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1004 if ( !is_himc_ime_unicode(data
) )
1006 ret
= candlist
->dwSize
;
1007 if ( lpCandList
&& dwBufLen
>= ret
)
1008 memcpy(lpCandList
, candlist
, ret
);
1011 ret
= convert_candidatelist_WtoA( candlist
, lpCandList
, dwBufLen
);
1014 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1018 /***********************************************************************
1019 * ImmGetCandidateListCountA (IMM32.@)
1021 DWORD WINAPI
ImmGetCandidateListCountA(
1022 HIMC hIMC
, LPDWORD lpdwListCount
)
1024 InputContextData
*data
= get_imc_data(hIMC
);
1025 LPCANDIDATEINFO candinfo
;
1028 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1030 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1033 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1035 *lpdwListCount
= count
= candinfo
->dwCount
;
1037 if ( !is_himc_ime_unicode(data
) )
1038 ret
= candinfo
->dwSize
;
1041 ret
= sizeof(CANDIDATEINFO
);
1043 ret
+= ImmGetCandidateListA(hIMC
, count
, NULL
, 0);
1046 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1050 /***********************************************************************
1051 * ImmGetCandidateListCountW (IMM32.@)
1053 DWORD WINAPI
ImmGetCandidateListCountW(
1054 HIMC hIMC
, LPDWORD lpdwListCount
)
1056 InputContextData
*data
= get_imc_data(hIMC
);
1057 LPCANDIDATEINFO candinfo
;
1060 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1062 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1065 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1067 *lpdwListCount
= count
= candinfo
->dwCount
;
1069 if ( is_himc_ime_unicode(data
) )
1070 ret
= candinfo
->dwSize
;
1073 ret
= sizeof(CANDIDATEINFO
);
1075 ret
+= ImmGetCandidateListW(hIMC
, count
, NULL
, 0);
1078 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1082 /***********************************************************************
1083 * ImmGetCandidateListW (IMM32.@)
1085 DWORD WINAPI
ImmGetCandidateListW(
1086 HIMC hIMC
, DWORD dwIndex
,
1087 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1089 InputContextData
*data
= get_imc_data(hIMC
);
1090 LPCANDIDATEINFO candinfo
;
1091 LPCANDIDATELIST candlist
;
1094 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1096 if (!data
|| !data
->IMC
.hCandInfo
)
1099 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1100 if ( dwIndex
>= candinfo
->dwCount
||
1101 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1104 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1105 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1108 if ( is_himc_ime_unicode(data
) )
1110 ret
= candlist
->dwSize
;
1111 if ( lpCandList
&& dwBufLen
>= ret
)
1112 memcpy(lpCandList
, candlist
, ret
);
1115 ret
= convert_candidatelist_AtoW( candlist
, lpCandList
, dwBufLen
);
1118 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1122 /***********************************************************************
1123 * ImmGetCandidateWindow (IMM32.@)
1125 BOOL WINAPI
ImmGetCandidateWindow(
1126 HIMC hIMC
, DWORD dwIndex
, LPCANDIDATEFORM lpCandidate
)
1128 InputContextData
*data
= get_imc_data(hIMC
);
1130 TRACE("%p, %d, %p\n", hIMC
, dwIndex
, lpCandidate
);
1132 if (!data
|| !lpCandidate
)
1135 if ( dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
1138 if (data
->IMC
.cfCandForm
[dwIndex
].dwIndex
!= dwIndex
)
1141 *lpCandidate
= data
->IMC
.cfCandForm
[dwIndex
];
1146 /***********************************************************************
1147 * ImmGetCompositionFontA (IMM32.@)
1149 BOOL WINAPI
ImmGetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
1154 TRACE("(%p, %p):\n", hIMC
, lplf
);
1156 rc
= ImmGetCompositionFontW(hIMC
,&lfW
);
1160 memcpy(lplf
,&lfW
,sizeof(LOGFONTA
));
1161 WideCharToMultiByte(CP_ACP
, 0, lfW
.lfFaceName
, -1, lplf
->lfFaceName
,
1162 LF_FACESIZE
, NULL
, NULL
);
1166 /***********************************************************************
1167 * ImmGetCompositionFontW (IMM32.@)
1169 BOOL WINAPI
ImmGetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
1171 InputContextData
*data
= get_imc_data(hIMC
);
1173 TRACE("(%p, %p):\n", hIMC
, lplf
);
1178 *lplf
= data
->IMC
.lfFont
.W
;
1184 /* Helpers for the GetCompositionString functions */
1186 static INT
CopyCompStringIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE target
, INT tlen
,
1191 if (is_himc_ime_unicode(data
) && !unicode
)
1192 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)source
, slen
, (LPSTR
)target
, tlen
, NULL
, NULL
);
1193 else if (!is_himc_ime_unicode(data
) && unicode
)
1194 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)source
, slen
, (LPWSTR
)target
, tlen
) * sizeof(WCHAR
);
1197 int dlen
= (unicode
)?sizeof(WCHAR
):sizeof(CHAR
);
1198 memcpy( target
, source
, min(slen
,tlen
)*dlen
);
1205 static INT
CopyCompAttrIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1206 LPBYTE target
, INT tlen
, BOOL unicode
)
1210 if (is_himc_ime_unicode(data
) && !unicode
)
1212 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, sslen
, NULL
, 0, NULL
, NULL
);
1215 const BYTE
*src
= source
;
1216 LPBYTE dst
= target
;
1217 int i
, j
= 0, k
= 0;
1221 for (i
= 0; i
< sslen
; ++i
)
1225 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)ssource
+ i
, 1,
1226 NULL
, 0, NULL
, NULL
);
1227 for (; len
> 0; --len
)
1240 else if (!is_himc_ime_unicode(data
) && unicode
)
1242 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, sslen
, NULL
, 0);
1245 const BYTE
*src
= source
;
1246 LPBYTE dst
= target
;
1251 for (i
= 0; i
< sslen
; ++i
)
1253 if (IsDBCSLeadByte(((LPSTR
)ssource
)[i
]))
1266 memcpy( target
, source
, min(slen
,tlen
));
1273 static INT
CopyCompClauseIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
,
1274 LPBYTE target
, INT tlen
, BOOL unicode
)
1278 if (is_himc_ime_unicode(data
) && !unicode
)
1286 tlen
/= sizeof (DWORD
);
1287 for (i
= 0; i
< tlen
; ++i
)
1289 ((DWORD
*)target
)[i
] = WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
,
1290 ((DWORD
*)source
)[i
],
1294 rc
= sizeof (DWORD
) * i
;
1299 else if (!is_himc_ime_unicode(data
) && unicode
)
1307 tlen
/= sizeof (DWORD
);
1308 for (i
= 0; i
< tlen
; ++i
)
1310 ((DWORD
*)target
)[i
] = MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
,
1311 ((DWORD
*)source
)[i
],
1314 rc
= sizeof (DWORD
) * i
;
1321 memcpy( target
, source
, min(slen
,tlen
));
1328 static INT
CopyCompOffsetIMEtoClient(InputContextData
*data
, DWORD offset
, LPBYTE ssource
, BOOL unicode
)
1332 if (is_himc_ime_unicode(data
) && !unicode
)
1334 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, offset
, NULL
, 0, NULL
, NULL
);
1336 else if (!is_himc_ime_unicode(data
) && unicode
)
1338 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, offset
, NULL
, 0);
1346 static LONG
ImmGetCompositionStringT( HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
,
1347 DWORD dwBufLen
, BOOL unicode
)
1350 InputContextData
*data
= get_imc_data(hIMC
);
1351 LPCOMPOSITIONSTRING compstr
;
1354 TRACE("(%p, 0x%x, %p, %d)\n", hIMC
, dwIndex
, lpBuf
, dwBufLen
);
1359 if (!data
->IMC
.hCompStr
)
1362 compdata
= ImmLockIMCC(data
->IMC
.hCompStr
);
1363 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1368 TRACE("GCS_RESULTSTR\n");
1369 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
, lpBuf
, dwBufLen
, unicode
);
1372 TRACE("GCS_COMPSTR\n");
1373 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
, lpBuf
, dwBufLen
, unicode
);
1376 TRACE("GCS_COMPATTR\n");
1377 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompAttrOffset
, compstr
->dwCompAttrLen
,
1378 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1379 lpBuf
, dwBufLen
, unicode
);
1381 case GCS_COMPCLAUSE
:
1382 TRACE("GCS_COMPCLAUSE\n");
1383 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompClauseOffset
,compstr
->dwCompClauseLen
,
1384 compdata
+ compstr
->dwCompStrOffset
,
1385 lpBuf
, dwBufLen
, unicode
);
1387 case GCS_RESULTCLAUSE
:
1388 TRACE("GCS_RESULTCLAUSE\n");
1389 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultClauseOffset
,compstr
->dwResultClauseLen
,
1390 compdata
+ compstr
->dwResultStrOffset
,
1391 lpBuf
, dwBufLen
, unicode
);
1393 case GCS_RESULTREADSTR
:
1394 TRACE("GCS_RESULTREADSTR\n");
1395 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultReadStrOffset
, compstr
->dwResultReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1397 case GCS_RESULTREADCLAUSE
:
1398 TRACE("GCS_RESULTREADCLAUSE\n");
1399 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultReadClauseOffset
,compstr
->dwResultReadClauseLen
,
1400 compdata
+ compstr
->dwResultStrOffset
,
1401 lpBuf
, dwBufLen
, unicode
);
1403 case GCS_COMPREADSTR
:
1404 TRACE("GCS_COMPREADSTR\n");
1405 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1407 case GCS_COMPREADATTR
:
1408 TRACE("GCS_COMPREADATTR\n");
1409 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompReadAttrOffset
, compstr
->dwCompReadAttrLen
,
1410 compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
,
1411 lpBuf
, dwBufLen
, unicode
);
1413 case GCS_COMPREADCLAUSE
:
1414 TRACE("GCS_COMPREADCLAUSE\n");
1415 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompReadClauseOffset
,compstr
->dwCompReadClauseLen
,
1416 compdata
+ compstr
->dwCompStrOffset
,
1417 lpBuf
, dwBufLen
, unicode
);
1420 TRACE("GCS_CURSORPOS\n");
1421 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwCursorPos
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1423 case GCS_DELTASTART
:
1424 TRACE("GCS_DELTASTART\n");
1425 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwDeltaStart
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1428 FIXME("Unhandled index 0x%x\n",dwIndex
);
1432 ImmUnlockIMCC(data
->IMC
.hCompStr
);
1437 /***********************************************************************
1438 * ImmGetCompositionStringA (IMM32.@)
1440 LONG WINAPI
ImmGetCompositionStringA(
1441 HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
, DWORD dwBufLen
)
1443 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, FALSE
);
1447 /***********************************************************************
1448 * ImmGetCompositionStringW (IMM32.@)
1450 LONG WINAPI
ImmGetCompositionStringW(
1451 HIMC hIMC
, DWORD dwIndex
,
1452 LPVOID lpBuf
, DWORD dwBufLen
)
1454 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, TRUE
);
1457 /***********************************************************************
1458 * ImmGetCompositionWindow (IMM32.@)
1460 BOOL WINAPI
ImmGetCompositionWindow(HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
1462 InputContextData
*data
= get_imc_data(hIMC
);
1464 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
1469 *lpCompForm
= data
->IMC
.cfCompForm
;
1473 /***********************************************************************
1474 * ImmGetContext (IMM32.@)
1477 HIMC WINAPI
ImmGetContext(HWND hWnd
)
1481 TRACE("%p\n", hWnd
);
1483 if (!IsWindow(hWnd
))
1485 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1489 rc
= GetPropW(hWnd
,szwWineIMCProperty
);
1492 else if (rc
== NULL
)
1493 rc
= get_default_context( hWnd
);
1497 InputContextData
*data
= rc
;
1498 data
->IMC
.hWnd
= hWnd
;
1501 TRACE("returning %p\n", rc
);
1506 /***********************************************************************
1507 * ImmGetConversionListA (IMM32.@)
1509 DWORD WINAPI
ImmGetConversionListA(
1511 LPCSTR pSrc
, LPCANDIDATELIST lpDst
,
1512 DWORD dwBufLen
, UINT uFlag
)
1514 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1515 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_a(pSrc
), lpDst
,
1517 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1519 if (!is_kbd_ime_unicode(immHkl
))
1520 return immHkl
->pImeConversionList(hIMC
,(LPCWSTR
)pSrc
,lpDst
,dwBufLen
,uFlag
);
1523 LPCANDIDATELIST lpwDst
;
1525 LPWSTR pwSrc
= strdupAtoW(pSrc
);
1527 len
= immHkl
->pImeConversionList(hIMC
, pwSrc
, NULL
, 0, uFlag
);
1528 lpwDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1531 immHkl
->pImeConversionList(hIMC
, pwSrc
, lpwDst
, len
, uFlag
);
1532 ret
= convert_candidatelist_WtoA( lpwDst
, lpDst
, dwBufLen
);
1533 HeapFree(GetProcessHeap(), 0, lpwDst
);
1535 HeapFree(GetProcessHeap(), 0, pwSrc
);
1544 /***********************************************************************
1545 * ImmGetConversionListW (IMM32.@)
1547 DWORD WINAPI
ImmGetConversionListW(
1549 LPCWSTR pSrc
, LPCANDIDATELIST lpDst
,
1550 DWORD dwBufLen
, UINT uFlag
)
1552 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1553 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_w(pSrc
), lpDst
,
1555 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1557 if (is_kbd_ime_unicode(immHkl
))
1558 return immHkl
->pImeConversionList(hIMC
,pSrc
,lpDst
,dwBufLen
,uFlag
);
1561 LPCANDIDATELIST lpaDst
;
1563 LPSTR paSrc
= strdupWtoA(pSrc
);
1565 len
= immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, NULL
, 0, uFlag
);
1566 lpaDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1569 immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, lpaDst
, len
, uFlag
);
1570 ret
= convert_candidatelist_AtoW( lpaDst
, lpDst
, dwBufLen
);
1571 HeapFree(GetProcessHeap(), 0, lpaDst
);
1573 HeapFree(GetProcessHeap(), 0, paSrc
);
1582 /***********************************************************************
1583 * ImmGetConversionStatus (IMM32.@)
1585 BOOL WINAPI
ImmGetConversionStatus(
1586 HIMC hIMC
, LPDWORD lpfdwConversion
, LPDWORD lpfdwSentence
)
1588 InputContextData
*data
= get_imc_data(hIMC
);
1590 TRACE("%p %p %p\n", hIMC
, lpfdwConversion
, lpfdwSentence
);
1595 if (lpfdwConversion
)
1596 *lpfdwConversion
= data
->IMC
.fdwConversion
;
1598 *lpfdwSentence
= data
->IMC
.fdwSentence
;
1603 /***********************************************************************
1604 * ImmGetDefaultIMEWnd (IMM32.@)
1606 HWND WINAPI
ImmGetDefaultIMEWnd(HWND hWnd
)
1608 HWND ret
, new = NULL
;
1609 IMMThreadData
* thread_data
= IMM_GetThreadData(hWnd
);
1612 if (thread_data
->hwndDefault
== NULL
&& thread_data
->threadID
== GetCurrentThreadId())
1614 /* Do not create the window inside of a critical section */
1615 LeaveCriticalSection(&threaddata_cs
);
1616 new = CreateWindowExW( WS_EX_TOOLWINDOW
,
1617 szwIME
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0, 0, 0, 0);
1618 /* thread_data is in the current thread so we can assume it's still valid */
1619 EnterCriticalSection(&threaddata_cs
);
1620 /* See if anyone beat us */
1621 if (thread_data
->hwndDefault
== NULL
)
1623 thread_data
->hwndDefault
= new;
1627 ret
= thread_data
->hwndDefault
;
1628 LeaveCriticalSection(&threaddata_cs
);
1629 TRACE("Default is %p\n",ret
);
1630 /* Clean up an unused new window outside of the critical section */
1635 TRACE("Default is %p\n",ret
);
1639 /***********************************************************************
1640 * ImmGetDescriptionA (IMM32.@)
1642 UINT WINAPI
ImmGetDescriptionA(
1643 HKL hKL
, LPSTR lpszDescription
, UINT uBufLen
)
1648 TRACE("%p %p %d\n", hKL
, lpszDescription
, uBufLen
);
1650 /* find out how many characters in the unicode buffer */
1651 len
= ImmGetDescriptionW( hKL
, NULL
, 0 );
1655 /* allocate a buffer of that size */
1656 buf
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof (WCHAR
) );
1660 /* fetch the unicode buffer */
1661 len
= ImmGetDescriptionW( hKL
, buf
, len
+ 1 );
1663 /* convert it back to ASCII */
1664 len
= WideCharToMultiByte( CP_ACP
, 0, buf
, len
+ 1,
1665 lpszDescription
, uBufLen
, NULL
, NULL
);
1667 HeapFree( GetProcessHeap(), 0, buf
);
1675 /***********************************************************************
1676 * ImmGetDescriptionW (IMM32.@)
1678 UINT WINAPI
ImmGetDescriptionW(HKL hKL
, LPWSTR lpszDescription
, UINT uBufLen
)
1680 static const WCHAR name
[] = { 'W','i','n','e',' ','X','I','M',0 };
1682 FIXME("(%p, %p, %d): semi stub\n", hKL
, lpszDescription
, uBufLen
);
1685 if (!uBufLen
) return lstrlenW( name
);
1686 lstrcpynW( lpszDescription
, name
, uBufLen
);
1687 return lstrlenW( lpszDescription
);
1690 /***********************************************************************
1691 * ImmGetGuideLineA (IMM32.@)
1693 DWORD WINAPI
ImmGetGuideLineA(
1694 HIMC hIMC
, DWORD dwIndex
, LPSTR lpBuf
, DWORD dwBufLen
)
1696 FIXME("(%p, %d, %s, %d): stub\n",
1697 hIMC
, dwIndex
, debugstr_a(lpBuf
), dwBufLen
1699 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1703 /***********************************************************************
1704 * ImmGetGuideLineW (IMM32.@)
1706 DWORD WINAPI
ImmGetGuideLineW(HIMC hIMC
, DWORD dwIndex
, LPWSTR lpBuf
, DWORD dwBufLen
)
1708 FIXME("(%p, %d, %s, %d): stub\n",
1709 hIMC
, dwIndex
, debugstr_w(lpBuf
), dwBufLen
1711 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1715 /***********************************************************************
1716 * ImmGetIMEFileNameA (IMM32.@)
1718 UINT WINAPI
ImmGetIMEFileNameA( HKL hKL
, LPSTR lpszFileName
, UINT uBufLen
)
1721 UINT wBufLen
= uBufLen
;
1724 if (uBufLen
&& lpszFileName
)
1725 bufW
= HeapAlloc(GetProcessHeap(),0,uBufLen
* sizeof(WCHAR
));
1726 else /* We need this to get the number of byte required */
1728 bufW
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
* sizeof(WCHAR
));
1732 rc
= ImmGetIMEFileNameW(hKL
,bufW
,wBufLen
);
1736 if (uBufLen
&& lpszFileName
)
1737 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, lpszFileName
,
1738 uBufLen
, NULL
, NULL
);
1739 else /* get the length */
1740 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
,
1744 HeapFree(GetProcessHeap(),0,bufW
);
1748 /***********************************************************************
1749 * ImmGetIMEFileNameW (IMM32.@)
1751 UINT WINAPI
ImmGetIMEFileNameW(HKL hKL
, LPWSTR lpszFileName
, UINT uBufLen
)
1756 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1758 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hKL
);
1759 rc
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, regKey
, &hkey
);
1760 if (rc
!= ERROR_SUCCESS
)
1767 rc
= RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, NULL
, &length
);
1769 if (rc
!= ERROR_SUCCESS
)
1775 if (length
> uBufLen
* sizeof(WCHAR
) || !lpszFileName
)
1780 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1784 return length
/ sizeof(WCHAR
);
1787 RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, lpszFileName
, &length
);
1791 return length
/ sizeof(WCHAR
);
1794 /***********************************************************************
1795 * ImmGetOpenStatus (IMM32.@)
1797 BOOL WINAPI
ImmGetOpenStatus(HIMC hIMC
)
1799 InputContextData
*data
= get_imc_data(hIMC
);
1805 TRACE("(%p): semi-stub\n", hIMC
);
1808 FIXME("(%p): semi-stub\n", hIMC
);
1810 return data
->IMC
.fOpen
;
1813 /***********************************************************************
1814 * ImmGetProperty (IMM32.@)
1816 DWORD WINAPI
ImmGetProperty(HKL hKL
, DWORD fdwIndex
)
1821 TRACE("(%p, %d)\n", hKL
, fdwIndex
);
1822 kbd
= IMM_GetImmHkl(hKL
);
1824 if (kbd
&& kbd
->hIME
)
1828 case IGP_PROPERTY
: rc
= kbd
->imeInfo
.fdwProperty
; break;
1829 case IGP_CONVERSION
: rc
= kbd
->imeInfo
.fdwConversionCaps
; break;
1830 case IGP_SENTENCE
: rc
= kbd
->imeInfo
.fdwSentenceCaps
; break;
1831 case IGP_SETCOMPSTR
: rc
= kbd
->imeInfo
.fdwSCSCaps
; break;
1832 case IGP_SELECT
: rc
= kbd
->imeInfo
.fdwSelectCaps
; break;
1833 case IGP_GETIMEVERSION
: rc
= IMEVER_0400
; break;
1834 case IGP_UI
: rc
= 0; break;
1841 /***********************************************************************
1842 * ImmGetRegisterWordStyleA (IMM32.@)
1844 UINT WINAPI
ImmGetRegisterWordStyleA(
1845 HKL hKL
, UINT nItem
, LPSTYLEBUFA lpStyleBuf
)
1847 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1848 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1849 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1851 if (!is_kbd_ime_unicode(immHkl
))
1852 return immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)lpStyleBuf
);
1858 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,&sbw
);
1859 WideCharToMultiByte(CP_ACP
, 0, sbw
.szDescription
, -1,
1860 lpStyleBuf
->szDescription
, 32, NULL
, NULL
);
1861 lpStyleBuf
->dwStyle
= sbw
.dwStyle
;
1869 /***********************************************************************
1870 * ImmGetRegisterWordStyleW (IMM32.@)
1872 UINT WINAPI
ImmGetRegisterWordStyleW(
1873 HKL hKL
, UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
1875 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1876 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1877 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1879 if (is_kbd_ime_unicode(immHkl
))
1880 return immHkl
->pImeGetRegisterWordStyle(nItem
,lpStyleBuf
);
1886 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)&sba
);
1887 MultiByteToWideChar(CP_ACP
, 0, sba
.szDescription
, -1,
1888 lpStyleBuf
->szDescription
, 32);
1889 lpStyleBuf
->dwStyle
= sba
.dwStyle
;
1897 /***********************************************************************
1898 * ImmGetStatusWindowPos (IMM32.@)
1900 BOOL WINAPI
ImmGetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
1902 InputContextData
*data
= get_imc_data(hIMC
);
1904 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
1906 if (!data
|| !lpptPos
)
1909 *lpptPos
= data
->IMC
.ptStatusWndPos
;
1914 /***********************************************************************
1915 * ImmGetVirtualKey (IMM32.@)
1917 UINT WINAPI
ImmGetVirtualKey(HWND hWnd
)
1919 OSVERSIONINFOA version
;
1920 InputContextData
*data
= ImmGetContext( hWnd
);
1921 TRACE("%p\n", hWnd
);
1924 return data
->lastVK
;
1926 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
1927 GetVersionExA( &version
);
1928 switch(version
.dwPlatformId
)
1930 case VER_PLATFORM_WIN32_WINDOWS
:
1931 return VK_PROCESSKEY
;
1932 case VER_PLATFORM_WIN32_NT
:
1935 FIXME("%d not supported\n",version
.dwPlatformId
);
1936 return VK_PROCESSKEY
;
1940 /***********************************************************************
1941 * ImmInstallIMEA (IMM32.@)
1943 HKL WINAPI
ImmInstallIMEA(
1944 LPCSTR lpszIMEFileName
, LPCSTR lpszLayoutText
)
1946 LPWSTR lpszwIMEFileName
;
1947 LPWSTR lpszwLayoutText
;
1950 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName
),
1951 debugstr_a(lpszLayoutText
));
1953 lpszwIMEFileName
= strdupAtoW(lpszIMEFileName
);
1954 lpszwLayoutText
= strdupAtoW(lpszLayoutText
);
1956 hkl
= ImmInstallIMEW(lpszwIMEFileName
, lpszwLayoutText
);
1958 HeapFree(GetProcessHeap(),0,lpszwIMEFileName
);
1959 HeapFree(GetProcessHeap(),0,lpszwLayoutText
);
1963 /***********************************************************************
1964 * ImmInstallIMEW (IMM32.@)
1966 HKL WINAPI
ImmInstallIMEW(
1967 LPCWSTR lpszIMEFileName
, LPCWSTR lpszLayoutText
)
1969 INT lcid
= GetUserDefaultLCID();
1974 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1976 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName
),
1977 debugstr_w(lpszLayoutText
));
1979 /* Start with 2. e001 will be blank and so default to the wine internal IME */
1982 while (count
< 0xfff)
1984 DWORD disposition
= 0;
1986 hkl
= (HKL
)MAKELPARAM( lcid
, 0xe000 | count
);
1987 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hkl
);
1989 rc
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, regKey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hkey
, &disposition
);
1990 if (rc
== ERROR_SUCCESS
&& disposition
== REG_CREATED_NEW_KEY
)
1992 else if (rc
== ERROR_SUCCESS
)
2000 WARN("Unable to find slot to install IME\n");
2004 if (rc
== ERROR_SUCCESS
)
2006 rc
= RegSetValueExW(hkey
, szImeFileW
, 0, REG_SZ
, (const BYTE
*)lpszIMEFileName
,
2007 (lstrlenW(lpszIMEFileName
) + 1) * sizeof(WCHAR
));
2008 if (rc
== ERROR_SUCCESS
)
2009 rc
= RegSetValueExW(hkey
, szLayoutTextW
, 0, REG_SZ
, (const BYTE
*)lpszLayoutText
,
2010 (lstrlenW(lpszLayoutText
) + 1) * sizeof(WCHAR
));
2016 WARN("Unable to set IME registry values\n");
2021 /***********************************************************************
2022 * ImmIsIME (IMM32.@)
2024 BOOL WINAPI
ImmIsIME(HKL hKL
)
2027 TRACE("(%p):\n", hKL
);
2028 ptr
= IMM_GetImmHkl(hKL
);
2029 return (ptr
&& ptr
->hIME
);
2032 /***********************************************************************
2033 * ImmIsUIMessageA (IMM32.@)
2035 BOOL WINAPI
ImmIsUIMessageA(
2036 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2038 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2039 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2040 (msg
== WM_IME_SETCONTEXT
) ||
2041 (msg
== WM_IME_NOTIFY
) ||
2042 (msg
== WM_IME_COMPOSITIONFULL
) ||
2043 (msg
== WM_IME_SELECT
) ||
2044 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2047 SendMessageA(hWndIME
, msg
, wParam
, lParam
);
2054 /***********************************************************************
2055 * ImmIsUIMessageW (IMM32.@)
2057 BOOL WINAPI
ImmIsUIMessageW(
2058 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2060 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2061 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2062 (msg
== WM_IME_SETCONTEXT
) ||
2063 (msg
== WM_IME_NOTIFY
) ||
2064 (msg
== WM_IME_COMPOSITIONFULL
) ||
2065 (msg
== WM_IME_SELECT
) ||
2066 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2069 SendMessageW(hWndIME
, msg
, wParam
, lParam
);
2076 /***********************************************************************
2077 * ImmNotifyIME (IMM32.@)
2079 BOOL WINAPI
ImmNotifyIME(
2080 HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
2082 InputContextData
*data
= get_imc_data(hIMC
);
2084 TRACE("(%p, %d, %d, %d)\n",
2085 hIMC
, dwAction
, dwIndex
, dwValue
);
2089 SetLastError(ERROR_SUCCESS
);
2093 if (!data
|| ! data
->immKbd
->pNotifyIME
)
2098 return data
->immKbd
->pNotifyIME(hIMC
,dwAction
,dwIndex
,dwValue
);
2101 /***********************************************************************
2102 * ImmRegisterWordA (IMM32.@)
2104 BOOL WINAPI
ImmRegisterWordA(
2105 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszRegister
)
2107 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2108 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2109 debugstr_a(lpszRegister
));
2110 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2112 if (!is_kbd_ime_unicode(immHkl
))
2113 return immHkl
->pImeRegisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2114 (LPCWSTR
)lpszRegister
);
2117 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2118 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
2121 rc
= immHkl
->pImeRegisterWord(lpszwReading
,dwStyle
,lpszwRegister
);
2122 HeapFree(GetProcessHeap(),0,lpszwReading
);
2123 HeapFree(GetProcessHeap(),0,lpszwRegister
);
2131 /***********************************************************************
2132 * ImmRegisterWordW (IMM32.@)
2134 BOOL WINAPI
ImmRegisterWordW(
2135 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
2137 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2138 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2139 debugstr_w(lpszRegister
));
2140 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2142 if (is_kbd_ime_unicode(immHkl
))
2143 return immHkl
->pImeRegisterWord(lpszReading
,dwStyle
,lpszRegister
);
2146 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2147 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
2150 rc
= immHkl
->pImeRegisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2151 (LPCWSTR
)lpszaRegister
);
2152 HeapFree(GetProcessHeap(),0,lpszaReading
);
2153 HeapFree(GetProcessHeap(),0,lpszaRegister
);
2161 /***********************************************************************
2162 * ImmReleaseContext (IMM32.@)
2164 BOOL WINAPI
ImmReleaseContext(HWND hWnd
, HIMC hIMC
)
2166 static BOOL shown
= FALSE
;
2169 FIXME("(%p, %p): stub\n", hWnd
, hIMC
);
2175 /***********************************************************************
2176 * ImmRequestMessageA(IMM32.@)
2178 LRESULT WINAPI
ImmRequestMessageA(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2180 InputContextData
*data
= get_imc_data(hIMC
);
2182 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2184 if (data
) return SendMessageA(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2186 SetLastError(ERROR_INVALID_HANDLE
);
2190 /***********************************************************************
2191 * ImmRequestMessageW(IMM32.@)
2193 LRESULT WINAPI
ImmRequestMessageW(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2195 InputContextData
*data
= get_imc_data(hIMC
);
2197 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2199 if (data
) return SendMessageW(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2201 SetLastError(ERROR_INVALID_HANDLE
);
2205 /***********************************************************************
2206 * ImmSetCandidateWindow (IMM32.@)
2208 BOOL WINAPI
ImmSetCandidateWindow(
2209 HIMC hIMC
, LPCANDIDATEFORM lpCandidate
)
2211 InputContextData
*data
= get_imc_data(hIMC
);
2213 TRACE("(%p, %p)\n", hIMC
, lpCandidate
);
2215 if (!data
|| !lpCandidate
)
2218 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2221 TRACE("\t%x, %x, (%i,%i), (%i,%i - %i,%i)\n",
2222 lpCandidate
->dwIndex
, lpCandidate
->dwStyle
,
2223 lpCandidate
->ptCurrentPos
.x
, lpCandidate
->ptCurrentPos
.y
,
2224 lpCandidate
->rcArea
.top
, lpCandidate
->rcArea
.left
,
2225 lpCandidate
->rcArea
.bottom
, lpCandidate
->rcArea
.right
);
2227 if ( lpCandidate
->dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
2230 data
->IMC
.cfCandForm
[lpCandidate
->dwIndex
] = *lpCandidate
;
2231 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCANDIDATEPOS
);
2232 ImmInternalSendIMENotify(data
, IMN_SETCANDIDATEPOS
, 1 << lpCandidate
->dwIndex
);
2237 /***********************************************************************
2238 * ImmSetCompositionFontA (IMM32.@)
2240 BOOL WINAPI
ImmSetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
2242 InputContextData
*data
= get_imc_data(hIMC
);
2243 TRACE("(%p, %p)\n", hIMC
, lplf
);
2247 SetLastError(ERROR_INVALID_HANDLE
);
2251 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2254 memcpy(&data
->IMC
.lfFont
.W
,lplf
,sizeof(LOGFONTA
));
2255 MultiByteToWideChar(CP_ACP
, 0, lplf
->lfFaceName
, -1, data
->IMC
.lfFont
.W
.lfFaceName
,
2257 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2258 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2263 /***********************************************************************
2264 * ImmSetCompositionFontW (IMM32.@)
2266 BOOL WINAPI
ImmSetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
2268 InputContextData
*data
= get_imc_data(hIMC
);
2269 TRACE("(%p, %p)\n", hIMC
, lplf
);
2273 SetLastError(ERROR_INVALID_HANDLE
);
2277 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2280 data
->IMC
.lfFont
.W
= *lplf
;
2281 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2282 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2287 /***********************************************************************
2288 * ImmSetCompositionStringA (IMM32.@)
2290 BOOL WINAPI
ImmSetCompositionStringA(
2291 HIMC hIMC
, DWORD dwIndex
,
2292 LPCVOID lpComp
, DWORD dwCompLen
,
2293 LPCVOID lpRead
, DWORD dwReadLen
)
2297 WCHAR
*CompBuffer
= NULL
;
2298 WCHAR
*ReadBuffer
= NULL
;
2300 InputContextData
*data
= get_imc_data(hIMC
);
2302 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2303 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2308 if (!(dwIndex
== SCS_SETSTR
||
2309 dwIndex
== SCS_CHANGEATTR
||
2310 dwIndex
== SCS_CHANGECLAUSE
||
2311 dwIndex
== SCS_SETRECONVERTSTRING
||
2312 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2315 if (!is_himc_ime_unicode(data
))
2316 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2317 dwCompLen
, lpRead
, dwReadLen
);
2319 comp_len
= MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0);
2322 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
* sizeof(WCHAR
));
2323 MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
);
2326 read_len
= MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0);
2329 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
* sizeof(WCHAR
));
2330 MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
);
2333 rc
= ImmSetCompositionStringW(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2334 ReadBuffer
, read_len
);
2336 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2337 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2342 /***********************************************************************
2343 * ImmSetCompositionStringW (IMM32.@)
2345 BOOL WINAPI
ImmSetCompositionStringW(
2346 HIMC hIMC
, DWORD dwIndex
,
2347 LPCVOID lpComp
, DWORD dwCompLen
,
2348 LPCVOID lpRead
, DWORD dwReadLen
)
2352 CHAR
*CompBuffer
= NULL
;
2353 CHAR
*ReadBuffer
= NULL
;
2355 InputContextData
*data
= get_imc_data(hIMC
);
2357 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2358 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2363 if (!(dwIndex
== SCS_SETSTR
||
2364 dwIndex
== SCS_CHANGEATTR
||
2365 dwIndex
== SCS_CHANGECLAUSE
||
2366 dwIndex
== SCS_SETRECONVERTSTRING
||
2367 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2370 if (is_himc_ime_unicode(data
))
2371 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2372 dwCompLen
, lpRead
, dwReadLen
);
2374 comp_len
= WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0, NULL
,
2378 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
);
2379 WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
,
2383 read_len
= WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0, NULL
,
2387 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
);
2388 WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
,
2392 rc
= ImmSetCompositionStringA(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2393 ReadBuffer
, read_len
);
2395 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2396 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2401 /***********************************************************************
2402 * ImmSetCompositionWindow (IMM32.@)
2404 BOOL WINAPI
ImmSetCompositionWindow(
2405 HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
2407 BOOL reshow
= FALSE
;
2408 InputContextData
*data
= get_imc_data(hIMC
);
2410 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
2411 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm
->dwStyle
,
2412 lpCompForm
->ptCurrentPos
.x
, lpCompForm
->ptCurrentPos
.y
, lpCompForm
->rcArea
.top
,
2413 lpCompForm
->rcArea
.left
, lpCompForm
->rcArea
.bottom
, lpCompForm
->rcArea
.right
);
2417 SetLastError(ERROR_INVALID_HANDLE
);
2421 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2424 data
->IMC
.cfCompForm
= *lpCompForm
;
2426 if (IsWindowVisible(data
->immKbd
->UIWnd
))
2429 ShowWindow(data
->immKbd
->UIWnd
,SW_HIDE
);
2432 /* FIXME: this is a partial stub */
2435 ShowWindow(data
->immKbd
->UIWnd
,SW_SHOWNOACTIVATE
);
2437 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONWINDOW
, 0);
2441 /***********************************************************************
2442 * ImmSetConversionStatus (IMM32.@)
2444 BOOL WINAPI
ImmSetConversionStatus(
2445 HIMC hIMC
, DWORD fdwConversion
, DWORD fdwSentence
)
2447 DWORD oldConversion
, oldSentence
;
2448 InputContextData
*data
= get_imc_data(hIMC
);
2450 TRACE("%p %d %d\n", hIMC
, fdwConversion
, fdwSentence
);
2454 SetLastError(ERROR_INVALID_HANDLE
);
2458 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2461 if ( fdwConversion
!= data
->IMC
.fdwConversion
)
2463 oldConversion
= data
->IMC
.fdwConversion
;
2464 data
->IMC
.fdwConversion
= fdwConversion
;
2465 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldConversion
, IMC_SETCONVERSIONMODE
);
2466 ImmInternalSendIMENotify(data
, IMN_SETCONVERSIONMODE
, 0);
2468 if ( fdwSentence
!= data
->IMC
.fdwSentence
)
2470 oldSentence
= data
->IMC
.fdwSentence
;
2471 data
->IMC
.fdwSentence
= fdwSentence
;
2472 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldSentence
, IMC_SETSENTENCEMODE
);
2473 ImmInternalSendIMENotify(data
, IMN_SETSENTENCEMODE
, 0);
2479 /***********************************************************************
2480 * ImmSetOpenStatus (IMM32.@)
2482 BOOL WINAPI
ImmSetOpenStatus(HIMC hIMC
, BOOL fOpen
)
2484 InputContextData
*data
= get_imc_data(hIMC
);
2486 TRACE("%p %d\n", hIMC
, fOpen
);
2490 SetLastError(ERROR_INVALID_HANDLE
);
2494 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2497 if (data
->immKbd
->UIWnd
== NULL
)
2499 /* create the ime window */
2500 data
->immKbd
->UIWnd
= CreateWindowExW( WS_EX_TOOLWINDOW
,
2501 data
->immKbd
->imeClassName
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0,
2502 0, data
->immKbd
->hIME
, 0);
2503 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2506 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2508 if (!fOpen
!= !data
->IMC
.fOpen
)
2510 data
->IMC
.fOpen
= fOpen
;
2511 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETOPENSTATUS
);
2512 ImmInternalSendIMENotify(data
, IMN_SETOPENSTATUS
, 0);
2518 /***********************************************************************
2519 * ImmSetStatusWindowPos (IMM32.@)
2521 BOOL WINAPI
ImmSetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
2523 InputContextData
*data
= get_imc_data(hIMC
);
2525 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
2527 if (!data
|| !lpptPos
)
2529 SetLastError(ERROR_INVALID_HANDLE
);
2533 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2536 TRACE("\t(%i,%i)\n", lpptPos
->x
, lpptPos
->y
);
2538 data
->IMC
.ptStatusWndPos
= *lpptPos
;
2539 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETSTATUSWINDOWPOS
);
2540 ImmInternalSendIMENotify(data
, IMN_SETSTATUSWINDOWPOS
, 0);
2545 /***********************************************************************
2546 * ImmCreateSoftKeyboard(IMM32.@)
2548 HWND WINAPI
ImmCreateSoftKeyboard(UINT uType
, UINT hOwner
, int x
, int y
)
2550 FIXME("(%d, %d, %d, %d): stub\n", uType
, hOwner
, x
, y
);
2551 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2555 /***********************************************************************
2556 * ImmDestroySoftKeyboard(IMM32.@)
2558 BOOL WINAPI
ImmDestroySoftKeyboard(HWND hSoftWnd
)
2560 FIXME("(%p): stub\n", hSoftWnd
);
2561 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2565 /***********************************************************************
2566 * ImmShowSoftKeyboard(IMM32.@)
2568 BOOL WINAPI
ImmShowSoftKeyboard(HWND hSoftWnd
, int nCmdShow
)
2570 FIXME("(%p, %d): stub\n", hSoftWnd
, nCmdShow
);
2571 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2575 /***********************************************************************
2576 * ImmSimulateHotKey (IMM32.@)
2578 BOOL WINAPI
ImmSimulateHotKey(HWND hWnd
, DWORD dwHotKeyID
)
2580 FIXME("(%p, %d): stub\n", hWnd
, dwHotKeyID
);
2581 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2585 /***********************************************************************
2586 * ImmUnregisterWordA (IMM32.@)
2588 BOOL WINAPI
ImmUnregisterWordA(
2589 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszUnregister
)
2591 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2592 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2593 debugstr_a(lpszUnregister
));
2594 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2596 if (!is_kbd_ime_unicode(immHkl
))
2597 return immHkl
->pImeUnregisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2598 (LPCWSTR
)lpszUnregister
);
2601 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2602 LPWSTR lpszwUnregister
= strdupAtoW(lpszUnregister
);
2605 rc
= immHkl
->pImeUnregisterWord(lpszwReading
,dwStyle
,lpszwUnregister
);
2606 HeapFree(GetProcessHeap(),0,lpszwReading
);
2607 HeapFree(GetProcessHeap(),0,lpszwUnregister
);
2615 /***********************************************************************
2616 * ImmUnregisterWordW (IMM32.@)
2618 BOOL WINAPI
ImmUnregisterWordW(
2619 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
2621 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2622 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2623 debugstr_w(lpszUnregister
));
2624 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2626 if (is_kbd_ime_unicode(immHkl
))
2627 return immHkl
->pImeUnregisterWord(lpszReading
,dwStyle
,lpszUnregister
);
2630 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2631 LPSTR lpszaUnregister
= strdupWtoA(lpszUnregister
);
2634 rc
= immHkl
->pImeUnregisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2635 (LPCWSTR
)lpszaUnregister
);
2636 HeapFree(GetProcessHeap(),0,lpszaReading
);
2637 HeapFree(GetProcessHeap(),0,lpszaUnregister
);
2645 /***********************************************************************
2646 * ImmGetImeMenuItemsA (IMM32.@)
2648 DWORD WINAPI
ImmGetImeMenuItemsA( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2649 LPIMEMENUITEMINFOA lpImeParentMenu
, LPIMEMENUITEMINFOA lpImeMenu
,
2652 InputContextData
*data
= get_imc_data(hIMC
);
2653 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2654 lpImeParentMenu
, lpImeMenu
, dwSize
);
2658 SetLastError(ERROR_INVALID_HANDLE
);
2662 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2664 if (!is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2665 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2666 (IMEMENUITEMINFOW
*)lpImeParentMenu
,
2667 (IMEMENUITEMINFOW
*)lpImeMenu
, dwSize
);
2670 IMEMENUITEMINFOW lpImeParentMenuW
;
2671 IMEMENUITEMINFOW
*lpImeMenuW
, *parent
= NULL
;
2674 if (lpImeParentMenu
)
2675 parent
= &lpImeParentMenuW
;
2678 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOA
);
2679 dwSize
= count
* sizeof(IMEMENUITEMINFOW
);
2680 lpImeMenuW
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2685 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2686 parent
, lpImeMenuW
, dwSize
);
2688 if (lpImeParentMenu
)
2690 memcpy(lpImeParentMenu
,&lpImeParentMenuW
,sizeof(IMEMENUITEMINFOA
));
2691 lpImeParentMenu
->hbmpItem
= lpImeParentMenuW
.hbmpItem
;
2692 WideCharToMultiByte(CP_ACP
, 0, lpImeParentMenuW
.szString
,
2693 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
,
2696 if (lpImeMenu
&& rc
)
2699 for (i
= 0; i
< rc
; i
++)
2701 memcpy(&lpImeMenu
[i
],&lpImeMenuW
[1],sizeof(IMEMENUITEMINFOA
));
2702 lpImeMenu
[i
].hbmpItem
= lpImeMenuW
[i
].hbmpItem
;
2703 WideCharToMultiByte(CP_ACP
, 0, lpImeMenuW
[i
].szString
,
2704 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
,
2708 HeapFree(GetProcessHeap(),0,lpImeMenuW
);
2716 /***********************************************************************
2717 * ImmGetImeMenuItemsW (IMM32.@)
2719 DWORD WINAPI
ImmGetImeMenuItemsW( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2720 LPIMEMENUITEMINFOW lpImeParentMenu
, LPIMEMENUITEMINFOW lpImeMenu
,
2723 InputContextData
*data
= get_imc_data(hIMC
);
2724 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2725 lpImeParentMenu
, lpImeMenu
, dwSize
);
2729 SetLastError(ERROR_INVALID_HANDLE
);
2733 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2735 if (is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2736 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2737 lpImeParentMenu
, lpImeMenu
, dwSize
);
2740 IMEMENUITEMINFOA lpImeParentMenuA
;
2741 IMEMENUITEMINFOA
*lpImeMenuA
, *parent
= NULL
;
2744 if (lpImeParentMenu
)
2745 parent
= &lpImeParentMenuA
;
2748 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOW
);
2749 dwSize
= count
* sizeof(IMEMENUITEMINFOA
);
2750 lpImeMenuA
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2755 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2756 (IMEMENUITEMINFOW
*)parent
,
2757 (IMEMENUITEMINFOW
*)lpImeMenuA
, dwSize
);
2759 if (lpImeParentMenu
)
2761 memcpy(lpImeParentMenu
,&lpImeParentMenuA
,sizeof(IMEMENUITEMINFOA
));
2762 lpImeParentMenu
->hbmpItem
= lpImeParentMenuA
.hbmpItem
;
2763 MultiByteToWideChar(CP_ACP
, 0, lpImeParentMenuA
.szString
,
2764 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
);
2766 if (lpImeMenu
&& rc
)
2769 for (i
= 0; i
< rc
; i
++)
2771 memcpy(&lpImeMenu
[i
],&lpImeMenuA
[1],sizeof(IMEMENUITEMINFOA
));
2772 lpImeMenu
[i
].hbmpItem
= lpImeMenuA
[i
].hbmpItem
;
2773 MultiByteToWideChar(CP_ACP
, 0, lpImeMenuA
[i
].szString
,
2774 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
);
2777 HeapFree(GetProcessHeap(),0,lpImeMenuA
);
2785 /***********************************************************************
2786 * ImmLockIMC(IMM32.@)
2788 LPINPUTCONTEXT WINAPI
ImmLockIMC(HIMC hIMC
)
2790 InputContextData
*data
= get_imc_data(hIMC
);
2798 /***********************************************************************
2799 * ImmUnlockIMC(IMM32.@)
2801 BOOL WINAPI
ImmUnlockIMC(HIMC hIMC
)
2803 InputContextData
*data
= get_imc_data(hIMC
);
2812 /***********************************************************************
2813 * ImmGetIMCLockCount(IMM32.@)
2815 DWORD WINAPI
ImmGetIMCLockCount(HIMC hIMC
)
2817 InputContextData
*data
= get_imc_data(hIMC
);
2820 return data
->dwLock
;
2823 /***********************************************************************
2824 * ImmCreateIMCC(IMM32.@)
2826 HIMCC WINAPI
ImmCreateIMCC(DWORD size
)
2828 return GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, size
);
2831 /***********************************************************************
2832 * ImmDestroyIMCC(IMM32.@)
2834 HIMCC WINAPI
ImmDestroyIMCC(HIMCC block
)
2836 return GlobalFree(block
);
2839 /***********************************************************************
2840 * ImmLockIMCC(IMM32.@)
2842 LPVOID WINAPI
ImmLockIMCC(HIMCC imcc
)
2844 return GlobalLock(imcc
);
2847 /***********************************************************************
2848 * ImmUnlockIMCC(IMM32.@)
2850 BOOL WINAPI
ImmUnlockIMCC(HIMCC imcc
)
2852 return GlobalUnlock(imcc
);
2855 /***********************************************************************
2856 * ImmGetIMCCLockCount(IMM32.@)
2858 DWORD WINAPI
ImmGetIMCCLockCount(HIMCC imcc
)
2860 return GlobalFlags(imcc
) & GMEM_LOCKCOUNT
;
2863 /***********************************************************************
2864 * ImmReSizeIMCC(IMM32.@)
2866 HIMCC WINAPI
ImmReSizeIMCC(HIMCC imcc
, DWORD size
)
2868 return GlobalReAlloc(imcc
, size
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
2871 /***********************************************************************
2872 * ImmGetIMCCSize(IMM32.@)
2874 DWORD WINAPI
ImmGetIMCCSize(HIMCC imcc
)
2876 return GlobalSize(imcc
);
2879 /***********************************************************************
2880 * ImmGenerateMessage(IMM32.@)
2882 BOOL WINAPI
ImmGenerateMessage(HIMC hIMC
)
2884 InputContextData
*data
= get_imc_data(hIMC
);
2888 SetLastError(ERROR_INVALID_HANDLE
);
2892 TRACE("%i messages queued\n",data
->IMC
.dwNumMsgBuf
);
2893 if (data
->IMC
.dwNumMsgBuf
> 0)
2895 LPTRANSMSG lpTransMsg
;
2897 DWORD i
, dwNumMsgBuf
;
2899 /* We are going to detach our hMsgBuff so that if processing messages
2900 generates new messages they go into a new buffer */
2901 hMsgBuf
= data
->IMC
.hMsgBuf
;
2902 dwNumMsgBuf
= data
->IMC
.dwNumMsgBuf
;
2904 data
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
2905 data
->IMC
.dwNumMsgBuf
= 0;
2907 lpTransMsg
= ImmLockIMCC(hMsgBuf
);
2908 for (i
= 0; i
< dwNumMsgBuf
; i
++)
2909 ImmInternalSendIMEMessage(data
, lpTransMsg
[i
].message
, lpTransMsg
[i
].wParam
, lpTransMsg
[i
].lParam
);
2911 ImmUnlockIMCC(hMsgBuf
);
2912 ImmDestroyIMCC(hMsgBuf
);
2918 /***********************************************************************
2919 * ImmTranslateMessage(IMM32.@)
2920 * ( Undocumented, call internally and from user32.dll )
2922 BOOL WINAPI
ImmTranslateMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lKeyData
)
2924 InputContextData
*data
;
2925 HIMC imc
= ImmGetContext(hwnd
);
2931 static const DWORD list_count
= 10;
2933 TRACE("%p %x %x %x\n",hwnd
, msg
, (UINT
)wParam
, (UINT
)lKeyData
);
2940 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeToAsciiEx
)
2943 GetKeyboardState(state
);
2944 scancode
= lKeyData
>> 0x10 & 0xff;
2946 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list_count
* sizeof(TRANSMSG
) + sizeof(DWORD
));
2947 ((DWORD
*)list
)[0] = list_count
;
2949 if (data
->immKbd
->imeInfo
.fdwProperty
& IME_PROP_KBD_CHAR_FIRST
)
2953 if (!is_himc_ime_unicode(data
))
2954 ToAscii(data
->lastVK
, scancode
, state
, &chr
, 0);
2956 ToUnicodeEx(data
->lastVK
, scancode
, state
, &chr
, 1, 0, GetKeyboardLayout(0));
2957 uVirtKey
= MAKELONG(data
->lastVK
,chr
);
2960 uVirtKey
= data
->lastVK
;
2962 msg_count
= data
->immKbd
->pImeToAsciiEx(uVirtKey
, scancode
, state
, list
, 0, imc
);
2963 TRACE("%i messages generated\n",msg_count
);
2964 if (msg_count
&& msg_count
<= list_count
)
2967 LPTRANSMSG msgs
= (LPTRANSMSG
)((LPBYTE
)list
+ sizeof(DWORD
));
2969 for (i
= 0; i
< msg_count
; i
++)
2970 ImmInternalPostIMEMessage(data
, msgs
[i
].message
, msgs
[i
].wParam
, msgs
[i
].lParam
);
2972 else if (msg_count
> list_count
)
2973 ImmGenerateMessage(imc
);
2975 HeapFree(GetProcessHeap(),0,list
);
2977 data
->lastVK
= VK_PROCESSKEY
;
2979 return (msg_count
> 0);
2982 /***********************************************************************
2983 * ImmProcessKey(IMM32.@)
2984 * ( Undocumented, called from user32.dll )
2986 BOOL WINAPI
ImmProcessKey(HWND hwnd
, HKL hKL
, UINT vKey
, LPARAM lKeyData
, DWORD unknown
)
2988 InputContextData
*data
;
2989 HIMC imc
= ImmGetContext(hwnd
);
2992 TRACE("%p %p %x %x %x\n",hwnd
, hKL
, vKey
, (UINT
)lKeyData
, unknown
);
2999 /* Make sure we are inputting to the correct keyboard */
3000 if (data
->immKbd
->hkl
!= hKL
)
3002 ImmHkl
*new_hkl
= IMM_GetImmHkl(hKL
);
3005 data
->immKbd
->pImeSelect(imc
, FALSE
);
3006 data
->immKbd
->uSelected
--;
3007 data
->immKbd
= new_hkl
;
3008 data
->immKbd
->pImeSelect(imc
, TRUE
);
3009 data
->immKbd
->uSelected
++;
3015 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeProcessKey
)
3018 GetKeyboardState(state
);
3019 if (data
->immKbd
->pImeProcessKey(imc
, vKey
, lKeyData
, state
))
3021 data
->lastVK
= vKey
;
3025 data
->lastVK
= VK_PROCESSKEY
;
3029 /***********************************************************************
3030 * ImmDisableTextFrameService(IMM32.@)
3032 BOOL WINAPI
ImmDisableTextFrameService(DWORD idThread
)
3038 /***********************************************************************
3039 * ImmEnumInputContext(IMM32.@)
3042 BOOL WINAPI
ImmEnumInputContext(DWORD idThread
, IMCENUMPROC lpfn
, LPARAM lParam
)
3048 /***********************************************************************
3049 * ImmGetHotKey(IMM32.@)
3052 BOOL WINAPI
ImmGetHotKey(DWORD hotkey
, UINT
*modifiers
, UINT
*key
, HKL hkl
)
3054 FIXME("%x, %p, %p, %p: stub\n", hotkey
, modifiers
, key
, hkl
);