Added xxx_Unregister() functions to all common controls.
[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 "windows.h"
20 #include "commctrl.h"
21 #include "comboex.h"
22 #include "win.h"
23 #include "debug.h"
24
25 #define ID_CB_EDIT    1001
26
27 #define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)wndPtr->wExtra[0])
28
29
30 // << COMBOEX_DeleteItem >>
31
32
33 __inline__ static LRESULT
34 COMBOEX_GetComboControl (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
35 {
36     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
37
38     TRACE (comboex, "\n");
39
40     return (LRESULT)infoPtr->hwndCombo;
41 }
42
43
44 __inline__ static LRESULT
45 COMBOEX_GetEditControl (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
46 {
47     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
48
49     if ((wndPtr->dwStyle & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
50         return 0;
51
52     FIXME (comboex, "-- 0x%x\n", GetDlgItem32 (infoPtr->hwndCombo, ID_CB_EDIT));
53
54     return (LRESULT)GetDlgItem32 (infoPtr->hwndCombo, ID_CB_EDIT);
55 }
56
57
58 __inline__ static LRESULT
59 COMBOEX_GetExtendedStyle (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
60 {
61     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
62
63     return (LRESULT)infoPtr->dwExtStyle;
64 }
65
66
67 __inline__ static LRESULT
68 COMBOEX_GetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
69 {
70     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
71
72     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
73
74     return (LRESULT)infoPtr->himl;
75 }
76
77
78
79
80 static LRESULT
81 COMBOEX_InsertItem32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
82 {
83     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
84
85     FIXME (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
86
87     return -1;
88 }
89
90
91
92 static LRESULT
93 COMBOEX_SetExtendedStyle (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
94 {
95     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
96     DWORD dwTemp;
97
98     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
99
100     dwTemp = infoPtr->dwExtStyle;
101
102     if ((DWORD)wParam) {
103         infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
104     }
105     else
106         infoPtr->dwExtStyle = (DWORD)lParam;
107
108     /* FIXME: repaint?? */
109
110     return (LRESULT)dwTemp;
111 }
112
113
114 __inline__ static LRESULT
115 COMBOEX_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
116 {
117     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
118     HIMAGELIST himlTemp;
119
120     TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
121
122     himlTemp = infoPtr->himl;
123     infoPtr->himl = (HIMAGELIST)lParam;
124
125     return (LRESULT)himlTemp;
126 }
127
128
129
130
131 static LRESULT
132 COMBOEX_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
133 {
134     COMBOEX_INFO *infoPtr;
135     DWORD dwComboStyle;
136
137     /* allocate memory for info structure */
138     infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
139     wndPtr->wExtra[0] = (DWORD)infoPtr;
140
141     if (infoPtr == NULL) {
142         ERR (listview, "could not allocate info memory!\n");
143         return 0;
144     }
145
146     if ((COMBOEX_INFO*)wndPtr->wExtra[0] != infoPtr) {
147         ERR (listview, "pointer assignment error!\n");
148         return 0;
149     }
150
151
152     /* initialize info structure */
153
154
155     /* create combo box */
156     dwComboStyle = 
157         wndPtr->dwStyle & (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
158
159     infoPtr->hwndCombo =
160         CreateWindow32A ("ComboBox", "",
161                          WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
162                          0, 0, 0, 0, wndPtr->hwndSelf, (HMENU32)1,
163                          wndPtr->hInstance, NULL);
164
165
166     return 0;
167 }
168
169
170 static LRESULT
171 COMBOEX_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
172 {
173     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
174
175
176     if (infoPtr->hwndCombo)
177         DestroyWindow32 (infoPtr->hwndCombo);
178
179
180
181
182     /* free comboex info data */
183     COMCTL32_Free (infoPtr);
184
185     return 0;
186 }
187
188
189 static LRESULT
190 COMBOEX_Size (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
191 {
192     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr(wndPtr);
193     RECT32 rect;
194
195     GetClientRect32 (wndPtr->hwndSelf, &rect);
196
197     MoveWindow32 (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
198                   rect.bottom - rect.top, TRUE);
199
200     return 0;
201 }
202
203
204 LRESULT WINAPI
205 COMBOEX_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
206 {
207     WND *wndPtr = WIN_FindWndPtr(hwnd);
208
209     switch (uMsg)
210     {
211 //      case CBEM_DELETEITEM:
212
213         case CBEM_GETCOMBOCONTROL:
214             return COMBOEX_GetComboControl (wndPtr, wParam, lParam);
215
216         case CBEM_GETEDITCONTROL:
217             return COMBOEX_GetEditControl (wndPtr, wParam, lParam);
218
219         case CBEM_GETEXTENDEDSTYLE:
220             return COMBOEX_GetExtendedStyle (wndPtr, wParam, lParam);
221
222         case CBEM_GETIMAGELIST:
223             return COMBOEX_GetImageList (wndPtr, wParam, lParam);
224
225 //      case CBEM_GETITEM32A:
226 //      case CBEM_GETITEM32W:
227 //      case CBEM_GETUNICODEFORMAT:
228 //      case CBEM_HASEDITCHANGED:
229
230         case CBEM_INSERTITEM32A:
231             return COMBOEX_InsertItem32A (wndPtr, wParam, lParam);
232
233 //      case CBEM_INSERTITEM32W:
234
235         case CBEM_SETEXTENDEDSTYLE:
236             return COMBOEX_SetExtendedStyle (wndPtr, wParam, lParam);
237
238         case CBEM_SETIMAGELIST:
239             return COMBOEX_SetImageList (wndPtr, wParam, lParam);
240
241 //      case CBEM_SETITEM32A:
242 //      case CBEM_SETITEM32W:
243 //      case CBEM_SETUNICODEFORMAT:
244
245
246         case WM_CREATE:
247             return COMBOEX_Create (wndPtr, wParam, lParam);
248
249         case WM_DESTROY:
250             return COMBOEX_Destroy (wndPtr, wParam, lParam);
251
252         case WM_SIZE:
253             return COMBOEX_Size (wndPtr, wParam, lParam);
254
255         default:
256             if (uMsg >= WM_USER)
257                 ERR (comboex, "unknown msg %04x wp=%08x lp=%08lx\n",
258                      uMsg, wParam, lParam);
259             return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
260     }
261     return 0;
262 }
263
264
265 VOID
266 COMBOEX_Register (VOID)
267 {
268     WNDCLASS32A wndClass;
269
270     if (GlobalFindAtom32A (WC_COMBOBOXEX32A)) return;
271
272     ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
273     wndClass.style         = CS_GLOBALCLASS;
274     wndClass.lpfnWndProc   = (WNDPROC32)COMBOEX_WindowProc;
275     wndClass.cbClsExtra    = 0;
276     wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *);
277     wndClass.hCursor       = LoadCursor32A (0, IDC_ARROW32A);
278     wndClass.hbrBackground = (HBRUSH32)(COLOR_WINDOW + 1);
279     wndClass.lpszClassName = WC_COMBOBOXEX32A;
280  
281     RegisterClass32A (&wndClass);
282 }
283
284
285 VOID
286 COMBOEX_Unregister (VOID)
287 {
288     if (GlobalFindAtom32A (WC_COMBOBOXEX32A))
289         UnregisterClass32A (WC_COMBOBOXEX32A, (HINSTANCE32)NULL);
290 }
291