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-2022 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 BOOL WINAPI ImmDisableTextFrameService(_In_ DWORD dwThreadId); 21 BOOL WINAPI CtfImmIsCiceroStartedInThread(VOID); 22 23 typedef struct tagSOFTKBDDATA 24 { 25 UINT uCount; 26 WORD wCode[1][256]; 27 } SOFTKBDDATA, *PSOFTKBDDATA, *LPSOFTKBDDATA; 28 29 /* wParam for WM_IME_CONTROL */ 30 #define IMC_GETCONVERSIONMODE 0x0001 31 #define IMC_GETSENTENCEMODE 0x0003 32 #define IMC_GETOPENSTATUS 0x0005 33 #define IMC_GETSOFTKBDFONT 0x0011 34 #define IMC_SETSOFTKBDFONT 0x0012 35 #define IMC_GETSOFTKBDPOS 0x0013 36 #define IMC_SETSOFTKBDPOS 0x0014 37 #define IMC_GETSOFTKBDSUBTYPE 0x0015 38 #define IMC_SETSOFTKBDSUBTYPE 0x0016 39 #define IMC_SETSOFTKBDDATA 0x0018 40 41 /* wParam for WM_IME_SYSTEM */ 42 #define IMS_NOTIFYIMESHOW 0x05 43 #define IMS_UPDATEIMEUI 0x06 44 #define IMS_SETCANDFORM 0x09 45 #define IMS_SETCOMPFONT 0x0A 46 #define IMS_SETCOMPFORM 0x0B 47 #define IMS_CONFIGURE 0x0D 48 #define IMS_SETOPENSTATUS 0x0F 49 #define IMS_FREELAYOUT 0x11 50 #define IMS_GETCONVSTATUS 0x14 51 #define IMS_IMEHELP 0x15 52 #define IMS_IMEACTIVATE 0x17 53 #define IMS_IMEDEACTIVATE 0x18 54 #define IMS_ACTIVATELAYOUT 0x19 55 #define IMS_GETIMEMENU 0x1C 56 #define IMS_GETCONTEXT 0x1E 57 #define IMS_SENDNOTIFICATION 0x1F 58 #define IMS_COMPLETECOMPSTR 0x20 59 #define IMS_LOADTHREADLAYOUT 0x21 60 #define IMS_SETLANGBAND 0x23 61 #define IMS_UNSETLANGBAND 0x24 62 63 /* wParam for WM_IME_NOTIFY */ 64 #define IMN_SOFTKBDDESTROYED 0x0011 65 66 #define IMMGWL_IMC 0 67 #define IMMGWL_PRIVATE (sizeof(LONG)) 68 69 #define IMMGWLP_IMC 0 70 #define IMMGWLP_PRIVATE (sizeof(LONG_PTR)) 71 72 typedef struct _tagINPUTCONTEXT { 73 HWND hWnd; 74 BOOL fOpen; 75 POINT ptStatusWndPos; 76 POINT ptSoftKbdPos; 77 DWORD fdwConversion; 78 DWORD fdwSentence; 79 union { 80 LOGFONTA A; 81 LOGFONTW W; 82 } lfFont; 83 COMPOSITIONFORM cfCompForm; 84 CANDIDATEFORM cfCandForm[4]; 85 HIMCC hCompStr; 86 HIMCC hCandInfo; 87 HIMCC hGuideLine; 88 HIMCC hPrivate; 89 DWORD dwNumMsgBuf; 90 HIMCC hMsgBuf; 91 DWORD fdwInit; 92 DWORD dwReserve[3]; 93 } INPUTCONTEXT, *PINPUTCONTEXT, *LPINPUTCONTEXT; 94 95 #ifdef _WIN64 96 C_ASSERT(offsetof(INPUTCONTEXT, hWnd) == 0x0); 97 C_ASSERT(offsetof(INPUTCONTEXT, fOpen) == 0x8); 98 C_ASSERT(offsetof(INPUTCONTEXT, ptStatusWndPos) == 0xc); 99 C_ASSERT(offsetof(INPUTCONTEXT, ptSoftKbdPos) == 0x14); 100 C_ASSERT(offsetof(INPUTCONTEXT, fdwConversion) == 0x1c); 101 C_ASSERT(offsetof(INPUTCONTEXT, fdwSentence) == 0x20); 102 C_ASSERT(offsetof(INPUTCONTEXT, lfFont) == 0x24); 103 C_ASSERT(offsetof(INPUTCONTEXT, cfCompForm) == 0x80); 104 C_ASSERT(offsetof(INPUTCONTEXT, cfCandForm) == 0x9c); 105 C_ASSERT(offsetof(INPUTCONTEXT, hCompStr) == 0x120); 106 C_ASSERT(offsetof(INPUTCONTEXT, hCandInfo) == 0x128); 107 C_ASSERT(offsetof(INPUTCONTEXT, hGuideLine) == 0x130); 108 C_ASSERT(offsetof(INPUTCONTEXT, hPrivate) == 0x138); 109 C_ASSERT(offsetof(INPUTCONTEXT, dwNumMsgBuf) == 0x140); 110 C_ASSERT(offsetof(INPUTCONTEXT, hMsgBuf) == 0x148); 111 C_ASSERT(offsetof(INPUTCONTEXT, fdwInit) == 0x150); 112 C_ASSERT(offsetof(INPUTCONTEXT, dwReserve) == 0x154); 113 C_ASSERT(sizeof(INPUTCONTEXT) == 0x160); 114 #else 115 C_ASSERT(offsetof(INPUTCONTEXT, hWnd) == 0x0); 116 C_ASSERT(offsetof(INPUTCONTEXT, fOpen) == 0x4); 117 C_ASSERT(offsetof(INPUTCONTEXT, ptStatusWndPos) == 0x8); 118 C_ASSERT(offsetof(INPUTCONTEXT, ptSoftKbdPos) == 0x10); 119 C_ASSERT(offsetof(INPUTCONTEXT, fdwConversion) == 0x18); 120 C_ASSERT(offsetof(INPUTCONTEXT, fdwSentence) == 0x1c); 121 C_ASSERT(offsetof(INPUTCONTEXT, lfFont) == 0x20); 122 C_ASSERT(offsetof(INPUTCONTEXT, cfCompForm) == 0x7c); 123 C_ASSERT(offsetof(INPUTCONTEXT, cfCandForm) == 0x98); 124 C_ASSERT(offsetof(INPUTCONTEXT, hCompStr) == 0x118); 125 C_ASSERT(offsetof(INPUTCONTEXT, hCandInfo) == 0x11c); 126 C_ASSERT(offsetof(INPUTCONTEXT, hGuideLine) == 0x120); 127 C_ASSERT(offsetof(INPUTCONTEXT, hPrivate) == 0x124); 128 C_ASSERT(offsetof(INPUTCONTEXT, dwNumMsgBuf) == 0x128); 129 C_ASSERT(offsetof(INPUTCONTEXT, hMsgBuf) == 0x12c); 130 C_ASSERT(offsetof(INPUTCONTEXT, fdwInit) == 0x130); 131 C_ASSERT(offsetof(INPUTCONTEXT, dwReserve) == 0x134); 132 C_ASSERT(sizeof(INPUTCONTEXT) == 0x140); 133 #endif 134 135 struct IME_STATE; 136 137 /* unconfirmed */ 138 #ifdef __cplusplus 139 typedef struct INPUTCONTEXTDX : INPUTCONTEXT 140 { 141 #else 142 typedef struct INPUTCONTEXTDX 143 { 144 INPUTCONTEXT; 145 #endif 146 UINT nVKey; // +0x140 147 BOOL bNeedsTrans; // +0x144 148 DWORD dwUnknown1; 149 DWORD dwUIFlags; // +0x14c 150 DWORD dwUnknown2; 151 struct IME_STATE *pState; // +0x154 152 DWORD dwChange; // +0x158 153 HIMCC hCtfImeContext; 154 } INPUTCONTEXTDX, *PINPUTCONTEXTDX, *LPINPUTCONTEXTDX; 155 156 // bits of fdwInit of INPUTCONTEXT 157 #define INIT_STATUSWNDPOS 0x00000001 158 #define INIT_CONVERSION 0x00000002 159 #define INIT_SENTENCE 0x00000004 160 #define INIT_LOGFONT 0x00000008 161 #define INIT_COMPFORM 0x00000010 162 #define INIT_SOFTKBDPOS 0x00000020 163 #define INIT_GUIDMAP 0x00000040 164 165 // bits for INPUTCONTEXTDX.dwChange 166 #define INPUTCONTEXTDX_CHANGE_OPEN 0x1 167 #define INPUTCONTEXTDX_CHANGE_CONVERSION 0x2 168 #define INPUTCONTEXTDX_CHANGE_SENTENCE 0x4 169 #define INPUTCONTEXTDX_CHANGE_FORCE_OPEN 0x100 170 171 #ifndef WM_IME_REPORT 172 #define WM_IME_REPORT 0x280 173 #endif 174 175 // WM_IME_REPORT wParam 176 #define IR_STRINGSTART 0x100 177 #define IR_STRINGEND 0x101 178 #define IR_OPENCONVERT 0x120 179 #define IR_CHANGECONVERT 0x121 180 #define IR_CLOSECONVERT 0x122 181 #define IR_FULLCONVERT 0x123 182 #define IR_IMESELECT 0x130 183 #define IR_STRING 0x140 184 #define IR_DBCSCHAR 0x160 185 #define IR_UNDETERMINE 0x170 186 #define IR_STRINGEX 0x180 187 #define IR_MODEINFO 0x190 188 189 // for IR_UNDETERMINE 190 typedef struct tagUNDETERMINESTRUCT 191 { 192 DWORD dwSize; 193 UINT uDefIMESize; 194 UINT uDefIMEPos; 195 UINT uUndetTextLen; 196 UINT uUndetTextPos; 197 UINT uUndetAttrPos; 198 UINT uCursorPos; 199 UINT uDeltaStart; 200 UINT uDetermineTextLen; 201 UINT uDetermineTextPos; 202 UINT uDetermineDelimPos; 203 UINT uYomiTextLen; 204 UINT uYomiTextPos; 205 UINT uYomiDelimPos; 206 } UNDETERMINESTRUCT, *PUNDETERMINESTRUCT, *LPUNDETERMINESTRUCT; 207 208 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC); 209 210 typedef struct IME_SUBSTATE 211 { 212 struct IME_SUBSTATE *pNext; 213 HKL hKL; 214 DWORD dwValue; 215 } IME_SUBSTATE, *PIME_SUBSTATE; 216 217 #ifndef _WIN64 218 C_ASSERT(sizeof(IME_SUBSTATE) == 0xc); 219 #endif 220 221 typedef struct IME_STATE 222 { 223 struct IME_STATE *pNext; 224 WORD wLang; 225 WORD fOpen; 226 DWORD dwConversion; 227 DWORD dwSentence; 228 DWORD dwInit; 229 PIME_SUBSTATE pSubState; 230 } IME_STATE, *PIME_STATE; 231 232 #ifndef _WIN64 233 C_ASSERT(sizeof(IME_STATE) == 0x18); 234 #endif 235 236 typedef struct _tagTRANSMSG 237 { 238 UINT message; 239 WPARAM wParam; 240 LPARAM lParam; 241 } TRANSMSG, *PTRANSMSG, *LPTRANSMSG; 242 243 typedef struct _tagTRANSMSGLIST 244 { 245 UINT uMsgCount; 246 TRANSMSG TransMsg[ANYSIZE_ARRAY]; 247 } TRANSMSGLIST, *PTRANSMSGLIST, *LPTRANSMSGLIST; 248 249 #define DEFINE_IME_ENTRY(type, name, params, extended) typedef type (WINAPI *FN_##name) params; 250 #include <imetable.h> 251 #undef DEFINE_IME_ENTRY 252 253 typedef struct IMEDPI 254 { 255 struct IMEDPI *pNext; 256 HINSTANCE hInst; 257 HKL hKL; 258 IMEINFO ImeInfo; 259 UINT uCodePage; 260 WCHAR szUIClass[16]; 261 DWORD cLockObj; 262 DWORD dwFlags; 263 #define DEFINE_IME_ENTRY(type, name, params, extended) FN_##name name; 264 #include <imetable.h> 265 #undef DEFINE_IME_ENTRY 266 } IMEDPI, *PIMEDPI; 267 268 #ifndef _WIN64 269 C_ASSERT(offsetof(IMEDPI, pNext) == 0x0); 270 C_ASSERT(offsetof(IMEDPI, hInst) == 0x4); 271 C_ASSERT(offsetof(IMEDPI, hKL) == 0x8); 272 C_ASSERT(offsetof(IMEDPI, ImeInfo) == 0xc); 273 C_ASSERT(offsetof(IMEDPI, uCodePage) == 0x28); 274 C_ASSERT(offsetof(IMEDPI, szUIClass) == 0x2c); 275 C_ASSERT(offsetof(IMEDPI, cLockObj) == 0x4c); 276 C_ASSERT(offsetof(IMEDPI, dwFlags) == 0x50); 277 C_ASSERT(offsetof(IMEDPI, ImeInquire) == 0x54); 278 C_ASSERT(offsetof(IMEDPI, ImeConversionList) == 0x58); 279 C_ASSERT(offsetof(IMEDPI, ImeRegisterWord) == 0x5c); 280 C_ASSERT(offsetof(IMEDPI, ImeUnregisterWord) == 0x60); 281 C_ASSERT(offsetof(IMEDPI, ImeGetRegisterWordStyle) == 0x64); 282 C_ASSERT(offsetof(IMEDPI, ImeEnumRegisterWord) == 0x68); 283 C_ASSERT(offsetof(IMEDPI, ImeConfigure) == 0x6c); 284 C_ASSERT(offsetof(IMEDPI, ImeDestroy) == 0x70); 285 C_ASSERT(offsetof(IMEDPI, ImeEscape) == 0x74); 286 C_ASSERT(offsetof(IMEDPI, ImeProcessKey) == 0x78); 287 C_ASSERT(offsetof(IMEDPI, ImeSelect) == 0x7c); 288 C_ASSERT(offsetof(IMEDPI, ImeSetActiveContext) == 0x80); 289 C_ASSERT(offsetof(IMEDPI, ImeToAsciiEx) == 0x84); 290 C_ASSERT(offsetof(IMEDPI, NotifyIME) == 0x88); 291 C_ASSERT(offsetof(IMEDPI, ImeSetCompositionString) == 0x8c); 292 C_ASSERT(offsetof(IMEDPI, ImeGetImeMenuItems) == 0x90); 293 C_ASSERT(offsetof(IMEDPI, CtfImeInquireExW) == 0x94); 294 C_ASSERT(offsetof(IMEDPI, CtfImeSelectEx) == 0x98); 295 C_ASSERT(offsetof(IMEDPI, CtfImeEscapeEx) == 0x9c); 296 C_ASSERT(offsetof(IMEDPI, CtfImeGetGuidAtom) == 0xa0); 297 C_ASSERT(offsetof(IMEDPI, CtfImeIsGuidMapEnable) == 0xa4); 298 C_ASSERT(sizeof(IMEDPI) == 0xa8); 299 #endif 300 301 /* flags for IMEDPI.dwFlags */ 302 #define IMEDPI_FLAG_UNLOADED 0x1 303 #define IMEDPI_FLAG_LOCKED 0x2 304 305 /* unconfirmed */ 306 typedef struct tagCLIENTIMC 307 { 308 HANDLE hInputContext; /* LocalAlloc'ed LHND */ 309 LONG cLockObj; 310 DWORD dwFlags; 311 DWORD dwCompatFlags; 312 RTL_CRITICAL_SECTION cs; 313 UINT uCodePage; 314 HKL hKL; 315 BOOL bCtfIme; 316 } CLIENTIMC, *PCLIENTIMC; 317 318 #ifndef _WIN64 319 C_ASSERT(offsetof(CLIENTIMC, hInputContext) == 0x0); 320 C_ASSERT(offsetof(CLIENTIMC, cLockObj) == 0x4); 321 C_ASSERT(offsetof(CLIENTIMC, dwFlags) == 0x8); 322 C_ASSERT(offsetof(CLIENTIMC, dwCompatFlags) == 0xc); 323 C_ASSERT(offsetof(CLIENTIMC, cs) == 0x10); 324 C_ASSERT(offsetof(CLIENTIMC, uCodePage) == 0x28); 325 C_ASSERT(offsetof(CLIENTIMC, hKL) == 0x2c); 326 C_ASSERT(sizeof(CLIENTIMC) == 0x34); 327 #endif 328 329 /* flags for CLIENTIMC */ 330 #define CLIENTIMC_WIDE 0x1 331 #define CLIENTIMC_ACTIVE 0x2 332 #define CLIENTIMC_UNKNOWN4 0x20 333 #define CLIENTIMC_DESTROY 0x40 334 #define CLIENTIMC_DISABLEIME 0x80 335 #define CLIENTIMC_UNKNOWN2 0x100 336 337 /* IME file interface */ 338 339 BOOL WINAPI 340 ImeInquire( 341 _Out_ LPIMEINFO lpIMEInfo, 342 _Out_ LPWSTR lpszWndClass, 343 _In_ DWORD dwSystemInfoFlags); 344 345 DWORD WINAPI 346 ImeConversionList( 347 _In_ HIMC hIMC, 348 _In_ LPCWSTR lpSrc, 349 _Out_ LPCANDIDATELIST lpDst, 350 _In_ DWORD dwBufLen, 351 _In_ UINT uFlag); 352 353 BOOL WINAPI 354 ImeRegisterWord( 355 _In_ LPCWSTR lpszReading, 356 _In_ DWORD dwStyle, 357 _In_ LPCWSTR lpszString); 358 359 BOOL WINAPI 360 ImeUnregisterWord( 361 _In_ LPCWSTR lpszReading, 362 _In_ DWORD dwStyle, 363 _In_ LPCWSTR lpszString); 364 365 UINT WINAPI 366 ImeGetRegisterWordStyle( 367 _In_ UINT nItem, 368 _Out_ LPSTYLEBUFW lpStyleBuf); 369 370 UINT WINAPI 371 ImeEnumRegisterWord( 372 _In_ REGISTERWORDENUMPROCW lpfnEnumProc, 373 _In_opt_ LPCWSTR lpszReading, 374 _In_ DWORD dwStyle, 375 _In_opt_ LPCWSTR lpszString, 376 _In_opt_ LPVOID lpData); 377 378 BOOL WINAPI 379 ImeConfigure( 380 _In_ HKL hKL, 381 _In_ HWND hWnd, 382 _In_ DWORD dwMode, 383 _Inout_opt_ LPVOID lpData); 384 385 BOOL WINAPI 386 ImeDestroy( 387 _In_ UINT uReserved); 388 389 LRESULT WINAPI 390 ImeEscape( 391 _In_ HIMC hIMC, 392 _In_ UINT uEscape, 393 _Inout_opt_ LPVOID lpData); 394 395 BOOL WINAPI 396 ImeProcessKey( 397 _In_ HIMC hIMC, 398 _In_ UINT uVirKey, 399 _In_ LPARAM lParam, 400 _In_ CONST LPBYTE lpbKeyState); 401 402 BOOL WINAPI 403 ImeSelect( 404 _In_ HIMC hIMC, 405 _In_ BOOL fSelect); 406 407 BOOL WINAPI 408 ImeSetActiveContext( 409 _In_ HIMC hIMC, 410 _In_ BOOL fFlag); 411 412 UINT WINAPI 413 ImeToAsciiEx( 414 _In_ UINT uVirKey, 415 _In_ UINT uScanCode, 416 _In_ CONST LPBYTE lpbKeyState, 417 _Out_ LPTRANSMSGLIST lpTransMsgList, 418 _In_ UINT fuState, 419 _In_ HIMC hIMC); 420 421 BOOL WINAPI 422 NotifyIME( 423 _In_ HIMC hIMC, 424 _In_ DWORD dwAction, 425 _In_ DWORD dwIndex, 426 _In_ DWORD_PTR dwValue); 427 428 BOOL WINAPI 429 ImeSetCompositionString( 430 _In_ HIMC hIMC, 431 _In_ DWORD dwIndex, 432 _In_opt_ LPCVOID lpComp, 433 _In_ DWORD dwCompLen, 434 _In_opt_ LPCVOID lpRead, 435 _In_ DWORD dwReadLen); 436 437 DWORD WINAPI 438 ImeGetImeMenuItems( 439 _In_ HIMC hIMC, 440 _In_ DWORD dwFlags, 441 _In_ DWORD dwType, 442 _Inout_opt_ LPIMEMENUITEMINFOW lpImeParentMenu, 443 _Inout_opt_ LPIMEMENUITEMINFOW lpImeMenu, 444 _In_ DWORD dwSize); 445 446 #ifdef __cplusplus 447 } // extern "C" 448 #endif 449 450 #endif /* ndef _IMMDEV_ */ 451