1 | /* $Id: comboex.cpp,v 1.2 2000-02-25 17:00:15 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * ComboBoxEx control
|
---|
4 | *
|
---|
5 | * Copyright 1998, 1999 Eric Kohl
|
---|
6 | * Copyright 1999 Achim Hasenmueller
|
---|
7 | *
|
---|
8 | * NOTES
|
---|
9 | * This is just a dummy control. An author is needed! Any volunteers?
|
---|
10 | * I will only improve this control once in a while.
|
---|
11 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
12 | *
|
---|
13 | * TODO:
|
---|
14 | * - All messages.
|
---|
15 | * - All notifications.
|
---|
16 | *
|
---|
17 | * FIXME:
|
---|
18 | * - should include "combo.h"
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "winbase.h"
|
---|
22 | #include "commctrl.h"
|
---|
23 | #include "comctl32.h"
|
---|
24 | #include "ccbase.h"
|
---|
25 | #include "comboex.h"
|
---|
26 |
|
---|
27 |
|
---|
28 | #define ID_CB_EDIT 1001
|
---|
29 |
|
---|
30 | #define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)getInfoPtr(hwnd))
|
---|
31 |
|
---|
32 |
|
---|
33 | /* << COMBOEX_DeleteItem >> */
|
---|
34 |
|
---|
35 |
|
---|
36 | static LRESULT
|
---|
37 | COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
38 | {
|
---|
39 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
40 |
|
---|
41 | // TRACE (comboex, "\n");
|
---|
42 |
|
---|
43 | return (LRESULT)infoPtr->hwndCombo;
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | static LRESULT
|
---|
48 | COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
49 | {
|
---|
50 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
51 |
|
---|
52 | if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
|
---|
53 | return 0;
|
---|
54 |
|
---|
55 | // TRACE (comboex, "-- 0x%x\n", GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT));
|
---|
56 |
|
---|
57 | return (LRESULT)GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT);
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | static LRESULT
|
---|
62 | COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
63 | {
|
---|
64 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
65 |
|
---|
66 | return (LRESULT)infoPtr->dwExtStyle;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | static LRESULT
|
---|
71 | COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
72 | {
|
---|
73 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
74 |
|
---|
75 | // TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
|
---|
76 |
|
---|
77 | return (LRESULT)infoPtr->himl;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 | static LRESULT
|
---|
84 | COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
85 | {
|
---|
86 | /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */
|
---|
87 |
|
---|
88 | // FIXME (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
|
---|
89 |
|
---|
90 | return -1;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | static LRESULT
|
---|
96 | COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
97 | {
|
---|
98 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
99 | DWORD dwTemp;
|
---|
100 |
|
---|
101 | // TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
|
---|
102 |
|
---|
103 | dwTemp = infoPtr->dwExtStyle;
|
---|
104 |
|
---|
105 | if ((DWORD)wParam) {
|
---|
106 | infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
|
---|
107 | }
|
---|
108 | else
|
---|
109 | infoPtr->dwExtStyle = (DWORD)lParam;
|
---|
110 |
|
---|
111 | /* FIXME: repaint?? */
|
---|
112 |
|
---|
113 | return (LRESULT)dwTemp;
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | static LRESULT
|
---|
118 | COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
119 | {
|
---|
120 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
121 | HIMAGELIST himlTemp;
|
---|
122 |
|
---|
123 | // TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam);
|
---|
124 |
|
---|
125 | himlTemp = infoPtr->himl;
|
---|
126 | infoPtr->himl = (HIMAGELIST)lParam;
|
---|
127 |
|
---|
128 | return (LRESULT)himlTemp;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | static LRESULT
|
---|
133 | COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
134 | {
|
---|
135 | /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */
|
---|
136 |
|
---|
137 | // FIXME (comboex, "(%p): stub\n", (LPVOID)lParam);
|
---|
138 |
|
---|
139 | return TRUE;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | /* << COMBOEX_SetItem32W >> */
|
---|
144 |
|
---|
145 |
|
---|
146 | static LRESULT
|
---|
147 | COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
148 | {
|
---|
149 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
|
---|
150 |
|
---|
151 | // FIXME (comboex, "(0x%x 0x%x 0x%lx): stub\n", uMsg, wParam, lParam);
|
---|
152 |
|
---|
153 | if (infoPtr->hwndCombo)
|
---|
154 | return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
|
---|
155 |
|
---|
156 | return 0;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | static LRESULT
|
---|
161 | COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
162 | {
|
---|
163 | COMBOEX_INFO *infoPtr;
|
---|
164 | DWORD dwComboStyle;
|
---|
165 |
|
---|
166 | /* allocate memory for info structure */
|
---|
167 | infoPtr = (COMBOEX_INFO*)initControl(hwnd,sizeof(COMBOEX_INFO));
|
---|
168 | if (infoPtr == NULL) {
|
---|
169 | // ERR (comboex, "could not allocate info memory!\n");
|
---|
170 | return 0;
|
---|
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 | doneControl(hwnd);
|
---|
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 | static 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 defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
|
---|
303 | }
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|
308 | VOID
|
---|
309 | COMBOEX_Register (VOID)
|
---|
310 | {
|
---|
311 | WNDCLASSA wndClass;
|
---|
312 |
|
---|
313 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
314 | wndClass.style = CS_GLOBALCLASS;
|
---|
315 | wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
|
---|
316 | wndClass.cbClsExtra = 0;
|
---|
317 | wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
|
---|
318 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
319 | wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
---|
320 | wndClass.lpszClassName = WC_COMBOBOXEXA;
|
---|
321 |
|
---|
322 | RegisterClassA (&wndClass);
|
---|
323 | }
|
---|
324 |
|
---|
325 |
|
---|
326 | VOID
|
---|
327 | COMBOEX_Unregister (VOID)
|
---|
328 | {
|
---|
329 | UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);
|
---|
330 | }
|
---|
331 |
|
---|