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(DWORD
);
182 needed_size
+= lpcs
->dwResultReadClauseLen
;
183 needed_size
+= lpcs
->dwResultReadStrLen
* sizeof(DWORD
);
184 needed_size
+= lpcs
->dwResultClauseLen
;
185 needed_size
+= lpcs
->dwResultStrLen
* sizeof(DWORD
);
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
);
276 new_one
->dwCompStrLen
= len
;
279 new_one
->dwCompStrOffset
= current_offset
;
280 memcpy(&newdata
[current_offset
], compstr
, len
* sizeof(WCHAR
));
291 static HIMCC
updateResultStr(HIMCC old
, LPWSTR resultstr
, DWORD len
)
293 /* we need to make sure the ResultStr and ResultClause fields are all
297 LPBYTE newdata
= NULL
;
298 LPBYTE olddata
= NULL
;
299 LPCOMPOSITIONSTRING new_one
;
300 LPCOMPOSITIONSTRING lpcs
= NULL
;
301 INT current_offset
= 0;
303 TRACE("%s, %i\n", debugstr_wn(resultstr
, len
), len
);
305 if (old
== NULL
&& resultstr
== NULL
&& len
== 0)
308 if (resultstr
== NULL
&& len
!= 0)
310 ERR("resultstr is NULL however we have a len! Please report\n");
316 olddata
= ImmLockIMCC(old
);
317 lpcs
= (LPCOMPOSITIONSTRING
)olddata
;
320 needed_size
= sizeof(COMPOSITIONSTRING
) + len
* sizeof(WCHAR
) +
325 needed_size
+= lpcs
->dwCompReadAttrLen
;
326 needed_size
+= lpcs
->dwCompReadClauseLen
;
327 needed_size
+= lpcs
->dwCompReadStrLen
* sizeof(DWORD
);
328 needed_size
+= lpcs
->dwCompAttrLen
;
329 needed_size
+= lpcs
->dwCompClauseLen
;
330 needed_size
+= lpcs
->dwCompStrLen
* sizeof(DWORD
);
331 needed_size
+= lpcs
->dwResultReadClauseLen
;
332 needed_size
+= lpcs
->dwResultReadStrLen
* sizeof(DWORD
);
333 needed_size
+= lpcs
->dwPrivateSize
;
335 rc
= ImmCreateIMCC(needed_size
);
336 newdata
= ImmLockIMCC(rc
);
337 new_one
= (LPCOMPOSITIONSTRING
)newdata
;
339 new_one
->dwSize
= needed_size
;
340 current_offset
= sizeof(COMPOSITIONSTRING
);
343 current_offset
= updateField(lpcs
->dwCompReadAttrLen
,
344 lpcs
->dwCompReadAttrOffset
,
345 current_offset
, newdata
, olddata
,
346 &new_one
->dwCompReadAttrLen
,
347 &new_one
->dwCompReadAttrOffset
, FALSE
);
349 current_offset
= updateField(lpcs
->dwCompReadClauseLen
,
350 lpcs
->dwCompReadClauseOffset
,
351 current_offset
, newdata
, olddata
,
352 &new_one
->dwCompReadClauseLen
,
353 &new_one
->dwCompReadClauseOffset
, FALSE
);
355 current_offset
= updateField(lpcs
->dwCompReadStrLen
,
356 lpcs
->dwCompReadStrOffset
,
357 current_offset
, newdata
, olddata
,
358 &new_one
->dwCompReadStrLen
,
359 &new_one
->dwCompReadStrOffset
, TRUE
);
361 current_offset
= updateField(lpcs
->dwCompAttrLen
,
362 lpcs
->dwCompAttrOffset
,
363 current_offset
, newdata
, olddata
,
364 &new_one
->dwCompAttrLen
,
365 &new_one
->dwCompAttrOffset
, FALSE
);
367 current_offset
= updateField(lpcs
->dwCompClauseLen
,
368 lpcs
->dwCompClauseOffset
,
369 current_offset
, newdata
, olddata
,
370 &new_one
->dwCompClauseLen
,
371 &new_one
->dwCompClauseOffset
, FALSE
);
373 current_offset
= updateField(lpcs
->dwCompStrLen
,
374 lpcs
->dwCompStrOffset
,
375 current_offset
, newdata
, olddata
,
376 &new_one
->dwCompStrLen
,
377 &new_one
->dwCompStrOffset
, TRUE
);
379 new_one
->dwCursorPos
= lpcs
->dwCursorPos
;
380 new_one
->dwDeltaStart
= 0;
382 current_offset
= updateField(lpcs
->dwResultReadClauseLen
,
383 lpcs
->dwResultReadClauseOffset
,
384 current_offset
, newdata
, olddata
,
385 &new_one
->dwResultReadClauseLen
,
386 &new_one
->dwResultReadClauseOffset
, FALSE
);
388 current_offset
= updateField(lpcs
->dwResultReadStrLen
,
389 lpcs
->dwResultReadStrOffset
,
390 current_offset
, newdata
, olddata
,
391 &new_one
->dwResultReadStrLen
,
392 &new_one
->dwResultReadStrOffset
, TRUE
);
394 /* new ResultClause , ResultStr */
396 current_offset
= updateField(lpcs
->dwPrivateSize
,
397 lpcs
->dwPrivateOffset
,
398 current_offset
, newdata
, olddata
,
399 &new_one
->dwPrivateSize
,
400 &new_one
->dwPrivateOffset
, FALSE
);
407 new_one
->dwResultClauseLen
= sizeof(DWORD
) * 2;
408 new_one
->dwResultClauseOffset
= current_offset
;
409 *(DWORD
*)&newdata
[current_offset
] = 0;
410 current_offset
+= sizeof(DWORD
);
411 *(DWORD
*)&newdata
[current_offset
] = len
;
412 current_offset
+= sizeof(DWORD
);
416 new_one
->dwResultStrLen
= len
;
419 new_one
->dwResultStrOffset
= current_offset
;
420 memcpy(&newdata
[current_offset
], resultstr
, len
* sizeof(WCHAR
));
429 static void GenerateIMEMessage(HIMC hIMC
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
431 LPINPUTCONTEXT lpIMC
;
432 LPTRANSMSG lpTransMsg
;
434 lpIMC
= LockRealIMC(hIMC
);
438 lpIMC
->hMsgBuf
= ImmReSizeIMCC(lpIMC
->hMsgBuf
, (lpIMC
->dwNumMsgBuf
+ 1) * sizeof(TRANSMSG
));
442 lpTransMsg
= ImmLockIMCC(lpIMC
->hMsgBuf
);
446 lpTransMsg
+= lpIMC
->dwNumMsgBuf
;
447 lpTransMsg
->message
= msg
;
448 lpTransMsg
->wParam
= wParam
;
449 lpTransMsg
->lParam
= lParam
;
451 ImmUnlockIMCC(lpIMC
->hMsgBuf
);
452 lpIMC
->dwNumMsgBuf
++;
454 ImmGenerateMessage(RealIMC(hIMC
));
458 static void GenerateIMECHARMessages(HIMC hIMC
, LPWSTR String
, DWORD length
)
460 LPINPUTCONTEXT lpIMC
;
461 LPTRANSMSG lpTransMsg
;
467 lpIMC
= LockRealIMC(hIMC
);
471 lpIMC
->hMsgBuf
= ImmReSizeIMCC(lpIMC
->hMsgBuf
, (lpIMC
->dwNumMsgBuf
+ length
) * sizeof(TRANSMSG
));
475 lpTransMsg
= ImmLockIMCC(lpIMC
->hMsgBuf
);
479 lpTransMsg
+= lpIMC
->dwNumMsgBuf
;
480 for (i
= 0; i
< length
; i
++)
482 lpTransMsg
->message
= WM_IME_CHAR
;
483 lpTransMsg
->wParam
= String
[i
];
484 lpTransMsg
->lParam
= 1;
488 ImmUnlockIMCC(lpIMC
->hMsgBuf
);
489 lpIMC
->dwNumMsgBuf
+= length
;
491 ImmGenerateMessage(RealIMC(hIMC
));
495 static BOOL
GenerateMessageToTransKey(LPDWORD lpTransBuf
, UINT
*uNumTranMsgs
,
496 UINT msg
, WPARAM wParam
, LPARAM lParam
)
500 if (*uNumTranMsgs
+ 1 >= (UINT
)*lpTransBuf
)
503 ptr
= (LPTRANSMSG
)(lpTransBuf
+ 1 + *uNumTranMsgs
* 3);
505 ptr
->wParam
= wParam
;
506 ptr
->lParam
= lParam
;
513 static BOOL
IME_RemoveFromSelected(HIMC hIMC
)
516 for (i
= 0; i
< hSelectedCount
; i
++)
518 if (hSelectedFrom
[i
] == hIMC
)
520 if (i
< hSelectedCount
- 1)
521 memmove(&hSelectedFrom
[i
], &hSelectedFrom
[i
+ 1], (hSelectedCount
- i
- 1) * sizeof(HIMC
));
529 static void IME_AddToSelected(HIMC hIMC
)
533 hSelectedFrom
= HeapReAlloc(GetProcessHeap(), 0, hSelectedFrom
, hSelectedCount
* sizeof(HIMC
));
535 hSelectedFrom
= HeapAlloc(GetProcessHeap(), 0, sizeof(HIMC
));
536 hSelectedFrom
[hSelectedCount
- 1] = hIMC
;
539 static void UpdateDataInDefaultIMEWindow(HIMC hIMC
, HWND hwnd
, BOOL showable
)
541 LPCOMPOSITIONSTRING compstr
;
542 LPINPUTCONTEXT lpIMC
;
544 lpIMC
= LockRealIMC(hIMC
);
549 compstr
= ImmLockIMCC(lpIMC
->hCompStr
);
553 if (compstr
== NULL
|| compstr
->dwCompStrLen
== 0)
554 ShowWindow(hwnd
, SW_HIDE
);
556 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
558 RedrawWindow(hwnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_INVALIDATE
);
561 ImmUnlockIMCC(lpIMC
->hCompStr
);
566 BOOL WINAPI
ImeConfigure(HKL hKL
, HWND hWnd
, DWORD dwMode
, LPVOID lpData
)
568 FIXME("(%p, %p, %d, %p): stub\n", hKL
, hWnd
, dwMode
, lpData
);
569 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
573 DWORD WINAPI
ImeConversionList(HIMC hIMC
, LPCWSTR lpSource
, LPCANDIDATELIST lpCandList
,
574 DWORD dwBufLen
, UINT uFlag
)
577 FIXME("(%p, %s, %p, %d, %d): stub\n", hIMC
, debugstr_w(lpSource
), lpCandList
,
579 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
583 BOOL WINAPI
ImeDestroy(UINT uForce
)
586 HeapFree(GetProcessHeap(), 0, hSelectedFrom
);
587 hSelectedFrom
= NULL
;
592 LRESULT WINAPI
ImeEscape(HIMC hIMC
, UINT uSubFunc
, LPVOID lpData
)
594 TRACE("%x %p\n", uSubFunc
, lpData
);
598 BOOL WINAPI
ImeProcessKey(HIMC hIMC
, UINT vKey
, LPARAM lKeyData
, const LPBYTE lpbKeyState
)
600 LPINPUTCONTEXT lpIMC
;
603 TRACE("hIMC %p vKey 0x%04x lKeyData 0x%08lx lpbKeyState %p\n", hIMC
, vKey
, lKeyData
, lpbKeyState
);
614 inIME
= macdrv_using_input_method();
615 lpIMC
= LockRealIMC(hIMC
);
618 LPIMEPRIVATE myPrivate
;
619 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
621 if (inIME
&& !myPrivate
->bInternalState
)
622 ImmSetOpenStatus(RealIMC(FROM_MACDRV
), TRUE
);
623 else if (!inIME
&& myPrivate
->bInternalState
)
625 ShowWindow(myPrivate
->hwndDefault
, SW_HIDE
);
626 ImmDestroyIMCC(lpIMC
->hCompStr
);
627 lpIMC
->hCompStr
= ImeCreateBlankCompStr();
628 ImmSetOpenStatus(RealIMC(FROM_MACDRV
), FALSE
);
631 myPrivate
->repeat
= (lKeyData
>> 30) & 0x1;
633 myPrivate
->bInternalState
= inIME
;
634 ImmUnlockIMCC(lpIMC
->hPrivate
);
641 BOOL WINAPI
ImeSelect(HIMC hIMC
, BOOL fSelect
)
643 LPINPUTCONTEXT lpIMC
;
644 TRACE("%p %s\n", hIMC
, fSelect
? "TRUE" : "FALSE");
646 if (hIMC
== FROM_MACDRV
)
648 ERR("ImeSelect should never be called from Cocoa\n");
657 return IME_RemoveFromSelected(hIMC
);
659 IME_AddToSelected(hIMC
);
661 /* Initialize our structures */
662 lpIMC
= LockRealIMC(hIMC
);
665 LPIMEPRIVATE myPrivate
;
666 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
667 myPrivate
->bInComposition
= FALSE
;
668 myPrivate
->bInternalState
= FALSE
;
669 myPrivate
->textfont
= NULL
;
670 myPrivate
->hwndDefault
= NULL
;
671 myPrivate
->repeat
= 0;
672 ImmUnlockIMCC(lpIMC
->hPrivate
);
679 BOOL WINAPI
ImeSetActiveContext(HIMC hIMC
, BOOL fFlag
)
681 FIXME("(%p, %x): stub\n", hIMC
, fFlag
);
685 UINT WINAPI
ImeToAsciiEx(UINT uVKey
, UINT uScanCode
, const LPBYTE lpbKeyState
,
686 LPDWORD lpdwTransKey
, UINT fuState
, HIMC hIMC
)
689 LPINPUTCONTEXT lpIMC
;
690 LPIMEPRIVATE myPrivate
;
695 TRACE("uVKey 0x%04x uScanCode 0x%04x fuState %u hIMC %p\n", uVKey
, uScanCode
, fuState
, hIMC
);
697 vkey
= LOWORD(uVKey
);
699 if (vkey
== VK_KANA
|| vkey
== VK_KANJI
|| vkey
== VK_MENU
)
701 TRACE("Skipping metakey\n");
705 lpIMC
= LockRealIMC(hIMC
);
706 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
707 if (!myPrivate
->bInternalState
)
709 ImmUnlockIMCC(lpIMC
->hPrivate
);
714 repeat
= myPrivate
->repeat
;
715 hwndDefault
= myPrivate
->hwndDefault
;
716 ImmUnlockIMCC(lpIMC
->hPrivate
);
719 TRACE("Processing Mac 0x%04x\n", vkey
);
720 macdrv_process_text_input(uVKey
, uScanCode
, repeat
, lpbKeyState
, hIMC
, &done
);
723 MsgWaitForMultipleObjectsEx(0, NULL
, INFINITE
, QS_POSTMESSAGE
| QS_SENDMESSAGE
, 0);
728 UINT msg
= (uScanCode
& 0x8000) ? WM_KEYUP
: WM_KEYDOWN
;
730 /* KeyStroke not processed by the IME
731 * so we need to rebuild the KeyDown message and pass it on to WINE
733 if (!GenerateMessageToTransKey(lpdwTransKey
, &msgs
, msg
, vkey
, MAKELONG(0x0001, uScanCode
)))
734 GenerateIMEMessage(hIMC
, msg
, vkey
, MAKELONG(0x0001, uScanCode
));
739 UpdateDataInDefaultIMEWindow(hIMC
, hwndDefault
, FALSE
);
743 BOOL WINAPI
NotifyIME(HIMC hIMC
, DWORD dwAction
, DWORD dwIndex
, DWORD dwValue
)
746 LPINPUTCONTEXT lpIMC
;
748 TRACE("%p %i %i %i\n", hIMC
, dwAction
, dwIndex
, dwValue
);
750 lpIMC
= LockRealIMC(hIMC
);
756 case NI_OPENCANDIDATE
: FIXME("NI_OPENCANDIDATE\n"); break;
757 case NI_CLOSECANDIDATE
: FIXME("NI_CLOSECANDIDATE\n"); break;
758 case NI_SELECTCANDIDATESTR
: FIXME("NI_SELECTCANDIDATESTR\n"); break;
759 case NI_CHANGECANDIDATELIST
: FIXME("NI_CHANGECANDIDATELIST\n"); break;
760 case NI_SETCANDIDATE_PAGESTART
: FIXME("NI_SETCANDIDATE_PAGESTART\n"); break;
761 case NI_SETCANDIDATE_PAGESIZE
: FIXME("NI_SETCANDIDATE_PAGESIZE\n"); break;
762 case NI_CONTEXTUPDATED
:
765 case IMC_SETCOMPOSITIONWINDOW
: FIXME("NI_CONTEXTUPDATED: IMC_SETCOMPOSITIONWINDOW\n"); break;
766 case IMC_SETCONVERSIONMODE
: FIXME("NI_CONTEXTUPDATED: IMC_SETCONVERSIONMODE\n"); break;
767 case IMC_SETSENTENCEMODE
: FIXME("NI_CONTEXTUPDATED: IMC_SETSENTENCEMODE\n"); break;
768 case IMC_SETCANDIDATEPOS
: FIXME("NI_CONTEXTUPDATED: IMC_SETCANDIDATEPOS\n"); break;
769 case IMC_SETCOMPOSITIONFONT
:
771 LPIMEPRIVATE myPrivate
;
772 TRACE("NI_CONTEXTUPDATED: IMC_SETCOMPOSITIONFONT\n");
774 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
775 if (myPrivate
->textfont
)
777 DeleteObject(myPrivate
->textfont
);
778 myPrivate
->textfont
= NULL
;
780 myPrivate
->textfont
= CreateFontIndirectW(&lpIMC
->lfFont
.W
);
781 ImmUnlockIMCC(lpIMC
->hPrivate
);
784 case IMC_SETOPENSTATUS
:
786 LPIMEPRIVATE myPrivate
;
787 TRACE("NI_CONTEXTUPDATED: IMC_SETOPENSTATUS\n");
789 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
790 if (lpIMC
->fOpen
!= myPrivate
->bInternalState
&& myPrivate
->bInComposition
)
792 if(lpIMC
->fOpen
== FALSE
)
794 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
795 myPrivate
->bInComposition
= FALSE
;
799 GenerateIMEMessage(hIMC
, WM_IME_STARTCOMPOSITION
, 0, 0);
800 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, 0, 0);
803 myPrivate
->bInternalState
= lpIMC
->fOpen
;
807 default: FIXME("NI_CONTEXTUPDATED: Unknown\n"); break;
810 case NI_COMPOSITIONSTR
:
818 LPCOMPOSITIONSTRING cs
= NULL
;
820 LPIMEPRIVATE myPrivate
;
822 TRACE("NI_COMPOSITIONSTR: CPS_COMPLETE\n");
824 /* clear existing result */
825 newCompStr
= updateResultStr(lpIMC
->hCompStr
, NULL
, 0);
827 ImmDestroyIMCC(lpIMC
->hCompStr
);
828 lpIMC
->hCompStr
= newCompStr
;
832 cdata
= ImmLockIMCC(lpIMC
->hCompStr
);
833 cs
= (LPCOMPOSITIONSTRING
)cdata
;
834 cplen
= cs
->dwCompStrLen
;
835 cpstr
= (LPWSTR
)&cdata
[cs
->dwCompStrOffset
];
836 ImmUnlockIMCC(lpIMC
->hCompStr
);
840 WCHAR param
= cpstr
[0];
841 DWORD flags
= GCS_COMPSTR
;
843 newCompStr
= updateResultStr(lpIMC
->hCompStr
, cpstr
, cplen
);
844 ImmDestroyIMCC(lpIMC
->hCompStr
);
845 lpIMC
->hCompStr
= newCompStr
;
846 newCompStr
= updateCompStr(lpIMC
->hCompStr
, NULL
, 0, &flags
);
847 ImmDestroyIMCC(lpIMC
->hCompStr
);
848 lpIMC
->hCompStr
= newCompStr
;
850 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, 0, flags
);
852 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, param
,
853 GCS_RESULTSTR
| GCS_RESULTCLAUSE
);
856 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
858 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
859 myPrivate
->bInComposition
= FALSE
;
860 ImmUnlockIMCC(lpIMC
->hPrivate
);
865 case CPS_CONVERT
: FIXME("NI_COMPOSITIONSTR: CPS_CONVERT\n"); break;
866 case CPS_REVERT
: FIXME("NI_COMPOSITIONSTR: CPS_REVERT\n"); break;
869 LPIMEPRIVATE myPrivate
;
871 TRACE("NI_COMPOSITIONSTR: CPS_CANCEL\n");
874 ImmDestroyIMCC(lpIMC
->hCompStr
);
876 lpIMC
->hCompStr
= ImeCreateBlankCompStr();
878 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
879 if (myPrivate
->bInComposition
)
881 GenerateIMEMessage(hIMC
, WM_IME_ENDCOMPOSITION
, 0, 0);
882 myPrivate
->bInComposition
= FALSE
;
884 ImmUnlockIMCC(lpIMC
->hPrivate
);
888 default: FIXME("NI_COMPOSITIONSTR: Unknown\n"); break;
891 default: FIXME("Unknown Message\n"); break;
898 BOOL WINAPI
ImeRegisterWord(LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszRegister
)
900 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszRegister
));
901 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
905 BOOL WINAPI
ImeUnregisterWord(LPCWSTR lpszReading
, DWORD dwStyle
, LPCWSTR lpszUnregister
)
907 FIXME("(%s, %d, %s): stub\n", debugstr_w(lpszReading
), dwStyle
, debugstr_w(lpszUnregister
));
908 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
912 UINT WINAPI
ImeGetRegisterWordStyle(UINT nItem
, LPSTYLEBUFW lpStyleBuf
)
914 FIXME("(%d, %p): stub\n", nItem
, lpStyleBuf
);
915 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
919 UINT WINAPI
ImeEnumRegisterWord(REGISTERWORDENUMPROCW lpfnEnumProc
, LPCWSTR lpszReading
,
920 DWORD dwStyle
, LPCWSTR lpszRegister
, LPVOID lpData
)
922 FIXME("(%p, %s, %d, %s, %p): stub\n", lpfnEnumProc
, debugstr_w(lpszReading
), dwStyle
,
923 debugstr_w(lpszRegister
), lpData
);
924 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
928 static BOOL
IME_SetCompositionString(void* hIMC
, DWORD dwIndex
, LPCVOID lpComp
, DWORD dwCompLen
, DWORD cursor_pos
, BOOL cursor_valid
)
930 LPINPUTCONTEXT lpIMC
;
933 LPIMEPRIVATE myPrivate
;
935 TRACE("(%p, %d, %p, %d):\n", hIMC
, dwIndex
, lpComp
, dwCompLen
);
939 * this sets the composition string in the imm32.dll level
940 * of the composition buffer.
941 * TODO: set the Cocoa window's marked text string and tell text input context
944 lpIMC
= LockRealIMC(hIMC
);
949 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
951 if (dwIndex
== SCS_SETSTR
)
955 if (!myPrivate
->bInComposition
)
957 GenerateIMEMessage(hIMC
, WM_IME_STARTCOMPOSITION
, 0, 0);
958 myPrivate
->bInComposition
= TRUE
;
963 if (dwCompLen
&& lpComp
)
965 newCompStr
= updateCompStr(lpIMC
->hCompStr
, (LPCWSTR
)lpComp
, dwCompLen
/ sizeof(WCHAR
), &flags
);
966 ImmDestroyIMCC(lpIMC
->hCompStr
);
967 lpIMC
->hCompStr
= newCompStr
;
969 wParam
= ((const WCHAR
*)lpComp
)[0];
970 flags
|= GCS_COMPCLAUSE
| GCS_COMPATTR
| GCS_DELTASTART
;
974 newCompStr
= updateCompStr(lpIMC
->hCompStr
, NULL
, 0, &flags
);
975 ImmDestroyIMCC(lpIMC
->hCompStr
);
976 lpIMC
->hCompStr
= newCompStr
;
981 LPCOMPOSITIONSTRING compstr
;
982 compstr
= ImmLockIMCC(lpIMC
->hCompStr
);
983 compstr
->dwCursorPos
= cursor_pos
;
984 ImmUnlockIMCC(lpIMC
->hCompStr
);
985 flags
|= GCS_CURSORPOS
;
990 GenerateIMEMessage(hIMC
, WM_IME_COMPOSITION
, wParam
, flags
);
991 ImmUnlockIMCC(lpIMC
->hPrivate
);
997 BOOL WINAPI
ImeSetCompositionString(HIMC hIMC
, DWORD dwIndex
, LPCVOID lpComp
, DWORD dwCompLen
,
998 LPCVOID lpRead
, DWORD dwReadLen
)
1000 TRACE("(%p, %d, %p, %d, %p, %d):\n", hIMC
, dwIndex
, lpComp
, dwCompLen
, lpRead
, dwReadLen
);
1002 if (lpRead
&& dwReadLen
)
1003 FIXME("Reading string unimplemented\n");
1005 return IME_SetCompositionString(hIMC
, dwIndex
, lpComp
, dwCompLen
, 0, FALSE
);
1008 DWORD WINAPI
ImeGetImeMenuItems(HIMC hIMC
, DWORD dwFlags
, DWORD dwType
, LPIMEMENUITEMINFOW lpImeParentMenu
,
1009 LPIMEMENUITEMINFOW lpImeMenu
, DWORD dwSize
)
1011 FIXME("(%p, %x %x %p %p %x): stub\n", hIMC
, dwFlags
, dwType
, lpImeParentMenu
, lpImeMenu
, dwSize
);
1012 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1016 static void IME_NotifyComplete(void* hIMC
)
1018 NotifyIME(hIMC
, NI_COMPOSITIONSTR
, CPS_COMPLETE
, 0);
1022 * Internal functions to help with IME window management
1024 static void PaintDefaultIMEWnd(HIMC hIMC
, HWND hwnd
)
1029 LPCOMPOSITIONSTRING compstr
;
1030 LPBYTE compdata
= NULL
;
1032 MONITORINFO mon_info
;
1033 INT offX
= 0, offY
= 0;
1034 LPINPUTCONTEXT lpIMC
;
1036 lpIMC
= LockRealIMC(hIMC
);
1040 hdc
= BeginPaint(hwnd
, &ps
);
1042 GetClientRect(hwnd
, &rect
);
1043 FillRect(hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
1045 compdata
= ImmLockIMCC(lpIMC
->hCompStr
);
1046 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1048 if (compstr
->dwCompStrLen
&& compstr
->dwCompStrOffset
)
1052 HFONT oldfont
= NULL
;
1054 LPIMEPRIVATE myPrivate
;
1056 CompString
= (LPWSTR
)(compdata
+ compstr
->dwCompStrOffset
);
1057 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
1059 if (myPrivate
->textfont
)
1060 oldfont
= SelectObject(hdc
, myPrivate
->textfont
);
1062 ImmUnlockIMCC(lpIMC
->hPrivate
);
1064 GetTextExtentPoint32W(hdc
, CompString
, compstr
->dwCompStrLen
, &size
);
1067 LPtoDP(hdc
, &pt
, 1);
1070 * How this works based on tests on windows:
1071 * CFS_POINT: then we start our window at the point and grow it as large
1072 * as it needs to be for the string.
1073 * CFS_RECT: we still use the ptCurrentPos as a starting point and our
1074 * window is only as large as we need for the string, but we do not
1075 * grow such that our window exceeds the given rect. Wrapping if
1076 * needed and possible. If our ptCurrentPos is outside of our rect
1077 * then no window is displayed.
1078 * CFS_FORCE_POSITION: appears to behave just like CFS_POINT
1079 * maybe because the default MSIME does not do any IME adjusting.
1081 if (lpIMC
->cfCompForm
.dwStyle
!= CFS_DEFAULT
)
1083 POINT cpt
= lpIMC
->cfCompForm
.ptCurrentPos
;
1084 ClientToScreen(lpIMC
->hWnd
, &cpt
);
1087 rect
.right
= rect
.left
+ pt
.x
;
1088 rect
.bottom
= rect
.top
+ pt
.y
;
1089 monitor
= MonitorFromPoint(cpt
, MONITOR_DEFAULTTOPRIMARY
);
1091 else /* CFS_DEFAULT */
1093 /* Windows places the default IME window in the bottom left */
1094 HWND target
= lpIMC
->hWnd
;
1095 if (!target
) target
= GetFocus();
1097 GetWindowRect(target
, &rect
);
1098 rect
.top
= rect
.bottom
;
1099 rect
.right
= rect
.left
+ pt
.x
+ 20;
1100 rect
.bottom
= rect
.top
+ pt
.y
+ 20;
1102 monitor
= MonitorFromWindow(target
, MONITOR_DEFAULTTOPRIMARY
);
1105 if (lpIMC
->cfCompForm
.dwStyle
== CFS_RECT
)
1108 client
=lpIMC
->cfCompForm
.rcArea
;
1109 MapWindowPoints(lpIMC
->hWnd
, 0, (POINT
*)&client
, 2);
1110 IntersectRect(&rect
, &rect
, &client
);
1111 /* TODO: Wrap the input if needed */
1114 if (lpIMC
->cfCompForm
.dwStyle
== CFS_DEFAULT
)
1116 /* make sure we are on the desktop */
1117 mon_info
.cbSize
= sizeof(mon_info
);
1118 GetMonitorInfoW(monitor
, &mon_info
);
1120 if (rect
.bottom
> mon_info
.rcWork
.bottom
)
1122 int shift
= rect
.bottom
- mon_info
.rcWork
.bottom
;
1124 rect
.bottom
-= shift
;
1128 rect
.right
-= rect
.left
;
1131 if (rect
.right
> mon_info
.rcWork
.right
)
1133 int shift
= rect
.right
- mon_info
.rcWork
.right
;
1135 rect
.right
-= shift
;
1139 SetWindowPos(hwnd
, HWND_TOPMOST
, rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1140 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
1142 TextOutW(hdc
, offX
, offY
, CompString
, compstr
->dwCompStrLen
);
1145 SelectObject(hdc
, oldfont
);
1148 ImmUnlockIMCC(lpIMC
->hCompStr
);
1150 EndPaint(hwnd
, &ps
);
1151 UnlockRealIMC(hIMC
);
1154 static void DefaultIMEComposition(HIMC hIMC
, HWND hwnd
, LPARAM lParam
)
1156 TRACE("IME message WM_IME_COMPOSITION 0x%lx\n", lParam
);
1157 if (lParam
& GCS_RESULTSTR
)
1159 LPCOMPOSITIONSTRING compstr
;
1163 LPINPUTCONTEXT lpIMC
;
1165 lpIMC
= LockRealIMC(hIMC
);
1169 TRACE("Posting result as IME_CHAR\n");
1170 compdata
= ImmLockIMCC(lpIMC
->hCompStr
);
1171 compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1172 ResultStr
= (LPWSTR
)(compdata
+ compstr
->dwResultStrOffset
);
1173 GenerateIMECHARMessages(hIMC
, ResultStr
, compstr
->dwResultStrLen
);
1174 ImmUnlockIMCC(lpIMC
->hCompStr
);
1176 /* clear the buffer */
1177 newCompStr
= updateResultStr(lpIMC
->hCompStr
, NULL
, 0);
1178 ImmDestroyIMCC(lpIMC
->hCompStr
);
1179 lpIMC
->hCompStr
= newCompStr
;
1180 UnlockRealIMC(hIMC
);
1183 UpdateDataInDefaultIMEWindow(hIMC
, hwnd
, TRUE
);
1186 static void DefaultIMEStartComposition(HIMC hIMC
, HWND hwnd
)
1188 LPINPUTCONTEXT lpIMC
;
1190 lpIMC
= LockRealIMC(hIMC
);
1194 TRACE("IME message WM_IME_STARTCOMPOSITION\n");
1195 lpIMC
->hWnd
= GetFocus();
1196 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
1197 UnlockRealIMC(hIMC
);
1200 static LRESULT
ImeHandleNotify(HIMC hIMC
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1204 case IMN_OPENSTATUSWINDOW
:
1205 FIXME("WM_IME_NOTIFY:IMN_OPENSTATUSWINDOW\n");
1207 case IMN_CLOSESTATUSWINDOW
:
1208 FIXME("WM_IME_NOTIFY:IMN_CLOSESTATUSWINDOW\n");
1210 case IMN_OPENCANDIDATE
:
1211 FIXME("WM_IME_NOTIFY:IMN_OPENCANDIDATE\n");
1213 case IMN_CHANGECANDIDATE
:
1214 FIXME("WM_IME_NOTIFY:IMN_CHANGECANDIDATE\n");
1216 case IMN_CLOSECANDIDATE
:
1217 FIXME("WM_IME_NOTIFY:IMN_CLOSECANDIDATE\n");
1219 case IMN_SETCONVERSIONMODE
:
1220 FIXME("WM_IME_NOTIFY:IMN_SETCONVERSIONMODE\n");
1222 case IMN_SETSENTENCEMODE
:
1223 FIXME("WM_IME_NOTIFY:IMN_SETSENTENCEMODE\n");
1225 case IMN_SETOPENSTATUS
:
1226 FIXME("WM_IME_NOTIFY:IMN_SETOPENSTATUS\n");
1228 case IMN_SETCANDIDATEPOS
:
1229 FIXME("WM_IME_NOTIFY:IMN_SETCANDIDATEPOS\n");
1231 case IMN_SETCOMPOSITIONFONT
:
1232 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONFONT\n");
1234 case IMN_SETCOMPOSITIONWINDOW
:
1235 FIXME("WM_IME_NOTIFY:IMN_SETCOMPOSITIONWINDOW\n");
1238 FIXME("WM_IME_NOTIFY:IMN_GUIDELINE\n");
1240 case IMN_SETSTATUSWINDOWPOS
:
1241 FIXME("WM_IME_NOTIFY:IMN_SETSTATUSWINDOWPOS\n");
1244 FIXME("WM_IME_NOTIFY:<Unknown 0x%lx>\n", wParam
);
1250 static LRESULT WINAPI
IME_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1255 TRACE("Incoming Message 0x%x (0x%08lx, 0x%08lx)\n", msg
, wParam
, lParam
);
1258 * Each UI window contains the current Input Context.
1259 * This Input Context can be obtained by calling GetWindowLong
1260 * with IMMGWL_IMC when the UI window receives a WM_IME_xxx message.
1261 * The UI window can refer to this Input Context and handles the
1265 hIMC
= (HIMC
)GetWindowLongPtrW(hwnd
, IMMGWL_IMC
);
1267 hIMC
= RealIMC(FROM_MACDRV
);
1269 /* if we have no hIMC there are many messages we cannot process */
1273 case WM_IME_STARTCOMPOSITION
:
1274 case WM_IME_ENDCOMPOSITION
:
1275 case WM_IME_COMPOSITION
:
1277 case WM_IME_CONTROL
:
1278 case WM_IME_COMPOSITIONFULL
:
1291 LPIMEPRIVATE myPrivate
;
1292 LPINPUTCONTEXT lpIMC
;
1294 SetWindowTextA(hwnd
, "Wine Ime Active");
1296 lpIMC
= LockRealIMC(hIMC
);
1299 myPrivate
= ImmLockIMCC(lpIMC
->hPrivate
);
1300 myPrivate
->hwndDefault
= hwnd
;
1301 ImmUnlockIMCC(lpIMC
->hPrivate
);
1303 UnlockRealIMC(hIMC
);
1308 PaintDefaultIMEWnd(hIMC
, hwnd
);
1316 SetFocus((HWND
)wParam
);
1318 FIXME("Received focus, should never have focus\n");
1320 case WM_IME_COMPOSITION
:
1321 DefaultIMEComposition(hIMC
, hwnd
, lParam
);
1323 case WM_IME_STARTCOMPOSITION
:
1324 DefaultIMEStartComposition(hIMC
, hwnd
);
1326 case WM_IME_ENDCOMPOSITION
:
1327 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_ENDCOMPOSITION", wParam
, lParam
);
1328 ShowWindow(hwnd
, SW_HIDE
);
1331 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_SELECT", wParam
, lParam
);
1333 case WM_IME_CONTROL
:
1334 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_IME_CONTROL", wParam
, lParam
);
1338 rc
= ImeHandleNotify(hIMC
, hwnd
, msg
, wParam
, lParam
);
1341 TRACE("Non-standard message 0x%x\n", msg
);
1343 /* check the MSIME messages */
1344 if (msg
== WM_MSIME_SERVICE
)
1346 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_SERVICE", wParam
, lParam
);
1349 else if (msg
== WM_MSIME_RECONVERTOPTIONS
)
1351 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERTOPTIONS", wParam
, lParam
);
1353 else if (msg
== WM_MSIME_MOUSE
)
1355 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_MOUSE", wParam
, lParam
);
1357 else if (msg
== WM_MSIME_RECONVERTREQUEST
)
1359 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERTREQUEST", wParam
, lParam
);
1361 else if (msg
== WM_MSIME_RECONVERT
)
1363 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_RECONVERT", wParam
, lParam
);
1365 else if (msg
== WM_MSIME_QUERYPOSITION
)
1367 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_QUERYPOSITION", wParam
, lParam
);
1369 else if (msg
== WM_MSIME_DOCUMENTFEED
)
1371 TRACE("IME message %s, 0x%lx, 0x%lx\n", "WM_MSIME_DOCUMENTFEED", wParam
, lParam
);
1373 /* DefWndProc if not an IME message */
1374 if (!rc
&& !((msg
>= WM_IME_STARTCOMPOSITION
&& msg
<= WM_IME_KEYLAST
) ||
1375 (msg
>= WM_IME_SETCONTEXT
&& msg
<= WM_IME_KEYUP
)))
1376 rc
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1381 static BOOL WINAPI
register_classes( INIT_ONCE
*once
, void *param
, void **context
)
1384 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1385 wndClass
.style
= CS_GLOBALCLASS
| CS_IME
| CS_HREDRAW
| CS_VREDRAW
;
1386 wndClass
.lpfnWndProc
= (WNDPROC
) IME_WindowProc
;
1387 wndClass
.cbClsExtra
= 0;
1388 wndClass
.cbWndExtra
= 2 * sizeof(LONG_PTR
);
1389 wndClass
.hInstance
= macdrv_module
;
1390 wndClass
.hCursor
= LoadCursorW(NULL
, (LPWSTR
)IDC_ARROW
);
1391 wndClass
.hIcon
= LoadIconW(NULL
, (LPWSTR
)IDI_APPLICATION
);
1392 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1393 wndClass
.lpszMenuName
= 0;
1394 wndClass
.lpszClassName
= UI_CLASS_NAME
;
1396 RegisterClassW(&wndClass
);
1398 WM_MSIME_SERVICE
= RegisterWindowMessageA("MSIMEService");
1399 WM_MSIME_RECONVERTOPTIONS
= RegisterWindowMessageA("MSIMEReconvertOptions");
1400 WM_MSIME_MOUSE
= RegisterWindowMessageA("MSIMEMouseOperation");
1401 WM_MSIME_RECONVERTREQUEST
= RegisterWindowMessageA("MSIMEReconvertRequest");
1402 WM_MSIME_RECONVERT
= RegisterWindowMessageA("MSIMEReconvert");
1403 WM_MSIME_QUERYPOSITION
= RegisterWindowMessageA("MSIMEQueryPosition");
1404 WM_MSIME_DOCUMENTFEED
= RegisterWindowMessageA("MSIMEDocumentFeed");
1408 BOOL WINAPI
ImeInquire(LPIMEINFO lpIMEInfo
, LPWSTR lpszUIClass
, LPCWSTR lpszOption
)
1410 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
1413 InitOnceExecuteOnce( &init_once
, register_classes
, NULL
, NULL
);
1414 lpIMEInfo
->dwPrivateDataSize
= sizeof(IMEPRIVATE
);
1415 lpIMEInfo
->fdwProperty
= IME_PROP_UNICODE
| IME_PROP_AT_CARET
;
1416 lpIMEInfo
->fdwConversionCaps
= IME_CMODE_NATIVE
| IME_CMODE_FULLSHAPE
;
1417 lpIMEInfo
->fdwSentenceCaps
= IME_SMODE_AUTOMATIC
;
1418 lpIMEInfo
->fdwUICaps
= UI_CAP_2700
;
1419 /* Tell App we cannot accept ImeSetCompositionString calls */
1420 /* FIXME: Can we? */
1421 lpIMEInfo
->fdwSCSCaps
= 0;
1422 lpIMEInfo
->fdwSelectCaps
= SELECT_CAP_CONVERSION
;
1424 lstrcpyW(lpszUIClass
, UI_CLASS_NAME
);
1429 /* Interfaces to other parts of the Mac driver */
1431 /***********************************************************************
1432 * macdrv_im_set_text
1434 void macdrv_im_set_text(const macdrv_event
*event
)
1436 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
1437 void *himc
= event
->im_set_text
.data
;
1439 TRACE("win %p/%p himc %p text %s complete %u\n", hwnd
, event
->window
, himc
,
1440 debugstr_cf(event
->im_set_text
.text
), event
->im_set_text
.complete
);
1442 if (!himc
) himc
= RealIMC(FROM_MACDRV
);
1444 if (event
->im_set_text
.text
)
1446 CFIndex length
= CFStringGetLength(event
->im_set_text
.text
);
1447 const UniChar
*chars
= CFStringGetCharactersPtr(event
->im_set_text
.text
);
1448 UniChar
*buffer
= NULL
;
1452 buffer
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(*buffer
));
1453 CFStringGetCharacters(event
->im_set_text
.text
, CFRangeMake(0, length
), buffer
);
1458 IME_SetCompositionString(himc
, SCS_SETSTR
, chars
, length
* sizeof(*chars
),
1459 event
->im_set_text
.cursor_pos
, !event
->im_set_text
.complete
);
1465 input
.type
= INPUT_KEYBOARD
;
1468 input
.ki
.dwExtraInfo
= 0;
1470 for (i
= 0; i
< length
; i
++)
1472 input
.ki
.wScan
= chars
[i
];
1473 input
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
1474 __wine_send_input(hwnd
, &input
);
1476 input
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1477 __wine_send_input(hwnd
, &input
);
1481 HeapFree(GetProcessHeap(), 0, buffer
);
1484 if (event
->im_set_text
.complete
)
1485 IME_NotifyComplete(himc
);
1488 /***********************************************************************
1489 * macdrv_sent_text_input
1491 void macdrv_sent_text_input(const macdrv_event
*event
)
1493 TRACE("handled: %s\n", event
->sent_text_input
.handled
? "TRUE" : "FALSE");
1494 *event
->sent_text_input
.done
= event
->sent_text_input
.handled
? 1 : -1;
1498 /**************************************************************************
1499 * query_ime_char_rect
1501 BOOL
query_ime_char_rect(macdrv_query
* query
)
1503 HWND hwnd
= macdrv_get_window_hwnd(query
->window
);
1504 void *himc
= query
->ime_char_rect
.data
;
1505 CFRange
* range
= &query
->ime_char_rect
.range
;
1506 CGRect
* rect
= &query
->ime_char_rect
.rect
;
1507 IMECHARPOSITION charpos
;
1510 TRACE("win %p/%p himc %p range %ld-%ld\n", hwnd
, query
->window
, himc
, range
->location
,
1513 if (!himc
) himc
= RealIMC(FROM_MACDRV
);
1515 charpos
.dwSize
= sizeof(charpos
);
1516 charpos
.dwCharPos
= range
->location
;
1517 if (ImmRequestMessageW(himc
, IMR_QUERYCHARPOSITION
, (ULONG_PTR
)&charpos
))
1521 *rect
= CGRectMake(charpos
.pt
.x
, charpos
.pt
.y
, 0, charpos
.cLineHeight
);
1523 /* iterate over rest of length to extend rect */
1524 for (i
= 1; i
< range
->length
; i
++)
1526 charpos
.dwSize
= sizeof(charpos
);
1527 charpos
.dwCharPos
= range
->location
+ i
;
1528 if (!ImmRequestMessageW(himc
, IMR_QUERYCHARPOSITION
, (ULONG_PTR
)&charpos
) ||
1529 charpos
.pt
.y
!= rect
->origin
.y
)
1535 rect
->size
.width
= charpos
.pt
.x
- rect
->origin
.x
;
1543 LPINPUTCONTEXT ic
= ImmLockIMC(himc
);
1547 LPIMEPRIVATE
private = ImmLockIMCC(ic
->hPrivate
);
1548 LPBYTE compdata
= ImmLockIMCC(ic
->hCompStr
);
1549 LPCOMPOSITIONSTRING compstr
= (LPCOMPOSITIONSTRING
)compdata
;
1550 LPWSTR str
= (LPWSTR
)(compdata
+ compstr
->dwCompStrOffset
);
1552 if (private->hwndDefault
&& compstr
->dwCompStrOffset
&&
1553 IsWindowVisible(private->hwndDefault
))
1555 HDC dc
= GetDC(private->hwndDefault
);
1556 HFONT oldfont
= NULL
;
1559 if (private->textfont
)
1560 oldfont
= SelectObject(dc
, private->textfont
);
1562 if (range
->location
> compstr
->dwCompStrLen
)
1563 range
->location
= compstr
->dwCompStrLen
;
1564 if (range
->location
+ range
->length
> compstr
->dwCompStrLen
)
1565 range
->length
= compstr
->dwCompStrLen
- range
->location
;
1567 GetTextExtentPoint32W(dc
, str
, range
->location
, &size
);
1568 charpos
.rcDocument
.left
= size
.cx
;
1569 charpos
.rcDocument
.top
= 0;
1570 GetTextExtentPoint32W(dc
, str
, range
->location
+ range
->length
, &size
);
1571 charpos
.rcDocument
.right
= size
.cx
;
1572 charpos
.rcDocument
.bottom
= size
.cy
;
1574 if (ic
->cfCompForm
.dwStyle
== CFS_DEFAULT
)
1575 OffsetRect(&charpos
.rcDocument
, 10, 10);
1577 LPtoDP(dc
, (POINT
*)&charpos
.rcDocument
, 2);
1578 MapWindowPoints(private->hwndDefault
, 0, (POINT
*)&charpos
.rcDocument
, 2);
1579 *rect
= cgrect_from_rect(charpos
.rcDocument
);
1583 SelectObject(dc
, oldfont
);
1584 ReleaseDC(private->hwndDefault
, dc
);
1587 ImmUnlockIMCC(ic
->hCompStr
);
1588 ImmUnlockIMCC(ic
->hPrivate
);
1597 gti
.cbSize
= sizeof(gti
);
1598 if (GetGUIThreadInfo(0, >i
))
1600 MapWindowPoints(gti
.hwndCaret
, 0, (POINT
*)>i
.rcCaret
, 2);
1601 *rect
= cgrect_from_rect(gti
.rcCaret
);
1606 if (ret
&& range
->length
&& !rect
->size
.width
)
1607 rect
->size
.width
= 1;
1609 TRACE(" -> %s range %ld-%ld rect %s\n", ret
? "TRUE" : "FALSE", range
->location
,
1610 range
->length
, wine_dbgstr_cgrect(*rect
));