2 * Implementation of the 'IME window' class
4 * Copyright 2000 Hidenori Takeshima
8 * - handle all messages.
9 * - handle all notifications.
21 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(imm);
24 #include "imm_private.h"
26 #define IMM32_CONVERSION_BUFSIZE 200
28 static CHAR IMM32_szIMEClass[] = "IME";
29 static CHAR IMM32_szIMEWindowName[] = "Default IME";
38 CHAR A[IMM32_CONVERSION_BUFSIZE];
39 WCHAR W[IMM32_CONVERSION_BUFSIZE];
44 static BOOL IMM32_IsUIMessage( UINT nMsg );
47 LRESULT IMM32_IMEWnd_WM_KEYDOWN( IMM32_IMEWNDPARAM* pParam,
48 WPARAM wParam, LPARAM lParam )
50 BYTE bKeyState[ 256 ];
56 const IMM32_IMEKL* pkl;
58 if ( pParam->hwndActive == (HWND)NULL )
61 /* get context -> get pkl. */
62 hIMC = ImmGetContext( pParam->hwndActive );
63 if ( hIMC == NULLIMC )
65 pIMC = IMM32_LockIMC( hIMC );
68 ImmReleaseContext( pParam->hwndActive, hIMC );
73 GetKeyboardState( bKeyState );
74 if ( !pkl->handlers.pImeProcessKey
75 ( hIMC, wParam, lParam, bKeyState ) )
77 lr = SendMessageA( pParam->hwndActive, WM_IME_KEYDOWN,
83 nNumOfMsg = pkl->handlers.pImeToAsciiEx
84 ( wParam, (lParam>>16)&0xff,
85 bKeyState, &dwTransBufSize,
86 0, /* FIXME!!! - 1 if a menu is active */
89 /* FIXME - process generated messages */
90 /* I cannot use ImmGenerateMessage() since
91 * the IME window must handle generated messages. */
93 /* NOTE - I must check pkl->fUnicode. */
94 FIXME( "%d messages generated.\n", nNumOfMsg );
98 IMM32_UnlockIMC( hIMC );
99 ImmReleaseContext( pParam->hwndActive, hIMC );
105 LRESULT IMM32_IMEWnd_WM_KEYUP( IMM32_IMEWNDPARAM* pParam,
106 WPARAM wParam, LPARAM lParam )
108 BYTE bKeyState[ 256 ];
112 const IMM32_IMEKL* pkl;
114 if ( pParam->hwndActive == (HWND)NULL )
117 /* get context -> get pkl. */
118 hIMC = ImmGetContext( pParam->hwndActive );
119 if ( hIMC == NULLIMC )
121 pIMC = IMM32_LockIMC( hIMC );
124 ImmReleaseContext( pParam->hwndActive, hIMC );
129 GetKeyboardState( bKeyState );
130 if ( !pkl->handlers.pImeProcessKey
131 ( hIMC, wParam, lParam, bKeyState ) )
133 lr = SendMessageA( pParam->hwndActive, WM_IME_KEYUP,
140 IMM32_UnlockIMC( hIMC );
141 ImmReleaseContext( pParam->hwndActive, hIMC );
148 LRESULT CALLBACK IMM32_IMEWndProc( HWND hwnd, UINT nMsg,
149 WPARAM wParam, LPARAM lParam )
151 IMM32_IMEWNDPARAM* pParam =
152 (IMM32_IMEWNDPARAM*)GetWindowLongA( hwnd, 0L );
154 if ( nMsg == WM_CREATE )
156 pParam = (IMM32_IMEWNDPARAM*)IMM32_HeapAlloc(
157 HEAP_ZERO_MEMORY, sizeof(IMM32_IMEWNDPARAM) );
158 if ( pParam == NULL )
160 SetWindowLongA( hwnd, 0L, (LONG)pParam );
162 /* Initialize pParam. */
163 pParam->hwndSelf = hwnd;
164 pParam->hwndActive = (HWND)NULL;
165 pParam->dwBufUsed = 0;
169 else if ( nMsg == WM_DESTROY )
171 /* Uninitialize pParam. */
173 IMM32_HeapFree( pParam );
174 SetWindowLongA( hwnd, 0L, (LONG)NULL );
178 if ( pParam == NULL )
180 if ( IMM32_IsUIMessage( nMsg ) )
182 return DefWindowProcA( hwnd, nMsg, wParam, lParam );
185 /* FIXME - handle all messages. */
186 /* FIXME - handle all notifications. */
190 return IMM32_IMEWnd_WM_KEYDOWN( pParam, wParam, lParam );
192 return IMM32_IMEWnd_WM_KEYUP( pParam, wParam, lParam );
194 ERR( "Why WM_IME_KEYDOWN is generated?" );
197 ERR( "Why WM_IME_KEYUP is generated?" );
200 FIXME( "ignore WM_IME_CHAR - wParam %08x, lParam %08lx.\n",
204 /* TranslateMessage don't support IME HKL. - FIXME? */
205 FIXME( "ignore WM_CHAR - wParam %08x, lParam %08lx.\n",
210 case WM_IME_STARTCOMPOSITION:
211 case WM_IME_ENDCOMPOSITION:
212 case WM_IME_COMPOSITION:
213 case WM_IME_SETCONTEXT:
215 case WM_IME_COMPOSITIONFULL:
217 case 0x287: /* What is this message? IMM32.DLL returns TRUE. */
218 FIXME( "handle message %08x\n", nMsg );
222 return DefWindowProcA( hwnd, nMsg, wParam, lParam );
226 /***********************************************************************
227 * IMM32_RegisterClass (internal)
229 BOOL IMM32_RegisterIMEWndClass( HINSTANCE hInstDLL )
233 /* SDK says the "IME" window class is a system global class. */
234 wc.style = CS_GLOBALCLASS;
235 wc.lpfnWndProc = IMM32_IMEWndProc;
237 wc.cbWndExtra = sizeof(LONG);
238 wc.hInstance = hInstDLL;
239 wc.hIcon = (HICON)NULL;
240 wc.hCursor = LoadCursorA((HINSTANCE)NULL,IDC_ARROWA);
241 wc.hbrBackground = (HBRUSH)NULL;
242 wc.lpszMenuName = NULL;
243 wc.lpszClassName = IMM32_szIMEClass;
244 if ( !RegisterClassA( &wc ) )
250 /***********************************************************************
251 * IMM32_UnregisterClass (internal)
253 void IMM32_UnregisterIMEWndClass( HINSTANCE hInstDLL )
255 (void)UnregisterClassA( IMM32_szIMEClass, hInstDLL );
258 /***********************************************************************
259 * IMM32_CreateDefaultIMEWnd (internal)
262 HWND IMM32_CreateDefaultIMEWnd( void )
264 return CreateWindowExA( 0L,
266 IMM32_szIMEWindowName,
267 WS_POPUP | WS_CLIPSIBLINGS | WS_OVERLAPPED,
271 (HINSTANCE)GetModuleHandleA(NULL),
275 static BOOL IMM32_IsUIMessage( UINT nMsg )
279 case WM_IME_STARTCOMPOSITION:
280 case WM_IME_ENDCOMPOSITION:
281 case WM_IME_COMPOSITION:
282 case WM_IME_SETCONTEXT:
284 case WM_IME_COMPOSITIONFULL:
286 case 0x287: /* What is this message? IMM32.DLL returns TRUE. */
294 /***********************************************************************
295 * ImmIsUIMessageA (IMM32.@)
297 BOOL WINAPI ImmIsUIMessageA(
298 HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
300 TRACE("(0x%08x, %d, %d, %ld)\n",
301 hwndIME, msg, wParam, lParam);
303 if ( !IMM32_IsUIMessage( msg ) )
305 if ( hwndIME == (HWND)NULL )
310 case WM_IME_STARTCOMPOSITION:
311 case WM_IME_ENDCOMPOSITION:
312 case WM_IME_COMPOSITION:
313 case WM_IME_SETCONTEXT:
315 case WM_IME_COMPOSITIONFULL:
317 SendMessageA( hwndIME, msg, wParam, lParam );
319 case 0x287: /* What is this message? */
320 FIXME("(0x%08x, %d, %d, %ld) - unknown message 0x287.\n",
321 hwndIME, msg, wParam, lParam);
322 SendMessageA( hwndIME, msg, wParam, lParam );
329 /***********************************************************************
330 * ImmIsUIMessageW (IMM32.@)
332 BOOL WINAPI ImmIsUIMessageW(
333 HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
335 TRACE("(0x%08x, %d, %d, %ld)\n",
336 hwndIME, msg, wParam, lParam);
338 if ( !IMM32_IsUIMessage( msg ) )
340 if ( hwndIME == (HWND)NULL )
345 case WM_IME_STARTCOMPOSITION:
346 case WM_IME_ENDCOMPOSITION:
347 case WM_IME_COMPOSITION:
348 case WM_IME_SETCONTEXT:
350 case WM_IME_COMPOSITIONFULL:
352 SendMessageW( hwndIME, msg, wParam, lParam );
354 case 0x287: /* What is this message? */
355 FIXME("(0x%08x, %d, %d, %ld) - unknown message 0x287.\n",
356 hwndIME, msg, wParam, lParam);
357 SendMessageW( hwndIME, msg, wParam, lParam );