[COMCTL32_WINETEST] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / rostests / winetests / comctl32 / button.c
1 /* Unit test suite for Button control.
2 *
3 * Copyright 1999 Ove Kaaven
4 * Copyright 2003 Dimitrie O. Paun
5 * Copyright 2004, 2005 Dmitry Timoshkov
6 * Copyright 2014 Nikolay Sivov for CodeWeavers
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #undef USE_WINE_TODOS
24
25 //#include <windows.h>
26 #include <stdarg.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <wingdi.h>
30 #include <winuser.h>
31 #include <commctrl.h>
32
33 #include "wine/test.h"
34 #include "v6util.h"
35 #include "msg.h"
36
37 #define IS_WNDPROC_HANDLE(x) (((ULONG_PTR)(x) >> 16) == (~0u >> 16))
38
39 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
40 static BOOL (WINAPI *pRemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR);
41 static LRESULT (WINAPI *pDefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
42
43 /****************** button message test *************************/
44 #define ID_BUTTON 0x000e
45
46 #define COMBINED_SEQ_INDEX 0
47 #define NUM_MSG_SEQUENCES 1
48
49 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
50
51 struct wndclass_redirect_data
52 {
53 ULONG size;
54 DWORD res;
55 ULONG name_len;
56 ULONG name_offset;
57 ULONG module_len;
58 ULONG module_offset;
59 };
60
61 /* returned pointer is valid as long as activation context is alive */
62 static WCHAR* get_versioned_classname(const WCHAR *name)
63 {
64 BOOL (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
65 struct wndclass_redirect_data *wnddata;
66 ACTCTX_SECTION_KEYED_DATA data;
67 BOOL ret;
68
69 pFindActCtxSectionStringW = (void*)GetProcAddress(GetModuleHandleA("kernel32"), "FindActCtxSectionStringW");
70
71 memset(&data, 0, sizeof(data));
72 data.cbSize = sizeof(data);
73
74 ret = pFindActCtxSectionStringW(0, NULL,
75 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
76 name, &data);
77 ok(ret, "got %d, error %u\n", ret, GetLastError());
78 wnddata = (struct wndclass_redirect_data*)data.lpData;
79 return (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
80 }
81
82 static void init_functions(void)
83 {
84 HMODULE hmod = GetModuleHandleA("comctl32.dll");
85 ok(hmod != NULL, "got %p\n", hmod);
86
87 #define MAKEFUNC_ORD(f, ord) (p##f = (void*)GetProcAddress(hmod, (LPSTR)(ord)))
88 MAKEFUNC_ORD(SetWindowSubclass, 410);
89 MAKEFUNC_ORD(RemoveWindowSubclass, 412);
90 MAKEFUNC_ORD(DefSubclassProc, 413);
91 #undef MAKEFUNC_ORD
92 }
93
94 /* try to make sure pending X events have been processed before continuing */
95 static void flush_events(void)
96 {
97 MSG msg;
98 int diff = 200;
99 int min_timeout = 100;
100 DWORD time = GetTickCount() + diff;
101
102 while (diff > 0)
103 {
104 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
105 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
106 diff = time - GetTickCount();
107 }
108 }
109
110 static BOOL ignore_message( UINT message )
111 {
112 /* these are always ignored */
113 return (message >= 0xc000 ||
114 message == WM_GETICON ||
115 message == WM_GETOBJECT ||
116 message == WM_TIMECHANGE ||
117 message == WM_DISPLAYCHANGE ||
118 message == WM_DEVICECHANGE ||
119 message == WM_DWMNCRENDERINGCHANGED ||
120 message == WM_GETTEXTLENGTH ||
121 message == WM_GETTEXT);
122 }
123
124 static LRESULT CALLBACK button_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR ref_data)
125 {
126 static LONG defwndproc_counter = 0;
127 struct message msg = { 0 };
128 LRESULT ret;
129
130 if (ignore_message( message )) return pDefSubclassProc(hwnd, message, wParam, lParam);
131
132 switch (message)
133 {
134 case WM_SYNCPAINT:
135 break;
136 case BM_SETSTATE:
137 if (GetCapture())
138 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
139 /* fall through */
140 default:
141 msg.message = message;
142 msg.flags = sent|wparam|lparam;
143 if (defwndproc_counter) msg.flags |= defwinproc;
144 msg.wParam = wParam;
145 msg.lParam = lParam;
146 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
147 }
148
149 if (message == WM_NCDESTROY)
150 pRemoveWindowSubclass(hwnd, button_subclass_proc, 0);
151
152 defwndproc_counter++;
153 ret = pDefSubclassProc(hwnd, message, wParam, lParam);
154 defwndproc_counter--;
155
156 return ret;
157 }
158
159 static LRESULT WINAPI test_parent_wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
160 {
161 static LONG defwndproc_counter = 0;
162 static LONG beginpaint_counter = 0;
163 struct message msg = { 0 };
164 LRESULT ret;
165
166 if (ignore_message( message )) return 0;
167
168 if (message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
169 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
170 message == WM_ENABLE || message == WM_ENTERIDLE ||
171 message == WM_DRAWITEM || message == WM_COMMAND ||
172 message == WM_IME_SETCONTEXT)
173 {
174 msg.message = message;
175 msg.flags = sent|parent|wparam|lparam;
176 if (defwndproc_counter) msg.flags |= defwinproc;
177 if (beginpaint_counter) msg.flags |= beginpaint;
178 msg.wParam = wParam;
179 msg.lParam = lParam;
180 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
181 }
182
183 if (message == WM_PAINT)
184 {
185 PAINTSTRUCT ps;
186 beginpaint_counter++;
187 BeginPaint( hwnd, &ps );
188 beginpaint_counter--;
189 EndPaint( hwnd, &ps );
190 return 0;
191 }
192
193 defwndproc_counter++;
194 ret = DefWindowProcA(hwnd, message, wParam, lParam);
195 defwndproc_counter--;
196
197 return ret;
198 }
199
200 static const struct message setfocus_seq[] =
201 {
202 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
203 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
204 { BM_GETSTATE, sent|optional }, /* when touchscreen is present */
205 { WM_SETFOCUS, sent|wparam },
206 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
207 { WM_APP, sent|wparam|lparam },
208 { WM_PAINT, sent },
209 { 0 }
210 };
211
212 static const struct message killfocus_seq[] =
213 {
214 { WM_KILLFOCUS, sent|wparam, 0 },
215 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
216 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
217 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
218 { WM_APP, sent|wparam|lparam, 0, 0 },
219 { WM_PAINT, sent },
220 { 0 }
221 };
222
223 static const struct message setfocus_static_seq[] =
224 {
225 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
226 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
227 { BM_GETSTATE, sent|optional }, /* when touchscreen is present */
228 { WM_SETFOCUS, sent|wparam, 0 },
229 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
230 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
231 { WM_APP, sent|wparam|lparam, 0, 0 },
232 { WM_PAINT, sent },
233 { 0 }
234 };
235
236 static const struct message setfocus_groupbox_seq[] =
237 {
238 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
239 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
240 { BM_GETSTATE, sent|optional }, /* when touchscreen is present */
241 { WM_SETFOCUS, sent|wparam, 0 },
242 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
243 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
244 { WM_APP, sent|wparam|lparam, 0, 0 },
245 { WM_PAINT, sent },
246 { 0 }
247 };
248
249 static const struct message killfocus_static_seq[] =
250 {
251 { WM_KILLFOCUS, sent|wparam, 0 },
252 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
253 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
254 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
255 { WM_APP, sent|wparam|lparam, 0, 0 },
256 { WM_PAINT, sent },
257 { 0 }
258 };
259
260 static const struct message setfocus_ownerdraw_seq[] =
261 {
262 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
263 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
264 { BM_GETSTATE, sent|optional }, /* when touchscreen is present */
265 { WM_SETFOCUS, sent|wparam, 0 },
266 { WM_DRAWITEM, sent|wparam|parent, ID_BUTTON },
267 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
268 { WM_APP, sent|wparam|lparam, 0, 0 },
269 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
270 { 0 }
271 };
272
273 static const struct message killfocus_ownerdraw_seq[] =
274 {
275 { WM_KILLFOCUS, sent|wparam, 0 },
276 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
277 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
278 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
279 { WM_APP, sent|wparam|lparam, 0, 0 },
280 { WM_PAINT, sent },
281 { WM_DRAWITEM, sent|wparam|parent, ID_BUTTON },
282 { 0 }
283 };
284
285 static const struct message lbuttondown_seq[] =
286 {
287 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
288 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
289 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
290 { BM_GETSTATE, sent|defwinproc|optional }, /* when touchscreen is present */
291 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
292 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
293 { 0 }
294 };
295
296 static const struct message lbuttonup_seq[] =
297 {
298 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
299 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
300 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
301 { WM_COMMAND, sent|wparam|defwinproc, 0 },
302 { 0 }
303 };
304
305 static const struct message setfont_seq[] =
306 {
307 { WM_SETFONT, sent },
308 { 0 }
309 };
310
311 static const struct message setstyle_seq[] =
312 {
313 { BM_SETSTYLE, sent },
314 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
315 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
316 { WM_APP, sent|wparam|lparam, 0, 0 },
317 { WM_PAINT, sent },
318 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
319 { WM_ERASEBKGND, sent|defwinproc|optional },
320 { WM_PAINT, sent|optional },
321 { 0 }
322 };
323
324 static const struct message setstyle_static_seq[] =
325 {
326 { BM_SETSTYLE, sent },
327 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
328 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
329 { WM_APP, sent|wparam|lparam, 0, 0 },
330 { WM_PAINT, sent },
331 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
332 { WM_ERASEBKGND, sent|defwinproc|optional },
333 { 0 }
334 };
335
336 static const struct message setstyle_user_seq[] =
337 {
338 { BM_SETSTYLE, sent },
339 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
340 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
341 { WM_APP, sent|wparam|lparam, 0, 0 },
342 { WM_PAINT, sent },
343 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
344 { WM_ERASEBKGND, sent|defwinproc|optional },
345 { 0 }
346 };
347
348 static const struct message setstyle_ownerdraw_seq[] =
349 {
350 { BM_SETSTYLE, sent },
351 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
352 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
353 { WM_APP, sent|wparam|lparam, 0, 0 },
354 { WM_PAINT, sent },
355 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
356 { WM_ERASEBKGND, sent|defwinproc|optional },
357 { WM_DRAWITEM, sent|wparam|parent, ID_BUTTON },
358 { 0 }
359 };
360
361 static const struct message setstate_seq[] =
362 {
363 { BM_SETSTATE, sent },
364 { WM_APP, sent|wparam|lparam, 0, 0 },
365 { WM_PAINT, sent },
366 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
367 { WM_ERASEBKGND, sent|defwinproc|optional },
368 { WM_PAINT, sent|optional },
369 { 0 }
370 };
371
372 static const struct message setstate_static_seq[] =
373 {
374 { BM_SETSTATE, sent },
375 { WM_APP, sent|wparam|lparam, 0, 0 },
376 { WM_PAINT, sent },
377 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
378 { WM_ERASEBKGND, sent|defwinproc|optional },
379 { 0 }
380 };
381
382 static const struct message setstate_user_seq[] =
383 {
384 { BM_SETSTATE, sent },
385 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
386 { WM_APP, sent|wparam|lparam, 0, 0 },
387 { WM_PAINT, sent },
388 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
389 { WM_ERASEBKGND, sent|defwinproc|optional },
390 { 0 }
391 };
392
393 static const struct message setstate_ownerdraw_seq[] =
394 {
395 { BM_SETSTATE, sent },
396 { WM_APP, sent|wparam|lparam, 0, 0 },
397 { WM_PAINT, sent },
398 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
399 { WM_ERASEBKGND, sent|defwinproc|optional },
400 { WM_DRAWITEM, sent|wparam|parent, ID_BUTTON },
401 { 0 }
402 };
403
404 static const struct message clearstate_seq[] =
405 {
406 { BM_SETSTATE, sent },
407 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
408 { WM_APP, sent|wparam|lparam, 0, 0 },
409 { WM_PAINT, sent },
410 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
411 { WM_ERASEBKGND, sent|defwinproc|optional },
412 { 0 }
413 };
414
415 static const struct message clearstate_ownerdraw_seq[] =
416 {
417 { BM_SETSTATE, sent },
418 { WM_APP, sent|wparam|lparam, 0, 0 },
419 { WM_PAINT, sent },
420 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
421 { WM_ERASEBKGND, sent|defwinproc|optional },
422 { WM_DRAWITEM, sent|wparam|parent, ID_BUTTON },
423 { 0 }
424 };
425
426 static const struct message setcheck_ignored_seq[] =
427 {
428 { BM_SETCHECK, sent },
429 { WM_APP, sent|wparam|lparam, 0, 0 },
430 { WM_PAINT, sent|optional },
431 { 0 }
432 };
433
434 static const struct message setcheck_static_seq[] =
435 {
436 { BM_SETCHECK, sent },
437 { WM_APP, sent|wparam|lparam, 0, 0 },
438 { WM_PAINT, sent },
439 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
440 { WM_ERASEBKGND, sent|defwinproc|optional },
441 { 0 }
442 };
443
444 static const struct message setcheck_radio_seq[] =
445 {
446 { BM_SETCHECK, sent },
447 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
448 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
449 { WM_APP, sent|wparam|lparam, 0, 0 },
450 { 0 }
451 };
452
453 static const struct message setcheck_radio_redraw_seq[] =
454 {
455 { BM_SETCHECK, sent },
456 { WM_STYLECHANGING, sent|wparam|defwinproc, GWL_STYLE },
457 { WM_STYLECHANGED, sent|wparam|defwinproc, GWL_STYLE },
458 { WM_APP, sent|wparam|lparam, 0, 0 },
459 { WM_PAINT, sent },
460 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
461 { WM_ERASEBKGND, sent|defwinproc|optional },
462 { 0 }
463 };
464
465 static HWND create_button(DWORD style, HWND parent)
466 {
467 HMENU menuid = 0;
468 HWND hwnd;
469
470 if (parent)
471 {
472 style |= WS_CHILD|BS_NOTIFY;
473 menuid = (HMENU)ID_BUTTON;
474 }
475 hwnd = CreateWindowExA(0, "Button", "test", style, 0, 0, 50, 14, parent, menuid, 0, NULL);
476 ok(hwnd != NULL, "failed to create a button, 0x%08x, %p\n", style, parent);
477 pSetWindowSubclass(hwnd, button_subclass_proc, 0, 0);
478 return hwnd;
479 }
480
481 static void test_button_messages(void)
482 {
483 static const struct
484 {
485 DWORD style;
486 DWORD dlg_code;
487 const struct message *setfocus;
488 const struct message *killfocus;
489 const struct message *setstyle;
490 const struct message *setstate;
491 const struct message *clearstate;
492 const struct message *setcheck;
493 } button[] = {
494 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
495 setfocus_seq, killfocus_seq, setstyle_seq,
496 setstate_seq, setstate_seq, setcheck_ignored_seq },
497 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
498 setfocus_seq, killfocus_seq, setstyle_seq,
499 setstate_seq, setstate_seq, setcheck_ignored_seq },
500 { BS_CHECKBOX, DLGC_BUTTON,
501 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
502 setstate_static_seq, setstate_static_seq, setcheck_static_seq },
503 { BS_AUTOCHECKBOX, DLGC_BUTTON,
504 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
505 setstate_static_seq, setstate_static_seq, setcheck_static_seq },
506 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
507 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
508 setstate_static_seq, setstate_static_seq, setcheck_radio_redraw_seq },
509 { BS_3STATE, DLGC_BUTTON,
510 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
511 setstate_static_seq, setstate_static_seq, setcheck_static_seq },
512 { BS_AUTO3STATE, DLGC_BUTTON,
513 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
514 setstate_static_seq, setstate_static_seq, setcheck_static_seq },
515 { BS_GROUPBOX, DLGC_STATIC,
516 setfocus_groupbox_seq, killfocus_static_seq, setstyle_static_seq,
517 setstate_static_seq, setstate_static_seq, setcheck_ignored_seq },
518 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
519 setfocus_seq, killfocus_seq, setstyle_user_seq,
520 setstate_user_seq, clearstate_seq, setcheck_ignored_seq },
521 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
522 setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
523 setstate_static_seq, setstate_static_seq, setcheck_radio_redraw_seq },
524 { BS_OWNERDRAW, DLGC_BUTTON,
525 setfocus_ownerdraw_seq, killfocus_ownerdraw_seq, setstyle_ownerdraw_seq,
526 setstate_ownerdraw_seq, clearstate_ownerdraw_seq, setcheck_ignored_seq },
527 };
528 const struct message *seq;
529 unsigned int i;
530 HWND hwnd, parent;
531 DWORD dlg_code;
532 HFONT zfont;
533 BOOL todo;
534
535 /* selection with VK_SPACE should capture button window */
536 hwnd = create_button(BS_CHECKBOX | WS_VISIBLE | WS_POPUP, NULL);
537 ok(hwnd != 0, "Failed to create button window\n");
538 ReleaseCapture();
539 SetFocus(hwnd);
540 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
541 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
542 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
543 DestroyWindow(hwnd);
544
545 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
546 100, 100, 200, 200, 0, 0, 0, NULL);
547 ok(parent != 0, "Failed to create parent window\n");
548
549 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
550 {
551 MSG msg;
552 DWORD style, state;
553
554 trace("%d: button test sequence\n", i);
555 hwnd = create_button(button[i].style, parent);
556
557 style = GetWindowLongA(hwnd, GWL_STYLE);
558 style &= ~(WS_CHILD | BS_NOTIFY);
559 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
560 if (button[i].style == BS_USERBUTTON)
561 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
562 else
563 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
564
565 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
566 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
567
568 ShowWindow(hwnd, SW_SHOW);
569 UpdateWindow(hwnd);
570 SetFocus(0);
571 flush_events();
572 SetFocus(0);
573 flush_sequences(sequences, NUM_MSG_SEQUENCES);
574
575 todo = button[i].style != BS_OWNERDRAW;
576 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
577 SetFocus(hwnd);
578 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
579 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
580 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setfocus, "SetFocus(hwnd) on a button", todo);
581
582 todo = button[i].style == BS_OWNERDRAW;
583 SetFocus(0);
584 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
585 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
586 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].killfocus, "SetFocus(0) on a button", todo);
587 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
588
589 SendMessageA(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
590 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
591 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
592 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstyle, "BM_SETSTYLE on a button", TRUE);
593
594 style = GetWindowLongA(hwnd, GWL_STYLE);
595 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
596 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
597 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
598
599 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
600 ok(state == 0, "expected state 0, got %04x\n", state);
601
602 flush_sequences(sequences, NUM_MSG_SEQUENCES);
603
604 SendMessageA(hwnd, BM_SETSTATE, TRUE, 0);
605 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
606 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
607 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstate, "BM_SETSTATE/TRUE on a button", TRUE);
608
609 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
610 ok(state == BST_PUSHED, "expected state 0x0004, got %04x\n", state);
611
612 style = GetWindowLongA(hwnd, GWL_STYLE);
613 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
614 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
615
616 flush_sequences(sequences, NUM_MSG_SEQUENCES);
617
618 SendMessageA(hwnd, BM_SETSTATE, FALSE, 0);
619 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
620 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
621 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].clearstate, "BM_SETSTATE/FALSE on a button", TRUE);
622
623 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
624 ok(state == 0, "expected state 0, got %04x\n", state);
625
626 style = GetWindowLongA(hwnd, GWL_STYLE);
627 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
628 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
629
630 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
631 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
632
633 flush_sequences(sequences, NUM_MSG_SEQUENCES);
634
635 if (button[i].style == BS_RADIOBUTTON ||
636 button[i].style == BS_AUTORADIOBUTTON)
637 {
638 seq = setcheck_radio_seq;
639 todo = TRUE;
640 }
641 else
642 {
643 seq = setcheck_ignored_seq;
644 todo = FALSE;
645 }
646 SendMessageA(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
647 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
648 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
649 ok_sequence(sequences, COMBINED_SEQ_INDEX, seq, "BM_SETCHECK on a button", todo);
650
651 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
652 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
653
654 style = GetWindowLongA(hwnd, GWL_STYLE);
655 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
656 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
657
658 flush_sequences(sequences, NUM_MSG_SEQUENCES);
659
660 SendMessageA(hwnd, BM_SETCHECK, BST_CHECKED, 0);
661 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
662 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
663
664 if (button[i].style == BS_PUSHBUTTON ||
665 button[i].style == BS_DEFPUSHBUTTON ||
666 button[i].style == BS_GROUPBOX ||
667 button[i].style == BS_USERBUTTON ||
668 button[i].style == BS_OWNERDRAW)
669 {
670 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setcheck, "BM_SETCHECK on a button", FALSE);
671 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
672 ok(state == BST_UNCHECKED, "expected check BST_UNCHECKED, got %04x\n", state);
673 }
674 else
675 {
676 ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setcheck, "BM_SETCHECK on a button", TRUE);
677 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
678 ok(state == BST_CHECKED, "expected check BST_CHECKED, got %04x\n", state);
679 }
680
681 style = GetWindowLongA(hwnd, GWL_STYLE);
682 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
683 if (button[i].style == BS_RADIOBUTTON ||
684 button[i].style == BS_AUTORADIOBUTTON)
685 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
686 else
687 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
688
689 DestroyWindow(hwnd);
690 }
691
692 DestroyWindow(parent);
693
694 hwnd = create_button(BS_PUSHBUTTON, NULL);
695
696 SetForegroundWindow(hwnd);
697 flush_events();
698
699 SetActiveWindow(hwnd);
700 SetFocus(0);
701 flush_sequences(sequences, NUM_MSG_SEQUENCES);
702
703 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
704 ok_sequence(sequences, COMBINED_SEQ_INDEX, lbuttondown_seq, "WM_LBUTTONDOWN on a button", FALSE);
705
706 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
707 ok_sequence(sequences, COMBINED_SEQ_INDEX, lbuttonup_seq, "WM_LBUTTONUP on a button", TRUE);
708
709 flush_sequences(sequences, NUM_MSG_SEQUENCES);
710 zfont = GetStockObject(SYSTEM_FONT);
711 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
712 UpdateWindow(hwnd);
713 ok_sequence(sequences, COMBINED_SEQ_INDEX, setfont_seq, "WM_SETFONT on a button", FALSE);
714
715 DestroyWindow(hwnd);
716 }
717
718 static void test_button_class(void)
719 {
720 static const WCHAR testW[] = {'t','e','s','t',0};
721 WNDCLASSEXW exW, ex2W;
722 WNDCLASSEXA exA;
723 char buffA[100];
724 WCHAR *nameW;
725 HWND hwnd;
726 BOOL ret;
727 int len;
728
729 ret = GetClassInfoExA(NULL, WC_BUTTONA, &exA);
730 ok(ret, "got %d\n", ret);
731 todo_wine
732 ok(IS_WNDPROC_HANDLE(exA.lpfnWndProc), "got %p\n", exA.lpfnWndProc);
733
734 ret = GetClassInfoExW(NULL, WC_BUTTONW, &exW);
735 ok(ret, "got %d\n", ret);
736 ok(!IS_WNDPROC_HANDLE(exW.lpfnWndProc), "got %p\n", exW.lpfnWndProc);
737
738 /* check that versioned class is also accessible */
739 nameW = get_versioned_classname(WC_BUTTONW);
740 ok(lstrcmpW(nameW, WC_BUTTONW), "got %s\n", wine_dbgstr_w(nameW));
741
742 ret = GetClassInfoExW(NULL, nameW, &ex2W);
743 todo_wine
744 ok(ret, "got %d\n", ret);
745 if (ret) /* TODO: remove once Wine is fixed */
746 ok(ex2W.lpfnWndProc == exW.lpfnWndProc, "got %p, %p\n", exW.lpfnWndProc, ex2W.lpfnWndProc);
747
748 /* Check reported class name */
749 hwnd = create_button(BS_CHECKBOX, NULL);
750 len = GetClassNameA(hwnd, buffA, sizeof(buffA));
751 ok(len == strlen(buffA), "got %d\n", len);
752 ok(!strcmp(buffA, "Button"), "got %s\n", buffA);
753
754 len = RealGetWindowClassA(hwnd, buffA, sizeof(buffA));
755 ok(len == strlen(buffA), "got %d\n", len);
756 ok(!strcmp(buffA, "Button"), "got %s\n", buffA);
757 DestroyWindow(hwnd);
758
759 /* explicitly create with versioned class name */
760 hwnd = CreateWindowExW(0, nameW, testW, BS_CHECKBOX, 0, 0, 50, 14, NULL, 0, 0, NULL);
761 todo_wine
762 ok(hwnd != NULL, "failed to create a window %s\n", wine_dbgstr_w(nameW));
763 if (hwnd)
764 {
765 len = GetClassNameA(hwnd, buffA, sizeof(buffA));
766 ok(len == strlen(buffA), "got %d\n", len);
767 ok(!strcmp(buffA, "Button"), "got %s\n", buffA);
768
769 len = RealGetWindowClassA(hwnd, buffA, sizeof(buffA));
770 ok(len == strlen(buffA), "got %d\n", len);
771 ok(!strcmp(buffA, "Button"), "got %s\n", buffA);
772
773 DestroyWindow(hwnd);
774 }
775 }
776
777 static void register_parent_class(void)
778 {
779 WNDCLASSA cls;
780
781 cls.style = 0;
782 cls.lpfnWndProc = test_parent_wndproc;
783 cls.cbClsExtra = 0;
784 cls.cbWndExtra = 0;
785 cls.hInstance = GetModuleHandleA(0);
786 cls.hIcon = 0;
787 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
788 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
789 cls.lpszMenuName = NULL;
790 cls.lpszClassName = "TestParentClass";
791 RegisterClassA(&cls);
792 }
793
794 START_TEST(button)
795 {
796 ULONG_PTR ctx_cookie;
797 HANDLE hCtx;
798
799 if (!load_v6_module(&ctx_cookie, &hCtx))
800 return;
801
802 register_parent_class();
803
804 init_functions();
805 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
806
807 test_button_class();
808 test_button_messages();
809
810 unload_v6_module(ctx_cookie, hCtx);
811 }