947a871a6b9a289266c0d7aede9ce98c6cf5f81b
[reactos.git] / modules / rostests / winetests / comctl32 / comboex.c
1 /* Unit test suite for comboex control.
2 *
3 * Copyright 2005 Jason Edmeades
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "precomp.h"
21
22 #define EDITBOX_SEQ_INDEX 0
23 #define NUM_MSG_SEQUENCES 1
24
25 #define EDITBOX_ID 0
26
27 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
28
29 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
30
31 static HWND hComboExParentWnd;
32 static HINSTANCE hMainHinst;
33 static const char ComboExTestClass[] = "ComboExTestClass";
34
35 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
36
37 #define MAX_CHARS 100
38 static char *textBuffer = NULL;
39
40 static BOOL received_end_edit = FALSE;
41
42 static HWND createComboEx(DWORD style) {
43 return CreateWindowExA(0, WC_COMBOBOXEXA, NULL, style, 0, 0, 300, 300,
44 hComboExParentWnd, NULL, hMainHinst, NULL);
45 }
46
47 static LONG addItem(HWND cbex, int idx, const char *text) {
48 COMBOBOXEXITEMA cbexItem;
49 memset(&cbexItem, 0x00, sizeof(cbexItem));
50 cbexItem.mask = CBEIF_TEXT;
51 cbexItem.iItem = idx;
52 cbexItem.pszText = (char*)text;
53 cbexItem.cchTextMax = 0;
54 return SendMessageA(cbex, CBEM_INSERTITEMA, 0, (LPARAM)&cbexItem);
55 }
56
57 static LONG setItem(HWND cbex, int idx, const char *text) {
58 COMBOBOXEXITEMA cbexItem;
59 memset(&cbexItem, 0x00, sizeof(cbexItem));
60 cbexItem.mask = CBEIF_TEXT;
61 cbexItem.iItem = idx;
62 cbexItem.pszText = (char*)text;
63 cbexItem.cchTextMax = 0;
64 return SendMessageA(cbex, CBEM_SETITEMA, 0, (LPARAM)&cbexItem);
65 }
66
67 static LONG delItem(HWND cbex, int idx) {
68 return SendMessageA(cbex, CBEM_DELETEITEM, idx, 0);
69 }
70
71 static LONG getItem(HWND cbex, int idx, COMBOBOXEXITEMA *cbItem) {
72 memset(cbItem, 0x00, sizeof(COMBOBOXEXITEMA));
73 cbItem->mask = CBEIF_TEXT;
74 cbItem->pszText = textBuffer;
75 cbItem->iItem = idx;
76 cbItem->cchTextMax = 100;
77 return SendMessageA(cbex, CBEM_GETITEMA, 0, (LPARAM)cbItem);
78 }
79
80 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
81 {
82 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
83 static LONG defwndproc_counter = 0;
84 struct message msg = { 0 };
85 LRESULT ret;
86
87 msg.message = message;
88 msg.flags = sent|wparam|lparam;
89 if (defwndproc_counter) msg.flags |= defwinproc;
90 msg.wParam = wParam;
91 msg.lParam = lParam;
92 msg.id = EDITBOX_ID;
93
94 if (message != WM_PAINT &&
95 message != WM_ERASEBKGND &&
96 message != WM_NCPAINT &&
97 message != WM_NCHITTEST &&
98 message != WM_GETTEXT &&
99 message != WM_GETICON &&
100 message != WM_DEVICECHANGE)
101 {
102 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
103 }
104
105 defwndproc_counter++;
106 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
107 defwndproc_counter--;
108 return ret;
109 }
110
111 static HWND subclass_editbox(HWND hwndComboEx)
112 {
113 WNDPROC oldproc;
114 HWND hwnd;
115
116 hwnd = (HWND)SendMessageA(hwndComboEx, CBEM_GETEDITCONTROL, 0, 0);
117 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
118 (LONG_PTR)editbox_subclass_proc);
119 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
120
121 return hwnd;
122 }
123
124 static void test_comboboxex(void) {
125 HWND myHwnd = 0;
126 LONG res;
127 COMBOBOXEXITEMA cbexItem;
128 static const char *first_item = "First Item",
129 *second_item = "Second Item",
130 *third_item = "Third Item",
131 *middle_item = "Between First and Second Items",
132 *replacement_item = "Between First and Second Items",
133 *out_of_range_item = "Out of Range Item";
134
135 /* Allocate space for result */
136 textBuffer = HeapAlloc(GetProcessHeap(), 0, MAX_CHARS);
137
138 /* Basic comboboxex test */
139 myHwnd = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
140
141 /* Add items onto the end of the combobox */
142 res = addItem(myHwnd, -1, first_item);
143 ok(res == 0, "Adding simple item failed (%d)\n", res);
144 res = addItem(myHwnd, -1, second_item);
145 ok(res == 1, "Adding simple item failed (%d)\n", res);
146 res = addItem(myHwnd, 2, third_item);
147 ok(res == 2, "Adding simple item failed (%d)\n", res);
148 res = addItem(myHwnd, 1, middle_item);
149 ok(res == 1, "Inserting simple item failed (%d)\n", res);
150
151 /* Add an item completely out of range */
152 res = addItem(myHwnd, 99, out_of_range_item);
153 ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
154 res = addItem(myHwnd, 5, out_of_range_item);
155 ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
156 /* Removed: Causes traps on Windows XP
157 res = addItem(myHwnd, -2, "Out Of Range Item");
158 ok(res == -1, "Adding out of range worked unexpectedly (%ld)\n", res);
159 */
160
161 /* Get an item completely out of range */
162 res = getItem(myHwnd, 99, &cbexItem);
163 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
164 res = getItem(myHwnd, 4, &cbexItem);
165 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
166 res = getItem(myHwnd, -2, &cbexItem);
167 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
168
169 /* Get an item in range */
170 res = getItem(myHwnd, 0, &cbexItem);
171 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
172 ok(strcmp(first_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
173
174 res = getItem(myHwnd, 1, &cbexItem);
175 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
176 ok(strcmp(middle_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
177
178 res = getItem(myHwnd, 2, &cbexItem);
179 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
180 ok(strcmp(second_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
181
182 res = getItem(myHwnd, 3, &cbexItem);
183 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
184 ok(strcmp(third_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
185
186 /* Set an item completely out of range */
187 res = setItem(myHwnd, 99, replacement_item);
188 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
189 res = setItem(myHwnd, 4, replacement_item);
190 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
191 res = setItem(myHwnd, -2, replacement_item);
192 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
193
194 /* Set an item in range */
195 res = setItem(myHwnd, 0, replacement_item);
196 ok(res != 0, "Setting first item failed (%d)\n", res);
197 res = setItem(myHwnd, 3, replacement_item);
198 ok(res != 0, "Setting last item failed (%d)\n", res);
199
200 /* Remove items completely out of range (4 items in control at this point) */
201 res = delItem(myHwnd, -1);
202 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
203 res = delItem(myHwnd, 4);
204 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
205
206 /* Remove items in range (4 items in control at this point) */
207 res = delItem(myHwnd, 3);
208 ok(res == 3, "Deleting using out of range index failed (%d)\n", res);
209 res = delItem(myHwnd, 0);
210 ok(res == 2, "Deleting using out of range index failed (%d)\n", res);
211 res = delItem(myHwnd, 0);
212 ok(res == 1, "Deleting using out of range index failed (%d)\n", res);
213 res = delItem(myHwnd, 0);
214 ok(res == 0, "Deleting using out of range index failed (%d)\n", res);
215
216 /* Remove from an empty box */
217 res = delItem(myHwnd, 0);
218 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
219
220
221 /* Cleanup */
222 HeapFree(GetProcessHeap(), 0, textBuffer);
223 DestroyWindow(myHwnd);
224 }
225
226 static void test_WM_LBUTTONDOWN(void)
227 {
228 HWND hComboEx, hCombo, hEdit, hList;
229 COMBOBOXINFO cbInfo;
230 UINT x, y, item_height;
231 LRESULT result;
232 UINT i;
233 int idx;
234 RECT rect;
235 WCHAR buffer[3];
236 static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
237 static const WCHAR stringFormat[] = {'%','2','d','\0'};
238 BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO);
239
240 pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo");
241 if (!pGetComboBoxInfo){
242 win_skip("GetComboBoxInfo is not available\n");
243 return;
244 }
245
246 hComboEx = CreateWindowExA(0, WC_COMBOBOXEXA, NULL,
247 WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150,
248 hComboExParentWnd, NULL, hMainHinst, NULL);
249
250 for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){
251 COMBOBOXEXITEMW cbexItem;
252 wsprintfW(buffer, stringFormat, choices[i]);
253
254 memset(&cbexItem, 0x00, sizeof(cbexItem));
255 cbexItem.mask = CBEIF_TEXT;
256 cbexItem.iItem = i;
257 cbexItem.pszText = buffer;
258 cbexItem.cchTextMax = 0;
259 ok(SendMessageW(hComboEx, CBEM_INSERTITEMW, 0, (LPARAM)&cbexItem) >= 0,
260 "Failed to add item %d\n", i);
261 }
262
263 hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
264 hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
265
266 cbInfo.cbSize = sizeof(COMBOBOXINFO);
267 result = pGetComboBoxInfo(hCombo, &cbInfo);
268 ok(result, "Failed to get combobox info structure. LastError=%d\n",
269 GetLastError());
270 hList = cbInfo.hwndList;
271
272 ok(GetFocus() == hComboExParentWnd,
273 "Focus not on Main Window, instead on %p\n", GetFocus());
274
275 /* Click on the button to drop down the list */
276 x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2;
277 y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2;
278 result = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
279 ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
280 GetLastError());
281 ok(GetFocus() == hCombo ||
282 broken(GetFocus() != hCombo), /* win98 */
283 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
284 GetFocus());
285 ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0),
286 "The dropdown list should have appeared after clicking the button.\n");
287 idx = SendMessageA(hCombo, CB_GETTOPINDEX, 0, 0);
288 ok(idx == 0, "For TopIndex expected %d, got %d\n", 0, idx);
289
290 result = SendMessageA(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
291 ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n",
292 GetLastError());
293 ok(GetFocus() == hCombo ||
294 broken(GetFocus() != hCombo), /* win98 */
295 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
296 GetFocus());
297
298 /* Click on the 5th item in the list */
299 item_height = SendMessageA(hCombo, CB_GETITEMHEIGHT, 0, 0);
300 ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n");
301 x = rect.left + (rect.right-rect.left)/2;
302 y = item_height/2 + item_height*4;
303 result = SendMessageA(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
304 ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n",
305 GetLastError());
306 ok(GetFocus() == hCombo ||
307 broken(GetFocus() != hCombo), /* win98 */
308 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
309 GetFocus());
310
311 result = SendMessageA(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
312 ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
313 GetLastError());
314 ok(GetFocus() == hCombo ||
315 broken(GetFocus() != hCombo), /* win98 */
316 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
317 GetFocus());
318 ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0),
319 "The dropdown list should still be visible.\n");
320
321 result = SendMessageA(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
322 ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n",
323 GetLastError());
324 todo_wine ok(GetFocus() == hEdit ||
325 broken(GetFocus() == hCombo), /* win98 */
326 "Focus not on ComboBoxEx's Edit Control, instead on %p\n",
327 GetFocus());
328
329 result = SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0);
330 ok(!result ||
331 broken(result != 0), /* win98 */
332 "The dropdown list should have been rolled up.\n");
333 idx = SendMessageA(hComboEx, CB_GETCURSEL, 0, 0);
334 ok(idx == 4 ||
335 broken(idx == -1), /* win98 */
336 "Current Selection: expected %d, got %d\n", 4, idx);
337 ok(received_end_edit, "Expected to receive a CBEN_ENDEDIT message\n");
338
339 SetFocus( hComboExParentWnd );
340 ok( GetFocus() == hComboExParentWnd, "got %p\n", GetFocus() );
341 SetFocus( hComboEx );
342 ok( GetFocus() == hEdit, "got %p\n", GetFocus() );
343
344 DestroyWindow(hComboEx);
345 }
346
347 static void test_CB_GETLBTEXT(void)
348 {
349 HWND hCombo;
350 CHAR buff[1];
351 COMBOBOXEXITEMA item;
352 LRESULT ret;
353
354 hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
355
356 /* set text to null */
357 addItem(hCombo, 0, NULL);
358
359 buff[0] = 'a';
360 item.mask = CBEIF_TEXT;
361 item.iItem = 0;
362 item.pszText = buff;
363 item.cchTextMax = 1;
364 ret = SendMessageA(hCombo, CBEM_GETITEMA, 0, (LPARAM)&item);
365 ok(ret != 0, "CBEM_GETITEM failed\n");
366 ok(buff[0] == 0, "\n");
367
368 ret = SendMessageA(hCombo, CB_GETLBTEXTLEN, 0, 0);
369 ok(ret == 0, "Expected zero length\n");
370
371 ret = SendMessageA(hCombo, CB_GETLBTEXTLEN, 0, 0);
372 ok(ret == 0, "Expected zero length\n");
373
374 buff[0] = 'a';
375 ret = SendMessageA(hCombo, CB_GETLBTEXT, 0, (LPARAM)buff);
376 ok(ret == 0, "Expected zero length\n");
377 ok(buff[0] == 0, "Expected null terminator as a string, got %s\n", buff);
378
379 DestroyWindow(hCombo);
380 }
381
382 static void test_WM_WINDOWPOSCHANGING(void)
383 {
384 HWND hCombo;
385 WINDOWPOS wp;
386 RECT rect;
387 int combo_height;
388 int ret;
389
390 hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
391 ok(hCombo != NULL, "createComboEx failed\n");
392 ret = GetWindowRect(hCombo, &rect);
393 ok(ret, "GetWindowRect failed\n");
394 combo_height = rect.bottom - rect.top;
395 ok(combo_height > 0, "wrong combo height\n");
396
397 /* Test height > combo_height */
398 wp.x = rect.left;
399 wp.y = rect.top;
400 wp.cx = (rect.right - rect.left);
401 wp.cy = combo_height * 2;
402 wp.flags = 0;
403 wp.hwnd = hCombo;
404 wp.hwndInsertAfter = NULL;
405
406 ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
407 ok(ret == 0, "expected 0, got %x\n", ret);
408 ok(wp.cy == combo_height,
409 "Expected height %d, got %d\n", combo_height, wp.cy);
410
411 /* Test height < combo_height */
412 wp.x = rect.left;
413 wp.y = rect.top;
414 wp.cx = (rect.right - rect.left);
415 wp.cy = combo_height / 2;
416 wp.flags = 0;
417 wp.hwnd = hCombo;
418 wp.hwndInsertAfter = NULL;
419
420 ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
421 ok(ret == 0, "expected 0, got %x\n", ret);
422 ok(wp.cy == combo_height,
423 "Expected height %d, got %d\n", combo_height, wp.cy);
424
425 ret = DestroyWindow(hCombo);
426 ok(ret, "DestroyWindow failed\n");
427 }
428
429 static LRESULT ComboExTestOnNotify(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
430 {
431 NMHDR *hdr = (NMHDR*)lParam;
432 switch(hdr->code){
433 case CBEN_ENDEDITA:
434 {
435 NMCBEENDEDITA *edit_info = (NMCBEENDEDITA*)hdr;
436 if(edit_info->iWhy==CBENF_DROPDOWN){
437 received_end_edit = TRUE;
438 }
439 break;
440 }
441 case CBEN_ENDEDITW:
442 {
443 NMCBEENDEDITW *edit_info = (NMCBEENDEDITW*)hdr;
444 if(edit_info->iWhy==CBENF_DROPDOWN){
445 received_end_edit = TRUE;
446 }
447 break;
448 }
449 }
450 return 0;
451 }
452
453 static LRESULT CALLBACK ComboExTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
454 {
455 switch(msg) {
456
457 case WM_DESTROY:
458 PostQuitMessage(0);
459 break;
460 case WM_NOTIFY:
461 return ComboExTestOnNotify(hWnd,msg,wParam,lParam);
462 default:
463 return DefWindowProcA(hWnd, msg, wParam, lParam);
464 }
465
466 return 0L;
467 }
468
469 static BOOL init(void)
470 {
471 HMODULE hComctl32;
472 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
473 WNDCLASSA wc;
474 INITCOMMONCONTROLSEX iccex;
475
476 hComctl32 = GetModuleHandleA("comctl32.dll");
477 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
478 if (!pInitCommonControlsEx)
479 {
480 win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
481 return FALSE;
482 }
483 iccex.dwSize = sizeof(iccex);
484 iccex.dwICC = ICC_USEREX_CLASSES;
485 pInitCommonControlsEx(&iccex);
486
487 pSetWindowSubclass = (void*)GetProcAddress(hComctl32, (LPSTR)410);
488
489 wc.style = CS_HREDRAW | CS_VREDRAW;
490 wc.cbClsExtra = 0;
491 wc.cbWndExtra = 0;
492 wc.hInstance = GetModuleHandleA(NULL);
493 wc.hIcon = NULL;
494 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
495 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
496 wc.lpszMenuName = NULL;
497 wc.lpszClassName = ComboExTestClass;
498 wc.lpfnWndProc = ComboExTestWndProc;
499 RegisterClassA(&wc);
500
501 hComboExParentWnd = CreateWindowExA(0, ComboExTestClass, "ComboEx test", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
502 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
503 ok(hComboExParentWnd != NULL, "failed to create parent window\n");
504
505 hMainHinst = GetModuleHandleA(NULL);
506
507 return hComboExParentWnd != NULL;
508 }
509
510 static void cleanup(void)
511 {
512 MSG msg;
513
514 PostMessageA(hComboExParentWnd, WM_CLOSE, 0, 0);
515 while (GetMessageA(&msg,0,0,0)) {
516 TranslateMessage(&msg);
517 DispatchMessageA(&msg);
518 }
519
520 DestroyWindow(hComboExParentWnd);
521 UnregisterClassA(ComboExTestClass, GetModuleHandleA(NULL));
522 }
523
524 static void test_comboboxex_subclass(void)
525 {
526 HWND hComboEx, hCombo, hEdit;
527
528 hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
529
530 hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
531 ok(hCombo != NULL, "Failed to get internal combo\n");
532 hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
533 ok(hEdit != NULL, "Failed to get internal edit\n");
534
535 if (pSetWindowSubclass)
536 {
537 ok(GetPropA(hCombo, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
538 ok(GetPropA(hEdit, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
539 }
540
541 DestroyWindow(hComboEx);
542 }
543
544 static const struct message test_setitem_edit_seq[] = {
545 { WM_SETTEXT, sent|id, 0, 0, EDITBOX_ID },
546 { EM_SETSEL, sent|id|wparam|lparam, 0, 0, EDITBOX_ID },
547 { EM_SETSEL, sent|id|wparam|lparam, 0, -1, EDITBOX_ID },
548 { 0 }
549 };
550
551 static void test_get_set_item(void)
552 {
553 char textA[] = "test";
554 HWND hComboEx;
555 COMBOBOXEXITEMA item;
556 BOOL ret;
557
558 hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
559
560 subclass_editbox(hComboEx);
561
562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
563
564 memset(&item, 0, sizeof(item));
565 item.mask = CBEIF_TEXT;
566 item.pszText = textA;
567 item.iItem = -1;
568 ret = SendMessageA(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
569 expect(TRUE, ret);
570
571 ok_sequence(sequences, EDITBOX_SEQ_INDEX, test_setitem_edit_seq, "set item data for edit", FALSE);
572
573 /* get/set lParam */
574 item.mask = CBEIF_LPARAM;
575 item.iItem = -1;
576 item.lParam = 0xdeadbeef;
577 ret = SendMessageA(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
578 expect(TRUE, ret);
579 ok(item.lParam == 0, "Expected zero, got %lx\n", item.lParam);
580
581 item.lParam = 0x1abe11ed;
582 ret = SendMessageA(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
583 expect(TRUE, ret);
584
585 item.lParam = 0;
586 ret = SendMessageA(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
587 expect(TRUE, ret);
588 ok(item.lParam == 0x1abe11ed, "Expected 0x1abe11ed, got %lx\n", item.lParam);
589
590 DestroyWindow(hComboEx);
591 }
592
593 START_TEST(comboex)
594 {
595 if (!init())
596 return;
597
598 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
599
600 test_comboboxex();
601 test_WM_LBUTTONDOWN();
602 test_CB_GETLBTEXT();
603 test_WM_WINDOWPOSCHANGING();
604 test_comboboxex_subclass();
605 test_get_set_item();
606
607 cleanup();
608 }