comctl32/listview: Additional tests for LVM_GETSUBITEMRECT.
[wine] / dlls / comctl32 / tests / propsheet.c
1 /* Unit test suite for property sheet control.
2  *
3  * Copyright 2006 Huw Davies
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include <windows.h>
21 #include <commctrl.h>
22
23 #include "wine/test.h"
24
25 static HWND parent;
26
27 static int CALLBACK sheet_callback(HWND hwnd, UINT msg, LPARAM lparam)
28 {
29     switch(msg)
30     {
31     case PSCB_INITIALIZED:
32       {
33         char caption[256];
34         GetWindowTextA(hwnd, caption, sizeof(caption));
35         ok(!strcmp(caption,"test caption"), "caption: %s\n", caption);
36         return 0;
37       }
38     }
39     return 0;
40 }
41         
42 static INT_PTR CALLBACK page_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam,
43                                       LPARAM lparam)
44 {
45     switch(msg)
46     {
47     case WM_INITDIALOG:
48       {
49         HWND sheet = GetParent(hwnd);
50         char caption[256];
51         GetWindowTextA(sheet, caption, sizeof(caption));
52         ok(!strcmp(caption,"test caption"), "caption: %s\n", caption);
53         return TRUE;
54       }
55
56     case WM_NOTIFY:
57       {
58         NMHDR *nmhdr = (NMHDR *)lparam;
59         switch(nmhdr->code)
60         {
61         case PSN_APPLY:
62             return TRUE;
63         default:
64             return FALSE;
65         }
66       }
67     default:
68         return FALSE;
69     }
70 }
71
72 static void test_title(void)
73 {
74     HPROPSHEETPAGE hpsp[1];
75     PROPSHEETPAGEA psp;
76     PROPSHEETHEADERA psh;
77     HWND hdlg;
78
79     memset(&psp, 0, sizeof(psp));
80     psp.dwSize = sizeof(psp);
81     psp.dwFlags = 0;
82     psp.hInstance = GetModuleHandleW(NULL);
83     U(psp).pszTemplate = "prop_page1";
84     U2(psp).pszIcon = NULL;
85     psp.pfnDlgProc = page_dlg_proc;
86     psp.lParam = 0;
87
88     hpsp[0] = CreatePropertySheetPageA(&psp);
89
90     memset(&psh, 0, sizeof(psh));
91     psh.dwSize = sizeof(psh);
92     psh.dwFlags = PSH_MODELESS | PSH_USECALLBACK;
93     psh.pszCaption = "test caption";
94     psh.nPages = 1;
95     psh.hwndParent = GetDesktopWindow();
96     U3(psh).phpage = hpsp;
97     psh.pfnCallback = sheet_callback;
98
99     hdlg = (HWND)PropertySheetA(&psh);
100     DestroyWindow(hdlg);
101 }
102
103 static void test_nopage(void)
104 {
105     HPROPSHEETPAGE hpsp[1];
106     PROPSHEETPAGEA psp;
107     PROPSHEETHEADERA psh;
108     HWND hdlg;
109
110     memset(&psp, 0, sizeof(psp));
111     psp.dwSize = sizeof(psp);
112     psp.dwFlags = 0;
113     psp.hInstance = GetModuleHandleW(NULL);
114     U(psp).pszTemplate = "prop_page1";
115     U2(psp).pszIcon = NULL;
116     psp.pfnDlgProc = page_dlg_proc;
117     psp.lParam = 0;
118
119     hpsp[0] = CreatePropertySheetPageA(&psp);
120
121     memset(&psh, 0, sizeof(psh));
122     psh.dwSize = sizeof(psh);
123     psh.dwFlags = PSH_MODELESS | PSH_USECALLBACK;
124     psh.pszCaption = "test caption";
125     psh.nPages = 1;
126     psh.hwndParent = GetDesktopWindow();
127     U3(psh).phpage = hpsp;
128     psh.pfnCallback = sheet_callback;
129
130     hdlg = (HWND)PropertySheetA(&psh);
131     ShowWindow(hdlg,SW_NORMAL);
132     SendMessage(hdlg, PSM_REMOVEPAGE, 0, 0);
133     RedrawWindow(hdlg,NULL,NULL,RDW_UPDATENOW|RDW_ERASENOW);
134     DestroyWindow(hdlg);
135 }
136
137 static int CALLBACK disableowner_callback(HWND hwnd, UINT msg, LPARAM lparam)
138 {
139     switch(msg)
140     {
141     case PSCB_INITIALIZED:
142       {
143         ok(IsWindowEnabled(parent) == 0, "parent window should be disabled\n");
144         PostQuitMessage(0);
145         return FALSE;
146       }
147     }
148     return FALSE;
149 }
150
151 static void register_parent_wnd_class(void)
152 {
153     WNDCLASSA cls;
154
155     cls.style = 0;
156     cls.lpfnWndProc = DefWindowProcA;
157     cls.cbClsExtra = 0;
158     cls.cbWndExtra = 0;
159     cls.hInstance = GetModuleHandleA(NULL);
160     cls.hIcon = 0;
161     cls.hCursor = LoadCursorA(0, IDC_ARROW);
162     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
163     cls.lpszMenuName = NULL;
164     cls.lpszClassName = "parent class";
165     RegisterClassA(&cls);
166 }
167
168 static void test_disableowner(void)
169 {
170     HPROPSHEETPAGE hpsp[1];
171     PROPSHEETPAGEA psp;
172     PROPSHEETHEADERA psh;
173
174     register_parent_wnd_class();
175     parent = CreateWindowA("parent class", "", WS_CAPTION | WS_SYSMENU | WS_VISIBLE, 100, 100, 100, 100, GetDesktopWindow(), NULL, GetModuleHandleA(NULL), 0);
176
177     memset(&psp, 0, sizeof(psp));
178     psp.dwSize = sizeof(psp);
179     psp.dwFlags = 0;
180     psp.hInstance = GetModuleHandleW(NULL);
181     U(psp).pszTemplate = "prop_page1";
182     U2(psp).pszIcon = NULL;
183     psp.pfnDlgProc = NULL;
184     psp.lParam = 0;
185
186     hpsp[0] = CreatePropertySheetPageA(&psp);
187
188     memset(&psh, 0, sizeof(psh));
189     psh.dwSize = sizeof(psh);
190     psh.dwFlags = PSH_USECALLBACK;
191     psh.pszCaption = "test caption";
192     psh.nPages = 1;
193     psh.hwndParent = parent;
194     U3(psh).phpage = hpsp;
195     psh.pfnCallback = disableowner_callback;
196
197     PropertySheetA(&psh);
198     ok(IsWindowEnabled(parent) != 0, "parent window should be enabled\n");
199     DestroyWindow(parent);
200 }
201
202 START_TEST(propsheet)
203 {
204     test_title();
205     test_nopage();
206     test_disableowner();
207 }