janitorial: Pass HEAP_ZERO_MEMORY as flag to HeapAlloc() instead of zeroing out the...
[wine/wine-kai.git] / dlls / imm32 / imm.c
blobbc3f7a9f10a45bc86a9eadd0e7c5e6f0ce631125
1 /*
2 * IMM32 library
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2002, 2003 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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winerror.h"
29 #include "wine/debug.h"
30 #include "imm.h"
31 #include "winnls.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(imm);
35 #define FROM_IME 0xcafe1337
37 static void (*pX11DRV_ForceXIMReset)(HWND);
39 typedef struct tagInputContextData
41 LPBYTE CompositionString;
42 LPBYTE CompositionReadingString;
43 LPBYTE ResultString;
44 LPBYTE ResultReadingString;
45 DWORD dwCompStringSize; /* buffer size */
46 DWORD dwCompStringLength; /* string length (in bytes) */
47 DWORD dwCompReadStringSize;
48 DWORD dwResultStringSize;
49 DWORD dwResultReadStringSize;
50 HWND hwnd;
51 BOOL bOpen;
52 BOOL bInternalState;
53 BOOL bRead;
54 BOOL bInComposition;
55 LOGFONTW font;
56 HFONT textfont;
57 COMPOSITIONFORM CompForm;
58 } InputContextData;
60 static InputContextData *root_context = NULL;
61 static HWND hwndDefault = NULL;
62 static HANDLE hImeInst;
63 static const WCHAR WC_IMECLASSNAME[] = {'I','M','E',0};
64 static ATOM atIMEClass = 0;
66 /* MSIME messages */
67 static UINT WM_MSIME_SERVICE;
68 static UINT WM_MSIME_RECONVERTOPTIONS;
69 static UINT WM_MSIME_MOUSE;
70 static UINT WM_MSIME_RECONVERTREQUEST;
71 static UINT WM_MSIME_RECONVERT;
72 static UINT WM_MSIME_QUERYPOSITION;
73 static UINT WM_MSIME_DOCUMENTFEED;
76 * prototypes
78 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
79 LPARAM lParam);
80 static void UpdateDataInDefaultIMEWindow(HWND hwnd);
81 static void ImmInternalPostIMEMessage(UINT, WPARAM, LPARAM);
82 static void ImmInternalSetOpenStatus(BOOL fOpen);
84 static VOID IMM_PostResult(InputContextData *data)
86 unsigned int i;
87 TRACE("Posting result as IME_CHAR\n");
89 for (i = 0; i < data->dwResultStringSize / sizeof (WCHAR); i++)
90 ImmInternalPostIMEMessage (WM_IME_CHAR, ((WCHAR*)data->ResultString)[i],
91 1);
93 /* clear the buffer */
94 if (data->dwResultStringSize)
95 HeapFree(GetProcessHeap(),0,data->ResultString);
96 data->dwResultStringSize = 0;
97 data->ResultString = NULL;
100 static void IMM_Register(void)
102 WNDCLASSW wndClass;
103 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
104 wndClass.style = CS_GLOBALCLASS | CS_IME | CS_HREDRAW | CS_VREDRAW;
105 wndClass.lpfnWndProc = (WNDPROC) IME_WindowProc;
106 wndClass.cbClsExtra = 0;
107 wndClass.cbWndExtra = 0;
108 wndClass.hInstance = hImeInst;
109 wndClass.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
110 wndClass.hIcon = NULL;
111 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
112 wndClass.lpszMenuName = 0;
113 wndClass.lpszClassName = WC_IMECLASSNAME;
114 atIMEClass = RegisterClassW(&wndClass);
117 static void IMM_Unregister(void)
119 if (atIMEClass) {
120 UnregisterClassW(WC_IMECLASSNAME, NULL);
124 static void IMM_RegisterMessages(void)
126 WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
127 WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
128 WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
129 WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
130 WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
131 WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
132 WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
136 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
138 HMODULE x11drv;
140 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
141 switch (fdwReason)
143 case DLL_PROCESS_ATTACH:
144 DisableThreadLibraryCalls(hInstDLL);
145 hImeInst = hInstDLL;
146 IMM_RegisterMessages();
147 x11drv = GetModuleHandleA("winex11.drv");
148 if (x11drv) pX11DRV_ForceXIMReset = (void *)GetProcAddress( x11drv, "ForceXIMReset");
149 break;
150 case DLL_PROCESS_DETACH:
151 if (hwndDefault)
153 DestroyWindow(hwndDefault);
154 hwndDefault = 0;
156 IMM_Unregister();
157 break;
159 return TRUE;
162 /* for posting messages as the IME */
163 static void ImmInternalPostIMEMessage(UINT msg, WPARAM wParam, LPARAM lParam)
165 HWND target = GetFocus();
166 if (!target)
167 PostMessageW(root_context->hwnd,msg,wParam,lParam);
168 else
169 PostMessageW(target, msg, wParam, lParam);
172 static LRESULT ImmInternalSendIMENotify(WPARAM notify, LPARAM lParam)
174 HWND target;
176 target = root_context->hwnd;
177 if (!target) target = GetFocus();
179 if (target)
180 return SendMessageW(target, WM_IME_NOTIFY, notify, lParam);
182 return 0;
185 static void ImmInternalSetOpenStatus(BOOL fOpen)
187 TRACE("Setting internal state to %s\n",(fOpen)?"OPEN":"CLOSED");
189 root_context->bOpen = fOpen;
190 root_context->bInternalState = fOpen;
192 if (fOpen == FALSE)
194 ShowWindow(hwndDefault,SW_HIDE);
196 if (root_context->dwCompStringSize)
197 HeapFree(GetProcessHeap(),0,root_context->CompositionString);
198 if (root_context->dwCompReadStringSize)
199 HeapFree(GetProcessHeap(),0,root_context->CompositionReadingString);
200 if (root_context->dwResultStringSize)
201 HeapFree(GetProcessHeap(),0,root_context->ResultString);
202 if (root_context->dwResultReadStringSize)
203 HeapFree(GetProcessHeap(),0,root_context->ResultReadingString);
204 root_context->dwCompStringSize = 0;
205 root_context->dwCompStringLength = 0;
206 root_context->CompositionString = NULL;
207 root_context->dwCompReadStringSize = 0;
208 root_context->CompositionReadingString = NULL;
209 root_context->dwResultStringSize = 0;
210 root_context->ResultString = NULL;
211 root_context->dwResultReadStringSize = 0;
212 root_context->ResultReadingString = NULL;
214 else
215 ShowWindow(hwndDefault, SW_SHOWNOACTIVATE);
217 ImmInternalSendIMENotify(IMN_SETOPENSTATUS, 0);
221 /***********************************************************************
222 * ImmAssociateContext (IMM32.@)
224 HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
226 InputContextData *data = (InputContextData*)hIMC;
228 WARN("(%p, %p): semi-stub\n", hWnd, hIMC);
230 if (!hIMC)
231 return NULL;
234 * WINE SPECIFIC! MAY CONFLICT
235 * associate the root context we have an XIM created
237 if (hWnd == 0x000)
239 root_context = (InputContextData*)hIMC;
243 * If already associated just return
245 if (data->hwnd == hWnd)
246 return hIMC;
248 if (IsWindow(data->hwnd))
251 * Post a message that your context is switching
253 SendMessageW(data->hwnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
256 data->hwnd = hWnd;
258 if (IsWindow(data->hwnd))
261 * Post a message that your context is switching
263 SendMessageW(data->hwnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
267 * TODO: We need to keep track of the old context associated
268 * with a window and return it for now we will return NULL;
270 return NULL;
273 /***********************************************************************
274 * ImmAssociateContextEx (IMM32.@)
276 BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
278 FIXME("(%p, %p, %d): stub\n", hWnd, hIMC, dwFlags);
279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
280 return FALSE;
283 /***********************************************************************
284 * ImmConfigureIMEA (IMM32.@)
286 BOOL WINAPI ImmConfigureIMEA(
287 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
289 FIXME("(%p, %p, %d, %p): stub\n",
290 hKL, hWnd, dwMode, lpData
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
293 return FALSE;
296 /***********************************************************************
297 * ImmConfigureIMEW (IMM32.@)
299 BOOL WINAPI ImmConfigureIMEW(
300 HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
302 FIXME("(%p, %p, %d, %p): stub\n",
303 hKL, hWnd, dwMode, lpData
305 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
306 return FALSE;
309 /***********************************************************************
310 * ImmCreateContext (IMM32.@)
312 HIMC WINAPI ImmCreateContext(void)
314 InputContextData *new_context;
316 new_context = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputContextData));
318 return (HIMC)new_context;
321 /***********************************************************************
322 * ImmDestroyContext (IMM32.@)
324 BOOL WINAPI ImmDestroyContext(HIMC hIMC)
326 InputContextData *data = (InputContextData*)hIMC;
328 TRACE("Destroying %p\n",hIMC);
330 if (hIMC)
332 if (data->dwCompStringSize)
333 HeapFree(GetProcessHeap(),0,data->CompositionString);
334 if (data->dwCompReadStringSize)
335 HeapFree(GetProcessHeap(),0,data->CompositionReadingString);
336 if (data->dwResultStringSize)
337 HeapFree(GetProcessHeap(),0,data->ResultString);
338 if (data->dwResultReadStringSize)
339 HeapFree(GetProcessHeap(),0,data->ResultReadingString);
341 if (data->textfont)
343 DeleteObject(data->textfont);
344 data->textfont = NULL;
347 HeapFree(GetProcessHeap(),0,data);
349 return TRUE;
352 /***********************************************************************
353 * ImmDisableIME (IMM32.@)
355 BOOL WINAPI ImmDisableIME(DWORD idThread)
357 FIXME("(%d): stub\n", idThread);
358 return TRUE;
361 /***********************************************************************
362 * ImmEnumRegisterWordA (IMM32.@)
364 UINT WINAPI ImmEnumRegisterWordA(
365 HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
366 LPCSTR lpszReading, DWORD dwStyle,
367 LPCSTR lpszRegister, LPVOID lpData)
369 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
370 hKL, lpfnEnumProc,
371 debugstr_a(lpszReading), dwStyle,
372 debugstr_a(lpszRegister), lpData
374 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
375 return 0;
378 /***********************************************************************
379 * ImmEnumRegisterWordW (IMM32.@)
381 UINT WINAPI ImmEnumRegisterWordW(
382 HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
383 LPCWSTR lpszReading, DWORD dwStyle,
384 LPCWSTR lpszRegister, LPVOID lpData)
386 FIXME("(%p, %p, %s, %d, %s, %p): stub\n",
387 hKL, lpfnEnumProc,
388 debugstr_w(lpszReading), dwStyle,
389 debugstr_w(lpszRegister), lpData
391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
392 return 0;
395 /***********************************************************************
396 * ImmEscapeA (IMM32.@)
398 LRESULT WINAPI ImmEscapeA(
399 HKL hKL, HIMC hIMC,
400 UINT uEscape, LPVOID lpData)
402 FIXME("(%p, %p, %d, %p): stub\n",
403 hKL, hIMC, uEscape, lpData
405 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
406 return 0;
409 /***********************************************************************
410 * ImmEscapeW (IMM32.@)
412 LRESULT WINAPI ImmEscapeW(
413 HKL hKL, HIMC hIMC,
414 UINT uEscape, LPVOID lpData)
416 FIXME("(%p, %p, %d, %p): stub\n",
417 hKL, hIMC, uEscape, lpData
419 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
420 return 0;
423 /***********************************************************************
424 * ImmGetCandidateListA (IMM32.@)
426 DWORD WINAPI ImmGetCandidateListA(
427 HIMC hIMC, DWORD deIndex,
428 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
430 FIXME("(%p, %d, %p, %d): stub\n",
431 hIMC, deIndex,
432 lpCandList, dwBufLen
434 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
435 return 0;
438 /***********************************************************************
439 * ImmGetCandidateListCountA (IMM32.@)
441 DWORD WINAPI ImmGetCandidateListCountA(
442 HIMC hIMC, LPDWORD lpdwListCount)
444 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
446 return 0;
449 /***********************************************************************
450 * ImmGetCandidateListCountW (IMM32.@)
452 DWORD WINAPI ImmGetCandidateListCountW(
453 HIMC hIMC, LPDWORD lpdwListCount)
455 FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
456 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
457 return 0;
460 /***********************************************************************
461 * ImmGetCandidateListW (IMM32.@)
463 DWORD WINAPI ImmGetCandidateListW(
464 HIMC hIMC, DWORD deIndex,
465 LPCANDIDATELIST lpCandList, DWORD dwBufLen)
467 FIXME("(%p, %d, %p, %d): stub\n",
468 hIMC, deIndex,
469 lpCandList, dwBufLen
471 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
472 return 0;
475 /***********************************************************************
476 * ImmGetCandidateWindow (IMM32.@)
478 BOOL WINAPI ImmGetCandidateWindow(
479 HIMC hIMC, DWORD dwBufLen, LPCANDIDATEFORM lpCandidate)
481 FIXME("(%p, %d, %p): stub\n", hIMC, dwBufLen, lpCandidate);
482 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
483 return FALSE;
486 /***********************************************************************
487 * ImmGetCompositionFontA (IMM32.@)
489 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
491 FIXME("(%p, %p): stub\n", hIMC, lplf);
492 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
493 return FALSE;
496 /***********************************************************************
497 * ImmGetCompositionFontW (IMM32.@)
499 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
501 FIXME("(%p, %p): stub\n", hIMC, lplf);
502 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
503 return FALSE;
506 /***********************************************************************
507 * ImmGetCompositionStringA (IMM32.@)
509 LONG WINAPI ImmGetCompositionStringA(
510 HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
512 CHAR *buf;
513 LONG rc = 0;
514 InputContextData *data = (InputContextData*)hIMC;
516 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
518 if (!data)
519 return FALSE;
521 if (dwIndex == GCS_RESULTSTR)
523 TRACE("GSC_RESULTSTR %p %i\n",data->ResultString,
524 data->dwResultStringSize);
526 buf = HeapAlloc( GetProcessHeap(), 0, data->dwResultStringSize * 3 );
527 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->ResultString,
528 data->dwResultStringSize / sizeof(WCHAR), buf,
529 data->dwResultStringSize * 3, NULL, NULL);
530 if (dwBufLen >= rc)
531 memcpy(lpBuf,buf,rc);
533 data->bRead = TRUE;
534 HeapFree( GetProcessHeap(), 0, buf );
536 else if (dwIndex == GCS_COMPSTR)
538 TRACE("GSC_COMPSTR %p %i\n", data->CompositionString, data->dwCompStringLength);
540 buf = HeapAlloc( GetProcessHeap(), 0, data->dwCompStringLength * 3 );
541 rc = WideCharToMultiByte(CP_ACP, 0,(LPWSTR)data->CompositionString,
542 data->dwCompStringLength/ sizeof(WCHAR), buf,
543 data->dwCompStringLength* 3, NULL, NULL);
544 if (dwBufLen >= rc)
545 memcpy(lpBuf,buf,rc);
546 HeapFree( GetProcessHeap(), 0, buf );
548 else if (dwIndex == GCS_COMPATTR)
550 TRACE("GSC_COMPATTR %p %i\n", data->CompositionString, data->dwCompStringLength);
552 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->CompositionString,
553 data->dwCompStringLength/ sizeof(WCHAR), NULL,
554 0, NULL, NULL);
556 if (dwBufLen >= rc)
558 int i=0;
559 for (i = 0; i < rc; i++)
560 ((LPBYTE)lpBuf)[i] = ATTR_INPUT;
563 else if (dwIndex == GCS_COMPCLAUSE)
565 TRACE("GSC_COMPCLAUSE %p %i\n", data->CompositionString, data->dwCompStringLength);
567 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->CompositionString,
568 data->dwCompStringLength/ sizeof(WCHAR), NULL,
569 0, NULL, NULL);
571 if (dwBufLen >= sizeof(DWORD)*2)
573 ((LPDWORD)lpBuf)[0] = 0;
574 ((LPDWORD)lpBuf)[1] = rc;
576 rc = sizeof(DWORD)*2;
578 else if (dwIndex == GCS_RESULTCLAUSE)
580 TRACE("GSC_RESULTCLAUSE %p %i\n", data->ResultString, data->dwResultStringSize);
582 rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->ResultString,
583 data->dwResultStringSize/ sizeof(WCHAR), NULL,
584 0, NULL, NULL);
586 if (dwBufLen >= sizeof(DWORD)*2)
588 ((LPDWORD)lpBuf)[0] = 0;
589 ((LPDWORD)lpBuf)[1] = rc;
591 rc = sizeof(DWORD)*2;
593 else
595 FIXME("Unhandled index 0x%x\n",dwIndex);
598 return rc;
601 /***********************************************************************
602 * ImmGetCompositionStringW (IMM32.@)
604 LONG WINAPI ImmGetCompositionStringW(
605 HIMC hIMC, DWORD dwIndex,
606 LPVOID lpBuf, DWORD dwBufLen)
608 LONG rc = 0;
609 InputContextData *data = (InputContextData*)hIMC;
611 TRACE("(%p, 0x%x, %p, %d)\n", hIMC, dwIndex, lpBuf, dwBufLen);
613 if (!data)
614 return FALSE;
616 if (dwIndex == GCS_RESULTSTR)
618 data->bRead = TRUE;
620 if (dwBufLen >= data->dwResultStringSize)
621 memcpy(lpBuf,data->ResultString,data->dwResultStringSize);
623 rc = data->dwResultStringSize;
625 else if (dwIndex == GCS_RESULTREADSTR)
627 if (dwBufLen >= data->dwResultReadStringSize)
628 memcpy(lpBuf,data->ResultReadingString,
629 data->dwResultReadStringSize);
631 rc = data->dwResultReadStringSize;
633 else if (dwIndex == GCS_COMPSTR)
635 if (dwBufLen >= data->dwCompStringLength)
636 memcpy(lpBuf,data->CompositionString,data->dwCompStringLength);
638 rc = data->dwCompStringLength;
640 else if (dwIndex == GCS_COMPATTR)
642 unsigned int len = data->dwCompStringLength;
644 if (dwBufLen >= len)
646 unsigned int i=0;
647 for (i = 0; i < len; i++)
648 ((LPBYTE)lpBuf)[i] = ATTR_INPUT;
651 rc = len;
653 else if (dwIndex == GCS_COMPCLAUSE)
655 if (dwBufLen >= sizeof(DWORD)*2)
657 ((LPDWORD)lpBuf)[0] = 0;
658 ((LPDWORD)lpBuf)[1] = data->dwCompStringLength/sizeof(WCHAR);
660 rc = sizeof(DWORD)*2;
662 else if (dwIndex == GCS_COMPREADSTR)
664 if (dwBufLen >= data->dwCompReadStringSize)
665 memcpy(lpBuf,data->CompositionReadingString,
666 data->dwCompReadStringSize);
668 rc = data->dwCompReadStringSize;
670 else
672 FIXME("Unhandled index 0x%x\n",dwIndex);
675 return rc;
678 /***********************************************************************
679 * ImmGetCompositionWindow (IMM32.@)
681 BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
683 InputContextData *data = (InputContextData*)hIMC;
685 TRACE("(%p, %p)\n", hIMC, lpCompForm);
687 if (!data)
688 return FALSE;
690 memcpy(lpCompForm,&(data->CompForm),sizeof(COMPOSITIONFORM));
691 return 1;
694 /***********************************************************************
695 * ImmGetContext (IMM32.@)
698 HIMC WINAPI ImmGetContext(HWND hWnd)
700 TRACE("%p\n", hWnd);
702 if (!root_context)
703 return NULL;
705 root_context->hwnd = hWnd;
706 return (HIMC)root_context;
709 /***********************************************************************
710 * ImmGetConversionListA (IMM32.@)
712 DWORD WINAPI ImmGetConversionListA(
713 HKL hKL, HIMC hIMC,
714 LPCSTR pSrc, LPCANDIDATELIST lpDst,
715 DWORD dwBufLen, UINT uFlag)
717 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
718 hKL, hIMC, debugstr_a(pSrc), lpDst, dwBufLen, uFlag
720 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
721 return 0;
724 /***********************************************************************
725 * ImmGetConversionListW (IMM32.@)
727 DWORD WINAPI ImmGetConversionListW(
728 HKL hKL, HIMC hIMC,
729 LPCWSTR pSrc, LPCANDIDATELIST lpDst,
730 DWORD dwBufLen, UINT uFlag)
732 FIXME("(%p, %p, %s, %p, %d, %d): stub\n",
733 hKL, hIMC, debugstr_w(pSrc), lpDst, dwBufLen, uFlag
735 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
736 return 0;
739 /***********************************************************************
740 * ImmGetConversionStatus (IMM32.@)
742 BOOL WINAPI ImmGetConversionStatus(
743 HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
745 TRACE("(%p, %p, %p): best guess\n", hIMC, lpfdwConversion, lpfdwSentence);
746 if (lpfdwConversion)
747 *lpfdwConversion = IME_CMODE_NATIVE;
748 if (lpfdwSentence)
749 *lpfdwSentence = IME_SMODE_NONE;
750 return TRUE;
753 /***********************************************************************
754 * ImmGetDefaultIMEWnd (IMM32.@)
756 HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
758 FIXME("(%p - %p %p ): semi-stub\n", hWnd,hwndDefault, root_context);
760 if (hwndDefault == NULL)
762 static const WCHAR the_name[] = {'I','M','E','\0'};
764 IMM_Register();
765 hwndDefault = CreateWindowExW( WS_EX_TOOLWINDOW, WC_IMECLASSNAME,
766 the_name, WS_POPUP, 0, 0, 1, 1, 0, 0,
767 hImeInst, 0);
769 TRACE("Default created (%p)\n",hwndDefault);
772 return (HWND)hwndDefault;
775 /***********************************************************************
776 * ImmGetDescriptionA (IMM32.@)
778 UINT WINAPI ImmGetDescriptionA(
779 HKL hKL, LPSTR lpszDescription, UINT uBufLen)
781 WCHAR *buf;
782 DWORD len;
784 TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);
786 /* find out how many characters in the unicode buffer */
787 len = ImmGetDescriptionW( hKL, NULL, 0 );
789 /* allocate a buffer of that size */
790 buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
791 if( !buf )
792 return 0;
794 /* fetch the unicode buffer */
795 len = ImmGetDescriptionW( hKL, buf, len + 1 );
797 /* convert it back to ASCII */
798 len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
799 lpszDescription, uBufLen, NULL, NULL );
801 HeapFree( GetProcessHeap(), 0, buf );
803 return len;
806 /***********************************************************************
807 * ImmGetDescriptionW (IMM32.@)
809 UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
811 static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };
813 FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);
815 if (!uBufLen) return lstrlenW( name );
816 lstrcpynW( lpszDescription, name, uBufLen );
817 return lstrlenW( lpszDescription );
820 /***********************************************************************
821 * ImmGetGuideLineA (IMM32.@)
823 DWORD WINAPI ImmGetGuideLineA(
824 HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
826 FIXME("(%p, %d, %s, %d): stub\n",
827 hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
829 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
830 return 0;
833 /***********************************************************************
834 * ImmGetGuideLineW (IMM32.@)
836 DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
838 FIXME("(%p, %d, %s, %d): stub\n",
839 hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
841 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
842 return 0;
845 /***********************************************************************
846 * ImmGetIMEFileNameA (IMM32.@)
848 UINT WINAPI ImmGetIMEFileNameA(
849 HKL hKL, LPSTR lpszFileName, UINT uBufLen)
851 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
852 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
853 return 0;
856 /***********************************************************************
857 * ImmGetIMEFileNameW (IMM32.@)
859 UINT WINAPI ImmGetIMEFileNameW(
860 HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
862 FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
863 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
864 return 0;
867 /***********************************************************************
868 * ImmGetOpenStatus (IMM32.@)
870 BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
872 InputContextData *data = (InputContextData*)hIMC;
874 if (!data)
875 return FALSE;
876 FIXME("(%p): semi-stub\n", hIMC);
878 return data->bOpen;
881 /***********************************************************************
882 * ImmGetProperty (IMM32.@)
884 DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
886 DWORD rc = 0;
887 TRACE("(%p, %d)\n", hKL, fdwIndex);
889 switch (fdwIndex)
891 case IGP_PROPERTY:
892 TRACE("(%s)\n", "IGP_PROPERTY");
893 rc = IME_PROP_UNICODE | IME_PROP_AT_CARET;
894 break;
895 case IGP_CONVERSION:
896 FIXME("(%s)\n", "IGP_CONVERSION");
897 rc = IME_CMODE_NATIVE;
898 break;
899 case IGP_SENTENCE:
900 FIXME("%s)\n", "IGP_SENTENCE");
901 rc = IME_SMODE_AUTOMATIC;
902 break;
903 case IGP_SETCOMPSTR:
904 TRACE("(%s)\n", "IGP_SETCOMPSTR");
905 rc = 0;
906 break;
907 case IGP_SELECT:
908 TRACE("(%s)\n", "IGP_SELECT");
909 rc = SELECT_CAP_CONVERSION | SELECT_CAP_SENTENCE;
910 break;
911 case IGP_GETIMEVERSION:
912 TRACE("(%s)\n", "IGP_GETIMEVERSION");
913 rc = IMEVER_0400;
914 break;
915 case IGP_UI:
916 TRACE("(%s)\n", "IGP_UI");
917 rc = 0;
918 break;
919 default:
920 rc = 0;
922 return rc;
925 /***********************************************************************
926 * ImmGetRegisterWordStyleA (IMM32.@)
928 UINT WINAPI ImmGetRegisterWordStyleA(
929 HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
931 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
932 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
933 return 0;
936 /***********************************************************************
937 * ImmGetRegisterWordStyleW (IMM32.@)
939 UINT WINAPI ImmGetRegisterWordStyleW(
940 HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
942 FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
943 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
944 return 0;
947 /***********************************************************************
948 * ImmGetStatusWindowPos (IMM32.@)
950 BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
952 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
953 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
954 return FALSE;
957 /***********************************************************************
958 * ImmGetVirtualKey (IMM32.@)
960 UINT WINAPI ImmGetVirtualKey(HWND hWnd)
962 OSVERSIONINFOA version;
963 FIXME("(%p): stub\n", hWnd);
964 GetVersionExA( &version );
965 switch(version.dwPlatformId)
967 case VER_PLATFORM_WIN32_WINDOWS:
968 return VK_PROCESSKEY;
969 case VER_PLATFORM_WIN32_NT:
970 return 0;
971 default:
972 FIXME("%d not supported\n",version.dwPlatformId);
973 return VK_PROCESSKEY;
977 /***********************************************************************
978 * ImmInstallIMEA (IMM32.@)
980 HKL WINAPI ImmInstallIMEA(
981 LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
983 FIXME("(%s, %s): stub\n",
984 debugstr_a(lpszIMEFileName), debugstr_a(lpszLayoutText)
986 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
987 return NULL;
990 /***********************************************************************
991 * ImmInstallIMEW (IMM32.@)
993 HKL WINAPI ImmInstallIMEW(
994 LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
996 FIXME("(%s, %s): stub\n",
997 debugstr_w(lpszIMEFileName), debugstr_w(lpszLayoutText)
999 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1000 return NULL;
1003 /***********************************************************************
1004 * ImmIsIME (IMM32.@)
1006 BOOL WINAPI ImmIsIME(HKL hKL)
1008 TRACE("(%p): semi-stub\n", hKL);
1010 * FIXME: Dead key locales will return TRUE here when they should not
1011 * There is probably a more proper way to check this.
1013 return (root_context != NULL);
1016 /***********************************************************************
1017 * ImmIsUIMessageA (IMM32.@)
1019 BOOL WINAPI ImmIsUIMessageA(
1020 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1022 BOOL rc = FALSE;
1024 TRACE("(%p, %x, %d, %ld)\n", hWndIME, msg, wParam, lParam);
1025 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1026 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1027 (msg == WM_MSIME_SERVICE) ||
1028 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1029 (msg == WM_MSIME_MOUSE) ||
1030 (msg == WM_MSIME_RECONVERTREQUEST) ||
1031 (msg == WM_MSIME_RECONVERT) ||
1032 (msg == WM_MSIME_QUERYPOSITION) ||
1033 (msg == WM_MSIME_DOCUMENTFEED))
1036 if (!hwndDefault)
1037 ImmGetDefaultIMEWnd(NULL);
1039 if (hWndIME == NULL)
1040 PostMessageA(hwndDefault, msg, wParam, lParam);
1042 rc = TRUE;
1044 return rc;
1047 /***********************************************************************
1048 * ImmIsUIMessageW (IMM32.@)
1050 BOOL WINAPI ImmIsUIMessageW(
1051 HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
1053 BOOL rc = FALSE;
1054 TRACE("(%p, %d, %d, %ld): stub\n", hWndIME, msg, wParam, lParam);
1055 if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1056 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
1057 (msg == WM_MSIME_SERVICE) ||
1058 (msg == WM_MSIME_RECONVERTOPTIONS) ||
1059 (msg == WM_MSIME_MOUSE) ||
1060 (msg == WM_MSIME_RECONVERTREQUEST) ||
1061 (msg == WM_MSIME_RECONVERT) ||
1062 (msg == WM_MSIME_QUERYPOSITION) ||
1063 (msg == WM_MSIME_DOCUMENTFEED))
1064 rc = TRUE;
1065 return rc;
1068 /***********************************************************************
1069 * ImmNotifyIME (IMM32.@)
1071 BOOL WINAPI ImmNotifyIME(
1072 HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
1074 BOOL rc = FALSE;
1076 TRACE("(%p, %d, %d, %d)\n",
1077 hIMC, dwAction, dwIndex, dwValue);
1079 if (!root_context)
1080 return rc;
1082 switch(dwAction)
1084 case NI_CHANGECANDIDATELIST:
1085 FIXME("%s\n","NI_CHANGECANDIDATELIST");
1086 break;
1087 case NI_CLOSECANDIDATE:
1088 FIXME("%s\n","NI_CLOSECANDIDATE");
1089 break;
1090 case NI_COMPOSITIONSTR:
1091 switch (dwIndex)
1093 case CPS_CANCEL:
1094 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL");
1095 if (pX11DRV_ForceXIMReset)
1096 pX11DRV_ForceXIMReset(root_context->hwnd);
1097 if (root_context->dwCompStringSize)
1099 HeapFree(GetProcessHeap(),0,
1100 root_context->CompositionString);
1101 root_context->dwCompStringSize = 0;
1102 root_context->dwCompStringLength = 0;
1103 root_context->CompositionString = NULL;
1104 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1105 GCS_COMPSTR);
1107 rc = TRUE;
1108 break;
1109 case CPS_COMPLETE:
1110 TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_COMPLETE");
1111 if (hIMC != (HIMC)FROM_IME && pX11DRV_ForceXIMReset)
1112 pX11DRV_ForceXIMReset(root_context->hwnd);
1114 if (root_context->dwResultStringSize)
1116 HeapFree(GetProcessHeap(),0,root_context->ResultString);
1117 root_context->dwResultStringSize = 0;
1118 root_context->ResultString = NULL;
1120 if (root_context->dwCompStringLength)
1122 root_context->ResultString = HeapAlloc(
1123 GetProcessHeap(), 0, root_context->dwCompStringLength);
1124 root_context->dwResultStringSize =
1125 root_context->dwCompStringLength;
1127 memcpy(root_context->ResultString,
1128 root_context->CompositionString,
1129 root_context->dwCompStringLength);
1131 HeapFree(GetProcessHeap(),0,
1132 root_context->CompositionString);
1134 root_context->dwCompStringSize = 0;
1135 root_context->dwCompStringLength = 0;
1136 root_context->CompositionString = NULL;
1137 root_context->bRead = FALSE;
1139 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
1140 GCS_COMPSTR);
1142 ImmInternalPostIMEMessage(WM_IME_COMPOSITION,
1143 root_context->ResultString[0],
1144 GCS_RESULTSTR|GCS_RESULTCLAUSE);
1146 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION, 0, 0);
1147 root_context->bInComposition = FALSE;
1149 break;
1150 case CPS_CONVERT:
1151 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_CONVERT");
1152 break;
1153 case CPS_REVERT:
1154 FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_REVERT");
1155 break;
1156 default:
1157 ERR("%s - %s (%i)\n","NI_COMPOSITIONSTR","UNKNOWN",dwIndex);
1158 break;
1160 break;
1161 case NI_IMEMENUSELECTED:
1162 FIXME("%s\n", "NI_IMEMENUSELECTED");
1163 break;
1164 case NI_OPENCANDIDATE:
1165 FIXME("%s\n", "NI_OPENCANDIDATE");
1166 break;
1167 case NI_SELECTCANDIDATESTR:
1168 FIXME("%s\n", "NI_SELECTCANDIDATESTR");
1169 break;
1170 case NI_SETCANDIDATE_PAGESIZE:
1171 FIXME("%s\n", "NI_SETCANDIDATE_PAGESIZE");
1172 break;
1173 case NI_SETCANDIDATE_PAGESTART:
1174 FIXME("%s\n", "NI_SETCANDIDATE_PAGESTART");
1175 break;
1176 default:
1177 ERR("Unknown\n");
1180 return rc;
1183 /***********************************************************************
1184 * ImmRegisterWordA (IMM32.@)
1186 BOOL WINAPI ImmRegisterWordA(
1187 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
1189 FIXME("(%p, %s, %d, %s): stub\n",
1190 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister)
1192 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1193 return FALSE;
1196 /***********************************************************************
1197 * ImmRegisterWordW (IMM32.@)
1199 BOOL WINAPI ImmRegisterWordW(
1200 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
1202 FIXME("(%p, %s, %d, %s): stub\n",
1203 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister)
1205 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1206 return FALSE;
1209 /***********************************************************************
1210 * ImmReleaseContext (IMM32.@)
1212 BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
1214 FIXME("(%p, %p): stub\n", hWnd, hIMC);
1216 return TRUE;
1219 /***********************************************************************
1220 * ImmSetCandidateWindow (IMM32.@)
1222 BOOL WINAPI ImmSetCandidateWindow(
1223 HIMC hIMC, LPCANDIDATEFORM lpCandidate)
1225 FIXME("(%p, %p): stub\n", hIMC, lpCandidate);
1226 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1227 return FALSE;
1230 /***********************************************************************
1231 * ImmSetCompositionFontA (IMM32.@)
1233 BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
1235 InputContextData *data = (InputContextData*)hIMC;
1236 TRACE("(%p, %p)\n", hIMC, lplf);
1238 if (!data)
1239 return FALSE;
1241 memcpy(&data->font,lplf,sizeof(LOGFONTA));
1242 MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->font.lfFaceName,
1243 LF_FACESIZE);
1245 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1247 if (data->textfont)
1249 DeleteObject(data->textfont);
1250 data->textfont = NULL;
1253 data->textfont = CreateFontIndirectW(&data->font);
1254 return TRUE;
1257 /***********************************************************************
1258 * ImmSetCompositionFontW (IMM32.@)
1260 BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
1262 InputContextData *data = (InputContextData*)hIMC;
1263 TRACE("(%p, %p)\n", hIMC, lplf);
1265 if (!data)
1266 return FALSE;
1268 memcpy(&data->font,lplf,sizeof(LOGFONTW));
1269 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONFONT, 0);
1271 if (data->textfont)
1273 DeleteObject(data->textfont);
1274 data->textfont = NULL;
1276 data->textfont = CreateFontIndirectW(&data->font);
1277 return TRUE;
1280 /***********************************************************************
1281 * ImmSetCompositionStringA (IMM32.@)
1283 BOOL WINAPI ImmSetCompositionStringA(
1284 HIMC hIMC, DWORD dwIndex,
1285 LPCVOID lpComp, DWORD dwCompLen,
1286 LPCVOID lpRead, DWORD dwReadLen)
1288 DWORD comp_len;
1289 DWORD read_len;
1290 WCHAR *CompBuffer = NULL;
1291 WCHAR *ReadBuffer = NULL;
1292 BOOL rc;
1294 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1295 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1297 comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
1298 if (comp_len)
1300 CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
1301 MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
1304 read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
1305 if (read_len)
1307 ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
1308 MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
1311 rc = ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
1312 ReadBuffer, read_len);
1314 HeapFree(GetProcessHeap(), 0, CompBuffer);
1315 HeapFree(GetProcessHeap(), 0, ReadBuffer);
1317 return rc;
1320 /***********************************************************************
1321 * ImmSetCompositionStringW (IMM32.@)
1323 BOOL WINAPI ImmSetCompositionStringW(
1324 HIMC hIMC, DWORD dwIndex,
1325 LPCVOID lpComp, DWORD dwCompLen,
1326 LPCVOID lpRead, DWORD dwReadLen)
1328 DWORD flags = 0;
1329 WCHAR wParam = 0;
1331 TRACE("(%p, %d, %p, %d, %p, %d): stub\n",
1332 hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1335 if (hIMC != (HIMC)FROM_IME)
1336 FIXME("PROBLEM: This only sets the wine level string\n");
1339 * Explanation:
1340 * this sets the composition string in the imm32.dll level
1341 * of the composition buffer. we cannot manipulate the xim level
1342 * buffer, which means that once the xim level buffer changes again
1343 * any call to this function from the application will be lost
1346 if (lpRead && dwReadLen)
1347 FIXME("Reading string unimplemented\n");
1350 * app operating this api to also receive the message from xim
1353 if (dwIndex == SCS_SETSTR)
1355 if (!root_context->bInComposition)
1357 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION, 0, 0);
1358 root_context->bInComposition = TRUE;
1361 flags = GCS_COMPSTR;
1363 if (root_context->dwCompStringLength)
1364 HeapFree(GetProcessHeap(),0,root_context->CompositionString);
1366 root_context->dwCompStringLength = dwCompLen;
1367 root_context->dwCompStringSize = dwCompLen;
1369 if (dwCompLen && lpComp)
1371 root_context->CompositionString = HeapAlloc(GetProcessHeap(), 0,
1372 dwCompLen);
1373 memcpy(root_context->CompositionString,lpComp,dwCompLen);
1375 wParam = ((const WCHAR*)lpComp)[0];
1376 flags |= GCS_COMPCLAUSE | GCS_COMPATTR;
1378 else
1379 root_context->CompositionString = NULL;
1383 UpdateDataInDefaultIMEWindow(hwndDefault);
1385 ImmInternalPostIMEMessage(WM_IME_COMPOSITION, wParam, flags);
1387 return TRUE;
1390 /***********************************************************************
1391 * ImmSetCompositionWindow (IMM32.@)
1393 BOOL WINAPI ImmSetCompositionWindow(
1394 HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
1396 BOOL reshow = FALSE;
1397 InputContextData *data = (InputContextData*)hIMC;
1399 TRACE("(%p, %p)\n", hIMC, lpCompForm);
1400 TRACE("\t%x, (%i,%i), (%i,%i - %i,%i)\n",lpCompForm->dwStyle,
1401 lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
1402 lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);
1404 if (!data)
1405 return FALSE;
1407 memcpy(&data->CompForm,lpCompForm,sizeof(COMPOSITIONFORM));
1409 if (IsWindowVisible(hwndDefault))
1411 reshow = TRUE;
1412 ShowWindow(hwndDefault,SW_HIDE);
1415 /* FIXME: this is a partial stub */
1417 if (reshow)
1418 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
1420 ImmInternalSendIMENotify(IMN_SETCOMPOSITIONWINDOW, 0);
1421 return TRUE;
1424 /***********************************************************************
1425 * ImmSetConversionStatus (IMM32.@)
1427 BOOL WINAPI ImmSetConversionStatus(
1428 HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
1430 FIXME("(%p, %d, %d): stub\n",
1431 hIMC, fdwConversion, fdwSentence
1433 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1434 return FALSE;
1437 /***********************************************************************
1438 * ImmSetOpenStatus (IMM32.@)
1440 BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
1442 InputContextData *data = (InputContextData*)hIMC;
1444 TRACE("%p %d\n", hIMC, fOpen);
1446 if (hIMC == (HIMC)FROM_IME)
1448 ImmInternalSetOpenStatus(fOpen);
1449 ImmInternalSendIMENotify(IMN_SETOPENSTATUS, 0);
1450 return TRUE;
1453 if (!data)
1454 return FALSE;
1456 if (fOpen != data->bInternalState)
1458 if (fOpen == FALSE && pX11DRV_ForceXIMReset)
1459 pX11DRV_ForceXIMReset(data->hwnd);
1461 if (fOpen == FALSE)
1462 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1463 else
1464 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1466 ImmInternalSetOpenStatus(fOpen);
1467 ImmInternalSetOpenStatus(!fOpen);
1469 if (data->bOpen == FALSE)
1470 ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
1471 else
1472 ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);
1474 return FALSE;
1476 return TRUE;
1479 /***********************************************************************
1480 * ImmSetStatusWindowPos (IMM32.@)
1482 BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
1484 FIXME("(%p, %p): stub\n", hIMC, lpptPos);
1485 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1486 return FALSE;
1489 /***********************************************************************
1490 * ImmSimulateHotKey (IMM32.@)
1492 BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
1494 FIXME("(%p, %d): stub\n", hWnd, dwHotKeyID);
1495 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1496 return FALSE;
1499 /***********************************************************************
1500 * ImmUnregisterWordA (IMM32.@)
1502 BOOL WINAPI ImmUnregisterWordA(
1503 HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
1505 FIXME("(%p, %s, %d, %s): stub\n",
1506 hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszUnregister)
1508 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1509 return FALSE;
1512 /***********************************************************************
1513 * ImmUnregisterWordW (IMM32.@)
1515 BOOL WINAPI ImmUnregisterWordW(
1516 HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
1518 FIXME("(%p, %s, %d, %s): stub\n",
1519 hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszUnregister)
1521 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1522 return FALSE;
1525 /***********************************************************************
1526 * ImmGetImeMenuItemsA (IMM32.@)
1528 DWORD WINAPI ImmGetImeMenuItemsA( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1529 LPIMEMENUITEMINFOA lpImeParentMenu, LPIMEMENUITEMINFOA lpImeMenu,
1530 DWORD dwSize)
1532 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1533 lpImeParentMenu, lpImeMenu, dwSize);
1534 return 0;
1537 /***********************************************************************
1538 * ImmGetImeMenuItemsW (IMM32.@)
1540 DWORD WINAPI ImmGetImeMenuItemsW( HIMC hIMC, DWORD dwFlags, DWORD dwType,
1541 LPIMEMENUITEMINFOW lpImeParentMenu, LPIMEMENUITEMINFOW lpImeMenu,
1542 DWORD dwSize)
1544 FIXME("(%p, %i, %i, %p, %p, %i): stub\n", hIMC, dwFlags, dwType,
1545 lpImeParentMenu, lpImeMenu, dwSize);
1546 return 0;
1549 /*****
1550 * Internal functions to help with IME window management
1552 static void PaintDefaultIMEWnd(HWND hwnd)
1554 PAINTSTRUCT ps;
1555 RECT rect;
1556 HDC hdc = BeginPaint(hwnd,&ps);
1557 GetClientRect(hwnd,&rect);
1558 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
1560 if (root_context->dwCompStringLength && root_context->CompositionString)
1562 SIZE size;
1563 POINT pt;
1564 HFONT oldfont = NULL;
1566 if (root_context->textfont)
1567 oldfont = SelectObject(hdc,root_context->textfont);
1570 GetTextExtentPoint32W(hdc, (LPWSTR)root_context->CompositionString,
1571 root_context->dwCompStringLength / sizeof(WCHAR),
1572 &size);
1573 pt.x = size.cx;
1574 pt.y = size.cy;
1575 LPtoDP(hdc,&pt,1);
1577 if (root_context->CompForm.dwStyle == CFS_POINT ||
1578 root_context->CompForm.dwStyle == CFS_FORCE_POSITION)
1580 POINT cpt = root_context->CompForm.ptCurrentPos;
1581 ClientToScreen(root_context->hwnd,&cpt);
1582 rect.left = cpt.x;
1583 rect.top = cpt.y;
1584 rect.right = rect.left + pt.x + 20;
1585 rect.bottom = rect.top + pt.y + 20;
1587 else if (root_context->CompForm.dwStyle == CFS_RECT)
1589 POINT cpt;
1590 cpt.x = root_context->CompForm.rcArea.left;
1591 cpt.y = root_context->CompForm.rcArea.top;
1592 ClientToScreen(root_context->hwnd,&cpt);
1593 rect.left = cpt.x;
1594 rect.top = cpt.y;
1595 cpt.x = root_context->CompForm.rcArea.right;
1596 cpt.y = root_context->CompForm.rcArea.bottom;
1597 ClientToScreen(root_context->hwnd,&cpt);
1598 rect.right = cpt.x;
1599 rect.bottom = cpt.y;
1601 else
1603 rect.right = rect.left + pt.x + 20;
1604 rect.bottom = rect.top + pt.y + 20;
1606 MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left ,
1607 rect.bottom - rect.top, FALSE);
1608 TextOutW(hdc, 10,10,(LPWSTR)root_context->CompositionString,
1609 root_context->dwCompStringLength / sizeof(WCHAR));
1611 if (oldfont)
1612 SelectObject(hdc,oldfont);
1614 EndPaint(hwnd,&ps);
1617 static void UpdateDataInDefaultIMEWindow(HWND hwnd)
1619 RedrawWindow(hwnd,NULL,NULL,RDW_ERASENOW|RDW_INVALIDATE);
1623 * The window proc for the default IME window
1625 static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
1626 LPARAM lParam)
1628 LRESULT rc = 0;
1630 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", msg, (UINT)wParam,
1631 (UINT)lParam);
1633 switch(msg)
1635 case WM_PAINT:
1636 PaintDefaultIMEWnd(hwnd);
1637 return FALSE;
1639 case WM_NCCREATE:
1640 return TRUE;
1642 case WM_CREATE:
1643 SetWindowTextA(hwnd,"Wine Ime Active");
1644 return TRUE;
1646 case WM_SETFOCUS:
1647 if (wParam)
1648 SetFocus((HWND)wParam);
1649 else
1650 FIXME("Received focus, should never have focus\n");
1651 break;
1652 case WM_IME_COMPOSITION:
1653 TRACE("IME message %s, 0x%x, 0x%x (%i)\n",
1654 "WM_IME_COMPOSITION", (UINT)wParam, (UINT)lParam,
1655 root_context->bRead);
1656 if (lParam & GCS_RESULTSTR)
1657 IMM_PostResult(root_context);
1658 else
1659 UpdateDataInDefaultIMEWindow(hwnd);
1660 break;
1661 case WM_IME_STARTCOMPOSITION:
1662 TRACE("IME message %s, 0x%x, 0x%x\n",
1663 "WM_IME_STARTCOMPOSITION", (UINT)wParam, (UINT)lParam);
1664 root_context->hwnd = GetFocus();
1665 ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
1666 break;
1667 case WM_IME_ENDCOMPOSITION:
1668 TRACE("IME message %s, 0x%x, 0x%x\n",
1669 "WM_IME_ENDCOMPOSITION", (UINT)wParam, (UINT)lParam);
1670 ShowWindow(hwndDefault,SW_HIDE);
1671 break;
1672 case WM_IME_SELECT:
1673 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_SELECT",
1674 (UINT)wParam, (UINT)lParam);
1675 break;
1676 case WM_IME_CONTROL:
1677 TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_CONTROL",
1678 (UINT)wParam, (UINT)lParam);
1679 rc = 1;
1680 break;
1681 case WM_IME_NOTIFY:
1682 TRACE("!! IME NOTIFY\n");
1683 break;
1684 default:
1685 TRACE("Non-standard message 0x%x\n",msg);
1687 /* check the MSIME messages */
1688 if (msg == WM_MSIME_SERVICE)
1690 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_SERVICE",
1691 (UINT)wParam, (UINT)lParam);
1692 rc = FALSE;
1694 else if (msg == WM_MSIME_RECONVERTOPTIONS)
1696 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTOPTIONS",
1697 (UINT)wParam, (UINT)lParam);
1699 else if (msg == WM_MSIME_MOUSE)
1701 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_MOUSE",
1702 (UINT)wParam, (UINT)lParam);
1704 else if (msg == WM_MSIME_RECONVERTREQUEST)
1706 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTREQUEST",
1707 (UINT)wParam, (UINT)lParam);
1709 else if (msg == WM_MSIME_RECONVERT)
1711 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERT",
1712 (UINT)wParam, (UINT)lParam);
1714 else if (msg == WM_MSIME_QUERYPOSITION)
1716 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_QUERYPOSITION",
1717 (UINT)wParam, (UINT)lParam);
1719 else if (msg == WM_MSIME_DOCUMENTFEED)
1721 TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_DOCUMENTFEED",
1722 (UINT)wParam, (UINT)lParam);
1724 /* DefWndProc if not an IME message */
1725 else if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
1726 (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
1727 rc = DefWindowProcW(hwnd,msg,wParam,lParam);
1729 return rc;