clipping.c 15.9 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * DC clipping functions
 *
 * Copyright 1993 Alexandre Julliard
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21
#include <stdarg.h>
22
#include <stdlib.h>
23
#include "windef.h"
24
#include "winbase.h"
25
#include "wingdi.h"
26
#include "gdi_private.h"
27
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
28

29
WINE_DEFAULT_DEBUG_CHANNEL(clipping);
Alexandre Julliard's avatar
Alexandre Julliard committed
30 31


32 33
/* return the DC device rectangle if not empty */
static inline BOOL get_dc_device_rect( DC *dc, RECT *rect )
34
{
35 36 37
    *rect = dc->device_rect;
    offset_rect( rect, -dc->vis_rect.left, -dc->vis_rect.top );
    return !is_rect_empty( rect );
38 39
}

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/***********************************************************************
 *           get_clip_rect
 *
 * Compute a clip rectangle from its logical coordinates.
 */
static inline RECT get_clip_rect( DC * dc, int left, int top, int right, int bottom )
{
    RECT rect;

    rect.left   = left;
    rect.top    = top;
    rect.right  = right;
    rect.bottom = bottom;
    LPtoDP( dc->hSelf, (POINT *)&rect, 2 );
    if (dc->layout & LAYOUT_RTL)
    {
        int tmp = rect.left;
        rect.left = rect.right + 1;
        rect.right = tmp + 1;
    }
    return rect;
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76
/***********************************************************************
 *           clip_device_rect
 *
 * Clip a rectangle to the whole DC surface.
 */
BOOL clip_device_rect( DC *dc, RECT *dst, const RECT *src )
{
    RECT clip;

    if (get_dc_device_rect( dc, &clip )) return intersect_rect( dst, src, &clip );
    *dst = *src;
    return TRUE;
}

77 78 79 80 81 82 83 84 85
/***********************************************************************
 *           clip_visrect
 *
 * Clip a rectangle to the DC visible rect.
 */
BOOL clip_visrect( DC *dc, RECT *dst, const RECT *src )
{
    RECT clip;

86 87 88
    if (!clip_device_rect( dc, dst, src )) return FALSE;
    if (GetRgnBox( get_dc_region(dc), &clip )) return intersect_rect( dst, dst, &clip );
    return TRUE;
89 90
}

Alexandre Julliard's avatar
Alexandre Julliard committed
91
/***********************************************************************
92
 *           update_dc_clipping
Alexandre Julliard's avatar
Alexandre Julliard committed
93
 *
94
 * Update the DC and device clip regions when the ClipRgn or VisRgn have changed.
Alexandre Julliard's avatar
Alexandre Julliard committed
95
 */
96
void update_dc_clipping( DC * dc )
Alexandre Julliard's avatar
Alexandre Julliard committed
97
{
98
    PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceClipping );
99 100
    HRGN regions[3];
    int count = 0;
101

102 103 104 105 106
    if (dc->hVisRgn)  regions[count++] = dc->hVisRgn;
    if (dc->hClipRgn) regions[count++] = dc->hClipRgn;
    if (dc->hMetaRgn) regions[count++] = dc->hMetaRgn;

    if (count > 1)
107 108
    {
        if (!dc->region) dc->region = CreateRectRgn( 0, 0, 0, 0 );
109 110
        CombineRgn( dc->region, regions[0], regions[1], RGN_AND );
        if (count > 2) CombineRgn( dc->region, dc->region, regions[2], RGN_AND );
111
    }
112
    else  /* only one region, we don't need the total region */
113 114 115
    {
        if (dc->region) DeleteObject( dc->region );
        dc->region = 0;
116
    }
117
    physdev->funcs->pSetDeviceClipping( physdev, get_dc_region( dc ));
Alexandre Julliard's avatar
Alexandre Julliard committed
118 119
}

120
/***********************************************************************
121
 *           create_default_clip_region
122 123 124 125 126
 *
 * Create a default clipping region when none already exists.
 */
static inline void create_default_clip_region( DC * dc )
{
127
    RECT rect;
128

129
    if (!get_dc_device_rect( dc, &rect ))
130
    {
131 132 133 134
        rect.left = 0;
        rect.top = 0;
        rect.right = GetDeviceCaps( dc->hSelf, DESKTOPHORZRES );
        rect.bottom = GetDeviceCaps( dc->hSelf, DESKTOPVERTRES );
135
    }
136
    dc->hClipRgn = CreateRectRgnIndirect( &rect );
137 138
}

Alexandre Julliard's avatar
Alexandre Julliard committed
139

Alexandre Julliard's avatar
Alexandre Julliard committed
140
/***********************************************************************
141
 *           null driver fallback implementations
Alexandre Julliard's avatar
Alexandre Julliard committed
142
 */
143

144
INT nulldrv_ExtSelectClipRgn( PHYSDEV dev, HRGN rgn, INT mode )
Alexandre Julliard's avatar
Alexandre Julliard committed
145
{
146 147
    DC *dc = get_nulldrv_dc( dev );
    INT ret;
148

149
    if (!rgn)
Alexandre Julliard's avatar
Alexandre Julliard committed
150
    {
151
        switch (mode)
152
        {
153 154 155 156 157 158 159 160 161 162
        case RGN_COPY:
            if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
            dc->hClipRgn = 0;
            ret = SIMPLEREGION;
            break;

        case RGN_DIFF:
            return ERROR;

        default:
163
            FIXME("Unimplemented: hrgn NULL in mode: %d\n", mode);
164 165
            return ERROR;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
166
    }
167
    else
Alexandre Julliard's avatar
Alexandre Julliard committed
168
    {
169 170 171 172
        HRGN mirrored = 0;

        if (dc->layout & LAYOUT_RTL)
        {
173 174 175
            if (!(mirrored = CreateRectRgn( 0, 0, 0, 0 ))) return ERROR;
            mirror_region( mirrored, rgn, dc->vis_rect.right - dc->vis_rect.left );
            rgn = mirrored;
176 177
        }

178
        if (!dc->hClipRgn)
179
            create_default_clip_region( dc );
180

181 182
        if (mode == RGN_COPY)
            ret = CombineRgn( dc->hClipRgn, rgn, 0, mode );
183
        else
184
            ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, rgn, mode);
185 186

        if (mirrored) DeleteObject( mirrored );
Alexandre Julliard's avatar
Alexandre Julliard committed
187
    }
188
    update_dc_clipping( dc );
189 190
    return ret;
}
191

192
INT nulldrv_ExcludeClipRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
193 194 195 196 197 198 199 200 201 202
{
    DC *dc = get_nulldrv_dc( dev );
    RECT rect = get_clip_rect( dc, left, top, right, bottom );
    INT ret;
    HRGN rgn;

    if (!(rgn = CreateRectRgnIndirect( &rect ))) return ERROR;
    if (!dc->hClipRgn) create_default_clip_region( dc );
    ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, rgn, RGN_DIFF );
    DeleteObject( rgn );
203
    if (ret != ERROR) update_dc_clipping( dc );
204 205 206
    return ret;
}

207
INT nulldrv_IntersectClipRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
{
    DC *dc = get_nulldrv_dc( dev );
    RECT rect = get_clip_rect( dc, left, top, right, bottom );
    INT ret;
    HRGN rgn;

    if (!dc->hClipRgn)
    {
        dc->hClipRgn = CreateRectRgnIndirect( &rect );
        ret = SIMPLEREGION;
    }
    else
    {
        if (!(rgn = CreateRectRgnIndirect( &rect ))) return ERROR;
        ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, rgn, RGN_AND );
        DeleteObject( rgn );
    }
225
    if (ret != ERROR) update_dc_clipping( dc );
226 227 228
    return ret;
}

229
INT nulldrv_OffsetClipRgn( PHYSDEV dev, INT x, INT y )
230 231 232 233 234 235 236 237 238 239
{
    DC *dc = get_nulldrv_dc( dev );
    INT ret = NULLREGION;

    if (dc->hClipRgn)
    {
        x = MulDiv( x, dc->vportExtX, dc->wndExtX );
        y = MulDiv( y, dc->vportExtY, dc->wndExtY );
        if (dc->layout & LAYOUT_RTL) x = -x;
        ret = OffsetRgn( dc->hClipRgn, x, y );
240
	update_dc_clipping( dc );
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
    }
    return ret;
}


/***********************************************************************
 *           SelectClipRgn    (GDI32.@)
 */
INT WINAPI SelectClipRgn( HDC hdc, HRGN hrgn )
{
    return ExtSelectClipRgn( hdc, hrgn, RGN_COPY );
}


/******************************************************************************
 *		ExtSelectClipRgn	[GDI32.@]
 */
INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode )
{
260 261
    PHYSDEV physdev;
    INT retval;
262 263 264 265
    DC * dc = get_dc_ptr( hdc );

    TRACE("%p %p %d\n", hdc, hrgn, fnMode );

266 267 268 269 270
    if (!dc) return ERROR;
    update_dc( dc );
    physdev = GET_DC_PHYSDEV( dc, pExtSelectClipRgn );
    retval = physdev->funcs->pExtSelectClipRgn( physdev, hrgn, fnMode );
    release_dc_ptr( dc );
271
    return retval;
Alexandre Julliard's avatar
Alexandre Julliard committed
272 273 274
}

/***********************************************************************
275
 *           __wine_set_visible_region   (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
276
 */
277 278
void CDECL __wine_set_visible_region( HDC hdc, HRGN hrgn, const RECT *vis_rect, const RECT *device_rect,
                                      struct window_surface *surface )
Alexandre Julliard's avatar
Alexandre Julliard committed
279
{
280 281
    DC * dc;

282
    if (!(dc = get_dc_ptr( hdc ))) return;
Alexandre Julliard's avatar
Alexandre Julliard committed
283

284 285
    TRACE( "%p %p %s %s %p\n", hdc, hrgn,
           wine_dbgstr_rect(vis_rect), wine_dbgstr_rect(device_rect), surface );
Alexandre Julliard's avatar
Alexandre Julliard committed
286

287 288
    /* map region to DC coordinates */
    OffsetRgn( hrgn, -vis_rect->left, -vis_rect->top );
Alexandre Julliard's avatar
Alexandre Julliard committed
289

290
    if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
291
    dc->dirty = 0;
292
    dc->vis_rect = *vis_rect;
293
    dc->device_rect = *device_rect;
294
    dc->hVisRgn = hrgn;
295
    dibdrv_set_window_surface( dc, surface );
296
    DC_UpdateXforms( dc );
297
    update_dc_clipping( dc );
298
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
299 300 301
}


Alexandre Julliard's avatar
Alexandre Julliard committed
302
/***********************************************************************
303
 *           OffsetClipRgn    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
304
 */
305
INT WINAPI OffsetClipRgn( HDC hdc, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
306
{
307 308
    PHYSDEV physdev;
    INT ret;
309
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
310

311
    TRACE("%p %d,%d\n", hdc, x, y );
Alexandre Julliard's avatar
Alexandre Julliard committed
312

313 314 315 316 317
    if (!dc) return ERROR;
    update_dc( dc );
    physdev = GET_DC_PHYSDEV( dc, pOffsetClipRgn );
    ret = physdev->funcs->pOffsetClipRgn( physdev, x, y );
    release_dc_ptr( dc );
318
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
319 320 321
}


Alexandre Julliard's avatar
Alexandre Julliard committed
322
/***********************************************************************
323
 *           ExcludeClipRect    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
324
 */
325 326
INT WINAPI ExcludeClipRect( HDC hdc, INT left, INT top,
                                INT right, INT bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
327
{
328 329
    PHYSDEV physdev;
    INT ret;
330
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
331

332
    TRACE("%p %d,%d-%d,%d\n", hdc, left, top, right, bottom );
333

334 335 336 337 338
    if (!dc) return ERROR;
    update_dc( dc );
    physdev = GET_DC_PHYSDEV( dc, pExcludeClipRect );
    ret = physdev->funcs->pExcludeClipRect( physdev, left, top, right, bottom );
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
339
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
340 341 342
}


Alexandre Julliard's avatar
Alexandre Julliard committed
343
/***********************************************************************
344
 *           IntersectClipRect    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
345
 */
346
INT WINAPI IntersectClipRect( HDC hdc, INT left, INT top, INT right, INT bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
347
{
348 349
    PHYSDEV physdev;
    INT ret;
350
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
351

352
    TRACE("%p %d,%d - %d,%d\n", hdc, left, top, right, bottom );
353

354 355 356 357 358
    if (!dc) return ERROR;
    update_dc( dc );
    physdev = GET_DC_PHYSDEV( dc, pIntersectClipRect );
    ret = physdev->funcs->pIntersectClipRect( physdev, left, top, right, bottom );
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
359
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
360 361 362
}


Alexandre Julliard's avatar
Alexandre Julliard committed
363
/***********************************************************************
364
 *           PtVisible    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
365
 */
366
BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
367
{
368
    POINT pt;
369
    RECT visrect;
370
    BOOL ret;
371
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
372

373
    TRACE("%p %d,%d\n", hdc, x, y );
374
    if (!dc) return FALSE;
375

376 377 378
    pt.x = x;
    pt.y = y;
    LPtoDP( hdc, &pt, 1 );
379
    update_dc( dc );
380
    ret = (!get_dc_device_rect( dc, &visrect ) ||
381 382
           (pt.x >= visrect.left && pt.x < visrect.right &&
            pt.y >= visrect.top && pt.y < visrect.bottom));
383
    if (ret && get_dc_region( dc )) ret = PtInRegion( get_dc_region( dc ), pt.x, pt.y );
384
    release_dc_ptr( dc );
385 386
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
387 388


389 390 391 392
/***********************************************************************
 *           RectVisible    (GDI32.@)
 */
BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
Alexandre Julliard's avatar
Alexandre Julliard committed
393
{
394
    RECT tmpRect, visrect;
395
    BOOL ret;
396
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
397
    if (!dc) return FALSE;
398
    TRACE("%p %s\n", hdc, wine_dbgstr_rect( rect ));
399

400 401
    tmpRect = *rect;
    LPtoDP( hdc, (POINT *)&tmpRect, 2 );
402
    order_rect( &tmpRect );
403

404
    update_dc( dc );
405
    ret = (!get_dc_device_rect( dc, &visrect ) || intersect_rect( &visrect, &visrect, &tmpRect ));
406
    if (ret && get_dc_region( dc )) ret = RectInRegion( get_dc_region( dc ), &tmpRect );
407
    release_dc_ptr( dc );
408
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
409 410 411
}


Alexandre Julliard's avatar
Alexandre Julliard committed
412
/***********************************************************************
413
 *           GetClipBox    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
414
 */
415
INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
Alexandre Julliard's avatar
Alexandre Julliard committed
416
{
417
    RECT visrect;
418
    INT ret;
419
    DC *dc = get_dc_ptr( hdc );
420
    if (!dc) return ERROR;
421 422

    update_dc( dc );
423 424 425 426
    if (get_dc_region( dc ))
    {
        ret = GetRgnBox( get_dc_region( dc ), rect );
    }
427 428 429 430 431
    else
    {
        ret = is_rect_empty( &dc->vis_rect ) ? ERROR : SIMPLEREGION;
        *rect = dc->vis_rect;
    }
432

433 434
    if (get_dc_device_rect( dc, &visrect ) && !intersect_rect( rect, rect, &visrect )) ret = NULLREGION;

435 436 437 438 439 440
    if (dc->layout & LAYOUT_RTL)
    {
        int tmp = rect->left;
        rect->left = rect->right - 1;
        rect->right = tmp - 1;
    }
441
    DPtoLP( hdc, (LPPOINT)rect, 2 );
442
    release_dc_ptr( dc );
443
    TRACE("%p => %d %s\n", hdc, ret, wine_dbgstr_rect( rect ));
Alexandre Julliard's avatar
Alexandre Julliard committed
444
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
445 446
}

Alexandre Julliard's avatar
Alexandre Julliard committed
447

Alexandre Julliard's avatar
Alexandre Julliard committed
448
/***********************************************************************
449
 *           GetClipRgn  (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
450
 */
451
INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
Alexandre Julliard's avatar
Alexandre Julliard committed
452
{
453 454
    INT ret = -1;
    DC * dc;
455
    if ((dc = get_dc_ptr( hdc )))
456
    {
457
      if( dc->hClipRgn )
458
      {
459 460 461 462 463 464
          if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR )
          {
              ret = 1;
              if (dc->layout & LAYOUT_RTL)
                  mirror_region( hRgn, hRgn, dc->vis_rect.right - dc->vis_rect.left );
          }
Alexandre Julliard's avatar
Alexandre Julliard committed
465
      }
466
      else ret = 0;
467
      release_dc_ptr( dc );
468
    }
469
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
470
}
Alexandre Julliard's avatar
Alexandre Julliard committed
471

472 473 474 475 476 477 478

/***********************************************************************
 *           GetMetaRgn    (GDI32.@)
 */
INT WINAPI GetMetaRgn( HDC hdc, HRGN hRgn )
{
    INT ret = 0;
479
    DC * dc = get_dc_ptr( hdc );
480 481 482 483

    if (dc)
    {
        if (dc->hMetaRgn && CombineRgn( hRgn, dc->hMetaRgn, 0, RGN_COPY ) != ERROR)
484
        {
485
            ret = 1;
486 487 488
            if (dc->layout & LAYOUT_RTL)
                mirror_region( hRgn, hRgn, dc->vis_rect.right - dc->vis_rect.left );
        }
489
        release_dc_ptr( dc );
490 491 492 493 494
    }
    return ret;
}


495 496 497 498 499
/***********************************************************************
 * GetRandomRgn [GDI32.@]
 *
 * NOTES
 *     This function is documented in MSDN online for the case of
500
 *     iCode == SYSRGN (4).
501
 *
502 503 504 505
 *     For iCode == 1 it should return the clip region
 *                  2 "    "       "   the meta region
 *                  3 "    "       "   the intersection of the clip with
 *                                     the meta region (== 'Rao' region).
506 507 508
 *
 *     See http://www.codeproject.com/gdi/cliprgnguide.asp
 */
509
INT WINAPI GetRandomRgn(HDC hDC, HRGN hRgn, INT iCode)
510
{
511
    INT ret = 1;
512
    DC *dc = get_dc_ptr( hDC );
513 514 515

    if (!dc) return -1;

516
    switch (iCode)
517
    {
518
    case 1:
519 520
        if (dc->hClipRgn) CombineRgn( hRgn, dc->hClipRgn, 0, RGN_COPY );
        else ret = 0;
521 522
        break;
    case 2:
523 524
        if (dc->hMetaRgn) CombineRgn( hRgn, dc->hMetaRgn, 0, RGN_COPY );
        else ret = 0;
525 526
        break;
    case 3:
527
        if (dc->hClipRgn && dc->hMetaRgn) CombineRgn( hRgn, dc->hClipRgn, dc->hMetaRgn, RGN_AND );
528 529 530
        else if (dc->hClipRgn) CombineRgn( hRgn, dc->hClipRgn, 0, RGN_COPY );
        else if (dc->hMetaRgn) CombineRgn( hRgn, dc->hMetaRgn, 0, RGN_COPY );
        else ret = 0;
531
        break;
532
    case SYSRGN: /* == 4 */
533
        update_dc( dc );
534
        if (dc->hVisRgn)
535
        {
536
            CombineRgn( hRgn, dc->hVisRgn, 0, RGN_COPY );
537 538 539 540 541 542
            /* On Windows NT/2000, the SYSRGN returned is in screen coordinates */
            if (!(GetVersion() & 0x80000000)) OffsetRgn( hRgn, dc->vis_rect.left, dc->vis_rect.top );
        }
        else if (!is_rect_empty( &dc->device_rect ))
            SetRectRgn( hRgn, dc->device_rect.left, dc->device_rect.top,
                        dc->device_rect.right, dc->device_rect.bottom );
543 544
        else
            ret = 0;
545
        break;
546
    default:
547
        WARN("Unknown code %d\n", iCode);
548 549
        ret = -1;
        break;
550
    }
551
    release_dc_ptr( dc );
552
    return ret;
553 554 555 556
}


/***********************************************************************
557
 *           SetMetaRgn    (GDI32.@)
558
 */
559
INT WINAPI SetMetaRgn( HDC hdc )
560
{
561 562
    INT ret;
    RECT dummy;
563
    DC *dc = get_dc_ptr( hdc );
564

565
    if (!dc) return ERROR;
566

567
    if (dc->hClipRgn)
568
    {
569 570 571 572 573 574 575 576 577 578 579 580
        if (dc->hMetaRgn)
        {
            /* the intersection becomes the new meta region */
            CombineRgn( dc->hMetaRgn, dc->hMetaRgn, dc->hClipRgn, RGN_AND );
            DeleteObject( dc->hClipRgn );
            dc->hClipRgn = 0;
        }
        else
        {
            dc->hMetaRgn = dc->hClipRgn;
            dc->hClipRgn = 0;
        }
581 582
    }
    /* else nothing to do */
583

584
    /* Note: no need to call update_dc_clipping, the overall clip region hasn't changed */
585

586
    ret = GetRgnBox( dc->hMetaRgn, &dummy );
587
    release_dc_ptr( dc );
588
    return ret;
589
}