ReactOS  0.4.15-dev-1184-g23e04ae
imm.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS user32.dll
4  * FILE: win32ss/user/user32/misc/imm.c
5  * PURPOSE: User32.dll Imm functions
6  * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7  * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
8  * UPDATE HISTORY:
9  * 01/27/2009 Created
10  */
11 
12 #include <user32.h>
13 #include <strsafe.h>
14 
16 
17 #define IMM_INIT_MAGIC 0x19650412
18 
21 
22 /* define stub functions */
23 #undef DEFINE_IMM_ENTRY
24 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
25  static type WINAPI IMMSTUB_##name params { IMM_RETURN_##retkind((type)retval); }
26 #include "immtable.h"
27 
29 /* initialize by stubs */
30 #undef DEFINE_IMM_ENTRY
31 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
32  IMMSTUB_##name,
33 #include "immtable.h"
34 };
35 
37 {
38  UINT length;
39  STRSAFE_LPWSTR Safe = lpBuffer;
40 
42  if ( length && length < uSize )
43  {
44  StringCchCatW(Safe, uSize, L"\\");
45  return StringCchCatW(Safe, uSize, L"imm32.dll");
46  }
47  return StringCchCopyW(Safe, uSize, L"imm32.dll");
48 }
49 
50 /*
51  * @unimplemented
52  */
54 {
55  WCHAR ImmFile[MAX_PATH];
56  HMODULE imm32 = ghImm32;
57 
58  GetImmFileName(ImmFile, sizeof(ImmFile));
59  TRACE("File %ws\n",ImmFile);
60 
61  if (imm32 == NULL)
62  {
63  imm32 = GetModuleHandleW(ImmFile);
64  }
65 
66  if (imm32 == NULL)
67  {
68  imm32 = ghImm32 = LoadLibraryW(ImmFile);
69  if (imm32 == NULL)
70  {
71  ERR("Did not load!\n");
72  return FALSE;
73  }
74  return TRUE;
75  }
76 
77 /* load imm procedures */
78 #undef DEFINE_IMM_ENTRY
79 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
80  do { \
81  FN_##name proc = (FN_##name)GetProcAddress(imm32, #name); \
82  if (proc) { \
83  IMM_FN(name) = proc; \
84  } \
85  } while (0);
86 #include "immtable.h"
87 
88  return TRUE;
89 }
90 
92 {
95 }
96 
98 {
99  TRACE("Imm (%x)\n", magic);
100 
101  if (magic != IMM_INIT_MAGIC)
102  return FALSE;
103 
104  if (IMM_FN(ImmIsIME) != IMMSTUB_ImmIsIME)
105  return TRUE;
106 
108 
109  if (ghImm32 == NULL && !bImmInitializing)
110  {
111  WCHAR ImmFile[MAX_PATH];
112  GetImmFileName(ImmFile, sizeof(ImmFile));
113  ghImm32 = LoadLibraryW(ImmFile);
114  if (ghImm32 == NULL)
115  {
116  ERR("Did not load! 2\n");
117  return FALSE;
118  }
119  }
120 
121  return TRUE;
122 }
123 
125 {
126  PWND pWnd;
127  PIMEUI pimeui;
128 
129  pWnd = ValidateHwnd(hwnd);
130  if (pWnd)
131  {
132  if (!pWnd->fnid)
133  {
134  if (msg != WM_NCCREATE)
135  {
136  if (unicode)
137  return DefWindowProcW(hwnd, msg, wParam, lParam);
138  return DefWindowProcA(hwnd, msg, wParam, lParam);
139  }
141  pimeui = HeapAlloc( GetProcessHeap(), 0, sizeof(IMEUI) );
142  SetWindowLongPtrW(hwnd, 0, (LONG_PTR)pimeui);
143  }
144  else
145  {
146  if (pWnd->fnid != FNID_IME)
147  {
148  ERR("Wrong window class for Ime! fnId 0x%x\n",pWnd->fnid);
149  return 0;
150  }
151  pimeui = ((PIMEWND)pWnd)->pimeui;
152  if (pimeui == NULL)
153  {
154  ERR("Window is not set to IME!\n");
155  return 0;
156  }
157  }
158  }
159 
160  if (msg==WM_CREATE || msg==WM_NCCREATE)
161  return TRUE;
162 
163  if (msg==WM_NCDESTROY)
164  {
165  HeapFree( GetProcessHeap(), 0, pimeui );
166  SetWindowLongPtrW(hwnd, 0, 0);
168  }
169 
170  if (unicode)
171  return DefWindowProcW(hwnd, msg, wParam, lParam);
172  return DefWindowProcA(hwnd, msg, wParam, lParam);
173 }
174 
176 {
178 }
179 
181 {
183 }
184 
185 BOOL
186 WINAPI
188 {
190  if ( Ret )
191  {
192  if ( gpsi->dwSRVIFlags & SRVINFO_IMM32 )
193  {
194  HMODULE imm32 = GetModuleHandleW(L"imm32.dll");
195  if ( !imm32 )
196  {
197  imm32 = LoadLibraryW(L"imm32.dll");
198  if (!imm32)
199  {
200  ERR("UPUIE: Imm32 not installed!\n");
201  Ret = FALSE;
202  }
203  }
204  }
205  }
206  return Ret;
207 }
208 
209 static const WCHAR imeW[] = {'I','M','E',0};
210 
211 BOOL
212 WINAPI
214 {
216  ATOM atom;
217 
218  ZeroMemory(&WndClass, sizeof(WndClass));
219 
220  WndClass.cbSize = sizeof(WndClass);
221  WndClass.lpszClassName = imeW;
222  WndClass.style = CS_GLOBALCLASS;
223  WndClass.lpfnWndProc = ImeWndProcW;
224  WndClass.cbWndExtra = sizeof(LONG_PTR);
225  WndClass.hCursor = LoadCursorW(NULL, IDC_ARROW);
226 
227  atom = RegisterClassExWOWW( &WndClass,
228  0,
229  FNID_IME,
230  0,
231  FALSE);
232  if (atom)
233  {
235  TRACE("Register IME Class!\n");
236  return TRUE;
237  }
238  ERR("Failed to register IME Class!\n");
239  return FALSE;
240 }
241 
242 /*
243  * @unimplemented
244  */
245 BOOL WINAPI CliImmSetHotKey(DWORD dwID, UINT uModifiers, UINT uVirtualKey, HKL hKl)
246 {
248  return FALSE;
249 }
250 
251 /*
252  * @implemented
253  */
254 BOOL
255 WINAPI
257 {
258  return IMM_FN(ImmIMPSetIMEW)(hwnd, ime);
259 }
260 
261 /*
262  * @implemented
263  */
264 BOOL
265 WINAPI
267 {
268  return IMM_FN(ImmIMPQueryIMEW)(ime);
269 }
270 
271 /*
272  * @implemented
273  */
274 BOOL
275 WINAPI
277 {
278  return IMM_FN(ImmIMPGetIMEW)(hwnd, ime);
279 }
280 
281 /*
282  * @implemented
283  */
284 BOOL
285 WINAPI
287 {
288  return IMM_FN(ImmIMPSetIMEA)(hwnd, ime);
289 }
290 
291 /*
292  * @implemented
293  */
294 BOOL
295 WINAPI
297 {
298  return IMM_FN(ImmIMPQueryIMEA)(ime);
299 }
300 
301 /*
302  * @implemented
303  */
304 BOOL
305 WINAPI
307 {
308  return IMM_FN(ImmIMPGetIMEA)(hwnd, ime);
309 }
310 
311 /*
312  * @implemented
313  */
314 LRESULT
315 WINAPI
317 {
318  return IMM_FN(ImmSendIMEMessageExW)(hwnd, lParam);
319 }
320 
321 /*
322  * @implemented
323  */
324 LRESULT
325 WINAPI
327 {
328  return IMM_FN(ImmSendIMEMessageExA)(hwnd, lParam);
329 }
330 
331 /*
332  * @implemented
333  */
334 BOOL
335 WINAPI
337 {
338  return IMM_FN(ImmWINNLSEnableIME)(hwnd, enable);
339 }
340 
341 /*
342  * @implemented
343  */
344 BOOL
345 WINAPI
347 {
348  return IMM_FN(ImmWINNLSGetEnableStatus)(hwnd);
349 }
350 
351 /*
352  * @implemented
353  */
354 UINT
355 WINAPI
357 {
358  return FALSE;
359 }
UINT WINAPI WINNLSGetIMEHotkey(HWND hwnd)
Definition: imm.c:356
HRESULT WINAPI GetImmFileName(PWSTR lpBuffer, UINT uSize)
Definition: imm.c:36
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define LONG_PTR
Definition: treelist.c:79
BOOL WINAPI CliImmSetHotKey(DWORD dwID, UINT uModifiers, UINT uVirtualKey, HKL hKl)
Definition: imm.c:245
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI IMPGetIMEA(HWND hwnd, LPIMEPROA ime)
Definition: imm.c:306
u32_t magic(void)
LRESULT WINAPI ImeWndProcW(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: imm.c:180
#define ZeroMemory
Definition: winbase.h:1648
BOOL WINAPI WINNLSEnableIME(HWND hwnd, BOOL enable)
Definition: imm.c:336
UINT_PTR WPARAM
Definition: windef.h:207
wchar_t * STRSAFE_LPWSTR
Definition: ntstrsafe.h:53
BOOL WINAPI IMPSetIMEW(HWND hwnd, LPIMEPROW ime)
Definition: imm.c:256
LRESULT WINAPI ImeWndProc_common(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
Definition: imm.c:124
#define FNID_DESTROY
Definition: ntuser.h:859
#define WM_NCCREATE
Definition: winuser.h:1665
PSERVERINFO gpsi
Definition: main.c:27
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI SendIMEMessageExA(HWND hwnd, LPARAM lParam)
Definition: imm.c:326
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
ATOM WINAPI RegisterClassExWOWW(WNDCLASSEXW *, LPDWORD, WORD, DWORD, BOOL)
Definition: class.c:1411
BOOL WINAPI ImmIsIME(HKL hKL)
Definition: imm.c:2143
#define FALSE
Definition: types.h:117
DWORD dwSRVIFlags
Definition: ntuser.h:1004
DWORD fnid
Definition: ntuser.h:673
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define LoadLibraryW(x)
Definition: compat.h:495
static const WCHAR imeW[]
Definition: imm.c:209
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI User32InitializeImmEntryTable(DWORD)
Definition: imm.c:97
BOOL WINAPI InitializeImmEntryTable(VOID)
Definition: imm.c:91
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI IMPGetIMEW(HWND hwnd, LPIMEPROW ime)
Definition: imm.c:276
LRESULT WINAPI ImeWndProcA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: imm.c:175
BOOL WINAPI IntInitializeImmEntryTable(VOID)
Definition: imm.c:53
Imm32ApiTable gImmApiEntries
Definition: imm.c:28
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define CS_GLOBALCLASS
Definition: winuser.h:647
#define WM_NCDESTROY
Definition: winuser.h:1666
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define ICLS_IME
Definition: ntuser.h:888
static const WCHAR L[]
Definition: oid.c:1250
PWND FASTCALL ValidateHwnd(HWND hwnd)
Definition: misc.c:369
WINE_DEFAULT_DEBUG_CHANNEL(imm)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
UINT_PTR HKL
Definition: msctf.idl:101
DWORD_PTR NTAPI NtUserCallNoParam(DWORD Routine)
Definition: simplecall.c:59
BOOL WINAPI IMPQueryIMEW(LPIMEPROW ime)
Definition: imm.c:266
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:657
HINSTANCE ghImm32
Definition: imm.c:19
struct _IMEWND * PIMEWND
BOOL WINAPI WINNLSGetEnableStatus(HWND hwnd)
Definition: imm.c:346
GLboolean enable
Definition: glext.h:11120
BOOL WINAPI IMPQueryIMEA(LPIMEPROA ime)
Definition: imm.c:296
BOOL WINAPI RegisterIMEClass(VOID)
Definition: imm.c:213
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI UpdatePerUserImmEnabling(VOID)
Definition: imm.c:187
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
BOOL WINAPI IMPSetIMEA(HWND hwnd, LPIMEPROA ime)
Definition: imm.c:286
#define WM_CREATE
Definition: winuser.h:1590
#define SRVINFO_IMM32
Definition: ntuser.h:910
BOOL bImmInitializing
Definition: imm.c:20
#define ICLASS_TO_MASK(iCls)
Definition: ntuser.h:863
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define UNIMPLEMENTED
Definition: debug.h:115
BOOL NTAPI NtUserSetWindowFNID(HWND hWnd, WORD fnID)
Definition: window.c:4069
LRESULT WINAPI SendIMEMessageExW(HWND hwnd, LPARAM lParam)
Definition: imm.c:316
#define IMM_INIT_MAGIC
Definition: imm.c:17
#define SetWindowLongPtrW
Definition: winuser.h:5321
DWORD RegisterDefaultClasses
Definition: regcontrol.c:13
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
#define HeapFree(x, y, z)
Definition: compat.h:483
WCHAR WndClass[]
Definition: capicon.c:23
#define FNID_IME
Definition: ntuser.h:836
#define IMM_FN(name)
Definition: user32p.h:57