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
23 #include "resources.h"
25 #include "wine/test.h"
29 static LONG active_page
= -1;
31 static int CALLBACK
sheet_callback(HWND hwnd
, UINT msg
, LPARAM lparam
)
35 case PSCB_INITIALIZED
:
38 GetWindowTextA(hwnd
, caption
, sizeof(caption
));
39 ok(!strcmp(caption
,"test caption"), "caption: %s\n", caption
);
46 static INT_PTR CALLBACK
page_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
,
53 HWND sheet
= GetParent(hwnd
);
55 GetWindowTextA(sheet
, caption
, sizeof(caption
));
56 ok(!strcmp(caption
,"test caption"), "caption: %s\n", caption
);
62 NMHDR
*nmhdr
= (NMHDR
*)lparam
;
76 static void test_title(void)
78 HPROPSHEETPAGE hpsp
[1];
83 memset(&psp
, 0, sizeof(psp
));
84 psp
.dwSize
= sizeof(psp
);
86 psp
.hInstance
= GetModuleHandleW(NULL
);
87 U(psp
).pszTemplate
= "prop_page1";
88 U2(psp
).pszIcon
= NULL
;
89 psp
.pfnDlgProc
= page_dlg_proc
;
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";
99 psh
.hwndParent
= GetDesktopWindow();
100 U3(psh
).phpage
= hpsp
;
101 psh
.pfnCallback
= sheet_callback
;
103 hdlg
= (HWND
)PropertySheetA(&psh
);
107 static void test_nopage(void)
109 HPROPSHEETPAGE hpsp
[1];
111 PROPSHEETHEADERA psh
;
114 memset(&psp
, 0, sizeof(psp
));
115 psp
.dwSize
= sizeof(psp
);
117 psp
.hInstance
= GetModuleHandleW(NULL
);
118 U(psp
).pszTemplate
= "prop_page1";
119 U2(psp
).pszIcon
= NULL
;
120 psp
.pfnDlgProc
= page_dlg_proc
;
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";
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
);
141 static int CALLBACK
disableowner_callback(HWND hwnd
, UINT msg
, LPARAM lparam
)
145 case PSCB_INITIALIZED
:
147 ok(IsWindowEnabled(parent
) == 0, "parent window should be disabled\n");
155 static void register_parent_wnd_class(void)
160 cls
.lpfnWndProc
= DefWindowProcA
;
163 cls
.hInstance
= GetModuleHandleA(NULL
);
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];
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
);
184 psp
.hInstance
= GetModuleHandleW(NULL
);
185 U(psp
).pszTemplate
= "prop_page1";
186 U2(psp
).pszIcon
= NULL
;
187 psp
.pfnDlgProc
= NULL
;
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";
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
)
211 LPNMHDR hdr
= (LPNMHDR
)lparam
;
214 active_page
= PropSheet_HwndToIndex(hdr
->hwndFrom
, hwnd
);
217 /* prevent navigation away from the fourth page */
218 if(active_page
== 3){
219 SetWindowLongPtr(hwnd
, DWLP_MSGRESULT
, TRUE
);
229 static void test_wiznavigation(void)
231 HPROPSHEETPAGE hpsp
[4];
232 PROPSHEETPAGEA psp
[4];
233 PROPSHEETHEADERA psh
;
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";
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
);
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
);
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
));
345 START_TEST(propsheet
)
350 test_wiznavigation();