dplayx: Code to forward player creation
[wine/gsoc_dplay.git] / dlls / comctl32 / tests / propsheet.c
blobcf5c2017c70034fa220cc5d73d5d5dce69bb452d
1 /* Unit test suite for property sheet control.
3 * Copyright 2006 Huw Davies
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
20 #include <windows.h>
21 #include <commctrl.h>
23 #include "resources.h"
25 #include "wine/test.h"
27 static HWND parent;
29 static LONG active_page = -1;
31 static int CALLBACK sheet_callback(HWND hwnd, UINT msg, LPARAM lparam)
33 switch(msg)
35 case PSCB_INITIALIZED:
37 char caption[256];
38 GetWindowTextA(hwnd, caption, sizeof(caption));
39 ok(!strcmp(caption,"test caption"), "caption: %s\n", caption);
40 return 0;
43 return 0;
46 static INT_PTR CALLBACK page_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam,
47 LPARAM lparam)
49 switch(msg)
51 case WM_INITDIALOG:
53 HWND sheet = GetParent(hwnd);
54 char caption[256];
55 GetWindowTextA(sheet, caption, sizeof(caption));
56 ok(!strcmp(caption,"test caption"), "caption: %s\n", caption);
57 return TRUE;
60 case WM_NOTIFY:
62 NMHDR *nmhdr = (NMHDR *)lparam;
63 switch(nmhdr->code)
65 case PSN_APPLY:
66 return TRUE;
67 default:
68 return FALSE;
71 default:
72 return FALSE;
76 static void test_title(void)
78 HPROPSHEETPAGE hpsp[1];
79 PROPSHEETPAGEA psp;
80 PROPSHEETHEADERA psh;
81 HWND hdlg;
83 memset(&psp, 0, sizeof(psp));
84 psp.dwSize = sizeof(psp);
85 psp.dwFlags = 0;
86 psp.hInstance = GetModuleHandleW(NULL);
87 U(psp).pszTemplate = "prop_page1";
88 U2(psp).pszIcon = NULL;
89 psp.pfnDlgProc = page_dlg_proc;
90 psp.lParam = 0;
92 hpsp[0] = CreatePropertySheetPageA(&psp);
94 memset(&psh, 0, sizeof(psh));
95 psh.dwSize = sizeof(psh);
96 psh.dwFlags = PSH_MODELESS | PSH_USECALLBACK;
97 psh.pszCaption = "test caption";
98 psh.nPages = 1;
99 psh.hwndParent = GetDesktopWindow();
100 U3(psh).phpage = hpsp;
101 psh.pfnCallback = sheet_callback;
103 hdlg = (HWND)PropertySheetA(&psh);
104 DestroyWindow(hdlg);
107 static void test_nopage(void)
109 HPROPSHEETPAGE hpsp[1];
110 PROPSHEETPAGEA psp;
111 PROPSHEETHEADERA psh;
112 HWND hdlg;
114 memset(&psp, 0, sizeof(psp));
115 psp.dwSize = sizeof(psp);
116 psp.dwFlags = 0;
117 psp.hInstance = GetModuleHandleW(NULL);
118 U(psp).pszTemplate = "prop_page1";
119 U2(psp).pszIcon = NULL;
120 psp.pfnDlgProc = page_dlg_proc;
121 psp.lParam = 0;
123 hpsp[0] = CreatePropertySheetPageA(&psp);
125 memset(&psh, 0, sizeof(psh));
126 psh.dwSize = sizeof(psh);
127 psh.dwFlags = PSH_MODELESS | PSH_USECALLBACK;
128 psh.pszCaption = "test caption";
129 psh.nPages = 1;
130 psh.hwndParent = GetDesktopWindow();
131 U3(psh).phpage = hpsp;
132 psh.pfnCallback = sheet_callback;
134 hdlg = (HWND)PropertySheetA(&psh);
135 ShowWindow(hdlg,SW_NORMAL);
136 SendMessage(hdlg, PSM_REMOVEPAGE, 0, 0);
137 RedrawWindow(hdlg,NULL,NULL,RDW_UPDATENOW|RDW_ERASENOW);
138 DestroyWindow(hdlg);
141 static int CALLBACK disableowner_callback(HWND hwnd, UINT msg, LPARAM lparam)
143 switch(msg)
145 case PSCB_INITIALIZED:
147 ok(IsWindowEnabled(parent) == 0, "parent window should be disabled\n");
148 PostQuitMessage(0);
149 return FALSE;
152 return FALSE;
155 static void register_parent_wnd_class(void)
157 WNDCLASSA cls;
159 cls.style = 0;
160 cls.lpfnWndProc = DefWindowProcA;
161 cls.cbClsExtra = 0;
162 cls.cbWndExtra = 0;
163 cls.hInstance = GetModuleHandleA(NULL);
164 cls.hIcon = 0;
165 cls.hCursor = LoadCursorA(0, IDC_ARROW);
166 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
167 cls.lpszMenuName = NULL;
168 cls.lpszClassName = "parent class";
169 RegisterClassA(&cls);
172 static void test_disableowner(void)
174 HPROPSHEETPAGE hpsp[1];
175 PROPSHEETPAGEA psp;
176 PROPSHEETHEADERA psh;
178 register_parent_wnd_class();
179 parent = CreateWindowA("parent class", "", WS_CAPTION | WS_SYSMENU | WS_VISIBLE, 100, 100, 100, 100, GetDesktopWindow(), NULL, GetModuleHandleA(NULL), 0);
181 memset(&psp, 0, sizeof(psp));
182 psp.dwSize = sizeof(psp);
183 psp.dwFlags = 0;
184 psp.hInstance = GetModuleHandleW(NULL);
185 U(psp).pszTemplate = "prop_page1";
186 U2(psp).pszIcon = NULL;
187 psp.pfnDlgProc = NULL;
188 psp.lParam = 0;
190 hpsp[0] = CreatePropertySheetPageA(&psp);
192 memset(&psh, 0, sizeof(psh));
193 psh.dwSize = sizeof(psh);
194 psh.dwFlags = PSH_USECALLBACK;
195 psh.pszCaption = "test caption";
196 psh.nPages = 1;
197 psh.hwndParent = parent;
198 U3(psh).phpage = hpsp;
199 psh.pfnCallback = disableowner_callback;
201 PropertySheetA(&psh);
202 ok(IsWindowEnabled(parent) != 0, "parent window should be enabled\n");
203 DestroyWindow(parent);
206 static INT_PTR CALLBACK nav_page_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
208 switch(msg){
209 case WM_NOTIFY:
211 LPNMHDR hdr = (LPNMHDR)lparam;
212 switch(hdr->code){
213 case PSN_SETACTIVE:
214 active_page = PropSheet_HwndToIndex(hdr->hwndFrom, hwnd);
215 return TRUE;
216 case PSN_KILLACTIVE:
217 /* prevent navigation away from the fourth page */
218 if(active_page == 3){
219 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
220 return TRUE;
223 break;
226 return FALSE;
229 static void test_wiznavigation(void)
231 HPROPSHEETPAGE hpsp[4];
232 PROPSHEETPAGEA psp[4];
233 PROPSHEETHEADERA psh;
234 HWND hdlg, control;
235 LONG_PTR controlID;
236 LRESULT defidres;
237 BOOL hwndtoindex_supported = TRUE;
238 const INT nextID = 12324;
239 const INT backID = 12323;
241 /* create the property sheet pages */
242 memset(psp, 0, sizeof(PROPSHEETPAGEA) * 4);
244 psp[0].dwSize = sizeof(PROPSHEETPAGEA);
245 psp[0].hInstance = GetModuleHandleW(NULL);
246 U(psp[0]).pszTemplate = MAKEINTRESOURCE(IDD_PROP_PAGE_INTRO);
247 psp[0].pfnDlgProc = nav_page_proc;
248 hpsp[0] = CreatePropertySheetPageA(&psp[0]);
250 psp[1].dwSize = sizeof(PROPSHEETPAGEA);
251 psp[1].hInstance = GetModuleHandleW(NULL);
252 U(psp[1]).pszTemplate = MAKEINTRESOURCE(IDD_PROP_PAGE_EDIT);
253 psp[1].pfnDlgProc = nav_page_proc;
254 hpsp[1] = CreatePropertySheetPageA(&psp[1]);
256 psp[2].dwSize = sizeof(PROPSHEETPAGEA);
257 psp[2].hInstance = GetModuleHandleW(NULL);
258 U(psp[2]).pszTemplate = MAKEINTRESOURCE(IDD_PROP_PAGE_RADIO);
259 psp[2].pfnDlgProc = nav_page_proc;
260 hpsp[2] = CreatePropertySheetPageA(&psp[2]);
262 psp[3].dwSize = sizeof(PROPSHEETPAGEA);
263 psp[3].hInstance = GetModuleHandleW(NULL);
264 U(psp[3]).pszTemplate = MAKEINTRESOURCE(IDD_PROP_PAGE_EXIT);
265 psp[3].pfnDlgProc = nav_page_proc;
266 hpsp[3] = CreatePropertySheetPageA(&psp[3]);
268 /* set up the property sheet dialog */
269 memset(&psh, 0, sizeof(psh));
270 psh.dwSize = sizeof(psh);
271 psh.dwFlags = PSH_MODELESS | PSH_WIZARD;
272 psh.pszCaption = "A Wizard";
273 psh.nPages = 4;
274 psh.hwndParent = GetDesktopWindow();
275 U3(psh).phpage = hpsp;
276 hdlg = (HWND)PropertySheetA(&psh);
278 ok(active_page == 0, "Active page should be 0. Is: %d\n", active_page);
280 control = GetFocus();
281 controlID = GetWindowLongPtr(control, GWLP_ID);
282 ok(controlID == nextID, "Focus should have been set to the Next button. Expected: %d, Found: %ld\n", nextID, controlID);
284 /* simulate pressing the Next button */
285 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
286 if (!active_page) hwndtoindex_supported = FALSE;
287 if (hwndtoindex_supported)
288 ok(active_page == 1, "Active page should be 1 after pressing Next. Is: %d\n", active_page);
290 control = GetFocus();
291 controlID = GetWindowLongPtr(control, GWLP_ID);
292 ok(controlID == IDC_PS_EDIT1, "Focus should be set to the first item on the second page. Expected: %d, Found: %ld\n", IDC_PS_EDIT1, controlID);
294 defidres = SendMessage(hdlg, DM_GETDEFID, 0, 0);
295 ok(defidres == MAKELRESULT(nextID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", nextID, LOWORD(defidres));
297 /* set the focus to the second edit box on this page */
298 SetFocus(GetNextDlgTabItem(hdlg, control, FALSE));
300 /* press next again */
301 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
302 if (hwndtoindex_supported)
303 ok(active_page == 2, "Active page should be 2 after pressing Next. Is: %d\n", active_page);
305 control = GetFocus();
306 controlID = GetWindowLongPtr(control, GWLP_ID);
307 ok(controlID == IDC_PS_RADIO1, "Focus should have been set to item on third page. Expected: %d, Found %ld\n", IDC_PS_RADIO1, controlID);
309 /* back button */
310 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_BACK, 0);
311 if (hwndtoindex_supported)
312 ok(active_page == 1, "Active page should be 1 after pressing Back. Is: %d\n", active_page);
314 control = GetFocus();
315 controlID = GetWindowLongPtr(control, GWLP_ID);
316 ok(controlID == IDC_PS_EDIT1, "Focus should have been set to the first item on second page. Expected: %d, Found %ld\n", IDC_PS_EDIT1, controlID);
318 defidres = SendMessage(hdlg, DM_GETDEFID, 0, 0);
319 ok(defidres == MAKELRESULT(backID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", backID, LOWORD(defidres));
321 /* press next twice */
322 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
323 if (hwndtoindex_supported)
324 ok(active_page == 2, "Active page should be 2 after pressing Next. Is: %d\n", active_page);
325 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
326 if (hwndtoindex_supported)
327 ok(active_page == 3, "Active page should be 3 after pressing Next. Is: %d\n", active_page);
328 else
329 active_page = 3;
331 control = GetFocus();
332 controlID = GetWindowLongPtr(control, GWLP_ID);
333 ok(controlID == nextID, "Focus should have been set to the Next button. Expected: %d, Found: %ld\n", nextID, controlID);
335 /* try to navigate away, but shouldn't be able to */
336 SendMessage(hdlg, PSM_PRESSBUTTON, PSBTN_BACK, 0);
337 ok(active_page == 3, "Active page should still be 3 after pressing Back. Is: %d\n", active_page);
339 defidres = SendMessage(hdlg, DM_GETDEFID, 0, 0);
340 ok(defidres == MAKELRESULT(nextID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", nextID, LOWORD(defidres));
342 DestroyWindow(hdlg);
345 START_TEST(propsheet)
347 test_title();
348 test_nopage();
349 test_disableowner();
350 test_wiznavigation();