xref: /reactos/sdk/include/ddk/immdev.h (revision 8ea93d2a)
1 /*
2  * PROJECT:     ReactOS headers
3  * LICENSE:     LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4  * PURPOSE:     Providing DDK-compatible <immdev.h> and IME/IMM development helper
5  * COPYRIGHT:   Copyright 2021-2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #ifndef _IMMDEV_
9 #define _IMMDEV_
10 
11 #pragma once
12 
13 #include <wingdi.h>
14 #include <imm.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef struct _tagIMEINFO {
21     DWORD dwPrivateDataSize;
22     DWORD fdwProperty;
23     DWORD fdwConversionCaps;
24     DWORD fdwSentenceCaps;
25     DWORD fdwUICaps;
26     DWORD fdwSCSCaps;
27     DWORD fdwSelectCaps;
28 } IMEINFO, *PIMEINFO, NEAR *NPIMEINFO, FAR *LPIMEINFO;
29 
30 typedef struct tagCANDIDATEINFO {
31     DWORD dwSize;
32     DWORD dwCount;
33     DWORD dwOffset[32];
34     DWORD dwPrivateSize;
35     DWORD dwPrivateOffset;
36 } CANDIDATEINFO, *PCANDIDATEINFO, NEAR *NPCANDIDATEINFO, FAR *LPCANDIDATEINFO;
37 
38 #if (WINVER >= 0x040A)
39 BOOL WINAPI ImmDisableTextFrameService(_In_ DWORD dwThreadId);
40 #endif
41 
42 typedef struct tagSOFTKBDDATA {
43     UINT uCount;
44     WORD wCode[ANYSIZE_ARRAY][256];
45 } SOFTKBDDATA, *PSOFTKBDDATA, NEAR *NPSOFTKBDDATA, FAR *LPSOFTKBDDATA;
46 
47 typedef struct tagCOMPOSITIONSTRING {
48     DWORD dwSize;
49     DWORD dwCompReadAttrLen;
50     DWORD dwCompReadAttrOffset;
51     DWORD dwCompReadClauseLen;
52     DWORD dwCompReadClauseOffset;
53     DWORD dwCompReadStrLen;
54     DWORD dwCompReadStrOffset;
55     DWORD dwCompAttrLen;
56     DWORD dwCompAttrOffset;
57     DWORD dwCompClauseLen;
58     DWORD dwCompClauseOffset;
59     DWORD dwCompStrLen;
60     DWORD dwCompStrOffset;
61     DWORD dwCursorPos;
62     DWORD dwDeltaStart;
63     DWORD dwResultReadClauseLen;
64     DWORD dwResultReadClauseOffset;
65     DWORD dwResultReadStrLen;
66     DWORD dwResultReadStrOffset;
67     DWORD dwResultClauseLen;
68     DWORD dwResultClauseOffset;
69     DWORD dwResultStrLen;
70     DWORD dwResultStrOffset;
71     DWORD dwPrivateSize;
72     DWORD dwPrivateOffset;
73 } COMPOSITIONSTRING, *PCOMPOSITIONSTRING, NEAR *NPCOMPOSITIONSTRING, FAR *LPCOMPOSITIONSTRING;
74 
75 typedef struct tagGUIDELINE {
76     DWORD dwSize;
77     DWORD dwLevel;
78     DWORD dwIndex;
79     DWORD dwStrLen;
80     DWORD dwStrOffset;
81     DWORD dwPrivateSize;
82     DWORD dwPrivateOffset;
83 } GUIDELINE, *PGUIDELINE, NEAR *NPGUIDELINE, FAR *LPGUIDELINE;
84 
85 /* wParam for WM_IME_CONTROL */
86 #define IMC_GETCONVERSIONMODE           0x0001
87 #define IMC_GETSENTENCEMODE             0x0003
88 #define IMC_GETOPENSTATUS               0x0005
89 #define IMC_GETSOFTKBDFONT              0x0011
90 #define IMC_SETSOFTKBDFONT              0x0012
91 #define IMC_GETSOFTKBDPOS               0x0013
92 #define IMC_SETSOFTKBDPOS               0x0014
93 #define IMC_GETSOFTKBDSUBTYPE           0x0015
94 #define IMC_SETSOFTKBDSUBTYPE           0x0016
95 #define IMC_SETSOFTKBDDATA              0x0018
96 
97 /* wParam for WM_IME_SYSTEM */
98 #define IMS_NOTIFYIMESHOW       0x05
99 #define IMS_UPDATEIMEUI         0x06
100 #define IMS_SETCANDFORM         0x09
101 #define IMS_SETCOMPFONT         0x0A
102 #define IMS_SETCOMPFORM         0x0B
103 #define IMS_CONFIGURE           0x0D
104 #define IMS_SETOPENSTATUS       0x0F
105 #define IMS_FREELAYOUT          0x11
106 #define IMS_GETCONVSTATUS       0x14
107 #define IMS_IMEHELP             0x15
108 #define IMS_IMEACTIVATE         0x17
109 #define IMS_IMEDEACTIVATE       0x18
110 #define IMS_ACTIVATELAYOUT      0x19
111 #define IMS_GETIMEMENU          0x1C
112 #define IMS_GETCONTEXT          0x1E
113 #define IMS_SENDNOTIFICATION    0x1F
114 #define IMS_COMPLETECOMPSTR     0x20
115 #define IMS_LOADTHREADLAYOUT    0x21
116 #define IMS_SETLANGBAND         0x23
117 #define IMS_UNSETLANGBAND       0x24
118 
119 /* wParam for WM_IME_NOTIFY */
120 #define IMN_SOFTKBDDESTROYED    0x0011
121 
122 #define IMMGWL_IMC       0
123 #define IMMGWL_PRIVATE   (sizeof(LONG))
124 
125 #define IMMGWLP_IMC      0
126 #define IMMGWLP_PRIVATE  (sizeof(LONG_PTR))
127 
128 typedef struct _tagINPUTCONTEXT {
129     HWND                hWnd;
130     BOOL                fOpen;
131     POINT               ptStatusWndPos;
132     POINT               ptSoftKbdPos;
133     DWORD               fdwConversion;
134     DWORD               fdwSentence;
135     union {
136         LOGFONTA        A;
137         LOGFONTW        W;
138     } lfFont;
139     COMPOSITIONFORM     cfCompForm;
140     CANDIDATEFORM       cfCandForm[4];
141     HIMCC               hCompStr;
142     HIMCC               hCandInfo;
143     HIMCC               hGuideLine;
144     HIMCC               hPrivate;
145     DWORD               dwNumMsgBuf;
146     HIMCC               hMsgBuf;
147     DWORD               fdwInit;
148     DWORD               dwReserve[3];
149 } INPUTCONTEXT, *PINPUTCONTEXT, NEAR *NPINPUTCONTEXT, FAR *LPINPUTCONTEXT;
150 
151 #ifndef _WIN64
152 C_ASSERT(offsetof(INPUTCONTEXT, hWnd) == 0x0);
153 C_ASSERT(offsetof(INPUTCONTEXT, fOpen) == 0x4);
154 C_ASSERT(offsetof(INPUTCONTEXT, ptStatusWndPos) == 0x8);
155 C_ASSERT(offsetof(INPUTCONTEXT, ptSoftKbdPos) == 0x10);
156 C_ASSERT(offsetof(INPUTCONTEXT, fdwConversion) == 0x18);
157 C_ASSERT(offsetof(INPUTCONTEXT, fdwSentence) == 0x1C);
158 C_ASSERT(offsetof(INPUTCONTEXT, lfFont) == 0x20);
159 C_ASSERT(offsetof(INPUTCONTEXT, cfCompForm) == 0x7C);
160 C_ASSERT(offsetof(INPUTCONTEXT, cfCandForm) == 0x98);
161 C_ASSERT(offsetof(INPUTCONTEXT, hCompStr) == 0x118);
162 C_ASSERT(offsetof(INPUTCONTEXT, hCandInfo) == 0x11C);
163 C_ASSERT(offsetof(INPUTCONTEXT, hGuideLine) == 0x120);
164 C_ASSERT(offsetof(INPUTCONTEXT, hPrivate) == 0x124);
165 C_ASSERT(offsetof(INPUTCONTEXT, dwNumMsgBuf) == 0x128);
166 C_ASSERT(offsetof(INPUTCONTEXT, hMsgBuf) == 0x12C);
167 C_ASSERT(offsetof(INPUTCONTEXT, fdwInit) == 0x130);
168 C_ASSERT(offsetof(INPUTCONTEXT, dwReserve) == 0x134);
169 C_ASSERT(sizeof(INPUTCONTEXT) == 0x140);
170 #endif
171 
172 /* bits of fdwInit of INPUTCONTEXT */
173 #define INIT_STATUSWNDPOS               0x00000001
174 #define INIT_CONVERSION                 0x00000002
175 #define INIT_SENTENCE                   0x00000004
176 #define INIT_LOGFONT                    0x00000008
177 #define INIT_COMPFORM                   0x00000010
178 #define INIT_SOFTKBDPOS                 0x00000020
179 #define INIT_GUIDMAP                    0x00000040
180 
181 /* bits for INPUTCONTEXTDX.dwChange */
182 #define INPUTCONTEXTDX_CHANGE_OPEN          0x1
183 #define INPUTCONTEXTDX_CHANGE_CONVERSION    0x2
184 #define INPUTCONTEXTDX_CHANGE_SENTENCE      0x4
185 #define INPUTCONTEXTDX_CHANGE_FORCE_OPEN    0x100
186 
187 #ifndef WM_IME_REPORT
188     #define WM_IME_REPORT 0x280
189 #endif
190 
191 /* WM_IME_REPORT wParam */
192 #define IR_STRINGSTART   0x100
193 #define IR_STRINGEND     0x101
194 #define IR_OPENCONVERT   0x120
195 #define IR_CHANGECONVERT 0x121
196 #define IR_CLOSECONVERT  0x122
197 #define IR_FULLCONVERT   0x123
198 #define IR_IMESELECT     0x130
199 #define IR_STRING        0x140
200 #define IR_DBCSCHAR      0x160
201 #define IR_UNDETERMINE   0x170
202 #define IR_STRINGEX      0x180
203 #define IR_MODEINFO      0x190
204 
205 /* IMC */
206 
207 LPINPUTCONTEXT WINAPI ImmLockIMC(_In_ HIMC hIMC);
208 BOOL  WINAPI ImmUnlockIMC(_In_ HIMC hIMC);
209 DWORD WINAPI ImmGetIMCLockCount(_In_ HIMC hIMC);
210 
211 /* IMCC */
212 
213 HIMCC  WINAPI ImmCreateIMCC(_In_ DWORD size);
214 HIMCC  WINAPI ImmDestroyIMCC(_In_ HIMCC block);
215 LPVOID WINAPI ImmLockIMCC(_In_ HIMCC imcc);
216 BOOL   WINAPI ImmUnlockIMCC(_In_ HIMCC imcc);
217 DWORD  WINAPI ImmGetIMCCLockCount(_In_ HIMCC imcc);
218 HIMCC  WINAPI ImmReSizeIMCC(_In_ HIMCC imcc, _In_ DWORD size);
219 DWORD  WINAPI ImmGetIMCCSize(_In_ HIMCC imcc);
220 
221 /* Messaging */
222 
223 BOOL WINAPI ImmGenerateMessage(_In_ HIMC hIMC);
224 
225 BOOL WINAPI
226 ImmTranslateMessage(
227     _In_ HWND hwnd,
228     _In_ UINT msg,
229     _In_ WPARAM wParam,
230     _In_ LPARAM lKeyData);
231 
232 LRESULT WINAPI ImmRequestMessageA(_In_ HIMC hIMC, _In_ WPARAM wParam, _In_ LPARAM lParam);
233 LRESULT WINAPI ImmRequestMessageW(_In_ HIMC hIMC, _In_ WPARAM wParam, _In_ LPARAM lParam);
234 
235 #ifdef UNICODE
236     #define ImmRequestMessage ImmRequestMessageW
237 #else
238     #define ImmRequestMessage ImmRequestMessageA
239 #endif
240 
241 typedef struct _tagTRANSMSG {
242     UINT message;
243     WPARAM wParam;
244     LPARAM lParam;
245 } TRANSMSG, *PTRANSMSG, NEAR *NPTRANSMSG, FAR *LPTRANSMSG;
246 
247 typedef struct _tagTRANSMSGLIST {
248     UINT     uMsgCount;
249     TRANSMSG TransMsg[ANYSIZE_ARRAY];
250 } TRANSMSGLIST, *PTRANSMSGLIST, NEAR *NPTRANSMSGLIST, FAR *LPTRANSMSGLIST;
251 
252 /* Soft keyboard */
253 
254 HWND WINAPI
255 ImmCreateSoftKeyboard(
256     _In_ UINT uType,
257     _In_ HWND hwndParent,
258     _In_ INT x,
259     _In_ INT y);
260 
261 BOOL WINAPI
262 ImmShowSoftKeyboard(
263     _In_ HWND hwndSoftKBD,
264     _In_ INT nCmdShow);
265 
266 BOOL WINAPI
267 ImmDestroySoftKeyboard(
268     _In_ HWND hwndSoftKBD);
269 
270 /* IME file interface */
271 
272 BOOL WINAPI
273 ImeInquire(
274     _Out_ LPIMEINFO lpIMEInfo,
275     _Out_ LPTSTR lpszWndClass,
276     _In_ DWORD dwSystemInfoFlags);
277 
278 DWORD WINAPI
279 ImeConversionList(
280     _In_ HIMC hIMC,
281     _In_ LPCTSTR lpSrc,
282     _Out_ LPCANDIDATELIST lpDst,
283     _In_ DWORD dwBufLen,
284     _In_ UINT uFlag);
285 
286 BOOL WINAPI
287 ImeRegisterWord(
288     _In_ LPCTSTR lpszReading,
289     _In_ DWORD dwStyle,
290     _In_ LPCTSTR lpszString);
291 
292 BOOL WINAPI
293 ImeUnregisterWord(
294     _In_ LPCTSTR lpszReading,
295     _In_ DWORD dwStyle,
296     _In_ LPCTSTR lpszString);
297 
298 UINT WINAPI
299 ImeGetRegisterWordStyle(
300     _In_ UINT nItem,
301     _Out_ LPSTYLEBUF lpStyleBuf);
302 
303 UINT WINAPI
304 ImeEnumRegisterWord(
305     _In_ REGISTERWORDENUMPROC lpfnEnumProc,
306     _In_opt_ LPCTSTR lpszReading,
307     _In_ DWORD dwStyle,
308     _In_opt_ LPCTSTR lpszString,
309     _In_opt_ LPVOID lpData);
310 
311 BOOL WINAPI
312 ImeConfigure(
313     _In_ HKL hKL,
314     _In_ HWND hWnd,
315     _In_ DWORD dwMode,
316     _Inout_opt_ LPVOID lpData);
317 
318 BOOL WINAPI
319 ImeDestroy(
320     _In_ UINT uReserved);
321 
322 LRESULT WINAPI
323 ImeEscape(
324     _In_ HIMC hIMC,
325     _In_ UINT uEscape,
326     _Inout_opt_ LPVOID lpData);
327 
328 BOOL WINAPI
329 ImeProcessKey(
330     _In_ HIMC hIMC,
331     _In_ UINT uVirKey,
332     _In_ LPARAM lParam,
333     _In_ CONST LPBYTE lpbKeyState);
334 
335 BOOL WINAPI
336 ImeSelect(
337     _In_ HIMC hIMC,
338     _In_ BOOL fSelect);
339 
340 BOOL WINAPI
341 ImeSetActiveContext(
342     _In_ HIMC hIMC,
343     _In_ BOOL fFlag);
344 
345 UINT WINAPI
346 ImeToAsciiEx(
347     _In_ UINT uVirKey,
348     _In_ UINT uScanCode,
349     _In_ CONST LPBYTE lpbKeyState,
350     _Out_ LPTRANSMSGLIST lpTransMsgList,
351     _In_ UINT fuState,
352     _In_ HIMC hIMC);
353 
354 BOOL WINAPI
355 NotifyIME(
356     _In_ HIMC hIMC,
357     _In_ DWORD dwAction,
358     _In_ DWORD dwIndex,
359     _In_ DWORD_PTR dwValue);
360 
361 BOOL WINAPI
362 ImeSetCompositionString(
363     _In_ HIMC hIMC,
364     _In_ DWORD dwIndex,
365     _In_opt_ LPCVOID lpComp,
366     _In_ DWORD dwCompLen,
367     _In_opt_ LPCVOID lpRead,
368     _In_ DWORD dwReadLen);
369 
370 DWORD WINAPI
371 ImeGetImeMenuItems(
372     _In_ HIMC hIMC,
373     _In_ DWORD dwFlags,
374     _In_ DWORD dwType,
375     _Inout_opt_ LPIMEMENUITEMINFO lpImeParentMenu,
376     _Inout_opt_ LPIMEMENUITEMINFO lpImeMenu,
377     _In_ DWORD dwSize);
378 
379 #ifdef __cplusplus
380 } /* extern "C" */
381 #endif
382 
383 /* IME Property bits */
384 #define IME_PROP_END_UNLOAD             0x0001
385 #define IME_PROP_KBD_CHAR_FIRST         0x0002
386 #define IME_PROP_IGNORE_UPKEYS          0x0004
387 #define IME_PROP_NEED_ALTKEY            0x0008
388 #define IME_PROP_NO_KEYS_ON_CLOSE       0x0010
389 #define IME_PROP_ACCEPT_WIDE_VKEY       0x0020
390 
391 /* for NI_CONTEXTUPDATED */
392 #define IMC_SETCONVERSIONMODE           0x0002
393 #define IMC_SETSENTENCEMODE             0x0004
394 #define IMC_SETOPENSTATUS               0x0006
395 
396 /* dwAction for ImmNotifyIME */
397 #define NI_CONTEXTUPDATED               0x0003
398 #define NI_OPENCANDIDATE                0x0010
399 #define NI_CLOSECANDIDATE               0x0011
400 #define NI_SELECTCANDIDATESTR           0x0012
401 #define NI_CHANGECANDIDATELIST          0x0013
402 #define NI_FINALIZECONVERSIONRESULT     0x0014
403 #define NI_COMPOSITIONSTR               0x0015
404 #define NI_SETCANDIDATE_PAGESTART       0x0016
405 #define NI_SETCANDIDATE_PAGESIZE        0x0017
406 #define NI_IMEMENUSELECTED              0x0018
407 
408 /* dwSystemInfoFlags bits */
409 #define IME_SYSINFO_WINLOGON            0x0001
410 #define IME_SYSINFO_WOW16               0x0002
411 
412 #endif  /* ndef _IMMDEV_ */
413