2 * DC clipping functions
4 * Copyright 1993 Alexandre Julliard
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
14 /***********************************************************************
15 * CLIPPING_SetDeviceClipping
17 * Set the clip region of the physical device.
19 void CLIPPING_SetDeviceClipping( DC * dc )
23 RGNOBJ *obj = (RGNOBJ *) GDI_GetObjPtr(dc->w.hGCClipRgn, REGION_MAGIC);
26 XSetRegion( display, dc->u.x.gc, obj->region.xrgn );
27 XSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
29 else if (obj->region.pixmap)
31 XSetClipMask( display, dc->u.x.gc, obj->region.pixmap );
32 XSetClipOrigin( display, dc->u.x.gc,
33 dc->w.DCOrgX + obj->region.box.left,
34 dc->w.DCOrgY + obj->region.box.top );
36 else /* Clip everything */
38 XSetClipRectangles( display, dc->u.x.gc, 0, 0, NULL, 0, 0 );
43 XSetClipMask( display, dc->u.x.gc, None );
44 XSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
49 /***********************************************************************
50 * CLIPPING_UpdateGCRegion
52 * Update the GC clip region when the ClipRgn or VisRgn have changed.
54 static void CLIPPING_UpdateGCRegion( DC * dc )
56 if (!dc->w.hGCClipRgn) dc->w.hGCClipRgn = CreateRectRgn(0,0,0,0);
62 DeleteObject( dc->w.hGCClipRgn );
66 CombineRgn( dc->w.hGCClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
71 CombineRgn( dc->w.hGCClipRgn, dc->w.hVisRgn, 0, RGN_COPY );
73 CombineRgn( dc->w.hGCClipRgn, dc->w.hClipRgn, dc->w.hVisRgn, RGN_AND );
75 CLIPPING_SetDeviceClipping( dc );
79 /***********************************************************************
82 * Helper function for SelectClipRgn() and SelectVisRgn().
84 static int CLIPPING_SelectRgn( DC * dc, HRGN * hrgnPrev, HRGN hrgn )
90 if (!*hrgnPrev) *hrgnPrev = CreateRectRgn(0,0,0,0);
91 retval = CombineRgn( *hrgnPrev, hrgn, 0, RGN_COPY );
95 if (*hrgnPrev) DeleteObject( *hrgnPrev );
97 retval = SIMPLEREGION; /* Clip region == client area */
99 CLIPPING_UpdateGCRegion( dc );
104 /***********************************************************************
105 * SelectClipRgn (GDI.44)
107 int SelectClipRgn( HDC hdc, HRGN hrgn )
109 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
110 if (!dc) return ERROR;
112 #ifdef DEBUG_CLIPPING
113 printf( "SelectClipRgn: %d %d\n", hdc, hrgn );
115 return CLIPPING_SelectRgn( dc, &dc->w.hClipRgn, hrgn );
119 /***********************************************************************
120 * SelectVisRgn (GDI.105)
122 int SelectVisRgn( HDC hdc, HRGN hrgn )
124 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
125 if (!dc) return ERROR;
127 #ifdef DEBUG_CLIPPING
128 printf( "SelectVisRgn: %d %d\n", hdc, hrgn );
130 return CLIPPING_SelectRgn( dc, &dc->w.hVisRgn, hrgn );
134 /***********************************************************************
135 * OffsetClipRgn (GDI.32)
137 int OffsetClipRgn( HDC hdc, short x, short y )
139 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
142 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
143 if (!dc) return ERROR;
144 MF_MetaParam2(dc, META_OFFSETCLIPRGN, x, y);
145 return NULLREGION; /* ?? */
148 #ifdef DEBUG_CLIPPING
149 printf( "OffsetClipRgn: %d %d,%d\n", hdc, x, y );
154 int retval = OffsetRgn( dc->w.hClipRgn, x, y );
155 CLIPPING_UpdateGCRegion( dc );
158 else return SIMPLEREGION; /* Clip region == client area */
162 /***********************************************************************
163 * OffsetVisRgn (GDI.102)
165 int OffsetVisRgn( HDC hdc, short x, short y )
167 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
168 if (!dc) return ERROR;
169 #ifdef DEBUG_CLIPPING
170 printf( "OffsetVisRgn: %d %d,%d\n", hdc, x, y );
175 int retval = OffsetRgn( dc->w.hVisRgn, x, y );
176 CLIPPING_UpdateGCRegion( dc );
179 else return SIMPLEREGION; /* Clip region == client area */
183 /***********************************************************************
184 * CLIPPING_IntersectRect
186 * Helper function for {Intersect,Exclude}{Clip,Vis}Rect
188 int CLIPPING_IntersectRect( DC * dc, HRGN * hrgn, short left, short top,
189 short right, short bottom, int exclude )
191 HRGN tempRgn = 0, prevRgn = 0, newRgn = 0;
192 RGNOBJ *newObj, *prevObj;
197 if (!(*hrgn = CreateRectRgn( 0, 0, dc->w.DCSizeX, dc->w.DCSizeY )))
201 if (!(newRgn = CreateRectRgn( 0, 0, 0, 0))) goto Error;
202 if (!(tempRgn = CreateRectRgn( left, top, right, bottom ))) goto Error;
204 retval = CombineRgn( newRgn, *hrgn, tempRgn, exclude ? RGN_DIFF : RGN_AND);
205 if (retval == ERROR) goto Error;
207 newObj = (RGNOBJ *) GDI_GetObjPtr( newRgn, REGION_MAGIC );
208 prevObj = (RGNOBJ *) GDI_GetObjPtr( *hrgn, REGION_MAGIC );
209 if (newObj && prevObj) newObj->header.hNext = prevObj->header.hNext;
210 DeleteObject( tempRgn );
211 if (*hrgn) DeleteObject( *hrgn );
213 CLIPPING_UpdateGCRegion( dc );
217 if (tempRgn) DeleteObject( tempRgn );
218 if (newRgn) DeleteObject( newRgn );
221 DeleteObject( prevRgn );
228 /***********************************************************************
229 * ExcludeClipRect (GDI.21)
231 int ExcludeClipRect( HDC hdc, short left, short top,
232 short right, short bottom )
234 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
237 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
238 if (!dc) return ERROR;
239 MF_MetaParam4(dc, META_EXCLUDECLIPRECT, left, top, right, bottom);
240 return NULLREGION; /* ?? */
243 #ifdef DEBUG_CLIPPING
244 printf( "ExcludeClipRect: %d %dx%d,%dx%d\n",
245 hdc, left, top, right, bottom );
247 return CLIPPING_IntersectRect( dc, &dc->w.hClipRgn, left, top,
252 /***********************************************************************
253 * IntersectClipRect (GDI.22)
255 int IntersectClipRect( HDC hdc, short left, short top,
256 short right, short bottom )
258 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
261 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
262 if (!dc) return ERROR;
263 MF_MetaParam4(dc, META_INTERSECTCLIPRECT, left, top, right, bottom);
264 return NULLREGION; /* ?? */
267 #ifdef DEBUG_CLIPPING
268 printf( "IntersectClipRect: %d %dx%d,%dx%d\n",
269 hdc, left, top, right, bottom );
271 return CLIPPING_IntersectRect( dc, &dc->w.hClipRgn, left, top,
276 /***********************************************************************
277 * ExcludeVisRect (GDI.73)
279 int ExcludeVisRect( HDC hdc, short left, short top,
280 short right, short bottom )
282 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
283 if (!dc) return ERROR;
284 #ifdef DEBUG_CLIPPING
285 printf( "ExcludeVisRect: %d %dx%d,%dx%d\n",
286 hdc, left, top, right, bottom );
288 return CLIPPING_IntersectRect( dc, &dc->w.hVisRgn, left, top,
293 /***********************************************************************
294 * IntersectVisRect (GDI.98)
296 int IntersectVisRect( HDC hdc, short left, short top,
297 short right, short bottom )
299 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
300 if (!dc) return ERROR;
301 #ifdef DEBUG_CLIPPING
302 printf( "IntersectVisRect: %d %dx%d,%dx%d\n",
303 hdc, left, top, right, bottom );
305 return CLIPPING_IntersectRect( dc, &dc->w.hVisRgn, left, top,
310 /***********************************************************************
311 * PtVisible (GDI.103)
313 BOOL PtVisible( HDC hdc, short x, short y )
315 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
316 if (!dc) return ERROR;
317 #ifdef DEBUG_CLIPPING
318 printf( "PtVisible: %d %d,%d\n", hdc, x, y );
320 if (!dc->w.hClipRgn) return FALSE;
321 return PtInRegion( dc->w.hClipRgn, x, y );
325 /***********************************************************************
326 * RectVisible (GDI.104)
328 BOOL RectVisible( HDC hdc, LPRECT rect )
330 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
331 if (!dc) return ERROR;
332 #ifdef DEBUG_CLIPPING
333 printf( "RectVisible: %d %p\n", hdc, rect );
335 if (!dc->w.hClipRgn) return FALSE;
336 return RectInRegion( dc->w.hClipRgn, rect );
340 /***********************************************************************
341 * GetClipBox (GDI.77)
343 int GetClipBox( HDC hdc, LPRECT rect )
345 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
346 if (!dc) return ERROR;
347 #ifdef DEBUG_CLIPPING
348 printf( "GetClipBox: %d %p\n", hdc, rect );
351 if (dc->w.hGCClipRgn) return GetRgnBox( dc->w.hGCClipRgn, rect );
354 rect->top = rect->left = 0;
355 rect->right = dc->w.DCSizeX;
356 rect->bottom = dc->w.DCSizeY;
362 /***********************************************************************
363 * SaveVisRgn (GDI.129)
365 HRGN SaveVisRgn( HDC hdc )
368 RGNOBJ *obj, *copyObj;
369 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
371 #ifdef DEBUG_CLIPPING
372 printf( "SaveVisRgn: %d\n", hdc );
374 if (!dc->w.hVisRgn) return 0;
375 if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
377 if (!(copy = CreateRectRgn( 0, 0, 0, 0 ))) return 0;
378 CombineRgn( copy, dc->w.hVisRgn, 0, RGN_COPY );
379 if (!(copyObj = (RGNOBJ *) GDI_GetObjPtr( copy, REGION_MAGIC )))
381 copyObj->header.hNext = obj->header.hNext;
382 obj->header.hNext = copy;
387 /***********************************************************************
388 * RestoreVisRgn (GDI.130)
390 int RestoreVisRgn( HDC hdc )
393 RGNOBJ *obj, *savedObj;
394 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
395 if (!dc) return ERROR;
396 #ifdef DEBUG_CLIPPING
397 printf( "RestoreVisRgn: %d\n", hdc );
399 if (!dc->w.hVisRgn) return ERROR;
400 if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
402 if (!(saved = obj->header.hNext)) return ERROR;
403 if (!(savedObj = (RGNOBJ *) GDI_GetObjPtr( saved, REGION_MAGIC )))
405 DeleteObject( dc->w.hVisRgn );
406 dc->w.hVisRgn = saved;
407 CLIPPING_UpdateGCRegion( dc );
408 return savedObj->region.type;