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
;
34 static BOOL (WINAPI
*pSetWindowSubclass
)(HWND
, SUBCLASSPROC
, UINT_PTR
, DWORD_PTR
);
36 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
38 static const struct message set_child_seq
[] = {
39 { PGM_SETCHILD
, sent
},
40 { WM_WINDOWPOSCHANGING
, sent
},
41 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
42 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
43 { WM_WINDOWPOSCHANGED
, sent
},
44 { WM_WINDOWPOSCHANGING
, sent
|id
, 0, 0, CHILD1_ID
},
45 { WM_NCCALCSIZE
, sent
|wparam
|id
, TRUE
, 0, CHILD1_ID
},
46 { WM_CHILDACTIVATE
, sent
|id
, 0, 0, CHILD1_ID
},
47 { WM_WINDOWPOSCHANGED
, sent
|id
, 0, 0, CHILD1_ID
},
48 { WM_SIZE
, sent
|id
|defwinproc
, 0, 0, CHILD1_ID
},
52 static const struct message set_pos_seq
[] = {
54 { WM_WINDOWPOSCHANGING
, sent
},
55 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
56 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
57 { WM_WINDOWPOSCHANGED
, sent
},
58 { WM_MOVE
, sent
|optional
},
59 /* The WM_SIZE handler sends WM_WINDOWPOSCHANGING, WM_CHILDACTIVATE
60 * and WM_WINDOWPOSCHANGED (which sends WM_MOVE) to the child.
61 * Another WM_WINDOWPOSCHANGING is sent afterwards.
63 * The 2nd WM_WINDOWPOSCHANGING is unconditional, but the comparison
64 * function is too simple to roll back an accepted message, so we have
65 * to mark the 2nd message optional. */
66 { WM_SIZE
, sent
|optional
},
67 { WM_WINDOWPOSCHANGING
, sent
|id
, 0, 0, CHILD1_ID
}, /* Actually optional. */
68 { WM_CHILDACTIVATE
, sent
|id
, 0, 0, CHILD1_ID
}, /* Actually optional. */
69 { WM_WINDOWPOSCHANGED
, sent
|id
|optional
, TRUE
, 0, CHILD1_ID
},
70 { WM_MOVE
, sent
|id
|optional
|defwinproc
, 0, 0, CHILD1_ID
},
71 { WM_WINDOWPOSCHANGING
, sent
|id
|optional
, 0, 0, CHILD1_ID
}, /* Actually not optional. */
72 { WM_CHILDACTIVATE
, sent
|id
|optional
, 0, 0, CHILD1_ID
}, /* Actually not optional. */
76 static const struct message set_pos_empty_seq
[] = {
81 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
83 static LONG defwndproc_counter
= 0;
87 /* log system messages, except for painting */
88 if (message
< WM_USER
&&
89 message
!= WM_PAINT
&&
90 message
!= WM_ERASEBKGND
&&
91 message
!= WM_NCPAINT
&&
92 message
!= WM_NCHITTEST
&&
93 message
!= WM_GETTEXT
&&
94 message
!= WM_GETICON
&&
95 message
!= WM_DEVICECHANGE
)
97 msg
.message
= message
;
98 msg
.flags
= sent
|wparam
|lparam
|parent
;
99 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
102 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
103 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
106 if (message
== WM_NOTIFY
)
108 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
114 NMPGCALCSIZE
*nmpgcs
= (NMPGCALCSIZE
*)lParam
;
115 DWORD style
= GetWindowLongA(nmpgcs
->hdr
.hwndFrom
, GWL_STYLE
);
117 if (style
& PGS_HORZ
)
118 ok(nmpgcs
->dwFlag
== PGF_CALCWIDTH
, "Unexpected flags %#x.\n", nmpgcs
->dwFlag
);
120 ok(nmpgcs
->dwFlag
== PGF_CALCHEIGHT
, "Unexpected flags %#x.\n", nmpgcs
->dwFlag
);
128 defwndproc_counter
++;
129 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
130 defwndproc_counter
--;
135 static BOOL
register_parent_wnd_class(void)
140 cls
.lpfnWndProc
= parent_wnd_proc
;
143 cls
.hInstance
= GetModuleHandleA(NULL
);
145 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
146 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
147 cls
.lpszMenuName
= NULL
;
148 cls
.lpszClassName
= "Pager test parent class";
149 return RegisterClassA(&cls
);
152 static HWND
create_parent_window(void)
154 if (!register_parent_wnd_class())
157 return CreateWindowA("Pager test parent class", "Pager test parent window",
158 WS_OVERLAPPED
| WS_VISIBLE
,
159 0, 0, 200, 200, 0, NULL
, GetModuleHandleA(NULL
), NULL
);
162 static LRESULT WINAPI
pager_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
164 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
165 struct message msg
= { 0 };
167 msg
.message
= message
;
168 msg
.flags
= sent
|wparam
|lparam
;
171 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
172 return CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
175 static HWND
create_pager_control( DWORD style
)
181 GetClientRect( parent_wnd
, &rect
);
182 hwnd
= CreateWindowA( WC_PAGESCROLLERA
, "pager", WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
183 0, 0, 100, 100, parent_wnd
, 0, GetModuleHandleA(0), 0 );
184 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)pager_subclass_proc
);
185 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
189 static LRESULT WINAPI
child_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
192 static LONG defwndproc_counter
;
195 msg
.message
= message
;
196 msg
.flags
= sent
| wparam
| lparam
;
197 if (defwndproc_counter
)
198 msg
.flags
|= defwinproc
;
202 if (hwnd
== child1_wnd
)
207 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
209 defwndproc_counter
++;
210 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
211 defwndproc_counter
--;
216 static BOOL
register_child_wnd_class(void)
221 cls
.lpfnWndProc
= child_proc
;
224 cls
.hInstance
= GetModuleHandleA(NULL
);
226 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
227 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
228 cls
.lpszMenuName
= NULL
;
229 cls
.lpszClassName
= "Pager test child class";
230 return RegisterClassA(&cls
);
233 static void test_pager(void)
238 pager
= create_pager_control( PGS_HORZ
);
241 win_skip( "Pager control not supported\n" );
245 register_child_wnd_class();
247 child1_wnd
= CreateWindowA( "Pager test child class", "button", WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 300, 300,
248 pager
, 0, GetModuleHandleA(0), 0 );
250 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
251 SendMessageA( pager
, PGM_SETCHILD
, 0, (LPARAM
)child1_wnd
);
252 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_child_seq
, "set child", TRUE
);
253 GetWindowRect( pager
, &rect
);
254 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
255 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
257 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
258 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
259 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
260 GetWindowRect( pager
, &rect
);
261 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
262 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
264 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
265 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
266 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_empty_seq
, "set pos empty", TRUE
);
268 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
269 SendMessageA( pager
, PGM_SETPOS
, 0, 9 );
270 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
272 DestroyWindow( pager
);
274 /* Test if resizing works */
275 pager
= create_pager_control( CCS_NORESIZE
);
276 ok(pager
!= NULL
, "failed to create pager control\n");
278 GetWindowRect( pager
, &rect
);
279 MoveWindow( pager
, 0, 0, 200, 100, TRUE
);
280 GetWindowRect( pager
, &rect2
);
281 ok(rect2
.right
- rect2
.left
> rect
.right
- rect
.left
, "expected pager window to resize, %s\n",
282 wine_dbgstr_rect( &rect2
));
284 DestroyWindow( pager
);
286 pager
= create_pager_control( CCS_NORESIZE
| PGS_HORZ
);
287 ok(pager
!= NULL
, "failed to create pager control\n");
289 GetWindowRect( pager
, &rect
);
290 MoveWindow( pager
, 0, 0, 100, 200, TRUE
);
291 GetWindowRect( pager
, &rect2
);
292 ok(rect2
.bottom
- rect2
.top
> rect
.bottom
- rect
.top
, "expected pager window to resize, %s\n",
293 wine_dbgstr_rect( &rect2
));
295 DestroyWindow( pager
);
300 HMODULE mod
= GetModuleHandleA("comctl32.dll");
302 pSetWindowSubclass
= (void*)GetProcAddress(mod
, (LPSTR
)410);
304 InitCommonControls();
305 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
307 parent_wnd
= create_parent_window();
308 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");