xref: /reactos/dll/win32/imm32/precomp.h (revision 931224fb)
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 <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 {
67     HKL hKL;
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;
73 extern RTL_CRITICAL_SECTION gcsImeDpi;
74 extern PIMEDPI gpImeDpiList;
75 extern PSERVERINFO gpsi;
76 extern SHAREDINFO gSharedInfo;
77 extern HANDLE ghImmHeap;
78 extern DWORD g_aimm_compat_flags;
79 
80 BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName);
81 VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW);
82 VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA);
83 LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType);
84 LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType);
85 #define ValidateHwndNoErr(hwnd) ValidateHandleNoErr((hwnd), TYPE_WINDOW)
86 #define ValidateHwnd(hwnd) ValidateHandle((hwnd), TYPE_WINDOW)
87 BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC);
88 
89 LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes);
90 #define ImmLocalFree(lpData) HeapFree(ghImmHeap, 0, (lpData))
91 
92 LPWSTR APIENTRY Imm32WideFromAnsi(UINT uCodePage, LPCSTR pszA);
93 LPSTR APIENTRY Imm32AnsiFromWide(UINT uCodePage, LPCWSTR pszW);
94 LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage);
95 LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage);
96 PIMEDPI APIENTRY Imm32FindOrLoadImeDpi(HKL hKL);
97 LPINPUTCONTEXT APIENTRY Imm32InternalLockIMC(HIMC hIMC, BOOL fSelect);
98 BOOL APIENTRY Imm32ReleaseIME(HKL hKL);
99 BOOL APIENTRY Imm32IsSystemJapaneseOrKorean(VOID);
100 BOOL APIENTRY Imm32IsCrossThreadAccess(HIMC hIMC);
101 BOOL APIENTRY Imm32IsCrossProcessAccess(HWND hWnd);
102 BOOL WINAPI Imm32IsImcAnsi(HIMC hIMC);
103 
104 #if 0
105     #define UNEXPECTED() ASSERT(FALSE)
106 #else
107     #define UNEXPECTED() 0
108 #endif
109 
110 /*
111  * Unexpected Condition Checkers
112  * --- Examine the condition, and then generate trace log if necessary.
113  */
114 #ifdef NDEBUG /* on Release */
115 #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr))
116 #define IS_NULL_UNEXPECTEDLY(p) (!(p))
117 #define IS_ZERO_UNEXPECTEDLY(p) (!(p))
118 #define IS_TRUE_UNEXPECTEDLY(x) (x)
119 #define IS_FALSE_UNEXPECTEDLY(x) (!(x))
120 #define IS_ERROR_UNEXPECTEDLY(x) (!(x))
121 #else /* on Debug */
122 #define FAILED_UNEXPECTEDLY(hr) \
123     (FAILED(hr) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
124                    __FILE__, __FUNCTION__, __LINE__, "FAILED(%s)\n", #hr), UNEXPECTED(), TRUE) \
125                 : FALSE)
126 #define IS_NULL_UNEXPECTEDLY(p) \
127     (!(p) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
128                          __FILE__, __FUNCTION__, __LINE__, "%s was NULL\n", #p), UNEXPECTED(), TRUE) \
129           : FALSE)
130 #define IS_ZERO_UNEXPECTEDLY(p) \
131     (!(p) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
132                          __FILE__, __FUNCTION__, __LINE__, "%s was zero\n", #p), UNEXPECTED(), TRUE) \
133           : FALSE)
134 #define IS_TRUE_UNEXPECTEDLY(x) \
135     ((x) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
136                         __FILE__, __FUNCTION__, __LINE__, "%s was non-zero\n", #x), UNEXPECTED(), TRUE) \
137          : FALSE)
138 #define IS_FALSE_UNEXPECTEDLY(x) \
139     ((!(x)) ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
140                            __FILE__, __FUNCTION__, __LINE__, "%s was FALSE\n", #x), UNEXPECTED(), TRUE) \
141             : FALSE)
142 #define IS_ERROR_UNEXPECTEDLY(x) \
143     ((x) != ERROR_SUCCESS ? (ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, \
144                                           __FILE__, __FUNCTION__, __LINE__, \
145                                           "%s was 0x%X\n", #x, (x)), TRUE) \
146                           : FALSE)
147 #endif
148 
149 #define IS_CROSS_THREAD_HIMC(hIMC)     IS_TRUE_UNEXPECTEDLY(Imm32IsCrossThreadAccess(hIMC))
150 #define IS_CROSS_PROCESS_HWND(hWnd)    IS_TRUE_UNEXPECTEDLY(Imm32IsCrossProcessAccess(hWnd))
151 #define ImeDpi_IsUnicode(pImeDpi)      ((pImeDpi)->ImeInfo.fdwProperty & IME_PROP_UNICODE)
152 
153 DWORD APIENTRY
154 CandidateListWideToAnsi(const CANDIDATELIST *pWideCL, LPCANDIDATELIST pAnsiCL, DWORD dwBufLen,
155                         UINT uCodePage);
156 DWORD APIENTRY
157 CandidateListAnsiToWide(const CANDIDATELIST *pAnsiCL, LPCANDIDATELIST pWideCL, DWORD dwBufLen,
158                         UINT uCodePage);
159 
160 BOOL APIENTRY
161 Imm32MakeIMENotify(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue,
162                    DWORD_PTR dwCommand, DWORD_PTR dwData);
163 
164 DWORD APIENTRY Imm32BuildHimcList(DWORD dwThreadId, HIMC **pphList);
165 
166 INT APIENTRY
167 Imm32ImeMenuAnsiToWide(const IMEMENUITEMINFOA *pItemA, LPIMEMENUITEMINFOW pItemW,
168                        UINT uCodePage, BOOL bBitmap);
169 INT APIENTRY
170 Imm32ImeMenuWideToAnsi(const IMEMENUITEMINFOW *pItemW, LPIMEMENUITEMINFOA pItemA,
171                        UINT uCodePage);
172 
173 PIME_STATE APIENTRY Imm32FetchImeState(LPINPUTCONTEXTDX pIC, HKL hKL);
174 PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL);
175 
176 BOOL APIENTRY
177 Imm32LoadImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL);
178 BOOL APIENTRY
179 Imm32SaveImeStateSentence(LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL);
180 
181 DWORD APIENTRY
182 Imm32ReconvertAnsiFromWide(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage);
183 DWORD APIENTRY
184 Imm32ReconvertWideFromAnsi(LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage);
185 
186 HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase);
187 HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff);
188 BOOL APIENTRY Imm32LoadImeVerInfo(PIMEINFOEX pImeInfoEx);
189 UINT APIENTRY Imm32GetImeLayout(PREG_IME pLayouts, UINT cLayouts);
190 BOOL APIENTRY Imm32WriteImeLayout(HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayoutText);
191 HKL APIENTRY Imm32AssignNewLayout(UINT cKLs, const REG_IME *pLayouts, WORD wLangID);
192 BOOL APIENTRY Imm32CopyImeFile(LPWSTR pszOldFile, LPCWSTR pszNewFile);
193 PTHREADINFO FASTCALL Imm32CurrentPti(VOID);
194 
195 HBITMAP Imm32LoadBitmapFromBytes(const BYTE *pb);
196 BOOL Imm32StoreBitmapToBytes(HBITMAP hbm, LPBYTE pbData, DWORD cbDataMax);
197 
198 HRESULT CtfImmTIMCreateInputContext(_In_ HIMC hIMC);
199 HRESULT CtfImmTIMDestroyInputContext(_In_ HIMC hIMC);
200 HRESULT CtfImmCoInitialize(VOID);
201 HRESULT CtfImeCreateThreadMgr(VOID);
202 HRESULT CtfImeDestroyThreadMgr(VOID);
203 HRESULT Imm32ActivateOrDeactivateTIM(_In_ BOOL bCreate);
204