ReactOS 0.4.16-dev-1146-gc477928
precomp.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS IMM32
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Implementing IMM32
5 * COPYRIGHT: Copyright 1998 Patrik Stridvall
6 * Copyright 2002, 2003, 2007 CodeWeavers, Aric Stewart
7 * Copyright 2017 James Tabor <james.tabor@reactos.org>
8 * Copyright 2018 Amine Khaldi <amine.khaldi@reactos.org>
9 * Copyright 2020 Oleg Dubinskiy <oleg.dubinskij2013@yandex.ua>
10 * Copyright 2020-2022 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
11 */
12
13#pragma once
14
15#include <stdio.h>
16#include <stdlib.h>
17
18/* PSDK/NDK Headers */
19#define WIN32_NO_STATUS
20#include <windef.h>
21#include <winbase.h>
22#include <wingdi.h>
23#include <winuser.h>
24#include <winnls.h>
25#include <winreg.h>
26#include <winnls32.h>
27#include <winver.h>
28
29#include <imm.h>
30#include <immdev.h>
31#include <imm32_undoc.h>
32
33#define NTOS_MODE_USER
34#include <ndk/umtypes.h>
35#include <ndk/pstypes.h>
36#include <ndk/rtlfuncs.h>
37
38/* Public Win32K Headers */
39#include "ntuser.h"
40#include "ntwin32.h"
41
42/* Undocumented user definitions */
43#include <undocuser.h>
44
45#include <strsafe.h>
46
47#include <wine/debug.h>
48
49/* #define UNEXPECTED() (ASSERT(FALSE), TRUE) */
50#define UNEXPECTED() TRUE
51
52#define ERR_PRINTF(fmt, ...) (__WINE_IS_DEBUG_ON(_ERR, __wine_dbch___default) ? \
53 (wine_dbg_printf(fmt, ##__VA_ARGS__), UNEXPECTED()) : UNEXPECTED())
54
55/* Unexpected Condition Checkers */
56#if DBG
57 #define FAILED_UNEXPECTEDLY(hr) \
58 (FAILED(hr) ? ERR_PRINTF("FAILED(0x%08X)\n", hr) : FALSE)
59 #define IS_NULL_UNEXPECTEDLY(p) \
60 (!(p) ? ERR_PRINTF("%s was NULL\n", #p) : FALSE)
61 #define IS_ZERO_UNEXPECTEDLY(p) \
62 (!(p) ? ERR_PRINTF("%s was zero\n", #p) : FALSE)
63 #define IS_TRUE_UNEXPECTEDLY(x) \
64 ((x) ? ERR_PRINTF("%s was non-zero\n", #x) : FALSE)
65 #define IS_ERROR_UNEXPECTEDLY(x) \
66 ((x) != ERROR_SUCCESS ? ERR_PRINTF("%s was %d\n", #x, (int)(x)) : FALSE)
67#else
68 #define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
69 #define IS_NULL_UNEXPECTEDLY(p) (!(p))
70 #define IS_ZERO_UNEXPECTEDLY(p) (!(p))
71 #define IS_TRUE_UNEXPECTEDLY(x) (x)
72 #define IS_ERROR_UNEXPECTEDLY(x) ((x) != ERROR_SUCCESS)
73#endif
74
75#define IS_CROSS_THREAD_HIMC(hIMC) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossThreadAccess(hIMC))
76#define IS_CROSS_PROCESS_HWND(hWnd) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossProcessAccess(hWnd))
77
78#define IMM_INIT_MAGIC 0x19650412
79#define IMM_INVALID_CANDFORM ULONG_MAX
80#define INVALID_HOTKEY_ID 0xFFFFFFFF
81#define MAX_CANDIDATEFORM 4
82#define MAX_IMM_FILENAME 80
83
84#define LANGID_CHINESE_SIMPLIFIED MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)
85#define LANGID_CHINESE_TRADITIONAL MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)
86#define LANGID_JAPANESE MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)
87
88#define REGKEY_KEYBOARD_LAYOUTS L"System\\CurrentControlSet\\Control\\Keyboard Layouts"
89
90#define ROUNDUP4(n) (((n) + 3) & ~3) /* DWORD alignment */
91
92typedef struct REG_IME
93{
95 WCHAR szImeKey[20]; /* "E0XXYYYY": "E0XX" is the device handle. "YYYY" is a LANGID. */
96 WCHAR szFileName[80]; /* The IME module filename */
98
99extern HMODULE ghImm32Inst;
101extern PIMEDPI gpImeDpiList;
102extern PSERVERINFO gpsi;
104extern HANDLE ghImmHeap;
106
112#define ValidateHwndNoErr(hwnd) ValidateHandleNoErr((hwnd), TYPE_WINDOW)
113#define ValidateHwnd(hwnd) ValidateHandle((hwnd), TYPE_WINDOW)
115
117#define ImmLocalFree(lpData) HeapFree(ghImmHeap, 0, (lpData))
118
121LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage);
122LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage);
130
131#define ImeDpi_IsUnicode(pImeDpi) ((pImeDpi)->ImeInfo.fdwProperty & IME_PROP_UNICODE)
132
135 UINT uCodePage);
138 UINT uCodePage);
139
141Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue,
142 DWORD_PTR dwCommand, DWORD_PTR dwData);
143
145
148
153
155Imm32ReconvertAnsiFromWide(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage);
157Imm32ReconvertWideFromAnsi(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage);
158
159HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase);
160HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff);
162UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts);
163BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayoutText);
164HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID);
165BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile);
167
170
177
180 _In_ HIMC hIMC,
181 _In_ BOOL fActive,
182 _In_ HWND hWnd,
183 _In_ HKL hKL);
184
185BOOL
187 _In_ HIMC hIMC,
188 _In_ UINT vKey,
190
193 _In_ HWND hWnd,
194 _In_ BOOL fSet);
HWND hWnd
Definition: settings.c:17
LPARAM lParam
Definition: combotst.c:139
DWORD HIMC
Definition: dimm.idl:75
#define APIENTRY
Definition: api.h:79
LPINPUTCONTEXT APIENTRY Imm32InternalLockIMC(HIMC hIMC, BOOL fSelect)
Definition: imm.c:838
VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW)
Definition: utils.c:299
LPSTR APIENTRY Imm32AnsiFromWide(UINT uCodePage, LPCWSTR pszW)
Definition: utils.c:238
BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayoutText)
Definition: utils.c:971
struct REG_IME * PREG_IME
BOOL WINAPI Imm32IsImcAnsi(HIMC hIMC)
Definition: utils.c:216
BOOL APIENTRY Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue, DWORD_PTR dwCommand, DWORD_PTR dwData)
Definition: utils.c:427
PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL)
Definition: utils.c:524
HRESULT CtfImeSetActiveContextAlways(_In_ HIMC hIMC, _In_ BOOL fActive, _In_ HWND hWnd, _In_ HKL hKL)
Definition: msctfime.cpp:775
HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase)
Definition: utils.c:43
BOOL APIENTRY Imm32IsCrossThreadAccess(HIMC hIMC)
Definition: utils.c:26
HANDLE ghImmHeap
Definition: utils.c:16
VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA)
Definition: utils.c:312
BOOL Imm32StoreBitmapToBytes(HBITMAP hbm, LPBYTE pbData, DWORD cbDataMax)
Definition: utils.c:143
BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile)
Definition: utils.c:1068
LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
Definition: utils.c:338
DWORD APIENTRY CandidateListAnsiToWide(const CANDIDATELIST *pAnsiCL, LPCANDIDATELIST pWideCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:84
RTL_CRITICAL_SECTION gcsImeDpi
Definition: ime.c:16
UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts)
Definition: utils.c:896
HRESULT CtfImeCreateThreadMgr(VOID)
Definition: msctfime.cpp:666
HRESULT CtfImmCoInitialize(VOID)
Definition: ctf.c:574
HRESULT CtfImeDestroyThreadMgr(VOID)
Definition: msctfime.cpp:705
HMODULE ghImm32Inst
Definition: imm.c:17
PIMEDPI gpImeDpiList
Definition: ime.c:17
BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC)
Definition: utils.c:391
BOOL APIENTRY Imm32LoadImeVerInfo(PIMEINFOEX pImeInfoEx)
Definition: utils.c:793
PIMEDPI APIENTRY Imm32FindOrLoadImeDpi(HKL hKL)
Definition: ime.c:343
HRESULT CtfImmTIMCreateInputContext(_In_ HIMC hIMC)
Definition: ctf.c:939
PTHREADINFO FASTCALL Imm32CurrentPti(VOID)
Definition: utils.c:19
LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
Definition: utils.c:252
BOOL APIENTRY Imm32IsCrossProcessAccess(HWND hWnd)
Definition: utils.c:34
HRESULT Imm32ActivateOrDeactivateTIM(_In_ BOOL bCreate)
Definition: ctf.c:895
DWORD APIENTRY Imm32ReconvertAnsiFromWide(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
Definition: utils.c:639
BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName)
Definition: utils.c:286
DWORD APIENTRY Imm32BuildHimcList(DWORD dwThreadId, HIMC **pphList)
Definition: utils.c:459
LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType)
Definition: utils.c:377
HRESULT CtfImmTIMDestroyInputContext(_In_ HIMC hIMC)
Definition: ctf.c:929
PIME_STATE APIENTRY Imm32FetchImeState(LPINPUTCONTEXTDX pIC, HKL hKL)
Definition: utils.c:500
SHAREDINFO gSharedInfo
Definition: imm.c:19
BOOL CtfImeProcessCicHotkey(_In_ HIMC hIMC, _In_ UINT vKey, _In_ LPARAM lParam)
Definition: msctfime.cpp:795
BOOL APIENTRY Imm32SaveImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
Definition: utils.c:556
HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff)
Definition: utils.c:56
PSERVERINFO gpsi
Definition: imm.c:18
LRESULT CtfImmSetLangBand(_In_ HWND hWnd, _In_ BOOL fSet)
Definition: ctf.c:1233
BOOL APIENTRY Imm32IsSystemJapaneseOrKorean(VOID)
Definition: utils.c:69
LPVOID ImmLocalAlloc(_In_ DWORD dwFlags, _In_ DWORD dwBytes)
Definition: utils.c:414
DWORD g_aimm_compat_flags
Definition: ctf.c:204
HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID)
Definition: utils.c:850
DWORD APIENTRY CandidateListWideToAnsi(const CANDIDATELIST *pWideCL, LPCANDIDATELIST pAnsiCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:14
HBITMAP Imm32LoadBitmapFromBytes(const BYTE *pb)
Definition: utils.c:88
BOOL APIENTRY Imm32LoadImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
Definition: utils.c:544
LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage)
Definition: utils.c:273
BOOL APIENTRY Imm32ReleaseIME(HKL hKL)
Definition: ime.c:371
LPWSTR APIENTRY Imm32WideFromAnsi(UINT uCodePage, LPCSTR pszA)
Definition: utils.c:227
DWORD APIENTRY Imm32ReconvertWideFromAnsi(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
Definition: utils.c:576
DWORD dwThreadId
Definition: fdebug.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
static HBITMAP
Definition: button.c:44
static HANDLE ULONG_PTR dwData
Definition: file.c:35
UINT_PTR HKL
Definition: msctf.idl:143
unsigned int UINT
Definition: ndis.h:50
#define _In_
Definition: no_sal2.h:158
#define FASTCALL
Definition: nt_native.h:50
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
_In_ int _In_ BOOL bCreate
Definition: shlobj.h:1528
WCHAR szFileName[80]
Definition: precomp.h:96
HKL hKL
Definition: precomp.h:94
WCHAR szImeKey[20]
Definition: precomp.h:95
Definition: ntuser.h:199
uint32_t DWORD_PTR
Definition: typedefs.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4246
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193