1 /* Unit test suite for combo boxes.
3 * Copyright 2007 Mikolaj Zalewski
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.
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.
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
25 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
32 #define COMBO_YBORDERSIZE() 2
36 #define expect_eq(expr, value, type, fmt); { type val = expr; ok(val == (value), #expr " expected " #fmt " got " #fmt "\n", (value), val); }
37 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
38 r.bottom == _bottom && r.right == _right, "Invalid rect %s vs (%d,%d)-(%d,%d)\n", \
39 wine_dbgstr_rect(&r), _left, _top, _right, _bottom);
41 static HWND
build_combo(DWORD style
)
43 return CreateWindowA("ComboBox", "Combo", WS_VISIBLE
|WS_CHILD
|style
, 5, 5, 100, 100, hMainWnd
, (HMENU
)COMBO_ID
, NULL
, 0);
46 static int font_height(HFONT hFont
)
52 hDC
= CreateCompatibleDC(NULL
);
53 hFontOld
= SelectObject(hDC
, hFont
);
54 GetTextMetricsA(hDC
, &tm
);
55 SelectObject(hDC
, hFontOld
);
61 static INT CALLBACK
is_font_installed_proc(const LOGFONTA
*elf
, const TEXTMETRICA
*tm
, DWORD type
, LPARAM lParam
)
66 static BOOL
is_font_installed(const char *name
)
68 HDC hdc
= GetDC(NULL
);
69 BOOL ret
= !EnumFontFamiliesA(hdc
, name
, is_font_installed_proc
, 0);
74 static void test_setitemheight(DWORD style
)
76 HWND hCombo
= build_combo(style
);
80 trace("Style %x\n", style
);
81 GetClientRect(hCombo
, &r
);
82 expect_rect(r
, 0, 0, 100, font_height(GetStockObject(SYSTEM_FONT
)) + 8);
83 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&r
);
84 MapWindowPoints(HWND_DESKTOP
, hMainWnd
, (LPPOINT
)&r
, 2);
85 todo_wine
expect_rect(r
, 5, 5, 105, 105);
87 for (i
= 1; i
< 30; i
++)
89 SendMessageA(hCombo
, CB_SETITEMHEIGHT
, -1, i
);
90 GetClientRect(hCombo
, &r
);
91 expect_eq(r
.bottom
- r
.top
, i
+ 6, int, "%d");
94 DestroyWindow(hCombo
);
97 static void test_setfont(DWORD style
)
100 HFONT hFont1
, hFont2
;
104 if (!is_font_installed("Marlett"))
106 skip("Marlett font not available\n");
110 trace("Style %x\n", style
);
112 hCombo
= build_combo(style
);
113 hFont1
= CreateFontA(10, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, SYMBOL_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|FF_DONTCARE
, "Marlett");
114 hFont2
= CreateFontA(8, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, SYMBOL_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|FF_DONTCARE
, "Marlett");
116 GetClientRect(hCombo
, &r
);
117 expect_rect(r
, 0, 0, 100, font_height(GetStockObject(SYSTEM_FONT
)) + 8);
118 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&r
);
119 MapWindowPoints(HWND_DESKTOP
, hMainWnd
, (LPPOINT
)&r
, 2);
120 todo_wine
expect_rect(r
, 5, 5, 105, 105);
122 /* The size of the dropped control is initially equal to the size
123 of the window when it was created. The size of the calculated
124 dropped area changes only by how much the selection area
125 changes, not by how much the list area changes. */
126 if (font_height(hFont1
) == 10 && font_height(hFont2
) == 8)
128 SendMessageA(hCombo
, WM_SETFONT
, (WPARAM
)hFont1
, FALSE
);
129 GetClientRect(hCombo
, &r
);
130 expect_rect(r
, 0, 0, 100, 18);
131 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&r
);
132 MapWindowPoints(HWND_DESKTOP
, hMainWnd
, (LPPOINT
)&r
, 2);
133 todo_wine
expect_rect(r
, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT
)) - font_height(hFont1
)));
135 SendMessageA(hCombo
, WM_SETFONT
, (WPARAM
)hFont2
, FALSE
);
136 GetClientRect(hCombo
, &r
);
137 expect_rect(r
, 0, 0, 100, 16);
138 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&r
);
139 MapWindowPoints(HWND_DESKTOP
, hMainWnd
, (LPPOINT
)&r
, 2);
140 todo_wine
expect_rect(r
, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT
)) - font_height(hFont2
)));
142 SendMessageA(hCombo
, WM_SETFONT
, (WPARAM
)hFont1
, FALSE
);
143 GetClientRect(hCombo
, &r
);
144 expect_rect(r
, 0, 0, 100, 18);
145 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&r
);
146 MapWindowPoints(HWND_DESKTOP
, hMainWnd
, (LPPOINT
)&r
, 2);
147 todo_wine
expect_rect(r
, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT
)) - font_height(hFont1
)));
151 ok(0, "Expected Marlett font heights 10/8, got %d/%d\n",
152 font_height(hFont1
), font_height(hFont2
));
155 for (i
= 1; i
< 30; i
++)
157 HFONT hFont
= CreateFontA(i
, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, SYMBOL_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|FF_DONTCARE
, "Marlett");
158 int height
= font_height(hFont
);
160 SendMessageA(hCombo
, WM_SETFONT
, (WPARAM
)hFont
, FALSE
);
161 GetClientRect(hCombo
, &r
);
162 expect_eq(r
.bottom
- r
.top
, height
+ 8, int, "%d");
163 SendMessageA(hCombo
, WM_SETFONT
, 0, FALSE
);
167 DestroyWindow(hCombo
);
168 DeleteObject(hFont1
);
169 DeleteObject(hFont2
);
172 static LRESULT (CALLBACK
*old_parent_proc
)(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
);
173 static LPCSTR expected_edit_text
;
174 static LPCSTR expected_list_text
;
175 static BOOL selchange_fired
;
177 static LRESULT CALLBACK
parent_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
184 case MAKEWPARAM(COMBO_ID
, CBN_SELCHANGE
):
186 HWND hCombo
= (HWND
)lparam
;
188 char list
[20], edit
[20];
190 memset(list
, 0, sizeof(list
));
191 memset(edit
, 0, sizeof(edit
));
193 idx
= SendMessageA(hCombo
, CB_GETCURSEL
, 0, 0);
194 SendMessageA(hCombo
, CB_GETLBTEXT
, idx
, (LPARAM
)list
);
195 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(edit
), (LPARAM
)edit
);
197 ok(!strcmp(edit
, expected_edit_text
), "edit: got %s, expected %s\n",
198 edit
, expected_edit_text
);
199 ok(!strcmp(list
, expected_list_text
), "list: got %s, expected %s\n",
200 list
, expected_list_text
);
202 selchange_fired
= TRUE
;
209 return CallWindowProcA(old_parent_proc
, hwnd
, msg
, wparam
, lparam
);
212 static void test_selection(DWORD style
, const char * const text
[],
213 const int *edit
, const int *list
)
218 hCombo
= build_combo(style
);
220 SendMessageA(hCombo
, CB_ADDSTRING
, 0, (LPARAM
)text
[0]);
221 SendMessageA(hCombo
, CB_ADDSTRING
, 0, (LPARAM
)text
[1]);
222 SendMessageA(hCombo
, CB_SETCURSEL
, -1, 0);
224 old_parent_proc
= (void *)SetWindowLongPtrA(hMainWnd
, GWLP_WNDPROC
, (ULONG_PTR
)parent_wnd_proc
);
226 idx
= SendMessageA(hCombo
, CB_GETCURSEL
, 0, 0);
227 ok(idx
== -1, "expected selection -1, got %d\n", idx
);
229 /* keyboard navigation */
231 expected_list_text
= text
[list
[0]];
232 expected_edit_text
= text
[edit
[0]];
233 selchange_fired
= FALSE
;
234 SendMessageA(hCombo
, WM_KEYDOWN
, VK_DOWN
, 0);
235 ok(selchange_fired
, "CBN_SELCHANGE not sent!\n");
237 expected_list_text
= text
[list
[1]];
238 expected_edit_text
= text
[edit
[1]];
239 selchange_fired
= FALSE
;
240 SendMessageA(hCombo
, WM_KEYDOWN
, VK_DOWN
, 0);
241 ok(selchange_fired
, "CBN_SELCHANGE not sent!\n");
243 expected_list_text
= text
[list
[2]];
244 expected_edit_text
= text
[edit
[2]];
245 selchange_fired
= FALSE
;
246 SendMessageA(hCombo
, WM_KEYDOWN
, VK_UP
, 0);
247 ok(selchange_fired
, "CBN_SELCHANGE not sent!\n");
249 /* programmatic navigation */
251 expected_list_text
= text
[list
[3]];
252 expected_edit_text
= text
[edit
[3]];
253 selchange_fired
= FALSE
;
254 SendMessageA(hCombo
, CB_SETCURSEL
, list
[3], 0);
255 ok(!selchange_fired
, "CBN_SELCHANGE sent!\n");
257 expected_list_text
= text
[list
[4]];
258 expected_edit_text
= text
[edit
[4]];
259 selchange_fired
= FALSE
;
260 SendMessageA(hCombo
, CB_SETCURSEL
, list
[4], 0);
261 ok(!selchange_fired
, "CBN_SELCHANGE sent!\n");
263 SetWindowLongPtrA(hMainWnd
, GWLP_WNDPROC
, (ULONG_PTR
)old_parent_proc
);
264 DestroyWindow(hCombo
);
267 static void test_CBN_SELCHANGE(void)
269 static const char * const text
[] = { "alpha", "beta", "" };
270 static const int sel_1
[] = { 2, 0, 1, 0, 1 };
271 static const int sel_2
[] = { 0, 1, 0, 0, 1 };
273 test_selection(CBS_SIMPLE
, text
, sel_1
, sel_2
);
274 test_selection(CBS_DROPDOWN
, text
, sel_1
, sel_2
);
275 test_selection(CBS_DROPDOWNLIST
, text
, sel_2
, sel_2
);
278 static void test_WM_LBUTTONDOWN(void)
280 HWND hCombo
, hEdit
, hList
;
282 UINT x
, y
, item_height
;
287 static const UINT choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
288 static const CHAR stringFormat
[] = "%2d";
291 hCombo
= CreateWindowA("ComboBox", "Combo", WS_VISIBLE
|WS_CHILD
|CBS_DROPDOWN
,
292 0, 0, 200, 150, hMainWnd
, (HMENU
)COMBO_ID
, NULL
, 0);
294 for (i
= 0; i
< ARRAY_SIZE(choices
); i
++){
295 sprintf(buffer
, stringFormat
, choices
[i
]);
296 result
= SendMessageA(hCombo
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
298 "Failed to add item %d\n", i
);
301 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
302 SetLastError(0xdeadbeef);
303 ret
= GetComboBoxInfo(hCombo
, &cbInfo
);
304 ok(ret
, "Failed to get combobox info structure. LastError=%d\n",
306 hEdit
= cbInfo
.hwndItem
;
307 hList
= cbInfo
.hwndList
;
309 trace("hMainWnd=%p, hCombo=%p, hList=%p, hEdit=%p\n", hMainWnd
, hCombo
, hList
, hEdit
);
310 ok(GetFocus() == hMainWnd
, "Focus not on Main Window, instead on %p\n", GetFocus());
312 /* Click on the button to drop down the list */
313 x
= cbInfo
.rcButton
.left
+ (cbInfo
.rcButton
.right
-cbInfo
.rcButton
.left
)/2;
314 y
= cbInfo
.rcButton
.top
+ (cbInfo
.rcButton
.bottom
-cbInfo
.rcButton
.top
)/2;
315 result
= SendMessageA(hCombo
, WM_LBUTTONDOWN
, 0, MAKELPARAM(x
, y
));
316 ok(result
, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
318 ok(SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0),
319 "The dropdown list should have appeared after clicking the button.\n");
321 ok(GetFocus() == hEdit
,
322 "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
323 result
= SendMessageA(hCombo
, WM_LBUTTONUP
, 0, MAKELPARAM(x
, y
));
324 ok(result
, "WM_LBUTTONUP was not processed. LastError=%d\n",
326 ok(GetFocus() == hEdit
,
327 "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
329 /* Click on the 5th item in the list */
330 item_height
= SendMessageA(hCombo
, CB_GETITEMHEIGHT
, 0, 0);
331 ok(GetClientRect(hList
, &rect
), "Failed to get list's client rect.\n");
332 x
= rect
.left
+ (rect
.right
-rect
.left
)/2;
333 y
= item_height
/2 + item_height
*4;
334 result
= SendMessageA(hList
, WM_LBUTTONDOWN
, 0, MAKELPARAM(x
, y
));
335 ok(!result
, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
337 ok(GetFocus() == hEdit
,
338 "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
340 result
= SendMessageA(hList
, WM_MOUSEMOVE
, 0, MAKELPARAM(x
, y
));
341 ok(!result
, "WM_MOUSEMOVE was not processed. LastError=%d\n",
343 ok(GetFocus() == hEdit
,
344 "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
345 ok(SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0),
346 "The dropdown list should still be visible.\n");
348 result
= SendMessageA(hList
, WM_LBUTTONUP
, 0, MAKELPARAM(x
, y
));
349 ok(!result
, "WM_LBUTTONUP was not processed. LastError=%d\n",
351 ok(GetFocus() == hEdit
,
352 "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
353 ok(!SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0),
354 "The dropdown list should have been rolled up.\n");
355 idx
= SendMessageA(hCombo
, CB_GETCURSEL
, 0, 0);
356 ok(idx
, "Current Selection: expected %d, got %d\n", 4, idx
);
358 DestroyWindow(hCombo
);
361 static void test_changesize( DWORD style
)
363 HWND hCombo
= build_combo(style
);
365 INT ddheight
, clheight
, ddwidth
, clwidth
;
366 /* get initial measurements */
367 GetClientRect( hCombo
, &rc
);
368 clheight
= rc
.bottom
- rc
.top
;
369 clwidth
= rc
.right
- rc
.left
;
370 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&rc
);
371 ddheight
= rc
.bottom
- rc
.top
;
372 ddwidth
= rc
.right
- rc
.left
;
373 /* use MoveWindow to move & resize the combo */
374 /* first make it slightly smaller */
375 MoveWindow( hCombo
, 10, 10, clwidth
- 2, clheight
- 2, TRUE
);
376 GetClientRect( hCombo
, &rc
);
377 ok( rc
.right
- rc
.left
== clwidth
- 2, "clientrect width is %d vs %d\n",
378 rc
.right
- rc
.left
, clwidth
- 2);
379 ok( rc
.bottom
- rc
.top
== clheight
, "clientrect height is %d vs %d\n",
380 rc
.bottom
- rc
.top
, clheight
);
381 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&rc
);
382 ok( rc
.right
- rc
.left
== clwidth
- 2, "drop-down rect width is %d vs %d\n",
383 rc
.right
- rc
.left
, clwidth
- 2);
384 ok( rc
.bottom
- rc
.top
== ddheight
, "drop-down rect height is %d vs %d\n",
385 rc
.bottom
- rc
.top
, ddheight
);
386 ok( rc
.right
- rc
.left
== ddwidth
-2, "drop-down rect width is %d vs %d\n",
387 rc
.right
- rc
.left
, ddwidth
- 2);
388 /* new cx, cy is slightly bigger than the initial values */
389 MoveWindow( hCombo
, 10, 10, clwidth
+ 2, clheight
+ 2, TRUE
);
390 GetClientRect( hCombo
, &rc
);
391 ok( rc
.right
- rc
.left
== clwidth
+ 2, "clientrect width is %d vs %d\n",
392 rc
.right
- rc
.left
, clwidth
+ 2);
393 ok( rc
.bottom
- rc
.top
== clheight
, "clientrect height is %d vs %d\n",
394 rc
.bottom
- rc
.top
, clheight
);
395 SendMessageA(hCombo
, CB_GETDROPPEDCONTROLRECT
, 0, (LPARAM
)&rc
);
396 ok( rc
.right
- rc
.left
== clwidth
+ 2, "drop-down rect width is %d vs %d\n",
397 rc
.right
- rc
.left
, clwidth
+ 2);
399 ok( rc
.bottom
- rc
.top
== clheight
+ 2, "drop-down rect height is %d vs %d\n",
400 rc
.bottom
- rc
.top
, clheight
+ 2);
403 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, -1, 0);
404 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
405 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
406 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
408 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, 0, 0);
409 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
410 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
411 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
413 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, clwidth
- 1, 0);
414 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
415 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
416 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
418 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, clwidth
<< 1, 0);
419 ok( ddwidth
== (clwidth
<< 1), "drop-width is %d vs %d\n", ddwidth
, clwidth
<< 1);
420 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
421 ok( ddwidth
== (clwidth
<< 1), "drop-width is %d vs %d\n", ddwidth
, clwidth
<< 1);
423 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, 0, 0);
424 ok( ddwidth
== (clwidth
<< 1), "drop-width is %d vs %d\n", ddwidth
, clwidth
<< 1);
425 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
426 ok( ddwidth
== (clwidth
<< 1), "drop-width is %d vs %d\n", ddwidth
, clwidth
<< 1);
428 ddwidth
= SendMessageA(hCombo
, CB_SETDROPPEDWIDTH
, 1, 0);
429 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
430 ddwidth
= SendMessageA(hCombo
, CB_GETDROPPEDWIDTH
, 0, 0);
431 ok( ddwidth
== clwidth
+ 2, "drop-width is %d vs %d\n", ddwidth
, clwidth
+ 2);
433 DestroyWindow(hCombo
);
436 static void test_editselection(void)
447 hCombo
= build_combo(CBS_SIMPLE
);
448 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
449 SetLastError(0xdeadbeef);
450 ret
= GetComboBoxInfo(hCombo
, &cbInfo
);
451 ok(ret
, "Failed to get combobox info structure. LastError=%d\n",
453 hEdit
= cbInfo
.hwndItem
;
455 /* Initially combo selection is empty*/
456 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
457 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
458 ok(HIWORD(len
)==0, "Unexpected end position for selection %d\n", HIWORD(len
));
460 /* Set some text, and press a key to replace it */
462 SendMessageA(hCombo
, WM_SETTEXT
, 0, (LPARAM
)"Jason1");
463 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(edit
), (LPARAM
)edit
);
464 ok(strcmp(edit
, "Jason1")==0, "Unexpected text retrieved %s\n", edit
);
466 /* Now what is the selection - still empty */
467 SendMessageA(hCombo
, CB_GETEDITSEL
, (WPARAM
)&start
, (WPARAM
)&end
);
468 ok(start
==0, "Unexpected start position for selection %d\n", start
);
469 ok(end
==0, "Unexpected end position for selection %d\n", end
);
470 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
471 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
472 ok(HIWORD(len
)==0, "Unexpected end position for selection %d\n", HIWORD(len
));
474 /* Give it focus, and it gets selected */
475 SendMessageA(hCombo
, WM_SETFOCUS
, 0, (LPARAM
)hEdit
);
476 SendMessageA(hCombo
, CB_GETEDITSEL
, (WPARAM
)&start
, (WPARAM
)&end
);
477 ok(start
==0, "Unexpected start position for selection %d\n", start
);
478 ok(end
==6, "Unexpected end position for selection %d\n", end
);
479 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
480 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
481 ok(HIWORD(len
)==6, "Unexpected end position for selection %d\n", HIWORD(len
));
483 /* Now emulate a key press */
485 SendMessageA(hCombo
, WM_CHAR
, 'A', 0x1c0001);
486 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(edit
), (LPARAM
)edit
);
487 ok(strcmp(edit
, "A")==0, "Unexpected text retrieved %s\n", edit
);
489 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
490 ok(LOWORD(len
)==1, "Unexpected start position for selection %d\n", LOWORD(len
));
491 ok(HIWORD(len
)==1, "Unexpected end position for selection %d\n", HIWORD(len
));
493 /* Now what happens when it gets more focus a second time - it doesn't reselect */
494 SendMessageA(hCombo
, WM_SETFOCUS
, 0, (LPARAM
)hEdit
);
495 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
496 ok(LOWORD(len
)==1, "Unexpected start position for selection %d\n", LOWORD(len
));
497 ok(HIWORD(len
)==1, "Unexpected end position for selection %d\n", HIWORD(len
));
498 DestroyWindow(hCombo
);
500 /* Start again - Build a combo */
501 hCombo
= build_combo(CBS_SIMPLE
);
502 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
503 SetLastError(0xdeadbeef);
504 ret
= GetComboBoxInfo(hCombo
, &cbInfo
);
505 ok(ret
, "Failed to get combobox info structure. LastError=%d\n",
507 hEdit
= cbInfo
.hwndItem
;
509 /* Set some text and give focus so it gets selected */
511 SendMessageA(hCombo
, WM_SETTEXT
, 0, (LPARAM
)"Jason2");
512 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(edit
), (LPARAM
)edit
);
513 ok(strcmp(edit
, "Jason2")==0, "Unexpected text retrieved %s\n", edit
);
515 SendMessageA(hCombo
, WM_SETFOCUS
, 0, (LPARAM
)hEdit
);
517 /* Now what is the selection */
518 SendMessageA(hCombo
, CB_GETEDITSEL
, (WPARAM
)&start
, (WPARAM
)&end
);
519 ok(start
==0, "Unexpected start position for selection %d\n", start
);
520 ok(end
==6, "Unexpected end position for selection %d\n", end
);
521 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0,0);
522 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
523 ok(HIWORD(len
)==6, "Unexpected end position for selection %d\n", HIWORD(len
));
525 /* Now change the selection to the apparently invalid start -1, end -1 and
526 show it means no selection (ie start -1) but cursor at end */
527 SendMessageA(hCombo
, CB_SETEDITSEL
, 0, -1);
529 SendMessageA(hCombo
, WM_CHAR
, 'A', 0x1c0001);
530 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(edit
), (LPARAM
)edit
);
531 ok(strcmp(edit
, "Jason2A")==0, "Unexpected text retrieved %s\n", edit
);
532 DestroyWindow(hCombo
);
535 static WNDPROC edit_window_proc
;
536 static long setsel_start
= 1, setsel_end
= 1;
537 static HWND hCBN_SetFocus
, hCBN_KillFocus
;
539 static LRESULT CALLBACK
combobox_subclass_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
541 if (msg
== EM_SETSEL
)
543 setsel_start
= wParam
;
546 return CallWindowProcA(edit_window_proc
, hwnd
, msg
, wParam
, lParam
);
549 static LRESULT CALLBACK
test_window_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
554 switch (HIWORD(wParam
))
557 hCBN_SetFocus
= (HWND
)lParam
;
560 hCBN_KillFocus
= (HWND
)lParam
;
565 SetFocus((HWND
)wParam
);
568 return CallWindowProcA(old_parent_proc
, hwnd
, msg
, wParam
, lParam
);
571 static void test_editselection_focus(DWORD style
)
573 HWND hCombo
, hEdit
, hButton
;
576 const char wine_test
[] = "Wine Test";
577 char buffer
[16] = {0};
580 hCombo
= build_combo(style
);
581 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
582 SetLastError(0xdeadbeef);
583 ret
= GetComboBoxInfo(hCombo
, &cbInfo
);
584 ok(ret
, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
585 hEdit
= cbInfo
.hwndItem
;
587 hButton
= CreateWindowA("Button", "OK", WS_VISIBLE
|WS_CHILD
|BS_DEFPUSHBUTTON
,
588 5, 50, 100, 20, hMainWnd
, NULL
,
589 (HINSTANCE
)GetWindowLongPtrA(hMainWnd
, GWLP_HINSTANCE
), NULL
);
591 old_parent_proc
= (WNDPROC
)SetWindowLongPtrA(hMainWnd
, GWLP_WNDPROC
, (ULONG_PTR
)test_window_proc
);
592 edit_window_proc
= (WNDPROC
)SetWindowLongPtrA(hEdit
, GWLP_WNDPROC
, (ULONG_PTR
)combobox_subclass_proc
);
594 SendMessageA(hCombo
, WM_SETFOCUS
, 0, (LPARAM
)hEdit
);
595 ok(setsel_start
== 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start
);
596 todo_wine
ok(setsel_end
== INT_MAX
, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end
);
597 ok(hCBN_SetFocus
== hCombo
, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus
);
598 ok(GetFocus() == hEdit
, "hEdit should have keyboard focus\n");
600 SendMessageA(hMainWnd
, WM_NEXTDLGCTL
, (WPARAM
)hButton
, TRUE
);
601 ok(setsel_start
== 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start
);
602 todo_wine
ok(setsel_end
== 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end
);
603 ok(hCBN_KillFocus
== hCombo
, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus
);
604 ok(GetFocus() == hButton
, "hButton should have keyboard focus\n");
606 SendMessageA(hCombo
, WM_SETTEXT
, 0, (LPARAM
)wine_test
);
607 SendMessageA(hMainWnd
, WM_NEXTDLGCTL
, (WPARAM
)hCombo
, TRUE
);
608 ok(setsel_start
== 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start
);
609 todo_wine
ok(setsel_end
== INT_MAX
, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end
);
610 ok(hCBN_SetFocus
== hCombo
, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus
);
611 ok(GetFocus() == hEdit
, "hEdit should have keyboard focus\n");
612 SendMessageA(hCombo
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
613 ok(!strcmp(buffer
, wine_test
), "Unexpected text in edit control; got '%s'\n", buffer
);
615 SendMessageA(hMainWnd
, WM_NEXTDLGCTL
, (WPARAM
)hButton
, TRUE
);
616 ok(setsel_start
== 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start
);
617 todo_wine
ok(setsel_end
== 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end
);
618 ok(hCBN_KillFocus
== hCombo
, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus
);
619 ok(GetFocus() == hButton
, "hButton should have keyboard focus\n");
620 len
= SendMessageA(hCombo
, CB_GETEDITSEL
, 0, 0);
621 ok(len
== 0, "Unexpected text selection; start: %u, end: %u\n", LOWORD(len
), HIWORD(len
));
623 SetWindowLongPtrA(hMainWnd
, GWLP_WNDPROC
, (ULONG_PTR
)old_parent_proc
);
624 DestroyWindow(hButton
);
625 DestroyWindow(hCombo
);
628 static void test_listbox_styles(DWORD cb_style
)
632 DWORD style
, exstyle
, expect_style
, expect_exstyle
;
635 expect_style
= WS_CHILD
|WS_CLIPSIBLINGS
|LBS_COMBOBOX
|LBS_HASSTRINGS
|LBS_NOTIFY
;
636 if (cb_style
== CBS_SIMPLE
)
638 expect_style
|= WS_VISIBLE
;
639 expect_exstyle
= WS_EX_CLIENTEDGE
;
643 expect_style
|= WS_BORDER
;
644 expect_exstyle
= WS_EX_TOOLWINDOW
;
647 combo
= build_combo(cb_style
);
648 info
.cbSize
= sizeof(COMBOBOXINFO
);
649 SetLastError(0xdeadbeef);
650 ret
= GetComboBoxInfo(combo
, &info
);
651 ok(ret
, "Failed to get combobox info structure.\n");
653 style
= GetWindowLongW( info
.hwndList
, GWL_STYLE
);
654 exstyle
= GetWindowLongW( info
.hwndList
, GWL_EXSTYLE
);
655 ok(style
== expect_style
, "%08x: got %08x\n", cb_style
, style
);
656 ok(exstyle
== expect_exstyle
, "%08x: got %08x\n", cb_style
, exstyle
);
658 if (cb_style
!= CBS_SIMPLE
)
659 expect_exstyle
|= WS_EX_TOPMOST
;
661 SendMessageW(combo
, CB_SHOWDROPDOWN
, TRUE
, 0 );
662 style
= GetWindowLongW( info
.hwndList
, GWL_STYLE
);
663 exstyle
= GetWindowLongW( info
.hwndList
, GWL_EXSTYLE
);
664 ok(style
== (expect_style
| WS_VISIBLE
), "%08x: got %08x\n", cb_style
, style
);
665 ok(exstyle
== expect_exstyle
, "%08x: got %08x\n", cb_style
, exstyle
);
667 SendMessageW(combo
, CB_SHOWDROPDOWN
, FALSE
, 0 );
668 style
= GetWindowLongW( info
.hwndList
, GWL_STYLE
);
669 exstyle
= GetWindowLongW( info
.hwndList
, GWL_EXSTYLE
);
670 ok(style
== expect_style
, "%08x: got %08x\n", cb_style
, style
);
671 ok(exstyle
== expect_exstyle
, "%08x: got %08x\n", cb_style
, exstyle
);
673 DestroyWindow(combo
);
676 static void test_listbox_size(DWORD style
)
683 const char wine_test
[] = "Wine Test";
685 static const struct list_size_info
712 for(test
= 0; test
< ARRAY_SIZE(info_height
); test
++)
714 const struct list_size_info
*info_test
= &info_height
[test
];
715 int height_item
; /* Height of a list item */
716 int height_list
; /* Height of the list we got */
717 int expected_count_list
;
718 int expected_height_list
;
719 int list_height_nonclient
;
720 int list_height_calculated
;
721 RECT rect_list_client
, rect_list_complete
;
723 hCombo
= CreateWindowA("ComboBox", "Combo", WS_VISIBLE
|WS_CHILD
|style
, 5, 5, 100,
724 info_test
->height_combo
, hMainWnd
, (HMENU
)COMBO_ID
, NULL
, 0);
726 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
727 SetLastError(0xdeadbeef);
728 ret
= GetComboBoxInfo(hCombo
, &cbInfo
);
729 ok(ret
, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
731 hList
= cbInfo
.hwndList
;
732 for (i
= 0; i
< info_test
->num_items
; i
++)
733 SendMessageA(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) wine_test
);
735 /* Click on the button to drop down the list */
736 x
= cbInfo
.rcButton
.left
+ (cbInfo
.rcButton
.right
-cbInfo
.rcButton
.left
)/2;
737 y
= cbInfo
.rcButton
.top
+ (cbInfo
.rcButton
.bottom
-cbInfo
.rcButton
.top
)/2;
738 ret
= SendMessageA(hCombo
, WM_LBUTTONDOWN
, 0, MAKELPARAM(x
, y
));
739 ok(ret
, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
741 ok(SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0),
742 "The dropdown list should have appeared after clicking the button.\n");
744 GetClientRect(hList
, &rect_list_client
);
745 GetWindowRect(hList
, &rect_list_complete
);
746 height_list
= rect_list_client
.bottom
- rect_list_client
.top
;
747 height_item
= (int)SendMessageA(hList
, LB_GETITEMHEIGHT
, 0, 0);
749 list_height_nonclient
= (rect_list_complete
.bottom
- rect_list_complete
.top
)
750 - (rect_list_client
.bottom
- rect_list_client
.top
);
752 /* Calculate the expected client size of the listbox popup from the size of the combobox. */
753 list_height_calculated
= info_test
->height_combo
754 - (cbInfo
.rcItem
.bottom
+ COMBO_YBORDERSIZE())
755 - list_height_nonclient
758 expected_count_list
= list_height_calculated
/ height_item
;
759 if(expected_count_list
< 0)
760 expected_count_list
= 0;
761 expected_count_list
= min(expected_count_list
, info_test
->num_items
);
762 expected_height_list
= expected_count_list
* height_item
;
764 todo_wine_if(info_test
->todo
)
765 ok(expected_height_list
== height_list
,
766 "Test %d, expected list height to be %d, got %d\n", test
, expected_height_list
, height_list
);
768 DestroyWindow(hCombo
);
772 static void test_WS_VSCROLL(void)
780 info
.cbSize
= sizeof(info
);
781 hCombo
= build_combo(CBS_DROPDOWNLIST
);
783 SetLastError(0xdeadbeef);
784 ret
= GetComboBoxInfo(hCombo
, &info
);
785 ok(ret
, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
786 hList
= info
.hwndList
;
788 for(i
= 0; i
< 3; i
++)
791 sprintf(buffer
, "%d", i
);
792 SendMessageA(hCombo
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
795 style
= GetWindowLongA(info
.hwndList
, GWL_STYLE
);
796 SetWindowLongA(hList
, GWL_STYLE
, style
| WS_VSCROLL
);
798 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, TRUE
, 0);
799 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, FALSE
, 0);
801 style
= GetWindowLongA(hList
, GWL_STYLE
);
802 ok((style
& WS_VSCROLL
) != 0, "Style does not include WS_VSCROLL\n");
804 DestroyWindow(hCombo
);
809 hMainWnd
= CreateWindowA("static", "Test", WS_OVERLAPPEDWINDOW
, 10, 10, 300, 300, NULL
, NULL
, NULL
, 0);
810 ShowWindow(hMainWnd
, SW_SHOW
);
813 test_setfont(CBS_DROPDOWN
);
814 test_setfont(CBS_DROPDOWNLIST
);
815 test_setitemheight(CBS_DROPDOWN
);
816 test_setitemheight(CBS_DROPDOWNLIST
);
817 test_CBN_SELCHANGE();
818 test_WM_LBUTTONDOWN();
819 test_changesize(CBS_DROPDOWN
);
820 test_changesize(CBS_DROPDOWNLIST
);
821 test_editselection();
822 test_editselection_focus(CBS_SIMPLE
);
823 test_editselection_focus(CBS_DROPDOWN
);
824 test_listbox_styles(CBS_SIMPLE
);
825 test_listbox_styles(CBS_DROPDOWN
);
826 test_listbox_styles(CBS_DROPDOWNLIST
);
827 test_listbox_size(CBS_DROPDOWN
);
829 DestroyWindow(hMainWnd
);