64f2a1d179fc324c118cc7babad6903897016888
[reactos.git] / rostests / winetests / gdi32 / clipping.c
1 /*
2 * Unit test suite for clipping
3 *
4 * Copyright 2005 Huw Davies
5 * Copyright 2008,2011,2013 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "wine/test.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26
27 static void test_GetRandomRgn(void)
28 {
29 HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_VISIBLE|WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0);
30 HDC hdc;
31 HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
32 int ret;
33 RECT rc, rc2;
34 RECT ret_rc, window_rc;
35
36 ok( hwnd != 0, "CreateWindow failed\n" );
37
38 SetRect(&window_rc, 400, 300, 500, 400);
39 SetWindowPos(hwnd, HWND_TOPMOST, window_rc.left, window_rc.top,
40 window_rc.right - window_rc.left, window_rc.bottom - window_rc.top, 0 );
41 hdc = GetDC(hwnd);
42
43 ret = GetRandomRgn(hdc, hrgn, 1);
44 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
45 ret = GetRandomRgn(hdc, hrgn, 2);
46 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
47 ret = GetRandomRgn(hdc, hrgn, 3);
48 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
49
50 /* Set a clip region */
51 SetRect(&rc, 20, 20, 80, 80);
52 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
53
54 ret = GetRandomRgn(hdc, hrgn, 1);
55 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
56 GetRgnBox(hrgn, &ret_rc);
57 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
58 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
59
60 ret = GetRandomRgn(hdc, hrgn, 2);
61 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
62
63 ret = GetRandomRgn(hdc, hrgn, 3);
64 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
65 GetRgnBox(hrgn, &ret_rc);
66 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
67 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
68
69 /* Move the clip to the meta and clear the clip */
70 SetMetaRgn(hdc);
71
72 ret = GetRandomRgn(hdc, hrgn, 1);
73 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
74 ret = GetRandomRgn(hdc, hrgn, 2);
75 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
76 GetRgnBox(hrgn, &ret_rc);
77 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
78 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
79
80 ret = GetRandomRgn(hdc, hrgn, 3);
81 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
82 GetRgnBox(hrgn, &ret_rc);
83 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
84 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
85
86 /* Set a new clip (still got the meta) */
87 SetRect(&rc2, 10, 30, 70, 90);
88 IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom);
89
90 ret = GetRandomRgn(hdc, hrgn, 1);
91 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
92 GetRgnBox(hrgn, &ret_rc);
93 ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
94 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
95
96 ret = GetRandomRgn(hdc, hrgn, 2);
97 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
98 GetRgnBox(hrgn, &ret_rc);
99 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
100 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
101
102 IntersectRect(&rc2, &rc, &rc2);
103
104 ret = GetRandomRgn(hdc, hrgn, 3);
105 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
106 GetRgnBox(hrgn, &ret_rc);
107 ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
108 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
109
110
111 ret = GetRandomRgn(hdc, hrgn, SYSRGN);
112 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
113 GetRgnBox(hrgn, &ret_rc);
114 if(GetVersion() & 0x80000000)
115 OffsetRect(&window_rc, -window_rc.left, -window_rc.top);
116 /* the window may be partially obscured so the region may be smaller */
117 IntersectRect( &window_rc, &ret_rc, &ret_rc );
118 ok(EqualRect(&window_rc, &ret_rc) ||
119 broken(IsRectEmpty(&ret_rc)), /* win95 */
120 "GetRandomRgn %d,%d - %d,%d\n",
121 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
122
123 DeleteObject(hrgn);
124 ReleaseDC(hwnd, hdc);
125 DestroyWindow(hwnd);
126 }
127
128 static void verify_region(HRGN hrgn, const RECT *rc)
129 {
130 union
131 {
132 RGNDATA data;
133 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
134 } rgn;
135 const RECT *rect;
136 DWORD ret;
137
138 ret = GetRegionData(hrgn, 0, NULL);
139 if (IsRectEmpty(rc))
140 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
141 else
142 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
143
144 if (!ret) return;
145
146 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
147 if (IsRectEmpty(rc))
148 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
149 else
150 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
151
152 trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
153 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
154 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
155 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
156 rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
157 if (rgn.data.rdh.nCount != 0)
158 {
159 rect = (const RECT *)rgn.data.Buffer;
160 trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
161 ok(EqualRect(rect, rc), "rects don't match\n");
162 }
163
164 ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
165 ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
166 if (IsRectEmpty(rc))
167 {
168 ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
169 ok(rgn.data.rdh.nRgnSize == 0 ||
170 broken(rgn.data.rdh.nRgnSize == 168), /* NT4 */
171 "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
172 }
173 else
174 {
175 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
176 ok(rgn.data.rdh.nRgnSize == sizeof(RECT) ||
177 broken(rgn.data.rdh.nRgnSize == 168), /* NT4 */
178 "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
179 }
180 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
181 }
182
183 static void test_ExtCreateRegion(void)
184 {
185 static const RECT empty_rect;
186 static const RECT rc = { 111, 222, 333, 444 };
187 static const RECT arc[2] = { {0, 0, 10, 10}, {10, 10, 20, 20}};
188 static const RECT rc_xformed = { 76, 151, 187, 262 };
189 union
190 {
191 RGNDATA data;
192 char buf[sizeof(RGNDATAHEADER) + 2 * sizeof(RECT)];
193 } rgn;
194 HRGN hrgn;
195 XFORM xform;
196
197 if (0) /* crashes under Win9x */
198 {
199 SetLastError(0xdeadbeef);
200 hrgn = ExtCreateRegion(NULL, 0, NULL);
201 ok(!hrgn, "ExtCreateRegion should fail\n");
202 ok(GetLastError() == ERROR_INVALID_PARAMETER, "ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
203 }
204
205 rgn.data.rdh.dwSize = 0;
206 rgn.data.rdh.iType = 0;
207 rgn.data.rdh.nCount = 0;
208 rgn.data.rdh.nRgnSize = 0;
209 SetRectEmpty(&rgn.data.rdh.rcBound);
210 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
211
212 SetLastError(0xdeadbeef);
213 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
214 ok(!hrgn, "ExtCreateRegion should fail\n");
215 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
216
217 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) - 1;
218
219 SetLastError(0xdeadbeef);
220 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
221 ok(!hrgn, "ExtCreateRegion should fail\n");
222 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
223
224 /* although XP doesn't care about the type Win9x does */
225 rgn.data.rdh.iType = RDH_RECTANGLES;
226 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
227
228 /* sizeof(RGNDATAHEADER) is large enough */
229 SetLastError(0xdeadbeef);
230 hrgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER), &rgn.data);
231 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
232 verify_region(hrgn, &empty_rect);
233 DeleteObject(hrgn);
234
235 /* Cannot be smaller than sizeof(RGNDATAHEADER) */
236 SetLastError(0xdeadbeef);
237 hrgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) - 1, &rgn.data);
238 todo_wine
239 ok(!hrgn, "ExtCreateRegion should fail\n");
240 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
241
242 SetLastError(0xdeadbeef);
243 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
244 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
245 verify_region(hrgn, &empty_rect);
246 DeleteObject(hrgn);
247
248 rgn.data.rdh.nCount = 1;
249 SetRectEmpty(&rgn.data.rdh.rcBound);
250 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
251
252 /* With a single rect this seems to work... */
253 SetLastError(0xdeadbeef);
254 hrgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + sizeof(RECT) - 1, &rgn.data);
255 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
256 verify_region(hrgn, &rc);
257 DeleteObject(hrgn);
258
259 SetLastError(0xdeadbeef);
260 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
261 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
262 verify_region(hrgn, &rc);
263 DeleteObject(hrgn);
264
265 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) + 1;
266
267 SetLastError(0xdeadbeef);
268 hrgn = ExtCreateRegion(NULL, 1, &rgn.data);
269 ok(hrgn != 0 ||
270 broken(GetLastError() == 0xdeadbeef), /* NT4 */
271 "ExtCreateRegion error %u\n", GetLastError());
272 if(hrgn)
273 {
274 verify_region(hrgn, &rc);
275 DeleteObject(hrgn);
276 }
277
278 xform.eM11 = 0.5; /* 50% width */
279 xform.eM12 = 0.0;
280 xform.eM21 = 0.0;
281 xform.eM22 = 0.5; /* 50% height */
282 xform.eDx = 20.0;
283 xform.eDy = 40.0;
284
285 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
286
287 SetLastError(0xdeadbeef);
288 hrgn = ExtCreateRegion(&xform, sizeof(rgn), &rgn.data);
289 ok(hrgn != 0, "ExtCreateRegion error %u/%x\n", GetLastError(), GetLastError());
290 verify_region(hrgn, &rc_xformed);
291 DeleteObject(hrgn);
292
293 rgn.data.rdh.nCount = 2;
294 SetRectEmpty(&rgn.data.rdh.rcBound);
295 memcpy(rgn.data.Buffer, arc, sizeof(arc));
296
297 /* Buffer cannot be smaller than sizeof(RGNDATAHEADER) + 2 * sizeof(RECT) */
298 SetLastError(0xdeadbeef);
299 hrgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + 2 * sizeof(RECT) - 1, &rgn.data);
300 todo_wine
301 ok(!hrgn, "ExtCreateRegion should fail\n");
302 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
303
304 }
305
306 static void test_GetClipRgn(void)
307 {
308 HDC hdc;
309 HRGN hrgn, hrgn2, hrgn3, hrgn4;
310 int ret;
311
312 /* Test calling GetClipRgn with NULL device context and region handles. */
313 ret = GetClipRgn(NULL, NULL);
314 ok(ret == -1, "Expected GetClipRgn to return -1, got %d\n", ret);
315
316 hdc = GetDC(NULL);
317 ok(hdc != NULL, "Expected GetDC to return a valid device context handle\n");
318
319 /* Test calling GetClipRgn with a valid device context and NULL region. */
320 ret = GetClipRgn(hdc, NULL);
321 ok(ret == 0 ||
322 ret == -1 /* Win9x */,
323 "Expected GetClipRgn to return 0, got %d\n", ret);
324
325 /* Initialize the test regions. */
326 hrgn = CreateRectRgn(100, 100, 100, 100);
327 ok(hrgn != NULL,
328 "Expected CreateRectRgn to return a handle to a new rectangular region\n");
329
330 hrgn2 = CreateRectRgn(1, 2, 3, 4);
331 ok(hrgn2 != NULL,
332 "Expected CreateRectRgn to return a handle to a new rectangular region\n");
333
334 hrgn3 = CreateRectRgn(1, 2, 3, 4);
335 ok(hrgn3 != NULL,
336 "Expected CreateRectRgn to return a handle to a new rectangular region\n");
337
338 hrgn4 = CreateRectRgn(1, 2, 3, 4);
339 ok(hrgn4 != NULL,
340 "Expected CreateRectRgn to return a handle to a new rectangular region\n");
341
342 /* Try getting a clipping region from the device context
343 * when the device context's clipping region isn't set. */
344 ret = GetClipRgn(hdc, hrgn2);
345 ok(ret == 0, "Expected GetClipRgn to return 0, got %d\n", ret);
346
347 /* The region passed to GetClipRgn should be unchanged. */
348 ret = EqualRgn(hrgn2, hrgn3);
349 ok(ret == 1,
350 "Expected EqualRgn to compare the two regions as equal, got %d\n", ret);
351
352 /* Try setting and getting back a clipping region. */
353 ret = SelectClipRgn(hdc, hrgn);
354 ok(ret == NULLREGION,
355 "Expected SelectClipRgn to return NULLREGION, got %d\n", ret);
356
357 /* Passing a NULL region handle when the device context
358 * has a clipping region results in an error. */
359 ret = GetClipRgn(hdc, NULL);
360 ok(ret == -1, "Expected GetClipRgn to return -1, got %d\n", ret);
361
362 ret = GetClipRgn(hdc, hrgn2);
363 ok(ret == 1, "Expected GetClipRgn to return 1, got %d\n", ret);
364
365 ret = EqualRgn(hrgn, hrgn2);
366 ok(ret == 1,
367 "Expected EqualRgn to compare the two regions as equal, got %d\n", ret);
368
369 /* Try unsetting and then query the clipping region. */
370 ret = SelectClipRgn(hdc, NULL);
371 ok(ret == SIMPLEREGION || (ret == COMPLEXREGION && GetSystemMetrics(SM_CMONITORS) > 1),
372 "Expected SelectClipRgn to return SIMPLEREGION, got %d\n", ret);
373
374 ret = GetClipRgn(hdc, NULL);
375 ok(ret == 0 ||
376 ret == -1 /* Win9x */,
377 "Expected GetClipRgn to return 0, got %d\n", ret);
378
379 ret = GetClipRgn(hdc, hrgn3);
380 ok(ret == 0, "Expected GetClipRgn to return 0, got %d\n", ret);
381
382 ret = EqualRgn(hrgn3, hrgn4);
383 ok(ret == 1,
384 "Expected EqualRgn to compare the two regions as equal, got %d\n", ret);
385
386 DeleteObject(hrgn4);
387 DeleteObject(hrgn3);
388 DeleteObject(hrgn2);
389 DeleteObject(hrgn);
390 ReleaseDC(NULL, hdc);
391 }
392
393 static void test_memory_dc_clipping(void)
394 {
395 HDC hdc;
396 HRGN hrgn, hrgn_empty;
397 HBITMAP hbmp;
398 RECT rc;
399 int ret;
400
401 hdc = CreateCompatibleDC(0);
402 hrgn_empty = CreateRectRgn(0, 0, 0, 0);
403 hrgn = CreateRectRgn(0, 0, 0, 0);
404 hbmp = CreateCompatibleBitmap(hdc, 100, 100);
405
406 ret = GetClipRgn(hdc, hrgn);
407 ok(ret == 0, "expected 0, got %d\n", ret);
408
409 ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF);
410 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
411
412 ret = GetClipRgn(hdc, hrgn);
413 ok(ret == 1, "expected 1, got %d\n", ret);
414
415 ret = GetRgnBox(hrgn, &rc);
416 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
417 ok(rc.left == 0 && rc.top == 0 && rc.right == 1 && rc.bottom == 1,
418 "expected 0,0-1,1, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
419
420 ret = ExtSelectClipRgn(hdc, 0, RGN_COPY);
421 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
422
423 ret = GetClipRgn(hdc, hrgn);
424 ok(ret == 0, "expected 0, got %d\n", ret);
425
426 ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF);
427 ok(ret == 0, "expected 0, got %d\n", ret);
428
429 ret = GetClipRgn(hdc, hrgn);
430 ok(ret == 0, "expected 0, got %d\n", ret);
431
432 SelectObject(hdc, hbmp);
433
434 ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF);
435 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
436
437 ret = GetClipRgn(hdc, hrgn);
438 ok(ret == 1, "expected 1, got %d\n", ret);
439
440 ret = GetRgnBox(hrgn, &rc);
441 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
442 ok(rc.left == 0 && rc.top == 0 && rc.right == 100 && rc.bottom == 100,
443 "expected 0,0-100,100, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
444
445 SetRect( &rc, 10, 10, 20, 20 );
446 ret = RectVisible( hdc, &rc );
447 ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom );
448
449 SetRect( &rc, 20, 20, 10, 10 );
450 ret = RectVisible( hdc, &rc );
451 ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom );
452
453 ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF);
454 ok(ret == 0, "expected 0, got %d\n", ret);
455
456 ret = GetClipRgn(hdc, hrgn);
457 ok(ret == 1, "expected 1, got %d\n", ret);
458
459 ret = GetRgnBox(hrgn, &rc);
460 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
461 ok(rc.left == 0 && rc.top == 0 && rc.right == 100 && rc.bottom == 100,
462 "expected 0,0-100,100, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
463
464 DeleteDC(hdc);
465 DeleteObject(hrgn);
466 DeleteObject(hrgn_empty);
467 DeleteObject(hbmp);
468 }
469
470 static void test_window_dc_clipping(void)
471 {
472 HDC hdc;
473 HRGN hrgn, hrgn_empty;
474 HWND hwnd;
475 RECT rc, virtual_rect;
476 int ret, screen_width, screen_height;
477
478 /* Windows versions earlier than Win2k do not support the virtual screen metrics,
479 * so we fall back to the primary screen metrics. */
480 screen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
481 if(!screen_width) screen_width = GetSystemMetrics(SM_CXSCREEN);
482 screen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
483 if(!screen_height) screen_height = GetSystemMetrics(SM_CYSCREEN);
484 SetRect(&virtual_rect, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN),
485 GetSystemMetrics(SM_XVIRTUALSCREEN) + screen_width, GetSystemMetrics(SM_YVIRTUALSCREEN) + screen_height);
486
487 trace("screen resolution %d x %d\n", screen_width, screen_height);
488
489 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
490 -100, -100, screen_width * 2, screen_height * 2, 0, 0, 0, NULL);
491 hdc = GetWindowDC(0);
492 hrgn_empty = CreateRectRgn(0, 0, 0, 0);
493 hrgn = CreateRectRgn(0, 0, 0, 0);
494
495 ret = GetClipRgn(hdc, hrgn);
496 ok(ret == 0, "expected 0, got %d\n", ret);
497
498 ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF);
499 ok(ret == 0, "expected 0, got %d\n", ret);
500
501 ret = GetClipRgn(hdc, hrgn);
502 ok(ret == 0, "expected 0, got %d\n", ret);
503
504 ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF);
505 ok(ret == SIMPLEREGION || (ret == COMPLEXREGION && GetSystemMetrics(SM_CMONITORS) > 1),
506 "expected SIMPLEREGION, got %d\n", ret);
507
508 ret = GetClipRgn(hdc, hrgn);
509 ok(ret == 1, "expected 1, got %d\n", ret);
510
511 ret = GetRgnBox(hrgn, &rc);
512 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
513 ok(EqualRect(&rc, &virtual_rect), "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
514 virtual_rect.left, virtual_rect.top, virtual_rect.right, virtual_rect.bottom,
515 rc.left, rc.top, rc.right, rc.bottom);
516
517 SetRect( &rc, 10, 10, 20, 20 );
518 ret = RectVisible( hdc, &rc );
519 ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom );
520
521 SetRect( &rc, 20, 20, 10, 10 );
522 ret = RectVisible( hdc, &rc );
523 ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom );
524
525 ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF);
526 ok(ret == 0, "expected 0, got %d\n", ret);
527
528 ret = GetClipRgn(hdc, hrgn);
529 ok(ret == 1, "expected 1, got %d\n", ret);
530
531 ret = GetRgnBox(hrgn, &rc);
532 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
533 ok(EqualRect(&rc, &virtual_rect), "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
534 virtual_rect.left, virtual_rect.top, virtual_rect.right, virtual_rect.bottom,
535 rc.left, rc.top, rc.right, rc.bottom);
536
537 ret = ExtSelectClipRgn(hdc, 0, RGN_COPY);
538 ok(ret == SIMPLEREGION || (ret == COMPLEXREGION && GetSystemMetrics(SM_CMONITORS) > 1),
539 "expected SIMPLEREGION, got %d\n", ret);
540
541 ret = GetClipRgn(hdc, hrgn);
542 ok(ret == 0, "expected 0, got %d\n", ret);
543
544 DeleteDC(hdc);
545 DeleteObject(hrgn);
546 DeleteObject(hrgn_empty);
547 DestroyWindow(hwnd);
548 }
549
550
551 START_TEST(clipping)
552 {
553 test_GetRandomRgn();
554 test_ExtCreateRegion();
555 test_GetClipRgn();
556 test_memory_dc_clipping();
557 test_window_dc_clipping();
558 }