Removed no longer necessary win.h include, added now necessary other
[wine] / dlls / comctl32 / comboex.c
1 /*
2  * ComboBoxEx control
3  *
4  * Copyright 1998, 1999 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 "winbase.h"
20 #include "commctrl.h"
21 #include "comboex.h"
22 #include "debug.h"
23
24 #define ID_CB_EDIT    1001
25
26 #define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
27
28
29 /* << COMBOEX_DeleteItem >> */
30
31
32 __inline__ static LRESULT
33 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
34 {
35     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
36
37     TRACE (comboex, "\n");
38
39     return (LRESULT)infoPtr->hwndCombo;
40 }
41
42
43 __inline__ static LRESULT
44 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
45 {
46     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
47
48     if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
49         return 0;
50
51     TRACE (comboex, "-- 0x%x\n", GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT));
52
53     return (LRESULT)GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT);
54 }
55
56
57 __inline__ static LRESULT
58 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
59 {
60     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
61
62     return (LRESULT)infoPtr->dwExtStyle;
63 }
64
65
66 __inline__ static LRESULT
67 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
68 {
69     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
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_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
81 {
82     /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */
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 (HWND hwnd, WPARAM wParam, LPARAM lParam)
93 {
94     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
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 (HWND hwnd, WPARAM wParam, LPARAM lParam)
115 {
116     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
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_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
130 {
131     /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */
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 (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
144 {
145     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
146
147     FIXME (comboex, "(0x%x 0x%x 0x%lx): stub\n", uMsg, wParam, lParam);
148
149     if (infoPtr->hwndCombo)    
150         return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
151
152     return 0;
153 }
154
155
156 static LRESULT
157 COMBOEX_Create (HWND hwnd, WPARAM 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     if (infoPtr == NULL) {
165         ERR (listview, "could not allocate info memory!\n");
166         return 0;
167     }
168
169     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
170
171
172     /* initialize info structure */
173
174
175     /* create combo box */
176     dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
177                         (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
178
179     infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
180                          WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
181                         0, 0, 0, 0, hwnd, (HMENU)1,
182                         GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
183
184     return 0;
185 }
186
187
188 static LRESULT
189 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
190 {
191     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
192
193
194     if (infoPtr->hwndCombo)
195         DestroyWindow (infoPtr->hwndCombo);
196
197
198
199
200     /* free comboex info data */
201     COMCTL32_Free (infoPtr);
202
203     return 0;
204 }
205
206
207 static LRESULT
208 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
209 {
210     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
211     RECT rect;
212
213     GetClientRect (hwnd, &rect);
214
215     MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
216                   rect.bottom - rect.top, TRUE);
217
218     return 0;
219 }
220
221
222 LRESULT WINAPI
223 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
224 {
225     switch (uMsg)
226     {
227 /*      case CBEM_DELETEITEM: */
228
229         case CBEM_GETCOMBOCONTROL:
230             return COMBOEX_GetComboControl (hwnd, wParam, lParam);
231
232         case CBEM_GETEDITCONTROL:
233             return COMBOEX_GetEditControl (hwnd, wParam, lParam);
234
235         case CBEM_GETEXTENDEDSTYLE:
236             return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
237
238         case CBEM_GETIMAGELIST:
239             return COMBOEX_GetImageList (hwnd, wParam, lParam);
240
241 /*      case CBEM_GETITEM32A:
242         case CBEM_GETITEM32W:
243         case CBEM_GETUNICODEFORMAT:
244         case CBEM_HASEDITCHANGED:
245 */
246
247         case CBEM_INSERTITEMA:
248             return COMBOEX_InsertItemA (hwnd, wParam, lParam);
249
250 /*      case CBEM_INSERTITEM32W: */
251
252         case CBEM_SETEXTENDEDSTYLE:
253             return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
254
255         case CBEM_SETIMAGELIST:
256             return COMBOEX_SetImageList (hwnd, wParam, lParam);
257
258         case CBEM_SETITEMA:
259             return COMBOEX_SetItemA (hwnd, wParam, lParam);
260
261 /*      case CBEM_SETITEM32W:
262         case CBEM_SETUNICODEFORMAT:
263 */
264
265         case CB_DELETESTRING:
266         case CB_FINDSTRINGEXACT:
267         case CB_GETCOUNT:
268         case CB_GETCURSEL:
269         case CB_GETDROPPEDCONTROLRECT:
270         case CB_GETDROPPEDSTATE:
271         case CB_GETITEMDATA:
272         case CB_GETITEMHEIGHT:
273         case CB_GETLBTEXT:
274         case CB_GETLBTEXTLEN:
275         case CB_GETEXTENDEDUI:
276         case CB_LIMITTEXT:
277         case CB_RESETCONTENT:
278         case CB_SELECTSTRING:
279         case CB_SETCURSEL:
280         case CB_SETDROPPEDWIDTH:
281         case CB_SETEXTENDEDUI:
282         case CB_SETITEMDATA:
283         case CB_SETITEMHEIGHT:
284         case CB_SHOWDROPDOWN:
285             return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
286
287
288         case WM_CREATE:
289             return COMBOEX_Create (hwnd, wParam, lParam);
290
291         case WM_DESTROY:
292             return COMBOEX_Destroy (hwnd, wParam, lParam);
293
294         case WM_SIZE:
295             return COMBOEX_Size (hwnd, wParam, lParam);
296
297         default:
298             if (uMsg >= WM_USER)
299                 ERR (comboex, "unknown msg %04x wp=%08x lp=%08lx\n",
300                      uMsg, wParam, lParam);
301             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
302     }
303     return 0;
304 }
305
306
307 VOID
308 COMBOEX_Register (VOID)
309 {
310     WNDCLASSA wndClass;
311
312     if (GlobalFindAtomA (WC_COMBOBOXEXA)) return;
313
314     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
315     wndClass.style         = CS_GLOBALCLASS;
316     wndClass.lpfnWndProc   = (WNDPROC)COMBOEX_WindowProc;
317     wndClass.cbClsExtra    = 0;
318     wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *);
319     wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
320     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
321     wndClass.lpszClassName = WC_COMBOBOXEXA;
322  
323     RegisterClassA (&wndClass);
324 }
325
326
327 VOID
328 COMBOEX_Unregister (VOID)
329 {
330     if (GlobalFindAtomA (WC_COMBOBOXEXA))
331         UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);
332 }
333