ReactOS  0.4.15-dev-4594-g505ac65
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-2021 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 <ddk/immdev.h>
31 
32 #define NTOS_MODE_USER
33 #include <ndk/umtypes.h>
34 #include <ndk/pstypes.h>
35 #include <ndk/rtlfuncs.h>
36 
37 /* Public Win32K Headers */
38 #include "ntuser.h"
39 #include "ntwin32.h"
40 
41 /* Undocumented user definitions */
42 #include <undocuser.h>
43 #include <imm32_undoc.h>
44 
45 #include <strsafe.h>
46 
47 #include <wine/debug.h>
48 #include <wine/list.h>
49 
50 #define IMM_INIT_MAGIC 0x19650412
51 #define IMM_INVALID_CANDFORM ULONG_MAX
52 #define INVALID_HOTKEY_ID 0xFFFFFFFF
53 #define MAX_CANDIDATEFORM 4
54 #define MAX_IMM_FILENAME 80
55 
56 #define LANGID_CHINESE_SIMPLIFIED MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)
57 #define LANGID_CHINESE_TRADITIONAL MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)
58 #define LANGID_JAPANESE MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)
59 
60 #define REGKEY_KEYBOARD_LAYOUTS L"System\\CurrentControlSet\\Control\\Keyboard Layouts"
61 #define REGKEY_IMM L"Software\\Microsoft\\Windows NT\\CurrentVersion\\IMM"
62 
63 #define ROUNDUP4(n) (((n) + 3) & ~3) /* DWORD alignment */
64 
65 typedef struct REG_IME
66 {
68  WCHAR szImeKey[20]; /* "E0XXYYYY": "E0XX" is the device handle. "YYYY" is a LANGID. */
69  WCHAR szFileName[80]; /* The IME module filename */
70 } REG_IME, *PREG_IME;
71 
72 extern HMODULE ghImm32Inst;
74 extern PIMEDPI gpImeDpiList;
75 extern PSERVERINFO gpsi;
76 extern SHAREDINFO gSharedInfo;
77 extern HANDLE ghImmHeap;
78 
83 LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType);
84 #define ValidateHwndNoErr(hwnd) ValidateHandleNoErr((hwnd), TYPE_WINDOW)
85 #define ValidateHwnd(hwnd) ValidateHandle((hwnd), TYPE_WINDOW)
87 
89 #define ImmLocalFree(lpData) HeapFree(ghImmHeap, 0, (lpData))
90 
93 LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage);
94 LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage);
99 
100 static inline BOOL Imm32IsCrossThreadAccess(HIMC hIMC)
101 {
102  DWORD dwImeThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
104  return (dwImeThreadId != dwThreadId);
105 }
106 
107 // Win: TestWindowProcess
109 {
112 }
113 
115 
116 #define ImeDpi_IsUnicode(pImeDpi) ((pImeDpi)->ImeInfo.fdwProperty & IME_PROP_UNICODE)
117 #define IS_IMM_MODE() (gpsi && (gpsi->dwSRVIFlags & SRVINFO_IMM32))
118 #define Imm32IsCiceroMode() (gpsi && (gpsi->dwSRVIFlags & SRVINFO_CICERO_ENABLED))
119 #define Imm32Is16BitMode() (GetWin32ClientInfo()->dwTIFlags & TIF_16BIT)
120 
123  UINT uCodePage);
126  UINT uCodePage);
127 
129 Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue,
130  DWORD_PTR dwCommand, DWORD_PTR dwData);
131 
133 
136  UINT uCodePage, BOOL bBitmap);
139  UINT uCodePage);
140 
143 
148 
153 
154 HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase);
155 HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff);
157 UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts);
158 BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayout);
159 HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID);
160 BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile);
161 
163 {
164  if (NtCurrentTeb()->Win32ThreadInfo == NULL)
166  return NtCurrentTeb()->Win32ThreadInfo;
167 }
HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff)
Definition: utils.c:33
PSERVERINFO gpsi
Definition: imm.c:17
#define QUERY_WINDOW_UNIQUE_PROCESS_ID
Definition: ntuser.h:2919
DWORD_PTR NTAPI NtUserGetThreadState(DWORD Routine)
Definition: misc.c:232
BOOL APIENTRY Imm32LoadImeVerInfo(PIMEINFOEX pImeInfoEx)
Definition: utils.c:642
DWORD APIENTRY Imm32ReconvertAnsiFromWide(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
Definition: utils.c:504
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
BOOL APIENTRY Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue, DWORD_PTR dwCommand, DWORD_PTR dwData)
Definition: utils.c:247
BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayout)
Definition: utils.c:811
VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW)
Definition: utils.c:132
BOOL APIENTRY Imm32LoadImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
Definition: utils.c:414
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:234
Definition: ntuser.h:190
HWND hWnd
Definition: settings.c:17
UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts)
Definition: utils.c:743
WCHAR szImeKey[20]
Definition: precomp.h:68
static HANDLE ULONG_PTR dwData
Definition: file.c:35
static PTHREADINFO FASTCALL Imm32CurrentPti(VOID)
Definition: precomp.h:162
char * LPSTR
Definition: xmlstorage.h:182
HANDLE UniqueProcess
Definition: compat.h:684
PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL)
Definition: utils.c:394
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4245
#define FASTCALL
Definition: nt_native.h:50
#define DWORD
Definition: nt_native.h:44
HKL hKL
Definition: precomp.h:67
int32_t INT
Definition: typedefs.h:58
DWORD APIENTRY Imm32ReconvertWideFromAnsi(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
Definition: utils.c:448
LPSTR APIENTRY Imm32AnsiFromWide(LPCWSTR pszW)
Definition: utils.c:76
INT APIENTRY Imm32ImeMenuAnsiToWide(const IMEMENUITEMINFOA *pItemA, LPIMEMENUITEMINFOW pItemW, UINT uCodePage, BOOL bBitmap)
Definition: utils.c:319
HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase)
Definition: utils.c:20
BOOL APIENTRY Imm32IsSystemJapaneseOrKorean(VOID)
Definition: utils.c:45
DWORD_PTR NTAPI NtUserQueryWindow(HWND hWnd, DWORD Index)
Definition: window.c:4172
PIME_STATE APIENTRY Imm32FetchImeState(LPINPUTCONTEXTDX pIC, HKL hKL)
Definition: utils.c:370
BOOL APIENTRY Imm32ReleaseIME(HKL hKL)
Definition: ime.c:311
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
BOOL WINAPI Imm32IsImcAnsi(HIMC hIMC)
Definition: utils.c:54
const char * LPCSTR
Definition: xmlstorage.h:183
DWORD HIMC
Definition: dimm.idl:75
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:459
HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID)
Definition: utils.c:697
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1165
LPINPUTCONTEXT APIENTRY Imm32InternalLockIMC(HIMC hIMC, BOOL fSelect)
Definition: imm.c:816
struct REG_IME REG_IME
DWORD APIENTRY Imm32BuildHimcList(DWORD dwThreadId, HIMC **pphList)
Definition: utils.c:279
LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
Definition: utils.c:171
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR szFileName[80]
Definition: precomp.h:69
LONG HRESULT
Definition: typedefs.h:79
DWORD_PTR NTAPI NtUserQueryInputContext(HIMC hIMC, DWORD dwType)
Definition: ime.c:1773
#define WINAPI
Definition: msvc.h:6
PIMEDPI APIENTRY Imm32FindOrLoadImeDpi(HKL hKL)
Definition: ime.c:285
unsigned short WORD
Definition: ntddk_ex.h:93
VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA)
Definition: utils.c:145
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile)
Definition: utils.c:908
RTL_CRITICAL_SECTION gcsImeDpi
Definition: ime.c:16
HMODULE ghImm32Inst
Definition: imm.c:16
static BOOL Imm32IsCrossThreadAccess(HIMC hIMC)
Definition: precomp.h:100
DWORD dwThreadId
Definition: fdebug.c:31
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
Definition: utils.c:89
LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage)
Definition: utils.c:109
UINT_PTR HKL
Definition: msctf.idl:101
uint32_t DWORD_PTR
Definition: typedefs.h:65
BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName)
Definition: utils.c:122
DWORD APIENTRY CandidateListAnsiToWide(const CANDIDATELIST *pAnsiCL, LPCANDIDATELIST pWideCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:84
SHAREDINFO gSharedInfo
Definition: imm.c:18
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
unsigned short USHORT
Definition: pedump.c:61
PIMEDPI gpImeDpiList
Definition: ime.c:17
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC)
Definition: utils.c:221
struct REG_IME * PREG_IME
HANDLE ghImmHeap
Definition: utils.c:16
uint32_t * LPDWORD
Definition: typedefs.h:59
unsigned int ULONG
Definition: retypes.h:1
BOOL APIENTRY Imm32SaveImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
Definition: utils.c:427
static BOOL Imm32IsCrossProcessAccess(HWND hWnd)
Definition: precomp.h:108
LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType)
Definition: utils.c:207
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
INT APIENTRY Imm32ImeMenuWideToAnsi(const IMEMENUITEMINFOW *pItemW, LPIMEMENUITEMINFOA pItemA, UINT uCodePage)
Definition: utils.c:346
LPWSTR APIENTRY Imm32WideFromAnsi(LPCSTR pszA)
Definition: utils.c:65
#define APIENTRY
Definition: api.h:79
DWORD APIENTRY CandidateListWideToAnsi(const CANDIDATELIST *pWideCL, LPCANDIDATELIST pAnsiCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:14