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 DestroyWindow(data
->hwndDefault
);
274 HeapFree(GetProcessHeap(),0,data
);
275 TRACE("Thread Data Destroyed\n");
279 LeaveCriticalSection(&threaddata_cs
);
282 static HMODULE
load_graphics_driver(void)
284 static const WCHAR display_device_guid_propW
[] = {
285 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
286 'd','e','v','i','c','e','_','g','u','i','d',0 };
287 static const WCHAR key_pathW
[] = {
288 'S','y','s','t','e','m','\\',
289 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
290 'C','o','n','t','r','o','l','\\',
291 'V','i','d','e','o','\\','{',0};
292 static const WCHAR displayW
[] = {'}','\\','0','0','0','0',0};
293 static const WCHAR driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
298 WCHAR path
[MAX_PATH
];
299 WCHAR key
[(sizeof(key_pathW
) + sizeof(displayW
)) / sizeof(WCHAR
) + 40];
300 UINT guid_atom
= HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW
));
302 if (!guid_atom
) return 0;
303 memcpy( key
, key_pathW
, sizeof(key_pathW
) );
304 if (!GlobalGetAtomNameW( guid_atom
, key
+ strlenW(key
), 40 )) return 0;
305 strcatW( key
, displayW
);
306 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, key
, &hkey
)) return 0;
308 if (!RegQueryValueExW( hkey
, driverW
, NULL
, NULL
, (BYTE
*)path
, &size
)) ret
= LoadLibraryW( path
);
310 TRACE( "%s %p\n", debugstr_w(path
), ret
);
314 /* ImmHkl loading and freeing */
315 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
316 static ImmHkl
*IMM_GetImmHkl(HKL hkl
)
319 WCHAR filename
[MAX_PATH
];
321 TRACE("Seeking ime for keyboard %p\n",hkl
);
323 LIST_FOR_EACH_ENTRY(ptr
, &ImmHklList
, ImmHkl
, entry
)
328 /* not found... create it */
330 ptr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ImmHkl
));
333 if (ImmGetIMEFileNameW(hkl
, filename
, MAX_PATH
)) ptr
->hIME
= LoadLibraryW(filename
);
334 if (!ptr
->hIME
) ptr
->hIME
= load_graphics_driver();
337 LOAD_FUNCPTR(ImeInquire
);
338 if (!ptr
->pImeInquire
|| !ptr
->pImeInquire(&ptr
->imeInfo
, ptr
->imeClassName
, NULL
))
340 FreeLibrary(ptr
->hIME
);
345 LOAD_FUNCPTR(ImeDestroy
);
346 LOAD_FUNCPTR(ImeSelect
);
347 if (!ptr
->pImeSelect
|| !ptr
->pImeDestroy
)
349 FreeLibrary(ptr
->hIME
);
354 LOAD_FUNCPTR(ImeConfigure
);
355 LOAD_FUNCPTR(ImeEscape
);
356 LOAD_FUNCPTR(ImeSetActiveContext
);
357 LOAD_FUNCPTR(ImeToAsciiEx
);
358 LOAD_FUNCPTR(NotifyIME
);
359 LOAD_FUNCPTR(ImeRegisterWord
);
360 LOAD_FUNCPTR(ImeUnregisterWord
);
361 LOAD_FUNCPTR(ImeEnumRegisterWord
);
362 LOAD_FUNCPTR(ImeSetCompositionString
);
363 LOAD_FUNCPTR(ImeConversionList
);
364 LOAD_FUNCPTR(ImeProcessKey
);
365 LOAD_FUNCPTR(ImeGetRegisterWordStyle
);
366 LOAD_FUNCPTR(ImeGetImeMenuItems
);
367 /* make sure our classname is WCHAR */
368 if (!is_kbd_ime_unicode(ptr
))
371 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ptr
->imeClassName
,
373 lstrcpyW(ptr
->imeClassName
, bufW
);
378 list_add_head(&ImmHklList
,&ptr
->entry
);
384 HWND WINAPI
__wine_get_ui_window(HKL hkl
)
386 ImmHkl
*immHkl
= IMM_GetImmHkl(hkl
);
387 return immHkl
->UIWnd
;
390 static void IMM_FreeAllImmHkl(void)
392 ImmHkl
*ptr
,*cursor2
;
394 LIST_FOR_EACH_ENTRY_SAFE(ptr
, cursor2
, &ImmHklList
, ImmHkl
, entry
)
396 list_remove(&ptr
->entry
);
400 FreeLibrary(ptr
->hIME
);
403 DestroyWindow(ptr
->UIWnd
);
404 HeapFree(GetProcessHeap(),0,ptr
);
408 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
410 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
413 case DLL_PROCESS_ATTACH
:
414 if (!User32InitializeImmEntryTable(IMM_INIT_MAGIC
))
419 case DLL_THREAD_ATTACH
:
421 case DLL_THREAD_DETACH
:
422 IMM_FreeThreadData();
424 case DLL_PROCESS_DETACH
:
425 if (lpReserved
) break;
426 IMM_FreeThreadData();
433 /* for posting messages as the IME */
434 static void ImmInternalPostIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
436 HWND target
= GetFocus();
438 PostMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
440 PostMessageW(target
, msg
, wParam
, lParam
);
443 static LRESULT
ImmInternalSendIMENotify(InputContextData
*data
, WPARAM notify
, LPARAM lParam
)
447 target
= data
->IMC
.hWnd
;
448 if (!target
) target
= GetFocus();
451 return SendMessageW(target
, WM_IME_NOTIFY
, notify
, lParam
);
456 static HIMCC
ImmCreateBlankCompStr(void)
459 LPCOMPOSITIONSTRING ptr
;
460 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
461 ptr
= ImmLockIMCC(rc
);
462 memset(ptr
,0,sizeof(COMPOSITIONSTRING
));
463 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
468 static InputContextData
* get_imc_data(HIMC hIMC
)
470 InputContextData
*data
= hIMC
;
475 if(IsBadReadPtr(data
, sizeof(InputContextData
)) || data
->magic
!= WINE_IMC_VALID_MAGIC
)
477 SetLastError(ERROR_INVALID_HANDLE
);
483 static HIMC
get_default_context( HWND hwnd
)
486 IMMThreadData
* thread_data
= IMM_GetThreadData( hwnd
);
488 if (!thread_data
) return 0;
490 if (thread_data
->defaultContext
)
492 ret
= thread_data
->defaultContext
;
493 LeaveCriticalSection(&threaddata_cs
);
497 /* can't create a default context in another thread */
498 if (thread_data
->threadID
!= GetCurrentThreadId())
500 LeaveCriticalSection(&threaddata_cs
);
504 LeaveCriticalSection(&threaddata_cs
);
506 ret
= ImmCreateContext();
508 ((InputContextData
*)ret
)->threadDefault
= TRUE
;
510 /* thread_data is in the current thread so we can assume it's still valid */
511 EnterCriticalSection(&threaddata_cs
);
513 if (thread_data
->defaultContext
) /* someone beat us */
515 IMM_DestroyContext( ret
);
516 ret
= thread_data
->defaultContext
;
518 else thread_data
->defaultContext
= ret
;
520 LeaveCriticalSection(&threaddata_cs
);
524 static BOOL
IMM_IsCrossThreadAccess(HWND hWnd
, HIMC hIMC
)
526 InputContextData
*data
;
530 DWORD thread
= GetWindowThreadProcessId(hWnd
, NULL
);
531 if (thread
!= GetCurrentThreadId()) return TRUE
;
533 data
= get_imc_data(hIMC
);
534 if (data
&& data
->threadID
!= GetCurrentThreadId())
540 /***********************************************************************
541 * ImmAssociateContext (IMM32.@)
543 HIMC WINAPI
ImmAssociateContext(HWND hWnd
, HIMC hIMC
)
546 InputContextData
*data
= get_imc_data(hIMC
);
548 TRACE("(%p, %p):\n", hWnd
, hIMC
);
554 * If already associated just return
556 if (hIMC
&& data
->IMC
.hWnd
== hWnd
)
559 if (hIMC
&& IMM_IsCrossThreadAccess(hWnd
, hIMC
))
564 HIMC defaultContext
= get_default_context( hWnd
);
565 old
= RemovePropW(hWnd
,szwWineIMCProperty
);
568 old
= defaultContext
;
569 else if (old
== (HIMC
)-1)
572 if (hIMC
!= defaultContext
)
574 if (hIMC
== NULL
) /* Meaning disable imm for that window*/
575 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)-1);
577 SetPropW(hWnd
,szwWineIMCProperty
,hIMC
);
582 InputContextData
*old_data
= old
;
583 if (old_data
->IMC
.hWnd
== hWnd
)
584 old_data
->IMC
.hWnd
= NULL
;
591 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, FALSE
, ISC_SHOWUIALL
);
592 data
->IMC
.hWnd
= hWnd
;
593 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, TRUE
, ISC_SHOWUIALL
);
600 * Helper function for ImmAssociateContextEx
602 static BOOL CALLBACK
_ImmAssociateContextExEnumProc(HWND hwnd
, LPARAM lParam
)
604 HIMC hImc
= (HIMC
)lParam
;
605 ImmAssociateContext(hwnd
,hImc
);
609 /***********************************************************************
610 * ImmAssociateContextEx (IMM32.@)
612 BOOL WINAPI
ImmAssociateContextEx(HWND hWnd
, HIMC hIMC
, DWORD dwFlags
)
614 TRACE("(%p, %p, 0x%x):\n", hWnd
, hIMC
, dwFlags
);
622 ImmAssociateContext(hWnd
,hIMC
);
626 HIMC defaultContext
= get_default_context( hWnd
);
627 if (!defaultContext
) return FALSE
;
628 ImmAssociateContext(hWnd
,defaultContext
);
631 case IACE_IGNORENOCONTEXT
:
632 if (GetPropW(hWnd
,szwWineIMCProperty
))
633 ImmAssociateContext(hWnd
,hIMC
);
636 EnumChildWindows(hWnd
,_ImmAssociateContextExEnumProc
,(LPARAM
)hIMC
);
639 FIXME("Unknown dwFlags 0x%x\n",dwFlags
);
644 /***********************************************************************
645 * ImmConfigureIMEA (IMM32.@)
647 BOOL WINAPI
ImmConfigureIMEA(
648 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
650 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
652 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
654 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
657 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
659 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| !is_kbd_ime_unicode(immHkl
))
660 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
664 REGISTERWORDA
*rwa
= lpData
;
667 rww
.lpReading
= strdupAtoW(rwa
->lpReading
);
668 rww
.lpWord
= strdupAtoW(rwa
->lpWord
);
669 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rww
);
670 HeapFree(GetProcessHeap(),0,rww
.lpReading
);
671 HeapFree(GetProcessHeap(),0,rww
.lpWord
);
679 /***********************************************************************
680 * ImmConfigureIMEW (IMM32.@)
682 BOOL WINAPI
ImmConfigureIMEW(
683 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
685 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
687 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
689 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
692 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
694 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| is_kbd_ime_unicode(immHkl
))
695 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
698 REGISTERWORDW
*rww
= lpData
;
702 rwa
.lpReading
= strdupWtoA(rww
->lpReading
);
703 rwa
.lpWord
= strdupWtoA(rww
->lpWord
);
704 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rwa
);
705 HeapFree(GetProcessHeap(),0,rwa
.lpReading
);
706 HeapFree(GetProcessHeap(),0,rwa
.lpWord
);
714 /***********************************************************************
715 * ImmCreateContext (IMM32.@)
717 HIMC WINAPI
ImmCreateContext(void)
719 InputContextData
*new_context
;
724 new_context
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputContextData
));
727 new_context
->immKbd
= IMM_GetImmHkl(GetKeyboardLayout(0));
729 if (!new_context
->immKbd
->hIME
)
731 TRACE("IME dll could not be loaded\n");
732 HeapFree(GetProcessHeap(),0,new_context
);
736 /* the HIMCCs are never NULL */
737 new_context
->IMC
.hCompStr
= ImmCreateBlankCompStr();
738 new_context
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
739 new_context
->IMC
.hCandInfo
= ImmCreateIMCC(sizeof(CANDIDATEINFO
));
740 ci
= ImmLockIMCC(new_context
->IMC
.hCandInfo
);
741 memset(ci
,0,sizeof(CANDIDATEINFO
));
742 ci
->dwSize
= sizeof(CANDIDATEINFO
);
743 ImmUnlockIMCC(new_context
->IMC
.hCandInfo
);
744 new_context
->IMC
.hGuideLine
= ImmCreateIMCC(sizeof(GUIDELINE
));
745 gl
= ImmLockIMCC(new_context
->IMC
.hGuideLine
);
746 memset(gl
,0,sizeof(GUIDELINE
));
747 gl
->dwSize
= sizeof(GUIDELINE
);
748 ImmUnlockIMCC(new_context
->IMC
.hGuideLine
);
750 for (i
= 0; i
< sizeof(new_context
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
); i
++)
751 new_context
->IMC
.cfCandForm
[i
].dwIndex
= ~0u;
753 /* Initialize the IME Private */
754 new_context
->IMC
.hPrivate
= ImmCreateIMCC(new_context
->immKbd
->imeInfo
.dwPrivateDataSize
);
756 new_context
->IMC
.fdwConversion
= new_context
->immKbd
->imeInfo
.fdwConversionCaps
;
757 new_context
->IMC
.fdwSentence
= new_context
->immKbd
->imeInfo
.fdwSentenceCaps
;
759 if (!new_context
->immKbd
->pImeSelect(new_context
, TRUE
))
761 TRACE("Selection of IME failed\n");
762 IMM_DestroyContext(new_context
);
765 new_context
->threadID
= GetCurrentThreadId();
766 SendMessageW(GetFocus(), WM_IME_SELECT
, TRUE
, (LPARAM
)GetKeyboardLayout(0));
768 new_context
->immKbd
->uSelected
++;
769 TRACE("Created context %p\n",new_context
);
771 new_context
->magic
= WINE_IMC_VALID_MAGIC
;
775 static BOOL
IMM_DestroyContext(HIMC hIMC
)
777 InputContextData
*data
= get_imc_data(hIMC
);
779 TRACE("Destroying %p\n",hIMC
);
784 data
->immKbd
->uSelected
--;
785 data
->immKbd
->pImeSelect(hIMC
, FALSE
);
786 SendMessageW(data
->IMC
.hWnd
, WM_IME_SELECT
, FALSE
, (LPARAM
)GetKeyboardLayout(0));
788 ImmDestroyIMCC(data
->IMC
.hCompStr
);
789 ImmDestroyIMCC(data
->IMC
.hCandInfo
);
790 ImmDestroyIMCC(data
->IMC
.hGuideLine
);
791 ImmDestroyIMCC(data
->IMC
.hPrivate
);
792 ImmDestroyIMCC(data
->IMC
.hMsgBuf
);
795 HeapFree(GetProcessHeap(),0,data
);
800 /***********************************************************************
801 * ImmDestroyContext (IMM32.@)
803 BOOL WINAPI
ImmDestroyContext(HIMC hIMC
)
805 if (!IMM_IsDefaultContext(hIMC
) && !IMM_IsCrossThreadAccess(NULL
, hIMC
))
806 return IMM_DestroyContext(hIMC
);
811 /***********************************************************************
812 * ImmDisableIME (IMM32.@)
814 BOOL WINAPI
ImmDisableIME(DWORD idThread
)
816 FIXME("(%d): stub\n", idThread
);
820 /***********************************************************************
821 * ImmEnumRegisterWordA (IMM32.@)
823 UINT WINAPI
ImmEnumRegisterWordA(
824 HKL hKL
, REGISTERWORDENUMPROCA lpfnEnumProc
,
825 LPCSTR lpszReading
, DWORD dwStyle
,
826 LPCSTR lpszRegister
, LPVOID lpData
)
828 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
829 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
830 debugstr_a(lpszReading
), dwStyle
, debugstr_a(lpszRegister
), lpData
);
831 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
833 if (!is_kbd_ime_unicode(immHkl
))
834 return immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
835 (LPCWSTR
)lpszReading
, dwStyle
, (LPCWSTR
)lpszRegister
, lpData
);
838 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
839 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
842 rc
= immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
843 lpszwReading
, dwStyle
, lpszwRegister
,
846 HeapFree(GetProcessHeap(),0,lpszwReading
);
847 HeapFree(GetProcessHeap(),0,lpszwRegister
);
855 /***********************************************************************
856 * ImmEnumRegisterWordW (IMM32.@)
858 UINT WINAPI
ImmEnumRegisterWordW(
859 HKL hKL
, REGISTERWORDENUMPROCW lpfnEnumProc
,
860 LPCWSTR lpszReading
, DWORD dwStyle
,
861 LPCWSTR lpszRegister
, LPVOID lpData
)
863 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
864 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
865 debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
), lpData
);
866 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
868 if (is_kbd_ime_unicode(immHkl
))
869 return immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, lpszReading
, dwStyle
,
870 lpszRegister
, lpData
);
873 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
874 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
877 rc
= immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, (LPCWSTR
)lpszaReading
,
878 dwStyle
, (LPCWSTR
)lpszaRegister
, lpData
);
880 HeapFree(GetProcessHeap(),0,lpszaReading
);
881 HeapFree(GetProcessHeap(),0,lpszaRegister
);
889 static inline BOOL
EscapeRequiresWA(UINT uEscape
)
891 if (uEscape
== IME_ESC_GET_EUDC_DICTIONARY
||
892 uEscape
== IME_ESC_SET_EUDC_DICTIONARY
||
893 uEscape
== IME_ESC_IME_NAME
||
894 uEscape
== IME_ESC_GETHELPFILENAME
)
899 /***********************************************************************
900 * ImmEscapeA (IMM32.@)
902 LRESULT WINAPI
ImmEscapeA(
904 UINT uEscape
, LPVOID lpData
)
906 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
907 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
909 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
911 if (!EscapeRequiresWA(uEscape
) || !is_kbd_ime_unicode(immHkl
))
912 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
915 WCHAR buffer
[81]; /* largest required buffer should be 80 */
917 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
919 MultiByteToWideChar(CP_ACP
,0,lpData
,-1,buffer
,81);
920 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
924 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
925 WideCharToMultiByte(CP_ACP
,0,buffer
,-1,lpData
,80, NULL
, NULL
);
934 /***********************************************************************
935 * ImmEscapeW (IMM32.@)
937 LRESULT WINAPI
ImmEscapeW(
939 UINT uEscape
, LPVOID lpData
)
941 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
942 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
944 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
946 if (!EscapeRequiresWA(uEscape
) || is_kbd_ime_unicode(immHkl
))
947 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
950 CHAR buffer
[81]; /* largest required buffer should be 80 */
952 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
954 WideCharToMultiByte(CP_ACP
,0,lpData
,-1,buffer
,81, NULL
, NULL
);
955 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
959 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
960 MultiByteToWideChar(CP_ACP
,0,buffer
,-1,lpData
,80);
969 /***********************************************************************
970 * ImmGetCandidateListA (IMM32.@)
972 DWORD WINAPI
ImmGetCandidateListA(
973 HIMC hIMC
, DWORD dwIndex
,
974 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
976 InputContextData
*data
= get_imc_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_WtoA( candlist
, lpCandList
, dwBufLen
);
1005 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1009 /***********************************************************************
1010 * ImmGetCandidateListCountA (IMM32.@)
1012 DWORD WINAPI
ImmGetCandidateListCountA(
1013 HIMC hIMC
, LPDWORD lpdwListCount
)
1015 InputContextData
*data
= get_imc_data(hIMC
);
1016 LPCANDIDATEINFO candinfo
;
1019 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1021 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1024 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1026 *lpdwListCount
= count
= candinfo
->dwCount
;
1028 if ( !is_himc_ime_unicode(data
) )
1029 ret
= candinfo
->dwSize
;
1032 ret
= sizeof(CANDIDATEINFO
);
1034 ret
+= ImmGetCandidateListA(hIMC
, count
, NULL
, 0);
1037 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1041 /***********************************************************************
1042 * ImmGetCandidateListCountW (IMM32.@)
1044 DWORD WINAPI
ImmGetCandidateListCountW(
1045 HIMC hIMC
, LPDWORD lpdwListCount
)
1047 InputContextData
*data
= get_imc_data(hIMC
);
1048 LPCANDIDATEINFO candinfo
;
1051 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1053 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1056 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1058 *lpdwListCount
= count
= candinfo
->dwCount
;
1060 if ( is_himc_ime_unicode(data
) )
1061 ret
= candinfo
->dwSize
;
1064 ret
= sizeof(CANDIDATEINFO
);
1066 ret
+= ImmGetCandidateListW(hIMC
, count
, NULL
, 0);
1069 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1073 /***********************************************************************
1074 * ImmGetCandidateListW (IMM32.@)
1076 DWORD WINAPI
ImmGetCandidateListW(
1077 HIMC hIMC
, DWORD dwIndex
,
1078 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1080 InputContextData
*data
= get_imc_data(hIMC
);
1081 LPCANDIDATEINFO candinfo
;
1082 LPCANDIDATELIST candlist
;
1085 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1087 if (!data
|| !data
->IMC
.hCandInfo
)
1090 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1091 if ( dwIndex
>= candinfo
->dwCount
||
1092 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1095 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1096 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1099 if ( is_himc_ime_unicode(data
) )
1101 ret
= candlist
->dwSize
;
1102 if ( lpCandList
&& dwBufLen
>= ret
)
1103 memcpy(lpCandList
, candlist
, ret
);
1106 ret
= convert_candidatelist_AtoW( candlist
, lpCandList
, dwBufLen
);
1109 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1113 /***********************************************************************
1114 * ImmGetCandidateWindow (IMM32.@)
1116 BOOL WINAPI
ImmGetCandidateWindow(
1117 HIMC hIMC
, DWORD dwIndex
, LPCANDIDATEFORM lpCandidate
)
1119 InputContextData
*data
= get_imc_data(hIMC
);
1121 TRACE("%p, %d, %p\n", hIMC
, dwIndex
, lpCandidate
);
1123 if (!data
|| !lpCandidate
)
1126 if ( dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
1129 if (data
->IMC
.cfCandForm
[dwIndex
].dwIndex
!= dwIndex
)
1132 *lpCandidate
= data
->IMC
.cfCandForm
[dwIndex
];
1137 /***********************************************************************
1138 * ImmGetCompositionFontA (IMM32.@)
1140 BOOL WINAPI
ImmGetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
1145 TRACE("(%p, %p):\n", hIMC
, lplf
);
1147 rc
= ImmGetCompositionFontW(hIMC
,&lfW
);
1151 memcpy(lplf
,&lfW
,sizeof(LOGFONTA
));
1152 WideCharToMultiByte(CP_ACP
, 0, lfW
.lfFaceName
, -1, lplf
->lfFaceName
,
1153 LF_FACESIZE
, NULL
, NULL
);
1157 /***********************************************************************
1158 * ImmGetCompositionFontW (IMM32.@)
1160 BOOL WINAPI
ImmGetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
1162 InputContextData
*data
= get_imc_data(hIMC
);
1164 TRACE("(%p, %p):\n", hIMC
, lplf
);
1169 *lplf
= data
->IMC
.lfFont
.W
;
1175 /* Helpers for the GetCompositionString functions */
1177 static INT
CopyCompStringIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE target
, INT tlen
,
1182 if (is_himc_ime_unicode(data
) && !unicode
)
1183 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)source
, slen
, (LPSTR
)target
, tlen
, NULL
, NULL
);
1184 else if (!is_himc_ime_unicode(data
) && unicode
)
1185 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)source
, slen
, (LPWSTR
)target
, tlen
) * sizeof(WCHAR
);
1188 int dlen
= (unicode
)?sizeof(WCHAR
):sizeof(CHAR
);
1189 memcpy( target
, source
, min(slen
,tlen
)*dlen
);
1196 static INT
CopyCompAttrIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1197 LPBYTE target
, INT tlen
, BOOL unicode
)
1201 if (is_himc_ime_unicode(data
) && !unicode
)
1203 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, sslen
, NULL
, 0, NULL
, NULL
);
1206 const BYTE
*src
= source
;
1207 LPBYTE dst
= target
;
1208 int i
, j
= 0, k
= 0;
1212 for (i
= 0; i
< sslen
; ++i
)
1216 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)ssource
+ i
, 1,
1217 NULL
, 0, NULL
, NULL
);
1218 for (; len
> 0; --len
)
1231 else if (!is_himc_ime_unicode(data
) && unicode
)
1233 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, sslen
, NULL
, 0);
1236 const BYTE
*src
= source
;
1237 LPBYTE dst
= target
;
1242 for (i
= 0; i
< sslen
; ++i
)
1244 if (IsDBCSLeadByte(((LPSTR
)ssource
)[i
]))
1257 memcpy( target
, source
, min(slen
,tlen
));
1264 static INT
CopyCompClauseIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
,
1265 LPBYTE target
, INT tlen
, BOOL unicode
)
1269 if (is_himc_ime_unicode(data
) && !unicode
)
1277 tlen
/= sizeof (DWORD
);
1278 for (i
= 0; i
< tlen
; ++i
)
1280 ((DWORD
*)target
)[i
] = WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
,
1281 ((DWORD
*)source
)[i
],
1285 rc
= sizeof (DWORD
) * i
;
1290 else if (!is_himc_ime_unicode(data
) && unicode
)
1298 tlen
/= sizeof (DWORD
);
1299 for (i
= 0; i
< tlen
; ++i
)
1301 ((DWORD
*)target
)[i
] = MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
,
1302 ((DWORD
*)source
)[i
],
1305 rc
= sizeof (DWORD
) * i
;
1312 memcpy( target
, source
, min(slen
,tlen
));
1319 static INT
CopyCompOffsetIMEtoClient(InputContextData
*data
, DWORD offset
, LPBYTE ssource
, BOOL unicode
)
1323 if (is_himc_ime_unicode(data
) && !unicode
)
1325 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, offset
, NULL
, 0, NULL
, NULL
);
1327 else if (!is_himc_ime_unicode(data
) && unicode
)
1329 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, offset
, NULL
, 0);
1337 static LONG
ImmGetCompositionStringT( HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
,
1338 DWORD dwBufLen
, BOOL unicode
)
1341 InputContextData
*data
= get_imc_data(hIMC
);
1342 LPCOMPOSITIONSTRING compstr
;
1345 TRACE("(%p, 0x%x, %p, %d)\n", hIMC
, dwIndex
, lpBuf
, dwBufLen
);
1350 if (!data
->IMC
.hCompStr
)
1353 compdata
= ImmLockIMCC(data
->IMC
.hCompStr
);
1354 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1359 TRACE("GCS_RESULTSTR\n");
1360 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
, lpBuf
, dwBufLen
, unicode
);
1363 TRACE("GCS_COMPSTR\n");
1364 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
, lpBuf
, dwBufLen
, unicode
);
1367 TRACE("GCS_COMPATTR\n");
1368 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompAttrOffset
, compstr
->dwCompAttrLen
,
1369 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1370 lpBuf
, dwBufLen
, unicode
);
1372 case GCS_COMPCLAUSE
:
1373 TRACE("GCS_COMPCLAUSE\n");
1374 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompClauseOffset
,compstr
->dwCompClauseLen
,
1375 compdata
+ compstr
->dwCompStrOffset
,
1376 lpBuf
, dwBufLen
, unicode
);
1378 case GCS_RESULTCLAUSE
:
1379 TRACE("GCS_RESULTCLAUSE\n");
1380 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultClauseOffset
,compstr
->dwResultClauseLen
,
1381 compdata
+ compstr
->dwResultStrOffset
,
1382 lpBuf
, dwBufLen
, unicode
);
1384 case GCS_RESULTREADSTR
:
1385 TRACE("GCS_RESULTREADSTR\n");
1386 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultReadStrOffset
, compstr
->dwResultReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1388 case GCS_RESULTREADCLAUSE
:
1389 TRACE("GCS_RESULTREADCLAUSE\n");
1390 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultReadClauseOffset
,compstr
->dwResultReadClauseLen
,
1391 compdata
+ compstr
->dwResultStrOffset
,
1392 lpBuf
, dwBufLen
, unicode
);
1394 case GCS_COMPREADSTR
:
1395 TRACE("GCS_COMPREADSTR\n");
1396 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1398 case GCS_COMPREADATTR
:
1399 TRACE("GCS_COMPREADATTR\n");
1400 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompReadAttrOffset
, compstr
->dwCompReadAttrLen
,
1401 compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
,
1402 lpBuf
, dwBufLen
, unicode
);
1404 case GCS_COMPREADCLAUSE
:
1405 TRACE("GCS_COMPREADCLAUSE\n");
1406 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompReadClauseOffset
,compstr
->dwCompReadClauseLen
,
1407 compdata
+ compstr
->dwCompStrOffset
,
1408 lpBuf
, dwBufLen
, unicode
);
1411 TRACE("GCS_CURSORPOS\n");
1412 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwCursorPos
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1414 case GCS_DELTASTART
:
1415 TRACE("GCS_DELTASTART\n");
1416 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwDeltaStart
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1419 FIXME("Unhandled index 0x%x\n",dwIndex
);
1423 ImmUnlockIMCC(data
->IMC
.hCompStr
);
1428 /***********************************************************************
1429 * ImmGetCompositionStringA (IMM32.@)
1431 LONG WINAPI
ImmGetCompositionStringA(
1432 HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
, DWORD dwBufLen
)
1434 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, FALSE
);
1438 /***********************************************************************
1439 * ImmGetCompositionStringW (IMM32.@)
1441 LONG WINAPI
ImmGetCompositionStringW(
1442 HIMC hIMC
, DWORD dwIndex
,
1443 LPVOID lpBuf
, DWORD dwBufLen
)
1445 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, TRUE
);
1448 /***********************************************************************
1449 * ImmGetCompositionWindow (IMM32.@)
1451 BOOL WINAPI
ImmGetCompositionWindow(HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
1453 InputContextData
*data
= get_imc_data(hIMC
);
1455 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
1460 *lpCompForm
= data
->IMC
.cfCompForm
;
1464 /***********************************************************************
1465 * ImmGetContext (IMM32.@)
1468 HIMC WINAPI
ImmGetContext(HWND hWnd
)
1472 TRACE("%p\n", hWnd
);
1474 if (!IsWindow(hWnd
))
1476 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1480 rc
= GetPropW(hWnd
,szwWineIMCProperty
);
1483 else if (rc
== NULL
)
1484 rc
= get_default_context( hWnd
);
1488 InputContextData
*data
= rc
;
1489 data
->IMC
.hWnd
= hWnd
;
1492 TRACE("returning %p\n", rc
);
1497 /***********************************************************************
1498 * ImmGetConversionListA (IMM32.@)
1500 DWORD WINAPI
ImmGetConversionListA(
1502 LPCSTR pSrc
, LPCANDIDATELIST lpDst
,
1503 DWORD dwBufLen
, UINT uFlag
)
1505 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1506 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_a(pSrc
), lpDst
,
1508 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1510 if (!is_kbd_ime_unicode(immHkl
))
1511 return immHkl
->pImeConversionList(hIMC
,(LPCWSTR
)pSrc
,lpDst
,dwBufLen
,uFlag
);
1514 LPCANDIDATELIST lpwDst
;
1516 LPWSTR pwSrc
= strdupAtoW(pSrc
);
1518 len
= immHkl
->pImeConversionList(hIMC
, pwSrc
, NULL
, 0, uFlag
);
1519 lpwDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1522 immHkl
->pImeConversionList(hIMC
, pwSrc
, lpwDst
, len
, uFlag
);
1523 ret
= convert_candidatelist_WtoA( lpwDst
, lpDst
, dwBufLen
);
1524 HeapFree(GetProcessHeap(), 0, lpwDst
);
1526 HeapFree(GetProcessHeap(), 0, pwSrc
);
1535 /***********************************************************************
1536 * ImmGetConversionListW (IMM32.@)
1538 DWORD WINAPI
ImmGetConversionListW(
1540 LPCWSTR pSrc
, LPCANDIDATELIST lpDst
,
1541 DWORD dwBufLen
, UINT uFlag
)
1543 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1544 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_w(pSrc
), lpDst
,
1546 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1548 if (is_kbd_ime_unicode(immHkl
))
1549 return immHkl
->pImeConversionList(hIMC
,pSrc
,lpDst
,dwBufLen
,uFlag
);
1552 LPCANDIDATELIST lpaDst
;
1554 LPSTR paSrc
= strdupWtoA(pSrc
);
1556 len
= immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, NULL
, 0, uFlag
);
1557 lpaDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1560 immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, lpaDst
, len
, uFlag
);
1561 ret
= convert_candidatelist_AtoW( lpaDst
, lpDst
, dwBufLen
);
1562 HeapFree(GetProcessHeap(), 0, lpaDst
);
1564 HeapFree(GetProcessHeap(), 0, paSrc
);
1573 /***********************************************************************
1574 * ImmGetConversionStatus (IMM32.@)
1576 BOOL WINAPI
ImmGetConversionStatus(
1577 HIMC hIMC
, LPDWORD lpfdwConversion
, LPDWORD lpfdwSentence
)
1579 InputContextData
*data
= get_imc_data(hIMC
);
1581 TRACE("%p %p %p\n", hIMC
, lpfdwConversion
, lpfdwSentence
);
1586 if (lpfdwConversion
)
1587 *lpfdwConversion
= data
->IMC
.fdwConversion
;
1589 *lpfdwSentence
= data
->IMC
.fdwSentence
;
1594 /***********************************************************************
1595 * ImmGetDefaultIMEWnd (IMM32.@)
1597 HWND WINAPI
ImmGetDefaultIMEWnd(HWND hWnd
)
1599 HWND ret
, new = NULL
;
1600 IMMThreadData
* thread_data
= IMM_GetThreadData(hWnd
);
1603 if (thread_data
->hwndDefault
== NULL
&& thread_data
->threadID
== GetCurrentThreadId())
1605 /* Do not create the window inside of a critical section */
1606 LeaveCriticalSection(&threaddata_cs
);
1607 new = CreateWindowExW( WS_EX_TOOLWINDOW
,
1608 szwIME
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0, 0, 0, 0);
1609 /* thread_data is in the current thread so we can assume it's still valid */
1610 EnterCriticalSection(&threaddata_cs
);
1611 /* See if anyone beat us */
1612 if (thread_data
->hwndDefault
== NULL
)
1614 thread_data
->hwndDefault
= new;
1618 ret
= thread_data
->hwndDefault
;
1619 LeaveCriticalSection(&threaddata_cs
);
1620 TRACE("Default is %p\n",ret
);
1621 /* Clean up an unused new window outside of the critical section */
1626 TRACE("Default is %p\n",ret
);
1630 /***********************************************************************
1631 * ImmGetDescriptionA (IMM32.@)
1633 UINT WINAPI
ImmGetDescriptionA(
1634 HKL hKL
, LPSTR lpszDescription
, UINT uBufLen
)
1639 TRACE("%p %p %d\n", hKL
, lpszDescription
, uBufLen
);
1641 /* find out how many characters in the unicode buffer */
1642 len
= ImmGetDescriptionW( hKL
, NULL
, 0 );
1646 /* allocate a buffer of that size */
1647 buf
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof (WCHAR
) );
1651 /* fetch the unicode buffer */
1652 len
= ImmGetDescriptionW( hKL
, buf
, len
+ 1 );
1654 /* convert it back to ASCII */
1655 len
= WideCharToMultiByte( CP_ACP
, 0, buf
, len
+ 1,
1656 lpszDescription
, uBufLen
, NULL
, NULL
);
1658 HeapFree( GetProcessHeap(), 0, buf
);
1666 /***********************************************************************
1667 * ImmGetDescriptionW (IMM32.@)
1669 UINT WINAPI
ImmGetDescriptionW(HKL hKL
, LPWSTR lpszDescription
, UINT uBufLen
)
1671 static const WCHAR name
[] = { 'W','i','n','e',' ','X','I','M',0 };
1673 FIXME("(%p, %p, %d): semi stub\n", hKL
, lpszDescription
, uBufLen
);
1676 if (!uBufLen
) return lstrlenW( name
);
1677 lstrcpynW( lpszDescription
, name
, uBufLen
);
1678 return lstrlenW( lpszDescription
);
1681 /***********************************************************************
1682 * ImmGetGuideLineA (IMM32.@)
1684 DWORD WINAPI
ImmGetGuideLineA(
1685 HIMC hIMC
, DWORD dwIndex
, LPSTR lpBuf
, DWORD dwBufLen
)
1687 FIXME("(%p, %d, %s, %d): stub\n",
1688 hIMC
, dwIndex
, debugstr_a(lpBuf
), dwBufLen
1690 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1694 /***********************************************************************
1695 * ImmGetGuideLineW (IMM32.@)
1697 DWORD WINAPI
ImmGetGuideLineW(HIMC hIMC
, DWORD dwIndex
, LPWSTR lpBuf
, DWORD dwBufLen
)
1699 FIXME("(%p, %d, %s, %d): stub\n",
1700 hIMC
, dwIndex
, debugstr_w(lpBuf
), dwBufLen
1702 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1706 /***********************************************************************
1707 * ImmGetIMEFileNameA (IMM32.@)
1709 UINT WINAPI
ImmGetIMEFileNameA( HKL hKL
, LPSTR lpszFileName
, UINT uBufLen
)
1712 UINT wBufLen
= uBufLen
;
1715 if (uBufLen
&& lpszFileName
)
1716 bufW
= HeapAlloc(GetProcessHeap(),0,uBufLen
* sizeof(WCHAR
));
1717 else /* We need this to get the number of byte required */
1719 bufW
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
* sizeof(WCHAR
));
1723 rc
= ImmGetIMEFileNameW(hKL
,bufW
,wBufLen
);
1727 if (uBufLen
&& lpszFileName
)
1728 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, lpszFileName
,
1729 uBufLen
, NULL
, NULL
);
1730 else /* get the length */
1731 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
,
1735 HeapFree(GetProcessHeap(),0,bufW
);
1739 /***********************************************************************
1740 * ImmGetIMEFileNameW (IMM32.@)
1742 UINT WINAPI
ImmGetIMEFileNameW(HKL hKL
, LPWSTR lpszFileName
, UINT uBufLen
)
1747 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1749 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hKL
);
1750 rc
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, regKey
, &hkey
);
1751 if (rc
!= ERROR_SUCCESS
)
1758 rc
= RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, NULL
, &length
);
1760 if (rc
!= ERROR_SUCCESS
)
1766 if (length
> uBufLen
* sizeof(WCHAR
) || !lpszFileName
)
1771 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1775 return length
/ sizeof(WCHAR
);
1778 RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, lpszFileName
, &length
);
1782 return length
/ sizeof(WCHAR
);
1785 /***********************************************************************
1786 * ImmGetOpenStatus (IMM32.@)
1788 BOOL WINAPI
ImmGetOpenStatus(HIMC hIMC
)
1790 InputContextData
*data
= get_imc_data(hIMC
);
1796 TRACE("(%p): semi-stub\n", hIMC
);
1799 FIXME("(%p): semi-stub\n", hIMC
);
1801 return data
->IMC
.fOpen
;
1804 /***********************************************************************
1805 * ImmGetProperty (IMM32.@)
1807 DWORD WINAPI
ImmGetProperty(HKL hKL
, DWORD fdwIndex
)
1812 TRACE("(%p, %d)\n", hKL
, fdwIndex
);
1813 kbd
= IMM_GetImmHkl(hKL
);
1815 if (kbd
&& kbd
->hIME
)
1819 case IGP_PROPERTY
: rc
= kbd
->imeInfo
.fdwProperty
; break;
1820 case IGP_CONVERSION
: rc
= kbd
->imeInfo
.fdwConversionCaps
; break;
1821 case IGP_SENTENCE
: rc
= kbd
->imeInfo
.fdwSentenceCaps
; break;
1822 case IGP_SETCOMPSTR
: rc
= kbd
->imeInfo
.fdwSCSCaps
; break;
1823 case IGP_SELECT
: rc
= kbd
->imeInfo
.fdwSelectCaps
; break;
1824 case IGP_GETIMEVERSION
: rc
= IMEVER_0400
; break;
1825 case IGP_UI
: rc
= 0; break;
1832 /***********************************************************************
1833 * ImmGetRegisterWordStyleA (IMM32.@)
1835 UINT WINAPI
ImmGetRegisterWordStyleA(
1836 HKL hKL
, UINT nItem
, LPSTYLEBUFA lpStyleBuf
)
1838 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1839 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1840 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1842 if (!is_kbd_ime_unicode(immHkl
))
1843 return immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)lpStyleBuf
);
1849 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,&sbw
);
1850 WideCharToMultiByte(CP_ACP
, 0, sbw
.szDescription
, -1,
1851 lpStyleBuf
->szDescription
, 32, NULL
, NULL
);
1852 lpStyleBuf
->dwStyle
= sbw
.dwStyle
;
1860 /***********************************************************************
1861 * ImmGetRegisterWordStyleW (IMM32.@)
1863 UINT WINAPI
ImmGetRegisterWordStyleW(
1864 HKL hKL
, UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
1866 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1867 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1868 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1870 if (is_kbd_ime_unicode(immHkl
))
1871 return immHkl
->pImeGetRegisterWordStyle(nItem
,lpStyleBuf
);
1877 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)&sba
);
1878 MultiByteToWideChar(CP_ACP
, 0, sba
.szDescription
, -1,
1879 lpStyleBuf
->szDescription
, 32);
1880 lpStyleBuf
->dwStyle
= sba
.dwStyle
;
1888 /***********************************************************************
1889 * ImmGetStatusWindowPos (IMM32.@)
1891 BOOL WINAPI
ImmGetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
1893 InputContextData
*data
= get_imc_data(hIMC
);
1895 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
1897 if (!data
|| !lpptPos
)
1900 *lpptPos
= data
->IMC
.ptStatusWndPos
;
1905 /***********************************************************************
1906 * ImmGetVirtualKey (IMM32.@)
1908 UINT WINAPI
ImmGetVirtualKey(HWND hWnd
)
1910 OSVERSIONINFOA version
;
1911 InputContextData
*data
= ImmGetContext( hWnd
);
1912 TRACE("%p\n", hWnd
);
1915 return data
->lastVK
;
1917 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
1918 GetVersionExA( &version
);
1919 switch(version
.dwPlatformId
)
1921 case VER_PLATFORM_WIN32_WINDOWS
:
1922 return VK_PROCESSKEY
;
1923 case VER_PLATFORM_WIN32_NT
:
1926 FIXME("%d not supported\n",version
.dwPlatformId
);
1927 return VK_PROCESSKEY
;
1931 /***********************************************************************
1932 * ImmInstallIMEA (IMM32.@)
1934 HKL WINAPI
ImmInstallIMEA(
1935 LPCSTR lpszIMEFileName
, LPCSTR lpszLayoutText
)
1937 LPWSTR lpszwIMEFileName
;
1938 LPWSTR lpszwLayoutText
;
1941 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName
),
1942 debugstr_a(lpszLayoutText
));
1944 lpszwIMEFileName
= strdupAtoW(lpszIMEFileName
);
1945 lpszwLayoutText
= strdupAtoW(lpszLayoutText
);
1947 hkl
= ImmInstallIMEW(lpszwIMEFileName
, lpszwLayoutText
);
1949 HeapFree(GetProcessHeap(),0,lpszwIMEFileName
);
1950 HeapFree(GetProcessHeap(),0,lpszwLayoutText
);
1954 /***********************************************************************
1955 * ImmInstallIMEW (IMM32.@)
1957 HKL WINAPI
ImmInstallIMEW(
1958 LPCWSTR lpszIMEFileName
, LPCWSTR lpszLayoutText
)
1960 INT lcid
= GetUserDefaultLCID();
1965 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1967 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName
),
1968 debugstr_w(lpszLayoutText
));
1970 /* Start with 2. e001 will be blank and so default to the wine internal IME */
1973 while (count
< 0xfff)
1975 DWORD disposition
= 0;
1977 hkl
= (HKL
)MAKELPARAM( lcid
, 0xe000 | count
);
1978 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hkl
);
1980 rc
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, regKey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hkey
, &disposition
);
1981 if (rc
== ERROR_SUCCESS
&& disposition
== REG_CREATED_NEW_KEY
)
1983 else if (rc
== ERROR_SUCCESS
)
1991 WARN("Unable to find slot to install IME\n");
1995 if (rc
== ERROR_SUCCESS
)
1997 rc
= RegSetValueExW(hkey
, szImeFileW
, 0, REG_SZ
, (const BYTE
*)lpszIMEFileName
,
1998 (lstrlenW(lpszIMEFileName
) + 1) * sizeof(WCHAR
));
1999 if (rc
== ERROR_SUCCESS
)
2000 rc
= RegSetValueExW(hkey
, szLayoutTextW
, 0, REG_SZ
, (const BYTE
*)lpszLayoutText
,
2001 (lstrlenW(lpszLayoutText
) + 1) * sizeof(WCHAR
));
2007 WARN("Unable to set IME registry values\n");
2012 /***********************************************************************
2013 * ImmIsIME (IMM32.@)
2015 BOOL WINAPI
ImmIsIME(HKL hKL
)
2018 TRACE("(%p):\n", hKL
);
2019 ptr
= IMM_GetImmHkl(hKL
);
2020 return (ptr
&& ptr
->hIME
);
2023 /***********************************************************************
2024 * ImmIsUIMessageA (IMM32.@)
2026 BOOL WINAPI
ImmIsUIMessageA(
2027 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2029 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2030 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2031 (msg
== WM_IME_SETCONTEXT
) ||
2032 (msg
== WM_IME_NOTIFY
) ||
2033 (msg
== WM_IME_COMPOSITIONFULL
) ||
2034 (msg
== WM_IME_SELECT
) ||
2035 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2038 SendMessageA(hWndIME
, msg
, wParam
, lParam
);
2045 /***********************************************************************
2046 * ImmIsUIMessageW (IMM32.@)
2048 BOOL WINAPI
ImmIsUIMessageW(
2049 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2051 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2052 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2053 (msg
== WM_IME_SETCONTEXT
) ||
2054 (msg
== WM_IME_NOTIFY
) ||
2055 (msg
== WM_IME_COMPOSITIONFULL
) ||
2056 (msg
== WM_IME_SELECT
) ||
2057 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2060 SendMessageW(hWndIME
, msg
, wParam
, lParam
);
2067 /***********************************************************************
2068 * ImmNotifyIME (IMM32.@)
2070 BOOL WINAPI
ImmNotifyIME(
2071 HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
2073 InputContextData
*data
= get_imc_data(hIMC
);
2075 TRACE("(%p, %d, %d, %d)\n",
2076 hIMC
, dwAction
, dwIndex
, dwValue
);
2080 SetLastError(ERROR_SUCCESS
);
2084 if (!data
|| ! data
->immKbd
->pNotifyIME
)
2089 return data
->immKbd
->pNotifyIME(hIMC
,dwAction
,dwIndex
,dwValue
);
2092 /***********************************************************************
2093 * ImmRegisterWordA (IMM32.@)
2095 BOOL WINAPI
ImmRegisterWordA(
2096 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszRegister
)
2098 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2099 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2100 debugstr_a(lpszRegister
));
2101 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2103 if (!is_kbd_ime_unicode(immHkl
))
2104 return immHkl
->pImeRegisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2105 (LPCWSTR
)lpszRegister
);
2108 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2109 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
2112 rc
= immHkl
->pImeRegisterWord(lpszwReading
,dwStyle
,lpszwRegister
);
2113 HeapFree(GetProcessHeap(),0,lpszwReading
);
2114 HeapFree(GetProcessHeap(),0,lpszwRegister
);
2122 /***********************************************************************
2123 * ImmRegisterWordW (IMM32.@)
2125 BOOL WINAPI
ImmRegisterWordW(
2126 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
2128 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2129 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2130 debugstr_w(lpszRegister
));
2131 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2133 if (is_kbd_ime_unicode(immHkl
))
2134 return immHkl
->pImeRegisterWord(lpszReading
,dwStyle
,lpszRegister
);
2137 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2138 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
2141 rc
= immHkl
->pImeRegisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2142 (LPCWSTR
)lpszaRegister
);
2143 HeapFree(GetProcessHeap(),0,lpszaReading
);
2144 HeapFree(GetProcessHeap(),0,lpszaRegister
);
2152 /***********************************************************************
2153 * ImmReleaseContext (IMM32.@)
2155 BOOL WINAPI
ImmReleaseContext(HWND hWnd
, HIMC hIMC
)
2157 static BOOL shown
= FALSE
;
2160 FIXME("(%p, %p): stub\n", hWnd
, hIMC
);
2166 /***********************************************************************
2167 * ImmRequestMessageA(IMM32.@)
2169 LRESULT WINAPI
ImmRequestMessageA(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2171 InputContextData
*data
= get_imc_data(hIMC
);
2173 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2175 if (data
) return SendMessageA(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2177 SetLastError(ERROR_INVALID_HANDLE
);
2181 /***********************************************************************
2182 * ImmRequestMessageW(IMM32.@)
2184 LRESULT WINAPI
ImmRequestMessageW(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2186 InputContextData
*data
= get_imc_data(hIMC
);
2188 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2190 if (data
) return SendMessageW(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2192 SetLastError(ERROR_INVALID_HANDLE
);
2196 /***********************************************************************
2197 * ImmSetCandidateWindow (IMM32.@)
2199 BOOL WINAPI
ImmSetCandidateWindow(
2200 HIMC hIMC
, LPCANDIDATEFORM lpCandidate
)
2202 InputContextData
*data
= get_imc_data(hIMC
);
2204 TRACE("(%p, %p)\n", hIMC
, lpCandidate
);
2206 if (!data
|| !lpCandidate
)
2209 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2212 TRACE("\t%x, %x, (%i,%i), (%i,%i - %i,%i)\n",
2213 lpCandidate
->dwIndex
, lpCandidate
->dwStyle
,
2214 lpCandidate
->ptCurrentPos
.x
, lpCandidate
->ptCurrentPos
.y
,
2215 lpCandidate
->rcArea
.top
, lpCandidate
->rcArea
.left
,
2216 lpCandidate
->rcArea
.bottom
, lpCandidate
->rcArea
.right
);
2218 if ( lpCandidate
->dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
2221 data
->IMC
.cfCandForm
[lpCandidate
->dwIndex
] = *lpCandidate
;
2222 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCANDIDATEPOS
);
2223 ImmInternalSendIMENotify(data
, IMN_SETCANDIDATEPOS
, 1 << lpCandidate
->dwIndex
);
2228 /***********************************************************************
2229 * ImmSetCompositionFontA (IMM32.@)
2231 BOOL WINAPI
ImmSetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
2233 InputContextData
*data
= get_imc_data(hIMC
);
2234 TRACE("(%p, %p)\n", hIMC
, lplf
);
2238 SetLastError(ERROR_INVALID_HANDLE
);
2242 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2245 memcpy(&data
->IMC
.lfFont
.W
,lplf
,sizeof(LOGFONTA
));
2246 MultiByteToWideChar(CP_ACP
, 0, lplf
->lfFaceName
, -1, data
->IMC
.lfFont
.W
.lfFaceName
,
2248 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2249 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2254 /***********************************************************************
2255 * ImmSetCompositionFontW (IMM32.@)
2257 BOOL WINAPI
ImmSetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
2259 InputContextData
*data
= get_imc_data(hIMC
);
2260 TRACE("(%p, %p)\n", hIMC
, lplf
);
2264 SetLastError(ERROR_INVALID_HANDLE
);
2268 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2271 data
->IMC
.lfFont
.W
= *lplf
;
2272 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2273 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2278 /***********************************************************************
2279 * ImmSetCompositionStringA (IMM32.@)
2281 BOOL WINAPI
ImmSetCompositionStringA(
2282 HIMC hIMC
, DWORD dwIndex
,
2283 LPCVOID lpComp
, DWORD dwCompLen
,
2284 LPCVOID lpRead
, DWORD dwReadLen
)
2288 WCHAR
*CompBuffer
= NULL
;
2289 WCHAR
*ReadBuffer
= NULL
;
2291 InputContextData
*data
= get_imc_data(hIMC
);
2293 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2294 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2299 if (!(dwIndex
== SCS_SETSTR
||
2300 dwIndex
== SCS_CHANGEATTR
||
2301 dwIndex
== SCS_CHANGECLAUSE
||
2302 dwIndex
== SCS_SETRECONVERTSTRING
||
2303 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2306 if (!is_himc_ime_unicode(data
))
2307 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2308 dwCompLen
, lpRead
, dwReadLen
);
2310 comp_len
= MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0);
2313 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
* sizeof(WCHAR
));
2314 MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
);
2317 read_len
= MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0);
2320 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
* sizeof(WCHAR
));
2321 MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
);
2324 rc
= ImmSetCompositionStringW(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2325 ReadBuffer
, read_len
);
2327 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2328 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2333 /***********************************************************************
2334 * ImmSetCompositionStringW (IMM32.@)
2336 BOOL WINAPI
ImmSetCompositionStringW(
2337 HIMC hIMC
, DWORD dwIndex
,
2338 LPCVOID lpComp
, DWORD dwCompLen
,
2339 LPCVOID lpRead
, DWORD dwReadLen
)
2343 CHAR
*CompBuffer
= NULL
;
2344 CHAR
*ReadBuffer
= NULL
;
2346 InputContextData
*data
= get_imc_data(hIMC
);
2348 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2349 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2354 if (!(dwIndex
== SCS_SETSTR
||
2355 dwIndex
== SCS_CHANGEATTR
||
2356 dwIndex
== SCS_CHANGECLAUSE
||
2357 dwIndex
== SCS_SETRECONVERTSTRING
||
2358 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2361 if (is_himc_ime_unicode(data
))
2362 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2363 dwCompLen
, lpRead
, dwReadLen
);
2365 comp_len
= WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0, NULL
,
2369 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
);
2370 WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
,
2374 read_len
= WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0, NULL
,
2378 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
);
2379 WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
,
2383 rc
= ImmSetCompositionStringA(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2384 ReadBuffer
, read_len
);
2386 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2387 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2392 /***********************************************************************
2393 * ImmSetCompositionWindow (IMM32.@)
2395 BOOL WINAPI
ImmSetCompositionWindow(
2396 HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
2398 BOOL reshow
= FALSE
;
2399 InputContextData
*data
= get_imc_data(hIMC
);
2401 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
2402 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm
->dwStyle
,
2403 lpCompForm
->ptCurrentPos
.x
, lpCompForm
->ptCurrentPos
.y
, lpCompForm
->rcArea
.top
,
2404 lpCompForm
->rcArea
.left
, lpCompForm
->rcArea
.bottom
, lpCompForm
->rcArea
.right
);
2408 SetLastError(ERROR_INVALID_HANDLE
);
2412 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2415 data
->IMC
.cfCompForm
= *lpCompForm
;
2417 if (IsWindowVisible(data
->immKbd
->UIWnd
))
2420 ShowWindow(data
->immKbd
->UIWnd
,SW_HIDE
);
2423 /* FIXME: this is a partial stub */
2426 ShowWindow(data
->immKbd
->UIWnd
,SW_SHOWNOACTIVATE
);
2428 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONWINDOW
, 0);
2432 /***********************************************************************
2433 * ImmSetConversionStatus (IMM32.@)
2435 BOOL WINAPI
ImmSetConversionStatus(
2436 HIMC hIMC
, DWORD fdwConversion
, DWORD fdwSentence
)
2438 DWORD oldConversion
, oldSentence
;
2439 InputContextData
*data
= get_imc_data(hIMC
);
2441 TRACE("%p %d %d\n", hIMC
, fdwConversion
, fdwSentence
);
2445 SetLastError(ERROR_INVALID_HANDLE
);
2449 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2452 if ( fdwConversion
!= data
->IMC
.fdwConversion
)
2454 oldConversion
= data
->IMC
.fdwConversion
;
2455 data
->IMC
.fdwConversion
= fdwConversion
;
2456 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldConversion
, IMC_SETCONVERSIONMODE
);
2457 ImmInternalSendIMENotify(data
, IMN_SETCONVERSIONMODE
, 0);
2459 if ( fdwSentence
!= data
->IMC
.fdwSentence
)
2461 oldSentence
= data
->IMC
.fdwSentence
;
2462 data
->IMC
.fdwSentence
= fdwSentence
;
2463 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldSentence
, IMC_SETSENTENCEMODE
);
2464 ImmInternalSendIMENotify(data
, IMN_SETSENTENCEMODE
, 0);
2470 /***********************************************************************
2471 * ImmSetOpenStatus (IMM32.@)
2473 BOOL WINAPI
ImmSetOpenStatus(HIMC hIMC
, BOOL fOpen
)
2475 InputContextData
*data
= get_imc_data(hIMC
);
2477 TRACE("%p %d\n", hIMC
, fOpen
);
2481 SetLastError(ERROR_INVALID_HANDLE
);
2485 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2488 if (data
->immKbd
->UIWnd
== NULL
)
2490 /* create the ime window */
2491 data
->immKbd
->UIWnd
= CreateWindowExW( WS_EX_TOOLWINDOW
,
2492 data
->immKbd
->imeClassName
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0,
2493 0, data
->immKbd
->hIME
, 0);
2494 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2497 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2499 if (!fOpen
!= !data
->IMC
.fOpen
)
2501 data
->IMC
.fOpen
= fOpen
;
2502 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETOPENSTATUS
);
2503 ImmInternalSendIMENotify(data
, IMN_SETOPENSTATUS
, 0);
2509 /***********************************************************************
2510 * ImmSetStatusWindowPos (IMM32.@)
2512 BOOL WINAPI
ImmSetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
2514 InputContextData
*data
= get_imc_data(hIMC
);
2516 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
2518 if (!data
|| !lpptPos
)
2520 SetLastError(ERROR_INVALID_HANDLE
);
2524 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2527 TRACE("\t(%i,%i)\n", lpptPos
->x
, lpptPos
->y
);
2529 data
->IMC
.ptStatusWndPos
= *lpptPos
;
2530 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETSTATUSWINDOWPOS
);
2531 ImmInternalSendIMENotify(data
, IMN_SETSTATUSWINDOWPOS
, 0);
2536 /***********************************************************************
2537 * ImmCreateSoftKeyboard(IMM32.@)
2539 HWND WINAPI
ImmCreateSoftKeyboard(UINT uType
, UINT hOwner
, int x
, int y
)
2541 FIXME("(%d, %d, %d, %d): stub\n", uType
, hOwner
, x
, y
);
2542 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2546 /***********************************************************************
2547 * ImmDestroySoftKeyboard(IMM32.@)
2549 BOOL WINAPI
ImmDestroySoftKeyboard(HWND hSoftWnd
)
2551 FIXME("(%p): stub\n", hSoftWnd
);
2552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2556 /***********************************************************************
2557 * ImmShowSoftKeyboard(IMM32.@)
2559 BOOL WINAPI
ImmShowSoftKeyboard(HWND hSoftWnd
, int nCmdShow
)
2561 FIXME("(%p, %d): stub\n", hSoftWnd
, nCmdShow
);
2562 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2566 /***********************************************************************
2567 * ImmSimulateHotKey (IMM32.@)
2569 BOOL WINAPI
ImmSimulateHotKey(HWND hWnd
, DWORD dwHotKeyID
)
2571 FIXME("(%p, %d): stub\n", hWnd
, dwHotKeyID
);
2572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2576 /***********************************************************************
2577 * ImmUnregisterWordA (IMM32.@)
2579 BOOL WINAPI
ImmUnregisterWordA(
2580 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszUnregister
)
2582 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2583 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2584 debugstr_a(lpszUnregister
));
2585 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2587 if (!is_kbd_ime_unicode(immHkl
))
2588 return immHkl
->pImeUnregisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2589 (LPCWSTR
)lpszUnregister
);
2592 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2593 LPWSTR lpszwUnregister
= strdupAtoW(lpszUnregister
);
2596 rc
= immHkl
->pImeUnregisterWord(lpszwReading
,dwStyle
,lpszwUnregister
);
2597 HeapFree(GetProcessHeap(),0,lpszwReading
);
2598 HeapFree(GetProcessHeap(),0,lpszwUnregister
);
2606 /***********************************************************************
2607 * ImmUnregisterWordW (IMM32.@)
2609 BOOL WINAPI
ImmUnregisterWordW(
2610 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
2612 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2613 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2614 debugstr_w(lpszUnregister
));
2615 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2617 if (is_kbd_ime_unicode(immHkl
))
2618 return immHkl
->pImeUnregisterWord(lpszReading
,dwStyle
,lpszUnregister
);
2621 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2622 LPSTR lpszaUnregister
= strdupWtoA(lpszUnregister
);
2625 rc
= immHkl
->pImeUnregisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2626 (LPCWSTR
)lpszaUnregister
);
2627 HeapFree(GetProcessHeap(),0,lpszaReading
);
2628 HeapFree(GetProcessHeap(),0,lpszaUnregister
);
2636 /***********************************************************************
2637 * ImmGetImeMenuItemsA (IMM32.@)
2639 DWORD WINAPI
ImmGetImeMenuItemsA( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2640 LPIMEMENUITEMINFOA lpImeParentMenu
, LPIMEMENUITEMINFOA lpImeMenu
,
2643 InputContextData
*data
= get_imc_data(hIMC
);
2644 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2645 lpImeParentMenu
, lpImeMenu
, dwSize
);
2649 SetLastError(ERROR_INVALID_HANDLE
);
2653 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2655 if (!is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2656 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2657 (IMEMENUITEMINFOW
*)lpImeParentMenu
,
2658 (IMEMENUITEMINFOW
*)lpImeMenu
, dwSize
);
2661 IMEMENUITEMINFOW lpImeParentMenuW
;
2662 IMEMENUITEMINFOW
*lpImeMenuW
, *parent
= NULL
;
2665 if (lpImeParentMenu
)
2666 parent
= &lpImeParentMenuW
;
2669 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOA
);
2670 dwSize
= count
* sizeof(IMEMENUITEMINFOW
);
2671 lpImeMenuW
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2676 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2677 parent
, lpImeMenuW
, dwSize
);
2679 if (lpImeParentMenu
)
2681 memcpy(lpImeParentMenu
,&lpImeParentMenuW
,sizeof(IMEMENUITEMINFOA
));
2682 lpImeParentMenu
->hbmpItem
= lpImeParentMenuW
.hbmpItem
;
2683 WideCharToMultiByte(CP_ACP
, 0, lpImeParentMenuW
.szString
,
2684 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
,
2687 if (lpImeMenu
&& rc
)
2690 for (i
= 0; i
< rc
; i
++)
2692 memcpy(&lpImeMenu
[i
],&lpImeMenuW
[1],sizeof(IMEMENUITEMINFOA
));
2693 lpImeMenu
[i
].hbmpItem
= lpImeMenuW
[i
].hbmpItem
;
2694 WideCharToMultiByte(CP_ACP
, 0, lpImeMenuW
[i
].szString
,
2695 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
,
2699 HeapFree(GetProcessHeap(),0,lpImeMenuW
);
2707 /***********************************************************************
2708 * ImmGetImeMenuItemsW (IMM32.@)
2710 DWORD WINAPI
ImmGetImeMenuItemsW( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2711 LPIMEMENUITEMINFOW lpImeParentMenu
, LPIMEMENUITEMINFOW lpImeMenu
,
2714 InputContextData
*data
= get_imc_data(hIMC
);
2715 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2716 lpImeParentMenu
, lpImeMenu
, dwSize
);
2720 SetLastError(ERROR_INVALID_HANDLE
);
2724 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2726 if (is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2727 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2728 lpImeParentMenu
, lpImeMenu
, dwSize
);
2731 IMEMENUITEMINFOA lpImeParentMenuA
;
2732 IMEMENUITEMINFOA
*lpImeMenuA
, *parent
= NULL
;
2735 if (lpImeParentMenu
)
2736 parent
= &lpImeParentMenuA
;
2739 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOW
);
2740 dwSize
= count
* sizeof(IMEMENUITEMINFOA
);
2741 lpImeMenuA
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2746 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2747 (IMEMENUITEMINFOW
*)parent
,
2748 (IMEMENUITEMINFOW
*)lpImeMenuA
, dwSize
);
2750 if (lpImeParentMenu
)
2752 memcpy(lpImeParentMenu
,&lpImeParentMenuA
,sizeof(IMEMENUITEMINFOA
));
2753 lpImeParentMenu
->hbmpItem
= lpImeParentMenuA
.hbmpItem
;
2754 MultiByteToWideChar(CP_ACP
, 0, lpImeParentMenuA
.szString
,
2755 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
);
2757 if (lpImeMenu
&& rc
)
2760 for (i
= 0; i
< rc
; i
++)
2762 memcpy(&lpImeMenu
[i
],&lpImeMenuA
[1],sizeof(IMEMENUITEMINFOA
));
2763 lpImeMenu
[i
].hbmpItem
= lpImeMenuA
[i
].hbmpItem
;
2764 MultiByteToWideChar(CP_ACP
, 0, lpImeMenuA
[i
].szString
,
2765 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
);
2768 HeapFree(GetProcessHeap(),0,lpImeMenuA
);
2776 /***********************************************************************
2777 * ImmLockIMC(IMM32.@)
2779 LPINPUTCONTEXT WINAPI
ImmLockIMC(HIMC hIMC
)
2781 InputContextData
*data
= get_imc_data(hIMC
);
2789 /***********************************************************************
2790 * ImmUnlockIMC(IMM32.@)
2792 BOOL WINAPI
ImmUnlockIMC(HIMC hIMC
)
2794 InputContextData
*data
= get_imc_data(hIMC
);
2803 /***********************************************************************
2804 * ImmGetIMCLockCount(IMM32.@)
2806 DWORD WINAPI
ImmGetIMCLockCount(HIMC hIMC
)
2808 InputContextData
*data
= get_imc_data(hIMC
);
2811 return data
->dwLock
;
2814 /***********************************************************************
2815 * ImmCreateIMCC(IMM32.@)
2817 HIMCC WINAPI
ImmCreateIMCC(DWORD size
)
2819 return GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, size
);
2822 /***********************************************************************
2823 * ImmDestroyIMCC(IMM32.@)
2825 HIMCC WINAPI
ImmDestroyIMCC(HIMCC block
)
2827 return GlobalFree(block
);
2830 /***********************************************************************
2831 * ImmLockIMCC(IMM32.@)
2833 LPVOID WINAPI
ImmLockIMCC(HIMCC imcc
)
2835 return GlobalLock(imcc
);
2838 /***********************************************************************
2839 * ImmUnlockIMCC(IMM32.@)
2841 BOOL WINAPI
ImmUnlockIMCC(HIMCC imcc
)
2843 return GlobalUnlock(imcc
);
2846 /***********************************************************************
2847 * ImmGetIMCCLockCount(IMM32.@)
2849 DWORD WINAPI
ImmGetIMCCLockCount(HIMCC imcc
)
2851 return GlobalFlags(imcc
) & GMEM_LOCKCOUNT
;
2854 /***********************************************************************
2855 * ImmReSizeIMCC(IMM32.@)
2857 HIMCC WINAPI
ImmReSizeIMCC(HIMCC imcc
, DWORD size
)
2859 return GlobalReAlloc(imcc
, size
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
2862 /***********************************************************************
2863 * ImmGetIMCCSize(IMM32.@)
2865 DWORD WINAPI
ImmGetIMCCSize(HIMCC imcc
)
2867 return GlobalSize(imcc
);
2870 /***********************************************************************
2871 * ImmGenerateMessage(IMM32.@)
2873 BOOL WINAPI
ImmGenerateMessage(HIMC hIMC
)
2875 InputContextData
*data
= get_imc_data(hIMC
);
2879 SetLastError(ERROR_INVALID_HANDLE
);
2883 TRACE("%i messages queued\n",data
->IMC
.dwNumMsgBuf
);
2884 if (data
->IMC
.dwNumMsgBuf
> 0)
2886 LPTRANSMSG lpTransMsg
;
2889 lpTransMsg
= ImmLockIMCC(data
->IMC
.hMsgBuf
);
2890 for (i
= 0; i
< data
->IMC
.dwNumMsgBuf
; i
++)
2891 ImmInternalPostIMEMessage(data
, lpTransMsg
[i
].message
, lpTransMsg
[i
].wParam
, lpTransMsg
[i
].lParam
);
2893 ImmUnlockIMCC(data
->IMC
.hMsgBuf
);
2895 data
->IMC
.dwNumMsgBuf
= 0;
2901 /***********************************************************************
2902 * ImmTranslateMessage(IMM32.@)
2903 * ( Undocumented, call internally and from user32.dll )
2905 BOOL WINAPI
ImmTranslateMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lKeyData
)
2907 InputContextData
*data
;
2908 HIMC imc
= ImmGetContext(hwnd
);
2914 static const DWORD list_count
= 10;
2916 TRACE("%p %x %x %x\n",hwnd
, msg
, (UINT
)wParam
, (UINT
)lKeyData
);
2923 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeToAsciiEx
)
2926 GetKeyboardState(state
);
2927 scancode
= lKeyData
>> 0x10 & 0xff;
2929 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list_count
* sizeof(TRANSMSG
) + sizeof(DWORD
));
2930 ((DWORD
*)list
)[0] = list_count
;
2932 if (data
->immKbd
->imeInfo
.fdwProperty
& IME_PROP_KBD_CHAR_FIRST
)
2936 if (!is_himc_ime_unicode(data
))
2937 ToAscii(data
->lastVK
, scancode
, state
, &chr
, 0);
2939 ToUnicodeEx(data
->lastVK
, scancode
, state
, &chr
, 1, 0, GetKeyboardLayout(0));
2940 uVirtKey
= MAKELONG(data
->lastVK
,chr
);
2943 uVirtKey
= data
->lastVK
;
2945 msg_count
= data
->immKbd
->pImeToAsciiEx(uVirtKey
, scancode
, state
, list
, 0, imc
);
2946 TRACE("%i messages generated\n",msg_count
);
2947 if (msg_count
&& msg_count
<= list_count
)
2950 LPTRANSMSG msgs
= (LPTRANSMSG
)((LPBYTE
)list
+ sizeof(DWORD
));
2952 for (i
= 0; i
< msg_count
; i
++)
2953 ImmInternalPostIMEMessage(data
, msgs
[i
].message
, msgs
[i
].wParam
, msgs
[i
].lParam
);
2955 else if (msg_count
> list_count
)
2956 ImmGenerateMessage(imc
);
2958 HeapFree(GetProcessHeap(),0,list
);
2960 data
->lastVK
= VK_PROCESSKEY
;
2962 return (msg_count
> 0);
2965 /***********************************************************************
2966 * ImmProcessKey(IMM32.@)
2967 * ( Undocumented, called from user32.dll )
2969 BOOL WINAPI
ImmProcessKey(HWND hwnd
, HKL hKL
, UINT vKey
, LPARAM lKeyData
, DWORD unknown
)
2971 InputContextData
*data
;
2972 HIMC imc
= ImmGetContext(hwnd
);
2975 TRACE("%p %p %x %x %x\n",hwnd
, hKL
, vKey
, (UINT
)lKeyData
, unknown
);
2982 /* Make sure we are inputting to the correct keyboard */
2983 if (data
->immKbd
->hkl
!= hKL
)
2985 ImmHkl
*new_hkl
= IMM_GetImmHkl(hKL
);
2988 data
->immKbd
->pImeSelect(imc
, FALSE
);
2989 data
->immKbd
->uSelected
--;
2990 data
->immKbd
= new_hkl
;
2991 data
->immKbd
->pImeSelect(imc
, TRUE
);
2992 data
->immKbd
->uSelected
++;
2998 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeProcessKey
)
3001 GetKeyboardState(state
);
3002 if (data
->immKbd
->pImeProcessKey(imc
, vKey
, lKeyData
, state
))
3004 data
->lastVK
= vKey
;
3008 data
->lastVK
= VK_PROCESSKEY
;
3012 /***********************************************************************
3013 * ImmDisableTextFrameService(IMM32.@)
3015 BOOL WINAPI
ImmDisableTextFrameService(DWORD idThread
)
3021 /***********************************************************************
3022 * ImmEnumInputContext(IMM32.@)
3025 BOOL WINAPI
ImmEnumInputContext(DWORD idThread
, IMCENUMPROC lpfn
, LPARAM lParam
)
3031 /***********************************************************************
3032 * ImmGetHotKey(IMM32.@)
3035 BOOL WINAPI
ImmGetHotKey(DWORD hotkey
, UINT
*modifiers
, UINT
*key
, HKL hkl
)
3037 FIXME("%x, %p, %p, %p: stub\n", hotkey
, modifiers
, key
, hkl
);