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
{
101 static struct list ImmHklList
= LIST_INIT(ImmHklList
);
102 static struct list ImmThreadDataList
= LIST_INIT(ImmThreadDataList
);
104 static const WCHAR szwWineIMCProperty
[] = {'W','i','n','e','I','m','m','H','I','M','C','P','r','o','p','e','r','t','y',0};
106 static const WCHAR szImeFileW
[] = {'I','m','e',' ','F','i','l','e',0};
107 static const WCHAR szLayoutTextW
[] = {'L','a','y','o','u','t',' ','T','e','x','t',0};
108 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};
110 static const WCHAR szwIME
[] = {'I','M','E',0};
112 static CRITICAL_SECTION threaddata_cs
;
113 static CRITICAL_SECTION_DEBUG critsect_debug
=
115 0, 0, &threaddata_cs
,
116 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
117 0, 0, { (DWORD_PTR
)(__FILE__
": threaddata_cs") }
119 static CRITICAL_SECTION threaddata_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
120 static BOOL disable_ime
;
122 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
123 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
125 static BOOL
IMM_DestroyContext(HIMC hIMC
);
126 static InputContextData
* get_imc_data(HIMC hIMC
);
128 static inline WCHAR
*strdupAtoW( const char *str
)
133 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
134 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
135 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
140 static inline CHAR
*strdupWtoA( const WCHAR
*str
)
145 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
146 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
147 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
152 static DWORD
convert_candidatelist_WtoA(
153 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
157 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
158 if ( lpDst
&& dwBufLen
> 0 )
161 lpDst
->dwOffset
[0] = ret
;
164 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
166 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
168 if ( lpDst
&& dwBufLen
> 0 )
170 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
172 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1,
173 (LPSTR
)dest
, dwBufLen
, NULL
, NULL
);
175 if ( i
+ 1 < lpSrc
->dwCount
)
176 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(char);
177 dwBufLen
-= len
* sizeof(char);
180 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1, NULL
, 0, NULL
, NULL
);
182 ret
+= len
* sizeof(char);
191 static DWORD
convert_candidatelist_AtoW(
192 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
196 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
197 if ( lpDst
&& dwBufLen
> 0 )
200 lpDst
->dwOffset
[0] = ret
;
203 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
205 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
207 if ( lpDst
&& dwBufLen
> 0 )
209 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
211 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1,
212 (LPWSTR
)dest
, dwBufLen
);
214 if ( i
+ 1 < lpSrc
->dwCount
)
215 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(WCHAR
);
216 dwBufLen
-= len
* sizeof(WCHAR
);
219 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, NULL
, 0);
221 ret
+= len
* sizeof(WCHAR
);
230 static IMMThreadData
*IMM_GetThreadData(HWND hwnd
, DWORD thread
)
237 if (!(thread
= GetWindowThreadProcessId(hwnd
, &process
))) return NULL
;
238 if (process
!= GetCurrentProcessId()) return NULL
;
242 HANDLE h
= OpenThread(THREAD_QUERY_INFORMATION
, FALSE
, thread
);
244 process
= GetProcessIdOfThread(h
);
246 if (process
!= GetCurrentProcessId()) return NULL
;
249 thread
= GetCurrentThreadId();
251 EnterCriticalSection(&threaddata_cs
);
252 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
253 if (data
->threadID
== thread
) return data
;
255 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
));
256 data
->threadID
= thread
;
257 list_add_head(&ImmThreadDataList
,&data
->entry
);
258 TRACE("Thread Data Created (%x)\n",thread
);
262 static BOOL
IMM_IsDefaultContext(HIMC imc
)
264 InputContextData
*data
= get_imc_data(imc
);
269 return data
->threadDefault
;
272 static void IMM_FreeThreadData(void)
276 EnterCriticalSection(&threaddata_cs
);
277 LIST_FOR_EACH_ENTRY(data
, &ImmThreadDataList
, IMMThreadData
, entry
)
279 if (data
->threadID
== GetCurrentThreadId())
281 list_remove(&data
->entry
);
282 LeaveCriticalSection(&threaddata_cs
);
283 IMM_DestroyContext(data
->defaultContext
);
284 HeapFree(GetProcessHeap(),0,data
);
285 TRACE("Thread Data Destroyed\n");
289 LeaveCriticalSection(&threaddata_cs
);
292 static HMODULE
load_graphics_driver(void)
294 static const WCHAR display_device_guid_propW
[] = {
295 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
296 'd','e','v','i','c','e','_','g','u','i','d',0 };
297 static const WCHAR key_pathW
[] = {
298 'S','y','s','t','e','m','\\',
299 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
300 'C','o','n','t','r','o','l','\\',
301 'V','i','d','e','o','\\','{',0};
302 static const WCHAR displayW
[] = {'}','\\','0','0','0','0',0};
303 static const WCHAR driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
308 WCHAR path
[MAX_PATH
];
309 WCHAR key
[(sizeof(key_pathW
) + sizeof(displayW
)) / sizeof(WCHAR
) + 40];
310 UINT guid_atom
= HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW
));
312 if (!guid_atom
) return 0;
313 memcpy( key
, key_pathW
, sizeof(key_pathW
) );
314 if (!GlobalGetAtomNameW( guid_atom
, key
+ strlenW(key
), 40 )) return 0;
315 strcatW( key
, displayW
);
316 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, key
, &hkey
)) return 0;
318 if (!RegQueryValueExW( hkey
, driverW
, NULL
, NULL
, (BYTE
*)path
, &size
)) ret
= LoadLibraryW( path
);
320 TRACE( "%s %p\n", debugstr_w(path
), ret
);
324 /* ImmHkl loading and freeing */
325 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
326 static ImmHkl
*IMM_GetImmHkl(HKL hkl
)
329 WCHAR filename
[MAX_PATH
];
331 TRACE("Seeking ime for keyboard %p\n",hkl
);
333 LIST_FOR_EACH_ENTRY(ptr
, &ImmHklList
, ImmHkl
, entry
)
338 /* not found... create it */
340 ptr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ImmHkl
));
343 if (ImmGetIMEFileNameW(hkl
, filename
, MAX_PATH
)) ptr
->hIME
= LoadLibraryW(filename
);
344 if (!ptr
->hIME
) ptr
->hIME
= load_graphics_driver();
347 LOAD_FUNCPTR(ImeInquire
);
348 if (!ptr
->pImeInquire
|| !ptr
->pImeInquire(&ptr
->imeInfo
, ptr
->imeClassName
, NULL
))
350 FreeLibrary(ptr
->hIME
);
355 LOAD_FUNCPTR(ImeDestroy
);
356 LOAD_FUNCPTR(ImeSelect
);
357 if (!ptr
->pImeSelect
|| !ptr
->pImeDestroy
)
359 FreeLibrary(ptr
->hIME
);
364 LOAD_FUNCPTR(ImeConfigure
);
365 LOAD_FUNCPTR(ImeEscape
);
366 LOAD_FUNCPTR(ImeSetActiveContext
);
367 LOAD_FUNCPTR(ImeToAsciiEx
);
368 LOAD_FUNCPTR(NotifyIME
);
369 LOAD_FUNCPTR(ImeRegisterWord
);
370 LOAD_FUNCPTR(ImeUnregisterWord
);
371 LOAD_FUNCPTR(ImeEnumRegisterWord
);
372 LOAD_FUNCPTR(ImeSetCompositionString
);
373 LOAD_FUNCPTR(ImeConversionList
);
374 LOAD_FUNCPTR(ImeProcessKey
);
375 LOAD_FUNCPTR(ImeGetRegisterWordStyle
);
376 LOAD_FUNCPTR(ImeGetImeMenuItems
);
377 /* make sure our classname is WCHAR */
378 if (!is_kbd_ime_unicode(ptr
))
381 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ptr
->imeClassName
,
383 lstrcpyW(ptr
->imeClassName
, bufW
);
388 list_add_head(&ImmHklList
,&ptr
->entry
);
394 HWND WINAPI
__wine_get_ui_window(HKL hkl
)
396 ImmHkl
*immHkl
= IMM_GetImmHkl(hkl
);
397 return immHkl
->UIWnd
;
400 static void IMM_FreeAllImmHkl(void)
402 ImmHkl
*ptr
,*cursor2
;
404 LIST_FOR_EACH_ENTRY_SAFE(ptr
, cursor2
, &ImmHklList
, ImmHkl
, entry
)
406 list_remove(&ptr
->entry
);
410 FreeLibrary(ptr
->hIME
);
413 DestroyWindow(ptr
->UIWnd
);
414 HeapFree(GetProcessHeap(),0,ptr
);
418 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
420 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
423 case DLL_PROCESS_ATTACH
:
424 if (!User32InitializeImmEntryTable(IMM_INIT_MAGIC
))
429 case DLL_THREAD_ATTACH
:
431 case DLL_THREAD_DETACH
:
432 IMM_FreeThreadData();
434 case DLL_PROCESS_DETACH
:
435 if (lpReserved
) break;
436 IMM_FreeThreadData();
443 /* for posting messages as the IME */
444 static void ImmInternalPostIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
446 HWND target
= GetFocus();
448 PostMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
450 PostMessageW(target
, msg
, wParam
, lParam
);
453 /* for sending messages as the IME */
454 static void ImmInternalSendIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
456 HWND target
= GetFocus();
458 SendMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
460 SendMessageW(target
, msg
, wParam
, lParam
);
463 static LRESULT
ImmInternalSendIMENotify(InputContextData
*data
, WPARAM notify
, LPARAM lParam
)
467 target
= data
->IMC
.hWnd
;
468 if (!target
) target
= GetFocus();
471 return SendMessageW(target
, WM_IME_NOTIFY
, notify
, lParam
);
476 static HIMCC
ImmCreateBlankCompStr(void)
479 LPCOMPOSITIONSTRING ptr
;
480 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
481 ptr
= ImmLockIMCC(rc
);
482 memset(ptr
,0,sizeof(COMPOSITIONSTRING
));
483 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
488 static InputContextData
* get_imc_data(HIMC hIMC
)
490 InputContextData
*data
= hIMC
;
495 if(IsBadReadPtr(data
, sizeof(InputContextData
)) || data
->magic
!= WINE_IMC_VALID_MAGIC
)
497 SetLastError(ERROR_INVALID_HANDLE
);
503 static HIMC
get_default_context( HWND hwnd
)
506 IMMThreadData
* thread_data
= IMM_GetThreadData( hwnd
, 0 );
508 if (!thread_data
) return 0;
510 if (thread_data
->defaultContext
)
512 ret
= thread_data
->defaultContext
;
513 LeaveCriticalSection(&threaddata_cs
);
517 /* can't create a default context in another thread */
518 if (thread_data
->threadID
!= GetCurrentThreadId())
520 LeaveCriticalSection(&threaddata_cs
);
524 LeaveCriticalSection(&threaddata_cs
);
526 ret
= ImmCreateContext();
528 ((InputContextData
*)ret
)->threadDefault
= TRUE
;
530 /* thread_data is in the current thread so we can assume it's still valid */
531 EnterCriticalSection(&threaddata_cs
);
533 if (thread_data
->defaultContext
) /* someone beat us */
535 IMM_DestroyContext( ret
);
536 ret
= thread_data
->defaultContext
;
538 else thread_data
->defaultContext
= ret
;
540 LeaveCriticalSection(&threaddata_cs
);
544 static BOOL
IMM_IsCrossThreadAccess(HWND hWnd
, HIMC hIMC
)
546 InputContextData
*data
;
550 DWORD thread
= GetWindowThreadProcessId(hWnd
, NULL
);
551 if (thread
!= GetCurrentThreadId()) return TRUE
;
553 data
= get_imc_data(hIMC
);
554 if (data
&& data
->threadID
!= GetCurrentThreadId())
560 /***********************************************************************
561 * ImmAssociateContext (IMM32.@)
563 HIMC WINAPI
ImmAssociateContext(HWND hWnd
, HIMC hIMC
)
566 InputContextData
*data
= get_imc_data(hIMC
);
568 TRACE("(%p, %p):\n", hWnd
, hIMC
);
574 * If already associated just return
576 if (hIMC
&& data
->IMC
.hWnd
== hWnd
)
579 if (hIMC
&& IMM_IsCrossThreadAccess(hWnd
, hIMC
))
584 HIMC defaultContext
= get_default_context( hWnd
);
585 old
= RemovePropW(hWnd
,szwWineIMCProperty
);
588 old
= defaultContext
;
589 else if (old
== (HIMC
)-1)
592 if (hIMC
!= defaultContext
)
594 if (hIMC
== NULL
) /* Meaning disable imm for that window*/
595 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)-1);
597 SetPropW(hWnd
,szwWineIMCProperty
,hIMC
);
602 InputContextData
*old_data
= old
;
603 if (old_data
->IMC
.hWnd
== hWnd
)
604 old_data
->IMC
.hWnd
= NULL
;
611 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, FALSE
, ISC_SHOWUIALL
);
612 data
->IMC
.hWnd
= hWnd
;
613 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, TRUE
, ISC_SHOWUIALL
);
620 * Helper function for ImmAssociateContextEx
622 static BOOL CALLBACK
_ImmAssociateContextExEnumProc(HWND hwnd
, LPARAM lParam
)
624 HIMC hImc
= (HIMC
)lParam
;
625 ImmAssociateContext(hwnd
,hImc
);
629 /***********************************************************************
630 * ImmAssociateContextEx (IMM32.@)
632 BOOL WINAPI
ImmAssociateContextEx(HWND hWnd
, HIMC hIMC
, DWORD dwFlags
)
634 TRACE("(%p, %p, 0x%x):\n", hWnd
, hIMC
, dwFlags
);
642 ImmAssociateContext(hWnd
,hIMC
);
646 HIMC defaultContext
= get_default_context( hWnd
);
647 if (!defaultContext
) return FALSE
;
648 ImmAssociateContext(hWnd
,defaultContext
);
651 case IACE_IGNORENOCONTEXT
:
652 if (GetPropW(hWnd
,szwWineIMCProperty
))
653 ImmAssociateContext(hWnd
,hIMC
);
656 EnumChildWindows(hWnd
,_ImmAssociateContextExEnumProc
,(LPARAM
)hIMC
);
659 FIXME("Unknown dwFlags 0x%x\n",dwFlags
);
664 /***********************************************************************
665 * ImmConfigureIMEA (IMM32.@)
667 BOOL WINAPI
ImmConfigureIMEA(
668 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
670 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
672 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
674 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
677 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
679 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| !is_kbd_ime_unicode(immHkl
))
680 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
684 REGISTERWORDA
*rwa
= lpData
;
687 rww
.lpReading
= strdupAtoW(rwa
->lpReading
);
688 rww
.lpWord
= strdupAtoW(rwa
->lpWord
);
689 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rww
);
690 HeapFree(GetProcessHeap(),0,rww
.lpReading
);
691 HeapFree(GetProcessHeap(),0,rww
.lpWord
);
699 /***********************************************************************
700 * ImmConfigureIMEW (IMM32.@)
702 BOOL WINAPI
ImmConfigureIMEW(
703 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
705 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
707 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
709 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
712 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
714 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| is_kbd_ime_unicode(immHkl
))
715 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
718 REGISTERWORDW
*rww
= lpData
;
722 rwa
.lpReading
= strdupWtoA(rww
->lpReading
);
723 rwa
.lpWord
= strdupWtoA(rww
->lpWord
);
724 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rwa
);
725 HeapFree(GetProcessHeap(),0,rwa
.lpReading
);
726 HeapFree(GetProcessHeap(),0,rwa
.lpWord
);
734 /***********************************************************************
735 * ImmCreateContext (IMM32.@)
737 HIMC WINAPI
ImmCreateContext(void)
739 InputContextData
*new_context
;
744 new_context
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputContextData
));
747 new_context
->immKbd
= IMM_GetImmHkl(GetKeyboardLayout(0));
749 if (!new_context
->immKbd
->hIME
)
751 TRACE("IME dll could not be loaded\n");
752 HeapFree(GetProcessHeap(),0,new_context
);
756 /* the HIMCCs are never NULL */
757 new_context
->IMC
.hCompStr
= ImmCreateBlankCompStr();
758 new_context
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
759 new_context
->IMC
.hCandInfo
= ImmCreateIMCC(sizeof(CANDIDATEINFO
));
760 ci
= ImmLockIMCC(new_context
->IMC
.hCandInfo
);
761 memset(ci
,0,sizeof(CANDIDATEINFO
));
762 ci
->dwSize
= sizeof(CANDIDATEINFO
);
763 ImmUnlockIMCC(new_context
->IMC
.hCandInfo
);
764 new_context
->IMC
.hGuideLine
= ImmCreateIMCC(sizeof(GUIDELINE
));
765 gl
= ImmLockIMCC(new_context
->IMC
.hGuideLine
);
766 memset(gl
,0,sizeof(GUIDELINE
));
767 gl
->dwSize
= sizeof(GUIDELINE
);
768 ImmUnlockIMCC(new_context
->IMC
.hGuideLine
);
770 for (i
= 0; i
< sizeof(new_context
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
); i
++)
771 new_context
->IMC
.cfCandForm
[i
].dwIndex
= ~0u;
773 /* Initialize the IME Private */
774 new_context
->IMC
.hPrivate
= ImmCreateIMCC(new_context
->immKbd
->imeInfo
.dwPrivateDataSize
);
776 new_context
->IMC
.fdwConversion
= new_context
->immKbd
->imeInfo
.fdwConversionCaps
;
777 new_context
->IMC
.fdwSentence
= new_context
->immKbd
->imeInfo
.fdwSentenceCaps
;
779 if (!new_context
->immKbd
->pImeSelect(new_context
, TRUE
))
781 TRACE("Selection of IME failed\n");
782 IMM_DestroyContext(new_context
);
785 new_context
->threadID
= GetCurrentThreadId();
786 SendMessageW(GetFocus(), WM_IME_SELECT
, TRUE
, (LPARAM
)new_context
->immKbd
);
788 new_context
->immKbd
->uSelected
++;
789 TRACE("Created context %p\n",new_context
);
791 new_context
->magic
= WINE_IMC_VALID_MAGIC
;
795 static BOOL
IMM_DestroyContext(HIMC hIMC
)
797 InputContextData
*data
= get_imc_data(hIMC
);
799 TRACE("Destroying %p\n",hIMC
);
804 data
->immKbd
->uSelected
--;
805 data
->immKbd
->pImeSelect(hIMC
, FALSE
);
806 SendMessageW(data
->IMC
.hWnd
, WM_IME_SELECT
, FALSE
, (LPARAM
)data
->immKbd
);
808 ImmDestroyIMCC(data
->IMC
.hCompStr
);
809 ImmDestroyIMCC(data
->IMC
.hCandInfo
);
810 ImmDestroyIMCC(data
->IMC
.hGuideLine
);
811 ImmDestroyIMCC(data
->IMC
.hPrivate
);
812 ImmDestroyIMCC(data
->IMC
.hMsgBuf
);
815 HeapFree(GetProcessHeap(),0,data
);
820 /***********************************************************************
821 * ImmDestroyContext (IMM32.@)
823 BOOL WINAPI
ImmDestroyContext(HIMC hIMC
)
825 if (!IMM_IsDefaultContext(hIMC
) && !IMM_IsCrossThreadAccess(NULL
, hIMC
))
826 return IMM_DestroyContext(hIMC
);
831 /***********************************************************************
832 * ImmDisableIME (IMM32.@)
834 BOOL WINAPI
ImmDisableIME(DWORD idThread
)
836 if (idThread
== (DWORD
)-1)
839 IMMThreadData
*thread_data
= IMM_GetThreadData(NULL
, idThread
);
840 if (!thread_data
) return FALSE
;
841 thread_data
->disableIME
= TRUE
;
842 LeaveCriticalSection(&threaddata_cs
);
847 /***********************************************************************
848 * ImmEnumRegisterWordA (IMM32.@)
850 UINT WINAPI
ImmEnumRegisterWordA(
851 HKL hKL
, REGISTERWORDENUMPROCA lpfnEnumProc
,
852 LPCSTR lpszReading
, DWORD dwStyle
,
853 LPCSTR lpszRegister
, LPVOID lpData
)
855 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
856 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
857 debugstr_a(lpszReading
), dwStyle
, debugstr_a(lpszRegister
), lpData
);
858 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
860 if (!is_kbd_ime_unicode(immHkl
))
861 return immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
862 (LPCWSTR
)lpszReading
, dwStyle
, (LPCWSTR
)lpszRegister
, lpData
);
865 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
866 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
869 rc
= immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
870 lpszwReading
, dwStyle
, lpszwRegister
,
873 HeapFree(GetProcessHeap(),0,lpszwReading
);
874 HeapFree(GetProcessHeap(),0,lpszwRegister
);
882 /***********************************************************************
883 * ImmEnumRegisterWordW (IMM32.@)
885 UINT WINAPI
ImmEnumRegisterWordW(
886 HKL hKL
, REGISTERWORDENUMPROCW lpfnEnumProc
,
887 LPCWSTR lpszReading
, DWORD dwStyle
,
888 LPCWSTR lpszRegister
, LPVOID lpData
)
890 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
891 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
892 debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
), lpData
);
893 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
895 if (is_kbd_ime_unicode(immHkl
))
896 return immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, lpszReading
, dwStyle
,
897 lpszRegister
, lpData
);
900 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
901 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
904 rc
= immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, (LPCWSTR
)lpszaReading
,
905 dwStyle
, (LPCWSTR
)lpszaRegister
, lpData
);
907 HeapFree(GetProcessHeap(),0,lpszaReading
);
908 HeapFree(GetProcessHeap(),0,lpszaRegister
);
916 static inline BOOL
EscapeRequiresWA(UINT uEscape
)
918 if (uEscape
== IME_ESC_GET_EUDC_DICTIONARY
||
919 uEscape
== IME_ESC_SET_EUDC_DICTIONARY
||
920 uEscape
== IME_ESC_IME_NAME
||
921 uEscape
== IME_ESC_GETHELPFILENAME
)
926 /***********************************************************************
927 * ImmEscapeA (IMM32.@)
929 LRESULT WINAPI
ImmEscapeA(
931 UINT uEscape
, LPVOID lpData
)
933 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
934 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
936 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
938 if (!EscapeRequiresWA(uEscape
) || !is_kbd_ime_unicode(immHkl
))
939 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
942 WCHAR buffer
[81]; /* largest required buffer should be 80 */
944 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
946 MultiByteToWideChar(CP_ACP
,0,lpData
,-1,buffer
,81);
947 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
951 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
952 WideCharToMultiByte(CP_ACP
,0,buffer
,-1,lpData
,80, NULL
, NULL
);
961 /***********************************************************************
962 * ImmEscapeW (IMM32.@)
964 LRESULT WINAPI
ImmEscapeW(
966 UINT uEscape
, LPVOID lpData
)
968 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
969 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
971 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
973 if (!EscapeRequiresWA(uEscape
) || is_kbd_ime_unicode(immHkl
))
974 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
977 CHAR buffer
[81]; /* largest required buffer should be 80 */
979 if (uEscape
== IME_ESC_SET_EUDC_DICTIONARY
)
981 WideCharToMultiByte(CP_ACP
,0,lpData
,-1,buffer
,81, NULL
, NULL
);
982 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
986 rc
= immHkl
->pImeEscape(hIMC
,uEscape
,buffer
);
987 MultiByteToWideChar(CP_ACP
,0,buffer
,-1,lpData
,80);
996 /***********************************************************************
997 * ImmGetCandidateListA (IMM32.@)
999 DWORD WINAPI
ImmGetCandidateListA(
1000 HIMC hIMC
, DWORD dwIndex
,
1001 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1003 InputContextData
*data
= get_imc_data(hIMC
);
1004 LPCANDIDATEINFO candinfo
;
1005 LPCANDIDATELIST candlist
;
1008 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1010 if (!data
|| !data
->IMC
.hCandInfo
)
1013 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1014 if ( dwIndex
>= candinfo
->dwCount
||
1015 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1018 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1019 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1022 if ( !is_himc_ime_unicode(data
) )
1024 ret
= candlist
->dwSize
;
1025 if ( lpCandList
&& dwBufLen
>= ret
)
1026 memcpy(lpCandList
, candlist
, ret
);
1029 ret
= convert_candidatelist_WtoA( candlist
, lpCandList
, dwBufLen
);
1032 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1036 /***********************************************************************
1037 * ImmGetCandidateListCountA (IMM32.@)
1039 DWORD WINAPI
ImmGetCandidateListCountA(
1040 HIMC hIMC
, LPDWORD lpdwListCount
)
1042 InputContextData
*data
= get_imc_data(hIMC
);
1043 LPCANDIDATEINFO candinfo
;
1046 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1048 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1051 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1053 *lpdwListCount
= count
= candinfo
->dwCount
;
1055 if ( !is_himc_ime_unicode(data
) )
1056 ret
= candinfo
->dwSize
;
1059 ret
= sizeof(CANDIDATEINFO
);
1061 ret
+= ImmGetCandidateListA(hIMC
, count
, NULL
, 0);
1064 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1068 /***********************************************************************
1069 * ImmGetCandidateListCountW (IMM32.@)
1071 DWORD WINAPI
ImmGetCandidateListCountW(
1072 HIMC hIMC
, LPDWORD lpdwListCount
)
1074 InputContextData
*data
= get_imc_data(hIMC
);
1075 LPCANDIDATEINFO candinfo
;
1078 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
1080 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
1083 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1085 *lpdwListCount
= count
= candinfo
->dwCount
;
1087 if ( is_himc_ime_unicode(data
) )
1088 ret
= candinfo
->dwSize
;
1091 ret
= sizeof(CANDIDATEINFO
);
1093 ret
+= ImmGetCandidateListW(hIMC
, count
, NULL
, 0);
1096 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1100 /***********************************************************************
1101 * ImmGetCandidateListW (IMM32.@)
1103 DWORD WINAPI
ImmGetCandidateListW(
1104 HIMC hIMC
, DWORD dwIndex
,
1105 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
1107 InputContextData
*data
= get_imc_data(hIMC
);
1108 LPCANDIDATEINFO candinfo
;
1109 LPCANDIDATELIST candlist
;
1112 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
1114 if (!data
|| !data
->IMC
.hCandInfo
)
1117 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
1118 if ( dwIndex
>= candinfo
->dwCount
||
1119 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
1122 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
1123 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
1126 if ( is_himc_ime_unicode(data
) )
1128 ret
= candlist
->dwSize
;
1129 if ( lpCandList
&& dwBufLen
>= ret
)
1130 memcpy(lpCandList
, candlist
, ret
);
1133 ret
= convert_candidatelist_AtoW( candlist
, lpCandList
, dwBufLen
);
1136 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
1140 /***********************************************************************
1141 * ImmGetCandidateWindow (IMM32.@)
1143 BOOL WINAPI
ImmGetCandidateWindow(
1144 HIMC hIMC
, DWORD dwIndex
, LPCANDIDATEFORM lpCandidate
)
1146 InputContextData
*data
= get_imc_data(hIMC
);
1148 TRACE("%p, %d, %p\n", hIMC
, dwIndex
, lpCandidate
);
1150 if (!data
|| !lpCandidate
)
1153 if ( dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
1156 if (data
->IMC
.cfCandForm
[dwIndex
].dwIndex
!= dwIndex
)
1159 *lpCandidate
= data
->IMC
.cfCandForm
[dwIndex
];
1164 /***********************************************************************
1165 * ImmGetCompositionFontA (IMM32.@)
1167 BOOL WINAPI
ImmGetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
1172 TRACE("(%p, %p):\n", hIMC
, lplf
);
1174 rc
= ImmGetCompositionFontW(hIMC
,&lfW
);
1178 memcpy(lplf
,&lfW
,sizeof(LOGFONTA
));
1179 WideCharToMultiByte(CP_ACP
, 0, lfW
.lfFaceName
, -1, lplf
->lfFaceName
,
1180 LF_FACESIZE
, NULL
, NULL
);
1184 /***********************************************************************
1185 * ImmGetCompositionFontW (IMM32.@)
1187 BOOL WINAPI
ImmGetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
1189 InputContextData
*data
= get_imc_data(hIMC
);
1191 TRACE("(%p, %p):\n", hIMC
, lplf
);
1196 *lplf
= data
->IMC
.lfFont
.W
;
1202 /* Helpers for the GetCompositionString functions */
1204 static INT
CopyCompStringIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE target
, INT tlen
,
1209 if (is_himc_ime_unicode(data
) && !unicode
)
1210 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)source
, slen
, (LPSTR
)target
, tlen
, NULL
, NULL
);
1211 else if (!is_himc_ime_unicode(data
) && unicode
)
1212 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)source
, slen
, (LPWSTR
)target
, tlen
) * sizeof(WCHAR
);
1215 int dlen
= (unicode
)?sizeof(WCHAR
):sizeof(CHAR
);
1216 memcpy( target
, source
, min(slen
,tlen
)*dlen
);
1223 static INT
CopyCompAttrIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1224 LPBYTE target
, INT tlen
, BOOL unicode
)
1228 if (is_himc_ime_unicode(data
) && !unicode
)
1230 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, sslen
, NULL
, 0, NULL
, NULL
);
1233 const BYTE
*src
= source
;
1234 LPBYTE dst
= target
;
1235 int i
, j
= 0, k
= 0;
1239 for (i
= 0; i
< sslen
; ++i
)
1243 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)ssource
+ i
, 1,
1244 NULL
, 0, NULL
, NULL
);
1245 for (; len
> 0; --len
)
1258 else if (!is_himc_ime_unicode(data
) && unicode
)
1260 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, sslen
, NULL
, 0);
1263 const BYTE
*src
= source
;
1264 LPBYTE dst
= target
;
1269 for (i
= 0; i
< sslen
; ++i
)
1271 if (IsDBCSLeadByte(((LPSTR
)ssource
)[i
]))
1284 memcpy( target
, source
, min(slen
,tlen
));
1291 static INT
CopyCompClauseIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
,
1292 LPBYTE target
, INT tlen
, BOOL unicode
)
1296 if (is_himc_ime_unicode(data
) && !unicode
)
1304 tlen
/= sizeof (DWORD
);
1305 for (i
= 0; i
< tlen
; ++i
)
1307 ((DWORD
*)target
)[i
] = WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
,
1308 ((DWORD
*)source
)[i
],
1312 rc
= sizeof (DWORD
) * i
;
1317 else if (!is_himc_ime_unicode(data
) && unicode
)
1325 tlen
/= sizeof (DWORD
);
1326 for (i
= 0; i
< tlen
; ++i
)
1328 ((DWORD
*)target
)[i
] = MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
,
1329 ((DWORD
*)source
)[i
],
1332 rc
= sizeof (DWORD
) * i
;
1339 memcpy( target
, source
, min(slen
,tlen
));
1346 static INT
CopyCompOffsetIMEtoClient(InputContextData
*data
, DWORD offset
, LPBYTE ssource
, BOOL unicode
)
1350 if (is_himc_ime_unicode(data
) && !unicode
)
1352 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, offset
, NULL
, 0, NULL
, NULL
);
1354 else if (!is_himc_ime_unicode(data
) && unicode
)
1356 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, offset
, NULL
, 0);
1364 static LONG
ImmGetCompositionStringT( HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
,
1365 DWORD dwBufLen
, BOOL unicode
)
1368 InputContextData
*data
= get_imc_data(hIMC
);
1369 LPCOMPOSITIONSTRING compstr
;
1372 TRACE("(%p, 0x%x, %p, %d)\n", hIMC
, dwIndex
, lpBuf
, dwBufLen
);
1377 if (!data
->IMC
.hCompStr
)
1380 compdata
= ImmLockIMCC(data
->IMC
.hCompStr
);
1381 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1386 TRACE("GCS_RESULTSTR\n");
1387 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
, lpBuf
, dwBufLen
, unicode
);
1390 TRACE("GCS_COMPSTR\n");
1391 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
, lpBuf
, dwBufLen
, unicode
);
1394 TRACE("GCS_COMPATTR\n");
1395 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompAttrOffset
, compstr
->dwCompAttrLen
,
1396 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1397 lpBuf
, dwBufLen
, unicode
);
1399 case GCS_COMPCLAUSE
:
1400 TRACE("GCS_COMPCLAUSE\n");
1401 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompClauseOffset
,compstr
->dwCompClauseLen
,
1402 compdata
+ compstr
->dwCompStrOffset
,
1403 lpBuf
, dwBufLen
, unicode
);
1405 case GCS_RESULTCLAUSE
:
1406 TRACE("GCS_RESULTCLAUSE\n");
1407 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultClauseOffset
,compstr
->dwResultClauseLen
,
1408 compdata
+ compstr
->dwResultStrOffset
,
1409 lpBuf
, dwBufLen
, unicode
);
1411 case GCS_RESULTREADSTR
:
1412 TRACE("GCS_RESULTREADSTR\n");
1413 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultReadStrOffset
, compstr
->dwResultReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1415 case GCS_RESULTREADCLAUSE
:
1416 TRACE("GCS_RESULTREADCLAUSE\n");
1417 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultReadClauseOffset
,compstr
->dwResultReadClauseLen
,
1418 compdata
+ compstr
->dwResultStrOffset
,
1419 lpBuf
, dwBufLen
, unicode
);
1421 case GCS_COMPREADSTR
:
1422 TRACE("GCS_COMPREADSTR\n");
1423 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1425 case GCS_COMPREADATTR
:
1426 TRACE("GCS_COMPREADATTR\n");
1427 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompReadAttrOffset
, compstr
->dwCompReadAttrLen
,
1428 compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
,
1429 lpBuf
, dwBufLen
, unicode
);
1431 case GCS_COMPREADCLAUSE
:
1432 TRACE("GCS_COMPREADCLAUSE\n");
1433 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompReadClauseOffset
,compstr
->dwCompReadClauseLen
,
1434 compdata
+ compstr
->dwCompStrOffset
,
1435 lpBuf
, dwBufLen
, unicode
);
1438 TRACE("GCS_CURSORPOS\n");
1439 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwCursorPos
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1441 case GCS_DELTASTART
:
1442 TRACE("GCS_DELTASTART\n");
1443 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwDeltaStart
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1446 FIXME("Unhandled index 0x%x\n",dwIndex
);
1450 ImmUnlockIMCC(data
->IMC
.hCompStr
);
1455 /***********************************************************************
1456 * ImmGetCompositionStringA (IMM32.@)
1458 LONG WINAPI
ImmGetCompositionStringA(
1459 HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
, DWORD dwBufLen
)
1461 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, FALSE
);
1465 /***********************************************************************
1466 * ImmGetCompositionStringW (IMM32.@)
1468 LONG WINAPI
ImmGetCompositionStringW(
1469 HIMC hIMC
, DWORD dwIndex
,
1470 LPVOID lpBuf
, DWORD dwBufLen
)
1472 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, TRUE
);
1475 /***********************************************************************
1476 * ImmGetCompositionWindow (IMM32.@)
1478 BOOL WINAPI
ImmGetCompositionWindow(HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
1480 InputContextData
*data
= get_imc_data(hIMC
);
1482 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
1487 *lpCompForm
= data
->IMC
.cfCompForm
;
1491 /***********************************************************************
1492 * ImmGetContext (IMM32.@)
1495 HIMC WINAPI
ImmGetContext(HWND hWnd
)
1499 TRACE("%p\n", hWnd
);
1501 if (!IsWindow(hWnd
))
1503 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1507 rc
= GetPropW(hWnd
,szwWineIMCProperty
);
1510 else if (rc
== NULL
)
1511 rc
= get_default_context( hWnd
);
1515 InputContextData
*data
= rc
;
1516 data
->IMC
.hWnd
= hWnd
;
1519 TRACE("returning %p\n", rc
);
1524 /***********************************************************************
1525 * ImmGetConversionListA (IMM32.@)
1527 DWORD WINAPI
ImmGetConversionListA(
1529 LPCSTR pSrc
, LPCANDIDATELIST lpDst
,
1530 DWORD dwBufLen
, UINT uFlag
)
1532 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1533 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_a(pSrc
), lpDst
,
1535 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1537 if (!is_kbd_ime_unicode(immHkl
))
1538 return immHkl
->pImeConversionList(hIMC
,(LPCWSTR
)pSrc
,lpDst
,dwBufLen
,uFlag
);
1541 LPCANDIDATELIST lpwDst
;
1543 LPWSTR pwSrc
= strdupAtoW(pSrc
);
1545 len
= immHkl
->pImeConversionList(hIMC
, pwSrc
, NULL
, 0, uFlag
);
1546 lpwDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1549 immHkl
->pImeConversionList(hIMC
, pwSrc
, lpwDst
, len
, uFlag
);
1550 ret
= convert_candidatelist_WtoA( lpwDst
, lpDst
, dwBufLen
);
1551 HeapFree(GetProcessHeap(), 0, lpwDst
);
1553 HeapFree(GetProcessHeap(), 0, pwSrc
);
1562 /***********************************************************************
1563 * ImmGetConversionListW (IMM32.@)
1565 DWORD WINAPI
ImmGetConversionListW(
1567 LPCWSTR pSrc
, LPCANDIDATELIST lpDst
,
1568 DWORD dwBufLen
, UINT uFlag
)
1570 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1571 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_w(pSrc
), lpDst
,
1573 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1575 if (is_kbd_ime_unicode(immHkl
))
1576 return immHkl
->pImeConversionList(hIMC
,pSrc
,lpDst
,dwBufLen
,uFlag
);
1579 LPCANDIDATELIST lpaDst
;
1581 LPSTR paSrc
= strdupWtoA(pSrc
);
1583 len
= immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, NULL
, 0, uFlag
);
1584 lpaDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1587 immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, lpaDst
, len
, uFlag
);
1588 ret
= convert_candidatelist_AtoW( lpaDst
, lpDst
, dwBufLen
);
1589 HeapFree(GetProcessHeap(), 0, lpaDst
);
1591 HeapFree(GetProcessHeap(), 0, paSrc
);
1600 /***********************************************************************
1601 * ImmGetConversionStatus (IMM32.@)
1603 BOOL WINAPI
ImmGetConversionStatus(
1604 HIMC hIMC
, LPDWORD lpfdwConversion
, LPDWORD lpfdwSentence
)
1606 InputContextData
*data
= get_imc_data(hIMC
);
1608 TRACE("%p %p %p\n", hIMC
, lpfdwConversion
, lpfdwSentence
);
1613 if (lpfdwConversion
)
1614 *lpfdwConversion
= data
->IMC
.fdwConversion
;
1616 *lpfdwSentence
= data
->IMC
.fdwSentence
;
1621 /***********************************************************************
1622 * ImmGetDefaultIMEWnd (IMM32.@)
1624 HWND WINAPI
ImmGetDefaultIMEWnd(HWND hWnd
)
1626 HWND ret
, new = NULL
;
1627 IMMThreadData
* thread_data
= IMM_GetThreadData(hWnd
, 0);
1630 if (thread_data
->hwndDefault
== NULL
&& thread_data
->threadID
== GetCurrentThreadId())
1632 if (thread_data
->disableIME
|| disable_ime
)
1634 TRACE("IME for this thread is disabled\n");
1635 LeaveCriticalSection(&threaddata_cs
);
1638 /* Do not create the window inside of a critical section */
1639 LeaveCriticalSection(&threaddata_cs
);
1640 new = CreateWindowExW( WS_EX_TOOLWINDOW
,
1641 szwIME
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0, 0, 0, 0);
1642 /* thread_data is in the current thread so we can assume it's still valid */
1643 EnterCriticalSection(&threaddata_cs
);
1644 /* See if anyone beat us */
1645 if (thread_data
->hwndDefault
== NULL
)
1647 thread_data
->hwndDefault
= new;
1651 ret
= thread_data
->hwndDefault
;
1652 LeaveCriticalSection(&threaddata_cs
);
1653 TRACE("Default is %p\n",ret
);
1654 /* Clean up an unused new window outside of the critical section */
1659 TRACE("Default is %p\n",ret
);
1663 /***********************************************************************
1664 * ImmGetDescriptionA (IMM32.@)
1666 UINT WINAPI
ImmGetDescriptionA(
1667 HKL hKL
, LPSTR lpszDescription
, UINT uBufLen
)
1672 TRACE("%p %p %d\n", hKL
, lpszDescription
, uBufLen
);
1674 /* find out how many characters in the unicode buffer */
1675 len
= ImmGetDescriptionW( hKL
, NULL
, 0 );
1679 /* allocate a buffer of that size */
1680 buf
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof (WCHAR
) );
1684 /* fetch the unicode buffer */
1685 len
= ImmGetDescriptionW( hKL
, buf
, len
+ 1 );
1687 /* convert it back to ASCII */
1688 len
= WideCharToMultiByte( CP_ACP
, 0, buf
, len
+ 1,
1689 lpszDescription
, uBufLen
, NULL
, NULL
);
1691 HeapFree( GetProcessHeap(), 0, buf
);
1699 /***********************************************************************
1700 * ImmGetDescriptionW (IMM32.@)
1702 UINT WINAPI
ImmGetDescriptionW(HKL hKL
, LPWSTR lpszDescription
, UINT uBufLen
)
1704 static const WCHAR name
[] = { 'W','i','n','e',' ','X','I','M',0 };
1706 FIXME("(%p, %p, %d): semi stub\n", hKL
, lpszDescription
, uBufLen
);
1709 if (!uBufLen
) return lstrlenW( name
);
1710 lstrcpynW( lpszDescription
, name
, uBufLen
);
1711 return lstrlenW( lpszDescription
);
1714 /***********************************************************************
1715 * ImmGetGuideLineA (IMM32.@)
1717 DWORD WINAPI
ImmGetGuideLineA(
1718 HIMC hIMC
, DWORD dwIndex
, LPSTR lpBuf
, DWORD dwBufLen
)
1720 FIXME("(%p, %d, %s, %d): stub\n",
1721 hIMC
, dwIndex
, debugstr_a(lpBuf
), dwBufLen
1723 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1727 /***********************************************************************
1728 * ImmGetGuideLineW (IMM32.@)
1730 DWORD WINAPI
ImmGetGuideLineW(HIMC hIMC
, DWORD dwIndex
, LPWSTR lpBuf
, DWORD dwBufLen
)
1732 FIXME("(%p, %d, %s, %d): stub\n",
1733 hIMC
, dwIndex
, debugstr_w(lpBuf
), dwBufLen
1735 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1739 /***********************************************************************
1740 * ImmGetIMEFileNameA (IMM32.@)
1742 UINT WINAPI
ImmGetIMEFileNameA( HKL hKL
, LPSTR lpszFileName
, UINT uBufLen
)
1745 UINT wBufLen
= uBufLen
;
1748 if (uBufLen
&& lpszFileName
)
1749 bufW
= HeapAlloc(GetProcessHeap(),0,uBufLen
* sizeof(WCHAR
));
1750 else /* We need this to get the number of byte required */
1752 bufW
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
* sizeof(WCHAR
));
1756 rc
= ImmGetIMEFileNameW(hKL
,bufW
,wBufLen
);
1760 if (uBufLen
&& lpszFileName
)
1761 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, lpszFileName
,
1762 uBufLen
, NULL
, NULL
);
1763 else /* get the length */
1764 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
,
1768 HeapFree(GetProcessHeap(),0,bufW
);
1772 /***********************************************************************
1773 * ImmGetIMEFileNameW (IMM32.@)
1775 UINT WINAPI
ImmGetIMEFileNameW(HKL hKL
, LPWSTR lpszFileName
, UINT uBufLen
)
1780 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
1782 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hKL
);
1783 rc
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, regKey
, &hkey
);
1784 if (rc
!= ERROR_SUCCESS
)
1791 rc
= RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, NULL
, &length
);
1793 if (rc
!= ERROR_SUCCESS
)
1799 if (length
> uBufLen
* sizeof(WCHAR
) || !lpszFileName
)
1804 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1808 return length
/ sizeof(WCHAR
);
1811 RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, lpszFileName
, &length
);
1815 return length
/ sizeof(WCHAR
);
1818 /***********************************************************************
1819 * ImmGetOpenStatus (IMM32.@)
1821 BOOL WINAPI
ImmGetOpenStatus(HIMC hIMC
)
1823 InputContextData
*data
= get_imc_data(hIMC
);
1829 TRACE("(%p): semi-stub\n", hIMC
);
1832 FIXME("(%p): semi-stub\n", hIMC
);
1834 return data
->IMC
.fOpen
;
1837 /***********************************************************************
1838 * ImmGetProperty (IMM32.@)
1840 DWORD WINAPI
ImmGetProperty(HKL hKL
, DWORD fdwIndex
)
1845 TRACE("(%p, %d)\n", hKL
, fdwIndex
);
1846 kbd
= IMM_GetImmHkl(hKL
);
1848 if (kbd
&& kbd
->hIME
)
1852 case IGP_PROPERTY
: rc
= kbd
->imeInfo
.fdwProperty
; break;
1853 case IGP_CONVERSION
: rc
= kbd
->imeInfo
.fdwConversionCaps
; break;
1854 case IGP_SENTENCE
: rc
= kbd
->imeInfo
.fdwSentenceCaps
; break;
1855 case IGP_SETCOMPSTR
: rc
= kbd
->imeInfo
.fdwSCSCaps
; break;
1856 case IGP_SELECT
: rc
= kbd
->imeInfo
.fdwSelectCaps
; break;
1857 case IGP_GETIMEVERSION
: rc
= IMEVER_0400
; break;
1858 case IGP_UI
: rc
= 0; break;
1865 /***********************************************************************
1866 * ImmGetRegisterWordStyleA (IMM32.@)
1868 UINT WINAPI
ImmGetRegisterWordStyleA(
1869 HKL hKL
, UINT nItem
, LPSTYLEBUFA lpStyleBuf
)
1871 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1872 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1873 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1875 if (!is_kbd_ime_unicode(immHkl
))
1876 return immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)lpStyleBuf
);
1882 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,&sbw
);
1883 WideCharToMultiByte(CP_ACP
, 0, sbw
.szDescription
, -1,
1884 lpStyleBuf
->szDescription
, 32, NULL
, NULL
);
1885 lpStyleBuf
->dwStyle
= sbw
.dwStyle
;
1893 /***********************************************************************
1894 * ImmGetRegisterWordStyleW (IMM32.@)
1896 UINT WINAPI
ImmGetRegisterWordStyleW(
1897 HKL hKL
, UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
1899 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1900 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1901 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1903 if (is_kbd_ime_unicode(immHkl
))
1904 return immHkl
->pImeGetRegisterWordStyle(nItem
,lpStyleBuf
);
1910 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)&sba
);
1911 MultiByteToWideChar(CP_ACP
, 0, sba
.szDescription
, -1,
1912 lpStyleBuf
->szDescription
, 32);
1913 lpStyleBuf
->dwStyle
= sba
.dwStyle
;
1921 /***********************************************************************
1922 * ImmGetStatusWindowPos (IMM32.@)
1924 BOOL WINAPI
ImmGetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
1926 InputContextData
*data
= get_imc_data(hIMC
);
1928 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
1930 if (!data
|| !lpptPos
)
1933 *lpptPos
= data
->IMC
.ptStatusWndPos
;
1938 /***********************************************************************
1939 * ImmGetVirtualKey (IMM32.@)
1941 UINT WINAPI
ImmGetVirtualKey(HWND hWnd
)
1943 OSVERSIONINFOA version
;
1944 InputContextData
*data
= ImmGetContext( hWnd
);
1945 TRACE("%p\n", hWnd
);
1948 return data
->lastVK
;
1950 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
1951 GetVersionExA( &version
);
1952 switch(version
.dwPlatformId
)
1954 case VER_PLATFORM_WIN32_WINDOWS
:
1955 return VK_PROCESSKEY
;
1956 case VER_PLATFORM_WIN32_NT
:
1959 FIXME("%d not supported\n",version
.dwPlatformId
);
1960 return VK_PROCESSKEY
;
1964 /***********************************************************************
1965 * ImmInstallIMEA (IMM32.@)
1967 HKL WINAPI
ImmInstallIMEA(
1968 LPCSTR lpszIMEFileName
, LPCSTR lpszLayoutText
)
1970 LPWSTR lpszwIMEFileName
;
1971 LPWSTR lpszwLayoutText
;
1974 TRACE ("(%s, %s)\n", debugstr_a(lpszIMEFileName
),
1975 debugstr_a(lpszLayoutText
));
1977 lpszwIMEFileName
= strdupAtoW(lpszIMEFileName
);
1978 lpszwLayoutText
= strdupAtoW(lpszLayoutText
);
1980 hkl
= ImmInstallIMEW(lpszwIMEFileName
, lpszwLayoutText
);
1982 HeapFree(GetProcessHeap(),0,lpszwIMEFileName
);
1983 HeapFree(GetProcessHeap(),0,lpszwLayoutText
);
1987 /***********************************************************************
1988 * ImmInstallIMEW (IMM32.@)
1990 HKL WINAPI
ImmInstallIMEW(
1991 LPCWSTR lpszIMEFileName
, LPCWSTR lpszLayoutText
)
1993 INT lcid
= GetUserDefaultLCID();
1998 WCHAR regKey
[sizeof(szImeRegFmt
)/sizeof(WCHAR
)+8];
2000 TRACE ("(%s, %s):\n", debugstr_w(lpszIMEFileName
),
2001 debugstr_w(lpszLayoutText
));
2003 /* Start with 2. e001 will be blank and so default to the wine internal IME */
2006 while (count
< 0xfff)
2008 DWORD disposition
= 0;
2010 hkl
= (HKL
)MAKELPARAM( lcid
, 0xe000 | count
);
2011 wsprintfW( regKey
, szImeRegFmt
, (ULONG_PTR
)hkl
);
2013 rc
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, regKey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hkey
, &disposition
);
2014 if (rc
== ERROR_SUCCESS
&& disposition
== REG_CREATED_NEW_KEY
)
2016 else if (rc
== ERROR_SUCCESS
)
2024 WARN("Unable to find slot to install IME\n");
2028 if (rc
== ERROR_SUCCESS
)
2030 rc
= RegSetValueExW(hkey
, szImeFileW
, 0, REG_SZ
, (const BYTE
*)lpszIMEFileName
,
2031 (lstrlenW(lpszIMEFileName
) + 1) * sizeof(WCHAR
));
2032 if (rc
== ERROR_SUCCESS
)
2033 rc
= RegSetValueExW(hkey
, szLayoutTextW
, 0, REG_SZ
, (const BYTE
*)lpszLayoutText
,
2034 (lstrlenW(lpszLayoutText
) + 1) * sizeof(WCHAR
));
2040 WARN("Unable to set IME registry values\n");
2045 /***********************************************************************
2046 * ImmIsIME (IMM32.@)
2048 BOOL WINAPI
ImmIsIME(HKL hKL
)
2051 TRACE("(%p):\n", hKL
);
2052 ptr
= IMM_GetImmHkl(hKL
);
2053 return (ptr
&& ptr
->hIME
);
2056 /***********************************************************************
2057 * ImmIsUIMessageA (IMM32.@)
2059 BOOL WINAPI
ImmIsUIMessageA(
2060 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2062 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2063 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2064 (msg
== WM_IME_SETCONTEXT
) ||
2065 (msg
== WM_IME_NOTIFY
) ||
2066 (msg
== WM_IME_COMPOSITIONFULL
) ||
2067 (msg
== WM_IME_SELECT
) ||
2068 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2071 SendMessageA(hWndIME
, msg
, wParam
, lParam
);
2078 /***********************************************************************
2079 * ImmIsUIMessageW (IMM32.@)
2081 BOOL WINAPI
ImmIsUIMessageW(
2082 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2084 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
2085 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
2086 (msg
== WM_IME_SETCONTEXT
) ||
2087 (msg
== WM_IME_NOTIFY
) ||
2088 (msg
== WM_IME_COMPOSITIONFULL
) ||
2089 (msg
== WM_IME_SELECT
) ||
2090 (msg
== 0x287 /* FIXME: WM_IME_SYSTEM */))
2093 SendMessageW(hWndIME
, msg
, wParam
, lParam
);
2100 /***********************************************************************
2101 * ImmNotifyIME (IMM32.@)
2103 BOOL WINAPI
ImmNotifyIME(
2104 HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
2106 InputContextData
*data
= get_imc_data(hIMC
);
2108 TRACE("(%p, %d, %d, %d)\n",
2109 hIMC
, dwAction
, dwIndex
, dwValue
);
2113 SetLastError(ERROR_SUCCESS
);
2117 if (!data
|| ! data
->immKbd
->pNotifyIME
)
2122 return data
->immKbd
->pNotifyIME(hIMC
,dwAction
,dwIndex
,dwValue
);
2125 /***********************************************************************
2126 * ImmRegisterWordA (IMM32.@)
2128 BOOL WINAPI
ImmRegisterWordA(
2129 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszRegister
)
2131 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2132 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2133 debugstr_a(lpszRegister
));
2134 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2136 if (!is_kbd_ime_unicode(immHkl
))
2137 return immHkl
->pImeRegisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2138 (LPCWSTR
)lpszRegister
);
2141 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2142 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
2145 rc
= immHkl
->pImeRegisterWord(lpszwReading
,dwStyle
,lpszwRegister
);
2146 HeapFree(GetProcessHeap(),0,lpszwReading
);
2147 HeapFree(GetProcessHeap(),0,lpszwRegister
);
2155 /***********************************************************************
2156 * ImmRegisterWordW (IMM32.@)
2158 BOOL WINAPI
ImmRegisterWordW(
2159 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
2161 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2162 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2163 debugstr_w(lpszRegister
));
2164 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
2166 if (is_kbd_ime_unicode(immHkl
))
2167 return immHkl
->pImeRegisterWord(lpszReading
,dwStyle
,lpszRegister
);
2170 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2171 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
2174 rc
= immHkl
->pImeRegisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2175 (LPCWSTR
)lpszaRegister
);
2176 HeapFree(GetProcessHeap(),0,lpszaReading
);
2177 HeapFree(GetProcessHeap(),0,lpszaRegister
);
2185 /***********************************************************************
2186 * ImmReleaseContext (IMM32.@)
2188 BOOL WINAPI
ImmReleaseContext(HWND hWnd
, HIMC hIMC
)
2190 static BOOL shown
= FALSE
;
2193 FIXME("(%p, %p): stub\n", hWnd
, hIMC
);
2199 /***********************************************************************
2200 * ImmRequestMessageA(IMM32.@)
2202 LRESULT WINAPI
ImmRequestMessageA(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2204 InputContextData
*data
= get_imc_data(hIMC
);
2206 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2208 if (data
) return SendMessageA(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2210 SetLastError(ERROR_INVALID_HANDLE
);
2214 /***********************************************************************
2215 * ImmRequestMessageW(IMM32.@)
2217 LRESULT WINAPI
ImmRequestMessageW(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
2219 InputContextData
*data
= get_imc_data(hIMC
);
2221 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
2223 if (data
) return SendMessageW(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
2225 SetLastError(ERROR_INVALID_HANDLE
);
2229 /***********************************************************************
2230 * ImmSetCandidateWindow (IMM32.@)
2232 BOOL WINAPI
ImmSetCandidateWindow(
2233 HIMC hIMC
, LPCANDIDATEFORM lpCandidate
)
2235 InputContextData
*data
= get_imc_data(hIMC
);
2237 TRACE("(%p, %p)\n", hIMC
, lpCandidate
);
2239 if (!data
|| !lpCandidate
)
2242 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2245 TRACE("\t%x, %x, %s, %s\n",
2246 lpCandidate
->dwIndex
, lpCandidate
->dwStyle
,
2247 wine_dbgstr_point(&lpCandidate
->ptCurrentPos
),
2248 wine_dbgstr_rect(&lpCandidate
->rcArea
));
2250 if ( lpCandidate
->dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
2253 data
->IMC
.cfCandForm
[lpCandidate
->dwIndex
] = *lpCandidate
;
2254 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCANDIDATEPOS
);
2255 ImmInternalSendIMENotify(data
, IMN_SETCANDIDATEPOS
, 1 << lpCandidate
->dwIndex
);
2260 /***********************************************************************
2261 * ImmSetCompositionFontA (IMM32.@)
2263 BOOL WINAPI
ImmSetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
2265 InputContextData
*data
= get_imc_data(hIMC
);
2266 TRACE("(%p, %p)\n", hIMC
, lplf
);
2270 SetLastError(ERROR_INVALID_HANDLE
);
2274 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2277 memcpy(&data
->IMC
.lfFont
.W
,lplf
,sizeof(LOGFONTA
));
2278 MultiByteToWideChar(CP_ACP
, 0, lplf
->lfFaceName
, -1, data
->IMC
.lfFont
.W
.lfFaceName
,
2280 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2281 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2286 /***********************************************************************
2287 * ImmSetCompositionFontW (IMM32.@)
2289 BOOL WINAPI
ImmSetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
2291 InputContextData
*data
= get_imc_data(hIMC
);
2292 TRACE("(%p, %p)\n", hIMC
, lplf
);
2296 SetLastError(ERROR_INVALID_HANDLE
);
2300 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2303 data
->IMC
.lfFont
.W
= *lplf
;
2304 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
2305 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
2310 /***********************************************************************
2311 * ImmSetCompositionStringA (IMM32.@)
2313 BOOL WINAPI
ImmSetCompositionStringA(
2314 HIMC hIMC
, DWORD dwIndex
,
2315 LPCVOID lpComp
, DWORD dwCompLen
,
2316 LPCVOID lpRead
, DWORD dwReadLen
)
2320 WCHAR
*CompBuffer
= NULL
;
2321 WCHAR
*ReadBuffer
= NULL
;
2323 InputContextData
*data
= get_imc_data(hIMC
);
2325 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2326 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2331 if (!(dwIndex
== SCS_SETSTR
||
2332 dwIndex
== SCS_CHANGEATTR
||
2333 dwIndex
== SCS_CHANGECLAUSE
||
2334 dwIndex
== SCS_SETRECONVERTSTRING
||
2335 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2338 if (!is_himc_ime_unicode(data
))
2339 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2340 dwCompLen
, lpRead
, dwReadLen
);
2342 comp_len
= MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0);
2345 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
* sizeof(WCHAR
));
2346 MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
);
2349 read_len
= MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0);
2352 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
* sizeof(WCHAR
));
2353 MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
);
2356 rc
= ImmSetCompositionStringW(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2357 ReadBuffer
, read_len
);
2359 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2360 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2365 /***********************************************************************
2366 * ImmSetCompositionStringW (IMM32.@)
2368 BOOL WINAPI
ImmSetCompositionStringW(
2369 HIMC hIMC
, DWORD dwIndex
,
2370 LPCVOID lpComp
, DWORD dwCompLen
,
2371 LPCVOID lpRead
, DWORD dwReadLen
)
2375 CHAR
*CompBuffer
= NULL
;
2376 CHAR
*ReadBuffer
= NULL
;
2378 InputContextData
*data
= get_imc_data(hIMC
);
2380 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2381 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2386 if (!(dwIndex
== SCS_SETSTR
||
2387 dwIndex
== SCS_CHANGEATTR
||
2388 dwIndex
== SCS_CHANGECLAUSE
||
2389 dwIndex
== SCS_SETRECONVERTSTRING
||
2390 dwIndex
== SCS_QUERYRECONVERTSTRING
))
2393 if (is_himc_ime_unicode(data
))
2394 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2395 dwCompLen
, lpRead
, dwReadLen
);
2397 comp_len
= WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0, NULL
,
2401 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
);
2402 WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
,
2406 read_len
= WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0, NULL
,
2410 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
);
2411 WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
,
2415 rc
= ImmSetCompositionStringA(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2416 ReadBuffer
, read_len
);
2418 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2419 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2424 /***********************************************************************
2425 * ImmSetCompositionWindow (IMM32.@)
2427 BOOL WINAPI
ImmSetCompositionWindow(
2428 HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
2430 BOOL reshow
= FALSE
;
2431 InputContextData
*data
= get_imc_data(hIMC
);
2433 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
2435 TRACE("\t%x, %s, %s\n", lpCompForm
->dwStyle
,
2436 wine_dbgstr_point(&lpCompForm
->ptCurrentPos
),
2437 wine_dbgstr_rect(&lpCompForm
->rcArea
));
2441 SetLastError(ERROR_INVALID_HANDLE
);
2445 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2448 data
->IMC
.cfCompForm
= *lpCompForm
;
2450 if (IsWindowVisible(data
->immKbd
->UIWnd
))
2453 ShowWindow(data
->immKbd
->UIWnd
,SW_HIDE
);
2456 /* FIXME: this is a partial stub */
2459 ShowWindow(data
->immKbd
->UIWnd
,SW_SHOWNOACTIVATE
);
2461 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONWINDOW
, 0);
2465 /***********************************************************************
2466 * ImmSetConversionStatus (IMM32.@)
2468 BOOL WINAPI
ImmSetConversionStatus(
2469 HIMC hIMC
, DWORD fdwConversion
, DWORD fdwSentence
)
2471 DWORD oldConversion
, oldSentence
;
2472 InputContextData
*data
= get_imc_data(hIMC
);
2474 TRACE("%p %d %d\n", hIMC
, fdwConversion
, fdwSentence
);
2478 SetLastError(ERROR_INVALID_HANDLE
);
2482 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2485 if ( fdwConversion
!= data
->IMC
.fdwConversion
)
2487 oldConversion
= data
->IMC
.fdwConversion
;
2488 data
->IMC
.fdwConversion
= fdwConversion
;
2489 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldConversion
, IMC_SETCONVERSIONMODE
);
2490 ImmInternalSendIMENotify(data
, IMN_SETCONVERSIONMODE
, 0);
2492 if ( fdwSentence
!= data
->IMC
.fdwSentence
)
2494 oldSentence
= data
->IMC
.fdwSentence
;
2495 data
->IMC
.fdwSentence
= fdwSentence
;
2496 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldSentence
, IMC_SETSENTENCEMODE
);
2497 ImmInternalSendIMENotify(data
, IMN_SETSENTENCEMODE
, 0);
2503 /***********************************************************************
2504 * ImmSetOpenStatus (IMM32.@)
2506 BOOL WINAPI
ImmSetOpenStatus(HIMC hIMC
, BOOL fOpen
)
2508 InputContextData
*data
= get_imc_data(hIMC
);
2510 TRACE("%p %d\n", hIMC
, fOpen
);
2514 SetLastError(ERROR_INVALID_HANDLE
);
2518 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2521 if (data
->immKbd
->UIWnd
== NULL
)
2523 /* create the ime window */
2524 data
->immKbd
->UIWnd
= CreateWindowExW( WS_EX_TOOLWINDOW
,
2525 data
->immKbd
->imeClassName
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0,
2526 0, data
->immKbd
->hIME
, 0);
2527 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2530 SetWindowLongPtrW(data
->immKbd
->UIWnd
, IMMGWL_IMC
, (LONG_PTR
)data
);
2532 if (!fOpen
!= !data
->IMC
.fOpen
)
2534 data
->IMC
.fOpen
= fOpen
;
2535 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETOPENSTATUS
);
2536 ImmInternalSendIMENotify(data
, IMN_SETOPENSTATUS
, 0);
2542 /***********************************************************************
2543 * ImmSetStatusWindowPos (IMM32.@)
2545 BOOL WINAPI
ImmSetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
2547 InputContextData
*data
= get_imc_data(hIMC
);
2549 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
2551 if (!data
|| !lpptPos
)
2553 SetLastError(ERROR_INVALID_HANDLE
);
2557 if (IMM_IsCrossThreadAccess(NULL
, hIMC
))
2560 TRACE("\t%s\n", wine_dbgstr_point(lpptPos
));
2562 data
->IMC
.ptStatusWndPos
= *lpptPos
;
2563 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETSTATUSWINDOWPOS
);
2564 ImmInternalSendIMENotify(data
, IMN_SETSTATUSWINDOWPOS
, 0);
2569 /***********************************************************************
2570 * ImmCreateSoftKeyboard(IMM32.@)
2572 HWND WINAPI
ImmCreateSoftKeyboard(UINT uType
, UINT hOwner
, int x
, int y
)
2574 FIXME("(%d, %d, %d, %d): stub\n", uType
, hOwner
, x
, y
);
2575 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2579 /***********************************************************************
2580 * ImmDestroySoftKeyboard(IMM32.@)
2582 BOOL WINAPI
ImmDestroySoftKeyboard(HWND hSoftWnd
)
2584 FIXME("(%p): stub\n", hSoftWnd
);
2585 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2589 /***********************************************************************
2590 * ImmShowSoftKeyboard(IMM32.@)
2592 BOOL WINAPI
ImmShowSoftKeyboard(HWND hSoftWnd
, int nCmdShow
)
2594 FIXME("(%p, %d): stub\n", hSoftWnd
, nCmdShow
);
2595 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2599 /***********************************************************************
2600 * ImmSimulateHotKey (IMM32.@)
2602 BOOL WINAPI
ImmSimulateHotKey(HWND hWnd
, DWORD dwHotKeyID
)
2604 FIXME("(%p, %d): stub\n", hWnd
, dwHotKeyID
);
2605 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2609 /***********************************************************************
2610 * ImmUnregisterWordA (IMM32.@)
2612 BOOL WINAPI
ImmUnregisterWordA(
2613 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszUnregister
)
2615 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2616 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2617 debugstr_a(lpszUnregister
));
2618 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2620 if (!is_kbd_ime_unicode(immHkl
))
2621 return immHkl
->pImeUnregisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2622 (LPCWSTR
)lpszUnregister
);
2625 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2626 LPWSTR lpszwUnregister
= strdupAtoW(lpszUnregister
);
2629 rc
= immHkl
->pImeUnregisterWord(lpszwReading
,dwStyle
,lpszwUnregister
);
2630 HeapFree(GetProcessHeap(),0,lpszwReading
);
2631 HeapFree(GetProcessHeap(),0,lpszwUnregister
);
2639 /***********************************************************************
2640 * ImmUnregisterWordW (IMM32.@)
2642 BOOL WINAPI
ImmUnregisterWordW(
2643 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
2645 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2646 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2647 debugstr_w(lpszUnregister
));
2648 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2650 if (is_kbd_ime_unicode(immHkl
))
2651 return immHkl
->pImeUnregisterWord(lpszReading
,dwStyle
,lpszUnregister
);
2654 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2655 LPSTR lpszaUnregister
= strdupWtoA(lpszUnregister
);
2658 rc
= immHkl
->pImeUnregisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2659 (LPCWSTR
)lpszaUnregister
);
2660 HeapFree(GetProcessHeap(),0,lpszaReading
);
2661 HeapFree(GetProcessHeap(),0,lpszaUnregister
);
2669 /***********************************************************************
2670 * ImmGetImeMenuItemsA (IMM32.@)
2672 DWORD WINAPI
ImmGetImeMenuItemsA( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2673 LPIMEMENUITEMINFOA lpImeParentMenu
, LPIMEMENUITEMINFOA lpImeMenu
,
2676 InputContextData
*data
= get_imc_data(hIMC
);
2677 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2678 lpImeParentMenu
, lpImeMenu
, dwSize
);
2682 SetLastError(ERROR_INVALID_HANDLE
);
2686 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2688 if (!is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2689 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2690 (IMEMENUITEMINFOW
*)lpImeParentMenu
,
2691 (IMEMENUITEMINFOW
*)lpImeMenu
, dwSize
);
2694 IMEMENUITEMINFOW lpImeParentMenuW
;
2695 IMEMENUITEMINFOW
*lpImeMenuW
, *parent
= NULL
;
2698 if (lpImeParentMenu
)
2699 parent
= &lpImeParentMenuW
;
2702 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOA
);
2703 dwSize
= count
* sizeof(IMEMENUITEMINFOW
);
2704 lpImeMenuW
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2709 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2710 parent
, lpImeMenuW
, dwSize
);
2712 if (lpImeParentMenu
)
2714 memcpy(lpImeParentMenu
,&lpImeParentMenuW
,sizeof(IMEMENUITEMINFOA
));
2715 lpImeParentMenu
->hbmpItem
= lpImeParentMenuW
.hbmpItem
;
2716 WideCharToMultiByte(CP_ACP
, 0, lpImeParentMenuW
.szString
,
2717 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
,
2720 if (lpImeMenu
&& rc
)
2723 for (i
= 0; i
< rc
; i
++)
2725 memcpy(&lpImeMenu
[i
],&lpImeMenuW
[1],sizeof(IMEMENUITEMINFOA
));
2726 lpImeMenu
[i
].hbmpItem
= lpImeMenuW
[i
].hbmpItem
;
2727 WideCharToMultiByte(CP_ACP
, 0, lpImeMenuW
[i
].szString
,
2728 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
,
2732 HeapFree(GetProcessHeap(),0,lpImeMenuW
);
2740 /***********************************************************************
2741 * ImmGetImeMenuItemsW (IMM32.@)
2743 DWORD WINAPI
ImmGetImeMenuItemsW( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2744 LPIMEMENUITEMINFOW lpImeParentMenu
, LPIMEMENUITEMINFOW lpImeMenu
,
2747 InputContextData
*data
= get_imc_data(hIMC
);
2748 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2749 lpImeParentMenu
, lpImeMenu
, dwSize
);
2753 SetLastError(ERROR_INVALID_HANDLE
);
2757 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2759 if (is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2760 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2761 lpImeParentMenu
, lpImeMenu
, dwSize
);
2764 IMEMENUITEMINFOA lpImeParentMenuA
;
2765 IMEMENUITEMINFOA
*lpImeMenuA
, *parent
= NULL
;
2768 if (lpImeParentMenu
)
2769 parent
= &lpImeParentMenuA
;
2772 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOW
);
2773 dwSize
= count
* sizeof(IMEMENUITEMINFOA
);
2774 lpImeMenuA
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2779 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2780 (IMEMENUITEMINFOW
*)parent
,
2781 (IMEMENUITEMINFOW
*)lpImeMenuA
, dwSize
);
2783 if (lpImeParentMenu
)
2785 memcpy(lpImeParentMenu
,&lpImeParentMenuA
,sizeof(IMEMENUITEMINFOA
));
2786 lpImeParentMenu
->hbmpItem
= lpImeParentMenuA
.hbmpItem
;
2787 MultiByteToWideChar(CP_ACP
, 0, lpImeParentMenuA
.szString
,
2788 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
);
2790 if (lpImeMenu
&& rc
)
2793 for (i
= 0; i
< rc
; i
++)
2795 memcpy(&lpImeMenu
[i
],&lpImeMenuA
[1],sizeof(IMEMENUITEMINFOA
));
2796 lpImeMenu
[i
].hbmpItem
= lpImeMenuA
[i
].hbmpItem
;
2797 MultiByteToWideChar(CP_ACP
, 0, lpImeMenuA
[i
].szString
,
2798 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
);
2801 HeapFree(GetProcessHeap(),0,lpImeMenuA
);
2809 /***********************************************************************
2810 * ImmLockIMC(IMM32.@)
2812 LPINPUTCONTEXT WINAPI
ImmLockIMC(HIMC hIMC
)
2814 InputContextData
*data
= get_imc_data(hIMC
);
2822 /***********************************************************************
2823 * ImmUnlockIMC(IMM32.@)
2825 BOOL WINAPI
ImmUnlockIMC(HIMC hIMC
)
2827 InputContextData
*data
= get_imc_data(hIMC
);
2836 /***********************************************************************
2837 * ImmGetIMCLockCount(IMM32.@)
2839 DWORD WINAPI
ImmGetIMCLockCount(HIMC hIMC
)
2841 InputContextData
*data
= get_imc_data(hIMC
);
2844 return data
->dwLock
;
2847 /***********************************************************************
2848 * ImmCreateIMCC(IMM32.@)
2850 HIMCC WINAPI
ImmCreateIMCC(DWORD size
)
2852 return GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, size
);
2855 /***********************************************************************
2856 * ImmDestroyIMCC(IMM32.@)
2858 HIMCC WINAPI
ImmDestroyIMCC(HIMCC block
)
2860 return GlobalFree(block
);
2863 /***********************************************************************
2864 * ImmLockIMCC(IMM32.@)
2866 LPVOID WINAPI
ImmLockIMCC(HIMCC imcc
)
2868 return GlobalLock(imcc
);
2871 /***********************************************************************
2872 * ImmUnlockIMCC(IMM32.@)
2874 BOOL WINAPI
ImmUnlockIMCC(HIMCC imcc
)
2876 return GlobalUnlock(imcc
);
2879 /***********************************************************************
2880 * ImmGetIMCCLockCount(IMM32.@)
2882 DWORD WINAPI
ImmGetIMCCLockCount(HIMCC imcc
)
2884 return GlobalFlags(imcc
) & GMEM_LOCKCOUNT
;
2887 /***********************************************************************
2888 * ImmReSizeIMCC(IMM32.@)
2890 HIMCC WINAPI
ImmReSizeIMCC(HIMCC imcc
, DWORD size
)
2892 return GlobalReAlloc(imcc
, size
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
2895 /***********************************************************************
2896 * ImmGetIMCCSize(IMM32.@)
2898 DWORD WINAPI
ImmGetIMCCSize(HIMCC imcc
)
2900 return GlobalSize(imcc
);
2903 /***********************************************************************
2904 * ImmGenerateMessage(IMM32.@)
2906 BOOL WINAPI
ImmGenerateMessage(HIMC hIMC
)
2908 InputContextData
*data
= get_imc_data(hIMC
);
2912 SetLastError(ERROR_INVALID_HANDLE
);
2916 TRACE("%i messages queued\n",data
->IMC
.dwNumMsgBuf
);
2917 if (data
->IMC
.dwNumMsgBuf
> 0)
2919 LPTRANSMSG lpTransMsg
;
2921 DWORD i
, dwNumMsgBuf
;
2923 /* We are going to detach our hMsgBuff so that if processing messages
2924 generates new messages they go into a new buffer */
2925 hMsgBuf
= data
->IMC
.hMsgBuf
;
2926 dwNumMsgBuf
= data
->IMC
.dwNumMsgBuf
;
2928 data
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
2929 data
->IMC
.dwNumMsgBuf
= 0;
2931 lpTransMsg
= ImmLockIMCC(hMsgBuf
);
2932 for (i
= 0; i
< dwNumMsgBuf
; i
++)
2933 ImmInternalSendIMEMessage(data
, lpTransMsg
[i
].message
, lpTransMsg
[i
].wParam
, lpTransMsg
[i
].lParam
);
2935 ImmUnlockIMCC(hMsgBuf
);
2936 ImmDestroyIMCC(hMsgBuf
);
2942 /***********************************************************************
2943 * ImmTranslateMessage(IMM32.@)
2944 * ( Undocumented, call internally and from user32.dll )
2946 BOOL WINAPI
ImmTranslateMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lKeyData
)
2948 InputContextData
*data
;
2949 HIMC imc
= ImmGetContext(hwnd
);
2955 static const DWORD list_count
= 10;
2957 TRACE("%p %x %x %x\n",hwnd
, msg
, (UINT
)wParam
, (UINT
)lKeyData
);
2964 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeToAsciiEx
)
2967 GetKeyboardState(state
);
2968 scancode
= lKeyData
>> 0x10 & 0xff;
2970 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list_count
* sizeof(TRANSMSG
) + sizeof(DWORD
));
2971 ((DWORD
*)list
)[0] = list_count
;
2973 if (data
->immKbd
->imeInfo
.fdwProperty
& IME_PROP_KBD_CHAR_FIRST
)
2977 if (!is_himc_ime_unicode(data
))
2978 ToAscii(data
->lastVK
, scancode
, state
, &chr
, 0);
2980 ToUnicodeEx(data
->lastVK
, scancode
, state
, &chr
, 1, 0, GetKeyboardLayout(0));
2981 uVirtKey
= MAKELONG(data
->lastVK
,chr
);
2984 uVirtKey
= data
->lastVK
;
2986 msg_count
= data
->immKbd
->pImeToAsciiEx(uVirtKey
, scancode
, state
, list
, 0, imc
);
2987 TRACE("%i messages generated\n",msg_count
);
2988 if (msg_count
&& msg_count
<= list_count
)
2991 LPTRANSMSG msgs
= (LPTRANSMSG
)((LPBYTE
)list
+ sizeof(DWORD
));
2993 for (i
= 0; i
< msg_count
; i
++)
2994 ImmInternalPostIMEMessage(data
, msgs
[i
].message
, msgs
[i
].wParam
, msgs
[i
].lParam
);
2996 else if (msg_count
> list_count
)
2997 ImmGenerateMessage(imc
);
2999 HeapFree(GetProcessHeap(),0,list
);
3001 data
->lastVK
= VK_PROCESSKEY
;
3003 return (msg_count
> 0);
3006 /***********************************************************************
3007 * ImmProcessKey(IMM32.@)
3008 * ( Undocumented, called from user32.dll )
3010 BOOL WINAPI
ImmProcessKey(HWND hwnd
, HKL hKL
, UINT vKey
, LPARAM lKeyData
, DWORD unknown
)
3012 InputContextData
*data
;
3013 HIMC imc
= ImmGetContext(hwnd
);
3016 TRACE("%p %p %x %x %x\n",hwnd
, hKL
, vKey
, (UINT
)lKeyData
, unknown
);
3023 /* Make sure we are inputting to the correct keyboard */
3024 if (data
->immKbd
->hkl
!= hKL
)
3026 ImmHkl
*new_hkl
= IMM_GetImmHkl(hKL
);
3029 data
->immKbd
->pImeSelect(imc
, FALSE
);
3030 data
->immKbd
->uSelected
--;
3031 data
->immKbd
= new_hkl
;
3032 data
->immKbd
->pImeSelect(imc
, TRUE
);
3033 data
->immKbd
->uSelected
++;
3039 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeProcessKey
)
3042 GetKeyboardState(state
);
3043 if (data
->immKbd
->pImeProcessKey(imc
, vKey
, lKeyData
, state
))
3045 data
->lastVK
= vKey
;
3049 data
->lastVK
= VK_PROCESSKEY
;
3053 /***********************************************************************
3054 * ImmDisableTextFrameService(IMM32.@)
3056 BOOL WINAPI
ImmDisableTextFrameService(DWORD idThread
)
3062 /***********************************************************************
3063 * ImmEnumInputContext(IMM32.@)
3066 BOOL WINAPI
ImmEnumInputContext(DWORD idThread
, IMCENUMPROC lpfn
, LPARAM lParam
)
3072 /***********************************************************************
3073 * ImmGetHotKey(IMM32.@)
3076 BOOL WINAPI
ImmGetHotKey(DWORD hotkey
, UINT
*modifiers
, UINT
*key
, HKL hkl
)
3078 FIXME("%x, %p, %p, %p: stub\n", hotkey
, modifiers
, key
, hkl
);