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
{
102 static struct list ImmHklList
= LIST_INIT(ImmHklList
);
103 static struct list ImmThreadDataList
= LIST_INIT(ImmThreadDataList
);
105 static const WCHAR szwWineIMCProperty
[] = {'W','i','n','e','I','m','m','H','I','M','C','P','r','o','p','e','r','t','y',0};
107 static const WCHAR szImeFileW
[] = {'I','m','e',' ','F','i','l','e',0};
108 static const WCHAR szLayoutTextW
[] = {'L','a','y','o','u','t',' ','T','e','x','t',0};
109 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};
111 static const WCHAR szwIME
[] = {'I','M','E',0};
112 static const WCHAR szwDefaultIME
[] = {'D','e','f','a','u','l','t',' ','I','M','E',0};
114 static CRITICAL_SECTION threaddata_cs
;
115 static CRITICAL_SECTION_DEBUG critsect_debug
=
117 0, 0, &threaddata_cs
,
118 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
119 0, 0, { (DWORD_PTR
)(__FILE__
": threaddata_cs") }
121 static CRITICAL_SECTION threaddata_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
122 static BOOL disable_ime
;
124 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
125 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
127 static BOOL
IMM_DestroyContext(HIMC hIMC
);
128 static InputContextData
* get_imc_data(HIMC hIMC
);
130 static inline WCHAR
*strdupAtoW( const char *str
)
135 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
136 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
137 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
142 static inline CHAR
*strdupWtoA( const WCHAR
*str
)
147 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
148 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
149 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
154 static DWORD
convert_candidatelist_WtoA(
155 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
159 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
160 if ( lpDst
&& dwBufLen
> 0 )
163 lpDst
->dwOffset
[0] = ret
;
166 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
168 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
170 if ( lpDst
&& dwBufLen
> 0 )
172 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
174 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1,
175 (LPSTR
)dest
, dwBufLen
, NULL
, NULL
);
177 if ( i
+ 1 < lpSrc
->dwCount
)
178 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(char);
179 dwBufLen
-= len
* sizeof(char);
182 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1, NULL
, 0, NULL
, NULL
);
184 ret
+= len
* sizeof(char);
193 static DWORD
convert_candidatelist_AtoW(
194 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
198 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
199 if ( lpDst
&& dwBufLen
> 0 )
202 lpDst
->dwOffset
[0] = ret
;
205 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
207 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
209 if ( lpDst
&& dwBufLen
> 0 )
211 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
213 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1,
214 (LPWSTR
)dest
, dwBufLen
);
216 if ( i
+ 1 < lpSrc
->dwCount
)
217 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(WCHAR
);
218 dwBufLen
-= len
* sizeof(WCHAR
);
221 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, NULL
, 0);
223 ret
+= len
* sizeof(WCHAR
);
232 static IMMThreadData
*IMM_GetThreadData(HWND hwnd
, DWORD thread
)
239 if (!(thread
= GetWindowThreadProcessId(hwnd
, &process
))) return NULL
;
240 if (process
!= GetCurrentProcessId()) return NULL
;
244 HANDLE h
= OpenThread(THREAD_QUERY_INFORMATION
, FALSE
, thread
);
246 process
= GetProcessIdOfThread(h
);
248 if (process
!= GetCurrentProcessId()) return NULL
;
251 thread
= GetCurrentThreadId();
253 EnterCriticalSection(&threaddata_cs
);
254 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
255 if (data
->threadID
== thread
) return data
;
257 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
));
258 data
->threadID
= thread
;
259 list_add_head(&ImmThreadDataList
,&data
->entry
);
260 TRACE("Thread Data Created (%x)\n",thread
);
264 static BOOL
IMM_IsDefaultContext(HIMC imc
)
266 InputContextData
*data
= get_imc_data(imc
);
271 return data
->threadDefault
;
274 static void IMM_FreeThreadData(void)
278 EnterCriticalSection(&threaddata_cs
);
279 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
281 if (data
->threadID
== GetCurrentThreadId())
283 list_remove(&data
->entry
);
284 LeaveCriticalSection(&threaddata_cs
);
285 IMM_DestroyContext(data
->defaultContext
);
286 HeapFree(GetProcessHeap(),0,data
);
287 TRACE("Thread Data Destroyed\n");
291 LeaveCriticalSection(&threaddata_cs
);
294 static HMODULE
load_graphics_driver(void)
296 static const WCHAR display_device_guid_propW
[] = {
297 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
298 'd','e','v','i','c','e','_','g','u','i','d',0 };
299 static const WCHAR key_pathW
[] = {
300 'S','y','s','t','e','m','\\',
301 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
302 'C','o','n','t','r','o','l','\\',
303 'V','i','d','e','o','\\','{',0};
304 static const WCHAR displayW
[] = {'}','\\','0','0','0','0',0};
305 static const WCHAR driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
310 WCHAR path
[MAX_PATH
];
311 WCHAR key
[(sizeof(key_pathW
) + sizeof(displayW
)) / sizeof(WCHAR
) + 40];
312 UINT guid_atom
= HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW
));
314 if (!guid_atom
) return 0;
315 memcpy( key
, key_pathW
, sizeof(key_pathW
) );
316 if (!GlobalGetAtomNameW( guid_atom
, key
+ strlenW(key
), 40 )) return 0;
317 strcatW( key
, displayW
);
318 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, key
, &hkey
)) return 0;
320 if (!RegQueryValueExW( hkey
, driverW
, NULL
, NULL
, (BYTE
*)path
, &size
)) ret
= LoadLibraryW( path
);
322 TRACE( "%s %p\n", debugstr_w(path
), ret
);
326 /* ImmHkl loading and freeing */
327 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
328 static ImmHkl
*IMM_GetImmHkl(HKL hkl
)
331 WCHAR filename
[MAX_PATH
];
333 TRACE("Seeking ime for keyboard %p\n",hkl
);
335 LIST_FOR_EACH_ENTRY(ptr
, &ImmHklList
, ImmHkl
, entry
)
340 /* not found... create it */
342 ptr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ImmHkl
));
345 if (ImmGetIMEFileNameW(hkl
, filename
, MAX_PATH
)) ptr
->hIME
= LoadLibraryW(filename
);
346 if (!ptr
->hIME
) ptr
->hIME
= load_graphics_driver();
349 LOAD_FUNCPTR(ImeInquire
);
350 if (!ptr
->pImeInquire
|| !ptr
->pImeInquire(&ptr
->imeInfo
, ptr
->imeClassName
, NULL
))
352 FreeLibrary(ptr
->hIME
);
357 LOAD_FUNCPTR(ImeDestroy
);
358 LOAD_FUNCPTR(ImeSelect
);
359 if (!ptr
->pImeSelect
|| !ptr
->pImeDestroy
)
361 FreeLibrary(ptr
->hIME
);
366 LOAD_FUNCPTR(ImeConfigure
);
367 LOAD_FUNCPTR(ImeEscape
);
368 LOAD_FUNCPTR(ImeSetActiveContext
);
369 LOAD_FUNCPTR(ImeToAsciiEx
);
370 LOAD_FUNCPTR(NotifyIME
);
371 LOAD_FUNCPTR(ImeRegisterWord
);
372 LOAD_FUNCPTR(ImeUnregisterWord
);
373 LOAD_FUNCPTR(ImeEnumRegisterWord
);
374 LOAD_FUNCPTR(ImeSetCompositionString
);
375 LOAD_FUNCPTR(ImeConversionList
);
376 LOAD_FUNCPTR(ImeProcessKey
);
377 LOAD_FUNCPTR(ImeGetRegisterWordStyle
);
378 LOAD_FUNCPTR(ImeGetImeMenuItems
);
379 /* make sure our classname is WCHAR */
380 if (!is_kbd_ime_unicode(ptr
))
383 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ptr
->imeClassName
,
385 lstrcpyW(ptr
->imeClassName
, bufW
);
390 list_add_head(&ImmHklList
,&ptr
->entry
);
396 HWND WINAPI
__wine_get_ui_window(HKL hkl
)
398 ImmHkl
*immHkl
= IMM_GetImmHkl(hkl
);
399 return immHkl
->UIWnd
;
402 static void IMM_FreeAllImmHkl(void)
404 ImmHkl
*ptr
,*cursor2
;
406 LIST_FOR_EACH_ENTRY_SAFE(ptr
, cursor2
, &ImmHklList
, ImmHkl
, entry
)
408 list_remove(&ptr
->entry
);
412 FreeLibrary(ptr
->hIME
);
415 DestroyWindow(ptr
->UIWnd
);
416 HeapFree(GetProcessHeap(),0,ptr
);
420 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
422 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
425 case DLL_PROCESS_ATTACH
:
426 if (!User32InitializeImmEntryTable(IMM_INIT_MAGIC
))
431 case DLL_THREAD_ATTACH
:
433 case DLL_THREAD_DETACH
:
434 IMM_FreeThreadData();
436 case DLL_PROCESS_DETACH
:
437 if (lpReserved
) break;
438 IMM_FreeThreadData();
445 /* for posting messages as the IME */
446 static void ImmInternalPostIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
448 HWND target
= GetFocus();
450 PostMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
452 PostMessageW(target
, msg
, wParam
, lParam
);
455 /* for sending messages as the IME */
456 static void ImmInternalSendIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
458 HWND target
= GetFocus();
460 SendMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
462 SendMessageW(target
, msg
, wParam
, lParam
);
465 static LRESULT
ImmInternalSendIMENotify(InputContextData
*data
, WPARAM notify
, LPARAM lParam
)
469 target
= data
->IMC
.hWnd
;
470 if (!target
) target
= GetFocus();
473 return SendMessageW(target
, WM_IME_NOTIFY
, notify
, lParam
);
478 static HIMCC
ImmCreateBlankCompStr(void)
481 LPCOMPOSITIONSTRING ptr
;
482 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
483 ptr
= ImmLockIMCC(rc
);
484 memset(ptr
,0,sizeof(COMPOSITIONSTRING
));
485 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
490 static InputContextData
* get_imc_data(HIMC hIMC
)
492 InputContextData
*data
= hIMC
;
497 if(IsBadReadPtr(data
, sizeof(InputContextData
)) || data
->magic
!= WINE_IMC_VALID_MAGIC
)
499 SetLastError(ERROR_INVALID_HANDLE
);
505 static HIMC
get_default_context( HWND hwnd
)
508 IMMThreadData
* thread_data
= IMM_GetThreadData( hwnd
, 0 );
510 if (!thread_data
) return 0;
512 if (thread_data
->defaultContext
)
514 ret
= thread_data
->defaultContext
;
515 LeaveCriticalSection(&threaddata_cs
);
519 /* can't create a default context in another thread */
520 if (thread_data
->threadID
!= GetCurrentThreadId())
522 LeaveCriticalSection(&threaddata_cs
);
526 LeaveCriticalSection(&threaddata_cs
);
528 ret
= ImmCreateContext();
530 ((InputContextData
*)ret
)->threadDefault
= TRUE
;
532 /* thread_data is in the current thread so we can assume it's still valid */
533 EnterCriticalSection(&threaddata_cs
);
535 if (thread_data
->defaultContext
) /* someone beat us */
537 IMM_DestroyContext( ret
);
538 ret
= thread_data
->defaultContext
;
540 else thread_data
->defaultContext
= ret
;
542 LeaveCriticalSection(&threaddata_cs
);
546 static BOOL
IMM_IsCrossThreadAccess(HWND hWnd
, HIMC hIMC
)
548 InputContextData
*data
;
552 DWORD thread
= GetWindowThreadProcessId(hWnd
, NULL
);
553 if (thread
!= GetCurrentThreadId()) return TRUE
;
555 data
= get_imc_data(hIMC
);
556 if (data
&& data
->threadID
!= GetCurrentThreadId())
562 /***********************************************************************
563 * ImmAssociateContext (IMM32.@)
565 HIMC WINAPI
ImmAssociateContext(HWND hWnd
, HIMC hIMC
)
568 InputContextData
*data
= get_imc_data(hIMC
);
570 TRACE("(%p, %p):\n", hWnd
, hIMC
);
576 * If already associated just return
578 if (hIMC
&& data
->IMC
.hWnd
== hWnd
)
581 if (hIMC
&& IMM_IsCrossThreadAccess(hWnd
, hIMC
))
586 HIMC defaultContext
= get_default_context( hWnd
);
587 old
= RemovePropW(hWnd
,szwWineIMCProperty
);
590 old
= defaultContext
;
591 else if (old
== (HIMC
)-1)
594 if (hIMC
!= defaultContext
)
596 if (hIMC
== NULL
) /* Meaning disable imm for that window*/
597 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)-1);
599 SetPropW(hWnd
,szwWineIMCProperty
,hIMC
);
604 InputContextData
*old_data
= old
;
605 if (old_data
->IMC
.hWnd
== hWnd
)
606 old_data
->IMC
.hWnd
= NULL
;
613 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, FALSE
, ISC_SHOWUIALL
);
614 data
->IMC
.hWnd
= hWnd
;
615 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, TRUE
, ISC_SHOWUIALL
);
622 * Helper function for ImmAssociateContextEx
624 static BOOL CALLBACK
_ImmAssociateContextExEnumProc(HWND hwnd
, LPARAM lParam
)
626 HIMC hImc
= (HIMC
)lParam
;
627 ImmAssociateContext(hwnd
,hImc
);
631 /***********************************************************************
632 * ImmAssociateContextEx (IMM32.@)
634 BOOL WINAPI
ImmAssociateContextEx(HWND hWnd
, HIMC hIMC
, DWORD dwFlags
)
636 TRACE("(%p, %p, 0x%x):\n", hWnd
, hIMC
, dwFlags
);
644 ImmAssociateContext(hWnd
,hIMC
);
648 HIMC defaultContext
= get_default_context( hWnd
);
649 if (!defaultContext
) return FALSE
;
650 ImmAssociateContext(hWnd
,defaultContext
);
653 case IACE_IGNORENOCONTEXT
:
654 if (GetPropW(hWnd
,szwWineIMCProperty
))
655 ImmAssociateContext(hWnd
,hIMC
);
658 EnumChildWindows(hWnd
,_ImmAssociateContextExEnumProc
,(LPARAM
)hIMC
);
661 FIXME("Unknown dwFlags 0x%x\n",dwFlags
);
666 /***********************************************************************
667 * ImmConfigureIMEA (IMM32.@)
669 BOOL WINAPI
ImmConfigureIMEA(
670 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
672 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
674 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
676 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
679 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
681 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| !is_kbd_ime_unicode(immHkl
))
682 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
686 REGISTERWORDA
*rwa
= lpData
;
689 rww
.lpReading
= strdupAtoW(rwa
->lpReading
);
690 rww
.lpWord
= strdupAtoW(rwa
->lpWord
);
691 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rww
);
692 HeapFree(GetProcessHeap(),0,rww
.lpReading
);
693 HeapFree(GetProcessHeap(),0,rww
.lpWord
);
701 /***********************************************************************
702 * ImmConfigureIMEW (IMM32.@)
704 BOOL WINAPI
ImmConfigureIMEW(
705 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
707 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
709 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
711 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
714 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
716 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| is_kbd_ime_unicode(immHkl
))
717 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
720 REGISTERWORDW
*rww
= lpData
;
724 rwa
.lpReading
= strdupWtoA(rww
->lpReading
);
725 rwa
.lpWord
= strdupWtoA(rww
->lpWord
);
726 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rwa
);
727 HeapFree(GetProcessHeap(),0,rwa
.lpReading
);
728 HeapFree(GetProcessHeap(),0,rwa
.lpWord
);
736 /***********************************************************************
737 * ImmCreateContext (IMM32.@)
739 HIMC WINAPI
ImmCreateContext(void)
741 InputContextData
*new_context
;
746 new_context
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputContextData
));
749 new_context
->immKbd
= IMM_GetImmHkl(GetKeyboardLayout(0));
751 if (!new_context
->immKbd
->hIME
)
753 TRACE("IME dll could not be loaded\n");
754 HeapFree(GetProcessHeap(),0,new_context
);
758 /* the HIMCCs are never NULL */
759 new_context
->IMC
.hCompStr
= ImmCreateBlankCompStr();
760 new_context
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
761 new_context
->IMC
.hCandInfo
= ImmCreateIMCC(sizeof(CANDIDATEINFO
));
762 ci
= ImmLockIMCC(new_context
->IMC
.hCandInfo
);
763 memset(ci
,0,sizeof(CANDIDATEINFO
));
764 ci
->dwSize
= sizeof(CANDIDATEINFO
);
765 ImmUnlockIMCC(new_context
->IMC
.hCandInfo
);
766 new_context
->IMC
.hGuideLine
= ImmCreateIMCC(sizeof(GUIDELINE
));
767 gl
= ImmLockIMCC(new_context
->IMC
.hGuideLine
);
768 memset(gl
,0,sizeof(GUIDELINE
));
769 gl
->dwSize
= sizeof(GUIDELINE
);
770 ImmUnlockIMCC(new_context
->IMC
.hGuideLine
);
772 for (i
= 0; i
< sizeof(new_context
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
); i
++)
773 new_context
->IMC
.cfCandForm
[i
].dwIndex
= ~0u;
775 /* Initialize the IME Private */
776 new_context
->IMC
.hPrivate
= ImmCreateIMCC(new_context
->immKbd
->imeInfo
.dwPrivateDataSize
);
778 new_context
->IMC
.fdwConversion
= new_context
->immKbd
->imeInfo
.fdwConversionCaps
;
779 new_context
->IMC
.fdwSentence
= new_context
->immKbd
->imeInfo
.fdwSentenceCaps
;
781 if (!new_context
->immKbd
->pImeSelect(new_context
, TRUE
))
783 TRACE("Selection of IME failed\n");
784 IMM_DestroyContext(new_context
);
787 new_context
->threadID
= GetCurrentThreadId();
788 SendMessageW(GetFocus(), WM_IME_SELECT
, TRUE
, (LPARAM
)new_context
->immKbd
);
790 new_context
->immKbd
->uSelected
++;
791 TRACE("Created context %p\n",new_context
);
793 new_context
->magic
= WINE_IMC_VALID_MAGIC
;
797 static BOOL
IMM_DestroyContext(HIMC hIMC
)
799 InputContextData
*data
= get_imc_data(hIMC
);
801 TRACE("Destroying %p\n",hIMC
);
806 data
->immKbd
->uSelected
--;
807 data
->immKbd
->pImeSelect(hIMC
, FALSE
);
808 SendMessageW(data
->IMC
.hWnd
, WM_IME_SELECT
, FALSE
, (LPARAM
)data
->immKbd
);
810 ImmDestroyIMCC(data
->IMC
.hCompStr
);
811 ImmDestroyIMCC(data
->IMC
.hCandInfo
);
812 ImmDestroyIMCC(data
->IMC
.hGuideLine
);
813 ImmDestroyIMCC(data
->IMC
.hPrivate
);
814 ImmDestroyIMCC(data
->IMC
.hMsgBuf
);
817 HeapFree(GetProcessHeap(),0,data
);
822 /***********************************************************************
823 * ImmDestroyContext (IMM32.@)
825 BOOL WINAPI
ImmDestroyContext(HIMC hIMC
)
827 if (!IMM_IsDefaultContext(hIMC
) && !IMM_IsCrossThreadAccess(NULL
, hIMC
))
828 return IMM_DestroyContext(hIMC
);
833 /***********************************************************************
834 * ImmDisableIME (IMM32.@)
836 BOOL WINAPI
ImmDisableIME(DWORD idThread
)
838 if (idThread
== (DWORD
)-1)
841 IMMThreadData
*thread_data
= IMM_GetThreadData(NULL
, idThread
);
842 if (!thread_data
) return FALSE
;
843 thread_data
->disableIME
= TRUE
;
844 LeaveCriticalSection(&threaddata_cs
);
849 /***********************************************************************
850 * ImmEnumRegisterWordA (IMM32.@)
852 UINT WINAPI
ImmEnumRegisterWordA(
853 HKL hKL
, REGISTERWORDENUMPROCA lpfnEnumProc
,
854 LPCSTR lpszReading
, DWORD dwStyle
,
855 LPCSTR lpszRegister
, LPVOID lpData
)
857 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
858 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
859 debugstr_a(lpszReading
), dwStyle
, debugstr_a(lpszRegister
), lpData
);
860 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
862 if (!is_kbd_ime_unicode(immHkl
))
863 return immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
864 (LPCWSTR
)lpszReading
, dwStyle
, (LPCWSTR
)lpszRegister
, lpData
);
867 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
868 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
871 rc
= immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
872 lpszwReading
, dwStyle
, lpszwRegister
,
875 HeapFree(GetProcessHeap(),0,lpszwReading
);
876 HeapFree(GetProcessHeap(),0,lpszwRegister
);
884 /***********************************************************************
885 * ImmEnumRegisterWordW (IMM32.@)
887 UINT WINAPI
ImmEnumRegisterWordW(
888 HKL hKL
, REGISTERWORDENUMPROCW lpfnEnumProc
,
889 LPCWSTR lpszReading
, DWORD dwStyle
,
890 LPCWSTR lpszRegister
, LPVOID lpData
)
892 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
893 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
894 debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
), lpData
);
895 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
897 if (is_kbd_ime_unicode(immHkl
))
898 return immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, lpszReading
, dwStyle
,
899 lpszRegister
, lpData
);
902 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
903 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
906 rc
= immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, (LPCWSTR
)lpszaReading
,
907 dwStyle
, (LPCWSTR
)lpszaRegister
, lpData
);
909 HeapFree(GetProcessHeap(),0,lpszaReading
);
910 HeapFree(GetProcessHeap(),0,lpszaRegister
);
918 static inline BOOL
EscapeRequiresWA(UINT uEscape
)
920 if (uEscape
== IME_ESC_GET_EUDC_DICTIONARY
||
921 uEscape
== IME_ESC_SET_EUDC_DICTIONARY
||
922 uEscape
== IME_ESC_IME_NAME
||
923 uEscape
== IME_ESC_GETHELPFILENAME
)
928 /***********************************************************************
929 * ImmEscapeA (IMM32.@)
931 LRESULT WINAPI
ImmEscapeA(
933 UINT uEscape
, LPVOID lpData
)
935 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
936 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
938 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
940 if (!EscapeRequiresWA(uEscape
) || !is_kbd_ime_unicode(immHkl
))
941 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
944 WCHAR buffer
[81]; /* largest required buffer should be 80 */
946 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
948 MultiByteToWideChar(CP_ACP
,0,lpData
,-1,buffer
,81);
949 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
953 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
954 WideCharToMultiByte(CP_ACP
,0,buffer
,-1,lpData
,80, NULL
, NULL
);
963 /***********************************************************************
964 * ImmEscapeW (IMM32.@)
966 LRESULT WINAPI
ImmEscapeW(
968 UINT uEscape
, LPVOID lpData
)
970 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
971 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
973 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
975 if (!EscapeRequiresWA(uEscape
) || is_kbd_ime_unicode(immHkl
))
976 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
979 CHAR buffer
[81]; /* largest required buffer should be 80 */
981 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
983 WideCharToMultiByte(CP_ACP
,0,lpData
,-1,buffer
,81, NULL
, NULL
);
984 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
988 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
989 MultiByteToWideChar(CP_ACP
,0,buffer
,-1,lpData
,80);
998 /***********************************************************************
999 * ImmGetCandidateListA (IMM32.@)
1001 DWORD WINAPI
ImmGetCandidateListA(
1002 HIMC hIMC
, DWORD dwIndex
,
1003 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1005 InputContextData
*data
= get_imc_data(hIMC
);
1006 LPCANDIDATEINFO candinfo
;
1007 LPCANDIDATELIST candlist
;
1010 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1012 if (!data
|| !data
->IMC
.hCandInfo
)
1015 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1016 if ( dwIndex
>= candinfo
->dwCount
||
1017 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1020 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1021 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1024 if ( !is_himc_ime_unicode(data
) )
1026 ret
= candlist
->dwSize
;
1027 if ( lpCandList
&& dwBufLen
>= ret
)
1028 memcpy(lpCandList
, candlist
, ret
);
1031 ret
= convert_candidatelist_WtoA( candlist
, lpCandList
, dwBufLen
);
1034 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1038 /***********************************************************************
1039 * ImmGetCandidateListCountA (IMM32.@)
1041 DWORD WINAPI
ImmGetCandidateListCountA(
1042 HIMC hIMC
, LPDWORD lpdwListCount
)
1044 InputContextData
*data
= get_imc_data(hIMC
);
1045 LPCANDIDATEINFO candinfo
;
1048 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1050 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1053 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1055 *lpdwListCount
= count
= candinfo
->dwCount
;
1057 if ( !is_himc_ime_unicode(data
) )
1058 ret
= candinfo
->dwSize
;
1061 ret
= sizeof(CANDIDATEINFO
);
1063 ret
+= ImmGetCandidateListA(hIMC
, count
, NULL
, 0);
1066 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1070 /***********************************************************************
1071 * ImmGetCandidateListCountW (IMM32.@)
1073 DWORD WINAPI
ImmGetCandidateListCountW(
1074 HIMC hIMC
, LPDWORD lpdwListCount
)
1076 InputContextData
*data
= get_imc_data(hIMC
);
1077 LPCANDIDATEINFO candinfo
;
1080 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1082 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1085 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1087 *lpdwListCount
= count
= candinfo
->dwCount
;
1089 if ( is_himc_ime_unicode(data
) )
1090 ret
= candinfo
->dwSize
;
1093 ret
= sizeof(CANDIDATEINFO
);
1095 ret
+= ImmGetCandidateListW(hIMC
, count
, NULL
, 0);
1098 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1102 /***********************************************************************
1103 * ImmGetCandidateListW (IMM32.@)
1105 DWORD WINAPI
ImmGetCandidateListW(
1106 HIMC hIMC
, DWORD dwIndex
,
1107 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1109 InputContextData
*data
= get_imc_data(hIMC
);
1110 LPCANDIDATEINFO candinfo
;
1111 LPCANDIDATELIST candlist
;
1114 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1116 if (!data
|| !data
->IMC
.hCandInfo
)
1119 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1120 if ( dwIndex
>= candinfo
->dwCount
||
1121 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1124 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1125 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1128 if ( is_himc_ime_unicode(data
) )
1130 ret
= candlist
->dwSize
;
1131 if ( lpCandList
&& dwBufLen
>= ret
)
1132 memcpy(lpCandList
, candlist
, ret
);
1135 ret
= convert_candidatelist_AtoW( candlist
, lpCandList
, dwBufLen
);
1138 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1142 /***********************************************************************
1143 * ImmGetCandidateWindow (IMM32.@)
1145 BOOL WINAPI
ImmGetCandidateWindow(
1146 HIMC hIMC
, DWORD dwIndex
, LPCANDIDATEFORM lpCandidate
)
1148 InputContextData
*data
= get_imc_data(hIMC
);
1150 TRACE("%p, %d, %p\n", hIMC
, dwIndex
, lpCandidate
);
1152 if (!data
|| !lpCandidate
)
1155 if ( dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
1158 if (data
->IMC
.cfCandForm
[dwIndex
].dwIndex
!= dwIndex
)
1161 *lpCandidate
= data
->IMC
.cfCandForm
[dwIndex
];
1166 /***********************************************************************
1167 * ImmGetCompositionFontA (IMM32.@)
1169 BOOL WINAPI
ImmGetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
1174 TRACE("(%p, %p):\n", hIMC
, lplf
);
1176 rc
= ImmGetCompositionFontW(hIMC
,&lfW
);
1180 memcpy(lplf
,&lfW
,sizeof(LOGFONTA
));
1181 WideCharToMultiByte(CP_ACP
, 0, lfW
.lfFaceName
, -1, lplf
->lfFaceName
,
1182 LF_FACESIZE
, NULL
, NULL
);
1186 /***********************************************************************
1187 * ImmGetCompositionFontW (IMM32.@)
1189 BOOL WINAPI
ImmGetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
1191 InputContextData
*data
= get_imc_data(hIMC
);
1193 TRACE("(%p, %p):\n", hIMC
, lplf
);
1198 *lplf
= data
->IMC
.lfFont
.W
;
1204 /* Helpers for the GetCompositionString functions */
1206 static INT
CopyCompStringIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE target
, INT tlen
,
1211 if (is_himc_ime_unicode(data
) && !unicode
)
1212 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)source
, slen
, (LPSTR
)target
, tlen
, NULL
, NULL
);
1213 else if (!is_himc_ime_unicode(data
) && unicode
)
1214 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)source
, slen
, (LPWSTR
)target
, tlen
) * sizeof(WCHAR
);
1217 int dlen
= (unicode
)?sizeof(WCHAR
):sizeof(CHAR
);
1218 memcpy( target
, source
, min(slen
,tlen
)*dlen
);
1225 static INT
CopyCompAttrIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1226 LPBYTE target
, INT tlen
, BOOL unicode
)
1230 if (is_himc_ime_unicode(data
) && !unicode
)
1232 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, sslen
, NULL
, 0, NULL
, NULL
);
1235 const BYTE
*src
= source
;
1236 LPBYTE dst
= target
;
1237 int i
, j
= 0, k
= 0;
1241 for (i
= 0; i
< sslen
; ++i
)
1245 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)ssource
+ i
, 1,
1246 NULL
, 0, NULL
, NULL
);
1247 for (; len
> 0; --len
)
1260 else if (!is_himc_ime_unicode(data
) && unicode
)
1262 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, sslen
, NULL
, 0);
1265 const BYTE
*src
= source
;
1266 LPBYTE dst
= target
;
1271 for (i
= 0; i
< sslen
; ++i
)
1273 if (IsDBCSLeadByte(((LPSTR
)ssource
)[i
]))
1286 memcpy( target
, source
, min(slen
,tlen
));
1293 static INT
CopyCompClauseIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
,
1294 LPBYTE target
, INT tlen
, BOOL unicode
)
1298 if (is_himc_ime_unicode(data
) && !unicode
)
1306 tlen
/= sizeof (DWORD
);
1307 for (i
= 0; i
< tlen
; ++i
)
1309 ((DWORD
*)target
)[i
] = WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
,
1310 ((DWORD
*)source
)[i
],
1314 rc
= sizeof (DWORD
) * i
;
1319 else if (!is_himc_ime_unicode(data
) && unicode
)
1327 tlen
/= sizeof (DWORD
);
1328 for (i
= 0; i
< tlen
; ++i
)
1330 ((DWORD
*)target
)[i
] = MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
,
1331 ((DWORD
*)source
)[i
],
1334 rc
= sizeof (DWORD
) * i
;
1341 memcpy( target
, source
, min(slen
,tlen
));
1348 static INT
CopyCompOffsetIMEtoClient(InputContextData
*data
, DWORD offset
, LPBYTE ssource
, BOOL unicode
)
1352 if (is_himc_ime_unicode(data
) && !unicode
)
1354 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, offset
, NULL
, 0, NULL
, NULL
);
1356 else if (!is_himc_ime_unicode(data
) && unicode
)
1358 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, offset
, NULL
, 0);
1366 static LONG
ImmGetCompositionStringT( HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
,
1367 DWORD dwBufLen
, BOOL unicode
)
1370 InputContextData
*data
= get_imc_data(hIMC
);
1371 LPCOMPOSITIONSTRING compstr
;
1374 TRACE("(%p, 0x%x, %p, %d)\n", hIMC
, dwIndex
, lpBuf
, dwBufLen
);
1379 if (!data
->IMC
.hCompStr
)
1382 compdata
= ImmLockIMCC(data
->IMC
.hCompStr
);
1383 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1388 TRACE("GCS_RESULTSTR\n");
1389 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
, lpBuf
, dwBufLen
, unicode
);
1392 TRACE("GCS_COMPSTR\n");
1393 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
, lpBuf
, dwBufLen
, unicode
);
1396 TRACE("GCS_COMPATTR\n");
1397 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompAttrOffset
, compstr
->dwCompAttrLen
,
1398 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1399 lpBuf
, dwBufLen
, unicode
);
1401 case GCS_COMPCLAUSE
:
1402 TRACE("GCS_COMPCLAUSE\n");
1403 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompClauseOffset
,compstr
->dwCompClauseLen
,
1404 compdata
+ compstr
->dwCompStrOffset
,
1405 lpBuf
, dwBufLen
, unicode
);
1407 case GCS_RESULTCLAUSE
:
1408 TRACE("GCS_RESULTCLAUSE\n");
1409 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultClauseOffset
,compstr
->dwResultClauseLen
,
1410 compdata
+ compstr
->dwResultStrOffset
,
1411 lpBuf
, dwBufLen
, unicode
);
1413 case GCS_RESULTREADSTR
:
1414 TRACE("GCS_RESULTREADSTR\n");
1415 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultReadStrOffset
, compstr
->dwResultReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1417 case GCS_RESULTREADCLAUSE
:
1418 TRACE("GCS_RESULTREADCLAUSE\n");
1419 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultReadClauseOffset
,compstr
->dwResultReadClauseLen
,
1420 compdata
+ compstr
->dwResultStrOffset
,
1421 lpBuf
, dwBufLen
, unicode
);
1423 case GCS_COMPREADSTR
:
1424 TRACE("GCS_COMPREADSTR\n");
1425 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1427 case GCS_COMPREADATTR
:
1428 TRACE("GCS_COMPREADATTR\n");
1429 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompReadAttrOffset
, compstr
->dwCompReadAttrLen
,
1430 compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
,
1431 lpBuf
, dwBufLen
, unicode
);
1433 case GCS_COMPREADCLAUSE
:
1434 TRACE("GCS_COMPREADCLAUSE\n");
1435 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompReadClauseOffset
,compstr
->dwCompReadClauseLen
,
1436 compdata
+ compstr
->dwCompStrOffset
,
1437 lpBuf
, dwBufLen
, unicode
);
1440 TRACE("GCS_CURSORPOS\n");
1441 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwCursorPos
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1443 case GCS_DELTASTART
:
1444 TRACE("GCS_DELTASTART\n");
1445 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwDeltaStart
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1448 FIXME("Unhandled index 0x%x\n",dwIndex
);
1452 ImmUnlockIMCC(data
->IMC
.hCompStr
);
1457 /***********************************************************************
1458 * ImmGetCompositionStringA (IMM32.@)
1460 LONG WINAPI
ImmGetCompositionStringA(
1461 HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
, DWORD dwBufLen
)
1463 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, FALSE
);
1467 /***********************************************************************
1468 * ImmGetCompositionStringW (IMM32.@)
1470 LONG WINAPI
ImmGetCompositionStringW(
1471 HIMC hIMC
, DWORD dwIndex
,
1472 LPVOID lpBuf
, DWORD dwBufLen
)
1474 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, TRUE
);
1477 /***********************************************************************
1478 * ImmGetCompositionWindow (IMM32.@)
1480 BOOL WINAPI
ImmGetCompositionWindow(HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
1482 InputContextData
*data
= get_imc_data(hIMC
);
1484 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
1489 *lpCompForm
= data
->IMC
.cfCompForm
;
1493 /***********************************************************************
1494 * ImmGetContext (IMM32.@)
1497 HIMC WINAPI
ImmGetContext(HWND hWnd
)
1501 TRACE("%p\n", hWnd
);
1503 if (!IsWindow(hWnd
))
1505 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1509 rc
= GetPropW(hWnd
,szwWineIMCProperty
);
1512 else if (rc
== NULL
)
1513 rc
= get_default_context( hWnd
);
1517 InputContextData
*data
= rc
;
1518 data
->IMC
.hWnd
= hWnd
;
1521 TRACE("returning %p\n", rc
);
1526 /***********************************************************************
1527 * ImmGetConversionListA (IMM32.@)
1529 DWORD WINAPI
ImmGetConversionListA(
1531 LPCSTR pSrc
, LPCANDIDATELIST lpDst
,
1532 DWORD dwBufLen
, UINT uFlag
)
1534 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1535 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_a(pSrc
), lpDst
,
1537 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1539 if (!is_kbd_ime_unicode(immHkl
))
1540 return immHkl
->pImeConversionList(hIMC
,(LPCWSTR
)pSrc
,lpDst
,dwBufLen
,uFlag
);
1543 LPCANDIDATELIST lpwDst
;
1545 LPWSTR pwSrc
= strdupAtoW(pSrc
);
1547 len
= immHkl
->pImeConversionList(hIMC
, pwSrc
, NULL
, 0, uFlag
);
1548 lpwDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1551 immHkl
->pImeConversionList(hIMC
, pwSrc
, lpwDst
, len
, uFlag
);
1552 ret
= convert_candidatelist_WtoA( lpwDst
, lpDst
, dwBufLen
);
1553 HeapFree(GetProcessHeap(), 0, lpwDst
);
1555 HeapFree(GetProcessHeap(), 0, pwSrc
);
1564 /***********************************************************************
1565 * ImmGetConversionListW (IMM32.@)
1567 DWORD WINAPI
ImmGetConversionListW(
1569 LPCWSTR pSrc
, LPCANDIDATELIST lpDst
,
1570 DWORD dwBufLen
, UINT uFlag
)
1572 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1573 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_w(pSrc
), lpDst
,
1575 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1577 if (is_kbd_ime_unicode(immHkl
))
1578 return immHkl
->pImeConversionList(hIMC
,pSrc
,lpDst
,dwBufLen
,uFlag
);
1581 LPCANDIDATELIST lpaDst
;
1583 LPSTR paSrc
= strdupWtoA(pSrc
);
1585 len
= immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, NULL
, 0, uFlag
);
1586 lpaDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1589 immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, lpaDst
, len
, uFlag
);
1590 ret
= convert_candidatelist_AtoW( lpaDst
, lpDst
, dwBufLen
);
1591 HeapFree(GetProcessHeap(), 0, lpaDst
);
1593 HeapFree(GetProcessHeap(), 0, paSrc
);
1602 /***********************************************************************
1603 * ImmGetConversionStatus (IMM32.@)
1605 BOOL WINAPI
ImmGetConversionStatus(
1606 HIMC hIMC
, LPDWORD lpfdwConversion
, LPDWORD lpfdwSentence
)
1608 InputContextData
*data
= get_imc_data(hIMC
);
1610 TRACE("%p %p %p\n", hIMC
, lpfdwConversion
, lpfdwSentence
);
1615 if (lpfdwConversion
)
1616 *lpfdwConversion
= data
->IMC
.fdwConversion
;
1618 *lpfdwSentence
= data
->IMC
.fdwSentence
;
1623 static BOOL
needs_ime_window(HWND hwnd
)
1627 if (GetClassNameW(hwnd
, classW
, sizeof(classW
)/sizeof(classW
[0])) &&
1628 !strcmpW(classW
, szwIME
))
1630 if (GetClassLongPtrW(hwnd
, GCL_STYLE
) & CS_IME
) return FALSE
;
1635 /***********************************************************************
1636 * __wine_register_window (IMM32.@)
1638 BOOL WINAPI
__wine_register_window(HWND hwnd
)
1641 IMMThreadData
*thread_data
;
1642 TRACE("(%p)\n", hwnd
);
1644 if (!needs_ime_window(hwnd
))
1647 thread_data
= IMM_GetThreadData(hwnd
, 0);
1651 if (thread_data
->disableIME
|| disable_ime
)
1653 TRACE("IME for this thread is disabled\n");
1654 LeaveCriticalSection(&threaddata_cs
);
1657 thread_data
->windowRefs
++;
1658 TRACE("windowRefs=%u, hwndDefault=%p\n",
1659 thread_data
->windowRefs
, thread_data
->hwndDefault
);
1661 /* Create default IME window */
1662 if (thread_data
->windowRefs
== 1)
1664 /* Do not create the window inside of a critical section */
1665 LeaveCriticalSection(&threaddata_cs
);
1666 new = CreateWindowExW( 0, szwIME
, szwDefaultIME
,
1667 WS_POPUP
| WS_DISABLED
| WS_CLIPSIBLINGS
,
1668 0, 0, 1, 1, 0, 0, 0, 0);
1669 /* thread_data is in the current thread so we can assume it's still valid */
1670 EnterCriticalSection(&threaddata_cs
);
1671 /* See if anyone beat us */
1672 if (thread_data
->hwndDefault
== NULL
)
1674 thread_data
->hwndDefault
= new;
1676 TRACE("Default is %p\n", thread_data
->hwndDefault
);
1680 LeaveCriticalSection(&threaddata_cs
);
1682 /* Clean up an unused new window outside of the critical section */
1688 /***********************************************************************
1689 * __wine_unregister_window (IMM32.@)
1691 void WINAPI
__wine_unregister_window(HWND hwnd
)
1693 HWND to_destroy
= 0;
1694 IMMThreadData
*thread_data
;
1695 TRACE("(%p)\n", hwnd
);
1697 thread_data
= IMM_GetThreadData(hwnd
, 0);
1698 if (!thread_data
) return;
1700 thread_data
->windowRefs
--;
1701 TRACE("windowRefs=%u, hwndDefault=%p\n",
1702 thread_data
->windowRefs
, thread_data
->hwndDefault
);
1704 /* Destroy default IME window */
1705 if (thread_data
->windowRefs
== 0 && thread_data
->hwndDefault
)
1707 to_destroy
= thread_data
->hwndDefault
;
1708 thread_data
->hwndDefault
= NULL
;
1710 LeaveCriticalSection(&threaddata_cs
);
1712 if (to_destroy
) DestroyWindow( to_destroy
);
1715 /***********************************************************************
1716 * ImmGetDefaultIMEWnd (IMM32.@)
1718 HWND WINAPI
ImmGetDefaultIMEWnd(HWND hWnd
)
1721 IMMThreadData
* thread_data
= IMM_GetThreadData(hWnd
, 0);
1724 ret
= thread_data
->hwndDefault
;
1725 LeaveCriticalSection(&threaddata_cs
);
1726 TRACE("Default is %p\n",ret
);
1730 /***********************************************************************
1731 * ImmGetDescriptionA (IMM32.@)
1733 UINT WINAPI
ImmGetDescriptionA(
1734 HKL hKL
, LPSTR lpszDescription
, UINT uBufLen
)
1739 TRACE("%p %p %d\n", hKL
, lpszDescription
, uBufLen
);
1741 /* find out how many characters in the unicode buffer */
1742 len
= ImmGetDescriptionW( hKL
, NULL
, 0 );
1746 /* allocate a buffer of that size */
1747 buf
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof (WCHAR
) );
1751 /* fetch the unicode buffer */
1752 len
= ImmGetDescriptionW( hKL
, buf
, len
+ 1 );
1754 /* convert it back to ASCII */
1755 len
= WideCharToMultiByte( CP_ACP
, 0, buf
, len
+ 1,
1756 lpszDescription
, uBufLen
, NULL
, NULL
);
1758 HeapFree( GetProcessHeap(), 0, buf
);
1766 /***********************************************************************
1767 * ImmGetDescriptionW (IMM32.@)
1769 UINT WINAPI
ImmGetDescriptionW(HKL hKL
, LPWSTR lpszDescription
, UINT uBufLen
)
1771 static const WCHAR name
[] = { 'W','i','n','e',' ','X','I','M',0 };
1773 FIXME("(%p, %p, %d): semi stub\n", hKL
, lpszDescription
, uBufLen
);
1776 if (!uBufLen
) return lstrlenW( name
);
1777 lstrcpynW( lpszDescription
, name
, uBufLen
);
1778 return lstrlenW( lpszDescription
);
1781 /***********************************************************************
1782 * ImmGetGuideLineA (IMM32.@)
1784 DWORD WINAPI
ImmGetGuideLineA(
1785 HIMC hIMC
, DWORD dwIndex
, LPSTR lpBuf
, DWORD dwBufLen
)
1787 FIXME("(%p, %d, %s, %d): stub\n",
1788 hIMC
, dwIndex
, debugstr_a(lpBuf
), dwBufLen
1790 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1794 /***********************************************************************
1795 * ImmGetGuideLineW (IMM32.@)
1797 DWORD WINAPI
ImmGetGuideLineW(HIMC hIMC
, DWORD dwIndex
, LPWSTR lpBuf
, DWORD dwBufLen
)
1799 FIXME("(%p, %d, %s, %d): stub\n",
1800 hIMC
, dwIndex
, debugstr_w(lpBuf
), dwBufLen
1802 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1806 /***********************************************************************
1807 * ImmGetIMEFileNameA (IMM32.@)
1809 UINT WINAPI
ImmGetIMEFileNameA( HKL hKL
, LPSTR lpszFileName
, UINT uBufLen
)
1812 UINT wBufLen
= uBufLen
;
1815 if (uBufLen
&& lpszFileName
)
1816 bufW
= HeapAlloc(GetProcessHeap(),0,uBufLen
* sizeof(WCHAR
));
1817 else /* We need this to get the number of byte required */
1819 bufW
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
* sizeof(WCHAR
));
1823 rc
= ImmGetIMEFileNameW(hKL
,bufW
,wBufLen
);
1827 if (uBufLen
&& lpszFileName
)
1828 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, lpszFileName
,
1829 uBufLen
, NULL
, NULL
);
1830 else /* get the length */
1831 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
,
1835 HeapFree(GetProcessHeap(),0,bufW
);
1839 /***********************************************************************
1840 * ImmGetIMEFileNameW (IMM32.@)
1842 UINT WINAPI
ImmGetIMEFileNameW(HKL hKL
, LPWSTR lpszFileName
, UINT uBufLen
)
1847 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1849 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hKL
);
1850 rc
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, regKey
, &hkey
);
1851 if (rc
!= ERROR_SUCCESS
)
1858 rc
= RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, NULL
, &length
);
1860 if (rc
!= ERROR_SUCCESS
)
1866 if (length
> uBufLen
* sizeof(WCHAR
) || !lpszFileName
)
1871 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1875 return length
/ sizeof(WCHAR
);
1878 RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, lpszFileName
, &length
);
1882 return length
/ sizeof(WCHAR
);
1885 /***********************************************************************
1886 * ImmGetOpenStatus (IMM32.@)
1888 BOOL WINAPI
ImmGetOpenStatus(HIMC hIMC
)
1890 InputContextData
*data
= get_imc_data(hIMC
);
1896 TRACE("(%p): semi-stub\n", hIMC
);
1899 FIXME("(%p): semi-stub\n", hIMC
);
1901 return data
->IMC
.fOpen
;
1904 /***********************************************************************
1905 * ImmGetProperty (IMM32.@)
1907 DWORD WINAPI
ImmGetProperty(HKL hKL
, DWORD fdwIndex
)
1912 TRACE("(%p, %d)\n", hKL
, fdwIndex
);
1913 kbd
= IMM_GetImmHkl(hKL
);
1915 if (kbd
&& kbd
->hIME
)
1919 case IGP_PROPERTY
: rc
= kbd
->imeInfo
.fdwProperty
; break;
1920 case IGP_CONVERSION
: rc
= kbd
->imeInfo
.fdwConversionCaps
; break;
1921 case IGP_SENTENCE
: rc
= kbd
->imeInfo
.fdwSentenceCaps
; break;
1922 case IGP_SETCOMPSTR
: rc
= kbd
->imeInfo
.fdwSCSCaps
; break;
1923 case IGP_SELECT
: rc
= kbd
->imeInfo
.fdwSelectCaps
; break;
1924 case IGP_GETIMEVERSION
: rc
= IMEVER_0400
; break;
1925 case IGP_UI
: rc
= 0; break;
1932 /***********************************************************************
1933 * ImmGetRegisterWordStyleA (IMM32.@)
1935 UINT WINAPI
ImmGetRegisterWordStyleA(
1936 HKL hKL
, UINT nItem
, LPSTYLEBUFA lpStyleBuf
)
1938 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1939 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1940 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1942 if (!is_kbd_ime_unicode(immHkl
))
1943 return immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)lpStyleBuf
);
1949 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,&sbw
);
1950 WideCharToMultiByte(CP_ACP
, 0, sbw
.szDescription
, -1,
1951 lpStyleBuf
->szDescription
, 32, NULL
, NULL
);
1952 lpStyleBuf
->dwStyle
= sbw
.dwStyle
;
1960 /***********************************************************************
1961 * ImmGetRegisterWordStyleW (IMM32.@)
1963 UINT WINAPI
ImmGetRegisterWordStyleW(
1964 HKL hKL
, UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
1966 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1967 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1968 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1970 if (is_kbd_ime_unicode(immHkl
))
1971 return immHkl
->pImeGetRegisterWordStyle(nItem
,lpStyleBuf
);
1977 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)&sba
);
1978 MultiByteToWideChar(CP_ACP
, 0, sba
.szDescription
, -1,
1979 lpStyleBuf
->szDescription
, 32);
1980 lpStyleBuf
->dwStyle
= sba
.dwStyle
;
1988 /***********************************************************************
1989 * ImmGetStatusWindowPos (IMM32.@)
1991 BOOL WINAPI
ImmGetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
1993 InputContextData
*data
= get_imc_data(hIMC
);
1995 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
1997 if (!data
|| !lpptPos
)
2000 *lpptPos
= data
->IMC
.ptStatusWndPos
;
2005 /***********************************************************************
2006 * ImmGetVirtualKey (IMM32.@)
2008 UINT WINAPI
ImmGetVirtualKey(HWND hWnd
)
2010 OSVERSIONINFOA version
;
2011 InputContextData
*data
= ImmGetContext( hWnd
);
2012 TRACE("%p\n", hWnd
);
2015 return data
->lastVK
;
2017 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
2018 GetVersionExA( &version
);
2019 switch(version
.dwPlatformId
)
2021 case VER_PLATFORM_WIN32_WINDOWS
:
2022 return VK_PROCESSKEY
;
2023 case VER_PLATFORM_WIN32_NT
:
2026 FIXME("%d not supported\n",version
.dwPlatformId
);
2027 return VK_PROCESSKEY
;
2031 /***********************************************************************
2032 * ImmInstallIMEA (IMM32.@)
2034 HKL WINAPI
ImmInstallIMEA(
2035 LPCSTR lpszIMEFileName
, LPCSTR lpszLayoutText
)
2037 LPWSTR lpszwIMEFileName
;
2038 LPWSTR lpszwLayoutText
;
2041 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName
),
2042 debugstr_a(lpszLayoutText
));
2044 lpszwIMEFileName
= strdupAtoW(lpszIMEFileName
);
2045 lpszwLayoutText
= strdupAtoW(lpszLayoutText
);
2047 hkl
= ImmInstallIMEW(lpszwIMEFileName
, lpszwLayoutText
);
2049 HeapFree(GetProcessHeap(),0,lpszwIMEFileName
);
2050 HeapFree(GetProcessHeap(),0,lpszwLayoutText
);
2054 /***********************************************************************
2055 * ImmInstallIMEW (IMM32.@)
2057 HKL WINAPI
ImmInstallIMEW(
2058 LPCWSTR lpszIMEFileName
, LPCWSTR lpszLayoutText
)
2060 INT lcid
= GetUserDefaultLCID();
2065 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
2067 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName
),
2068 debugstr_w(lpszLayoutText
));
2070 /* Start with 2. e001 will be blank and so default to the wine internal IME */
2073 while (count
< 0xfff)
2075 DWORD disposition
= 0;
2077 hkl
= (HKL
)MAKELPARAM( lcid
, 0xe000 | count
);
2078 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hkl
);
2080 rc
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, regKey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hkey
, &disposition
);
2081 if (rc
== ERROR_SUCCESS
&& disposition
== REG_CREATED_NEW_KEY
)
2083 else if (rc
== ERROR_SUCCESS
)
2091 WARN("Unable to find slot to install IME\n");
2095 if (rc
== ERROR_SUCCESS
)
2097 rc
= RegSetValueExW(hkey
, szImeFileW
, 0, REG_SZ
, (const BYTE
*)lpszIMEFileName
,
2098 (lstrlenW(lpszIMEFileName
) + 1) * sizeof(WCHAR
));
2099 if (rc
== ERROR_SUCCESS
)
2100 rc
= RegSetValueExW(hkey
, szLayoutTextW
, 0, REG_SZ
, (const BYTE
*)lpszLayoutText
,
2101 (lstrlenW(lpszLayoutText
) + 1) * sizeof(WCHAR
));
2107 WARN("Unable to set IME registry values\n");
2112 /***********************************************************************
2113 * ImmIsIME (IMM32.@)
2115 BOOL WINAPI
ImmIsIME(HKL hKL
)
2118 TRACE("(%p):\n", hKL
);
2119 ptr
= IMM_GetImmHkl(hKL
);
2120 return (ptr
&& ptr
->hIME
);
2123 /***********************************************************************
2124 * ImmIsUIMessageA (IMM32.@)
2126 BOOL WINAPI
ImmIsUIMessageA(
2127 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2129 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2130 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2131 (msg
== WM_IME_SETCONTEXT
) ||
2132 (msg
== WM_IME_NOTIFY
) ||
2133 (msg
== WM_IME_COMPOSITIONFULL
) ||
2134 (msg
== WM_IME_SELECT
) ||
2135 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2138 SendMessageA(hWndIME
, msg
, wParam
, lParam
);
2145 /***********************************************************************
2146 * ImmIsUIMessageW (IMM32.@)
2148 BOOL WINAPI
ImmIsUIMessageW(
2149 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2151 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2152 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2153 (msg
== WM_IME_SETCONTEXT
) ||
2154 (msg
== WM_IME_NOTIFY
) ||
2155 (msg
== WM_IME_COMPOSITIONFULL
) ||
2156 (msg
== WM_IME_SELECT
) ||
2157 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2160 SendMessageW(hWndIME
, msg
, wParam
, lParam
);
2167 /***********************************************************************
2168 * ImmNotifyIME (IMM32.@)
2170 BOOL WINAPI
ImmNotifyIME(
2171 HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
2173 InputContextData
*data
= get_imc_data(hIMC
);
2175 TRACE("(%p, %d, %d, %d)\n",
2176 hIMC
, dwAction
, dwIndex
, dwValue
);
2180 SetLastError(ERROR_SUCCESS
);
2184 if (!data
|| ! data
->immKbd
->pNotifyIME
)
2189 return data
->immKbd
->pNotifyIME(hIMC
,dwAction
,dwIndex
,dwValue
);
2192 /***********************************************************************
2193 * ImmRegisterWordA (IMM32.@)
2195 BOOL WINAPI
ImmRegisterWordA(
2196 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszRegister
)
2198 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2199 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2200 debugstr_a(lpszRegister
));
2201 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2203 if (!is_kbd_ime_unicode(immHkl
))
2204 return immHkl
->pImeRegisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2205 (LPCWSTR
)lpszRegister
);
2208 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2209 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
2212 rc
= immHkl
->pImeRegisterWord(lpszwReading
,dwStyle
,lpszwRegister
);
2213 HeapFree(GetProcessHeap(),0,lpszwReading
);
2214 HeapFree(GetProcessHeap(),0,lpszwRegister
);
2222 /***********************************************************************
2223 * ImmRegisterWordW (IMM32.@)
2225 BOOL WINAPI
ImmRegisterWordW(
2226 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
2228 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2229 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2230 debugstr_w(lpszRegister
));
2231 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2233 if (is_kbd_ime_unicode(immHkl
))
2234 return immHkl
->pImeRegisterWord(lpszReading
,dwStyle
,lpszRegister
);
2237 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2238 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
2241 rc
= immHkl
->pImeRegisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2242 (LPCWSTR
)lpszaRegister
);
2243 HeapFree(GetProcessHeap(),0,lpszaReading
);
2244 HeapFree(GetProcessHeap(),0,lpszaRegister
);
2252 /***********************************************************************
2253 * ImmReleaseContext (IMM32.@)
2255 BOOL WINAPI
ImmReleaseContext(HWND hWnd
, HIMC hIMC
)
2257 static BOOL shown
= FALSE
;
2260 FIXME("(%p, %p): stub\n", hWnd
, hIMC
);
2266 /***********************************************************************
2267 * ImmRequestMessageA(IMM32.@)
2269 LRESULT WINAPI
ImmRequestMessageA(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2271 InputContextData
*data
= get_imc_data(hIMC
);
2273 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2275 if (data
) return SendMessageA(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2277 SetLastError(ERROR_INVALID_HANDLE
);
2281 /***********************************************************************
2282 * ImmRequestMessageW(IMM32.@)
2284 LRESULT WINAPI
ImmRequestMessageW(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2286 InputContextData
*data
= get_imc_data(hIMC
);
2288 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2290 if (data
) return SendMessageW(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2292 SetLastError(ERROR_INVALID_HANDLE
);
2296 /***********************************************************************
2297 * ImmSetCandidateWindow (IMM32.@)
2299 BOOL WINAPI
ImmSetCandidateWindow(
2300 HIMC hIMC
, LPCANDIDATEFORM lpCandidate
)
2302 InputContextData
*data
= get_imc_data(hIMC
);
2304 TRACE("(%p, %p)\n", hIMC
, lpCandidate
);
2306 if (!data
|| !lpCandidate
)
2309 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2312 TRACE("\t%x, %x, %s, %s\n",
2313 lpCandidate
->dwIndex
, lpCandidate
->dwStyle
,
2314 wine_dbgstr_point(&lpCandidate
->ptCurrentPos
),
2315 wine_dbgstr_rect(&lpCandidate
->rcArea
));
2317 if ( lpCandidate
->dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
2320 data
->IMC
.cfCandForm
[lpCandidate
->dwIndex
] = *lpCandidate
;
2321 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCANDIDATEPOS
);
2322 ImmInternalSendIMENotify(data
, IMN_SETCANDIDATEPOS
, 1 << lpCandidate
->dwIndex
);
2327 /***********************************************************************
2328 * ImmSetCompositionFontA (IMM32.@)
2330 BOOL WINAPI
ImmSetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
2332 InputContextData
*data
= get_imc_data(hIMC
);
2333 TRACE("(%p, %p)\n", hIMC
, lplf
);
2337 SetLastError(ERROR_INVALID_HANDLE
);
2341 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2344 memcpy(&data
->IMC
.lfFont
.W
,lplf
,sizeof(LOGFONTA
));
2345 MultiByteToWideChar(CP_ACP
, 0, lplf
->lfFaceName
, -1, data
->IMC
.lfFont
.W
.lfFaceName
,
2347 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2348 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2353 /***********************************************************************
2354 * ImmSetCompositionFontW (IMM32.@)
2356 BOOL WINAPI
ImmSetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
2358 InputContextData
*data
= get_imc_data(hIMC
);
2359 TRACE("(%p, %p)\n", hIMC
, lplf
);
2363 SetLastError(ERROR_INVALID_HANDLE
);
2367 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2370 data
->IMC
.lfFont
.W
= *lplf
;
2371 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2372 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2377 /***********************************************************************
2378 * ImmSetCompositionStringA (IMM32.@)
2380 BOOL WINAPI
ImmSetCompositionStringA(
2381 HIMC hIMC
, DWORD dwIndex
,
2382 LPCVOID lpComp
, DWORD dwCompLen
,
2383 LPCVOID lpRead
, DWORD dwReadLen
)
2387 WCHAR
*CompBuffer
= NULL
;
2388 WCHAR
*ReadBuffer
= NULL
;
2390 InputContextData
*data
= get_imc_data(hIMC
);
2392 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2393 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2398 if (!(dwIndex
== SCS_SETSTR
||
2399 dwIndex
== SCS_CHANGEATTR
||
2400 dwIndex
== SCS_CHANGECLAUSE
||
2401 dwIndex
== SCS_SETRECONVERTSTRING
||
2402 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2405 if (!is_himc_ime_unicode(data
))
2406 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2407 dwCompLen
, lpRead
, dwReadLen
);
2409 comp_len
= MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0);
2412 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
* sizeof(WCHAR
));
2413 MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
);
2416 read_len
= MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0);
2419 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
* sizeof(WCHAR
));
2420 MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
);
2423 rc
= ImmSetCompositionStringW(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2424 ReadBuffer
, read_len
);
2426 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2427 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2432 /***********************************************************************
2433 * ImmSetCompositionStringW (IMM32.@)
2435 BOOL WINAPI
ImmSetCompositionStringW(
2436 HIMC hIMC
, DWORD dwIndex
,
2437 LPCVOID lpComp
, DWORD dwCompLen
,
2438 LPCVOID lpRead
, DWORD dwReadLen
)
2442 CHAR
*CompBuffer
= NULL
;
2443 CHAR
*ReadBuffer
= NULL
;
2445 InputContextData
*data
= get_imc_data(hIMC
);
2447 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2448 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2453 if (!(dwIndex
== SCS_SETSTR
||
2454 dwIndex
== SCS_CHANGEATTR
||
2455 dwIndex
== SCS_CHANGECLAUSE
||
2456 dwIndex
== SCS_SETRECONVERTSTRING
||
2457 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2460 if (is_himc_ime_unicode(data
))
2461 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2462 dwCompLen
, lpRead
, dwReadLen
);
2464 comp_len
= WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0, NULL
,
2468 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
);
2469 WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
,
2473 read_len
= WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0, NULL
,
2477 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
);
2478 WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
,
2482 rc
= ImmSetCompositionStringA(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2483 ReadBuffer
, read_len
);
2485 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2486 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2491 /***********************************************************************
2492 * ImmSetCompositionWindow (IMM32.@)
2494 BOOL WINAPI
ImmSetCompositionWindow(
2495 HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
2497 BOOL reshow
= FALSE
;
2498 InputContextData
*data
= get_imc_data(hIMC
);
2500 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
2502 TRACE("\t%x, %s, %s\n", lpCompForm
->dwStyle
,
2503 wine_dbgstr_point(&lpCompForm
->ptCurrentPos
),
2504 wine_dbgstr_rect(&lpCompForm
->rcArea
));
2508 SetLastError(ERROR_INVALID_HANDLE
);
2512 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2515 data
->IMC
.cfCompForm
= *lpCompForm
;
2517 if (IsWindowVisible(data
->immKbd
->UIWnd
))
2520 ShowWindow(data
->immKbd
->UIWnd
,SW_HIDE
);
2523 /* FIXME: this is a partial stub */
2526 ShowWindow(data
->immKbd
->UIWnd
,SW_SHOWNOACTIVATE
);
2528 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONWINDOW
, 0);
2532 /***********************************************************************
2533 * ImmSetConversionStatus (IMM32.@)
2535 BOOL WINAPI
ImmSetConversionStatus(
2536 HIMC hIMC
, DWORD fdwConversion
, DWORD fdwSentence
)
2538 DWORD oldConversion
, oldSentence
;
2539 InputContextData
*data
= get_imc_data(hIMC
);
2541 TRACE("%p %d %d\n", hIMC
, fdwConversion
, fdwSentence
);
2545 SetLastError(ERROR_INVALID_HANDLE
);
2549 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2552 if ( fdwConversion
!= data
->IMC
.fdwConversion
)
2554 oldConversion
= data
->IMC
.fdwConversion
;
2555 data
->IMC
.fdwConversion
= fdwConversion
;
2556 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldConversion
, IMC_SETCONVERSIONMODE
);
2557 ImmInternalSendIMENotify(data
, IMN_SETCONVERSIONMODE
, 0);
2559 if ( fdwSentence
!= data
->IMC
.fdwSentence
)
2561 oldSentence
= data
->IMC
.fdwSentence
;
2562 data
->IMC
.fdwSentence
= fdwSentence
;
2563 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldSentence
, IMC_SETSENTENCEMODE
);
2564 ImmInternalSendIMENotify(data
, IMN_SETSENTENCEMODE
, 0);
2570 /***********************************************************************
2571 * ImmSetOpenStatus (IMM32.@)
2573 BOOL WINAPI
ImmSetOpenStatus(HIMC hIMC
, BOOL fOpen
)
2575 InputContextData
*data
= get_imc_data(hIMC
);
2577 TRACE("%p %d\n", hIMC
, fOpen
);
2581 SetLastError(ERROR_INVALID_HANDLE
);
2585 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2588 if (data
->immKbd
->UIWnd
== NULL
)
2590 /* create the ime window */
2591 data
->immKbd
->UIWnd
= CreateWindowExW( WS_EX_TOOLWINDOW
,
2592 data
->immKbd
->imeClassName
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0,
2593 0, data
->immKbd
->hIME
, 0);
2594 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2597 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2599 if (!fOpen
!= !data
->IMC
.fOpen
)
2601 data
->IMC
.fOpen
= fOpen
;
2602 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETOPENSTATUS
);
2603 ImmInternalSendIMENotify(data
, IMN_SETOPENSTATUS
, 0);
2609 /***********************************************************************
2610 * ImmSetStatusWindowPos (IMM32.@)
2612 BOOL WINAPI
ImmSetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
2614 InputContextData
*data
= get_imc_data(hIMC
);
2616 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
2618 if (!data
|| !lpptPos
)
2620 SetLastError(ERROR_INVALID_HANDLE
);
2624 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2627 TRACE("\t%s\n", wine_dbgstr_point(lpptPos
));
2629 data
->IMC
.ptStatusWndPos
= *lpptPos
;
2630 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETSTATUSWINDOWPOS
);
2631 ImmInternalSendIMENotify(data
, IMN_SETSTATUSWINDOWPOS
, 0);
2636 /***********************************************************************
2637 * ImmCreateSoftKeyboard(IMM32.@)
2639 HWND WINAPI
ImmCreateSoftKeyboard(UINT uType
, UINT hOwner
, int x
, int y
)
2641 FIXME("(%d, %d, %d, %d): stub\n", uType
, hOwner
, x
, y
);
2642 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2646 /***********************************************************************
2647 * ImmDestroySoftKeyboard(IMM32.@)
2649 BOOL WINAPI
ImmDestroySoftKeyboard(HWND hSoftWnd
)
2651 FIXME("(%p): stub\n", hSoftWnd
);
2652 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2656 /***********************************************************************
2657 * ImmShowSoftKeyboard(IMM32.@)
2659 BOOL WINAPI
ImmShowSoftKeyboard(HWND hSoftWnd
, int nCmdShow
)
2661 FIXME("(%p, %d): stub\n", hSoftWnd
, nCmdShow
);
2662 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2666 /***********************************************************************
2667 * ImmSimulateHotKey (IMM32.@)
2669 BOOL WINAPI
ImmSimulateHotKey(HWND hWnd
, DWORD dwHotKeyID
)
2671 FIXME("(%p, %d): stub\n", hWnd
, dwHotKeyID
);
2672 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2676 /***********************************************************************
2677 * ImmUnregisterWordA (IMM32.@)
2679 BOOL WINAPI
ImmUnregisterWordA(
2680 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszUnregister
)
2682 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2683 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2684 debugstr_a(lpszUnregister
));
2685 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2687 if (!is_kbd_ime_unicode(immHkl
))
2688 return immHkl
->pImeUnregisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2689 (LPCWSTR
)lpszUnregister
);
2692 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2693 LPWSTR lpszwUnregister
= strdupAtoW(lpszUnregister
);
2696 rc
= immHkl
->pImeUnregisterWord(lpszwReading
,dwStyle
,lpszwUnregister
);
2697 HeapFree(GetProcessHeap(),0,lpszwReading
);
2698 HeapFree(GetProcessHeap(),0,lpszwUnregister
);
2706 /***********************************************************************
2707 * ImmUnregisterWordW (IMM32.@)
2709 BOOL WINAPI
ImmUnregisterWordW(
2710 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
2712 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2713 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2714 debugstr_w(lpszUnregister
));
2715 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2717 if (is_kbd_ime_unicode(immHkl
))
2718 return immHkl
->pImeUnregisterWord(lpszReading
,dwStyle
,lpszUnregister
);
2721 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2722 LPSTR lpszaUnregister
= strdupWtoA(lpszUnregister
);
2725 rc
= immHkl
->pImeUnregisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2726 (LPCWSTR
)lpszaUnregister
);
2727 HeapFree(GetProcessHeap(),0,lpszaReading
);
2728 HeapFree(GetProcessHeap(),0,lpszaUnregister
);
2736 /***********************************************************************
2737 * ImmGetImeMenuItemsA (IMM32.@)
2739 DWORD WINAPI
ImmGetImeMenuItemsA( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2740 LPIMEMENUITEMINFOA lpImeParentMenu
, LPIMEMENUITEMINFOA lpImeMenu
,
2743 InputContextData
*data
= get_imc_data(hIMC
);
2744 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2745 lpImeParentMenu
, lpImeMenu
, dwSize
);
2749 SetLastError(ERROR_INVALID_HANDLE
);
2753 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2755 if (!is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2756 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2757 (IMEMENUITEMINFOW
*)lpImeParentMenu
,
2758 (IMEMENUITEMINFOW
*)lpImeMenu
, dwSize
);
2761 IMEMENUITEMINFOW lpImeParentMenuW
;
2762 IMEMENUITEMINFOW
*lpImeMenuW
, *parent
= NULL
;
2765 if (lpImeParentMenu
)
2766 parent
= &lpImeParentMenuW
;
2769 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOA
);
2770 dwSize
= count
* sizeof(IMEMENUITEMINFOW
);
2771 lpImeMenuW
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2776 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2777 parent
, lpImeMenuW
, dwSize
);
2779 if (lpImeParentMenu
)
2781 memcpy(lpImeParentMenu
,&lpImeParentMenuW
,sizeof(IMEMENUITEMINFOA
));
2782 lpImeParentMenu
->hbmpItem
= lpImeParentMenuW
.hbmpItem
;
2783 WideCharToMultiByte(CP_ACP
, 0, lpImeParentMenuW
.szString
,
2784 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
,
2787 if (lpImeMenu
&& rc
)
2790 for (i
= 0; i
< rc
; i
++)
2792 memcpy(&lpImeMenu
[i
],&lpImeMenuW
[1],sizeof(IMEMENUITEMINFOA
));
2793 lpImeMenu
[i
].hbmpItem
= lpImeMenuW
[i
].hbmpItem
;
2794 WideCharToMultiByte(CP_ACP
, 0, lpImeMenuW
[i
].szString
,
2795 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
,
2799 HeapFree(GetProcessHeap(),0,lpImeMenuW
);
2807 /***********************************************************************
2808 * ImmGetImeMenuItemsW (IMM32.@)
2810 DWORD WINAPI
ImmGetImeMenuItemsW( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2811 LPIMEMENUITEMINFOW lpImeParentMenu
, LPIMEMENUITEMINFOW lpImeMenu
,
2814 InputContextData
*data
= get_imc_data(hIMC
);
2815 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2816 lpImeParentMenu
, lpImeMenu
, dwSize
);
2820 SetLastError(ERROR_INVALID_HANDLE
);
2824 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2826 if (is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2827 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2828 lpImeParentMenu
, lpImeMenu
, dwSize
);
2831 IMEMENUITEMINFOA lpImeParentMenuA
;
2832 IMEMENUITEMINFOA
*lpImeMenuA
, *parent
= NULL
;
2835 if (lpImeParentMenu
)
2836 parent
= &lpImeParentMenuA
;
2839 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOW
);
2840 dwSize
= count
* sizeof(IMEMENUITEMINFOA
);
2841 lpImeMenuA
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2846 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2847 (IMEMENUITEMINFOW
*)parent
,
2848 (IMEMENUITEMINFOW
*)lpImeMenuA
, dwSize
);
2850 if (lpImeParentMenu
)
2852 memcpy(lpImeParentMenu
,&lpImeParentMenuA
,sizeof(IMEMENUITEMINFOA
));
2853 lpImeParentMenu
->hbmpItem
= lpImeParentMenuA
.hbmpItem
;
2854 MultiByteToWideChar(CP_ACP
, 0, lpImeParentMenuA
.szString
,
2855 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
);
2857 if (lpImeMenu
&& rc
)
2860 for (i
= 0; i
< rc
; i
++)
2862 memcpy(&lpImeMenu
[i
],&lpImeMenuA
[1],sizeof(IMEMENUITEMINFOA
));
2863 lpImeMenu
[i
].hbmpItem
= lpImeMenuA
[i
].hbmpItem
;
2864 MultiByteToWideChar(CP_ACP
, 0, lpImeMenuA
[i
].szString
,
2865 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
);
2868 HeapFree(GetProcessHeap(),0,lpImeMenuA
);
2876 /***********************************************************************
2877 * ImmLockIMC(IMM32.@)
2879 LPINPUTCONTEXT WINAPI
ImmLockIMC(HIMC hIMC
)
2881 InputContextData
*data
= get_imc_data(hIMC
);
2889 /***********************************************************************
2890 * ImmUnlockIMC(IMM32.@)
2892 BOOL WINAPI
ImmUnlockIMC(HIMC hIMC
)
2894 InputContextData
*data
= get_imc_data(hIMC
);
2903 /***********************************************************************
2904 * ImmGetIMCLockCount(IMM32.@)
2906 DWORD WINAPI
ImmGetIMCLockCount(HIMC hIMC
)
2908 InputContextData
*data
= get_imc_data(hIMC
);
2911 return data
->dwLock
;
2914 /***********************************************************************
2915 * ImmCreateIMCC(IMM32.@)
2917 HIMCC WINAPI
ImmCreateIMCC(DWORD size
)
2919 return GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, size
);
2922 /***********************************************************************
2923 * ImmDestroyIMCC(IMM32.@)
2925 HIMCC WINAPI
ImmDestroyIMCC(HIMCC block
)
2927 return GlobalFree(block
);
2930 /***********************************************************************
2931 * ImmLockIMCC(IMM32.@)
2933 LPVOID WINAPI
ImmLockIMCC(HIMCC imcc
)
2935 return GlobalLock(imcc
);
2938 /***********************************************************************
2939 * ImmUnlockIMCC(IMM32.@)
2941 BOOL WINAPI
ImmUnlockIMCC(HIMCC imcc
)
2943 return GlobalUnlock(imcc
);
2946 /***********************************************************************
2947 * ImmGetIMCCLockCount(IMM32.@)
2949 DWORD WINAPI
ImmGetIMCCLockCount(HIMCC imcc
)
2951 return GlobalFlags(imcc
) & GMEM_LOCKCOUNT
;
2954 /***********************************************************************
2955 * ImmReSizeIMCC(IMM32.@)
2957 HIMCC WINAPI
ImmReSizeIMCC(HIMCC imcc
, DWORD size
)
2959 return GlobalReAlloc(imcc
, size
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
2962 /***********************************************************************
2963 * ImmGetIMCCSize(IMM32.@)
2965 DWORD WINAPI
ImmGetIMCCSize(HIMCC imcc
)
2967 return GlobalSize(imcc
);
2970 /***********************************************************************
2971 * ImmGenerateMessage(IMM32.@)
2973 BOOL WINAPI
ImmGenerateMessage(HIMC hIMC
)
2975 InputContextData
*data
= get_imc_data(hIMC
);
2979 SetLastError(ERROR_INVALID_HANDLE
);
2983 TRACE("%i messages queued\n",data
->IMC
.dwNumMsgBuf
);
2984 if (data
->IMC
.dwNumMsgBuf
> 0)
2986 LPTRANSMSG lpTransMsg
;
2988 DWORD i
, dwNumMsgBuf
;
2990 /* We are going to detach our hMsgBuff so that if processing messages
2991 generates new messages they go into a new buffer */
2992 hMsgBuf
= data
->IMC
.hMsgBuf
;
2993 dwNumMsgBuf
= data
->IMC
.dwNumMsgBuf
;
2995 data
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
2996 data
->IMC
.dwNumMsgBuf
= 0;
2998 lpTransMsg
= ImmLockIMCC(hMsgBuf
);
2999 for (i
= 0; i
< dwNumMsgBuf
; i
++)
3000 ImmInternalSendIMEMessage(data
, lpTransMsg
[i
].message
, lpTransMsg
[i
].wParam
, lpTransMsg
[i
].lParam
);
3002 ImmUnlockIMCC(hMsgBuf
);
3003 ImmDestroyIMCC(hMsgBuf
);
3009 /***********************************************************************
3010 * ImmTranslateMessage(IMM32.@)
3011 * ( Undocumented, call internally and from user32.dll )
3013 BOOL WINAPI
ImmTranslateMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lKeyData
)
3015 InputContextData
*data
;
3016 HIMC imc
= ImmGetContext(hwnd
);
3022 static const DWORD list_count
= 10;
3024 TRACE("%p %x %x %x\n",hwnd
, msg
, (UINT
)wParam
, (UINT
)lKeyData
);
3031 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeToAsciiEx
)
3034 GetKeyboardState(state
);
3035 scancode
= lKeyData
>> 0x10 & 0xff;
3037 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list_count
* sizeof(TRANSMSG
) + sizeof(DWORD
));
3038 ((DWORD
*)list
)[0] = list_count
;
3040 if (data
->immKbd
->imeInfo
.fdwProperty
& IME_PROP_KBD_CHAR_FIRST
)
3044 if (!is_himc_ime_unicode(data
))
3045 ToAscii(data
->lastVK
, scancode
, state
, &chr
, 0);
3047 ToUnicodeEx(data
->lastVK
, scancode
, state
, &chr
, 1, 0, GetKeyboardLayout(0));
3048 uVirtKey
= MAKELONG(data
->lastVK
,chr
);
3051 uVirtKey
= data
->lastVK
;
3053 msg_count
= data
->immKbd
->pImeToAsciiEx(uVirtKey
, scancode
, state
, list
, 0, imc
);
3054 TRACE("%i messages generated\n",msg_count
);
3055 if (msg_count
&& msg_count
<= list_count
)
3058 LPTRANSMSG msgs
= (LPTRANSMSG
)((LPBYTE
)list
+ sizeof(DWORD
));
3060 for (i
= 0; i
< msg_count
; i
++)
3061 ImmInternalPostIMEMessage(data
, msgs
[i
].message
, msgs
[i
].wParam
, msgs
[i
].lParam
);
3063 else if (msg_count
> list_count
)
3064 ImmGenerateMessage(imc
);
3066 HeapFree(GetProcessHeap(),0,list
);
3068 data
->lastVK
= VK_PROCESSKEY
;
3070 return (msg_count
> 0);
3073 /***********************************************************************
3074 * ImmProcessKey(IMM32.@)
3075 * ( Undocumented, called from user32.dll )
3077 BOOL WINAPI
ImmProcessKey(HWND hwnd
, HKL hKL
, UINT vKey
, LPARAM lKeyData
, DWORD unknown
)
3079 InputContextData
*data
;
3080 HIMC imc
= ImmGetContext(hwnd
);
3083 TRACE("%p %p %x %x %x\n",hwnd
, hKL
, vKey
, (UINT
)lKeyData
, unknown
);
3090 /* Make sure we are inputting to the correct keyboard */
3091 if (data
->immKbd
->hkl
!= hKL
)
3093 ImmHkl
*new_hkl
= IMM_GetImmHkl(hKL
);
3096 data
->immKbd
->pImeSelect(imc
, FALSE
);
3097 data
->immKbd
->uSelected
--;
3098 data
->immKbd
= new_hkl
;
3099 data
->immKbd
->pImeSelect(imc
, TRUE
);
3100 data
->immKbd
->uSelected
++;
3106 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeProcessKey
)
3109 GetKeyboardState(state
);
3110 if (data
->immKbd
->pImeProcessKey(imc
, vKey
, lKeyData
, state
))
3112 data
->lastVK
= vKey
;
3116 data
->lastVK
= VK_PROCESSKEY
;
3120 /***********************************************************************
3121 * ImmDisableTextFrameService(IMM32.@)
3123 BOOL WINAPI
ImmDisableTextFrameService(DWORD idThread
)
3129 /***********************************************************************
3130 * ImmEnumInputContext(IMM32.@)
3133 BOOL WINAPI
ImmEnumInputContext(DWORD idThread
, IMCENUMPROC lpfn
, LPARAM lParam
)
3139 /***********************************************************************
3140 * ImmGetHotKey(IMM32.@)
3143 BOOL WINAPI
ImmGetHotKey(DWORD hotkey
, UINT
*modifiers
, UINT
*key
, HKL hkl
)
3145 FIXME("%x, %p, %p, %p: stub\n", hotkey
, modifiers
, key
, hkl
);