Fixed some issues found by winapi_check.
[wine] / dlls / imm32 / imewnd.c
1 /*
2  *      Implementation of the 'IME window' class
3  *
4  *      Copyright 2000 Hidenori Takeshima
5  *
6  *
7  * FIXME:
8  *      - handle all messages.
9  *      - handle all notifications.
10  */
11
12 #include "config.h"
13
14 #include "winbase.h"
15 #include "windef.h"
16 #include "wingdi.h"
17 #include "winuser.h"
18 #include "winerror.h"
19 #include "immddk.h"
20
21 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(imm);
23
24 #include "imm_private.h"
25
26 static CHAR IMM32_szIMEClass[] = "IME";
27
28 typedef struct
29 {
30         int dummy;
31 } IMM32_IMEWNDPARAM;
32
33
34 static BOOL IMM32_IsUIMessage( UINT nMsg );
35
36
37 static
38 LRESULT CALLBACK IMM32_IMEWndProc( HWND hwnd, UINT nMsg,
39                                    WPARAM wParam, LPARAM lParam )
40 {
41         IMM32_IMEWNDPARAM* pParam =
42                 (IMM32_IMEWNDPARAM*)GetWindowLongA( hwnd, 0L );
43
44         if ( nMsg == WM_CREATE )
45         {
46                 pParam = (IMM32_IMEWNDPARAM*)IMM32_HeapAlloc(
47                                 HEAP_ZERO_MEMORY, sizeof(IMM32_IMEWNDPARAM) );
48                 if ( pParam == NULL )
49                         return -1L;
50                 SetWindowLongA( hwnd, 0L, (LONG)pParam );
51
52                 /* FIXME - Initialize pParam. */
53
54                 return 0;
55         }
56         else if ( nMsg == WM_DESTROY )
57         {
58                 /* FIXME - Uninitialize pParam. */
59
60                 IMM32_HeapFree( pParam );
61                 SetWindowLongA( hwnd, 0L, (LONG)NULL );
62                 return 0;
63         }
64
65         if ( pParam == NULL )
66         {
67                 if ( IMM32_IsUIMessage( nMsg ) )
68                         return 0;
69                 return DefWindowProcA( hwnd, nMsg, wParam, lParam );
70         }
71
72         /* FIXME - handle all messages. */
73         /* FIXME - handle all notifications. */
74         if ( IMM32_IsUIMessage( nMsg ) )
75                 return 0;
76
77         return DefWindowProcA( hwnd, nMsg, wParam, lParam );
78 }
79
80
81 /***********************************************************************
82  *              IMM32_RegisterClass (internal)
83  */
84 BOOL IMM32_RegisterIMEWndClass( HINSTANCE hInstDLL )
85 {
86         WNDCLASSA       wc;
87
88         /* SDK says the "IME" window class is a system global class. */
89         wc.style                = CS_GLOBALCLASS;
90         wc.lpfnWndProc          = IMM32_IMEWndProc;
91         wc.cbClsExtra           = 0;
92         wc.cbWndExtra           = sizeof(LONG);
93         wc.hInstance            = hInstDLL;
94         wc.hIcon                = LoadIconA((HINSTANCE)NULL,IDI_APPLICATIONA);
95         wc.hCursor              = LoadCursorA((HINSTANCE)NULL,IDC_IBEAMA);
96         wc.hbrBackground        = (HBRUSH)(COLOR_WINDOW+1); /* FIXME? */
97         wc.lpszMenuName         = NULL;
98         wc.lpszClassName        = IMM32_szIMEClass;
99         if ( !RegisterClassA( &wc ) )
100                 return FALSE;
101
102         return TRUE;
103 }
104
105 /***********************************************************************
106  *              IMM32_UnregisterClass (internal)
107  */
108 void IMM32_UnregisterIMEWndClass( HINSTANCE hInstDLL )
109 {
110         (void)UnregisterClassA( IMM32_szIMEClass, hInstDLL );
111 }
112
113
114
115 static BOOL IMM32_IsUIMessage( UINT nMsg )
116 {
117         switch ( nMsg )
118         {
119         case WM_IME_STARTCOMPOSITION:
120         case WM_IME_ENDCOMPOSITION:
121         case WM_IME_COMPOSITION:
122         case WM_IME_SETCONTEXT:
123         case WM_IME_NOTIFY:
124         case WM_IME_COMPOSITIONFULL:
125         case WM_IME_SELECT:
126         case 0x287: /* What is this message? IMM32.DLL returns TRUE. */
127                 return TRUE;
128         }
129
130         return FALSE;
131 }
132
133
134 /***********************************************************************
135  *              ImmIsUIMessageA (IMM32.@)
136  */
137 BOOL WINAPI ImmIsUIMessageA(
138         HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
139 {
140         TRACE("(0x%08x, %d, %d, %ld)\n",
141               hwndIME, msg, wParam, lParam);
142
143         if ( !IMM32_IsUIMessage( msg ) )
144                 return FALSE;
145         if ( hwndIME == (HWND)NULL )
146                 return TRUE;
147
148         switch ( msg )
149         {
150         case WM_IME_STARTCOMPOSITION:
151         case WM_IME_ENDCOMPOSITION:
152         case WM_IME_COMPOSITION:
153         case WM_IME_SETCONTEXT:
154         case WM_IME_NOTIFY:
155         case WM_IME_COMPOSITIONFULL:
156         case WM_IME_SELECT:
157                 SendMessageA( hwndIME, msg, wParam, lParam );
158                 break;
159         case 0x287: /* What is this message? */
160                 FIXME("(0x%08x, %d, %d, %ld) - unknown message 0x287.\n",
161                       hwndIME, msg, wParam, lParam);
162                 SendMessageA( hwndIME, msg, wParam, lParam );
163                 break;
164         }
165
166         return TRUE;
167 }
168
169 /***********************************************************************
170  *              ImmIsUIMessageW (IMM32.@)
171  */
172 BOOL WINAPI ImmIsUIMessageW(
173         HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
174 {
175         TRACE("(0x%08x, %d, %d, %ld)\n",
176               hwndIME, msg, wParam, lParam);
177
178         if ( !IMM32_IsUIMessage( msg ) )
179                 return FALSE;
180         if ( hwndIME == (HWND)NULL )
181                 return TRUE;
182
183         switch ( msg )
184         {
185         case WM_IME_STARTCOMPOSITION:
186         case WM_IME_ENDCOMPOSITION:
187         case WM_IME_COMPOSITION:
188         case WM_IME_SETCONTEXT:
189         case WM_IME_NOTIFY:
190         case WM_IME_COMPOSITIONFULL:
191         case WM_IME_SELECT:
192                 SendMessageW( hwndIME, msg, wParam, lParam );
193                 break;
194         case 0x287: /* What is this message? */
195                 FIXME("(0x%08x, %d, %d, %ld) - unknown message 0x287.\n",
196                       hwndIME, msg, wParam, lParam);
197                 SendMessageW( hwndIME, msg, wParam, lParam );
198                 break;
199         }
200
201         return TRUE;
202 }