ReactOS  0.4.15-dev-3440-g915569a
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 
19 /* Is != NULL when we have loaded the IMM ourselves */
21 
23 
24 /* define stub functions */
25 #undef DEFINE_IMM_ENTRY
26 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
27  static type WINAPI IMMSTUB_##name params { IMM_RETURN_##retkind((type)retval); }
28 #include "immtable.h"
29 
31 /* initialize by stubs */
32 #undef DEFINE_IMM_ENTRY
33 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
34  IMMSTUB_##name,
35 #include "immtable.h"
36 };
37 
38 HRESULT
40  _In_ size_t cchBuffer)
41 {
43  if (length && length < cchBuffer)
44  {
46  return StringCchCatW(lpBuffer, cchBuffer, L"imm32.dll");
47  }
48  return StringCchCopyW(lpBuffer, cchBuffer, L"imm32.dll");
49 }
50 
51 /*
52  * @unimplemented
53  */
55 {
56  WCHAR ImmFile[MAX_PATH];
57  HMODULE imm32 = ghImm32;
58 
59  /* Check whether the IMM table has already been initialized */
60  if (IMM_FN(ImmWINNLSEnableIME) != IMMSTUB_ImmWINNLSEnableIME)
61  return TRUE;
62 
63  GetImmFileName(ImmFile, _countof(ImmFile));
64  TRACE("File %S\n", ImmFile);
65 
66  /* If IMM32 is already loaded, use it without increasing reference count. */
67  if (imm32 == NULL)
68  imm32 = GetModuleHandleW(ImmFile);
69 
70  /*
71  * Loading imm32.dll will call imm32!DllMain function.
72  * imm32!DllMain calls User32InitializeImmEntryTable.
73  * Thus, if imm32.dll was loaded, the table has been loaded.
74  */
75  if (imm32 == NULL)
76  {
77  imm32 = ghImm32 = LoadLibraryW(ImmFile);
78  if (imm32 == NULL)
79  {
80  ERR("Did not load imm32.dll!\n");
81  return FALSE;
82  }
83  return TRUE;
84  }
85 
86 /* load imm procedures */
87 #undef DEFINE_IMM_ENTRY
88 #define DEFINE_IMM_ENTRY(type, name, params, retval, retkind) \
89  do { \
90  FN_##name proc = (FN_##name)GetProcAddress(imm32, #name); \
91  if (!proc) { \
92  ERR("Could not load %s\n", #name); \
93  return FALSE; \
94  } \
95  IMM_FN(name) = proc; \
96  } while (0);
97 #include "immtable.h"
98 
99  return TRUE;
100 }
101 
103 {
106 }
107 
109 {
110  TRACE("Imm (%x)\n", magic);
111 
112  if (magic != IMM_INIT_MAGIC)
113  return FALSE;
114 
115  /* Check whether the IMM table has already been initialized */
116  if (IMM_FN(ImmWINNLSEnableIME) != IMMSTUB_ImmWINNLSEnableIME)
117  return TRUE;
118 
120 
121  if (ghImm32 == NULL && !bImmInitializing)
122  {
123  WCHAR ImmFile[MAX_PATH];
124  GetImmFileName(ImmFile, _countof(ImmFile));
125  ghImm32 = LoadLibraryW(ImmFile);
126  if (ghImm32 == NULL)
127  {
128  ERR("Did not load imm32.dll!\n");
129  return FALSE;
130  }
131  }
132 
134 }
135 
137 {
138  PWND pWnd;
139  PIMEUI pimeui;
140 
141  pWnd = ValidateHwnd(hwnd);
142  if (pWnd)
143  {
144  if (!pWnd->fnid)
145  {
146  if (msg != WM_NCCREATE)
147  {
148  if (unicode)
149  return DefWindowProcW(hwnd, msg, wParam, lParam);
150  return DefWindowProcA(hwnd, msg, wParam, lParam);
151  }
153  pimeui = HeapAlloc( GetProcessHeap(), 0, sizeof(IMEUI) );
154  SetWindowLongPtrW(hwnd, 0, (LONG_PTR)pimeui);
155  }
156  else
157  {
158  if (pWnd->fnid != FNID_IME)
159  {
160  ERR("Wrong window class for Ime! fnId 0x%x\n",pWnd->fnid);
161  return 0;
162  }
163  pimeui = ((PIMEWND)pWnd)->pimeui;
164  if (pimeui == NULL)
165  {
166  ERR("Window is not set to IME!\n");
167  return 0;
168  }
169  }
170  }
171 
172  if (msg==WM_CREATE || msg==WM_NCCREATE)
173  return TRUE;
174 
175  if (msg==WM_NCDESTROY)
176  {
177  HeapFree( GetProcessHeap(), 0, pimeui );
178  SetWindowLongPtrW(hwnd, 0, 0);
180  }
181 
182  if (unicode)
183  return DefWindowProcW(hwnd, msg, wParam, lParam);
184  return DefWindowProcA(hwnd, msg, wParam, lParam);
185 }
186 
188 {
190 }
191 
193 {
195 }
196 
197 BOOL
198 WINAPI
200 {
202  if ( Ret )
203  {
204  if ( gpsi->dwSRVIFlags & SRVINFO_IMM32 )
205  {
206  HMODULE imm32 = GetModuleHandleW(L"imm32.dll");
207  if ( !imm32 )
208  {
209  imm32 = LoadLibraryW(L"imm32.dll");
210  if (!imm32)
211  {
212  ERR("UPUIE: Imm32 not installed!\n");
213  Ret = FALSE;
214  }
215  }
216  }
217  }
218  return Ret;
219 }
220 
221 static const WCHAR imeW[] = {'I','M','E',0};
222 
223 BOOL
224 WINAPI
226 {
228  ATOM atom;
229 
230  ZeroMemory(&WndClass, sizeof(WndClass));
231 
232  WndClass.cbSize = sizeof(WndClass);
233  WndClass.lpszClassName = imeW;
234  WndClass.style = CS_GLOBALCLASS;
235  WndClass.lpfnWndProc = ImeWndProcW;
236  WndClass.cbWndExtra = sizeof(LONG_PTR);
237  WndClass.hCursor = LoadCursorW(NULL, IDC_ARROW);
238 
239  atom = RegisterClassExWOWW( &WndClass,
240  0,
241  FNID_IME,
242  0,
243  FALSE);
244  if (atom)
245  {
247  TRACE("Register IME Class!\n");
248  return TRUE;
249  }
250  ERR("Failed to register IME Class!\n");
251  return FALSE;
252 }
253 
254 /*
255  * @unimplemented
256  */
257 BOOL WINAPI CliImmSetHotKey(DWORD dwID, UINT uModifiers, UINT uVirtualKey, HKL hKl)
258 {
260  return FALSE;
261 }
262 
263 /*
264  * @implemented
265  */
266 BOOL
267 WINAPI
269 {
270  return IMM_FN(ImmIMPSetIMEW)(hwnd, ime);
271 }
272 
273 /*
274  * @implemented
275  */
276 BOOL
277 WINAPI
279 {
280  return IMM_FN(ImmIMPQueryIMEW)(ime);
281 }
282 
283 /*
284  * @implemented
285  */
286 BOOL
287 WINAPI
289 {
290  return IMM_FN(ImmIMPGetIMEW)(hwnd, ime);
291 }
292 
293 /*
294  * @implemented
295  */
296 BOOL
297 WINAPI
299 {
300  return IMM_FN(ImmIMPSetIMEA)(hwnd, ime);
301 }
302 
303 /*
304  * @implemented
305  */
306 BOOL
307 WINAPI
309 {
310  return IMM_FN(ImmIMPQueryIMEA)(ime);
311 }
312 
313 /*
314  * @implemented
315  */
316 BOOL
317 WINAPI
319 {
320  return IMM_FN(ImmIMPGetIMEA)(hwnd, ime);
321 }
322 
323 /*
324  * @implemented
325  */
326 LRESULT
327 WINAPI
329 {
331 }
332 
333 /*
334  * @implemented
335  */
336 LRESULT
337 WINAPI
339 {
341 }
342 
343 /*
344  * @implemented
345  */
346 BOOL
347 WINAPI
349 {
350  return IMM_FN(ImmWINNLSEnableIME)(hwnd, enable);
351 }
352 
353 /*
354  * @implemented
355  */
356 BOOL
357 WINAPI
359 {
360  return IMM_FN(ImmWINNLSGetEnableStatus)(hwnd);
361 }
362 
363 /*
364  * @implemented
365  */
366 UINT
367 WINAPI
369 {
370  return FALSE;
371 }
UINT WINAPI WINNLSGetIMEHotkey(HWND hwnd)
Definition: imm.c:368
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:257
HRESULT GetImmFileName(_Out_ LPWSTR lpBuffer, _In_ size_t cchBuffer)
Definition: imm.c:39
#define _Out_
Definition: ms_sal.h:345
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
BOOL WINAPI IMPGetIMEA(HWND hwnd, LPIMEPROA ime)
Definition: imm.c:318
u32_t magic(void)
LRESULT WINAPI ImeWndProcW(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: imm.c:192
#define ZeroMemory
Definition: winbase.h:1664
BOOL WINAPI WINNLSEnableIME(HWND hwnd, BOOL enable)
Definition: imm.c:348
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI IMPSetIMEW(HWND hwnd, LPIMEPROW ime)
Definition: imm.c:268
LRESULT WINAPI ImeWndProc_common(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
Definition: imm.c:136
WORD WINAPI ImmSendIMEMessageExA(HWND hWnd, LPARAM lParam)
Definition: win3.c:210
#define FNID_DESTROY
Definition: ntuser.h:868
#define WM_NCCREATE
Definition: winuser.h:1670
PSERVERINFO gpsi
Definition: main.c:27
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI ImmRegisterClient(PSHAREDINFO ptr, HINSTANCE hMod)
Definition: imm.c:44
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI SendIMEMessageExA(HWND hwnd, LPARAM lParam)
Definition: imm.c:338
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:1413
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
DWORD dwSRVIFlags
Definition: ntuser.h:1013
DWORD fnid
Definition: ntuser.h:679
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI ImmIMPQueryIMEW(LPIMEPROW pImePro)
Definition: utils.c:1034
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
static DWORD cchBuffer
Definition: fusion.c:85
BOOL WINAPI ImmIMPSetIMEA(HWND hWnd, LPIMEPROA pImePro)
Definition: utils.c:1043
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define LoadLibraryW(x)
Definition: compat.h:606
static const WCHAR imeW[]
Definition: imm.c:221
BOOL WINAPI User32InitializeImmEntryTable(DWORD)
Definition: imm.c:108
#define _In_
Definition: ms_sal.h:308
BOOL WINAPI InitializeImmEntryTable(VOID)
Definition: imm.c:102
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI IMPGetIMEW(HWND hwnd, LPIMEPROW ime)
Definition: imm.c:288
LRESULT WINAPI ImeWndProcA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: imm.c:187
Imm32ApiTable gImmApiEntries
Definition: imm.c:30
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define CS_GLOBALCLASS
Definition: winuser.h:647
#define WM_NCDESTROY
Definition: winuser.h:1671
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
BOOL WINAPI ImmIMPGetIMEW(HWND hWnd, LPIMEPROW pImePro)
Definition: utils.c:1016
unsigned long DWORD
Definition: ntddk_ex.h:95
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
WORD WINAPI ImmSendIMEMessageExW(HWND hWnd, LPARAM lParam)
Definition: win3.c:219
#define ICLS_IME
Definition: ntuser.h:897
PWND FASTCALL ValidateHwnd(HWND hwnd)
Definition: misc.c:359
BOOL WINAPI ImmIMPSetIMEW(HWND hWnd, LPIMEPROW pImePro)
Definition: utils.c:1052
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:278
static BOOL IntInitializeImmEntryTable(VOID)
Definition: imm.c:54
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:663
HINSTANCE ghImm32
Definition: imm.c:20
struct _IMEWND * PIMEWND
BOOL WINAPI WINNLSGetEnableStatus(HWND hwnd)
Definition: imm.c:358
GLboolean enable
Definition: glext.h:11120
BOOL WINAPI IMPQueryIMEA(LPIMEPROA ime)
Definition: imm.c:308
BOOL WINAPI RegisterIMEClass(VOID)
Definition: imm.c:225
SHAREDINFO gSharedInfo
Definition: dllmain.c:30
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
#define NULL
Definition: types.h:112
BOOL WINAPI UpdatePerUserImmEnabling(VOID)
Definition: imm.c:199
BOOL WINAPI ImmIMPQueryIMEA(LPIMEPROA pImePro)
Definition: utils.c:1025
#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:298
#define WM_CREATE
Definition: winuser.h:1595
#define SRVINFO_IMM32
Definition: ntuser.h:919
BOOL WINAPI ImmIMPGetIMEA(HWND hWnd, LPIMEPROA pImePro)
Definition: utils.c:1007
BOOL bImmInitializing
Definition: imm.c:22
#define ICLASS_TO_MASK(iCls)
Definition: ntuser.h:872
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:4084
LRESULT WINAPI SendIMEMessageExW(HWND hwnd, LPARAM lParam)
Definition: imm.c:328
#define IMM_INIT_MAGIC
Definition: imm.c:17
#define SetWindowLongPtrW
Definition: winuser.h:5326
DWORD RegisterDefaultClasses
Definition: regcontrol.c:13
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
#define HeapFree(x, y, z)
Definition: compat.h:594
WCHAR WndClass[]
Definition: capicon.c:23
#define FNID_IME
Definition: ntuser.h:844
#define IMM_FN(name)
Definition: user32p.h:56