2 * The IME for interfacing with Mac input methods
4 * Copyright 2008, 2013 CodeWeavers, Aric Stewart
5 * Copyright 2013 Ken Thomases for CodeWeavers Inc.
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
24 * The normal flow for IMM/IME Processing is as follows.
25 * 1) The Keyboard Driver generates key messages which are first passed to
26 * the IMM and then to IME via ImeProcessKey. If the IME returns 0 then
27 * it does not want the key and the keyboard driver then generates the
28 * WM_KEYUP/WM_KEYDOWN messages. However if the IME is going to process the
29 * key it returns non-zero.
30 * 2) If the IME is going to process the key then the IMM calls ImeToAsciiEx to
31 * process the key. the IME modifies the HIMC structure to reflect the
32 * current state and generates any messages it needs the IMM to process.
33 * 3) IMM checks the messages and send them to the application in question. From
34 * here the IMM level deals with if the application is IME aware or not.
46 WINE_DEFAULT_DEBUG_CHANNEL(imm
);
48 #define FROM_MACDRV ((HIMC)0xcafe1337)
50 typedef struct _IMEPRIVATE
{
57 } IMEPRIVATE
, *LPIMEPRIVATE
;
59 typedef struct _tagTRANSMSG
{
63 } TRANSMSG
, *LPTRANSMSG
;
65 static const WCHAR UI_CLASS_NAME
[] = {'W','i','n','e',' ','M','a','c',' ','I','M','E',0};
67 static HIMC
*hSelectedFrom
= NULL
;
68 static INT hSelectedCount
= 0;
71 static UINT WM_MSIME_SERVICE
;
72 static UINT WM_MSIME_RECONVERTOPTIONS
;
73 static UINT WM_MSIME_MOUSE
;
74 static UINT WM_MSIME_RECONVERTREQUEST
;
75 static UINT WM_MSIME_RECONVERT
;
76 static UINT WM_MSIME_QUERYPOSITION
;
77 static UINT WM_MSIME_DOCUMENTFEED
;
80 static HIMC
RealIMC(HIMC hIMC
)
82 if (hIMC
== FROM_MACDRV
)
85 HWND wnd
= GetFocus();
86 HIMC winHimc
= ImmGetContext(wnd
);
87 for (i
= 0; i
< hSelectedCount
; i
++)
88 if (winHimc
== hSelectedFrom
[i
])
96 static LPINPUTCONTEXT
LockRealIMC(HIMC hIMC
)
98 HIMC real_imc
= RealIMC(hIMC
);
100 return ImmLockIMC(real_imc
);
105 static BOOL
UnlockRealIMC(HIMC hIMC
)
107 HIMC real_imc
= RealIMC(hIMC
);
109 return ImmUnlockIMC(real_imc
);
114 static HIMCC
ImeCreateBlankCompStr(void)
117 LPCOMPOSITIONSTRING ptr
;
118 rc
= ImmCreateIMCC(sizeof(COMPOSITIONSTRING
));
119 ptr
= ImmLockIMCC(rc
);
120 memset(ptr
, 0, sizeof(COMPOSITIONSTRING
));
121 ptr
->dwSize
= sizeof(COMPOSITIONSTRING
);
126 static int updateField(DWORD origLen
, DWORD origOffset
, DWORD currentOffset
,
127 LPBYTE target
, LPBYTE source
, DWORD
* lenParam
,
128 DWORD
* offsetParam
, BOOL wchars
)
130 if (origLen
> 0 && origOffset
> 0)
132 int truelen
= origLen
;
134 truelen
*= sizeof(WCHAR
);
136 memcpy(&target
[currentOffset
], &source
[origOffset
], truelen
);
139 *offsetParam
= currentOffset
;
140 currentOffset
+= truelen
;
142 return currentOffset
;
145 static HIMCC
updateCompStr(HIMCC old
, LPCWSTR compstr
, DWORD len
, DWORD
*flags
)
147 /* we need to make sure the CompStr, CompClaus and CompAttr fields are all
151 LPBYTE newdata
= NULL
;
152 LPBYTE olddata
= NULL
;
153 LPCOMPOSITIONSTRING new_one
;
154 LPCOMPOSITIONSTRING lpcs
= NULL
;
155 INT current_offset
= 0;
157 TRACE("%s, %i\n", debugstr_wn(compstr
, len
), len
);
159 if (old
== NULL
&& compstr
== NULL
&& len
== 0)
162 if (compstr
== NULL
&& len
!= 0)
164 ERR("compstr is NULL however we have a len! Please report\n");
170 olddata
= ImmLockIMCC(old
);
171 lpcs
= (LPCOMPOSITIONSTRING
)olddata
;
174 needed_size
= sizeof(COMPOSITIONSTRING
) + len
* sizeof(WCHAR
) +
175 len
+ sizeof(DWORD
) * 2;
179 needed_size
+= lpcs
->dwCompReadAttrLen
;
180 needed_size
+= lpcs
->dwCompReadClauseLen
;
181 needed_size
+= lpcs
->dwCompReadStrLen
* sizeof(WCHAR
);
182 needed_size
+= lpcs
->dwResultReadClauseLen
;
183 needed_size
+= lpcs
->dwResultReadStrLen
* sizeof(WCHAR
);
184 needed_size
+= lpcs
->dwResultClauseLen
;
185 needed_size
+= lpcs
->dwResultStrLen
* sizeof(WCHAR
);
186 needed_size
+= lpcs
->dwPrivateSize
;
188 rc
= ImmCreateIMCC(needed_size
);
189 newdata
= ImmLockIMCC(rc
);
190 new_one
= (LPCOMPOSITIONSTRING
)newdata
;
192 new_one
->dwSize
= needed_size
;
193 current_offset
= sizeof(COMPOSITIONSTRING
);
196 current_offset
= updateField(lpcs
->dwCompReadAttrLen
,
197 lpcs
->dwCompReadAttrOffset
,
198 current_offset
, newdata
, olddata
,
199 &new_one
->dwCompReadAttrLen
,
200 &new_one
->dwCompReadAttrOffset
, FALSE
);
202 current_offset
= updateField(lpcs
->dwCompReadClauseLen
,
203 lpcs
->dwCompReadClauseOffset
,
204 current_offset
, newdata
, olddata
,
205 &new_one
->dwCompReadClauseLen
,
206 &new_one
->dwCompReadClauseOffset
, FALSE
);
208 current_offset
= updateField(lpcs
->dwCompReadStrLen
,
209 lpcs
->dwCompReadStrOffset
,
210 current_offset
, newdata
, olddata
,
211 &new_one
->dwCompReadStrLen
,
212 &new_one
->dwCompReadStrOffset
, TRUE
);
214 /* new CompAttr, CompClause, CompStr, dwCursorPos */
215 new_one
->dwDeltaStart
= 0;
216 new_one
->dwCursorPos
= lpcs
->dwCursorPos
;
218 current_offset
= updateField(lpcs
->dwResultReadClauseLen
,
219 lpcs
->dwResultReadClauseOffset
,
220 current_offset
, newdata
, olddata
,
221 &new_one
->dwResultReadClauseLen
,
222 &new_one
->dwResultReadClauseOffset
, FALSE
);
224 current_offset
= updateField(lpcs
->dwResultReadStrLen
,
225 lpcs
->dwResultReadStrOffset
,
226 current_offset
, newdata
, olddata
,
227 &new_one
->dwResultReadStrLen
,
228 &new_one
->dwResultReadStrOffset
, TRUE
);
230 current_offset
= updateField(lpcs
->dwResultClauseLen
,
231 lpcs
->dwResultClauseOffset
,
232 current_offset
, newdata
, olddata
,
233 &new_one
->dwResultClauseLen
,
234 &new_one
->dwResultClauseOffset
, FALSE
);
236 current_offset
= updateField(lpcs
->dwResultStrLen
,
237 lpcs
->dwResultStrOffset
,
238 current_offset
, newdata
, olddata
,
239 &new_one
->dwResultStrLen
,
240 &new_one
->dwResultStrOffset
, TRUE
);
242 current_offset
= updateField(lpcs
->dwPrivateSize
,
243 lpcs
->dwPrivateOffset
,
244 current_offset
, newdata
, olddata
,
245 &new_one
->dwPrivateSize
,
246 &new_one
->dwPrivateOffset
, FALSE
);
250 new_one
->dwCursorPos
= len
;
251 *flags
|= GCS_CURSORPOS
;
256 new_one
->dwCompAttrLen
= len
;
259 new_one
->dwCompAttrOffset
= current_offset
;
260 memset(&newdata
[current_offset
], ATTR_INPUT
, len
);
261 current_offset
+= len
;
267 new_one
->dwCompClauseLen
= sizeof(DWORD
) * 2;
268 new_one
->dwCompClauseOffset
= current_offset
;
269 *(DWORD
*)&newdata
[current_offset
] = 0;
270 current_offset
+= sizeof(DWORD
);
271 *(DWORD
*)&newdata
[current_offset
] = len
;
272 current_offset
+= sizeof(DWORD
);
275 new_one
->dwCompClauseLen
= 0;
278 new_one
->dwCompStrLen
= len
;
281 new_one
->dwCompStrOffset
= current_offset
;
282 memcpy(&newdata
[current_offset
], compstr
, len
* sizeof(WCHAR
));
293 static HIMCC
updateResultStr(HIMCC old
, LPWSTR resultstr
, DWORD len
)
295 /* we need to make sure the ResultStr and ResultClause fields are all
299 LPBYTE newdata
= NULL
;
300 LPBYTE olddata
= NULL
;
301 LPCOMPOSITIONSTRING new_one
;
302 LPCOMPOSITIONSTRING lpcs
= NULL
;
303 INT current_offset
= 0;
305 TRACE("%s, %i\n", debugstr_wn(resultstr
, len
), len
);
307 if (old
== NULL
&& resultstr
== NULL
&& len
== 0)
310 if (resultstr
== NULL
&& len
!= 0)
312 ERR("resultstr is NULL however we have a len! Please report\n");
318 olddata
= ImmLockIMCC(old
);
319 lpcs
= (LPCOMPOSITIONSTRING
)olddata
;
322 needed_size
= sizeof(COMPOSITIONSTRING
) + len
* sizeof(WCHAR
) +
327 needed_size
+= lpcs
->dwCompReadAttrLen
;
328 needed_size
+= lpcs
->dwCompReadClauseLen
;
329 needed_size
+= lpcs
->dwCompReadStrLen
* sizeof(WCHAR
);
330 needed_size
+= lpcs
->dwCompAttrLen
;
331 needed_size
+= lpcs
->dwCompClauseLen
;
332 needed_size
+= lpcs
->dwCompStrLen
* sizeof(WCHAR
);
333 needed_size
+= lpcs
->dwResultReadClauseLen
;
334 needed_size
+= lpcs
->dwResultReadStrLen
* sizeof(WCHAR
);
335 needed_size
+= lpcs
->dwPrivateSize
;
337 rc
= ImmCreateIMCC(needed_size
);
338 newdata
= ImmLockIMCC(rc
);
339 new_one
= (LPCOMPOSITIONSTRING
)newdata
;
341 new_one
->dwSize
= needed_size
;
342 current_offset
= sizeof(COMPOSITIONSTRING
);
345 current_offset
= updateField(lpcs
->dwCompReadAttrLen
,
346 lpcs
->dwCompReadAttrOffset
,
347 current_offset
, newdata
, olddata
,
348 &new_one
->dwCompReadAttrLen
,
349 &new_one
->dwCompReadAttrOffset
, FALSE
);
351 current_offset
= updateField(lpcs
->dwCompReadClauseLen
,
352 lpcs
->dwCompReadClauseOffset
,
353 current_offset
, newdata
, olddata
,
354 &new_one
->dwCompReadClauseLen
,
355 &new_one
->dwCompReadClauseOffset
, FALSE
);
357 current_offset
= updateField(lpcs
->dwCompReadStrLen
,
358 lpcs
->dwCompReadStrOffset
,
359 current_offset
, newdata
, olddata
,
360 &new_one
->dwCompReadStrLen
,
361 &new_one
->dwCompReadStrOffset
, TRUE
);
363 current_offset
= updateField(lpcs
->dwCompAttrLen
,
364 lpcs
->dwCompAttrOffset
,
365 current_offset
, newdata
, olddata
,
366 &new_one
->dwCompAttrLen
,
367 &new_one
->dwCompAttrOffset
, FALSE
);
369 current_offset
= updateField(lpcs
->dwCompClauseLen
,
370 lpcs
->dwCompClauseOffset
,
371 current_offset
, newdata
, olddata
,
372 &new_one
->dwCompClauseLen
,
373 &new_one
->dwCompClauseOffset
, FALSE
);
375 current_offset
= updateField(lpcs
->dwCompStrLen
,
376 lpcs
->dwCompStrOffset
,
377 current_offset
, newdata
, olddata
,
378 &new_one
->dwCompStrLen
,
379 &new_one
->dwCompStrOffset
, TRUE
);
381 new_one
->dwCursorPos
= lpcs
->dwCursorPos
;
382 new_one
->dwDeltaStart
= 0;
384 current_offset
= updateField(lpcs
->dwResultReadClauseLen
,
385 lpcs
->dwResultReadClauseOffset
,
386 current_offset
, newdata
, olddata
,
387 &new_one
->dwResultReadClauseLen
,
388 &new_one
->dwResultReadClauseOffset
, FALSE
);
390 current_offset
= updateField(lpcs
->dwResultReadStrLen
,
391 lpcs
->dwResultReadStrOffset
,
392 current_offset
, newdata
, olddata
,
393 &new_one
->dwResultReadStrLen
,
394 &new_one
->dwResultReadStrOffset
, TRUE
);
396 /* new ResultClause , ResultStr */
398 current_offset
= updateField(lpcs
->dwPrivateSize
,
399 lpcs
->dwPrivateOffset
,
400 current_offset
, newdata
, olddata
,
401 &new_one
->dwPrivateSize
,
402 &new_one
->dwPrivateOffset
, FALSE
);
409 new_one
->dwResultClauseLen
= sizeof(DWORD
) * 2;
410 new_one
->dwResultClauseOffset
= current_offset
;
411 *(DWORD
*)&newdata
[current_offset
] = 0;
412 current_offset
+= sizeof(DWORD
);
413 *(DWORD
*)&newdata
[current_offset
] = len
;
414 current_offset
+= sizeof(DWORD
);
417 new_one
->dwResultClauseLen
= 0;
420 new_one
->dwResultStrLen
= len
;
423 new_one
->dwResultStrOffset
= current_offset
;
424 memcpy(&newdata
[current_offset
], resultstr
, len
* sizeof(WCHAR
));
433 static void GenerateIMEMessage(HIMC hIMC
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
435 LPINPUTCONTEXT lpIMC
;
436 LPTRANSMSG lpTransMsg
;
438 lpIMC
= LockRealIMC(hIMC
);
442 lpIMC
->hMsgBuf
= ImmReSizeIMCC(lpIMC
->hMsgBuf
, (lpIMC
->dwNumMsgBuf
+ 1) * sizeof(TRANSMSG
));
446 lpTransMsg
= ImmLockIMCC(lpIMC
->hMsgBuf
);
450 lpTransMsg
+= lpIMC
->dwNumMsgBuf
;
451 lpTransMsg
->message
= msg
;
452 lpTransMsg
->wParam
= wParam
;
453 lpTransMsg
->lParam
= lParam
;
455 ImmUnlockIMCC(lpIMC
->hMsgBuf
);
456 lpIMC
->dwNumMsgBuf
++;
458 ImmGenerateMessage(RealIMC(hIMC
));
462 static void GenerateIMECHARMessages(HIMC hIMC
, LPWSTR String
, DWORD length
)
464 LPINPUTCONTEXT lpIMC
;
465 LPTRANSMSG lpTransMsg
;
471 lpIMC
= LockRealIMC(hIMC
);
475 lpIMC
->hMsgBuf
= ImmReSizeIMCC(lpIMC
->hMsgBuf
, (lpIMC
->dwNumMsgBuf
+ length
) * sizeof(TRANSMSG
));
479 lpTransMsg
= ImmLockIMCC(lpIMC
->hMsgBuf
);
483 lpTransMsg
+= lpIMC
->dwNumMsgBuf
;
484 for (i
= 0; i
< length
; i
++)
486 lpTransMsg
->message
= WM_IME_CHAR
;
487 lpTransMsg
->wParam
= String
[i
];
488 lpTransMsg
->lParam
= 1;
492 ImmUnlockIMCC(lpIMC
->hMsgBuf
);
493 lpIMC
->dwNumMsgBuf
+= length
;
495 ImmGenerateMessage(RealIMC(hIMC
));
499 static BOOL
GenerateMessageToTransKey(LPDWORD lpTransBuf
, UINT
*uNumTranMsgs
,
500 UINT msg
, WPARAM wParam
, LPARAM lParam
)
504 if (*uNumTranMsgs
+ 1 >= (UINT
)*lpTransBuf
)
507 ptr
= (LPTRANSMSG
)(lpTransBuf
+ 1 + *uNumTranMsgs
* 3);
509 ptr
->wParam
= wParam
;
510 ptr
->lParam
= lParam
;
517 static BOOL
IME_RemoveFromSelected(HIMC hIMC
)
520 for (i
= 0; i
< hSelectedCount
; i
++)
522 if (hSelectedFrom
[i
] == hIMC
)
524 if (i
< hSelectedCount
- 1)
525 memmove(&hSelectedFrom
[i
], &hSelectedFrom
[i
+ 1], (hSelectedCount
- i
- 1) * sizeof(HIMC
));
533 static void IME_AddToSelected(HIMC hIMC
)
537 hSelectedFrom
= HeapReAlloc(GetProcessHeap(), 0, hSelectedFrom
, hSelectedCount
* sizeof(HIMC
));
539 hSelectedFrom
= HeapAlloc(GetProcessHeap(), 0, sizeof(HIMC
));
540 hSelectedFrom
[hSelectedCount
- 1] = hIMC
;
543 static void UpdateDataInDefaultIMEWindow(HIMC hIMC
, HWND hwnd
, BOOL showable
)
545 LPCOMPOSITIONSTRING compstr
;
546 LPINPUTCONTEXT lpIMC
;
548 lpIMC
= LockRealIMC(hIMC
);
553 compstr
= ImmLockIMCC(lpIMC
->hCompStr
);
557 if (compstr
== NULL
|| compstr
->dwCompStrLen
== 0)
558 ShowWindow(hwnd
, SW_HIDE
);
560 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
562 RedrawWindow(hwnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_INVALIDATE
);
565 ImmUnlockIMCC(lpIMC
->hCompStr
);
570 BOOL WINAPI
ImeConfigure(HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
572 FIXME("(%p, %p, %d, %p): stub\n", hKL
, hWnd
, dwMode
, lpData
);
573 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
577 DWORD WINAPI
ImeConversionList(HIMC hIMC
, LPCWSTR lpSource
, LPCANDIDATELIST lpCandList
,
578 DWORD dwBufLen
, UINT uFlag
)
581 FIXME("(%p, %s, %p, %d, %d): stub\n", hIMC
, debugstr_w(lpSource
), lpCandList
,
583 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
587 BOOL WINAPI
ImeDestroy(UINT uForce
)
590 HeapFree(GetProcessHeap(), 0, hSelectedFrom
);
591 hSelectedFrom
= NULL
;
596 LRESULT WINAPI
ImeEscape(HIMC hIMC
, UINT uSubFunc
, LPVOID lpData
)
598 TRACE("%x %p\n", uSubFunc
, lpData
);
602 BOOL WINAPI
ImeProcessKey(HIMC hIMC
, UINT vKey
, LPARAM lKeyData
, const LPBYTE lpbKeyState
)
604 LPINPUTCONTEXT lpIMC
;
607 TRACE("hIMC %p vKey 0x%04x lKeyData 0x%08lx lpbKeyState %p\n", hIMC
, vKey
, lKeyData
, lpbKeyState
);
618 inIME
= macdrv_using_input_method();
619 lpIMC
= LockRealIMC(hIMC
);
622 LPIMEPRIVATE myPrivate
;
623 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
625 if (inIME
&& !myPrivate
->bInternalState
)
626 ImmSetOpenStatus(RealIMC(FROM_MACDRV
), TRUE
);
627 else if (!inIME
&& myPrivate
->bInternalState
)
629 ShowWindow(myPrivate
->hwndDefault
, SW_HIDE
);
630 ImmDestroyIMCC(lpIMC
->hCompStr
);
631 lpIMC
->hCompStr
= ImeCreateBlankCompStr();
632 ImmSetOpenStatus(RealIMC(FROM_MACDRV
), FALSE
);
635 myPrivate
->repeat
= (lKeyData
>> 30) & 0x1;
637 myPrivate
->bInternalState
= inIME
;
638 ImmUnlockIMCC(lpIMC
->hPrivate
);
645 BOOL WINAPI
ImeSelect(HIMC hIMC
, BOOL fSelect
)
647 LPINPUTCONTEXT lpIMC
;
648 TRACE("%p %s\n", hIMC
, fSelect
? "TRUE" : "FALSE");
650 if (hIMC
== FROM_MACDRV
)
652 ERR("ImeSelect should never be called from Cocoa\n");
661 return IME_RemoveFromSelected(hIMC
);
663 IME_AddToSelected(hIMC
);
665 /* Initialize our structures */
666 lpIMC
= LockRealIMC(hIMC
);
669 LPIMEPRIVATE myPrivate
;
670 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
671 myPrivate
->bInComposition
= FALSE
;
672 myPrivate
->bInternalState
= FALSE
;
673 myPrivate
->textfont
= NULL
;
674 myPrivate
->hwndDefault
= NULL
;
675 myPrivate
->repeat
= 0;
676 ImmUnlockIMCC(lpIMC
->hPrivate
);
683 BOOL WINAPI
ImeSetActiveContext(HIMC hIMC
, BOOL fFlag
)
685 FIXME("(%p, %x): stub\n", hIMC
, fFlag
);
689 UINT WINAPI
ImeToAsciiEx(UINT uVKey
, UINT uScanCode
, const LPBYTE lpbKeyState
,
690 LPDWORD lpdwTransKey
, UINT fuState
, HIMC hIMC
)
693 LPINPUTCONTEXT lpIMC
;
694 LPIMEPRIVATE myPrivate
;
699 TRACE("uVKey 0x%04x uScanCode 0x%04x fuState %u hIMC %p\n", uVKey
, uScanCode
, fuState
, hIMC
);
701 vkey
= LOWORD(uVKey
);
703 if (vkey
== VK_KANA
|| vkey
== VK_KANJI
|| vkey
== VK_MENU
)
705 TRACE("Skipping metakey\n");
709 lpIMC
= LockRealIMC(hIMC
);
710 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
711 if (!myPrivate
->bInternalState
)
713 ImmUnlockIMCC(lpIMC
->hPrivate
);
718 repeat
= myPrivate
->repeat
;
719 hwndDefault
= myPrivate
->hwndDefault
;
720 ImmUnlockIMCC(lpIMC
->hPrivate
);
723 TRACE("Processing Mac 0x%04x\n", vkey
);
724 macdrv_process_text_input(uVKey
, uScanCode
, repeat
, lpbKeyState
, hIMC
, &done
);
727 MsgWaitForMultipleObjectsEx(0, NULL
, INFINITE
, QS_POSTMESSAGE
| QS_SENDMESSAGE
, 0);
732 UINT msg
= (uScanCode
& 0x8000) ? WM_KEYUP
: WM_KEYDOWN
;
734 /* KeyStroke not processed by the IME
735 * so we need to rebuild the KeyDown message and pass it on to WINE
737 if (!GenerateMessageToTransKey(lpdwTransKey
, &msgs
, msg
, vkey
, MAKELONG(0x0001, uScanCode
)))
738 GenerateIMEMessage(hIMC
, msg
, vkey
, MAKELONG(0x0001, uScanCode
));
743 UpdateDataInDefaultIMEWindow(hIMC
, hwndDefault
, FALSE
);
747 BOOL WINAPI
NotifyIME(HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
750 LPINPUTCONTEXT lpIMC
;
752 TRACE("%p %i %i %i\n", hIMC
, dwAction
, dwIndex
, dwValue
);
754 lpIMC
= LockRealIMC(hIMC
);
760 case NI_OPENCANDIDATE
: FIXME("NI_OPENCANDIDATE\n"); break;
761 case NI_CLOSECANDIDATE
: FIXME("NI_CLOSECANDIDATE\n"); break;
762 case NI_SELECTCANDIDATESTR
: FIXME("NI_SELECTCANDIDATESTR\n"); break;
763 case NI_CHANGECANDIDATELIST
: FIXME("NI_CHANGECANDIDATELIST\n"); break;
764 case NI_SETCANDIDATE_PAGESTART
: FIXME("NI_SETCANDIDATE_PAGESTART\n"); break;
765 case NI_SETCANDIDATE_PAGESIZE
: FIXME("NI_SETCANDIDATE_PAGESIZE\n"); break;
766 case NI_CONTEXTUPDATED
:
769 case IMC_SETCOMPOSITIONWINDOW
: FIXME("NI_CONTEXTUPDATED: IMC_SETCOMPOSITIONWINDOW\n"); break;
770 case IMC_SETCONVERSIONMODE
: FIXME("NI_CONTEXTUPDATED: IMC_SETCONVERSIONMODE\n"); break;
771 case IMC_SETSENTENCEMODE
: FIXME("NI_CONTEXTUPDATED: IMC_SETSENTENCEMODE\n"); break;
772 case IMC_SETCANDIDATEPOS
: FIXME("NI_CONTEXTUPDATED: IMC_SETCANDIDATEPOS\n"); break;
773 case IMC_SETCOMPOSITIONFONT
:
775 LPIMEPRIVATE myPrivate
;
776 TRACE("NI_CONTEXTUPDATED: IMC_SETCOMPOSITIONFONT\n");
778 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
779 if (myPrivate
->textfont
)
781 DeleteObject(myPrivate
->textfont
);
782 myPrivate
->textfont
= NULL
;
784 myPrivate
->textfont
= CreateFontIndirectW(&lpIMC
->lfFont
.W
);
785 ImmUnlockIMCC(lpIMC
->hPrivate
);
788 case IMC_SETOPENSTATUS
:
790 LPIMEPRIVATE myPrivate
;
791 TRACE("NI_CONTEXTUPDATED: IMC_SETOPENSTATUS\n");
793 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
794 if (lpIMC
->fOpen
!= myPrivate
->bInternalState
&& myPrivate
->bInComposition
)
796 if(lpIMC
->fOpen
== FALSE
)
798 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
799 myPrivate
->bInComposition
= FALSE
;
803 GenerateIMEMessage(hIMC
, WM_IME_STARTCOMPOSITION
, 0, 0);
804 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, 0, 0);
807 myPrivate
->bInternalState
= lpIMC
->fOpen
;
811 default: FIXME("NI_CONTEXTUPDATED: Unknown\n"); break;
814 case NI_COMPOSITIONSTR
:
822 LPCOMPOSITIONSTRING cs
= NULL
;
824 LPIMEPRIVATE myPrivate
;
826 TRACE("NI_COMPOSITIONSTR: CPS_COMPLETE\n");
828 /* clear existing result */
829 newCompStr
= updateResultStr(lpIMC
->hCompStr
, NULL
, 0);
831 ImmDestroyIMCC(lpIMC
->hCompStr
);
832 lpIMC
->hCompStr
= newCompStr
;
836 cdata
= ImmLockIMCC(lpIMC
->hCompStr
);
837 cs
= (LPCOMPOSITIONSTRING
)cdata
;
838 cplen
= cs
->dwCompStrLen
;
839 cpstr
= (LPWSTR
)&cdata
[cs
->dwCompStrOffset
];
840 ImmUnlockIMCC(lpIMC
->hCompStr
);
842 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
845 WCHAR param
= cpstr
[0];
846 DWORD flags
= GCS_COMPSTR
;
848 newCompStr
= updateResultStr(lpIMC
->hCompStr
, cpstr
, cplen
);
849 ImmDestroyIMCC(lpIMC
->hCompStr
);
850 lpIMC
->hCompStr
= newCompStr
;
851 newCompStr
= updateCompStr(lpIMC
->hCompStr
, NULL
, 0, &flags
);
852 ImmDestroyIMCC(lpIMC
->hCompStr
);
853 lpIMC
->hCompStr
= newCompStr
;
855 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, 0, flags
);
857 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, param
,
858 GCS_RESULTSTR
| GCS_RESULTCLAUSE
);
860 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
862 else if (myPrivate
->bInComposition
)
863 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
866 myPrivate
->bInComposition
= FALSE
;
867 ImmUnlockIMCC(lpIMC
->hPrivate
);
872 case CPS_CONVERT
: FIXME("NI_COMPOSITIONSTR: CPS_CONVERT\n"); break;
873 case CPS_REVERT
: FIXME("NI_COMPOSITIONSTR: CPS_REVERT\n"); break;
876 LPIMEPRIVATE myPrivate
;
878 TRACE("NI_COMPOSITIONSTR: CPS_CANCEL\n");
881 ImmDestroyIMCC(lpIMC
->hCompStr
);
883 lpIMC
->hCompStr
= ImeCreateBlankCompStr();
885 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
886 if (myPrivate
->bInComposition
)
888 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
889 myPrivate
->bInComposition
= FALSE
;
891 ImmUnlockIMCC(lpIMC
->hPrivate
);
895 default: FIXME("NI_COMPOSITIONSTR: Unknown\n"); break;
898 default: FIXME("Unknown Message\n"); break;
905 BOOL WINAPI
ImeRegisterWord(LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
907 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
));
908 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
912 BOOL WINAPI
ImeUnregisterWord(LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
914 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszUnregister
));
915 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
919 UINT WINAPI
ImeGetRegisterWordStyle(UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
921 FIXME("(%d, %p): stub\n", nItem
, lpStyleBuf
);
922 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
926 UINT WINAPI
ImeEnumRegisterWord(REGISTERWORDENUMPROCW lpfnEnumProc
, LPCWSTR lpszReading
,
927 DWORD dwStyle
, LPCWSTR lpszRegister
, LPVOID lpData
)
929 FIXME("(%p, %s, %d, %s, %p): stub\n", lpfnEnumProc
, debugstr_w(lpszReading
), dwStyle
,
930 debugstr_w(lpszRegister
), lpData
);
931 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
935 static BOOL
IME_SetCompositionString(void* hIMC
, DWORD dwIndex
, LPCVOID lpComp
, DWORD dwCompLen
, DWORD cursor_pos
, BOOL cursor_valid
)
937 LPINPUTCONTEXT lpIMC
;
940 LPIMEPRIVATE myPrivate
;
942 TRACE("(%p, %d, %p, %d):\n", hIMC
, dwIndex
, lpComp
, dwCompLen
);
946 * this sets the composition string in the imm32.dll level
947 * of the composition buffer.
948 * TODO: set the Cocoa window's marked text string and tell text input context
951 lpIMC
= LockRealIMC(hIMC
);
956 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
958 if (dwIndex
== SCS_SETSTR
)
962 if (!myPrivate
->bInComposition
)
964 GenerateIMEMessage(hIMC
, WM_IME_STARTCOMPOSITION
, 0, 0);
965 myPrivate
->bInComposition
= TRUE
;
970 if (dwCompLen
&& lpComp
)
972 newCompStr
= updateCompStr(lpIMC
->hCompStr
, (LPCWSTR
)lpComp
, dwCompLen
/ sizeof(WCHAR
), &flags
);
973 ImmDestroyIMCC(lpIMC
->hCompStr
);
974 lpIMC
->hCompStr
= newCompStr
;
976 wParam
= ((const WCHAR
*)lpComp
)[0];
977 flags
|= GCS_COMPCLAUSE
| GCS_COMPATTR
| GCS_DELTASTART
;
981 newCompStr
= updateCompStr(lpIMC
->hCompStr
, NULL
, 0, &flags
);
982 ImmDestroyIMCC(lpIMC
->hCompStr
);
983 lpIMC
->hCompStr
= newCompStr
;
988 LPCOMPOSITIONSTRING compstr
;
989 compstr
= ImmLockIMCC(lpIMC
->hCompStr
);
990 compstr
->dwCursorPos
= cursor_pos
;
991 ImmUnlockIMCC(lpIMC
->hCompStr
);
992 flags
|= GCS_CURSORPOS
;
997 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, wParam
, flags
);
998 ImmUnlockIMCC(lpIMC
->hPrivate
);
1004 BOOL WINAPI
ImeSetCompositionString(HIMC hIMC
, DWORD dwIndex
, LPCVOID lpComp
, DWORD dwCompLen
,
1005 LPCVOID lpRead
, DWORD dwReadLen
)
1007 TRACE("(%p, %d, %p, %d, %p, %d):\n", hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
1009 if (lpRead
&& dwReadLen
)
1010 FIXME("Reading string unimplemented\n");
1012 return IME_SetCompositionString(hIMC
, dwIndex
, lpComp
, dwCompLen
, 0, FALSE
);
1015 DWORD WINAPI
ImeGetImeMenuItems(HIMC hIMC
, DWORD dwFlags
, DWORD dwType
, LPIMEMENUITEMINFOW lpImeParentMenu
,
1016 LPIMEMENUITEMINFOW lpImeMenu
, DWORD dwSize
)
1018 FIXME("(%p, %x %x %p %p %x): stub\n", hIMC
, dwFlags
, dwType
, lpImeParentMenu
, lpImeMenu
, dwSize
);
1019 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1023 static void IME_NotifyComplete(void* hIMC
)
1025 NotifyIME(hIMC
, NI_COMPOSITIONSTR
, CPS_COMPLETE
, 0);
1029 * Internal functions to help with IME window management
1031 static void PaintDefaultIMEWnd(HIMC hIMC
, HWND hwnd
)
1036 LPCOMPOSITIONSTRING compstr
;
1037 LPBYTE compdata
= NULL
;
1039 MONITORINFO mon_info
;
1040 INT offX
= 0, offY
= 0;
1041 LPINPUTCONTEXT lpIMC
;
1043 lpIMC
= LockRealIMC(hIMC
);
1047 hdc
= BeginPaint(hwnd
, &ps
);
1049 GetClientRect(hwnd
, &rect
);
1050 FillRect(hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
1052 compdata
= ImmLockIMCC(lpIMC
->hCompStr
);
1053 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1055 if (compstr
->dwCompStrLen
&& compstr
->dwCompStrOffset
)
1059 HFONT oldfont
= NULL
;
1061 LPIMEPRIVATE myPrivate
;
1063 CompString
= (LPWSTR
)(compdata
+ compstr
->dwCompStrOffset
);
1064 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
1066 if (myPrivate
->textfont
)
1067 oldfont
= SelectObject(hdc
, myPrivate
->textfont
);
1069 ImmUnlockIMCC(lpIMC
->hPrivate
);
1071 GetTextExtentPoint32W(hdc
, CompString
, compstr
->dwCompStrLen
, &size
);
1074 LPtoDP(hdc
, &pt
, 1);
1077 * How this works based on tests on windows:
1078 * CFS_POINT: then we start our window at the point and grow it as large
1079 * as it needs to be for the string.
1080 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
1081 * window is only as large as we need for the string, but we do not
1082 * grow such that our window exceeds the given rect. Wrapping if
1083 * needed and possible. If our ptCurrentPos is outside of our rect
1084 * then no window is displayed.
1085 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
1086 * maybe because the default MSIME does not do any IME adjusting.
1088 if (lpIMC
->cfCompForm
.dwStyle
!= CFS_DEFAULT
)
1090 POINT cpt
= lpIMC
->cfCompForm
.ptCurrentPos
;
1091 ClientToScreen(lpIMC
->hWnd
, &cpt
);
1094 rect
.right
= rect
.left
+ pt
.x
;
1095 rect
.bottom
= rect
.top
+ pt
.y
;
1096 monitor
= MonitorFromPoint(cpt
, MONITOR_DEFAULTTOPRIMARY
);
1098 else /* CFS_DEFAULT */
1100 /* Windows places the default IME window in the bottom left */
1101 HWND target
= lpIMC
->hWnd
;
1102 if (!target
) target
= GetFocus();
1104 GetWindowRect(target
, &rect
);
1105 rect
.top
= rect
.bottom
;
1106 rect
.right
= rect
.left
+ pt
.x
+ 20;
1107 rect
.bottom
= rect
.top
+ pt
.y
+ 20;
1109 monitor
= MonitorFromWindow(target
, MONITOR_DEFAULTTOPRIMARY
);
1112 if (lpIMC
->cfCompForm
.dwStyle
== CFS_RECT
)
1115 client
=lpIMC
->cfCompForm
.rcArea
;
1116 MapWindowPoints(lpIMC
->hWnd
, 0, (POINT
*)&client
, 2);
1117 IntersectRect(&rect
, &rect
, &client
);
1118 /* TODO: Wrap the input if needed */
1121 if (lpIMC
->cfCompForm
.dwStyle
== CFS_DEFAULT
)
1123 /* make sure we are on the desktop */
1124 mon_info
.cbSize
= sizeof(mon_info
);
1125 GetMonitorInfoW(monitor
, &mon_info
);
1127 if (rect
.bottom
> mon_info
.rcWork
.bottom
)
1129 int shift
= rect
.bottom
- mon_info
.rcWork
.bottom
;
1131 rect
.bottom
-= shift
;
1135 rect
.right
-= rect
.left
;
1138 if (rect
.right
> mon_info
.rcWork
.right
)
1140 int shift
= rect
.right
- mon_info
.rcWork
.right
;
1142 rect
.right
-= shift
;
1146 SetWindowPos(hwnd
, HWND_TOPMOST
, rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1147 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
1149 TextOutW(hdc
, offX
, offY
, CompString
, compstr
->dwCompStrLen
);
1152 SelectObject(hdc
, oldfont
);
1155 ImmUnlockIMCC(lpIMC
->hCompStr
);
1157 EndPaint(hwnd
, &ps
);
1158 UnlockRealIMC(hIMC
);
1161 static void DefaultIMEComposition(HIMC hIMC
, HWND hwnd
, LPARAM lParam
)
1163 TRACE("IME message WM_IME_COMPOSITION 0x%lx\n", lParam
);
1164 if (lParam
& GCS_RESULTSTR
)
1166 LPCOMPOSITIONSTRING compstr
;
1170 LPINPUTCONTEXT lpIMC
;
1172 lpIMC
= LockRealIMC(hIMC
);
1176 TRACE("Posting result as IME_CHAR\n");
1177 compdata
= ImmLockIMCC(lpIMC
->hCompStr
);
1178 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1179 ResultStr
= (LPWSTR
)(compdata
+ compstr
->dwResultStrOffset
);
1180 GenerateIMECHARMessages(hIMC
, ResultStr
, compstr
->dwResultStrLen
);
1181 ImmUnlockIMCC(lpIMC
->hCompStr
);
1183 /* clear the buffer */
1184 newCompStr
= updateResultStr(lpIMC
->hCompStr
, NULL
, 0);
1185 ImmDestroyIMCC(lpIMC
->hCompStr
);
1186 lpIMC
->hCompStr
= newCompStr
;
1187 UnlockRealIMC(hIMC
);
1190 UpdateDataInDefaultIMEWindow(hIMC
, hwnd
, TRUE
);
1193 static void DefaultIMEStartComposition(HIMC hIMC
, HWND hwnd
)
1195 LPINPUTCONTEXT lpIMC
;
1197 lpIMC
= LockRealIMC(hIMC
);
1201 TRACE("IME message WM_IME_STARTCOMPOSITION\n");
1202 lpIMC
->hWnd
= GetFocus();
1203 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
1204 UnlockRealIMC(hIMC
);
1207 static LRESULT
ImeHandleNotify(HIMC hIMC
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1211 case IMN_OPENSTATUSWINDOW
:
1212 FIXME("WM_IME_NOTIFY:IMN_OPENSTATUSWINDOW\n");
1214 case IMN_CLOSESTATUSWINDOW
:
1215 FIXME("WM_IME_NOTIFY:IMN_CLOSESTATUSWINDOW\n");
1217 case IMN_OPENCANDIDATE
:
1218 FIXME("WM_IME_NOTIFY:IMN_OPENCANDIDATE\n");
1220 case IMN_CHANGECANDIDATE
:
1221 FIXME("WM_IME_NOTIFY:IMN_CHANGECANDIDATE\n");
1223 case IMN_CLOSECANDIDATE
:
1224 FIXME("WM_IME_NOTIFY:IMN_CLOSECANDIDATE\n");
1226 case IMN_SETCONVERSIONMODE
:
1227 FIXME("WM_IME_NOTIFY:IMN_SETCONVERSIONMODE\n");
1229 case IMN_SETSENTENCEMODE
:
1230 FIXME("WM_IME_NOTIFY:IMN_SETSENTENCEMODE\n");
1232 case IMN_SETOPENSTATUS
:
1233 FIXME("WM_IME_NOTIFY:IMN_SETOPENSTATUS\n");
1235 case IMN_SETCANDIDATEPOS
:
1236 FIXME("WM_IME_NOTIFY:IMN_SETCANDIDATEPOS\n");
1238 case IMN_SETCOMPOSITIONFONT
:
1239 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONFONT\n");
1241 case IMN_SETCOMPOSITIONWINDOW
:
1242 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONWINDOW\n");
1245 FIXME("WM_IME_NOTIFY:IMN_GUIDELINE\n");
1247 case IMN_SETSTATUSWINDOWPOS
:
1248 FIXME("WM_IME_NOTIFY:IMN_SETSTATUSWINDOWPOS\n");
1251 FIXME("WM_IME_NOTIFY:<Unknown 0x%lx>\n", wParam
);
1257 static LRESULT WINAPI
IME_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1262 TRACE("Incoming Message 0x%x (0x%08lx, 0x%08lx)\n", msg
, wParam
, lParam
);
1265 * Each UI window contains the current Input Context.
1266 * This Input Context can be obtained by calling GetWindowLong
1267 * with IMMGWL_IMC when the UI window receives a WM_IME_xxx message.
1268 * The UI window can refer to this Input Context and handles the
1272 hIMC
= (HIMC
)GetWindowLongPtrW(hwnd
, IMMGWL_IMC
);
1274 hIMC
= RealIMC(FROM_MACDRV
);
1276 /* if we have no hIMC there are many messages we cannot process */
1280 case WM_IME_STARTCOMPOSITION
:
1281 case WM_IME_ENDCOMPOSITION
:
1282 case WM_IME_COMPOSITION
:
1284 case WM_IME_CONTROL
:
1285 case WM_IME_COMPOSITIONFULL
:
1298 LPIMEPRIVATE myPrivate
;
1299 LPINPUTCONTEXT lpIMC
;
1301 SetWindowTextA(hwnd
, "Wine Ime Active");
1303 lpIMC
= LockRealIMC(hIMC
);
1306 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
1307 myPrivate
->hwndDefault
= hwnd
;
1308 ImmUnlockIMCC(lpIMC
->hPrivate
);
1310 UnlockRealIMC(hIMC
);
1315 PaintDefaultIMEWnd(hIMC
, hwnd
);
1323 SetFocus((HWND
)wParam
);
1325 FIXME("Received focus, should never have focus\n");
1327 case WM_IME_COMPOSITION
:
1328 DefaultIMEComposition(hIMC
, hwnd
, lParam
);
1330 case WM_IME_STARTCOMPOSITION
:
1331 DefaultIMEStartComposition(hIMC
, hwnd
);
1333 case WM_IME_ENDCOMPOSITION
:
1334 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_ENDCOMPOSITION", wParam
, lParam
);
1335 ShowWindow(hwnd
, SW_HIDE
);
1338 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_SELECT", wParam
, lParam
);
1340 case WM_IME_CONTROL
:
1341 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_CONTROL", wParam
, lParam
);
1345 rc
= ImeHandleNotify(hIMC
, hwnd
, msg
, wParam
, lParam
);
1348 TRACE("Non-standard message 0x%x\n", msg
);
1350 /* check the MSIME messages */
1351 if (msg
== WM_MSIME_SERVICE
)
1353 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_SERVICE", wParam
, lParam
);
1356 else if (msg
== WM_MSIME_RECONVERTOPTIONS
)
1358 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERTOPTIONS", wParam
, lParam
);
1360 else if (msg
== WM_MSIME_MOUSE
)
1362 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_MOUSE", wParam
, lParam
);
1364 else if (msg
== WM_MSIME_RECONVERTREQUEST
)
1366 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERTREQUEST", wParam
, lParam
);
1368 else if (msg
== WM_MSIME_RECONVERT
)
1370 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERT", wParam
, lParam
);
1372 else if (msg
== WM_MSIME_QUERYPOSITION
)
1374 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_QUERYPOSITION", wParam
, lParam
);
1376 else if (msg
== WM_MSIME_DOCUMENTFEED
)
1378 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_DOCUMENTFEED", wParam
, lParam
);
1380 /* DefWndProc if not an IME message */
1381 if (!rc
&& !((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
1382 (msg
>= WM_IME_SETCONTEXT
&& msg
<= WM_IME_KEYUP
)))
1383 rc
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1388 static BOOL WINAPI
register_classes( INIT_ONCE
*once
, void *param
, void **context
)
1391 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1392 wndClass
.style
= CS_GLOBALCLASS
| CS_IME
| CS_HREDRAW
| CS_VREDRAW
;
1393 wndClass
.lpfnWndProc
= (WNDPROC
) IME_WindowProc
;
1394 wndClass
.cbClsExtra
= 0;
1395 wndClass
.cbWndExtra
= 2 * sizeof(LONG_PTR
);
1396 wndClass
.hInstance
= macdrv_module
;
1397 wndClass
.hCursor
= LoadCursorW(NULL
, (LPWSTR
)IDC_ARROW
);
1398 wndClass
.hIcon
= LoadIconW(NULL
, (LPWSTR
)IDI_APPLICATION
);
1399 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1400 wndClass
.lpszMenuName
= 0;
1401 wndClass
.lpszClassName
= UI_CLASS_NAME
;
1403 RegisterClassW(&wndClass
);
1405 WM_MSIME_SERVICE
= RegisterWindowMessageA("MSIMEService");
1406 WM_MSIME_RECONVERTOPTIONS
= RegisterWindowMessageA("MSIMEReconvertOptions");
1407 WM_MSIME_MOUSE
= RegisterWindowMessageA("MSIMEMouseOperation");
1408 WM_MSIME_RECONVERTREQUEST
= RegisterWindowMessageA("MSIMEReconvertRequest");
1409 WM_MSIME_RECONVERT
= RegisterWindowMessageA("MSIMEReconvert");
1410 WM_MSIME_QUERYPOSITION
= RegisterWindowMessageA("MSIMEQueryPosition");
1411 WM_MSIME_DOCUMENTFEED
= RegisterWindowMessageA("MSIMEDocumentFeed");
1415 BOOL WINAPI
ImeInquire(LPIMEINFO lpIMEInfo
, LPWSTR lpszUIClass
, LPCWSTR lpszOption
)
1417 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
1420 InitOnceExecuteOnce( &init_once
, register_classes
, NULL
, NULL
);
1421 lpIMEInfo
->dwPrivateDataSize
= sizeof(IMEPRIVATE
);
1422 lpIMEInfo
->fdwProperty
= IME_PROP_UNICODE
| IME_PROP_AT_CARET
;
1423 lpIMEInfo
->fdwConversionCaps
= IME_CMODE_NATIVE
| IME_CMODE_FULLSHAPE
;
1424 lpIMEInfo
->fdwSentenceCaps
= IME_SMODE_AUTOMATIC
;
1425 lpIMEInfo
->fdwUICaps
= UI_CAP_2700
;
1426 /* Tell App we cannot accept ImeSetCompositionString calls */
1427 /* FIXME: Can we? */
1428 lpIMEInfo
->fdwSCSCaps
= 0;
1429 lpIMEInfo
->fdwSelectCaps
= SELECT_CAP_CONVERSION
;
1431 lstrcpyW(lpszUIClass
, UI_CLASS_NAME
);
1436 /* Interfaces to other parts of the Mac driver */
1438 /***********************************************************************
1439 * macdrv_im_set_text
1441 void macdrv_im_set_text(const macdrv_event
*event
)
1443 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
1444 void *himc
= event
->im_set_text
.data
;
1446 TRACE("win %p/%p himc %p text %s complete %u\n", hwnd
, event
->window
, himc
,
1447 debugstr_cf(event
->im_set_text
.text
), event
->im_set_text
.complete
);
1449 if (!himc
) himc
= RealIMC(FROM_MACDRV
);
1451 if (event
->im_set_text
.text
)
1453 CFIndex length
= CFStringGetLength(event
->im_set_text
.text
);
1454 const UniChar
*chars
= CFStringGetCharactersPtr(event
->im_set_text
.text
);
1455 UniChar
*buffer
= NULL
;
1459 buffer
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(*buffer
));
1460 CFStringGetCharacters(event
->im_set_text
.text
, CFRangeMake(0, length
), buffer
);
1465 IME_SetCompositionString(himc
, SCS_SETSTR
, chars
, length
* sizeof(*chars
),
1466 event
->im_set_text
.cursor_pos
, !event
->im_set_text
.complete
);
1472 input
.type
= INPUT_KEYBOARD
;
1475 input
.ki
.dwExtraInfo
= 0;
1477 for (i
= 0; i
< length
; i
++)
1479 input
.ki
.wScan
= chars
[i
];
1480 input
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
1481 __wine_send_input(hwnd
, &input
);
1483 input
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1484 __wine_send_input(hwnd
, &input
);
1488 HeapFree(GetProcessHeap(), 0, buffer
);
1491 if (event
->im_set_text
.complete
)
1492 IME_NotifyComplete(himc
);
1495 /***********************************************************************
1496 * macdrv_sent_text_input
1498 void macdrv_sent_text_input(const macdrv_event
*event
)
1500 TRACE("handled: %s\n", event
->sent_text_input
.handled
? "TRUE" : "FALSE");
1501 *event
->sent_text_input
.done
= event
->sent_text_input
.handled
? 1 : -1;
1505 /**************************************************************************
1506 * query_ime_char_rect
1508 BOOL
query_ime_char_rect(macdrv_query
* query
)
1510 HWND hwnd
= macdrv_get_window_hwnd(query
->window
);
1511 void *himc
= query
->ime_char_rect
.data
;
1512 CFRange
* range
= &query
->ime_char_rect
.range
;
1513 CGRect
* rect
= &query
->ime_char_rect
.rect
;
1514 IMECHARPOSITION charpos
;
1517 TRACE("win %p/%p himc %p range %ld-%ld\n", hwnd
, query
->window
, himc
, range
->location
,
1520 if (!himc
) himc
= RealIMC(FROM_MACDRV
);
1522 charpos
.dwSize
= sizeof(charpos
);
1523 charpos
.dwCharPos
= range
->location
;
1524 if (ImmRequestMessageW(himc
, IMR_QUERYCHARPOSITION
, (ULONG_PTR
)&charpos
))
1528 *rect
= CGRectMake(charpos
.pt
.x
, charpos
.pt
.y
, 0, charpos
.cLineHeight
);
1530 /* iterate over rest of length to extend rect */
1531 for (i
= 1; i
< range
->length
; i
++)
1533 charpos
.dwSize
= sizeof(charpos
);
1534 charpos
.dwCharPos
= range
->location
+ i
;
1535 if (!ImmRequestMessageW(himc
, IMR_QUERYCHARPOSITION
, (ULONG_PTR
)&charpos
) ||
1536 charpos
.pt
.y
!= rect
->origin
.y
)
1542 rect
->size
.width
= charpos
.pt
.x
- rect
->origin
.x
;
1550 LPINPUTCONTEXT ic
= ImmLockIMC(himc
);
1554 LPIMEPRIVATE
private = ImmLockIMCC(ic
->hPrivate
);
1555 LPBYTE compdata
= ImmLockIMCC(ic
->hCompStr
);
1556 LPCOMPOSITIONSTRING compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1557 LPWSTR str
= (LPWSTR
)(compdata
+ compstr
->dwCompStrOffset
);
1559 if (private->hwndDefault
&& compstr
->dwCompStrOffset
&&
1560 IsWindowVisible(private->hwndDefault
))
1562 HDC dc
= GetDC(private->hwndDefault
);
1563 HFONT oldfont
= NULL
;
1566 if (private->textfont
)
1567 oldfont
= SelectObject(dc
, private->textfont
);
1569 if (range
->location
> compstr
->dwCompStrLen
)
1570 range
->location
= compstr
->dwCompStrLen
;
1571 if (range
->location
+ range
->length
> compstr
->dwCompStrLen
)
1572 range
->length
= compstr
->dwCompStrLen
- range
->location
;
1574 GetTextExtentPoint32W(dc
, str
, range
->location
, &size
);
1575 charpos
.rcDocument
.left
= size
.cx
;
1576 charpos
.rcDocument
.top
= 0;
1577 GetTextExtentPoint32W(dc
, str
, range
->location
+ range
->length
, &size
);
1578 charpos
.rcDocument
.right
= size
.cx
;
1579 charpos
.rcDocument
.bottom
= size
.cy
;
1581 if (ic
->cfCompForm
.dwStyle
== CFS_DEFAULT
)
1582 OffsetRect(&charpos
.rcDocument
, 10, 10);
1584 LPtoDP(dc
, (POINT
*)&charpos
.rcDocument
, 2);
1585 MapWindowPoints(private->hwndDefault
, 0, (POINT
*)&charpos
.rcDocument
, 2);
1586 *rect
= cgrect_from_rect(charpos
.rcDocument
);
1590 SelectObject(dc
, oldfont
);
1591 ReleaseDC(private->hwndDefault
, dc
);
1594 ImmUnlockIMCC(ic
->hCompStr
);
1595 ImmUnlockIMCC(ic
->hPrivate
);
1604 gti
.cbSize
= sizeof(gti
);
1605 if (GetGUIThreadInfo(0, >i
))
1607 MapWindowPoints(gti
.hwndCaret
, 0, (POINT
*)>i
.rcCaret
, 2);
1608 *rect
= cgrect_from_rect(gti
.rcCaret
);
1613 if (ret
&& range
->length
&& !rect
->size
.width
)
1614 rect
->size
.width
= 1;
1616 TRACE(" -> %s range %ld-%ld rect %s\n", ret
? "TRUE" : "FALSE", range
->location
,
1617 range
->length
, wine_dbgstr_cgrect(*rect
));