4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2002, 2003, 2007 CodeWeavers, Aric Stewart
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
35 #include "wine/list.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(imm
);
39 typedef struct tagIMCCInternal
45 #define MAKE_FUNCPTR(f) typeof(f) * p##f
46 typedef struct _tagImmHkl
{
51 WCHAR imeClassName
[17]; /* 16 character max */
54 /* Function Pointers */
55 MAKE_FUNCPTR(ImeInquire
);
56 MAKE_FUNCPTR(ImeConfigure
);
57 MAKE_FUNCPTR(ImeDestroy
);
58 MAKE_FUNCPTR(ImeEscape
);
59 MAKE_FUNCPTR(ImeSelect
);
60 MAKE_FUNCPTR(ImeSetActiveContext
);
61 MAKE_FUNCPTR(ImeToAsciiEx
);
62 MAKE_FUNCPTR(NotifyIME
);
63 MAKE_FUNCPTR(ImeRegisterWord
);
64 MAKE_FUNCPTR(ImeUnregisterWord
);
65 MAKE_FUNCPTR(ImeEnumRegisterWord
);
66 MAKE_FUNCPTR(ImeSetCompositionString
);
67 MAKE_FUNCPTR(ImeConversionList
);
68 MAKE_FUNCPTR(ImeProcessKey
);
69 MAKE_FUNCPTR(ImeGetRegisterWordStyle
);
70 MAKE_FUNCPTR(ImeGetImeMenuItems
);
74 typedef struct tagInputContextData
84 typedef struct _tagTRANSMSG
{
88 } TRANSMSG
, *LPTRANSMSG
;
90 typedef struct _tagIMMThreadData
{
95 static DWORD tlsIndex
= 0;
96 static struct list ImmHklList
= LIST_INIT(ImmHklList
);
99 static UINT WM_MSIME_SERVICE
;
100 static UINT WM_MSIME_RECONVERTOPTIONS
;
101 static UINT WM_MSIME_MOUSE
;
102 static UINT WM_MSIME_RECONVERTREQUEST
;
103 static UINT WM_MSIME_RECONVERT
;
104 static UINT WM_MSIME_QUERYPOSITION
;
105 static UINT WM_MSIME_DOCUMENTFEED
;
107 static const WCHAR szwWineIMCProperty
[] = {'W','i','n','e','I','m','m','H','I','M','C','P','r','o','p','e','r','t','y',0};
109 #define is_himc_ime_unicode(p) (p->immKbd->imeInfo.fdwProperty & IME_PROP_UNICODE)
110 #define is_kbd_ime_unicode(p) (p->imeInfo.fdwProperty & IME_PROP_UNICODE)
112 static BOOL
IMM_DestroyContext(HIMC hIMC
);
114 static inline WCHAR
*strdupAtoW( const char *str
)
119 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
120 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
121 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
126 static inline CHAR
*strdupWtoA( const WCHAR
*str
)
131 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
132 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
133 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
138 static DWORD
convert_candidatelist_WtoA(
139 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
143 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
144 if ( lpDst
&& dwBufLen
> 0 )
147 lpDst
->dwOffset
[0] = ret
;
150 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
152 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
154 if ( lpDst
&& dwBufLen
> 0 )
156 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
158 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1,
159 (LPSTR
)dest
, dwBufLen
, NULL
, NULL
);
161 if ( i
+ 1 < lpSrc
->dwCount
)
162 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(char);
163 dwBufLen
-= len
* sizeof(char);
166 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)src
, -1, NULL
, 0, NULL
, NULL
);
168 ret
+= len
* sizeof(char);
177 static DWORD
convert_candidatelist_AtoW(
178 LPCANDIDATELIST lpSrc
, LPCANDIDATELIST lpDst
, DWORD dwBufLen
)
182 ret
= FIELD_OFFSET( CANDIDATELIST
, dwOffset
[lpSrc
->dwCount
] );
183 if ( lpDst
&& dwBufLen
> 0 )
186 lpDst
->dwOffset
[0] = ret
;
189 for ( i
= 0; i
< lpSrc
->dwCount
; i
++)
191 LPBYTE src
= (LPBYTE
)lpSrc
+ lpSrc
->dwOffset
[i
];
193 if ( lpDst
&& dwBufLen
> 0 )
195 LPBYTE dest
= (LPBYTE
)lpDst
+ lpDst
->dwOffset
[i
];
197 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1,
198 (LPWSTR
)dest
, dwBufLen
);
200 if ( i
+ 1 < lpSrc
->dwCount
)
201 lpDst
->dwOffset
[i
+1] = lpDst
->dwOffset
[i
] + len
* sizeof(WCHAR
);
202 dwBufLen
-= len
* sizeof(WCHAR
);
205 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, NULL
, 0);
207 ret
+= len
* sizeof(WCHAR
);
216 static IMMThreadData
* IMM_GetThreadData(void)
218 return (IMMThreadData
*)TlsGetValue(tlsIndex
);
221 static void IMM_InitThreadData(void)
223 IMMThreadData
* data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
224 sizeof(IMMThreadData
));
225 TlsSetValue(tlsIndex
,data
);
227 TRACE("Thread Data Created\n");
230 static void IMM_FreeThreadData(void)
232 IMMThreadData
* data
= TlsGetValue(tlsIndex
);
233 IMM_DestroyContext(data
->defaultContext
);
234 DestroyWindow(data
->hwndDefault
);
235 HeapFree(GetProcessHeap(),0,data
);
236 TRACE("Thread Data Destroyed\n");
239 static HMODULE
LoadDefaultWineIME(void)
241 char buffer
[MAX_PATH
], libname
[32], *name
, *next
;
245 TRACE("Attempting to fall back to wine default IME\n");
247 strcpy( buffer
, "x11" ); /* default value */
248 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
249 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Drivers", &hkey
))
251 DWORD type
, count
= sizeof(buffer
);
252 RegQueryValueExA( hkey
, "Ime", 0, &type
, (LPBYTE
) buffer
, &count
);
259 next
= strchr( name
, ',' );
260 if (next
) *next
++ = 0;
262 snprintf( libname
, sizeof(libname
), "wine%s.drv", name
);
263 if ((module
= LoadLibraryA( libname
)) != 0) break;
270 /* ImmHkl loading and freeing */
271 #define LOAD_FUNCPTR(f) if((ptr->p##f = (LPVOID)GetProcAddress(ptr->hIME, #f)) == NULL){WARN("Can't find function %s in ime\n", #f);}
272 static ImmHkl
*IMM_GetImmHkl(HKL hkl
)
275 WCHAR filename
[MAX_PATH
];
277 TRACE("Seeking ime for keyboard 0x%x\n",(unsigned)hkl
);
279 LIST_FOR_EACH_ENTRY(ptr
, &ImmHklList
, ImmHkl
, entry
)
284 /* not found... create it */
286 ptr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ImmHkl
));
289 if (ImmGetIMEFileNameW(hkl
, filename
, MAX_PATH
)) ptr
->hIME
= LoadLibraryW(filename
);
291 ptr
->hIME
= LoadDefaultWineIME();
294 LOAD_FUNCPTR(ImeInquire
);
295 if (!ptr
->pImeInquire
|| !ptr
->pImeInquire(&ptr
->imeInfo
, ptr
->imeClassName
, NULL
))
297 FreeLibrary(ptr
->hIME
);
302 LOAD_FUNCPTR(ImeDestroy
);
303 LOAD_FUNCPTR(ImeSelect
);
304 if (!ptr
->pImeSelect
|| !ptr
->pImeDestroy
)
306 FreeLibrary(ptr
->hIME
);
311 LOAD_FUNCPTR(ImeConfigure
);
312 LOAD_FUNCPTR(ImeEscape
);
313 LOAD_FUNCPTR(ImeSetActiveContext
);
314 LOAD_FUNCPTR(ImeToAsciiEx
);
315 LOAD_FUNCPTR(NotifyIME
);
316 LOAD_FUNCPTR(ImeRegisterWord
);
317 LOAD_FUNCPTR(ImeUnregisterWord
);
318 LOAD_FUNCPTR(ImeEnumRegisterWord
);
319 LOAD_FUNCPTR(ImeSetCompositionString
);
320 LOAD_FUNCPTR(ImeConversionList
);
321 LOAD_FUNCPTR(ImeProcessKey
);
322 LOAD_FUNCPTR(ImeGetRegisterWordStyle
);
323 LOAD_FUNCPTR(ImeGetImeMenuItems
);
324 /* make sure our classname is WCHAR */
325 if (!is_kbd_ime_unicode(ptr
))
328 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ptr
->imeClassName
,
330 lstrcpyW(ptr
->imeClassName
, bufW
);
335 list_add_head(&ImmHklList
,&ptr
->entry
);
341 static void IMM_FreeAllImmHkl(void)
343 ImmHkl
*ptr
,*cursor2
;
345 LIST_FOR_EACH_ENTRY_SAFE(ptr
, cursor2
, &ImmHklList
, ImmHkl
, entry
)
347 list_remove(&ptr
->entry
);
351 FreeLibrary(ptr
->hIME
);
353 HeapFree(GetProcessHeap(),0,ptr
);
357 static void IMM_RegisterMessages(void)
359 WM_MSIME_SERVICE
= RegisterWindowMessageA("MSIMEService");
360 WM_MSIME_RECONVERTOPTIONS
= RegisterWindowMessageA("MSIMEReconvertOptions");
361 WM_MSIME_MOUSE
= RegisterWindowMessageA("MSIMEMouseOperation");
362 WM_MSIME_RECONVERTREQUEST
= RegisterWindowMessageA("MSIMEReconvertRequest");
363 WM_MSIME_RECONVERT
= RegisterWindowMessageA("MSIMEReconvert");
364 WM_MSIME_QUERYPOSITION
= RegisterWindowMessageA("MSIMEQueryPosition");
365 WM_MSIME_DOCUMENTFEED
= RegisterWindowMessageA("MSIMEDocumentFeed");
368 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
370 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
373 case DLL_PROCESS_ATTACH
:
374 IMM_RegisterMessages();
375 tlsIndex
= TlsAlloc();
376 IMM_InitThreadData();
378 case DLL_THREAD_ATTACH
:
379 IMM_InitThreadData();
381 case DLL_THREAD_DETACH
:
382 IMM_FreeThreadData();
384 case DLL_PROCESS_DETACH
:
385 IMM_FreeThreadData();
393 /* for posting messages as the IME */
394 static void ImmInternalPostIMEMessage(InputContextData
*data
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
396 HWND target
= GetFocus();
398 PostMessageW(data
->IMC
.hWnd
,msg
,wParam
,lParam
);
400 PostMessageW(target
, msg
, wParam
, lParam
);
403 static LRESULT
ImmInternalSendIMENotify(InputContextData
*data
, WPARAM notify
, LPARAM lParam
)
407 target
= data
->IMC
.hWnd
;
408 if (!target
) target
= GetFocus();
411 return SendMessageW(target
, WM_IME_NOTIFY
, notify
, lParam
);
416 static HIMCC
ImmCreateBlankCompStr(void)
419 LPCOMPOSITIONSTRING ptr
;
420 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
421 ptr
= (LPCOMPOSITIONSTRING
)ImmLockIMCC(rc
);
422 memset(ptr
,0,sizeof(COMPOSITIONSTRING
));
423 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
428 /***********************************************************************
429 * ImmAssociateContext (IMM32.@)
431 HIMC WINAPI
ImmAssociateContext(HWND hWnd
, HIMC hIMC
)
434 InputContextData
*data
= (InputContextData
*)hIMC
;
436 TRACE("(%p, %p):\n", hWnd
, hIMC
);
438 if (!IMM_GetThreadData()->defaultContext
)
439 IMM_GetThreadData()->defaultContext
= ImmCreateContext();
442 * If already associated just return
444 if (hIMC
&& data
->IMC
.hWnd
== hWnd
)
449 old
= (HIMC
)RemovePropW(hWnd
,szwWineIMCProperty
);
452 old
= IMM_GetThreadData()->defaultContext
;
453 else if (old
== (HIMC
)-1)
456 if (hIMC
!= IMM_GetThreadData()->defaultContext
)
458 if (hIMC
== NULL
) /* Meaning disable imm for that window*/
459 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)-1);
461 SetPropW(hWnd
,szwWineIMCProperty
,(HANDLE
)hIMC
);
466 InputContextData
*old_data
= (InputContextData
*)old
;
467 if (old_data
->IMC
.hWnd
== hWnd
)
468 old_data
->IMC
.hWnd
= NULL
;
475 if (IsWindow(data
->IMC
.hWnd
))
478 * Post a message that your context is switching
480 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, FALSE
, ISC_SHOWUIALL
);
483 data
->IMC
.hWnd
= hWnd
;
485 if (IsWindow(data
->IMC
.hWnd
))
488 * Post a message that your context is switching
490 SendMessageW(data
->IMC
.hWnd
, WM_IME_SETCONTEXT
, TRUE
, ISC_SHOWUIALL
);
496 /***********************************************************************
497 * ImmAssociateContextEx (IMM32.@)
499 BOOL WINAPI
ImmAssociateContextEx(HWND hWnd
, HIMC hIMC
, DWORD dwFlags
)
501 FIXME("(%p, %p, %d): stub\n", hWnd
, hIMC
, dwFlags
);
502 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
506 /***********************************************************************
507 * ImmConfigureIMEA (IMM32.@)
509 BOOL WINAPI
ImmConfigureIMEA(
510 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
512 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
514 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
516 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
519 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
521 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| !is_kbd_ime_unicode(immHkl
))
522 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
526 REGISTERWORDA
*rwa
= (REGISTERWORDA
*)lpData
;
529 rww
.lpReading
= strdupAtoW(rwa
->lpReading
);
530 rww
.lpWord
= strdupAtoW(rwa
->lpWord
);
531 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rww
);
532 HeapFree(GetProcessHeap(),0,rww
.lpReading
);
533 HeapFree(GetProcessHeap(),0,rww
.lpWord
);
541 /***********************************************************************
542 * ImmConfigureIMEW (IMM32.@)
544 BOOL WINAPI
ImmConfigureIMEW(
545 HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
547 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
549 TRACE("(%p, %p, %d, %p):\n", hKL
, hWnd
, dwMode
, lpData
);
551 if (dwMode
== IME_CONFIG_REGISTERWORD
&& !lpData
)
554 if (immHkl
->hIME
&& immHkl
->pImeConfigure
)
556 if (dwMode
!= IME_CONFIG_REGISTERWORD
|| is_kbd_ime_unicode(immHkl
))
557 return immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,lpData
);
560 REGISTERWORDW
*rww
= (REGISTERWORDW
*)lpData
;
564 rwa
.lpReading
= strdupWtoA(rww
->lpReading
);
565 rwa
.lpWord
= strdupWtoA(rww
->lpWord
);
566 rc
= immHkl
->pImeConfigure(hKL
,hWnd
,dwMode
,&rwa
);
567 HeapFree(GetProcessHeap(),0,rwa
.lpReading
);
568 HeapFree(GetProcessHeap(),0,rwa
.lpWord
);
576 /***********************************************************************
577 * ImmCreateContext (IMM32.@)
579 HIMC WINAPI
ImmCreateContext(void)
581 InputContextData
*new_context
;
585 new_context
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputContextData
));
588 new_context
->immKbd
= IMM_GetImmHkl(GetKeyboardLayout(0));
590 if (!new_context
->immKbd
->hIME
)
592 TRACE("IME dll could not be loaded\n");
593 HeapFree(GetProcessHeap(),0,new_context
);
597 /* the HIMCCs are never NULL */
598 new_context
->IMC
.hCompStr
= ImmCreateBlankCompStr();
599 new_context
->IMC
.hMsgBuf
= ImmCreateIMCC(0);
600 new_context
->IMC
.hCandInfo
= ImmCreateIMCC(sizeof(CANDIDATEINFO
));
601 ci
= ImmLockIMCC(new_context
->IMC
.hCandInfo
);
602 memset(ci
,0,sizeof(CANDIDATEINFO
));
603 ci
->dwSize
= sizeof(CANDIDATEINFO
);
604 ImmUnlockIMCC(new_context
->IMC
.hCandInfo
);
605 new_context
->IMC
.hGuideLine
= ImmCreateIMCC(sizeof(GUIDELINE
));
606 gl
= ImmLockIMCC(new_context
->IMC
.hGuideLine
);
607 memset(gl
,0,sizeof(GUIDELINE
));
608 gl
->dwSize
= sizeof(GUIDELINE
);
609 ImmUnlockIMCC(new_context
->IMC
.hGuideLine
);
611 /* Initialize the IME Private */
612 new_context
->IMC
.hPrivate
= ImmCreateIMCC(new_context
->immKbd
->imeInfo
.dwPrivateDataSize
);
614 if (!new_context
->immKbd
->pImeSelect(new_context
, TRUE
))
616 TRACE("Selection of IME failed\n");
617 IMM_DestroyContext(new_context
);
621 new_context
->immKbd
->uSelected
++;
622 TRACE("Created context 0x%x\n",(UINT
)new_context
);
624 return (HIMC
)new_context
;
627 static BOOL
IMM_DestroyContext(HIMC hIMC
)
629 InputContextData
*data
= (InputContextData
*)hIMC
;
631 TRACE("Destroying %p\n",hIMC
);
635 data
->immKbd
->uSelected
--;
636 data
->immKbd
->pImeSelect(hIMC
, FALSE
);
638 if (IMM_GetThreadData()->hwndDefault
== data
->imeWnd
)
639 IMM_GetThreadData()->hwndDefault
= NULL
;
640 DestroyWindow(data
->imeWnd
);
642 ImmDestroyIMCC(data
->IMC
.hCompStr
);
643 ImmDestroyIMCC(data
->IMC
.hCandInfo
);
644 ImmDestroyIMCC(data
->IMC
.hGuideLine
);
645 ImmDestroyIMCC(data
->IMC
.hPrivate
);
646 ImmDestroyIMCC(data
->IMC
.hMsgBuf
);
648 HeapFree(GetProcessHeap(),0,data
);
653 /***********************************************************************
654 * ImmDestroyContext (IMM32.@)
656 BOOL WINAPI
ImmDestroyContext(HIMC hIMC
)
658 if (hIMC
!= IMM_GetThreadData()->defaultContext
)
659 return IMM_DestroyContext(hIMC
);
664 /***********************************************************************
665 * ImmDisableIME (IMM32.@)
667 BOOL WINAPI
ImmDisableIME(DWORD idThread
)
669 FIXME("(%d): stub\n", idThread
);
673 /***********************************************************************
674 * ImmEnumRegisterWordA (IMM32.@)
676 UINT WINAPI
ImmEnumRegisterWordA(
677 HKL hKL
, REGISTERWORDENUMPROCA lpfnEnumProc
,
678 LPCSTR lpszReading
, DWORD dwStyle
,
679 LPCSTR lpszRegister
, LPVOID lpData
)
681 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
682 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
683 debugstr_a(lpszReading
), dwStyle
, debugstr_a(lpszRegister
), lpData
);
684 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
686 if (!is_kbd_ime_unicode(immHkl
))
687 return immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
688 (LPCWSTR
)lpszReading
, dwStyle
, (LPCWSTR
)lpszRegister
, lpData
);
691 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
692 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
695 rc
= immHkl
->pImeEnumRegisterWord((REGISTERWORDENUMPROCW
)lpfnEnumProc
,
696 lpszwReading
, dwStyle
, lpszwRegister
,
699 HeapFree(GetProcessHeap(),0,lpszwReading
);
700 HeapFree(GetProcessHeap(),0,lpszwRegister
);
708 /***********************************************************************
709 * ImmEnumRegisterWordW (IMM32.@)
711 UINT WINAPI
ImmEnumRegisterWordW(
712 HKL hKL
, REGISTERWORDENUMPROCW lpfnEnumProc
,
713 LPCWSTR lpszReading
, DWORD dwStyle
,
714 LPCWSTR lpszRegister
, LPVOID lpData
)
716 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
717 TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL
, lpfnEnumProc
,
718 debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
), lpData
);
719 if (immHkl
->hIME
&& immHkl
->pImeEnumRegisterWord
)
721 if (is_kbd_ime_unicode(immHkl
))
722 return immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, lpszReading
, dwStyle
,
723 lpszRegister
, lpData
);
726 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
727 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
730 rc
= immHkl
->pImeEnumRegisterWord(lpfnEnumProc
, (LPCWSTR
)lpszaReading
,
731 dwStyle
, (LPCWSTR
)lpszaRegister
, lpData
);
733 HeapFree(GetProcessHeap(),0,lpszaReading
);
734 HeapFree(GetProcessHeap(),0,lpszaRegister
);
742 /***********************************************************************
743 * ImmEscapeA (IMM32.@)
745 LRESULT WINAPI
ImmEscapeA(
747 UINT uEscape
, LPVOID lpData
)
749 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
750 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
752 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
754 if (!is_kbd_ime_unicode(immHkl
))
755 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
758 FIXME("A procedure called with W ime back end\n");
759 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
767 /***********************************************************************
768 * ImmEscapeW (IMM32.@)
770 LRESULT WINAPI
ImmEscapeW(
772 UINT uEscape
, LPVOID lpData
)
774 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
775 TRACE("(%p, %p, %d, %p):\n", hKL
, hIMC
, uEscape
, lpData
);
777 if (immHkl
->hIME
&& immHkl
->pImeEscape
)
779 if (is_kbd_ime_unicode(immHkl
))
780 return immHkl
->pImeEscape(hIMC
,uEscape
,lpData
);
783 FIXME("W procedure called with A ime back end\n");
784 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
792 /***********************************************************************
793 * ImmGetCandidateListA (IMM32.@)
795 DWORD WINAPI
ImmGetCandidateListA(
796 HIMC hIMC
, DWORD dwIndex
,
797 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
799 InputContextData
*data
= (InputContextData
*)hIMC
;
800 LPCANDIDATEINFO candinfo
;
801 LPCANDIDATELIST candlist
;
804 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
806 if (!data
|| !data
->IMC
.hCandInfo
)
809 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
810 if ( dwIndex
>= candinfo
->dwCount
||
811 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
814 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
815 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
818 if ( !is_himc_ime_unicode(data
) )
820 ret
= candlist
->dwSize
;
821 if ( lpCandList
&& dwBufLen
>= ret
)
822 memcpy(lpCandList
, candlist
, ret
);
825 ret
= convert_candidatelist_WtoA( candlist
, lpCandList
, dwBufLen
);
828 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
832 /***********************************************************************
833 * ImmGetCandidateListCountA (IMM32.@)
835 DWORD WINAPI
ImmGetCandidateListCountA(
836 HIMC hIMC
, LPDWORD lpdwListCount
)
838 InputContextData
*data
= (InputContextData
*)hIMC
;
839 LPCANDIDATEINFO candinfo
;
842 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
844 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
847 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
849 *lpdwListCount
= count
= candinfo
->dwCount
;
851 if ( !is_himc_ime_unicode(data
) )
852 ret
= candinfo
->dwSize
;
855 ret
= sizeof(CANDIDATEINFO
);
857 ret
+= ImmGetCandidateListA(hIMC
, count
, NULL
, 0);
860 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
864 /***********************************************************************
865 * ImmGetCandidateListCountW (IMM32.@)
867 DWORD WINAPI
ImmGetCandidateListCountW(
868 HIMC hIMC
, LPDWORD lpdwListCount
)
870 InputContextData
*data
= (InputContextData
*)hIMC
;
871 LPCANDIDATEINFO candinfo
;
874 TRACE("%p, %p\n", hIMC
, lpdwListCount
);
876 if (!data
|| !lpdwListCount
|| !data
->IMC
.hCandInfo
)
879 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
881 *lpdwListCount
= count
= candinfo
->dwCount
;
883 if ( is_himc_ime_unicode(data
) )
884 ret
= candinfo
->dwSize
;
887 ret
= sizeof(CANDIDATEINFO
);
889 ret
+= ImmGetCandidateListW(hIMC
, count
, NULL
, 0);
892 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
896 /***********************************************************************
897 * ImmGetCandidateListW (IMM32.@)
899 DWORD WINAPI
ImmGetCandidateListW(
900 HIMC hIMC
, DWORD dwIndex
,
901 LPCANDIDATELIST lpCandList
, DWORD dwBufLen
)
903 InputContextData
*data
= (InputContextData
*)hIMC
;
904 LPCANDIDATEINFO candinfo
;
905 LPCANDIDATELIST candlist
;
908 TRACE("%p, %d, %p, %d\n", hIMC
, dwIndex
, lpCandList
, dwBufLen
);
910 if (!data
|| !data
->IMC
.hCandInfo
)
913 candinfo
= ImmLockIMCC(data
->IMC
.hCandInfo
);
914 if ( dwIndex
>= candinfo
->dwCount
||
915 dwIndex
>= (sizeof(candinfo
->dwOffset
) / sizeof(DWORD
)) )
918 candlist
= (LPCANDIDATELIST
)((LPBYTE
)candinfo
+ candinfo
->dwOffset
[dwIndex
]);
919 if ( !candlist
->dwSize
|| !candlist
->dwCount
)
922 if ( is_himc_ime_unicode(data
) )
924 ret
= candlist
->dwSize
;
925 if ( lpCandList
&& dwBufLen
>= ret
)
926 memcpy(lpCandList
, candlist
, ret
);
929 ret
= convert_candidatelist_AtoW( candlist
, lpCandList
, dwBufLen
);
932 ImmUnlockIMCC(data
->IMC
.hCandInfo
);
936 /***********************************************************************
937 * ImmGetCandidateWindow (IMM32.@)
939 BOOL WINAPI
ImmGetCandidateWindow(
940 HIMC hIMC
, DWORD dwIndex
, LPCANDIDATEFORM lpCandidate
)
942 InputContextData
*data
= (InputContextData
*)hIMC
;
944 TRACE("%p, %d, %p\n", hIMC
, dwIndex
, lpCandidate
);
946 if (!data
|| !lpCandidate
)
949 if ( dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
952 *lpCandidate
= data
->IMC
.cfCandForm
[dwIndex
];
957 /***********************************************************************
958 * ImmGetCompositionFontA (IMM32.@)
960 BOOL WINAPI
ImmGetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
965 TRACE("(%p, %p):\n", hIMC
, lplf
);
967 rc
= ImmGetCompositionFontW(hIMC
,&lfW
);
971 memcpy(lplf
,&lfW
,sizeof(LOGFONTA
));
972 WideCharToMultiByte(CP_ACP
, 0, lfW
.lfFaceName
, -1, lplf
->lfFaceName
,
973 LF_FACESIZE
, NULL
, NULL
);
977 /***********************************************************************
978 * ImmGetCompositionFontW (IMM32.@)
980 BOOL WINAPI
ImmGetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
982 InputContextData
*data
= (InputContextData
*)hIMC
;
984 TRACE("(%p, %p):\n", hIMC
, lplf
);
989 *lplf
= data
->IMC
.lfFont
.W
;
995 /* Helpers for the GetCompositionString functions */
997 static INT
CopyCompStringIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE target
, INT tlen
,
1002 if (is_himc_ime_unicode(data
) && !unicode
)
1003 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)source
, slen
, (LPSTR
)target
, tlen
, NULL
, NULL
);
1004 else if (!is_himc_ime_unicode(data
) && unicode
)
1005 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)source
, slen
, (LPWSTR
)target
, tlen
) * sizeof(WCHAR
);
1008 int dlen
= (unicode
)?sizeof(WCHAR
):sizeof(CHAR
);
1009 memcpy( target
, source
, min(slen
,tlen
)*dlen
);
1016 static INT
CopyCompAttrIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1017 LPBYTE target
, INT tlen
, BOOL unicode
)
1021 if (is_himc_ime_unicode(data
) && !unicode
)
1023 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, sslen
, NULL
, 0, NULL
, NULL
);
1026 const BYTE
*src
= source
;
1027 LPBYTE dst
= target
;
1028 int i
, j
= 0, k
= 0;
1032 for (i
= 0; i
< sslen
; ++i
)
1036 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)ssource
+ i
, 1,
1037 NULL
, 0, NULL
, NULL
);
1038 for (; len
> 0; --len
)
1051 else if (!is_himc_ime_unicode(data
) && unicode
)
1053 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, sslen
, NULL
, 0);
1056 const BYTE
*src
= source
;
1057 LPBYTE dst
= target
;
1062 for (i
= 0; i
< sslen
; ++i
)
1064 if (IsDBCSLeadByte(((LPSTR
)ssource
)[i
]))
1077 memcpy( target
, source
, min(slen
,tlen
));
1084 static INT
CopyCompClauseIMEtoClient(InputContextData
*data
, LPBYTE source
, INT slen
, LPBYTE ssource
, INT sslen
,
1085 LPBYTE target
, INT tlen
, BOOL unicode
)
1089 if (is_himc_ime_unicode(data
) && !unicode
)
1097 tlen
/= sizeof (DWORD
);
1098 for (i
= 0; i
< tlen
; ++i
)
1100 ((DWORD
*)target
)[i
] = WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
,
1101 ((DWORD
*)source
)[i
],
1105 rc
= sizeof (DWORD
) * i
;
1110 else if (!is_himc_ime_unicode(data
) && unicode
)
1118 tlen
/= sizeof (DWORD
);
1119 for (i
= 0; i
< tlen
; ++i
)
1121 ((DWORD
*)target
)[i
] = MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
,
1122 ((DWORD
*)source
)[i
],
1125 rc
= sizeof (DWORD
) * i
;
1132 memcpy( target
, source
, min(slen
,tlen
));
1139 static INT
CopyCompOffsetIMEtoClient(InputContextData
*data
, DWORD offset
, LPBYTE ssource
, BOOL unicode
)
1143 if (is_himc_ime_unicode(data
) && !unicode
)
1145 rc
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)ssource
, offset
, NULL
, 0, NULL
, NULL
);
1147 else if (!is_himc_ime_unicode(data
) && unicode
)
1149 rc
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ssource
, offset
, NULL
, 0);
1157 static LONG
ImmGetCompositionStringT( HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
,
1158 DWORD dwBufLen
, BOOL unicode
)
1161 InputContextData
*data
= (InputContextData
*)hIMC
;
1162 LPCOMPOSITIONSTRING compstr
;
1165 TRACE("(%p, 0x%x, %p, %d)\n", hIMC
, dwIndex
, lpBuf
, dwBufLen
);
1170 if (!data
->IMC
.hCompStr
)
1173 compdata
= ImmLockIMCC(data
->IMC
.hCompStr
);
1174 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1179 TRACE("GCS_RESULTSTR\n");
1180 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
, lpBuf
, dwBufLen
, unicode
);
1183 TRACE("GCS_COMPSTR\n");
1184 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
, lpBuf
, dwBufLen
, unicode
);
1187 TRACE("GCS_COMPATTR\n");
1188 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompAttrOffset
, compstr
->dwCompAttrLen
,
1189 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1190 lpBuf
, dwBufLen
, unicode
);
1192 case GCS_COMPCLAUSE
:
1193 TRACE("GCS_COMPCLAUSE\n");
1194 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompClauseOffset
,compstr
->dwCompClauseLen
,
1195 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1196 lpBuf
, dwBufLen
, unicode
);
1198 case GCS_RESULTCLAUSE
:
1199 TRACE("GCS_RESULTCLAUSE\n");
1200 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultClauseOffset
,compstr
->dwResultClauseLen
,
1201 compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
,
1202 lpBuf
, dwBufLen
, unicode
);
1204 case GCS_RESULTREADSTR
:
1205 TRACE("GCS_RESULTREADSTR\n");
1206 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwResultReadStrOffset
, compstr
->dwResultReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1208 case GCS_RESULTREADCLAUSE
:
1209 TRACE("GCS_RESULTREADCLAUSE\n");
1210 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwResultReadClauseOffset
,compstr
->dwResultReadClauseLen
,
1211 compdata
+ compstr
->dwResultStrOffset
, compstr
->dwResultStrLen
,
1212 lpBuf
, dwBufLen
, unicode
);
1214 case GCS_COMPREADSTR
:
1215 TRACE("GCS_COMPREADSTR\n");
1216 rc
= CopyCompStringIMEtoClient(data
, compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
, lpBuf
, dwBufLen
, unicode
);
1218 case GCS_COMPREADATTR
:
1219 TRACE("GCS_COMPREADATTR\n");
1220 rc
= CopyCompAttrIMEtoClient(data
, compdata
+ compstr
->dwCompReadAttrOffset
, compstr
->dwCompReadAttrLen
,
1221 compdata
+ compstr
->dwCompReadStrOffset
, compstr
->dwCompReadStrLen
,
1222 lpBuf
, dwBufLen
, unicode
);
1224 case GCS_COMPREADCLAUSE
:
1225 TRACE("GCS_COMPREADCLAUSE\n");
1226 rc
= CopyCompClauseIMEtoClient(data
, compdata
+ compstr
->dwCompReadClauseOffset
,compstr
->dwCompReadClauseLen
,
1227 compdata
+ compstr
->dwCompStrOffset
, compstr
->dwCompStrLen
,
1228 lpBuf
, dwBufLen
, unicode
);
1231 TRACE("GCS_CURSORPOS\n");
1232 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwCursorPos
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1234 case GCS_DELTASTART
:
1235 TRACE("GCS_DELTASTART\n");
1236 rc
= CopyCompOffsetIMEtoClient(data
, compstr
->dwDeltaStart
, compdata
+ compstr
->dwCompStrOffset
, unicode
);
1239 FIXME("Unhandled index 0x%x\n",dwIndex
);
1243 ImmUnlockIMCC(data
->IMC
.hCompStr
);
1248 /***********************************************************************
1249 * ImmGetCompositionStringA (IMM32.@)
1251 LONG WINAPI
ImmGetCompositionStringA(
1252 HIMC hIMC
, DWORD dwIndex
, LPVOID lpBuf
, DWORD dwBufLen
)
1254 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, FALSE
);
1258 /***********************************************************************
1259 * ImmGetCompositionStringW (IMM32.@)
1261 LONG WINAPI
ImmGetCompositionStringW(
1262 HIMC hIMC
, DWORD dwIndex
,
1263 LPVOID lpBuf
, DWORD dwBufLen
)
1265 return ImmGetCompositionStringT(hIMC
, dwIndex
, lpBuf
, dwBufLen
, TRUE
);
1268 /***********************************************************************
1269 * ImmGetCompositionWindow (IMM32.@)
1271 BOOL WINAPI
ImmGetCompositionWindow(HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
1273 InputContextData
*data
= (InputContextData
*)hIMC
;
1275 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
1280 *lpCompForm
= data
->IMC
.cfCompForm
;
1284 /***********************************************************************
1285 * ImmGetContext (IMM32.@)
1288 HIMC WINAPI
ImmGetContext(HWND hWnd
)
1292 TRACE("%p\n", hWnd
);
1293 if (!IMM_GetThreadData()->defaultContext
)
1294 IMM_GetThreadData()->defaultContext
= ImmCreateContext();
1296 rc
= (HIMC
)GetPropW(hWnd
,szwWineIMCProperty
);
1299 else if (rc
== NULL
)
1300 rc
= IMM_GetThreadData()->defaultContext
;
1304 InputContextData
*data
= (InputContextData
*)rc
;
1305 data
->IMC
.hWnd
= hWnd
;
1307 TRACE("returning %p\n", rc
);
1312 /***********************************************************************
1313 * ImmGetConversionListA (IMM32.@)
1315 DWORD WINAPI
ImmGetConversionListA(
1317 LPCSTR pSrc
, LPCANDIDATELIST lpDst
,
1318 DWORD dwBufLen
, UINT uFlag
)
1320 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1321 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_a(pSrc
), lpDst
,
1323 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1325 if (!is_kbd_ime_unicode(immHkl
))
1326 return immHkl
->pImeConversionList(hIMC
,(LPCWSTR
)pSrc
,lpDst
,dwBufLen
,uFlag
);
1329 LPCANDIDATELIST lpwDst
;
1331 LPWSTR pwSrc
= strdupAtoW(pSrc
);
1333 len
= immHkl
->pImeConversionList(hIMC
, pwSrc
, NULL
, 0, uFlag
);
1334 lpwDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1337 immHkl
->pImeConversionList(hIMC
, pwSrc
, lpwDst
, len
, uFlag
);
1338 ret
= convert_candidatelist_WtoA( lpwDst
, lpDst
, dwBufLen
);
1339 HeapFree(GetProcessHeap(), 0, lpwDst
);
1341 HeapFree(GetProcessHeap(), 0, pwSrc
);
1350 /***********************************************************************
1351 * ImmGetConversionListW (IMM32.@)
1353 DWORD WINAPI
ImmGetConversionListW(
1355 LPCWSTR pSrc
, LPCANDIDATELIST lpDst
,
1356 DWORD dwBufLen
, UINT uFlag
)
1358 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1359 TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL
, hIMC
, debugstr_w(pSrc
), lpDst
,
1361 if (immHkl
->hIME
&& immHkl
->pImeConversionList
)
1363 if (is_kbd_ime_unicode(immHkl
))
1364 return immHkl
->pImeConversionList(hIMC
,pSrc
,lpDst
,dwBufLen
,uFlag
);
1367 LPCANDIDATELIST lpaDst
;
1369 LPSTR paSrc
= strdupWtoA(pSrc
);
1371 len
= immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, NULL
, 0, uFlag
);
1372 lpaDst
= HeapAlloc(GetProcessHeap(), 0, len
);
1375 immHkl
->pImeConversionList(hIMC
, (LPCWSTR
)paSrc
, lpaDst
, len
, uFlag
);
1376 ret
= convert_candidatelist_AtoW( lpaDst
, lpDst
, dwBufLen
);
1377 HeapFree(GetProcessHeap(), 0, lpaDst
);
1379 HeapFree(GetProcessHeap(), 0, paSrc
);
1388 /***********************************************************************
1389 * ImmGetConversionStatus (IMM32.@)
1391 BOOL WINAPI
ImmGetConversionStatus(
1392 HIMC hIMC
, LPDWORD lpfdwConversion
, LPDWORD lpfdwSentence
)
1394 InputContextData
*data
= (InputContextData
*)hIMC
;
1396 TRACE("%p %p %p\n", hIMC
, lpfdwConversion
, lpfdwSentence
);
1401 if (lpfdwConversion
)
1402 *lpfdwConversion
= data
->IMC
.fdwConversion
;
1404 *lpfdwSentence
= data
->IMC
.fdwSentence
;
1409 /***********************************************************************
1410 * ImmGetDefaultIMEWnd (IMM32.@)
1412 HWND WINAPI
ImmGetDefaultIMEWnd(HWND hWnd
)
1414 TRACE("Default is %x\n",(unsigned)IMM_GetThreadData()->hwndDefault
);
1415 return IMM_GetThreadData()->hwndDefault
;
1418 /***********************************************************************
1419 * ImmGetDescriptionA (IMM32.@)
1421 UINT WINAPI
ImmGetDescriptionA(
1422 HKL hKL
, LPSTR lpszDescription
, UINT uBufLen
)
1427 TRACE("%p %p %d\n", hKL
, lpszDescription
, uBufLen
);
1429 /* find out how many characters in the unicode buffer */
1430 len
= ImmGetDescriptionW( hKL
, NULL
, 0 );
1432 /* allocate a buffer of that size */
1433 buf
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof (WCHAR
) );
1437 /* fetch the unicode buffer */
1438 len
= ImmGetDescriptionW( hKL
, buf
, len
+ 1 );
1440 /* convert it back to ASCII */
1441 len
= WideCharToMultiByte( CP_ACP
, 0, buf
, len
+ 1,
1442 lpszDescription
, uBufLen
, NULL
, NULL
);
1444 HeapFree( GetProcessHeap(), 0, buf
);
1449 /***********************************************************************
1450 * ImmGetDescriptionW (IMM32.@)
1452 UINT WINAPI
ImmGetDescriptionW(HKL hKL
, LPWSTR lpszDescription
, UINT uBufLen
)
1454 static const WCHAR name
[] = { 'W','i','n','e',' ','X','I','M',0 };
1456 FIXME("(%p, %p, %d): semi stub\n", hKL
, lpszDescription
, uBufLen
);
1458 if (!uBufLen
) return lstrlenW( name
);
1459 lstrcpynW( lpszDescription
, name
, uBufLen
);
1460 return lstrlenW( lpszDescription
);
1463 /***********************************************************************
1464 * ImmGetGuideLineA (IMM32.@)
1466 DWORD WINAPI
ImmGetGuideLineA(
1467 HIMC hIMC
, DWORD dwIndex
, LPSTR lpBuf
, DWORD dwBufLen
)
1469 FIXME("(%p, %d, %s, %d): stub\n",
1470 hIMC
, dwIndex
, debugstr_a(lpBuf
), dwBufLen
1472 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1476 /***********************************************************************
1477 * ImmGetGuideLineW (IMM32.@)
1479 DWORD WINAPI
ImmGetGuideLineW(HIMC hIMC
, DWORD dwIndex
, LPWSTR lpBuf
, DWORD dwBufLen
)
1481 FIXME("(%p, %d, %s, %d): stub\n",
1482 hIMC
, dwIndex
, debugstr_w(lpBuf
), dwBufLen
1484 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1488 /***********************************************************************
1489 * ImmGetIMEFileNameA (IMM32.@)
1491 UINT WINAPI
ImmGetIMEFileNameA( HKL hKL
, LPSTR lpszFileName
, UINT uBufLen
)
1494 UINT wBufLen
= uBufLen
;
1497 if (uBufLen
&& lpszFileName
)
1498 bufW
= HeapAlloc(GetProcessHeap(),0,uBufLen
* sizeof(WCHAR
));
1499 else /* We need this to get the number of byte required */
1501 bufW
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
* sizeof(WCHAR
));
1505 rc
= ImmGetIMEFileNameW(hKL
,bufW
,wBufLen
);
1509 if (uBufLen
&& lpszFileName
)
1510 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, lpszFileName
,
1511 uBufLen
, NULL
, NULL
);
1512 else /* get the length */
1513 rc
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
,
1517 HeapFree(GetProcessHeap(),0,bufW
);
1521 /***********************************************************************
1522 * ImmGetIMEFileNameW (IMM32.@)
1524 UINT WINAPI
ImmGetIMEFileNameW(HKL hKL
, LPWSTR lpszFileName
, UINT uBufLen
)
1526 static const WCHAR szImeFileW
[] = {'I','m','e',' ','F','i','l','e',0};
1527 static const WCHAR fmt
[] = {'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','x',0};
1532 WCHAR regKey
[sizeof(fmt
)/sizeof(WCHAR
)+8];
1534 wsprintfW( regKey
, fmt
, (unsigned)hKL
);
1535 rc
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, regKey
, &hkey
);
1536 if (rc
!= ERROR_SUCCESS
)
1543 rc
= RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, NULL
, &length
);
1545 if (rc
!= ERROR_SUCCESS
)
1551 if (length
> uBufLen
* sizeof(WCHAR
) || !lpszFileName
)
1556 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1560 return length
/ sizeof(WCHAR
);
1563 RegGetValueW(hkey
, NULL
, szImeFileW
, RRF_RT_REG_SZ
, NULL
, lpszFileName
, &length
);
1567 return length
/ sizeof(WCHAR
);
1570 /***********************************************************************
1571 * ImmGetOpenStatus (IMM32.@)
1573 BOOL WINAPI
ImmGetOpenStatus(HIMC hIMC
)
1575 InputContextData
*data
= (InputContextData
*)hIMC
;
1579 FIXME("(%p): semi-stub\n", hIMC
);
1581 return data
->IMC
.fOpen
;
1584 /***********************************************************************
1585 * ImmGetProperty (IMM32.@)
1587 DWORD WINAPI
ImmGetProperty(HKL hKL
, DWORD fdwIndex
)
1592 TRACE("(%p, %d)\n", hKL
, fdwIndex
);
1593 kbd
= IMM_GetImmHkl(hKL
);
1595 if (kbd
&& kbd
->hIME
)
1599 case IGP_PROPERTY
: rc
= kbd
->imeInfo
.fdwProperty
; break;
1600 case IGP_CONVERSION
: rc
= kbd
->imeInfo
.fdwConversionCaps
; break;
1601 case IGP_SENTENCE
: rc
= kbd
->imeInfo
.fdwSentenceCaps
; break;
1602 case IGP_SETCOMPSTR
: rc
= kbd
->imeInfo
.fdwSCSCaps
; break;
1603 case IGP_SELECT
: rc
= kbd
->imeInfo
.fdwSelectCaps
; break;
1604 case IGP_GETIMEVERSION
: rc
= IMEVER_0400
; break;
1605 case IGP_UI
: rc
= 0; break;
1612 /***********************************************************************
1613 * ImmGetRegisterWordStyleA (IMM32.@)
1615 UINT WINAPI
ImmGetRegisterWordStyleA(
1616 HKL hKL
, UINT nItem
, LPSTYLEBUFA lpStyleBuf
)
1618 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1619 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1620 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1622 if (!is_kbd_ime_unicode(immHkl
))
1623 return immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)lpStyleBuf
);
1629 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,&sbw
);
1630 WideCharToMultiByte(CP_ACP
, 0, sbw
.szDescription
, -1,
1631 lpStyleBuf
->szDescription
, 32, NULL
, NULL
);
1632 lpStyleBuf
->dwStyle
= sbw
.dwStyle
;
1640 /***********************************************************************
1641 * ImmGetRegisterWordStyleW (IMM32.@)
1643 UINT WINAPI
ImmGetRegisterWordStyleW(
1644 HKL hKL
, UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
1646 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1647 TRACE("(%p, %d, %p):\n", hKL
, nItem
, lpStyleBuf
);
1648 if (immHkl
->hIME
&& immHkl
->pImeGetRegisterWordStyle
)
1650 if (is_kbd_ime_unicode(immHkl
))
1651 return immHkl
->pImeGetRegisterWordStyle(nItem
,lpStyleBuf
);
1657 rc
= immHkl
->pImeGetRegisterWordStyle(nItem
,(LPSTYLEBUFW
)&sba
);
1658 MultiByteToWideChar(CP_ACP
, 0, sba
.szDescription
, -1,
1659 lpStyleBuf
->szDescription
, 32);
1660 lpStyleBuf
->dwStyle
= sba
.dwStyle
;
1668 /***********************************************************************
1669 * ImmGetStatusWindowPos (IMM32.@)
1671 BOOL WINAPI
ImmGetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
1673 InputContextData
*data
= (InputContextData
*)hIMC
;
1675 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
1677 if (!data
|| !lpptPos
)
1680 *lpptPos
= data
->IMC
.ptStatusWndPos
;
1685 /***********************************************************************
1686 * ImmGetVirtualKey (IMM32.@)
1688 UINT WINAPI
ImmGetVirtualKey(HWND hWnd
)
1690 OSVERSIONINFOA version
;
1691 InputContextData
*data
= (InputContextData
*)ImmGetContext( hWnd
);
1692 TRACE("%p\n", hWnd
);
1695 return data
->lastVK
;
1697 GetVersionExA( &version
);
1698 switch(version
.dwPlatformId
)
1700 case VER_PLATFORM_WIN32_WINDOWS
:
1701 return VK_PROCESSKEY
;
1702 case VER_PLATFORM_WIN32_NT
:
1705 FIXME("%d not supported\n",version
.dwPlatformId
);
1706 return VK_PROCESSKEY
;
1710 /***********************************************************************
1711 * ImmInstallIMEA (IMM32.@)
1713 HKL WINAPI
ImmInstallIMEA(
1714 LPCSTR lpszIMEFileName
, LPCSTR lpszLayoutText
)
1716 FIXME("(%s, %s): stub\n",
1717 debugstr_a(lpszIMEFileName
), debugstr_a(lpszLayoutText
)
1719 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1723 /***********************************************************************
1724 * ImmInstallIMEW (IMM32.@)
1726 HKL WINAPI
ImmInstallIMEW(
1727 LPCWSTR lpszIMEFileName
, LPCWSTR lpszLayoutText
)
1729 FIXME("(%s, %s): stub\n",
1730 debugstr_w(lpszIMEFileName
), debugstr_w(lpszLayoutText
)
1732 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1736 /***********************************************************************
1737 * ImmIsIME (IMM32.@)
1739 BOOL WINAPI
ImmIsIME(HKL hKL
)
1742 TRACE("(%p):\n", hKL
);
1743 ptr
= IMM_GetImmHkl(hKL
);
1744 return (ptr
&& ptr
->hIME
);
1747 /***********************************************************************
1748 * ImmIsUIMessageA (IMM32.@)
1750 BOOL WINAPI
ImmIsUIMessageA(
1751 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1755 TRACE("(%p, %x, %ld, %ld)\n", hWndIME
, msg
, wParam
, lParam
);
1756 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
1757 (msg
>= WM_IME_SETCONTEXT
&& msg
<= WM_IME_KEYUP
) ||
1758 (msg
== WM_MSIME_SERVICE
) ||
1759 (msg
== WM_MSIME_RECONVERTOPTIONS
) ||
1760 (msg
== WM_MSIME_MOUSE
) ||
1761 (msg
== WM_MSIME_RECONVERTREQUEST
) ||
1762 (msg
== WM_MSIME_RECONVERT
) ||
1763 (msg
== WM_MSIME_QUERYPOSITION
) ||
1764 (msg
== WM_MSIME_DOCUMENTFEED
))
1767 if (!IMM_GetThreadData()->hwndDefault
)
1768 ImmGetDefaultIMEWnd(NULL
);
1770 if (hWndIME
== NULL
)
1771 PostMessageA(IMM_GetThreadData()->hwndDefault
, msg
, wParam
, lParam
);
1778 /***********************************************************************
1779 * ImmIsUIMessageW (IMM32.@)
1781 BOOL WINAPI
ImmIsUIMessageW(
1782 HWND hWndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1785 TRACE("(%p, %d, %ld, %ld):\n", hWndIME
, msg
, wParam
, lParam
);
1786 if ((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
1787 (msg
>= WM_IME_SETCONTEXT
&& msg
<= WM_IME_KEYUP
) ||
1788 (msg
== WM_MSIME_SERVICE
) ||
1789 (msg
== WM_MSIME_RECONVERTOPTIONS
) ||
1790 (msg
== WM_MSIME_MOUSE
) ||
1791 (msg
== WM_MSIME_RECONVERTREQUEST
) ||
1792 (msg
== WM_MSIME_RECONVERT
) ||
1793 (msg
== WM_MSIME_QUERYPOSITION
) ||
1794 (msg
== WM_MSIME_DOCUMENTFEED
))
1799 /***********************************************************************
1800 * ImmNotifyIME (IMM32.@)
1802 BOOL WINAPI
ImmNotifyIME(
1803 HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
1805 InputContextData
*data
= (InputContextData
*)hIMC
;
1807 TRACE("(%p, %d, %d, %d)\n",
1808 hIMC
, dwAction
, dwIndex
, dwValue
);
1810 if (!data
|| ! data
->immKbd
->pNotifyIME
)
1813 return data
->immKbd
->pNotifyIME(hIMC
,dwAction
,dwIndex
,dwValue
);
1816 /***********************************************************************
1817 * ImmRegisterWordA (IMM32.@)
1819 BOOL WINAPI
ImmRegisterWordA(
1820 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszRegister
)
1822 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1823 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
1824 debugstr_a(lpszRegister
));
1825 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
1827 if (!is_kbd_ime_unicode(immHkl
))
1828 return immHkl
->pImeRegisterWord((LPCWSTR
)lpszReading
,dwStyle
,
1829 (LPCWSTR
)lpszRegister
);
1832 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
1833 LPWSTR lpszwRegister
= strdupAtoW(lpszRegister
);
1836 rc
= immHkl
->pImeRegisterWord(lpszwReading
,dwStyle
,lpszwRegister
);
1837 HeapFree(GetProcessHeap(),0,lpszwReading
);
1838 HeapFree(GetProcessHeap(),0,lpszwRegister
);
1846 /***********************************************************************
1847 * ImmRegisterWordW (IMM32.@)
1849 BOOL WINAPI
ImmRegisterWordW(
1850 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
1852 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
1853 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
1854 debugstr_w(lpszRegister
));
1855 if (immHkl
->hIME
&& immHkl
->pImeRegisterWord
)
1857 if (is_kbd_ime_unicode(immHkl
))
1858 return immHkl
->pImeRegisterWord(lpszReading
,dwStyle
,lpszRegister
);
1861 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
1862 LPSTR lpszaRegister
= strdupWtoA(lpszRegister
);
1865 rc
= immHkl
->pImeRegisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
1866 (LPCWSTR
)lpszaRegister
);
1867 HeapFree(GetProcessHeap(),0,lpszaReading
);
1868 HeapFree(GetProcessHeap(),0,lpszaRegister
);
1876 /***********************************************************************
1877 * ImmReleaseContext (IMM32.@)
1879 BOOL WINAPI
ImmReleaseContext(HWND hWnd
, HIMC hIMC
)
1881 static int shown
= 0;
1884 FIXME("(%p, %p): stub\n", hWnd
, hIMC
);
1890 /***********************************************************************
1891 * ImmRequestMessageA(IMM32.@)
1893 LRESULT WINAPI
ImmRequestMessageA(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
1895 InputContextData
*data
= (InputContextData
*)hIMC
;
1897 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
1899 if (data
&& IsWindow(data
->IMC
.hWnd
))
1900 return SendMessageA(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
1905 /***********************************************************************
1906 * ImmRequestMessageW(IMM32.@)
1908 LRESULT WINAPI
ImmRequestMessageW(HIMC hIMC
, WPARAM wParam
, LPARAM lParam
)
1910 InputContextData
*data
= (InputContextData
*)hIMC
;
1912 TRACE("%p %ld %ld\n", hIMC
, wParam
, wParam
);
1914 if (data
&& IsWindow(data
->IMC
.hWnd
))
1915 return SendMessageW(data
->IMC
.hWnd
, WM_IME_REQUEST
, wParam
, lParam
);
1920 /***********************************************************************
1921 * ImmSetCandidateWindow (IMM32.@)
1923 BOOL WINAPI
ImmSetCandidateWindow(
1924 HIMC hIMC
, LPCANDIDATEFORM lpCandidate
)
1926 InputContextData
*data
= (InputContextData
*)hIMC
;
1928 TRACE("(%p, %p)\n", hIMC
, lpCandidate
);
1930 if (!data
|| !lpCandidate
)
1933 TRACE("\t%x, %x, (%i,%i), (%i,%i - %i,%i)\n",
1934 lpCandidate
->dwIndex
, lpCandidate
->dwStyle
,
1935 lpCandidate
->ptCurrentPos
.x
, lpCandidate
->ptCurrentPos
.y
,
1936 lpCandidate
->rcArea
.top
, lpCandidate
->rcArea
.left
,
1937 lpCandidate
->rcArea
.bottom
, lpCandidate
->rcArea
.right
);
1939 if ( lpCandidate
->dwIndex
>= (sizeof(data
->IMC
.cfCandForm
) / sizeof(CANDIDATEFORM
)) )
1942 data
->IMC
.cfCandForm
[lpCandidate
->dwIndex
] = *lpCandidate
;
1943 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCANDIDATEPOS
);
1944 ImmInternalSendIMENotify(data
, IMN_SETCANDIDATEPOS
, 1 << lpCandidate
->dwIndex
);
1949 /***********************************************************************
1950 * ImmSetCompositionFontA (IMM32.@)
1952 BOOL WINAPI
ImmSetCompositionFontA(HIMC hIMC
, LPLOGFONTA lplf
)
1954 InputContextData
*data
= (InputContextData
*)hIMC
;
1955 TRACE("(%p, %p)\n", hIMC
, lplf
);
1960 memcpy(&data
->IMC
.lfFont
.W
,lplf
,sizeof(LOGFONTA
));
1961 MultiByteToWideChar(CP_ACP
, 0, lplf
->lfFaceName
, -1, data
->IMC
.lfFont
.W
.lfFaceName
,
1963 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
1964 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
1969 /***********************************************************************
1970 * ImmSetCompositionFontW (IMM32.@)
1972 BOOL WINAPI
ImmSetCompositionFontW(HIMC hIMC
, LPLOGFONTW lplf
)
1974 InputContextData
*data
= (InputContextData
*)hIMC
;
1975 TRACE("(%p, %p)\n", hIMC
, lplf
);
1980 data
->IMC
.lfFont
.W
= *lplf
;
1981 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETCOMPOSITIONFONT
);
1982 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONFONT
, 0);
1987 /***********************************************************************
1988 * ImmSetCompositionStringA (IMM32.@)
1990 BOOL WINAPI
ImmSetCompositionStringA(
1991 HIMC hIMC
, DWORD dwIndex
,
1992 LPCVOID lpComp
, DWORD dwCompLen
,
1993 LPCVOID lpRead
, DWORD dwReadLen
)
1997 WCHAR
*CompBuffer
= NULL
;
1998 WCHAR
*ReadBuffer
= NULL
;
2000 InputContextData
*data
= (InputContextData
*)hIMC
;
2002 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2003 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2008 if (!is_himc_ime_unicode(data
))
2009 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2010 dwCompLen
, lpRead
, dwReadLen
);
2012 comp_len
= MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0);
2015 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
* sizeof(WCHAR
));
2016 MultiByteToWideChar(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
);
2019 read_len
= MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0);
2022 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
* sizeof(WCHAR
));
2023 MultiByteToWideChar(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
);
2026 rc
= ImmSetCompositionStringW(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2027 ReadBuffer
, read_len
);
2029 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2030 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2035 /***********************************************************************
2036 * ImmSetCompositionStringW (IMM32.@)
2038 BOOL WINAPI
ImmSetCompositionStringW(
2039 HIMC hIMC
, DWORD dwIndex
,
2040 LPCVOID lpComp
, DWORD dwCompLen
,
2041 LPCVOID lpRead
, DWORD dwReadLen
)
2045 CHAR
*CompBuffer
= NULL
;
2046 CHAR
*ReadBuffer
= NULL
;
2048 InputContextData
*data
= (InputContextData
*)hIMC
;
2050 TRACE("(%p, %d, %p, %d, %p, %d):\n",
2051 hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
2056 if (is_himc_ime_unicode(data
))
2057 return data
->immKbd
->pImeSetCompositionString(hIMC
, dwIndex
, lpComp
,
2058 dwCompLen
, lpRead
, dwReadLen
);
2060 comp_len
= WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, NULL
, 0, NULL
,
2064 CompBuffer
= HeapAlloc(GetProcessHeap(),0,comp_len
);
2065 WideCharToMultiByte(CP_ACP
, 0, lpComp
, dwCompLen
, CompBuffer
, comp_len
,
2069 read_len
= WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, NULL
, 0, NULL
,
2073 ReadBuffer
= HeapAlloc(GetProcessHeap(),0,read_len
);
2074 WideCharToMultiByte(CP_ACP
, 0, lpRead
, dwReadLen
, ReadBuffer
, read_len
,
2078 rc
= ImmSetCompositionStringA(hIMC
, dwIndex
, CompBuffer
, comp_len
,
2079 ReadBuffer
, read_len
);
2081 HeapFree(GetProcessHeap(), 0, CompBuffer
);
2082 HeapFree(GetProcessHeap(), 0, ReadBuffer
);
2087 /***********************************************************************
2088 * ImmSetCompositionWindow (IMM32.@)
2090 BOOL WINAPI
ImmSetCompositionWindow(
2091 HIMC hIMC
, LPCOMPOSITIONFORM lpCompForm
)
2093 BOOL reshow
= FALSE
;
2094 InputContextData
*data
= (InputContextData
*)hIMC
;
2096 TRACE("(%p, %p)\n", hIMC
, lpCompForm
);
2097 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm
->dwStyle
,
2098 lpCompForm
->ptCurrentPos
.x
, lpCompForm
->ptCurrentPos
.y
, lpCompForm
->rcArea
.top
,
2099 lpCompForm
->rcArea
.left
, lpCompForm
->rcArea
.bottom
, lpCompForm
->rcArea
.right
);
2104 data
->IMC
.cfCompForm
= *lpCompForm
;
2106 if (IsWindowVisible(IMM_GetThreadData()->hwndDefault
))
2109 ShowWindow(IMM_GetThreadData()->hwndDefault
,SW_HIDE
);
2112 /* FIXME: this is a partial stub */
2115 ShowWindow(IMM_GetThreadData()->hwndDefault
,SW_SHOWNOACTIVATE
);
2117 ImmInternalSendIMENotify(data
, IMN_SETCOMPOSITIONWINDOW
, 0);
2121 /***********************************************************************
2122 * ImmSetConversionStatus (IMM32.@)
2124 BOOL WINAPI
ImmSetConversionStatus(
2125 HIMC hIMC
, DWORD fdwConversion
, DWORD fdwSentence
)
2127 DWORD oldConversion
, oldSentence
;
2128 InputContextData
*data
= (InputContextData
*)hIMC
;
2130 TRACE("%p %d %d\n", hIMC
, fdwConversion
, fdwSentence
);
2135 if ( fdwConversion
!= data
->IMC
.fdwConversion
)
2137 oldConversion
= data
->IMC
.fdwConversion
;
2138 data
->IMC
.fdwConversion
= fdwConversion
;
2139 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldConversion
, IMC_SETCONVERSIONMODE
);
2140 ImmInternalSendIMENotify(data
, IMN_SETCONVERSIONMODE
, 0);
2142 if ( fdwSentence
!= data
->IMC
.fdwSentence
)
2144 oldSentence
= data
->IMC
.fdwSentence
;
2145 data
->IMC
.fdwSentence
= fdwSentence
;
2146 ImmNotifyIME(hIMC
, NI_CONTEXTUPDATED
, oldSentence
, IMC_SETSENTENCEMODE
);
2147 ImmInternalSendIMENotify(data
, IMN_SETSENTENCEMODE
, 0);
2153 /***********************************************************************
2154 * ImmSetOpenStatus (IMM32.@)
2156 BOOL WINAPI
ImmSetOpenStatus(HIMC hIMC
, BOOL fOpen
)
2158 InputContextData
*data
= (InputContextData
*)hIMC
;
2160 TRACE("%p %d\n", hIMC
, fOpen
);
2165 if (data
->imeWnd
== NULL
)
2167 /* create the ime window */
2168 data
->imeWnd
= CreateWindowExW( WS_EX_TOOLWINDOW
,
2169 data
->immKbd
->imeClassName
, NULL
, WS_POPUP
, 0, 0, 1, 1, 0,
2170 0, data
->immKbd
->hIME
, 0);
2171 SetWindowLongW(data
->imeWnd
, IMMGWL_IMC
, (LONG
)data
);
2172 IMM_GetThreadData()->hwndDefault
= data
->imeWnd
;
2175 if (!fOpen
!= !data
->IMC
.fOpen
)
2177 data
->IMC
.fOpen
= fOpen
;
2178 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETOPENSTATUS
);
2179 ImmInternalSendIMENotify(data
, IMN_SETOPENSTATUS
, 0);
2185 /***********************************************************************
2186 * ImmSetStatusWindowPos (IMM32.@)
2188 BOOL WINAPI
ImmSetStatusWindowPos(HIMC hIMC
, LPPOINT lpptPos
)
2190 InputContextData
*data
= (InputContextData
*)hIMC
;
2192 TRACE("(%p, %p)\n", hIMC
, lpptPos
);
2194 if (!data
|| !lpptPos
)
2197 TRACE("\t(%i,%i)\n", lpptPos
->x
, lpptPos
->y
);
2199 data
->IMC
.ptStatusWndPos
= *lpptPos
;
2200 ImmNotifyIME( hIMC
, NI_CONTEXTUPDATED
, 0, IMC_SETSTATUSWINDOWPOS
);
2201 ImmInternalSendIMENotify(data
, IMN_SETSTATUSWINDOWPOS
, 0);
2206 /***********************************************************************
2207 * ImmCreateSoftKeyboard(IMM32.@)
2209 HWND WINAPI
ImmCreateSoftKeyboard(UINT uType
, UINT hOwner
, int x
, int y
)
2211 FIXME("(%d, %d, %d, %d): stub\n", uType
, hOwner
, x
, y
);
2212 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2216 /***********************************************************************
2217 * ImmDestroySoftKeyboard(IMM32.@)
2219 BOOL WINAPI
ImmDestroySoftKeyboard(HWND hSoftWnd
)
2221 FIXME("(%p): stub\n", hSoftWnd
);
2222 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2226 /***********************************************************************
2227 * ImmShowSoftKeyboard(IMM32.@)
2229 BOOL WINAPI
ImmShowSoftKeyboard(HWND hSoftWnd
, int nCmdShow
)
2231 FIXME("(%p, %d): stub\n", hSoftWnd
, nCmdShow
);
2232 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2236 /***********************************************************************
2237 * ImmSimulateHotKey (IMM32.@)
2239 BOOL WINAPI
ImmSimulateHotKey(HWND hWnd
, DWORD dwHotKeyID
)
2241 FIXME("(%p, %d): stub\n", hWnd
, dwHotKeyID
);
2242 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2246 /***********************************************************************
2247 * ImmUnregisterWordA (IMM32.@)
2249 BOOL WINAPI
ImmUnregisterWordA(
2250 HKL hKL
, LPCSTR lpszReading
, DWORD dwStyle
, LPCSTR lpszUnregister
)
2252 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2253 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_a(lpszReading
), dwStyle
,
2254 debugstr_a(lpszUnregister
));
2255 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2257 if (!is_kbd_ime_unicode(immHkl
))
2258 return immHkl
->pImeUnregisterWord((LPCWSTR
)lpszReading
,dwStyle
,
2259 (LPCWSTR
)lpszUnregister
);
2262 LPWSTR lpszwReading
= strdupAtoW(lpszReading
);
2263 LPWSTR lpszwUnregister
= strdupAtoW(lpszUnregister
);
2266 rc
= immHkl
->pImeUnregisterWord(lpszwReading
,dwStyle
,lpszwUnregister
);
2267 HeapFree(GetProcessHeap(),0,lpszwReading
);
2268 HeapFree(GetProcessHeap(),0,lpszwUnregister
);
2276 /***********************************************************************
2277 * ImmUnregisterWordW (IMM32.@)
2279 BOOL WINAPI
ImmUnregisterWordW(
2280 HKL hKL
, LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
2282 ImmHkl
*immHkl
= IMM_GetImmHkl(hKL
);
2283 TRACE("(%p, %s, %d, %s):\n", hKL
, debugstr_w(lpszReading
), dwStyle
,
2284 debugstr_w(lpszUnregister
));
2285 if (immHkl
->hIME
&& immHkl
->pImeUnregisterWord
)
2287 if (is_kbd_ime_unicode(immHkl
))
2288 return immHkl
->pImeUnregisterWord(lpszReading
,dwStyle
,lpszUnregister
);
2291 LPSTR lpszaReading
= strdupWtoA(lpszReading
);
2292 LPSTR lpszaUnregister
= strdupWtoA(lpszUnregister
);
2295 rc
= immHkl
->pImeUnregisterWord((LPCWSTR
)lpszaReading
,dwStyle
,
2296 (LPCWSTR
)lpszaUnregister
);
2297 HeapFree(GetProcessHeap(),0,lpszaReading
);
2298 HeapFree(GetProcessHeap(),0,lpszaUnregister
);
2306 /***********************************************************************
2307 * ImmGetImeMenuItemsA (IMM32.@)
2309 DWORD WINAPI
ImmGetImeMenuItemsA( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2310 LPIMEMENUITEMINFOA lpImeParentMenu
, LPIMEMENUITEMINFOA lpImeMenu
,
2313 InputContextData
*data
= (InputContextData
*)hIMC
;
2314 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2315 lpImeParentMenu
, lpImeMenu
, dwSize
);
2316 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2318 if (!is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2319 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2320 (IMEMENUITEMINFOW
*)lpImeParentMenu
,
2321 (IMEMENUITEMINFOW
*)lpImeMenu
, dwSize
);
2324 IMEMENUITEMINFOW lpImeParentMenuW
;
2325 IMEMENUITEMINFOW
*lpImeMenuW
, *parent
= NULL
;
2328 if (lpImeParentMenu
)
2329 parent
= &lpImeParentMenuW
;
2332 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOA
);
2333 dwSize
= count
* sizeof(IMEMENUITEMINFOW
);
2334 lpImeMenuW
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2339 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2340 parent
, lpImeMenuW
, dwSize
);
2342 if (lpImeParentMenu
)
2344 memcpy(lpImeParentMenu
,&lpImeParentMenuW
,sizeof(IMEMENUITEMINFOA
));
2345 lpImeParentMenu
->hbmpItem
= lpImeParentMenuW
.hbmpItem
;
2346 WideCharToMultiByte(CP_ACP
, 0, lpImeParentMenuW
.szString
,
2347 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
,
2350 if (lpImeMenu
&& rc
)
2353 for (i
= 0; i
< rc
; i
++)
2355 memcpy(&lpImeMenu
[i
],&lpImeMenuW
[1],sizeof(IMEMENUITEMINFOA
));
2356 lpImeMenu
[i
].hbmpItem
= lpImeMenuW
[i
].hbmpItem
;
2357 WideCharToMultiByte(CP_ACP
, 0, lpImeMenuW
[i
].szString
,
2358 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
,
2362 HeapFree(GetProcessHeap(),0,lpImeMenuW
);
2370 /***********************************************************************
2371 * ImmGetImeMenuItemsW (IMM32.@)
2373 DWORD WINAPI
ImmGetImeMenuItemsW( HIMC hIMC
, DWORD dwFlags
, DWORD dwType
,
2374 LPIMEMENUITEMINFOW lpImeParentMenu
, LPIMEMENUITEMINFOW lpImeMenu
,
2377 InputContextData
*data
= (InputContextData
*)hIMC
;
2378 TRACE("(%p, %i, %i, %p, %p, %i):\n", hIMC
, dwFlags
, dwType
,
2379 lpImeParentMenu
, lpImeMenu
, dwSize
);
2380 if (data
->immKbd
->hIME
&& data
->immKbd
->pImeGetImeMenuItems
)
2382 if (is_himc_ime_unicode(data
) || (!lpImeParentMenu
&& !lpImeMenu
))
2383 return data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2384 lpImeParentMenu
, lpImeMenu
, dwSize
);
2387 IMEMENUITEMINFOA lpImeParentMenuA
;
2388 IMEMENUITEMINFOA
*lpImeMenuA
, *parent
= NULL
;
2391 if (lpImeParentMenu
)
2392 parent
= &lpImeParentMenuA
;
2395 int count
= dwSize
/ sizeof(LPIMEMENUITEMINFOW
);
2396 dwSize
= count
* sizeof(IMEMENUITEMINFOA
);
2397 lpImeMenuA
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
2402 rc
= data
->immKbd
->pImeGetImeMenuItems(hIMC
, dwFlags
, dwType
,
2403 (IMEMENUITEMINFOW
*)parent
,
2404 (IMEMENUITEMINFOW
*)lpImeMenuA
, dwSize
);
2406 if (lpImeParentMenu
)
2408 memcpy(lpImeParentMenu
,&lpImeParentMenuA
,sizeof(IMEMENUITEMINFOA
));
2409 lpImeParentMenu
->hbmpItem
= lpImeParentMenuA
.hbmpItem
;
2410 MultiByteToWideChar(CP_ACP
, 0, lpImeParentMenuA
.szString
,
2411 -1, lpImeParentMenu
->szString
, IMEMENUITEM_STRING_SIZE
);
2413 if (lpImeMenu
&& rc
)
2416 for (i
= 0; i
< rc
; i
++)
2418 memcpy(&lpImeMenu
[i
],&lpImeMenuA
[1],sizeof(IMEMENUITEMINFOA
));
2419 lpImeMenu
[i
].hbmpItem
= lpImeMenuA
[i
].hbmpItem
;
2420 MultiByteToWideChar(CP_ACP
, 0, lpImeMenuA
[i
].szString
,
2421 -1, lpImeMenu
[i
].szString
, IMEMENUITEM_STRING_SIZE
);
2424 HeapFree(GetProcessHeap(),0,lpImeMenuA
);
2432 /***********************************************************************
2433 * ImmLockIMC(IMM32.@)
2435 LPINPUTCONTEXT WINAPI
ImmLockIMC(HIMC hIMC
)
2437 InputContextData
*data
= (InputContextData
*)hIMC
;
2445 /***********************************************************************
2446 * ImmUnlockIMC(IMM32.@)
2448 BOOL WINAPI
ImmUnlockIMC(HIMC hIMC
)
2450 InputContextData
*data
= (InputContextData
*)hIMC
;
2452 return (data
->dwLock
!=0);
2455 /***********************************************************************
2456 * ImmGetIMCLockCount(IMM32.@)
2458 DWORD WINAPI
ImmGetIMCLockCount(HIMC hIMC
)
2460 InputContextData
*data
= (InputContextData
*)hIMC
;
2461 return data
->dwLock
;
2464 /***********************************************************************
2465 * ImmCreateIMCC(IMM32.@)
2467 HIMCC WINAPI
ImmCreateIMCC(DWORD size
)
2469 IMCCInternal
*internal
;
2470 int real_size
= size
+ sizeof(IMCCInternal
);
2472 internal
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, real_size
);
2473 if (internal
== NULL
)
2476 internal
->dwSize
= size
;
2477 return (HIMCC
)internal
;
2480 /***********************************************************************
2481 * ImmDestroyIMCC(IMM32.@)
2483 HIMCC WINAPI
ImmDestroyIMCC(HIMCC block
)
2485 HeapFree(GetProcessHeap(),0,block
);
2489 /***********************************************************************
2490 * ImmLockIMCC(IMM32.@)
2492 LPVOID WINAPI
ImmLockIMCC(HIMCC imcc
)
2494 IMCCInternal
*internal
;
2495 internal
= (IMCCInternal
*) imcc
;
2497 internal
->dwLock
++;
2498 return internal
+ 1;
2501 /***********************************************************************
2502 * ImmUnlockIMCC(IMM32.@)
2504 BOOL WINAPI
ImmUnlockIMCC(HIMCC imcc
)
2506 IMCCInternal
*internal
;
2507 internal
= (IMCCInternal
*) imcc
;
2509 internal
->dwLock
--;
2510 return (internal
->dwLock
!=0);
2513 /***********************************************************************
2514 * ImmGetIMCCLockCount(IMM32.@)
2516 DWORD WINAPI
ImmGetIMCCLockCount(HIMCC imcc
)
2518 IMCCInternal
*internal
;
2519 internal
= (IMCCInternal
*) imcc
;
2521 return internal
->dwLock
;
2524 /***********************************************************************
2525 * ImmReSizeIMCC(IMM32.@)
2527 HIMCC WINAPI
ImmReSizeIMCC(HIMCC imcc
, DWORD size
)
2529 IMCCInternal
*internal
,*newone
;
2530 int real_size
= size
+ sizeof(IMCCInternal
);
2532 internal
= (IMCCInternal
*) imcc
;
2534 newone
= HeapReAlloc(GetProcessHeap(), 0, internal
, real_size
);
2535 newone
->dwSize
= size
;
2540 /***********************************************************************
2541 * ImmGetIMCCSize(IMM32.@)
2543 DWORD WINAPI
ImmGetIMCCSize(HIMCC imcc
)
2545 IMCCInternal
*internal
;
2546 internal
= (IMCCInternal
*) imcc
;
2548 return internal
->dwSize
;
2551 /***********************************************************************
2552 * ImmGenerateMessage(IMM32.@)
2554 BOOL WINAPI
ImmGenerateMessage(HIMC hIMC
)
2556 InputContextData
*data
= (InputContextData
*)hIMC
;
2558 TRACE("%i messages queued\n",data
->IMC
.dwNumMsgBuf
);
2559 if (data
->IMC
.dwNumMsgBuf
> 0)
2561 LPTRANSMSG lpTransMsg
;
2564 lpTransMsg
= (LPTRANSMSG
)ImmLockIMCC(data
->IMC
.hMsgBuf
);
2565 for (i
= 0; i
< data
->IMC
.dwNumMsgBuf
; i
++)
2566 ImmInternalPostIMEMessage(data
, lpTransMsg
[i
].message
, lpTransMsg
[i
].wParam
, lpTransMsg
[i
].lParam
);
2568 ImmUnlockIMCC(data
->IMC
.hMsgBuf
);
2570 data
->IMC
.dwNumMsgBuf
= 0;
2576 /***********************************************************************
2577 * ImmTranslateMessage(IMM32.@)
2578 * ( Undocumented, call internally and from user32.dll )
2580 BOOL WINAPI
ImmTranslateMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lKeyData
)
2582 InputContextData
*data
;
2583 HIMC imc
= ImmGetContext(hwnd
);
2589 static const DWORD list_count
= 10;
2591 TRACE("%p %x %x %x\n",hwnd
, msg
, (UINT
)wParam
, (UINT
)lKeyData
);
2594 data
= (InputContextData
*)imc
;
2598 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeToAsciiEx
)
2601 GetKeyboardState(state
);
2602 scancode
= lKeyData
>> 0x10 & 0xff;
2604 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list_count
* sizeof(TRANSMSG
) + sizeof(DWORD
));
2605 ((DWORD
*)list
)[0] = list_count
;
2607 if (data
->immKbd
->imeInfo
.fdwProperty
& IME_PROP_KBD_CHAR_FIRST
)
2611 if (!is_himc_ime_unicode(data
))
2612 ToAscii(data
->lastVK
, scancode
, state
, &chr
, 0);
2614 ToUnicodeEx(data
->lastVK
, scancode
, state
, &chr
, 1, 0, GetKeyboardLayout(0));
2615 uVirtKey
= MAKELONG(data
->lastVK
,chr
);
2618 uVirtKey
= data
->lastVK
;
2620 msg_count
= data
->immKbd
->pImeToAsciiEx(uVirtKey
, scancode
, state
, list
, 0, imc
);
2621 TRACE("%i messages generated\n",msg_count
);
2622 if (msg_count
&& msg_count
<= list_count
)
2625 LPTRANSMSG msgs
= (LPTRANSMSG
)((LPBYTE
)list
+ sizeof(DWORD
));
2627 for (i
= 0; i
< msg_count
; i
++)
2628 ImmInternalPostIMEMessage(data
, msgs
[i
].message
, msgs
[i
].wParam
, msgs
[i
].lParam
);
2630 else if (msg_count
> list_count
)
2631 ImmGenerateMessage(imc
);
2633 HeapFree(GetProcessHeap(),0,list
);
2635 data
->lastVK
= VK_PROCESSKEY
;
2637 return (msg_count
> 0);
2640 /***********************************************************************
2641 * ImmProcessKey(IMM32.@)
2642 * ( Undocumented, called from user32.dll )
2644 BOOL WINAPI
ImmProcessKey(HWND hwnd
, HKL hKL
, UINT vKey
, LPARAM lKeyData
, DWORD unknown
)
2646 InputContextData
*data
;
2647 HIMC imc
= ImmGetContext(hwnd
);
2650 TRACE("%p %p %x %x %x\n",hwnd
, hKL
, vKey
, (UINT
)lKeyData
, unknown
);
2653 data
= (InputContextData
*)imc
;
2657 if (!data
->immKbd
->hIME
|| !data
->immKbd
->pImeProcessKey
)
2660 GetKeyboardState(state
);
2661 if (data
->immKbd
->pImeProcessKey(imc
, vKey
, lKeyData
, state
))
2663 data
->lastVK
= vKey
;
2667 data
->lastVK
= VK_PROCESSKEY
;