befcfc620504cc851fb27f50b00dfaed9b6a9c75
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for Button window class v6
5 * PROGRAMMERS: Giannis Adamopoulos
13 #define ok_rect(rc, l,r,t,b) ok((rc.left == (l)) && (rc.right == (r)) && (rc.top == (t)) && (rc.bottom == (b)), "Wrong rect. expected %d, %d, %d, %d got %ld, %ld, %ld, %ld\n", l,t,r,b, rc.left, rc.top, rc.right, rc.bottom)
14 #define ok_size(s, width, height) ok((s.cx == (width) && s.cy == (height)), "Expected size (%lu,%lu) got (%lu,%lu)\n", width, height, s.cx, s.cy)
16 void Test_TextMargin()
22 hwnd1
= CreateWindowW(L
"Button", L
"Test1", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
23 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
25 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
26 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
27 ok_rect(rc
, 1, 1, 1, 1);
29 SetRect(&rc
, 0,0,0,0);
30 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
31 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
33 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
34 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
35 ok_rect(rc
, 0, 0, 0, 0);
37 SetRect(&rc
, -1,-1,-1,-1);
38 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
39 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
41 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
42 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
43 ok_rect(rc
, -1, -1, -1, -1);
45 SetRect(&rc
, 1000,1000,1000,1000);
46 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
47 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
49 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
50 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
51 ok_rect(rc
, 1000, 1000, 1000, 1000);
60 BUTTON_IMAGELIST imlData
;
62 hwnd1
= CreateWindowW(L
"Button", L
"Test2", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
63 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
65 ret
= SendMessageW(hwnd1
, BCM_GETIMAGELIST
, 0, (LPARAM
)&imlData
);
66 ok (ret
== TRUE
, "Expected BCM_GETIMAGELIST to succeed\n");
67 ok (imlData
.himl
== 0, "Expected 0 himl\n");
68 ok (imlData
.uAlign
== 0, "Expected 0 uAlign\n");
69 ok_rect(imlData
.margin
, 0, 0, 0, 0);
71 SetRect(&imlData
.margin
, 0,0,0,1);
72 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
73 ok (ret
== FALSE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
75 imlData
.himl
= (HIMAGELIST
)0xdead;
76 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
77 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n");
79 ret
= SendMessageW(hwnd1
, BCM_GETIMAGELIST
, 0, (LPARAM
)&imlData
);
80 ok (ret
== TRUE
, "Expected BCM_GETIMAGELIST to succeed\n");
81 ok (imlData
.himl
== (HIMAGELIST
)0xdead, "Expected 0 himl\n");
82 ok (imlData
.uAlign
== 0, "Expected 0 uAlign\n");
83 ok_rect(imlData
.margin
, 0, 0, 0, 1);
86 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
87 ok (ret
== FALSE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
92 void Test_GetIdealSizeNoThemes()
102 BUTTON_IMAGELIST imlData
;
105 hwnd1
= CreateWindowW(L
"Button", L
" ", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
106 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
107 SetWindowTheme(hwnd1
, L
"", L
"");
109 font
= (HFONT
)SendMessageW(hwnd1
, WM_GETFONT
, 0, 0);
111 SelectObject(hdc
, font
);
112 GetTextExtentPoint32W(hdc
, L
" ", 1, &textent
);
114 memset(&wi
, 0, sizeof(wi
));
115 GetWindowInfo(hwnd1
, &wi
);
117 memset(&s
, 0, sizeof(s
));
118 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
119 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
120 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
- 1 + 2,
121 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1 + 2); /* the last +2 is the text margin */
123 DestroyWindow(hwnd1
);
128 hwnd1
= CreateWindowW(L
"Button", L
"", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
129 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
130 SetWindowTheme(hwnd1
, L
"", L
"");
132 memset(&s
, 0, sizeof(s
));
133 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
134 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
135 ok (s
.cx
> 80, "Expected big cx\n");
136 ok (s
.cy
> 80, "Expected big cy\n");
140 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
141 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
142 ok (s
.cx
> 80, "Expected big cx\n");
143 ok (s
.cy
> 80, "Expected big cy\n");
145 hbmp
= LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(5), IMAGE_BITMAP
, 0, 0, 0);
146 ok (hbmp
!= 0, "Expected LoadImage to succeed\n");
148 SendMessageW(hwnd1
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)hbmp
);
150 memset(&s
, 0, sizeof(s
));
151 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
152 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
153 ok (s
.cx
> 80, "Expected big cx\n");
154 ok (s
.cy
> 80, "Expected big cy\n");
156 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(5), 1, 1, 0, IMAGE_BITMAP
, 0);
157 ok (himl
!= 0, "Expected ImageList_LoadImage to succeed\n");
159 memset(&imlData
, 0, sizeof(imlData
));
161 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
162 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
164 memset(&s
, 0, sizeof(s
));
165 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
166 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
167 ok (s
.cx
> 80, "Expected big cx\n");
168 ok (s
.cy
> 80, "Expected big cy\n");
170 DestroyWindow(hwnd1
);
175 hwnd1
= CreateWindowW(L
"Button", L
" ", BS_BITMAP
, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
176 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
177 SetWindowTheme(hwnd1
, L
"", L
"");
179 SendMessageW(hwnd1
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)hbmp
);
181 memset(&s
, 0, sizeof(s
));
182 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
183 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
185 /* In xp and 2k3 the image is ignored, in vista+ its width is added to the text width */
186 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
- 1 + 2,
187 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1 + 2); /* the last +2 is the text margin */
189 DestroyWindow(hwnd1
);
194 hwnd1
= CreateWindowW(L
"Button", L
" ", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
195 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
196 SetWindowTheme(hwnd1
, L
"", L
"");
198 SetRect(&rc
, 0,0,0,0);
199 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
200 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
202 memset(&s
, 0, sizeof(s
));
203 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
204 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
205 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
- 1,
206 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1);
208 SetRect(&rc
, 50,50,50,50);
209 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
210 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
212 memset(&s
, 0, sizeof(s
));
213 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
214 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
215 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
- 1 + 100,
216 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1 + 100);
218 SetRect(&rc
, 0,0,0,0);
219 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
220 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
222 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
223 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
225 memset(&s
, 0, sizeof(s
));
226 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
227 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
228 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
, /* we get an extra pixel due to the iml */
229 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1);
233 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
234 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
235 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
,
236 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1);
240 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
241 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
242 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
,
243 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1);
245 DestroyWindow(hwnd1
);
250 /* Test again with some real text to see if the formula is correct */
251 hwnd1
= CreateWindowW(L
"Button", L
"Some test text", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
252 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
253 SetWindowTheme(hwnd1
, L
"", L
"");
255 font
= (HFONT
)SendMessageW(hwnd1
, WM_GETFONT
, 0, 0);
257 SelectObject(hdc
, font
);
258 GetTextExtentPoint32W(hdc
, L
"Some test text", 14, &textent
);
260 memset(&s
, 0, sizeof(s
));
261 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
262 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
263 ok_size(s
, textent
.cx
+ 2 * wi
.cxWindowBorders
- 1 + 2, /* the last +2 is the text margin */
264 textent
.cy
+ 2 * wi
.cyWindowBorders
+ 1 + 2);
266 DestroyWindow(hwnd1
);
271 LoadLibraryW(L
"comctl32.dll"); /* same as statically linking to comctl32 and doing InitCommonControls */
274 Test_GetIdealSizeNoThemes();