clipping.c 14.6 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 18
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

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

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


Alexandre Julliard's avatar
Alexandre Julliard committed
31 32 33
/***********************************************************************
 *           CLIPPING_UpdateGCRegion
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
34
 * Update the GC clip region when the ClipRgn or VisRgn have changed.
Alexandre Julliard's avatar
Alexandre Julliard committed
35
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
36
void CLIPPING_UpdateGCRegion( DC * dc )
Alexandre Julliard's avatar
Alexandre Julliard committed
37
{
38
    if (!dc->hGCClipRgn) dc->hGCClipRgn = CreateRectRgn( 0, 0, 0, 0 );
Alexandre Julliard's avatar
Alexandre Julliard committed
39

40
    if (!dc->hVisRgn)
Alexandre Julliard's avatar
Alexandre Julliard committed
41
    {
42
        ERR("hVisRgn is zero. Please report this.\n" );
Alexandre Julliard's avatar
Alexandre Julliard committed
43
        exit(1);
Alexandre Julliard's avatar
Alexandre Julliard committed
44
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
45

46
    if (dc->flags & DC_DIRTY) ERR( "DC is dirty. Please report this.\n" );
Alexandre Julliard's avatar
Alexandre Julliard committed
47

48 49
    if (!dc->hClipRgn)
        CombineRgn( dc->hGCClipRgn, dc->hVisRgn, 0, RGN_COPY );
Alexandre Julliard's avatar
Alexandre Julliard committed
50
    else
51
        CombineRgn(dc->hGCClipRgn, dc->hClipRgn, dc->hVisRgn, RGN_AND);
52 53
    if (dc->funcs->pSetDeviceClipping)
        dc->funcs->pSetDeviceClipping( dc->physDev, dc->hGCClipRgn );
Alexandre Julliard's avatar
Alexandre Julliard committed
54 55 56 57
}


/***********************************************************************
58
 *           SelectClipRgn    (GDI.44)
Alexandre Julliard's avatar
Alexandre Julliard committed
59
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
60
INT16 WINAPI SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
Alexandre Julliard's avatar
Alexandre Julliard committed
61
{
62
    return (INT16)SelectClipRgn( hdc, hrgn );
Alexandre Julliard's avatar
Alexandre Julliard committed
63 64 65 66
}


/***********************************************************************
67
 *           SelectClipRgn    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
68
 */
69
INT WINAPI SelectClipRgn( HDC hdc, HRGN hrgn )
70 71 72 73
{
    return ExtSelectClipRgn( hdc, hrgn, RGN_COPY );
}

74
/******************************************************************************
75
 *		ExtSelectClipRgn	[GDI.508]
76 77 78 79 80 81
 */
INT16 WINAPI ExtSelectClipRgn16( HDC16 hdc, HRGN16 hrgn, INT16 fnMode )
{
  return (INT16) ExtSelectClipRgn((HDC) hdc, (HRGN) hrgn, fnMode);
}

82
/******************************************************************************
83
 *		ExtSelectClipRgn	[GDI32.@]
84
 */
85
INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode )
Alexandre Julliard's avatar
Alexandre Julliard committed
86
{
87
    INT retval;
88
    DC * dc = DC_GetDCUpdate( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
89 90
    if (!dc) return ERROR;

91
    TRACE("%04x %04x %d\n", hdc, hrgn, fnMode );
Alexandre Julliard's avatar
Alexandre Julliard committed
92

93 94 95 96 97 98 99
    if (dc->funcs->pExtSelectClipRgn)
    {
        retval = dc->funcs->pExtSelectClipRgn( dc->physDev, hrgn, fnMode );
        GDI_ReleaseObj( hdc );
        return retval;
    }

100
    if (!hrgn)
Alexandre Julliard's avatar
Alexandre Julliard committed
101
    {
102 103
        if (fnMode == RGN_COPY)
        {
104
            if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
105
            dc->hClipRgn = 0;
106 107 108 109
            retval = SIMPLEREGION; /* Clip region == whole DC */
        }
        else
        {
110
            FIXME("Unimplemented: hrgn NULL in mode: %d\n", fnMode);
111
            GDI_ReleaseObj( hdc );
112 113
            return ERROR;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
114
    }
115
    else
Alexandre Julliard's avatar
Alexandre Julliard committed
116
    {
117
        if (!dc->hClipRgn)
118
        {
119
            RECT rect;
120 121
            GetRgnBox( dc->hVisRgn, &rect );
            dc->hClipRgn = CreateRectRgnIndirect( &rect );
122 123
        }

124
        if(fnMode == RGN_COPY)
125
            retval = CombineRgn( dc->hClipRgn, hrgn, 0, fnMode );
126
        else
127
            retval = CombineRgn( dc->hClipRgn, dc->hClipRgn, hrgn, fnMode);
Alexandre Julliard's avatar
Alexandre Julliard committed
128
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
129

Alexandre Julliard's avatar
Alexandre Julliard committed
130
    CLIPPING_UpdateGCRegion( dc );
131
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
132 133 134 135 136 137
    return retval;
}

/***********************************************************************
 *           SelectVisRgn    (GDI.105)
 */
138
INT16 WINAPI SelectVisRgn16( HDC16 hdc, HRGN16 hrgn )
Alexandre Julliard's avatar
Alexandre Julliard committed
139
{
Alexandre Julliard's avatar
Alexandre Julliard committed
140
    int retval;
141 142 143 144
    DC * dc;

    if (!hrgn) return ERROR;
    if (!(dc = DC_GetDCPtr( hdc ))) return ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
145

146
    TRACE("%04x %04x\n", hdc, hrgn );
Alexandre Julliard's avatar
Alexandre Julliard committed
147

148
    dc->flags &= ~DC_DIRTY;
Alexandre Julliard's avatar
Alexandre Julliard committed
149

150
    retval = CombineRgn16( dc->hVisRgn, hrgn, 0, RGN_COPY );
Alexandre Julliard's avatar
Alexandre Julliard committed
151
    CLIPPING_UpdateGCRegion( dc );
152
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
153
    return retval;
Alexandre Julliard's avatar
Alexandre Julliard committed
154 155 156 157
}


/***********************************************************************
158
 *           OffsetClipRgn    (GDI.32)
Alexandre Julliard's avatar
Alexandre Julliard committed
159
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
160
INT16 WINAPI OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
Alexandre Julliard's avatar
Alexandre Julliard committed
161
{
162
    return (INT16)OffsetClipRgn( hdc, x, y );
Alexandre Julliard's avatar
Alexandre Julliard committed
163 164 165 166
}


/***********************************************************************
167
 *           OffsetClipRgn    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
168
 */
169
INT WINAPI OffsetClipRgn( HDC hdc, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
170
{
171
    INT ret = SIMPLEREGION;
172
    DC *dc = DC_GetDCUpdate( hdc );
173
    if (!dc) return ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
174

175
    TRACE("%04x %d,%d\n", hdc, x, y );
Alexandre Julliard's avatar
Alexandre Julliard committed
176

177
    if(dc->funcs->pOffsetClipRgn)
178
        ret = dc->funcs->pOffsetClipRgn( dc->physDev, x, y );
179 180
    else if (dc->hClipRgn) {
        ret = OffsetRgn( dc->hClipRgn, XLSTODS(dc,x), YLSTODS(dc,y));
Alexandre Julliard's avatar
Alexandre Julliard committed
181 182
	CLIPPING_UpdateGCRegion( dc );
    }
183
    GDI_ReleaseObj( hdc );
184
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
185 186 187 188 189 190
}


/***********************************************************************
 *           OffsetVisRgn    (GDI.102)
 */
191
INT16 WINAPI OffsetVisRgn16( HDC16 hdc, INT16 x, INT16 y )
Alexandre Julliard's avatar
Alexandre Julliard committed
192
{
Alexandre Julliard's avatar
Alexandre Julliard committed
193
    INT16 retval;
194
    DC * dc = DC_GetDCUpdate( hdc );
195
    if (!dc) return ERROR;
196
    TRACE("%04x %d,%d\n", hdc, x, y );
197
    retval = OffsetRgn( dc->hVisRgn, x, y );
Alexandre Julliard's avatar
Alexandre Julliard committed
198
    CLIPPING_UpdateGCRegion( dc );
199
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
200
    return retval;
Alexandre Julliard's avatar
Alexandre Julliard committed
201 202 203 204
}


/***********************************************************************
205
 *           ExcludeClipRect    (GDI.21)
Alexandre Julliard's avatar
Alexandre Julliard committed
206
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
207 208
INT16 WINAPI ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
                                INT16 right, INT16 bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
209
{
210
    return (INT16)ExcludeClipRect( hdc, left, top, right, bottom );
Alexandre Julliard's avatar
Alexandre Julliard committed
211 212 213 214
}


/***********************************************************************
215
 *           ExcludeClipRect    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
216
 */
217 218
INT WINAPI ExcludeClipRect( HDC hdc, INT left, INT top,
                                INT right, INT bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
219
{
220
    HRGN newRgn;
221
    INT ret;
222
    DC *dc = DC_GetDCUpdate( hdc );
223
    if (!dc) return ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
224

225
    TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
226 227

    if(dc->funcs->pExcludeClipRect)
228
        ret = dc->funcs->pExcludeClipRect( dc->physDev, left, top, right, bottom );
229 230
    else
    {
231 232 233 234
        left   = XLPTODP( dc, left );
        right  = XLPTODP( dc, right );
        top    = YLPTODP( dc, top );
        bottom = YLPTODP( dc, bottom );
235

236 237 238 239 240 241 242 243 244 245 246 247
        if (!(newRgn = CreateRectRgn( left, top, right, bottom ))) ret = ERROR;
        else
        {
            if (!dc->hClipRgn)
            {
                dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
                CombineRgn( dc->hClipRgn, dc->hVisRgn, 0, RGN_COPY );
            }
            ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_DIFF );
            DeleteObject( newRgn );
        }
        if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
248
    }
249
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
250
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
251 252 253 254
}


/***********************************************************************
255
 *           IntersectClipRect    (GDI.22)
Alexandre Julliard's avatar
Alexandre Julliard committed
256
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
257 258
INT16 WINAPI IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
                                  INT16 right, INT16 bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
259
{
260
    return (INT16)IntersectClipRect( hdc, left, top, right, bottom );
Alexandre Julliard's avatar
Alexandre Julliard committed
261 262 263 264
}


/***********************************************************************
265
 *           IntersectClipRect    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
266
 */
267 268
INT WINAPI IntersectClipRect( HDC hdc, INT left, INT top,
                                  INT right, INT bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
269
{
270
    INT ret;
271
    DC *dc = DC_GetDCUpdate( hdc );
272
    if (!dc) return ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
273

274
    TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
275 276

    if(dc->funcs->pIntersectClipRect)
277
        ret = dc->funcs->pIntersectClipRect( dc->physDev, left, top, right, bottom );
278
    else
Alexandre Julliard's avatar
Alexandre Julliard committed
279
    {
280 281 282 283
        left   = XLPTODP( dc, left );
        right  = XLPTODP( dc, right );
        top    = YLPTODP( dc, top );
        bottom = YLPTODP( dc, bottom );
Alexandre Julliard's avatar
Alexandre Julliard committed
284

285
        if (!dc->hClipRgn)
286
        {
287 288 289 290 291 292 293 294 295
            dc->hClipRgn = CreateRectRgn( left, top, right, bottom );
            ret = SIMPLEREGION;
        }
        else
        {
            HRGN newRgn;

            if (!(newRgn = CreateRectRgn( left, top, right, bottom ))) ret = ERROR;
            else
296
            {
297 298
                ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_AND );
                DeleteObject( newRgn );
299 300
            }
        }
301
        if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
302
    }
303
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
304
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
305 306 307 308 309 310
}


/***********************************************************************
 *           ExcludeVisRect    (GDI.73)
 */
311
INT16 WINAPI ExcludeVisRect16( HDC16 hdc, INT16 left, INT16 top,
Alexandre Julliard's avatar
Alexandre Julliard committed
312
                             INT16 right, INT16 bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
313
{
314
    HRGN tempRgn;
315 316
    INT16 ret;
    DC * dc = DC_GetDCUpdate( hdc );
317
    if (!dc) return ERROR;
318

319 320 321 322
    left   = XLPTODP( dc, left );
    right  = XLPTODP( dc, right );
    top    = YLPTODP( dc, top );
    bottom = YLPTODP( dc, bottom );
323

324
    TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
Alexandre Julliard's avatar
Alexandre Julliard committed
325

326 327 328 329 330 331 332
    if (!(tempRgn = CreateRectRgn( left, top, right, bottom ))) ret = ERROR;
    else
    {
        ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
        DeleteObject( tempRgn );
    }
    if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
333 334
    GDI_ReleaseObj( hdc );
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
335 336 337 338 339 340
}


/***********************************************************************
 *           IntersectVisRect    (GDI.98)
 */
341
INT16 WINAPI IntersectVisRect16( HDC16 hdc, INT16 left, INT16 top,
Alexandre Julliard's avatar
Alexandre Julliard committed
342
                               INT16 right, INT16 bottom )
Alexandre Julliard's avatar
Alexandre Julliard committed
343
{
344
    HRGN tempRgn;
345
    INT16 ret;
346
    DC * dc = DC_GetDCUpdate( hdc );
347
    if (!dc) return ERROR;
348

349 350 351 352
    left   = XLPTODP( dc, left );
    right  = XLPTODP( dc, right );
    top    = YLPTODP( dc, top );
    bottom = YLPTODP( dc, bottom );
353

354
    TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
Alexandre Julliard's avatar
Alexandre Julliard committed
355

356 357 358 359 360 361 362
    if (!(tempRgn = CreateRectRgn( left, top, right, bottom ))) ret = ERROR;
    else
    {
        ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
        DeleteObject( tempRgn );
    }
    if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
363 364
    GDI_ReleaseObj( hdc );
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
365 366 367 368
}


/***********************************************************************
369
 *           PtVisible    (GDI.103)
Alexandre Julliard's avatar
Alexandre Julliard committed
370
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
371
BOOL16 WINAPI PtVisible16( HDC16 hdc, INT16 x, INT16 y )
Alexandre Julliard's avatar
Alexandre Julliard committed
372
{
373
    return PtVisible( hdc, x, y );
Alexandre Julliard's avatar
Alexandre Julliard committed
374 375 376 377
}


/***********************************************************************
378
 *           PtVisible    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
379
 */
380
BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
381
{
382 383
    BOOL ret = FALSE;
    DC *dc = DC_GetDCUpdate( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
384

385
    TRACE("%04x %d,%d\n", hdc, x, y );
386
    if (!dc) return FALSE;
387
    if (dc->hGCClipRgn)
388
    {
389
        ret = PtInRegion( dc->hGCClipRgn, XLPTODP(dc,x), YLPTODP(dc,y) );
390
    }
391 392 393
    GDI_ReleaseObj( hdc );
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
394 395 396


/***********************************************************************
397
 *           RectVisible    (GDI.465)
Patrik Stridvall's avatar
Patrik Stridvall committed
398
 *           RectVisibleOld (GDI.104)
Alexandre Julliard's avatar
Alexandre Julliard committed
399
 */
400 401 402 403 404 405 406 407 408 409 410 411
BOOL16 WINAPI RectVisible16( HDC16 hdc, const RECT16* rect16 )
{
    RECT rect;
    CONV_RECT16TO32( rect16, &rect );
    return RectVisible( hdc, &rect );
}


/***********************************************************************
 *           RectVisible    (GDI32.@)
 */
BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
Alexandre Julliard's avatar
Alexandre Julliard committed
412
{
413
    BOOL ret = FALSE;
414
    RECT tmpRect;
415
    DC *dc = DC_GetDCUpdate( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
416
    if (!dc) return FALSE;
417 418
    TRACE("%04x %d,%dx%d,%d\n",
          hdc, rect->left, rect->top, rect->right, rect->bottom );
419
    if (dc->hGCClipRgn)
420 421 422
    {
        /* copy rectangle to avoid overwriting by LPtoDP */
        tmpRect = *rect;
423 424
        LPtoDP( hdc, (LPPOINT)&tmpRect, 2 );
        ret = RectInRegion( dc->hGCClipRgn, &tmpRect );
425 426 427
    }
    GDI_ReleaseObj( hdc );
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
428 429 430
}


Alexandre Julliard's avatar
Alexandre Julliard committed
431
/***********************************************************************
432
 *           GetClipBox    (GDI.77)
Alexandre Julliard's avatar
Alexandre Julliard committed
433
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
434
INT16 WINAPI GetClipBox16( HDC16 hdc, LPRECT16 rect )
Alexandre Julliard's avatar
Alexandre Julliard committed
435
{
Alexandre Julliard's avatar
Alexandre Julliard committed
436
    int ret;
437 438
    DC *dc = DC_GetDCUpdate( hdc );
    if (!dc) return ERROR;
439
    ret = GetRgnBox16( dc->hGCClipRgn, rect );
Alexandre Julliard's avatar
Alexandre Julliard committed
440
    DPtoLP16( hdc, (LPPOINT16)rect, 2 );
441
    TRACE("%d,%d-%d,%d\n", rect->left,rect->top,rect->right,rect->bottom );
442
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
443 444 445 446 447
    return ret;
}


/***********************************************************************
448
 *           GetClipBox    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
449
 */
450
INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
Alexandre Julliard's avatar
Alexandre Julliard committed
451
{
452
    INT ret;
453 454
    DC *dc = DC_GetDCUpdate( hdc );
    if (!dc) return ERROR;
455
    ret = GetRgnBox( dc->hGCClipRgn, rect );
456
    DPtoLP( hdc, (LPPOINT)rect, 2 );
457
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
458
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
459 460
}

Alexandre Julliard's avatar
Alexandre Julliard committed
461

Alexandre Julliard's avatar
Alexandre Julliard committed
462
/***********************************************************************
463
 *           GetClipRgn  (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
464
 */
465
INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
Alexandre Julliard's avatar
Alexandre Julliard committed
466
{
467 468
    INT ret = -1;
    DC * dc;
469
    if (hRgn && (dc = DC_GetDCPtr( hdc )))
470
    {
471
      if( dc->hClipRgn )
472
      {
473
          if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR ) ret = 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
474
      }
475 476
      else ret = 0;
      GDI_ReleaseObj( hdc );
477
    }
478
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
479
}
Alexandre Julliard's avatar
Alexandre Julliard committed
480 481 482 483

/***********************************************************************
 *           SaveVisRgn    (GDI.129)
 */
484
HRGN16 WINAPI SaveVisRgn16( HDC16 hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
485
{
486
    HRGN copy;
487
    GDIOBJHDR *obj, *copyObj;
488 489
    DC *dc = DC_GetDCUpdate( hdc );

Alexandre Julliard's avatar
Alexandre Julliard committed
490
    if (!dc) return 0;
491
    TRACE("%04x\n", hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
492

493
    if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC )))
Alexandre Julliard's avatar
Alexandre Julliard committed
494
    {
495
        GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
496
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
497
    }
498
    if (!(copy = CreateRectRgn( 0, 0, 0, 0 )))
Alexandre Julliard's avatar
Alexandre Julliard committed
499
    {
500
        GDI_ReleaseObj( dc->hVisRgn );
501
        GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
502
        return 0;
503
    }
504
    CombineRgn( copy, dc->hVisRgn, 0, RGN_COPY );
505
    if (!(copyObj = GDI_GetObjPtr( copy, REGION_MAGIC )))
Alexandre Julliard's avatar
Alexandre Julliard committed
506
    {
507
        DeleteObject( copy );
508
        GDI_ReleaseObj( dc->hVisRgn );
509
        GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
510
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
511
    }
512 513
    copyObj->hNext = obj->hNext;
    obj->hNext = copy;
514
    GDI_ReleaseObj( copy );
515
    GDI_ReleaseObj( dc->hVisRgn );
516
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
517 518 519 520 521 522 523
    return copy;
}


/***********************************************************************
 *           RestoreVisRgn    (GDI.130)
 */
524
INT16 WINAPI RestoreVisRgn16( HDC16 hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
525
{
526
    HRGN saved;
527
    GDIOBJHDR *obj, *savedObj;
528
    DC *dc = DC_GetDCPtr( hdc );
529
    INT16 ret = ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
530

531 532
    if (!dc) return ERROR;

533
    TRACE("%04x\n", hdc );
534

535 536
    if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC ))) goto done;
    saved = obj->hNext;
537

538 539 540 541 542 543 544 545 546 547
    if ((savedObj = GDI_GetObjPtr( saved, REGION_MAGIC )))
    {
        ret = CombineRgn( dc->hVisRgn, saved, 0, RGN_COPY );
        obj->hNext = savedObj->hNext;
        GDI_ReleaseObj( saved );
        DeleteObject( saved );
        dc->flags &= ~DC_DIRTY;
        CLIPPING_UpdateGCRegion( dc );
    }
    GDI_ReleaseObj( dc->hVisRgn );
548 549
 done:
    GDI_ReleaseObj( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
550
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
551
}