1b4557a60SKatayama Hirofumi MZ /* 2b4557a60SKatayama Hirofumi MZ * PROJECT: ReactOS IMM32 3b4557a60SKatayama Hirofumi MZ * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4b4557a60SKatayama Hirofumi MZ * PURPOSE: Implementing IMM32 5b4557a60SKatayama Hirofumi MZ * COPYRIGHT: Copyright 1998 Patrik Stridvall 6b4557a60SKatayama Hirofumi MZ * Copyright 2002, 2003, 2007 CodeWeavers, Aric Stewart 7b4557a60SKatayama Hirofumi MZ * Copyright 2017 James Tabor <james.tabor@reactos.org> 8b4557a60SKatayama Hirofumi MZ * Copyright 2018 Amine Khaldi <amine.khaldi@reactos.org> 9b4557a60SKatayama Hirofumi MZ * Copyright 2020 Oleg Dubinskiy <oleg.dubinskij2013@yandex.ua> 10c2a94365SKatayama Hirofumi MZ * Copyright 2020-2022 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 11b4557a60SKatayama Hirofumi MZ */ 12b4557a60SKatayama Hirofumi MZ 13b4557a60SKatayama Hirofumi MZ #pragma once 14b4557a60SKatayama Hirofumi MZ 15b4557a60SKatayama Hirofumi MZ #include <stdio.h> 16b4557a60SKatayama Hirofumi MZ #include <stdlib.h> 17b4557a60SKatayama Hirofumi MZ 18b4557a60SKatayama Hirofumi MZ /* PSDK/NDK Headers */ 19b4557a60SKatayama Hirofumi MZ #define WIN32_NO_STATUS 20b4557a60SKatayama Hirofumi MZ #include <windef.h> 21b4557a60SKatayama Hirofumi MZ #include <winbase.h> 22b4557a60SKatayama Hirofumi MZ #include <wingdi.h> 23b4557a60SKatayama Hirofumi MZ #include <winuser.h> 24b4557a60SKatayama Hirofumi MZ #include <winnls.h> 25b4557a60SKatayama Hirofumi MZ #include <winreg.h> 264f006ec7SKatayama Hirofumi MZ #include <winnls32.h> 27a37d9a4eSKatayama Hirofumi MZ #include <winver.h> 28b4557a60SKatayama Hirofumi MZ 29b4557a60SKatayama Hirofumi MZ #include <imm.h> 30*8ea93d2aSKatayama Hirofumi MZ #include <immdev.h> 31*8ea93d2aSKatayama Hirofumi MZ #include <imm32_undoc.h> 32b4557a60SKatayama Hirofumi MZ 33b4557a60SKatayama Hirofumi MZ #define NTOS_MODE_USER 34b4557a60SKatayama Hirofumi MZ #include <ndk/umtypes.h> 35b4557a60SKatayama Hirofumi MZ #include <ndk/pstypes.h> 36b4557a60SKatayama Hirofumi MZ #include <ndk/rtlfuncs.h> 37b4557a60SKatayama Hirofumi MZ 38b4557a60SKatayama Hirofumi MZ /* Public Win32K Headers */ 39b4557a60SKatayama Hirofumi MZ #include "ntuser.h" 40b4557a60SKatayama Hirofumi MZ #include "ntwin32.h" 41b4557a60SKatayama Hirofumi MZ 42b4557a60SKatayama Hirofumi MZ /* Undocumented user definitions */ 43b4557a60SKatayama Hirofumi MZ #include <undocuser.h> 44b4557a60SKatayama Hirofumi MZ 45b4557a60SKatayama Hirofumi MZ #include <strsafe.h> 46b4557a60SKatayama Hirofumi MZ 47b4557a60SKatayama Hirofumi MZ #include <wine/debug.h> 48b4557a60SKatayama Hirofumi MZ #include <wine/list.h> 49b4557a60SKatayama Hirofumi MZ 50b4557a60SKatayama Hirofumi MZ #define IMM_INIT_MAGIC 0x19650412 51b4557a60SKatayama Hirofumi MZ #define IMM_INVALID_CANDFORM ULONG_MAX 52b4557a60SKatayama Hirofumi MZ #define INVALID_HOTKEY_ID 0xFFFFFFFF 53b4557a60SKatayama Hirofumi MZ #define MAX_CANDIDATEFORM 4 54afb6c8a1SKatayama Hirofumi MZ #define MAX_IMM_FILENAME 80 55b4557a60SKatayama Hirofumi MZ 56b4557a60SKatayama Hirofumi MZ #define LANGID_CHINESE_SIMPLIFIED MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) 57b4557a60SKatayama Hirofumi MZ #define LANGID_CHINESE_TRADITIONAL MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) 58b4557a60SKatayama Hirofumi MZ #define LANGID_JAPANESE MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) 59b4557a60SKatayama Hirofumi MZ 60b4557a60SKatayama Hirofumi MZ #define REGKEY_KEYBOARD_LAYOUTS L"System\\CurrentControlSet\\Control\\Keyboard Layouts" 61b4557a60SKatayama Hirofumi MZ 62b4557a60SKatayama Hirofumi MZ #define ROUNDUP4(n) (((n) + 3) & ~3) /* DWORD alignment */ 63b4557a60SKatayama Hirofumi MZ 64a37d9a4eSKatayama Hirofumi MZ typedef struct REG_IME 65a37d9a4eSKatayama Hirofumi MZ { 66a37d9a4eSKatayama Hirofumi MZ HKL hKL; 67a37d9a4eSKatayama Hirofumi MZ WCHAR szImeKey[20]; /* "E0XXYYYY": "E0XX" is the device handle. "YYYY" is a LANGID. */ 68a37d9a4eSKatayama Hirofumi MZ WCHAR szFileName[80]; /* The IME module filename */ 69a37d9a4eSKatayama Hirofumi MZ } REG_IME, *PREG_IME; 70a37d9a4eSKatayama Hirofumi MZ 71bc8a4ac3SKatayama Hirofumi MZ extern HMODULE ghImm32Inst; 72895909e6SKatayama Hirofumi MZ extern RTL_CRITICAL_SECTION gcsImeDpi; 733c169714SKatayama Hirofumi MZ extern PIMEDPI gpImeDpiList; 7482fa82d8SKatayama Hirofumi MZ extern PSERVERINFO gpsi; 756dfe0321SKatayama Hirofumi MZ extern SHAREDINFO gSharedInfo; 76ed765b7cSKatayama Hirofumi MZ extern HANDLE ghImmHeap; 77dabb3f4dSKatayama Hirofumi MZ extern DWORD g_aimm_compat_flags; 78b4557a60SKatayama Hirofumi MZ 79b4557a60SKatayama Hirofumi MZ BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName); 80b4557a60SKatayama Hirofumi MZ VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW); 81b4557a60SKatayama Hirofumi MZ VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA); 82be9a788fSKatayama Hirofumi MZ LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType); 83b0b925d2SKatayama Hirofumi MZ LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType); 84b0b925d2SKatayama Hirofumi MZ #define ValidateHwndNoErr(hwnd) ValidateHandleNoErr((hwnd), TYPE_WINDOW) 85b0b925d2SKatayama Hirofumi MZ #define ValidateHwnd(hwnd) ValidateHandle((hwnd), TYPE_WINDOW) 86be9a788fSKatayama Hirofumi MZ BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC); 875b522667SKatayama Hirofumi MZ 8846518ad6SKatayama Hirofumi MZ LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes); 89ed765b7cSKatayama Hirofumi MZ #define ImmLocalFree(lpData) HeapFree(ghImmHeap, 0, (lpData)) 905b522667SKatayama Hirofumi MZ 9165858036SKatayama Hirofumi MZ LPWSTR APIENTRY Imm32WideFromAnsi(UINT uCodePage, LPCSTR pszA); 9265858036SKatayama Hirofumi MZ LPSTR APIENTRY Imm32AnsiFromWide(UINT uCodePage, LPCWSTR pszW); 93fec35dc8SKatayama Hirofumi MZ LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage); 94fec35dc8SKatayama Hirofumi MZ LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage); 9597f4c3c3SKatayama Hirofumi MZ PIMEDPI APIENTRY Imm32FindOrLoadImeDpi(HKL hKL); 968de74398SKatayama Hirofumi MZ LPINPUTCONTEXT APIENTRY Imm32InternalLockIMC(HIMC hIMC, BOOL fSelect); 97e6a51b54SKatayama Hirofumi MZ BOOL APIENTRY Imm32ReleaseIME(HKL hKL); 988cdfc245SKatayama Hirofumi MZ BOOL APIENTRY Imm32IsSystemJapaneseOrKorean(VOID); 99c2a94365SKatayama Hirofumi MZ BOOL APIENTRY Imm32IsCrossThreadAccess(HIMC hIMC); 100c2a94365SKatayama Hirofumi MZ BOOL APIENTRY Imm32IsCrossProcessAccess(HWND hWnd); 10133affbfeSKatayama Hirofumi MZ BOOL WINAPI Imm32IsImcAnsi(HIMC hIMC); 10233affbfeSKatayama Hirofumi MZ 103a65014e3SKatayama Hirofumi MZ #if 0 104a65014e3SKatayama Hirofumi MZ #define UNEXPECTED() ASSERT(FALSE) 105a65014e3SKatayama Hirofumi MZ #else 106a65014e3SKatayama Hirofumi MZ #define UNEXPECTED() 0 107a65014e3SKatayama Hirofumi MZ #endif 108a65014e3SKatayama Hirofumi MZ 109c2a94365SKatayama Hirofumi MZ /* 110c2a94365SKatayama Hirofumi MZ * Unexpected Condition Checkers 111c2a94365SKatayama Hirofumi MZ * --- Examine the condition, and then generate trace log if necessary. 112c2a94365SKatayama Hirofumi MZ */ 113c2a94365SKatayama Hirofumi MZ #ifdef NDEBUG /* on Release */ 114931224fbSKatayama Hirofumi MZ #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr)) 115c2a94365SKatayama Hirofumi MZ #define IS_NULL_UNEXPECTEDLY(p) (!(p)) 116c2a94365SKatayama Hirofumi MZ #define IS_ZERO_UNEXPECTEDLY(p) (!(p)) 117c2a94365SKatayama Hirofumi MZ #define IS_TRUE_UNEXPECTEDLY(x) (x) 118c2a94365SKatayama Hirofumi MZ #define IS_FALSE_UNEXPECTEDLY(x) (!(x)) 119c2a94365SKatayama Hirofumi MZ #define IS_ERROR_UNEXPECTEDLY(x) (!(x)) 120c2a94365SKatayama Hirofumi MZ #else /* on Debug */ 121931224fbSKatayama Hirofumi MZ #define FAILED_UNEXPECTEDLY(hr) \ 122931224fbSKatayama Hirofumi MZ (FAILED(hr) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 123931224fbSKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, "FAILED(%s)\n", #hr), UNEXPECTED(), TRUE) \ 124931224fbSKatayama Hirofumi MZ : FALSE) 125c2a94365SKatayama Hirofumi MZ #define IS_NULL_UNEXPECTEDLY(p) \ 126c2a94365SKatayama Hirofumi MZ (!(p) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 127a65014e3SKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, "%s was NULL\n", #p), UNEXPECTED(), TRUE) \ 128c2a94365SKatayama Hirofumi MZ : FALSE) 129c2a94365SKatayama Hirofumi MZ #define IS_ZERO_UNEXPECTEDLY(p) \ 130c2a94365SKatayama Hirofumi MZ (!(p) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 131a65014e3SKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, "%s was zero\n", #p), UNEXPECTED(), TRUE) \ 132c2a94365SKatayama Hirofumi MZ : FALSE) 133c2a94365SKatayama Hirofumi MZ #define IS_TRUE_UNEXPECTEDLY(x) \ 134c2a94365SKatayama Hirofumi MZ ((x) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 135a65014e3SKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, "%s was non-zero\n", #x), UNEXPECTED(), TRUE) \ 136c2a94365SKatayama Hirofumi MZ : FALSE) 137c2a94365SKatayama Hirofumi MZ #define IS_FALSE_UNEXPECTEDLY(x) \ 138c2a94365SKatayama Hirofumi MZ ((!(x)) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 139a65014e3SKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, "%s was FALSE\n", #x), UNEXPECTED(), TRUE) \ 140c2a94365SKatayama Hirofumi MZ : FALSE) 141c2a94365SKatayama Hirofumi MZ #define IS_ERROR_UNEXPECTEDLY(x) \ 142c2a94365SKatayama Hirofumi MZ ((x) != ERROR_SUCCESS ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \ 143c2a94365SKatayama Hirofumi MZ __FILE__, __FUNCTION__, __LINE__, \ 144c2a94365SKatayama Hirofumi MZ "%s was 0x%X\n", #x, (x)), TRUE) \ 145c2a94365SKatayama Hirofumi MZ : FALSE) 146c2a94365SKatayama Hirofumi MZ #endif 147c2a94365SKatayama Hirofumi MZ 148c2a94365SKatayama Hirofumi MZ #define IS_CROSS_THREAD_HIMC(hIMC) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossThreadAccess(hIMC)) 149c2a94365SKatayama Hirofumi MZ #define IS_CROSS_PROCESS_HWND(hWnd) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossProcessAccess(hWnd)) 150e0da6437SKatayama Hirofumi MZ #define ImeDpi_IsUnicode(pImeDpi) ((pImeDpi)->ImeInfo.fdwProperty & IME_PROP_UNICODE) 151e0da6437SKatayama Hirofumi MZ 152b4557a60SKatayama Hirofumi MZ DWORD APIENTRY 153b4557a60SKatayama Hirofumi MZ CandidateListWideToAnsi(const CANDIDATELIST *pWideCL, LPCANDIDATELIST pAnsiCL, DWORD dwBufLen, 154b4557a60SKatayama Hirofumi MZ UINT uCodePage); 155b4557a60SKatayama Hirofumi MZ DWORD APIENTRY 156b4557a60SKatayama Hirofumi MZ CandidateListAnsiToWide(const CANDIDATELIST *pAnsiCL, LPCANDIDATELIST pWideCL, DWORD dwBufLen, 157b4557a60SKatayama Hirofumi MZ UINT uCodePage); 158b4557a60SKatayama Hirofumi MZ 159b4557a60SKatayama Hirofumi MZ BOOL APIENTRY 16016678606SKatayama Hirofumi MZ Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue, 161b4557a60SKatayama Hirofumi MZ DWORD_PTR dwCommand, DWORD_PTR dwData); 162b4557a60SKatayama Hirofumi MZ 163bc8a4ac3SKatayama Hirofumi MZ DWORD APIENTRY Imm32BuildHimcList(DWORD dwThreadId, HIMC **pphList); 16433affbfeSKatayama Hirofumi MZ 16533affbfeSKatayama Hirofumi MZ INT APIENTRY 16633affbfeSKatayama Hirofumi MZ Imm32ImeMenuAnsiToWide(const IMEMENUITEMINFOA *pItemA, LPIMEMENUITEMINFOW pItemW, 16733affbfeSKatayama Hirofumi MZ UINT uCodePage, BOOL bBitmap); 16833affbfeSKatayama Hirofumi MZ INT APIENTRY 16933affbfeSKatayama Hirofumi MZ Imm32ImeMenuWideToAnsi(const IMEMENUITEMINFOW *pItemW, LPIMEMENUITEMINFOA pItemA, 17033affbfeSKatayama Hirofumi MZ UINT uCodePage); 17166ef3149SKatayama Hirofumi MZ 17266ef3149SKatayama Hirofumi MZ PIME_STATE APIENTRY Imm32FetchImeState(LPINPUTCONTEXTDX pIC, HKL hKL); 17366ef3149SKatayama Hirofumi MZ PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL); 17466ef3149SKatayama Hirofumi MZ 17566ef3149SKatayama Hirofumi MZ BOOL APIENTRY 17666ef3149SKatayama Hirofumi MZ Imm32LoadImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL); 17766ef3149SKatayama Hirofumi MZ BOOL APIENTRY 17866ef3149SKatayama Hirofumi MZ Imm32SaveImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL); 17904cb13bcSKatayama Hirofumi MZ 18004cb13bcSKatayama Hirofumi MZ DWORD APIENTRY 18104cb13bcSKatayama Hirofumi MZ Imm32ReconvertAnsiFromWide(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage); 18204cb13bcSKatayama Hirofumi MZ DWORD APIENTRY 18304cb13bcSKatayama Hirofumi MZ Imm32ReconvertWideFromAnsi(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage); 184a37d9a4eSKatayama Hirofumi MZ 185a37d9a4eSKatayama Hirofumi MZ HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase); 186a37d9a4eSKatayama Hirofumi MZ HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff); 187a37d9a4eSKatayama Hirofumi MZ BOOL APIENTRY Imm32LoadImeVerInfo(PIMEINFOEX pImeInfoEx); 18816678606SKatayama Hirofumi MZ UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts); 1898f0e22acSKatayama Hirofumi MZ BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayoutText); 19016678606SKatayama Hirofumi MZ HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID); 19116678606SKatayama Hirofumi MZ BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile); 192c2a94365SKatayama Hirofumi MZ PTHREADINFO FASTCALL Imm32CurrentPti(VOID); 193ffbdb7d3SKatayama Hirofumi MZ 194ffbdb7d3SKatayama Hirofumi MZ HBITMAP Imm32LoadBitmapFromBytes(const BYTE *pb); 195ffbdb7d3SKatayama Hirofumi MZ BOOL Imm32StoreBitmapToBytes(HBITMAP hbm, LPBYTE pbData, DWORD cbDataMax); 196b3194e32SKatayama Hirofumi MZ 197b3194e32SKatayama Hirofumi MZ HRESULT CtfImmTIMCreateInputContext(_In_ HIMC hIMC); 198b3194e32SKatayama Hirofumi MZ HRESULT CtfImmTIMDestroyInputContext(_In_ HIMC hIMC); 199931224fbSKatayama Hirofumi MZ HRESULT CtfImmCoInitialize(VOID); 200931224fbSKatayama Hirofumi MZ HRESULT CtfImeCreateThreadMgr(VOID); 201931224fbSKatayama Hirofumi MZ HRESULT CtfImeDestroyThreadMgr(VOID); 202931224fbSKatayama Hirofumi MZ HRESULT Imm32ActivateOrDeactivateTIM(_In_ BOOL bCreate); 20375cf6920SKatayama Hirofumi MZ 20475cf6920SKatayama Hirofumi MZ HRESULT 20575cf6920SKatayama Hirofumi MZ CtfImeSetActiveContextAlways( 20675cf6920SKatayama Hirofumi MZ _In_ HIMC hIMC, 20775cf6920SKatayama Hirofumi MZ _In_ BOOL fActive, 20875cf6920SKatayama Hirofumi MZ _In_ HWND hWnd, 20975cf6920SKatayama Hirofumi MZ _In_ HKL hKL); 21075cf6920SKatayama Hirofumi MZ 21175cf6920SKatayama Hirofumi MZ BOOL 21275cf6920SKatayama Hirofumi MZ CtfImeProcessCicHotkey( 21375cf6920SKatayama Hirofumi MZ _In_ HIMC hIMC, 21475cf6920SKatayama Hirofumi MZ _In_ UINT vKey, 21575cf6920SKatayama Hirofumi MZ _In_ LPARAM lParam); 21675cf6920SKatayama Hirofumi MZ 21775cf6920SKatayama Hirofumi MZ LRESULT 21875cf6920SKatayama Hirofumi MZ CtfImmSetLangBand( 21975cf6920SKatayama Hirofumi MZ _In_ HWND hWnd, 22075cf6920SKatayama Hirofumi MZ _In_ BOOL fSet); 221