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 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
79 msg.message = message;
80 msg.flags = sent|wparam|lparam|parent;
81 if (defwndproc_counter) msg.flags |= defwinproc;
84 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
85 add_message(sequences, PAGER_SEQ_INDEX, &msg);
89 ret = DefWindowProcA(hwnd, message, wParam, lParam);
95 static BOOL register_parent_wnd_class(void)
100 cls.lpfnWndProc = parent_wnd_proc;
103 cls.hInstance = GetModuleHandleA(NULL);
105 cls.hCursor = LoadCursorA(0, IDC_ARROW);
106 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
107 cls.lpszMenuName = NULL;
108 cls.lpszClassName = "Pager test parent class";
109 return RegisterClassA(&cls);
112 static HWND create_parent_window(void)
114 if (!register_parent_wnd_class())
117 return CreateWindow("Pager test parent class", "Pager test parent window",
118 WS_OVERLAPPED | WS_VISIBLE,
119 0, 0, 200, 200, 0, NULL, GetModuleHandleA(NULL), NULL );
122 static LRESULT WINAPI pager_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
124 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
127 trace("pager: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
129 msg.message = message;
130 msg.flags = sent|wparam|lparam;
134 add_message(sequences, PAGER_SEQ_INDEX, &msg);
135 return CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
138 static HWND create_pager_control( DWORD style )
144 GetClientRect( parent_wnd, &rect );
145 hwnd = CreateWindowA( WC_PAGESCROLLERA, "pager", WS_CHILD | WS_BORDER | WS_VISIBLE | style,
146 0, 0, 100, 100, parent_wnd, 0, GetModuleHandleA(0), 0 );
147 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)pager_subclass_proc);
148 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
152 static void test_pager(void)
157 pager = create_pager_control( PGS_HORZ );
160 win_skip( "Pager control not supported\n" );
163 child = CreateWindowA( "BUTTON", "button", WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 300, 300,
164 pager, 0, GetModuleHandleA(0), 0 );
166 flush_sequences( sequences, NUM_MSG_SEQUENCES );
167 SendMessageA( pager, PGM_SETCHILD, 0, (LPARAM)child );
168 ok_sequence(sequences, PAGER_SEQ_INDEX, set_child_seq, "set child", TRUE);
169 GetWindowRect( pager, &rect );
170 ok( rect.right - rect.left == 100 && rect.bottom - rect.top == 100,
171 "pager resized %dx%d\n", rect.right - rect.left, rect.bottom - rect.top );
173 flush_sequences( sequences, NUM_MSG_SEQUENCES );
174 SendMessageA( pager, PGM_SETPOS, 0, 10 );
175 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_seq, "set pos", TRUE);
176 GetWindowRect( pager, &rect );
177 ok( rect.right - rect.left == 100 && rect.bottom - rect.top == 100,
178 "pager resized %dx%d\n", rect.right - rect.left, rect.bottom - rect.top );
180 flush_sequences( sequences, NUM_MSG_SEQUENCES );
181 SendMessageA( pager, PGM_SETPOS, 0, 10 );
182 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_empty_seq, "set pos empty", TRUE);
184 flush_sequences( sequences, NUM_MSG_SEQUENCES );
185 SendMessageA( pager, PGM_SETPOS, 0, 9 );
186 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_seq, "set pos", TRUE);
188 DestroyWindow( pager );
193 HMODULE mod = GetModuleHandleA("comctl32.dll");
195 pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410);
197 InitCommonControls();
198 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
200 parent_wnd = create_parent_window();
201 ok(parent_wnd != NULL, "Failed to create parent window!\n");