comctl32: header: Correct WM_[GS]ETUNICODEFORMAT.
[wine] / dlls / comctl32 / tests / toolbar.c
1 /* Unit tests for treeview.
2  *
3  * Copyright 2005 Krzysztof Foltman
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <assert.h>
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "commctrl.h" 
30
31 #include "wine/test.h"
32  
33 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
34   p->iBitmap = -2;
35   p->idCommand = idCommand;
36   p->fsState = TBSTATE_ENABLED;
37   p->fsStyle = fsStyle;
38   p->iString = nString;
39 }
40
41 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
42 {
43     switch(msg) {
44                   
45     case WM_CREATE:
46     {
47         TBBUTTON buttons[9];
48         int i;
49         HWND hToolbar;
50         for (i=0; i<9; i++)
51             MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
52         MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
53         MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
54
55         hToolbar = CreateToolbarEx(hWnd,
56             WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
57             WS_CHILD | TBSTYLE_LIST,
58             100,
59             0, NULL, (UINT)0,
60             buttons, sizeof(buttons)/sizeof(buttons[0]),
61             0, 0, 20, 16, sizeof(TBBUTTON));
62         ok(hToolbar != NULL, "Toolbar creation\n");
63
64         SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
65
66         /* test for exclusion working inside a separator-separated :-) group */
67         SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
68         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
69         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
70
71         SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
72         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
73         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
74
75         SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
76         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
77         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
78
79         /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
80         SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
81         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
82         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
83         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
84
85         SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
86         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
87         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
88         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
89
90         SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
91         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
92         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
93         ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
94         ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
95         PostMessage(hWnd, WM_CLOSE, 0, 0);
96         return 0;
97     }
98     case WM_DESTROY:
99         PostQuitMessage(0);
100         break;
101   
102     default:
103         return DefWindowProcA(hWnd, msg, wParam, lParam);
104     }
105     return 0L;
106 }
107
108 START_TEST(toolbar)
109 {
110     WNDCLASSA wc;
111     MSG msg;
112     RECT rc;
113     HWND hMainWnd;
114   
115     InitCommonControls();
116   
117     wc.style = CS_HREDRAW | CS_VREDRAW;
118     wc.cbClsExtra = 0;
119     wc.cbWndExtra = 0;
120     wc.hInstance = GetModuleHandleA(NULL);
121     wc.hIcon = NULL;
122     wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
123     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
124     wc.lpszMenuName = NULL;
125     wc.lpszClassName = "MyTestWnd";
126     wc.lpfnWndProc = MyWndProc;
127     RegisterClassA(&wc);
128     
129     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW, 
130       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
131     GetClientRect(hMainWnd, &rc);
132
133     while(GetMessageA(&msg,0,0,0)) {
134         TranslateMessage(&msg);
135         DispatchMessageA(&msg);
136     }
137 }