Optimized include/*.h: (recursively) include all headers needed by
[wine] / dlls / comctl32 / comboex.c
1 /*
2  * ComboBoxEx control
3  *
4  * Copyright 1998 Eric Kohl
5  *
6  * NOTES
7  *   This is just a dummy control. An author is needed! Any volunteers?
8  *   I will only improve this control once in a while.
9  *     Eric <ekohl@abo.rhein-zeitung.de>
10  *
11  * TODO:
12  *   - All messages.
13  *   - All notifications.
14  *
15  * FIXME:
16  *   - should include "combo.h" 
17  */
18
19 #include "commctrl.h"
20 #include "comboex.h"
21 #include "win.h"
22 #include "debug.h"
23
24 #define ID_CB_EDIT    1001
25
26 #define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)wndPtr->wExtra[0])
27
28
29 /* << COMBOEX_DeleteItem >> */
30
31
32 __inline__ static LRESULT
33 COMBOEX_GetComboControl (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
34 {
35     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
36
37     TRACE (comboex, "\n");
38
39     return (LRESULT)infoPtr->hwndCombo;
40 }
41
42
43 __inline__ static LRESULT
44 COMBOEX_GetEditControl (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
45 {
46     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
47
48     if ((wndPtr->dwStyle & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
49         return 0;
50
51     TRACE (comboex, "-- 0x%x\n", GetDlgItem32 (infoPtr->hwndCombo, ID_CB_EDIT));
52
53     return (LRESULT)GetDlgItem32 (infoPtr->hwndCombo, ID_CB_EDIT);
54 }
55
56
57 __inline__ static LRESULT
58 COMBOEX_GetExtendedStyle (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
59 {
60     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
61
62     return (LRESULT)infoPtr->dwExtStyle;
63 }
64
65
66 __inline__ static LRESULT
67 COMBOEX_GetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
68 {
69     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
70
71     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
72
73     return (LRESULT)infoPtr->himl;
74 }
75
76
77
78
79 static LRESULT
80 COMBOEX_InsertItem32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
81 {
82     /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr); */
83
84     FIXME (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
85
86     return -1;
87 }
88
89
90
91 static LRESULT
92 COMBOEX_SetExtendedStyle (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
93 {
94     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
95     DWORD dwTemp;
96
97     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
98
99     dwTemp = infoPtr->dwExtStyle;
100
101     if ((DWORD)wParam) {
102         infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
103     }
104     else
105         infoPtr->dwExtStyle = (DWORD)lParam;
106
107     /* FIXME: repaint?? */
108
109     return (LRESULT)dwTemp;
110 }
111
112
113 __inline__ static LRESULT
114 COMBOEX_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
115 {
116     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
117     HIMAGELIST himlTemp;
118
119     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
120
121     himlTemp = infoPtr->himl;
122     infoPtr->himl = (HIMAGELIST)lParam;
123
124     return (LRESULT)himlTemp;
125 }
126
127
128 static LRESULT
129 COMBOEX_SetItem32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
130 {
131     /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr); */
132
133     FIXME (comboex, "(%p): stub\n", (LPVOID)lParam);
134
135     return TRUE;
136 }
137
138
139 /* << COMBOEX_SetItem32W >> */
140
141
142 __inline__ static LRESULT
143 COMBOEX_Forward (WND *wndPtr, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
144 {
145     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
146
147     FIXME (comboex, "(0x%x 0x%x 0x%lx): stub\n", uMsg, wParam, lParam);
148
149     if (infoPtr->hwndCombo)    
150         return SendMessage32A (infoPtr->hwndCombo, uMsg, wParam, lParam);
151
152     return 0;
153 }
154
155
156 static LRESULT
157 COMBOEX_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
158 {
159     COMBOEX_INFO *infoPtr;
160     DWORD dwComboStyle;
161
162     /* allocate memory for info structure */
163     infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
164     wndPtr->wExtra[0] = (DWORD)infoPtr;
165
166     if (infoPtr == NULL) {
167         ERR (listview, "could not allocate info memory!\n");
168         return 0;
169     }
170
171     if ((COMBOEX_INFO*)wndPtr->wExtra[0] != infoPtr) {
172         ERR (listview, "pointer assignment error!\n");
173         return 0;
174     }
175
176
177     /* initialize info structure */
178
179
180     /* create combo box */
181     dwComboStyle = 
182         wndPtr->dwStyle & (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
183
184     infoPtr->hwndCombo =
185         CreateWindow32A ("ComboBox", "",
186                          WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
187                          0, 0, 0, 0, wndPtr->hwndSelf, (HMENU32)1,
188                          wndPtr->hInstance, NULL);
189
190
191     return 0;
192 }
193
194
195 static LRESULT
196 COMBOEX_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
197 {
198     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
199
200
201     if (infoPtr->hwndCombo)
202         DestroyWindow32 (infoPtr->hwndCombo);
203
204
205
206
207     /* free comboex info data */
208     COMCTL32_Free (infoPtr);
209
210     return 0;
211 }
212
213
214 static LRESULT
215 COMBOEX_Size (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
216 {
217     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
218     RECT32 rect;
219
220     GetClientRect32 (wndPtr->hwndSelf, &rect);
221
222     MoveWindow32 (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
223                   rect.bottom - rect.top, TRUE);
224
225     return 0;
226 }
227
228
229 LRESULT WINAPI
230 COMBOEX_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
231 {
232     WND *wndPtr = WIN_FindWndPtr(hwnd);
233
234     switch (uMsg)
235     {
236 /*      case CBEM_DELETEITEM: */
237
238         case CBEM_GETCOMBOCONTROL:
239             return COMBOEX_GetComboControl (wndPtr, wParam, lParam);
240
241         case CBEM_GETEDITCONTROL:
242             return COMBOEX_GetEditControl (wndPtr, wParam, lParam);
243
244         case CBEM_GETEXTENDEDSTYLE:
245             return COMBOEX_GetExtendedStyle (wndPtr, wParam, lParam);
246
247         case CBEM_GETIMAGELIST:
248             return COMBOEX_GetImageList (wndPtr, wParam, lParam);
249
250 /*      case CBEM_GETITEM32A:
251         case CBEM_GETITEM32W:
252         case CBEM_GETUNICODEFORMAT:
253         case CBEM_HASEDITCHANGED:
254 */
255
256         case CBEM_INSERTITEM32A:
257             return COMBOEX_InsertItem32A (wndPtr, wParam, lParam);
258
259 /*      case CBEM_INSERTITEM32W: */
260
261         case CBEM_SETEXTENDEDSTYLE:
262             return COMBOEX_SetExtendedStyle (wndPtr, wParam, lParam);
263
264         case CBEM_SETIMAGELIST:
265             return COMBOEX_SetImageList (wndPtr, wParam, lParam);
266
267         case CBEM_SETITEM32A:
268             return COMBOEX_SetItem32A (wndPtr, wParam, lParam);
269
270 /*      case CBEM_SETITEM32W:
271         case CBEM_SETUNICODEFORMAT:
272 */
273
274         case CB_DELETESTRING32:
275         case CB_FINDSTRINGEXACT32:
276         case CB_GETCOUNT32:
277         case CB_GETCURSEL32:
278         case CB_GETDROPPEDCONTROLRECT32:
279         case CB_GETDROPPEDSTATE32:
280         case CB_GETITEMDATA32:
281         case CB_GETITEMHEIGHT32:
282         case CB_GETLBTEXT32:
283         case CB_GETLBTEXTLEN32:
284         case CB_GETEXTENDEDUI32:
285         case CB_LIMITTEXT32:
286         case CB_RESETCONTENT32:
287         case CB_SELECTSTRING32:
288         case CB_SETCURSEL32:
289         case CB_SETDROPPEDWIDTH32:
290         case CB_SETEXTENDEDUI32:
291         case CB_SETITEMDATA32:
292         case CB_SETITEMHEIGHT32:
293         case CB_SHOWDROPDOWN32:
294             return COMBOEX_Forward (wndPtr, uMsg, wParam, lParam);
295
296
297         case WM_CREATE:
298             return COMBOEX_Create (wndPtr, wParam, lParam);
299
300         case WM_DESTROY:
301             return COMBOEX_Destroy (wndPtr, wParam, lParam);
302
303         case WM_SIZE:
304             return COMBOEX_Size (wndPtr, wParam, lParam);
305
306         default:
307             if (uMsg >= WM_USER)
308                 ERR (comboex, "unknown msg %04x wp=%08x lp=%08lx\n",
309                      uMsg, wParam, lParam);
310             return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
311     }
312     return 0;
313 }
314
315
316 VOID
317 COMBOEX_Register (VOID)
318 {
319     WNDCLASS32A wndClass;
320
321     if (GlobalFindAtom32A (WC_COMBOBOXEX32A)) return;
322
323     ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
324     wndClass.style         = CS_GLOBALCLASS;
325     wndClass.lpfnWndProc   = (WNDPROC32)COMBOEX_WindowProc;
326     wndClass.cbClsExtra    = 0;
327     wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *);
328     wndClass.hCursor       = LoadCursor32A (0, IDC_ARROW32A);
329     wndClass.hbrBackground = (HBRUSH32)(COLOR_WINDOW + 1);
330     wndClass.lpszClassName = WC_COMBOBOXEX32A;
331  
332     RegisterClass32A (&wndClass);
333 }
334
335
336 VOID
337 COMBOEX_Unregister (VOID)
338 {
339     if (GlobalFindAtom32A (WC_COMBOBOXEX32A))
340         UnregisterClass32A (WC_COMBOBOXEX32A, (HINSTANCE32)NULL);
341 }
342