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
27 #include "sysmetrics.h"
29 /* #define DEBUG_DC */
32 #define NB_DCE 5 /* Number of DCEs created at startup */
34 static DCE
*firstDCE
= 0;
35 static HDC32 defaultDCstate
= 0;
37 static void DCE_DeleteClipRgn( DCE
* );
38 static INT32
DCE_ReleaseDC( DCE
* );
41 /***********************************************************************
44 static void DCE_DumpCache(void)
51 printf("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
52 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
, (dce
->DCXflags
& DCX_CACHE
) ?
53 "Cache" : "Owned", (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
58 /***********************************************************************
63 DCE
*DCE_AllocDCE( HWND32 hWnd
, DCE_TYPE type
)
66 if (!(dce
= HeapAlloc( SystemHeap
, 0, sizeof(DCE
) ))) return NULL
;
67 if (!(dce
->hDC
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
)))
69 HeapFree( SystemHeap
, 0, dce
);
73 /* store DCE handle in DC hook data field */
75 SetDCHook( dce
->hDC
, (FARPROC16
)DCHook
, (DWORD
)dce
);
77 dce
->hwndCurrent
= hWnd
;
82 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
84 dce
->DCXflags
= DCX_DCEBUSY
;
87 WND
* wnd
= WIN_FindWndPtr(hWnd
);
89 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
90 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
92 SetHookFlags(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
94 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
100 /***********************************************************************
103 DCE
* DCE_FreeDCE( DCE
*dce
)
105 DCE
**ppDCE
= &firstDCE
;
107 if (!dce
) return NULL
;
108 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
109 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
111 SetDCHook(dce
->hDC
, NULL
, 0L);
113 DeleteDC32( dce
->hDC
);
114 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
115 DeleteObject32(dce
->hClipRgn
);
116 HeapFree( SystemHeap
, 0, dce
);
120 /***********************************************************************
123 * Remove owned DCE and reset unreleased cache DCEs.
125 void DCE_FreeWindowDCE( WND
* pWnd
)
127 DCE
*pDCE
= firstDCE
;
131 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
133 if( pDCE
== pWnd
->dce
) /* owned DCE */
135 pDCE
= DCE_FreeDCE( pDCE
);
141 if(!(pDCE
->DCXflags
& DCX_CACHE
) ) /* class DCE */
143 if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) )
144 DCE_DeleteClipRgn( pDCE
);
146 else if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
148 fprintf(stderr
,"[%04x] GetDC() without ReleaseDC()!\n", pWnd
->hwndSelf
);
149 DCE_ReleaseDC( pDCE
);
152 pDCE
->DCXflags
&= DCX_CACHE
;
153 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
154 pDCE
->hwndCurrent
= 0;
162 /***********************************************************************
165 static void DCE_DeleteClipRgn( DCE
* dce
)
167 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
169 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
170 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
172 if( dce
->hClipRgn
> 1 )
173 DeleteObject32( dce
->hClipRgn
);
177 dprintf_dc(stddeb
,"\trestoring VisRgn\n");
179 RestoreVisRgn(dce
->hDC
);
183 /***********************************************************************
186 static INT32
DCE_ReleaseDC( DCE
* dce
)
188 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
190 /* restore previous visible region */
192 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
193 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
194 DCE_DeleteClipRgn( dce
);
196 if (dce
->DCXflags
& DCX_CACHE
)
198 SetDCState( dce
->hDC
, defaultDCstate
);
199 dce
->DCXflags
&= ~DCX_DCEBUSY
;
200 if (dce
->DCXflags
& DCX_DCEDIRTY
)
202 /* don't keep around invalidated entries
203 * because SetDCState() disables hVisRgn updates
204 * by removing dirty bit. */
206 dce
->hwndCurrent
= 0;
207 dce
->DCXflags
&= DCX_CACHE
;
208 dce
->DCXflags
|= DCX_DCEEMPTY
;
215 /***********************************************************************
218 * It is called from SetWindowPos() - we have to mark as dirty all busy
219 * DCE's for windows that have pWnd->parent as an ansector and whose client
220 * rect intersects with specified update rectangle.
222 BOOL32
DCE_InvalidateDCE(WND
* pWnd
, const RECT32
* pRectUpdate
)
224 WND
* wndScope
= pWnd
->parent
;
231 dprintf_dc(stddeb
,"InvalidateDCE: scope hwnd = %04x, (%i,%i - %i,%i)\n",
232 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
233 pRectUpdate
->right
,pRectUpdate
->bottom
);
234 if( debugging_dc
) DCE_DumpCache();
236 /* walk all DCEs and fixup non-empty entries */
238 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
240 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
242 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
244 if( wndCurrent
&& wndCurrent
!= WIN_GetDesktop() )
246 WND
* wnd
= wndCurrent
;
247 INT32 xoffset
= 0, yoffset
= 0;
249 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) ) continue;
251 /* check if DCE window is within the z-order scope */
253 for( wnd
= wndCurrent
; wnd
; wnd
= wnd
->parent
)
255 if( wnd
== wndScope
)
259 wndRect
= wndCurrent
->rectWindow
;
261 OffsetRect32( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
262 yoffset
- wndCurrent
->rectClient
.top
);
264 if (pWnd
== wndCurrent
||
265 IntersectRect32( &wndRect
, &wndRect
, pRectUpdate
))
267 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
269 /* Don't bother with visible regions of unused DCEs */
271 dprintf_dc(stddeb
,"\tpurged %08x dce [%04x]\n",
272 (unsigned)dce
, wndCurrent
->hwndSelf
);
274 dce
->hwndCurrent
= 0;
275 dce
->DCXflags
&= DCX_CACHE
;
276 dce
->DCXflags
|= DCX_DCEEMPTY
;
280 /* Set dirty bits in the hDC and DCE structs */
282 dprintf_dc(stddeb
,"\tfixed up %08x dce [%04x]\n",
283 (unsigned)dce
, wndCurrent
->hwndSelf
);
285 dce
->DCXflags
|= DCX_DCEDIRTY
;
286 SetHookFlags(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
292 xoffset
+= wnd
->rectClient
.left
;
293 yoffset
+= wnd
->rectClient
.top
;
302 /***********************************************************************
310 for (i
= 0; i
< NB_DCE
; i
++)
312 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
313 if (!defaultDCstate
) defaultDCstate
= GetDCState( dce
->hDC
);
318 /***********************************************************************
321 * Calculate the visible rectangle of a window (i.e. the client or
322 * window area clipped by the client area of all ancestors) in the
323 * corresponding coordinates. Return FALSE if the visible region is empty.
325 static BOOL32
DCE_GetVisRect( WND
*wndPtr
, BOOL32 clientArea
, RECT32
*lprect
)
327 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
329 if (wndPtr
->dwStyle
& WS_VISIBLE
)
331 INT32 xoffset
= lprect
->left
;
332 INT32 yoffset
= lprect
->top
;
334 while (wndPtr
->parent
)
336 wndPtr
= wndPtr
->parent
;
338 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
341 xoffset
+= wndPtr
->rectClient
.left
;
342 yoffset
+= wndPtr
->rectClient
.top
;
343 OffsetRect32( lprect
, wndPtr
->rectClient
.left
,
344 wndPtr
->rectClient
.top
);
346 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
347 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
348 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
349 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
350 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
351 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
354 lprect
->left
= MAX( lprect
->left
, wndPtr
->rectClient
.left
);
355 lprect
->right
= MIN( lprect
->right
, wndPtr
->rectClient
.right
);
356 lprect
->top
= MAX( lprect
->top
, wndPtr
->rectClient
.top
);
357 lprect
->bottom
= MIN( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
359 OffsetRect32( lprect
, -xoffset
, -yoffset
);
364 SetRectEmpty32( lprect
);
369 /***********************************************************************
372 * Go through the linked list of windows from pWndStart to pWndEnd,
373 * adding to the clip region the intersection of the target rectangle
374 * with an offset window rectangle.
376 static BOOL32
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
377 HRGN32 hrgnClip
, LPRECT32 lpRect
, int x
, int y
)
381 if (pWndStart
->window
) return TRUE
; /* X itself will do the clipping */
383 for (; pWndStart
!= pWndEnd
; pWndStart
= pWndStart
->next
)
385 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
387 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
388 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
389 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
390 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
392 if( IntersectRect32( &rect
, &rect
, lpRect
))
393 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
))
396 return (pWndStart
== pWndEnd
);
400 /***********************************************************************
403 * Return the visible region of a window, i.e. the client or window area
404 * clipped by the client area of all ancestors, and then optionally
405 * by siblings and children.
407 HRGN32
DCE_GetVisRgn( HWND32 hwnd
, WORD flags
)
411 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
413 /* Get visible rectangle and create a region with it. */
415 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
417 if((hrgnVis
= CreateRectRgnIndirect32( &rect
)))
419 HRGN32 hrgnClip
= CreateRectRgn32( 0, 0, 0, 0 );
420 INT32 xoffset
, yoffset
;
424 /* Compute obscured region for the visible rectangle by
425 * clipping children, siblings, and ancestors. Note that
426 * DCE_GetVisRect() returns a rectangle either in client
427 * or in window coordinates (for DCX_WINDOW request). */
429 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
431 if( flags
& DCX_WINDOW
)
433 /* adjust offsets since child window rectangles are
434 * in client coordinates */
436 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
437 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
440 xoffset
= yoffset
= 0;
442 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
443 &rect
, xoffset
, yoffset
);
446 /* sibling window rectangles are in client
447 * coordinates of the parent window */
449 if (flags
& DCX_WINDOW
)
451 xoffset
= -wndPtr
->rectWindow
.left
;
452 yoffset
= -wndPtr
->rectWindow
.top
;
456 xoffset
= -wndPtr
->rectClient
.left
;
457 yoffset
= -wndPtr
->rectClient
.top
;
460 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
461 DCE_AddClipRects( wndPtr
->parent
->child
,
462 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
464 /* Clip siblings of all ancestors that have the
465 * WS_CLIPSIBLINGS style
468 while (wndPtr
->dwStyle
& WS_CHILD
)
470 wndPtr
= wndPtr
->parent
;
471 xoffset
-= wndPtr
->rectClient
.left
;
472 yoffset
-= wndPtr
->rectClient
.top
;
473 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
475 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
476 hrgnClip
, &rect
, xoffset
, yoffset
);
480 /* Now once we've got a jumbo clip region we have
481 * to substract it from the visible rectangle.
484 CombineRgn32( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
485 DeleteObject32( hrgnClip
);
489 DeleteObject32( hrgnVis
);
495 hrgnVis
= CreateRectRgn32(0, 0, 0, 0); /* empty */
500 /***********************************************************************
503 * Set the drawable, origin and dimensions for the DC associated to
506 static void DCE_SetDrawable( WND
*wndPtr
, DC
*dc
, WORD flags
, BOOL32 bSetClipOrigin
)
508 if (!wndPtr
) /* Get a DC for the whole screen */
512 dc
->u
.x
.drawable
= rootWindow
;
513 TSXSetSubwindowMode( display
, dc
->u
.x
.gc
, IncludeInferiors
);
517 if (flags
& DCX_WINDOW
)
519 dc
->w
.DCOrgX
= wndPtr
->rectWindow
.left
;
520 dc
->w
.DCOrgY
= wndPtr
->rectWindow
.top
;
524 dc
->w
.DCOrgX
= wndPtr
->rectClient
.left
;
525 dc
->w
.DCOrgY
= wndPtr
->rectClient
.top
;
527 while (!wndPtr
->window
)
529 wndPtr
= wndPtr
->parent
;
530 dc
->w
.DCOrgX
+= wndPtr
->rectClient
.left
;
531 dc
->w
.DCOrgY
+= wndPtr
->rectClient
.top
;
533 dc
->w
.DCOrgX
-= wndPtr
->rectWindow
.left
;
534 dc
->w
.DCOrgY
-= wndPtr
->rectWindow
.top
;
535 dc
->u
.x
.drawable
= wndPtr
->window
;
537 /* This is needed when we reuse a cached DC because
538 * SetDCState() called by ReleaseDC() screws up DC
539 * origins for child windows.
543 TSXSetClipOrigin( display
, dc
->u
.x
.gc
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
546 /***********************************************************************
549 * Translate given region from the wnd client to the DC coordinates
550 * and add it to the clipping region.
552 INT16
DCE_ExcludeRgn( HDC32 hDC
, WND
* wnd
, HRGN32 hRgn
)
556 HRGN32 hRgnClip
= GetClipRgn16( hDC
);
559 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
562 MapWindowPoints32( 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 OffsetRgn32(hRgn
, pt
.x
, pt
.y
);
572 if( hRgnClip
) ret
= CombineRgn32( hRgnClip
, hRgnClip
, hRgn
, RGN_DIFF
);
575 hRgnClip
= InquireVisRgn( hDC
);
576 ret
= CombineRgn32( hRgn
, hRgnClip
, hRgn
, RGN_DIFF
);
577 SelectClipRgn32( hDC
, hRgn
);
582 /***********************************************************************
583 * GetDCEx16 (USER.359)
585 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
587 return (HDC16
)GetDCEx32( hwnd
, hrgnClip
, flags
);
591 /***********************************************************************
592 * GetDCEx32 (USER32.230)
594 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
596 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
598 HDC32 WINAPI
GetDCEx32( HWND32 hwnd
, HRGN32 hrgnClip
, DWORD flags
)
600 HRGN32 hrgnVisible
= 0;
606 BOOL32 bUpdateVisRgn
= TRUE
;
607 BOOL32 bUpdateClipOrigin
= FALSE
;
609 dprintf_dc(stddeb
,"GetDCEx: hwnd %04x, hrgnClip %04x, flags %08x\n",
610 hwnd
, hrgnClip
, (unsigned)flags
);
612 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
616 if (!(wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
))) flags
|= DCX_CACHE
;
618 if (flags
& DCX_USESTYLE
)
620 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
622 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
623 flags
|= DCX_CLIPSIBLINGS
;
625 if ( !(flags
& DCX_WINDOW
) )
627 if (wndPtr
->class->style
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
629 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
630 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
632 else flags
|= DCX_CACHE
;
635 if( flags
& DCX_NOCLIPCHILDREN
)
638 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
641 if (flags
& DCX_WINDOW
)
642 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
644 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
645 flags
&= ~DCX_PARENTCLIP
;
646 else if( flags
& DCX_PARENTCLIP
)
649 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
650 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
652 flags
&= ~DCX_CLIPCHILDREN
;
653 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
654 flags
|= DCX_CLIPSIBLINGS
;
658 /* find a suitable DCE */
660 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
661 DCX_CACHE
| DCX_WINDOW
);
663 if (flags
& DCX_CACHE
)
668 dceEmpty
= dceUnused
= NULL
;
670 /* Strategy: First, we attempt to find a non-empty but unused DCE with
671 * compatible flags. Next, we look for an empty entry. If the cache is
672 * full we have to purge one of the unused entries.
675 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
677 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
681 if (dce
->DCXflags
& DCX_DCEEMPTY
)
684 if ((dce
->hwndCurrent
== hwnd
) &&
685 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
686 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
688 dprintf_dc(stddeb
,"\tfound valid %08x dce [%04x], flags %08x\n",
689 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
690 bUpdateVisRgn
= FALSE
;
691 bUpdateClipOrigin
= TRUE
;
696 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
700 dce
= (wndPtr
->class->style
& CS_OWNDC
) ? wndPtr
->dce
: wndPtr
->class->dce
;
701 if( dce
->hwndCurrent
== hwnd
)
703 dprintf_dc(stddeb
,"\tskipping hVisRgn update\n");
704 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
706 if( (dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) &&
707 (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) )
709 /* This is likely to be a nested BeginPaint(). */
711 if( dce
->hClipRgn
!= hrgnClip
)
713 fprintf(stdnimp
,"GetDCEx: new hrgnClip [%04x] smashes the previous [%04x]!\n",
714 hrgnClip
, dce
->hClipRgn
);
715 DCE_DeleteClipRgn( dce
);
718 RestoreVisRgn(dce
->hDC
);
724 dce
->hwndCurrent
= hwnd
;
726 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
729 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
730 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->w
.flags
& DC_DIRTY
);
732 /* recompute visible region */
734 DCE_SetDrawable( wndPtr
, dc
, flags
, bUpdateClipOrigin
);
737 dprintf_dc(stddeb
,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
739 if (flags
& DCX_PARENTCLIP
)
741 WND
*parentPtr
= wndPtr
->parent
;
743 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
745 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
746 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
748 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
750 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
);
751 if( flags
& DCX_WINDOW
)
752 OffsetRgn32( hrgnVisible
, -wndPtr
->rectWindow
.left
,
753 -wndPtr
->rectWindow
.top
);
755 OffsetRgn32( hrgnVisible
, -wndPtr
->rectClient
.left
,
756 -wndPtr
->rectClient
.top
);
759 hrgnVisible
= CreateRectRgn32( 0, 0, 0, 0 );
762 if ((hwnd
== GetDesktopWindow32()) &&
763 (rootWindow
== DefaultRootWindow(display
)))
764 hrgnVisible
= CreateRectRgn32( 0, 0, SYSMETRICS_CXSCREEN
,
765 SYSMETRICS_CYSCREEN
);
766 else hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
);
768 dc
->w
.flags
&= ~DC_DIRTY
;
769 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
770 SelectVisRgn( hdc
, hrgnVisible
);
773 dprintf_dc(stddeb
,"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
= CreateRectRgn32( 0, 0, 0, 0 );
781 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
782 dce
->hClipRgn
= hrgnClip
;
784 dprintf_dc(stddeb
, "\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
787 CombineRgn32( hrgnVisible
, InquireVisRgn( hdc
), hrgnClip
,
788 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
789 SelectVisRgn( hdc
, hrgnVisible
);
792 if( hrgnVisible
) DeleteObject32( hrgnVisible
);
794 dprintf_dc(stddeb
, "GetDCEx(%04x,%04x,0x%lx): returning %04x\n",
795 hwnd
, hrgnClip
, flags
, hdc
);
800 /***********************************************************************
803 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
805 return (HDC16
)GetDC32( hwnd
);
809 /***********************************************************************
810 * GetDC32 (USER32.229)
812 HDC32 WINAPI
GetDC32( HWND32 hwnd
)
815 return GetDCEx32( GetDesktopWindow32(), 0, DCX_CACHE
| DCX_WINDOW
);
816 return GetDCEx32( hwnd
, 0, DCX_USESTYLE
);
820 /***********************************************************************
821 * GetWindowDC16 (USER.67)
823 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
825 if (!hwnd
) hwnd
= GetDesktopWindow16();
826 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
830 /***********************************************************************
831 * GetWindowDC32 (USER32.)
833 HDC32 WINAPI
GetWindowDC32( HWND32 hwnd
)
835 if (!hwnd
) hwnd
= GetDesktopWindow32();
836 return GetDCEx32( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
840 /***********************************************************************
841 * ReleaseDC16 (USER.68)
843 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
845 return (INT32
)ReleaseDC32( hwnd
, hdc
);
849 /***********************************************************************
850 * ReleaseDC32 (USER32.439)
852 INT32 WINAPI
ReleaseDC32( HWND32 hwnd
, HDC32 hdc
)
854 DCE
* dce
= firstDCE
;
856 dprintf_dc(stddeb
, "ReleaseDC: %04x %04x\n", hwnd
, hdc
);
858 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
861 if ( dce
->DCXflags
& DCX_DCEBUSY
)
862 return DCE_ReleaseDC( dce
);
866 /***********************************************************************
869 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
871 BOOL16 WINAPI
DCHook( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
874 DCE
*dce
= firstDCE
;;
876 dprintf_dc(stddeb
,"DCHook: hDC = %04x, %i\n", hDC
, code
);
878 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
883 case DCHC_INVALIDVISRGN
:
885 /* GDI code calls this when it detects that the
886 * DC is dirty (usually after SetHookFlags()). This
887 * means that we have to recompute the visible region.
890 if( dce
->DCXflags
& DCX_DCEBUSY
)
892 SetHookFlags(hDC
, DCHF_VALIDATEVISRGN
);
893 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
);
895 dprintf_dc(stddeb
,"\tapplying saved clipRgn\n");
897 /* clip this region with saved clipping region */
899 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
900 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
903 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
904 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
905 SetRectRgn32(hVisRgn
,0,0,0,0);
907 CombineRgn32(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
908 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
910 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
911 SelectVisRgn(hDC
, hVisRgn
);
912 DeleteObject32( hVisRgn
);
914 else /* non-fatal but shouldn't happen */
915 dprintf_dc(stddeb
,"DCHook: DC is not in use!\n");
918 case DCHC_DELETEDC
: /* FIXME: ?? */
922 fprintf(stdnimp
,"DCHook: unknown code\n");
928 /**********************************************************************
929 * WindowFromDC16 (USER32.580)
931 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
933 return (HWND16
)WindowFromDC32( hDC
);
937 /**********************************************************************
938 * WindowFromDC32 (USER32.580)
940 HWND32 WINAPI
WindowFromDC32( HDC32 hDC
)
943 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
944 return dce
? dce
->hwndCurrent
: 0;
948 /***********************************************************************
949 * LockWindowUpdate16 (USER.294)
951 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
953 return LockWindowUpdate32( hwnd
);
957 /***********************************************************************
958 * LockWindowUpdate32 (USER32.377)
960 BOOL32 WINAPI
LockWindowUpdate32( HWND32 hwnd
)
962 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */