4 * Copyright 1993 Alexandre Julliard
5 * 1996,1997 Alex Korobka
8 * Note: Visible regions of CS_OWNDC/CS_CLASSDC window DCs
9 * have to be updated dynamically.
13 * DCX_DCEEMPTY - dce is uninitialized
14 * DCX_DCEBUSY - dce is in use
15 * DCX_DCEDIRTY - ReleaseDC() should wipe instead of caching
16 * DCX_KEEPCLIPRGN - ReleaseDC() should not delete the clipping region
17 * DCX_WINDOWPAINT - BeginPaint() is in effect
29 #include "sysmetrics.h"
32 #include "wine/winuser16.h"
34 #define NB_DCE 5 /* Number of DCEs created at startup */
36 static DCE
*firstDCE
= 0;
37 static HDC defaultDCstate
= 0;
39 static void DCE_DeleteClipRgn( DCE
* );
40 static INT
DCE_ReleaseDC( DCE
* );
43 /***********************************************************************
46 static void DCE_DumpCache(void)
53 DUMP("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
54 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
,
55 (dce
->DCXflags
& DCX_CACHE
) ? "Cache" : "Owned",
56 (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
61 /***********************************************************************
66 DCE
*DCE_AllocDCE( HWND hWnd
, DCE_TYPE type
)
69 if (!(dce
= HeapAlloc( SystemHeap
, 0, sizeof(DCE
) ))) return NULL
;
70 if (!(dce
->hDC
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
)))
72 HeapFree( SystemHeap
, 0, dce
);
76 /* store DCE handle in DC hook data field */
78 SetDCHook( dce
->hDC
, (FARPROC16
)DCHook16
, (DWORD
)dce
);
80 dce
->hwndCurrent
= hWnd
;
85 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
87 dce
->DCXflags
= DCX_DCEBUSY
;
90 WND
* wnd
= WIN_FindWndPtr(hWnd
);
92 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
93 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
95 SetHookFlags16(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
97 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
103 /***********************************************************************
106 DCE
* DCE_FreeDCE( DCE
*dce
)
108 DCE
**ppDCE
= &firstDCE
;
110 if (!dce
) return NULL
;
111 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
112 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
114 SetDCHook(dce
->hDC
, NULL
, 0L);
116 DeleteDC( dce
->hDC
);
117 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
118 DeleteObject(dce
->hClipRgn
);
119 HeapFree( SystemHeap
, 0, dce
);
123 /***********************************************************************
126 * Remove owned DCE and reset unreleased cache DCEs.
128 void DCE_FreeWindowDCE( WND
* pWnd
)
130 DCE
*pDCE
= firstDCE
;
134 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
136 if( pDCE
== pWnd
->dce
) /* owned DCE */
138 pDCE
= DCE_FreeDCE( pDCE
);
144 if(!(pDCE
->DCXflags
& DCX_CACHE
) ) /* class DCE */
146 if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) )
147 DCE_DeleteClipRgn( pDCE
);
149 else if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
151 ERR(dc
,"[%04x] GetDC() without ReleaseDC()!\n",
153 DCE_ReleaseDC( pDCE
);
156 pDCE
->DCXflags
&= DCX_CACHE
;
157 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
158 pDCE
->hwndCurrent
= 0;
166 /***********************************************************************
169 static void DCE_DeleteClipRgn( DCE
* dce
)
171 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
173 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
174 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
176 if( dce
->hClipRgn
> 1 )
177 DeleteObject( dce
->hClipRgn
);
181 TRACE(dc
,"\trestoring VisRgn\n");
183 RestoreVisRgn16(dce
->hDC
);
187 /***********************************************************************
190 static INT
DCE_ReleaseDC( DCE
* dce
)
192 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
194 /* restore previous visible region */
196 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
197 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
198 DCE_DeleteClipRgn( dce
);
200 if (dce
->DCXflags
& DCX_CACHE
)
202 SetDCState16( dce
->hDC
, defaultDCstate
);
203 dce
->DCXflags
&= ~DCX_DCEBUSY
;
204 if (dce
->DCXflags
& DCX_DCEDIRTY
)
206 /* don't keep around invalidated entries
207 * because SetDCState() disables hVisRgn updates
208 * by removing dirty bit. */
210 dce
->hwndCurrent
= 0;
211 dce
->DCXflags
&= DCX_CACHE
;
212 dce
->DCXflags
|= DCX_DCEEMPTY
;
219 /***********************************************************************
222 * It is called from SetWindowPos() - we have to mark as dirty all busy
223 * DCE's for windows that have pWnd->parent as an ansector and whose client
224 * rect intersects with specified update rectangle.
226 BOOL
DCE_InvalidateDCE(WND
* pWnd
, const RECT
* pRectUpdate
)
228 WND
* wndScope
= pWnd
->parent
;
235 TRACE(dc
,"scope hwnd = %04x, (%i,%i - %i,%i)\n",
236 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
237 pRectUpdate
->right
,pRectUpdate
->bottom
);
241 /* walk all DCEs and fixup non-empty entries */
243 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
245 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
247 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
249 if( wndCurrent
&& wndCurrent
!= WIN_GetDesktop() )
251 WND
* wnd
= wndCurrent
;
252 INT xoffset
= 0, yoffset
= 0;
254 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) ) continue;
256 /* check if DCE window is within the z-order scope */
258 for( wnd
= wndCurrent
; wnd
; wnd
= wnd
->parent
)
260 if( wnd
== wndScope
)
264 wndRect
= wndCurrent
->rectWindow
;
266 OffsetRect( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
267 yoffset
- wndCurrent
->rectClient
.top
);
269 if (pWnd
== wndCurrent
||
270 IntersectRect( &wndRect
, &wndRect
, pRectUpdate
))
272 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
274 /* Don't bother with visible regions of unused DCEs */
276 TRACE(dc
,"\tpurged %08x dce [%04x]\n",
277 (unsigned)dce
, wndCurrent
->hwndSelf
);
279 dce
->hwndCurrent
= 0;
280 dce
->DCXflags
&= DCX_CACHE
;
281 dce
->DCXflags
|= DCX_DCEEMPTY
;
285 /* Set dirty bits in the hDC and DCE structs */
287 TRACE(dc
,"\tfixed up %08x dce [%04x]\n",
288 (unsigned)dce
, wndCurrent
->hwndSelf
);
290 dce
->DCXflags
|= DCX_DCEDIRTY
;
291 SetHookFlags16(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
297 xoffset
+= wnd
->rectClient
.left
;
298 yoffset
+= wnd
->rectClient
.top
;
307 /***********************************************************************
315 for (i
= 0; i
< NB_DCE
; i
++)
317 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
318 if (!defaultDCstate
) defaultDCstate
= GetDCState16( dce
->hDC
);
323 /***********************************************************************
326 * Calculate the visible rectangle of a window (i.e. the client or
327 * window area clipped by the client area of all ancestors) in the
328 * corresponding coordinates. Return FALSE if the visible region is empty.
330 static BOOL
DCE_GetVisRect( WND
*wndPtr
, BOOL clientArea
, RECT
*lprect
)
332 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
334 if (wndPtr
->dwStyle
& WS_VISIBLE
)
336 INT xoffset
= lprect
->left
;
337 INT yoffset
= lprect
->top
;
339 while (wndPtr
->dwStyle
& WS_CHILD
)
341 wndPtr
= wndPtr
->parent
;
343 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
346 xoffset
+= wndPtr
->rectClient
.left
;
347 yoffset
+= wndPtr
->rectClient
.top
;
348 OffsetRect( lprect
, wndPtr
->rectClient
.left
,
349 wndPtr
->rectClient
.top
);
351 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
352 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
353 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
354 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
355 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
356 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
359 lprect
->left
= MAX( lprect
->left
, wndPtr
->rectClient
.left
);
360 lprect
->right
= MIN( lprect
->right
, wndPtr
->rectClient
.right
);
361 lprect
->top
= MAX( lprect
->top
, wndPtr
->rectClient
.top
);
362 lprect
->bottom
= MIN( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
364 OffsetRect( lprect
, -xoffset
, -yoffset
);
369 SetRectEmpty( lprect
);
374 /***********************************************************************
377 * Go through the linked list of windows from pWndStart to pWndEnd,
378 * adding to the clip region the intersection of the target rectangle
379 * with an offset window rectangle.
381 static BOOL
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
382 HRGN hrgnClip
, LPRECT lpRect
, int x
, int y
)
386 if( pWndStart
->pDriver
->pIsSelfClipping( pWndStart
) )
387 return TRUE
; /* The driver itself will do the clipping */
389 for (; pWndStart
!= pWndEnd
; pWndStart
= pWndStart
->next
)
391 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
393 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
394 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
395 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
396 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
398 if( IntersectRect( &rect
, &rect
, lpRect
))
399 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
))
402 return (pWndStart
== pWndEnd
);
406 /***********************************************************************
409 * Return the visible region of a window, i.e. the client or window area
410 * clipped by the client area of all ancestors, and then optionally
411 * by siblings and children.
413 HRGN
DCE_GetVisRgn( HWND hwnd
, WORD flags
, HWND hwndChild
, WORD cflags
)
417 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
418 WND
*childWnd
= WIN_FindWndPtr( hwndChild
);
420 /* Get visible rectangle and create a region with it. */
422 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
424 if((hrgnVis
= CreateRectRgnIndirect( &rect
)))
426 HRGN hrgnClip
= CreateRectRgn( 0, 0, 0, 0 );
427 INT xoffset
, yoffset
;
431 /* Compute obscured region for the visible rectangle by
432 * clipping children, siblings, and ancestors. Note that
433 * DCE_GetVisRect() returns a rectangle either in client
434 * or in window coordinates (for DCX_WINDOW request). */
436 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
438 if( flags
& DCX_WINDOW
)
440 /* adjust offsets since child window rectangles are
441 * in client coordinates */
443 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
444 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
447 xoffset
= yoffset
= 0;
449 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
450 &rect
, xoffset
, yoffset
);
453 /* We may need to clip children of child window, if a window with PARENTDC
454 * class style and CLIPCHILDREN window style (like in Free Agent 16
455 * preference dialogs) gets here, we take the region for the parent window
456 * but apparently still need to clip the children of the child window... */
458 if( (cflags
& DCX_CLIPCHILDREN
) && childWnd
&& childWnd
->child
)
460 if( flags
& DCX_WINDOW
)
462 /* adjust offsets since child window rectangles are
463 * in client coordinates */
465 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
466 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
469 xoffset
= yoffset
= 0;
471 /* client coordinates of child window */
472 xoffset
+= childWnd
->rectClient
.left
;
473 yoffset
+= childWnd
->rectClient
.top
;
475 DCE_AddClipRects( childWnd
->child
, NULL
, hrgnClip
,
476 &rect
, xoffset
, yoffset
);
479 /* sibling window rectangles are in client
480 * coordinates of the parent window */
482 if (flags
& DCX_WINDOW
)
484 xoffset
= -wndPtr
->rectWindow
.left
;
485 yoffset
= -wndPtr
->rectWindow
.top
;
489 xoffset
= -wndPtr
->rectClient
.left
;
490 yoffset
= -wndPtr
->rectClient
.top
;
493 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
494 DCE_AddClipRects( wndPtr
->parent
->child
,
495 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
497 /* Clip siblings of all ancestors that have the
498 * WS_CLIPSIBLINGS style
501 while (wndPtr
->dwStyle
& WS_CHILD
)
503 wndPtr
= wndPtr
->parent
;
504 xoffset
-= wndPtr
->rectClient
.left
;
505 yoffset
-= wndPtr
->rectClient
.top
;
506 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
508 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
509 hrgnClip
, &rect
, xoffset
, yoffset
);
513 /* Now once we've got a jumbo clip region we have
514 * to substract it from the visible rectangle.
517 CombineRgn( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
518 DeleteObject( hrgnClip
);
522 DeleteObject( hrgnVis
);
528 hrgnVis
= CreateRectRgn(0, 0, 0, 0); /* empty */
532 /***********************************************************************
535 * Change region from DC-origin relative coordinates to screen coords.
538 static void DCE_OffsetVisRgn( HDC hDC
, HRGN hVisRgn
)
541 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return;
543 OffsetRgn( hVisRgn
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
545 GDI_HEAP_UNLOCK( hDC
);
548 /***********************************************************************
551 * Translate given region from the wnd client to the DC coordinates
552 * and add it to the clipping region.
554 INT16
DCE_ExcludeRgn( HDC hDC
, WND
* wnd
, HRGN hRgn
)
559 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
562 MapWindowPoints( wnd
->hwndSelf
, dce
->hwndCurrent
, &pt
, 1);
563 if( dce
->DCXflags
& DCX_WINDOW
)
565 wnd
= WIN_FindWndPtr(dce
->hwndCurrent
);
566 pt
.x
+= wnd
->rectClient
.left
- wnd
->rectWindow
.left
;
567 pt
.y
+= wnd
->rectClient
.top
- wnd
->rectWindow
.top
;
571 OffsetRgn(hRgn
, pt
.x
, pt
.y
);
573 return ExtSelectClipRgn( hDC
, hRgn
, RGN_DIFF
);
576 /***********************************************************************
577 * GetDCEx16 (USER.359)
579 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
581 return (HDC16
)GetDCEx( hwnd
, hrgnClip
, flags
);
585 /***********************************************************************
586 * GetDCEx32 (USER32.231)
588 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
590 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
592 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
594 HRGN hrgnVisible
= 0;
600 BOOL bUpdateVisRgn
= TRUE
;
601 BOOL bUpdateClipOrigin
= FALSE
;
603 TRACE(dc
,"hwnd %04x, hrgnClip %04x, flags %08x\n",
604 hwnd
, hrgnClip
, (unsigned)flags
);
606 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
610 if (!(wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
))) flags
|= DCX_CACHE
;
612 if (flags
& DCX_USESTYLE
)
614 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
616 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
617 flags
|= DCX_CLIPSIBLINGS
;
619 if ( !(flags
& DCX_WINDOW
) )
621 if (wndPtr
->class->style
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
623 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
624 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
626 else flags
|= DCX_CACHE
;
629 if( flags
& DCX_NOCLIPCHILDREN
)
632 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
635 if (flags
& DCX_WINDOW
)
636 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
638 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
639 flags
&= ~DCX_PARENTCLIP
;
640 else if( flags
& DCX_PARENTCLIP
)
643 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
644 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
646 flags
&= ~DCX_CLIPCHILDREN
;
647 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
648 flags
|= DCX_CLIPSIBLINGS
;
652 /* find a suitable DCE */
654 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
655 DCX_CACHE
| DCX_WINDOW
);
657 if (flags
& DCX_CACHE
)
662 dceEmpty
= dceUnused
= NULL
;
664 /* Strategy: First, we attempt to find a non-empty but unused DCE with
665 * compatible flags. Next, we look for an empty entry. If the cache is
666 * full we have to purge one of the unused entries.
669 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
671 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
675 if (dce
->DCXflags
& DCX_DCEEMPTY
)
678 if ((dce
->hwndCurrent
== hwnd
) &&
679 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
680 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
682 TRACE(dc
,"\tfound valid %08x dce [%04x], flags %08x\n",
683 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
684 bUpdateVisRgn
= FALSE
;
685 bUpdateClipOrigin
= TRUE
;
690 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
694 dce
= (wndPtr
->class->style
& CS_OWNDC
) ? wndPtr
->dce
: wndPtr
->class->dce
;
695 if( dce
->hwndCurrent
== hwnd
)
697 TRACE(dc
,"\tskipping hVisRgn update\n");
698 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
700 if( (dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) &&
701 (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) )
703 /* This is likely to be a nested BeginPaint(). */
705 if( dce
->hClipRgn
!= hrgnClip
)
707 FIXME(dc
,"new hrgnClip[%04x] smashes the previous[%04x]\n",
708 hrgnClip
, dce
->hClipRgn
);
709 DCE_DeleteClipRgn( dce
);
712 RestoreVisRgn16(dce
->hDC
);
718 dce
->hwndCurrent
= hwnd
;
720 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
723 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
724 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->w
.flags
& DC_DIRTY
);
726 /* recompute visible region */
728 wndPtr
->pDriver
->pSetDrawable( wndPtr
, dc
, flags
, bUpdateClipOrigin
);
731 TRACE(dc
,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
733 if (flags
& DCX_PARENTCLIP
)
735 WND
*parentPtr
= wndPtr
->parent
;
737 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
739 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
740 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
742 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
744 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
745 wndPtr
->hwndSelf
, flags
);
746 if( flags
& DCX_WINDOW
)
747 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
748 -wndPtr
->rectWindow
.top
);
750 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
751 -wndPtr
->rectClient
.top
);
752 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
755 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
758 if ((hwnd
== GetDesktopWindow()) &&
759 (X11DRV_WND_GetXRootWindow(wndPtr
) == DefaultRootWindow(display
)))
760 hrgnVisible
= CreateRectRgn( 0, 0, SYSMETRICS_CXSCREEN
,
761 SYSMETRICS_CYSCREEN
);
764 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
765 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
768 dc
->w
.flags
&= ~DC_DIRTY
;
769 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
770 SelectVisRgn16( hdc
, hrgnVisible
);
773 TRACE(dc
,"no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
775 /* apply additional region operation (if any) */
777 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
779 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
781 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
782 dce
->hClipRgn
= hrgnClip
;
784 TRACE(dc
, "\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
787 CombineRgn( hrgnVisible
, hrgnClip
, 0, RGN_COPY
);
788 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
789 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
790 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
791 SelectVisRgn16( hdc
, hrgnVisible
);
794 if( hrgnVisible
) DeleteObject( hrgnVisible
);
796 TRACE(dc
, "(%04x,%04x,0x%lx): returning %04x\n",
797 hwnd
, hrgnClip
, flags
, hdc
);
802 /***********************************************************************
805 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
807 return (HDC16
)GetDC( hwnd
);
811 /***********************************************************************
812 * GetDC32 (USER32.230)
818 HWND hwnd
/* handle of window */
821 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE
| DCX_WINDOW
);
822 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
826 /***********************************************************************
827 * GetWindowDC16 (USER.67)
829 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
831 if (!hwnd
) hwnd
= GetDesktopWindow16();
832 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
836 /***********************************************************************
837 * GetWindowDC32 (USER32.304)
839 HDC WINAPI
GetWindowDC( HWND hwnd
)
841 if (!hwnd
) hwnd
= GetDesktopWindow();
842 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
846 /***********************************************************************
847 * ReleaseDC16 (USER.68)
849 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
851 return (INT16
)ReleaseDC( hwnd
, hdc
);
855 /***********************************************************************
856 * ReleaseDC32 (USER32.440)
862 INT WINAPI
ReleaseDC(
863 HWND hwnd
/* Handle of window - ignored */,
864 HDC hdc
/* Handle of device context */
866 DCE
* dce
= firstDCE
;
868 TRACE(dc
, "%04x %04x\n", hwnd
, hdc
);
870 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
873 if ( dce
->DCXflags
& DCX_DCEBUSY
)
874 return DCE_ReleaseDC( dce
);
878 /***********************************************************************
881 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
883 BOOL16 WINAPI
DCHook16( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
886 DCE
*dce
= firstDCE
;;
888 TRACE(dc
,"hDC = %04x, %i\n", hDC
, code
);
890 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
895 case DCHC_INVALIDVISRGN
:
897 /* GDI code calls this when it detects that the
898 * DC is dirty (usually after SetHookFlags()). This
899 * means that we have to recompute the visible region.
902 if( dce
->DCXflags
& DCX_DCEBUSY
)
904 SetHookFlags16(hDC
, DCHF_VALIDATEVISRGN
);
905 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
, 0, 0);
907 TRACE(dc
,"\tapplying saved clipRgn\n");
909 /* clip this region with saved clipping region */
911 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
912 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
915 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
916 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
917 SetRectRgn(hVisRgn
,0,0,0,0);
919 CombineRgn(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
920 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
922 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
923 DCE_OffsetVisRgn( hDC
, hVisRgn
);
924 SelectVisRgn16(hDC
, hVisRgn
);
925 DeleteObject( hVisRgn
);
927 else /* non-fatal but shouldn't happen */
928 WARN(dc
, "DC is not in use!\n");
931 case DCHC_DELETEDC
: /* FIXME: ?? */
935 FIXME(dc
,"unknown code\n");
941 /**********************************************************************
942 * WindowFromDC16 (USER.117)
944 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
946 return (HWND16
)WindowFromDC( hDC
);
950 /**********************************************************************
951 * WindowFromDC32 (USER32.581)
953 HWND WINAPI
WindowFromDC( HDC hDC
)
956 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
957 return dce
? dce
->hwndCurrent
: 0;
961 /***********************************************************************
962 * LockWindowUpdate16 (USER.294)
964 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
966 return LockWindowUpdate( hwnd
);
970 /***********************************************************************
971 * LockWindowUpdate32 (USER32.378)
973 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
975 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */