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