2 * Unit tests for the pager control
4 * Copyright 2012 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
27 #define NUM_MSG_SEQUENCES 1
28 #define PAGER_SEQ_INDEX 0
30 static HWND parent_wnd
, child1_wnd
, child2_wnd
;
35 static BOOL (WINAPI
*pSetWindowSubclass
)(HWND
, SUBCLASSPROC
, UINT_PTR
, DWORD_PTR
);
37 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
39 static const struct message set_child_seq
[] = {
40 { PGM_SETCHILD
, sent
},
41 { WM_WINDOWPOSCHANGING
, sent
},
42 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
43 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
44 { WM_WINDOWPOSCHANGED
, sent
},
45 { WM_WINDOWPOSCHANGING
, sent
|id
, 0, 0, CHILD1_ID
},
46 { WM_NCCALCSIZE
, sent
|wparam
|id
|optional
, TRUE
, 0, CHILD1_ID
},
47 { WM_CHILDACTIVATE
, sent
|id
, 0, 0, CHILD1_ID
},
48 { WM_WINDOWPOSCHANGED
, sent
|id
, 0, 0, CHILD1_ID
},
49 { WM_SIZE
, sent
|id
|defwinproc
|optional
, 0, 0, CHILD1_ID
},
53 /* This differs from the above message list only in the child window that is
54 * expected to receive the child messages. No message is sent to the old child.
55 * Also child 2 is hidden while child 1 is visible. The pager does not make the
56 * hidden child visible. */
57 static const struct message switch_child_seq
[] = {
58 { PGM_SETCHILD
, sent
},
59 { WM_WINDOWPOSCHANGING
, sent
},
60 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
61 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
62 { WM_WINDOWPOSCHANGED
, sent
},
63 { WM_WINDOWPOSCHANGING
, sent
|id
, 0, 0, CHILD2_ID
},
64 { WM_NCCALCSIZE
, sent
|wparam
|id
, TRUE
, 0, CHILD2_ID
},
65 { WM_CHILDACTIVATE
, sent
|id
, 0, 0, CHILD2_ID
},
66 { WM_WINDOWPOSCHANGED
, sent
|id
, 0, 0, CHILD2_ID
},
67 { WM_SIZE
, sent
|id
|defwinproc
, 0, 0, CHILD2_ID
},
71 static const struct message set_pos_seq
[] = {
73 { WM_WINDOWPOSCHANGING
, sent
},
74 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
75 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
76 { WM_WINDOWPOSCHANGED
, sent
},
77 { WM_MOVE
, sent
|optional
},
78 /* The WM_SIZE handler sends WM_WINDOWPOSCHANGING, WM_CHILDACTIVATE
79 * and WM_WINDOWPOSCHANGED (which sends WM_MOVE) to the child.
80 * Another WM_WINDOWPOSCHANGING is sent afterwards.
82 * The 2nd WM_WINDOWPOSCHANGING is unconditional, but the comparison
83 * function is too simple to roll back an accepted message, so we have
84 * to mark the 2nd message optional. */
85 { WM_SIZE
, sent
|optional
},
86 { WM_WINDOWPOSCHANGING
, sent
|id
, 0, 0, CHILD1_ID
}, /* Actually optional. */
87 { WM_CHILDACTIVATE
, sent
|id
, 0, 0, CHILD1_ID
}, /* Actually optional. */
88 { WM_WINDOWPOSCHANGED
, sent
|id
|optional
, TRUE
, 0, CHILD1_ID
},
89 { WM_MOVE
, sent
|id
|optional
|defwinproc
, 0, 0, CHILD1_ID
},
90 { WM_WINDOWPOSCHANGING
, sent
|id
|optional
, 0, 0, CHILD1_ID
}, /* Actually not optional. */
91 { WM_CHILDACTIVATE
, sent
|id
|optional
, 0, 0, CHILD1_ID
}, /* Actually not optional. */
95 static const struct message set_pos_empty_seq
[] = {
100 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
102 static LONG defwndproc_counter
= 0;
106 /* log system messages, except for painting */
107 if (message
< WM_USER
&&
108 message
!= WM_PAINT
&&
109 message
!= WM_ERASEBKGND
&&
110 message
!= WM_NCPAINT
&&
111 message
!= WM_NCHITTEST
&&
112 message
!= WM_GETTEXT
&&
113 message
!= WM_GETICON
&&
114 message
!= WM_DEVICECHANGE
)
116 msg
.message
= message
;
117 msg
.flags
= sent
|wparam
|lparam
|parent
;
118 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
121 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
122 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
125 if (message
== WM_NOTIFY
)
127 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
133 NMPGCALCSIZE
*nmpgcs
= (NMPGCALCSIZE
*)lParam
;
134 DWORD style
= GetWindowLongA(nmpgcs
->hdr
.hwndFrom
, GWL_STYLE
);
136 if (style
& PGS_HORZ
)
137 ok(nmpgcs
->dwFlag
== PGF_CALCWIDTH
, "Unexpected flags %#x.\n", nmpgcs
->dwFlag
);
139 ok(nmpgcs
->dwFlag
== PGF_CALCHEIGHT
, "Unexpected flags %#x.\n", nmpgcs
->dwFlag
);
147 defwndproc_counter
++;
148 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
149 defwndproc_counter
--;
154 static BOOL
register_parent_wnd_class(void)
159 cls
.lpfnWndProc
= parent_wnd_proc
;
162 cls
.hInstance
= GetModuleHandleA(NULL
);
164 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
165 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
166 cls
.lpszMenuName
= NULL
;
167 cls
.lpszClassName
= "Pager test parent class";
168 return RegisterClassA(&cls
);
171 static HWND
create_parent_window(void)
173 if (!register_parent_wnd_class())
176 return CreateWindowA("Pager test parent class", "Pager test parent window",
177 WS_OVERLAPPED
| WS_VISIBLE
,
178 0, 0, 200, 200, 0, NULL
, GetModuleHandleA(NULL
), NULL
);
181 static LRESULT WINAPI
pager_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
183 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
184 struct message msg
= { 0 };
186 msg
.message
= message
;
187 msg
.flags
= sent
|wparam
|lparam
;
190 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
191 return CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
194 static HWND
create_pager_control( DWORD style
)
200 GetClientRect( parent_wnd
, &rect
);
201 hwnd
= CreateWindowA( WC_PAGESCROLLERA
, "pager", WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
202 0, 0, 100, 100, parent_wnd
, 0, GetModuleHandleA(0), 0 );
203 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)pager_subclass_proc
);
204 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
208 static LRESULT WINAPI
child_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
211 static LONG defwndproc_counter
;
214 msg
.message
= message
;
215 msg
.flags
= sent
| wparam
| lparam
;
216 if (defwndproc_counter
)
217 msg
.flags
|= defwinproc
;
221 if (hwnd
== child1_wnd
)
223 else if (hwnd
== child2_wnd
)
228 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
230 defwndproc_counter
++;
231 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
232 defwndproc_counter
--;
237 static BOOL
register_child_wnd_class(void)
242 cls
.lpfnWndProc
= child_proc
;
245 cls
.hInstance
= GetModuleHandleA(NULL
);
247 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
248 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
249 cls
.lpszMenuName
= NULL
;
250 cls
.lpszClassName
= "Pager test child class";
251 return RegisterClassA(&cls
);
254 static void test_pager(void)
259 pager
= create_pager_control( PGS_HORZ
);
262 win_skip( "Pager control not supported\n" );
266 register_child_wnd_class();
268 child1_wnd
= CreateWindowA( "Pager test child class", "button", WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 300, 300,
269 pager
, 0, GetModuleHandleA(0), 0 );
270 child2_wnd
= CreateWindowA("Pager test child class", "button", WS_CHILD
| WS_BORDER
, 0, 0, 300, 300,
271 pager
, 0, GetModuleHandleA(0), 0);
273 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
274 SendMessageA( pager
, PGM_SETCHILD
, 0, (LPARAM
)child1_wnd
);
275 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_child_seq
, "set child", TRUE
);
276 GetWindowRect( pager
, &rect
);
277 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
278 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
280 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
281 SendMessageA(pager
, PGM_SETCHILD
, 0, (LPARAM
)child2_wnd
);
282 ok_sequence(sequences
, PAGER_SEQ_INDEX
, switch_child_seq
, "switch to invisible child", TRUE
);
283 GetWindowRect(pager
, &rect
);
284 ok(rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
285 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
286 todo_wine
ok(!IsWindowVisible(child2_wnd
), "Child window 2 is visible\n");
288 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
289 SendMessageA(pager
, PGM_SETCHILD
, 0, (LPARAM
)child1_wnd
);
290 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_child_seq
, "switch to visible child", TRUE
);
291 GetWindowRect(pager
, &rect
);
292 ok(rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
293 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
295 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
296 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
297 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
298 GetWindowRect( pager
, &rect
);
299 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
300 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
302 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
303 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
304 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_empty_seq
, "set pos empty", TRUE
);
306 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
307 SendMessageA( pager
, PGM_SETPOS
, 0, 9 );
308 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
310 DestroyWindow( pager
);
312 /* Test if resizing works */
313 pager
= create_pager_control( CCS_NORESIZE
);
314 ok(pager
!= NULL
, "failed to create pager control\n");
316 GetWindowRect( pager
, &rect
);
317 MoveWindow( pager
, 0, 0, 200, 100, TRUE
);
318 GetWindowRect( pager
, &rect2
);
319 ok(rect2
.right
- rect2
.left
> rect
.right
- rect
.left
, "expected pager window to resize, %s\n",
320 wine_dbgstr_rect( &rect2
));
322 DestroyWindow( pager
);
324 pager
= create_pager_control( CCS_NORESIZE
| PGS_HORZ
);
325 ok(pager
!= NULL
, "failed to create pager control\n");
327 GetWindowRect( pager
, &rect
);
328 MoveWindow( pager
, 0, 0, 100, 200, TRUE
);
329 GetWindowRect( pager
, &rect2
);
330 ok(rect2
.bottom
- rect2
.top
> rect
.bottom
- rect
.top
, "expected pager window to resize, %s\n",
331 wine_dbgstr_rect( &rect2
));
333 DestroyWindow( pager
);
338 HMODULE mod
= GetModuleHandleA("comctl32.dll");
340 pSetWindowSubclass
= (void*)GetProcAddress(mod
, (LPSTR
)410);
342 InitCommonControls();
343 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
345 parent_wnd
= create_parent_window();
346 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");