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
;
32 static BOOL (WINAPI
*pSetWindowSubclass
)(HWND
, SUBCLASSPROC
, UINT_PTR
, DWORD_PTR
);
34 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
36 static const struct message set_child_seq
[] = {
37 { PGM_SETCHILD
, sent
},
38 { WM_WINDOWPOSCHANGING
, sent
},
39 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
40 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
41 { WM_WINDOWPOSCHANGED
, sent
},
45 static const struct message set_pos_seq
[] = {
47 { WM_WINDOWPOSCHANGING
, sent
},
48 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
49 { WM_NOTIFY
, sent
|id
|parent
, 0, 0, PGN_CALCSIZE
},
50 { WM_WINDOWPOSCHANGED
, sent
},
51 { WM_MOVE
, sent
|optional
},
52 { WM_SIZE
, sent
|optional
},
56 static const struct message set_pos_empty_seq
[] = {
61 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
63 static LONG defwndproc_counter
= 0;
67 /* log system messages, except for painting */
68 if (message
< WM_USER
&&
69 message
!= WM_PAINT
&&
70 message
!= WM_ERASEBKGND
&&
71 message
!= WM_NCPAINT
&&
72 message
!= WM_NCHITTEST
&&
73 message
!= WM_GETTEXT
&&
74 message
!= WM_GETICON
&&
75 message
!= WM_DEVICECHANGE
)
77 msg
.message
= message
;
78 msg
.flags
= sent
|wparam
|lparam
|parent
;
79 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
82 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
83 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
87 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
93 static BOOL
register_parent_wnd_class(void)
98 cls
.lpfnWndProc
= parent_wnd_proc
;
101 cls
.hInstance
= GetModuleHandleA(NULL
);
103 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
104 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
105 cls
.lpszMenuName
= NULL
;
106 cls
.lpszClassName
= "Pager test parent class";
107 return RegisterClassA(&cls
);
110 static HWND
create_parent_window(void)
112 if (!register_parent_wnd_class())
115 return CreateWindowA("Pager test parent class", "Pager test parent window",
116 WS_OVERLAPPED
| WS_VISIBLE
,
117 0, 0, 200, 200, 0, NULL
, GetModuleHandleA(NULL
), NULL
);
120 static LRESULT WINAPI
pager_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
122 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
125 msg
.message
= message
;
126 msg
.flags
= sent
|wparam
|lparam
;
130 add_message(sequences
, PAGER_SEQ_INDEX
, &msg
);
131 return CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
134 static HWND
create_pager_control( DWORD style
)
140 GetClientRect( parent_wnd
, &rect
);
141 hwnd
= CreateWindowA( WC_PAGESCROLLERA
, "pager", WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
142 0, 0, 100, 100, parent_wnd
, 0, GetModuleHandleA(0), 0 );
143 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)pager_subclass_proc
);
144 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
148 static void test_pager(void)
153 pager
= create_pager_control( PGS_HORZ
);
156 win_skip( "Pager control not supported\n" );
159 child
= CreateWindowA( "BUTTON", "button", WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 300, 300,
160 pager
, 0, GetModuleHandleA(0), 0 );
162 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
163 SendMessageA( pager
, PGM_SETCHILD
, 0, (LPARAM
)child
);
164 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_child_seq
, "set child", TRUE
);
165 GetWindowRect( pager
, &rect
);
166 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
167 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
169 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
170 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
171 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
172 GetWindowRect( pager
, &rect
);
173 ok( rect
.right
- rect
.left
== 100 && rect
.bottom
- rect
.top
== 100,
174 "pager resized %dx%d\n", rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
176 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
177 SendMessageA( pager
, PGM_SETPOS
, 0, 10 );
178 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_empty_seq
, "set pos empty", TRUE
);
180 flush_sequences( sequences
, NUM_MSG_SEQUENCES
);
181 SendMessageA( pager
, PGM_SETPOS
, 0, 9 );
182 ok_sequence(sequences
, PAGER_SEQ_INDEX
, set_pos_seq
, "set pos", TRUE
);
184 DestroyWindow( pager
);
189 HMODULE mod
= GetModuleHandleA("comctl32.dll");
191 pSetWindowSubclass
= (void*)GetProcAddress(mod
, (LPSTR
)410);
193 InitCommonControls();
194 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
196 parent_wnd
= create_parent_window();
197 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");