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
30 #include "debugtools.h"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
36 DEFAULT_DEBUG_CHANNEL(dc
);
38 #define NB_DCE 5 /* Number of DCEs created at startup */
40 static DCE
*firstDCE
= 0;
41 static HDC defaultDCstate
= 0;
43 static void DCE_DeleteClipRgn( DCE
* );
44 static INT
DCE_ReleaseDC( DCE
* );
47 /***********************************************************************
50 static void DCE_DumpCache(void)
60 DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
61 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
,
62 (dce
->DCXflags
& DCX_CACHE
) ? "Cache" : "Owned",
63 (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
70 /***********************************************************************
75 DCE
*DCE_AllocDCE( HWND hWnd
, DCE_TYPE type
)
81 if (!(dce
= HeapAlloc( SystemHeap
, 0, sizeof(DCE
) ))) return NULL
;
82 if (!(dce
->hDC
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
)))
84 HeapFree( SystemHeap
, 0, dce
);
88 wnd
= WIN_FindWndPtr(hWnd
);
90 /* store DCE handle in DC hook data field */
92 hookProc
= GetProcAddress16( GetModuleHandle16("USER"), (LPCSTR
)362 );
93 SetDCHook( dce
->hDC
, hookProc
, (DWORD
)dce
);
95 dce
->hwndCurrent
= hWnd
;
100 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
102 dce
->DCXflags
= DCX_DCEBUSY
;
105 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
106 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
108 SetHookFlags16(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
110 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
112 WIN_ReleaseWndPtr(wnd
);
118 /***********************************************************************
121 DCE
* DCE_FreeDCE( DCE
*dce
)
125 if (!dce
) return NULL
;
131 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
132 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
134 SetDCHook(dce
->hDC
, NULL
, 0L);
136 DeleteDC( dce
->hDC
);
137 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
138 DeleteObject(dce
->hClipRgn
);
139 HeapFree( SystemHeap
, 0, dce
);
146 /***********************************************************************
149 * Remove owned DCE and reset unreleased cache DCEs.
151 void DCE_FreeWindowDCE( WND
* pWnd
)
160 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
162 if( pDCE
== pWnd
->dce
) /* owned or Class DCE*/
164 if (pWnd
->class->style
& CS_OWNDC
) /* owned DCE*/
166 pDCE
= DCE_FreeDCE( pDCE
);
170 else if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) ) /* Class DCE*/
172 DCE_DeleteClipRgn( pDCE
);
173 pDCE
->hwndCurrent
= 0;
178 if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
180 /* FIXME: AFAICS we are doing the right thing here so
181 * this should be a WARN. But this is best left as an ERR
182 * because the 'application error' is likely to come from
183 * another part of Wine (i.e. it's our fault after all).
184 * We should change this to WARN when Wine is more stable
187 ERR("[%04x] GetDC() without ReleaseDC()!\n",
189 DCE_ReleaseDC( pDCE
);
192 pDCE
->DCXflags
&= DCX_CACHE
;
193 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
194 pDCE
->hwndCurrent
= 0;
204 /***********************************************************************
207 static void DCE_DeleteClipRgn( DCE
* dce
)
209 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
211 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
212 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
214 if( dce
->hClipRgn
> 1 )
215 DeleteObject( dce
->hClipRgn
);
219 TRACE("\trestoring VisRgn\n");
221 RestoreVisRgn16(dce
->hDC
);
225 /***********************************************************************
228 static INT
DCE_ReleaseDC( DCE
* dce
)
230 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
232 /* restore previous visible region */
234 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
235 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
236 DCE_DeleteClipRgn( dce
);
238 if (dce
->DCXflags
& DCX_CACHE
)
240 SetDCState16( dce
->hDC
, defaultDCstate
);
241 dce
->DCXflags
&= ~DCX_DCEBUSY
;
242 if (dce
->DCXflags
& DCX_DCEDIRTY
)
244 /* don't keep around invalidated entries
245 * because SetDCState() disables hVisRgn updates
246 * by removing dirty bit. */
248 dce
->hwndCurrent
= 0;
249 dce
->DCXflags
&= DCX_CACHE
;
250 dce
->DCXflags
|= DCX_DCEEMPTY
;
257 /***********************************************************************
260 * It is called from SetWindowPos() and EVENT_MapNotify - we have to
261 * mark as dirty all busy DCEs for windows that have pWnd->parent as
262 * an ansector and whose client rect intersects with specified update
263 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
264 * DCX_CLIPCHILDREN flag is set. */
265 BOOL
DCE_InvalidateDCE(WND
* pWnd
, const RECT
* pRectUpdate
)
267 WND
* wndScope
= WIN_LockWndPtr(pWnd
->parent
);
268 WND
*pDesktop
= WIN_GetDesktop();
275 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
276 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
277 pRectUpdate
->right
,pRectUpdate
->bottom
);
281 /* walk all DCEs and fixup non-empty entries */
283 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
285 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
287 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
292 INT xoffset
= 0, yoffset
= 0;
294 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) )
296 /* child window positions don't bother us */
297 WIN_ReleaseWndPtr(wndCurrent
);
301 if( !Options
.desktopGeometry
&& wndCurrent
== pDesktop
)
303 /* don't bother with fake desktop */
304 WIN_ReleaseWndPtr(wndCurrent
);
308 /* check if DCE window is within the z-order scope */
310 for( wnd
= WIN_LockWndPtr(wndCurrent
); wnd
; WIN_UpdateWndPtr(&wnd
,wnd
->parent
))
312 if( wnd
== wndScope
)
316 wndRect
= wndCurrent
->rectWindow
;
318 OffsetRect( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
319 yoffset
- wndCurrent
->rectClient
.top
);
321 if (pWnd
== wndCurrent
||
322 IntersectRect( &wndRect
, &wndRect
, pRectUpdate
))
324 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
326 /* Don't bother with visible regions of unused DCEs */
328 TRACE("\tpurged %08x dce [%04x]\n",
329 (unsigned)dce
, wndCurrent
->hwndSelf
);
331 dce
->hwndCurrent
= 0;
332 dce
->DCXflags
&= DCX_CACHE
;
333 dce
->DCXflags
|= DCX_DCEEMPTY
;
337 /* Set dirty bits in the hDC and DCE structs */
339 TRACE("\tfixed up %08x dce [%04x]\n",
340 (unsigned)dce
, wndCurrent
->hwndSelf
);
342 dce
->DCXflags
|= DCX_DCEDIRTY
;
343 SetHookFlags16(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
347 WIN_ReleaseWndPtr(wnd
);
350 xoffset
+= wnd
->rectClient
.left
;
351 yoffset
+= wnd
->rectClient
.top
;
354 WIN_ReleaseWndPtr(wndCurrent
);
357 WIN_ReleaseWndPtr(wndScope
);
359 WIN_ReleaseDesktop();
363 /***********************************************************************
371 for (i
= 0; i
< NB_DCE
; i
++)
373 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
374 if (!defaultDCstate
) defaultDCstate
= GetDCState16( dce
->hDC
);
379 /***********************************************************************
382 * Calculate the visible rectangle of a window (i.e. the client or
383 * window area clipped by the client area of all ancestors) in the
384 * corresponding coordinates. Return FALSE if the visible region is empty.
386 static BOOL
DCE_GetVisRect( WND
*wndPtr
, BOOL clientArea
, RECT
*lprect
)
388 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
390 if (wndPtr
->dwStyle
& WS_VISIBLE
)
392 INT xoffset
= lprect
->left
;
393 INT yoffset
= lprect
->top
;
395 while( !(wndPtr
->flags
& WIN_NATIVE
) &&
396 ( wndPtr
= WIN_LockWndPtr(wndPtr
->parent
)) )
398 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
400 WIN_ReleaseWndPtr(wndPtr
);
404 xoffset
+= wndPtr
->rectClient
.left
;
405 yoffset
+= wndPtr
->rectClient
.top
;
406 OffsetRect( lprect
, wndPtr
->rectClient
.left
,
407 wndPtr
->rectClient
.top
);
409 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
410 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
411 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
412 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
413 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
414 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
416 WIN_ReleaseWndPtr(wndPtr
);
420 lprect
->left
= max( lprect
->left
, wndPtr
->rectClient
.left
);
421 lprect
->right
= min( lprect
->right
, wndPtr
->rectClient
.right
);
422 lprect
->top
= max( lprect
->top
, wndPtr
->rectClient
.top
);
423 lprect
->bottom
= min( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
425 WIN_ReleaseWndPtr(wndPtr
);
427 OffsetRect( lprect
, -xoffset
, -yoffset
);
432 SetRectEmpty( lprect
);
437 /***********************************************************************
440 * Go through the linked list of windows from pWndStart to pWndEnd,
441 * adding to the clip region the intersection of the target rectangle
442 * with an offset window rectangle.
444 static BOOL
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
445 HRGN hrgnClip
, LPRECT lpRect
, int x
, int y
)
449 if( pWndStart
->pDriver
->pIsSelfClipping( pWndStart
) )
450 return TRUE
; /* The driver itself will do the clipping */
452 for (WIN_LockWndPtr(pWndStart
); (pWndStart
&& (pWndStart
!= pWndEnd
)); WIN_UpdateWndPtr(&pWndStart
,pWndStart
->next
))
454 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
456 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
457 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
458 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
459 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
461 if( IntersectRect( &rect
, &rect
, lpRect
))
463 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
)) break;
466 WIN_ReleaseWndPtr(pWndStart
);
467 return (pWndStart
== pWndEnd
);
471 /***********************************************************************
474 * Return the visible region of a window, i.e. the client or window area
475 * clipped by the client area of all ancestors, and then optionally
476 * by siblings and children.
478 HRGN
DCE_GetVisRgn( HWND hwnd
, WORD flags
, HWND hwndChild
, WORD cflags
)
482 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
483 WND
*childWnd
= WIN_FindWndPtr( hwndChild
);
485 /* Get visible rectangle and create a region with it. */
487 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
489 if((hrgnVis
= CreateRectRgnIndirect( &rect
)))
491 HRGN hrgnClip
= CreateRectRgn( 0, 0, 0, 0 );
492 INT xoffset
, yoffset
;
496 /* Compute obscured region for the visible rectangle by
497 * clipping children, siblings, and ancestors. Note that
498 * DCE_GetVisRect() returns a rectangle either in client
499 * or in window coordinates (for DCX_WINDOW request). */
501 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
503 if( flags
& DCX_WINDOW
)
505 /* adjust offsets since child window rectangles are
506 * in client coordinates */
508 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
509 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
512 xoffset
= yoffset
= 0;
514 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
515 &rect
, xoffset
, yoffset
);
518 /* We may need to clip children of child window, if a window with PARENTDC
519 * class style and CLIPCHILDREN window style (like in Free Agent 16
520 * preference dialogs) gets here, we take the region for the parent window
521 * but apparently still need to clip the children of the child window... */
523 if( (cflags
& DCX_CLIPCHILDREN
) && childWnd
&& childWnd
->child
)
525 if( flags
& DCX_WINDOW
)
527 /* adjust offsets since child window rectangles are
528 * in client coordinates */
530 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
531 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
534 xoffset
= yoffset
= 0;
536 /* client coordinates of child window */
537 xoffset
+= childWnd
->rectClient
.left
;
538 yoffset
+= childWnd
->rectClient
.top
;
540 DCE_AddClipRects( childWnd
->child
, NULL
, hrgnClip
,
541 &rect
, xoffset
, yoffset
);
544 /* sibling window rectangles are in client
545 * coordinates of the parent window */
547 if (flags
& DCX_WINDOW
)
549 xoffset
= -wndPtr
->rectWindow
.left
;
550 yoffset
= -wndPtr
->rectWindow
.top
;
554 xoffset
= -wndPtr
->rectClient
.left
;
555 yoffset
= -wndPtr
->rectClient
.top
;
558 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
559 DCE_AddClipRects( wndPtr
->parent
->child
,
560 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
562 /* Clip siblings of all ancestors that have the
563 * WS_CLIPSIBLINGS style
566 while (wndPtr
->dwStyle
& WS_CHILD
)
568 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
569 xoffset
-= wndPtr
->rectClient
.left
;
570 yoffset
-= wndPtr
->rectClient
.top
;
571 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
573 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
574 hrgnClip
, &rect
, xoffset
, yoffset
);
578 /* Now once we've got a jumbo clip region we have
579 * to substract it from the visible rectangle.
582 CombineRgn( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
583 DeleteObject( hrgnClip
);
587 DeleteObject( hrgnVis
);
593 hrgnVis
= CreateRectRgn(0, 0, 0, 0); /* empty */
594 WIN_ReleaseWndPtr(wndPtr
);
595 WIN_ReleaseWndPtr(childWnd
);
599 /***********************************************************************
602 * Change region from DC-origin relative coordinates to screen coords.
605 static void DCE_OffsetVisRgn( HDC hDC
, HRGN hVisRgn
)
608 if (!(dc
= DC_GetDCPtr( hDC
))) return;
610 OffsetRgn( hVisRgn
, dc
->DCOrgX
, dc
->DCOrgY
);
612 GDI_ReleaseObj( hDC
);
615 /***********************************************************************
618 * Translate given region from the wnd client to the DC coordinates
619 * and add it to the clipping region.
621 INT
DCE_ExcludeRgn( HDC hDC
, WND
* wnd
, HRGN hRgn
)
626 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
629 MapWindowPoints( wnd
->hwndSelf
, dce
->hwndCurrent
, &pt
, 1);
630 if( dce
->DCXflags
& DCX_WINDOW
)
632 wnd
= WIN_FindWndPtr(dce
->hwndCurrent
);
633 pt
.x
+= wnd
->rectClient
.left
- wnd
->rectWindow
.left
;
634 pt
.y
+= wnd
->rectClient
.top
- wnd
->rectWindow
.top
;
635 WIN_ReleaseWndPtr(wnd
);
639 OffsetRgn(hRgn
, pt
.x
, pt
.y
);
641 return ExtSelectClipRgn( hDC
, hRgn
, RGN_DIFF
);
645 /***********************************************************************
646 * GetDCEx16 (USER.359)
648 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
650 return (HDC16
)GetDCEx( hwnd
, hrgnClip
, flags
);
654 /***********************************************************************
655 * GetDCEx (USER32.231)
657 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
659 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
661 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
663 HRGN hrgnVisible
= 0;
669 BOOL bUpdateVisRgn
= TRUE
;
670 BOOL bUpdateClipOrigin
= FALSE
;
672 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
673 hwnd
, hrgnClip
, (unsigned)flags
);
675 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
679 if (!(wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
))) flags
|= DCX_CACHE
;
681 if (flags
& DCX_USESTYLE
)
683 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
685 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
686 flags
|= DCX_CLIPSIBLINGS
;
688 if ( !(flags
& DCX_WINDOW
) )
690 if (wndPtr
->class->style
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
692 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
693 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
695 else flags
|= DCX_CACHE
;
698 if( flags
& DCX_NOCLIPCHILDREN
)
701 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
704 if (flags
& DCX_WINDOW
)
705 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
707 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
708 flags
&= ~DCX_PARENTCLIP
;
709 else if( flags
& DCX_PARENTCLIP
)
712 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
713 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
715 flags
&= ~DCX_CLIPCHILDREN
;
716 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
717 flags
|= DCX_CLIPSIBLINGS
;
721 /* find a suitable DCE */
723 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
724 DCX_CACHE
| DCX_WINDOW
);
726 if (flags
& DCX_CACHE
)
731 dceEmpty
= dceUnused
= NULL
;
733 /* Strategy: First, we attempt to find a non-empty but unused DCE with
734 * compatible flags. Next, we look for an empty entry. If the cache is
735 * full we have to purge one of the unused entries.
738 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
740 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
744 if (dce
->DCXflags
& DCX_DCEEMPTY
)
747 if ((dce
->hwndCurrent
== hwnd
) &&
748 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
749 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
751 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
752 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
753 bUpdateVisRgn
= FALSE
;
754 bUpdateClipOrigin
= TRUE
;
760 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
762 /* if there's no dce empty or unused, allocate a new one */
765 dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
);
770 dce
= (wndPtr
->class->style
& CS_OWNDC
) ? wndPtr
->dce
: wndPtr
->class->dce
;
771 if( dce
->hwndCurrent
== hwnd
)
773 TRACE("\tskipping hVisRgn update\n");
774 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
776 /* Abey - 16Jul99. to take care of the nested GetDC. first one
777 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
778 one with or without these flags. */
780 if(dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
782 /* This is likely to be a nested BeginPaint().
783 or a BeginPaint() followed by a GetDC()*/
785 if( dce
->hClipRgn
!= hrgnClip
)
787 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
788 hrgnClip
, dce
->hClipRgn
);
789 DCE_DeleteClipRgn( dce
);
792 RestoreVisRgn16(dce
->hDC
);
802 dce
->hwndCurrent
= hwnd
;
804 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
807 if (!(dc
= DC_GetDCPtr( hdc
)))
812 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->flags
& DC_DIRTY
);
814 /* recompute visible region */
815 wndPtr
->pDriver
->pSetDrawable( wndPtr
, hdc
, flags
, bUpdateClipOrigin
);
816 dc
->flags
&= ~DC_DIRTY
;
817 GDI_ReleaseObj( hdc
);
821 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
823 if (flags
& DCX_PARENTCLIP
)
825 WND
*parentPtr
= WIN_LockWndPtr(wndPtr
->parent
);
827 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
829 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
830 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
832 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
834 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
835 wndPtr
->hwndSelf
, flags
);
836 if( flags
& DCX_WINDOW
)
837 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
838 -wndPtr
->rectWindow
.top
);
840 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
841 -wndPtr
->rectClient
.top
);
842 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
845 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
846 WIN_ReleaseWndPtr(parentPtr
);
849 if ((hwnd
== GetDesktopWindow()) && !USER_Driver
.pIsSingleWindow())
850 hrgnVisible
= CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
) );
853 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
854 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
857 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
858 SelectVisRgn16( hdc
, hrgnVisible
);
861 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
863 /* apply additional region operation (if any) */
865 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
867 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
869 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
870 dce
->hClipRgn
= hrgnClip
;
872 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
875 CombineRgn( hrgnVisible
, hrgnClip
, 0, RGN_COPY
);
876 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
877 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
878 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
879 SelectVisRgn16( hdc
, hrgnVisible
);
882 if( hrgnVisible
) DeleteObject( hrgnVisible
);
884 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
885 hwnd
, hrgnClip
, flags
, hdc
);
887 WIN_ReleaseWndPtr(wndPtr
);
892 /***********************************************************************
895 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
897 return (HDC16
)GetDC( hwnd
);
901 /***********************************************************************
908 HWND hwnd
/* [in] handle of window */
911 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE
| DCX_WINDOW
);
912 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
916 /***********************************************************************
917 * GetWindowDC16 (USER.67)
919 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
921 if (!hwnd
) hwnd
= GetDesktopWindow16();
922 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
926 /***********************************************************************
927 * GetWindowDC (USER32.304)
929 HDC WINAPI
GetWindowDC( HWND hwnd
)
931 if (!hwnd
) hwnd
= GetDesktopWindow();
932 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
936 /***********************************************************************
937 * ReleaseDC16 (USER.68)
939 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
941 return (INT16
)ReleaseDC( hwnd
, hdc
);
945 /***********************************************************************
946 * ReleaseDC (USER32.440)
952 INT WINAPI
ReleaseDC(
953 HWND hwnd
/* [in] Handle of window - ignored */,
954 HDC hdc
/* [in] Handle of device context */
962 TRACE("%04x %04x\n", hwnd
, hdc
);
964 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
967 if ( dce
->DCXflags
& DCX_DCEBUSY
)
968 nRet
= DCE_ReleaseDC( dce
);
975 /***********************************************************************
978 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
980 BOOL16 WINAPI
DCHook16( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
984 DCE
*dce
= (DCE
*)data
;
987 TRACE("hDC = %04x, %i\n", hDC
, code
);
990 assert(dce
->hDC
== hDC
);
992 /* Grab the windows lock before doing anything else */
997 case DCHC_INVALIDVISRGN
:
999 /* GDI code calls this when it detects that the
1000 * DC is dirty (usually after SetHookFlags()). This
1001 * means that we have to recompute the visible region.
1004 if( dce
->DCXflags
& DCX_DCEBUSY
)
1007 /* Update stale DC in DCX */
1008 wndPtr
= WIN_FindWndPtr( dce
->hwndCurrent
);
1009 if (wndPtr
) wndPtr
->pDriver
->pSetDrawable( wndPtr
, dce
->hDC
, dce
->DCXflags
, TRUE
);
1011 SetHookFlags16(hDC
, DCHF_VALIDATEVISRGN
);
1012 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
, 0, 0);
1014 TRACE("\tapplying saved clipRgn\n");
1016 /* clip this region with saved clipping region */
1018 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
1019 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
1022 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
1023 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
1024 SetRectRgn(hVisRgn
,0,0,0,0);
1026 CombineRgn(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
1027 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
1029 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
1030 DCE_OffsetVisRgn( hDC
, hVisRgn
);
1031 SelectVisRgn16(hDC
, hVisRgn
);
1032 DeleteObject( hVisRgn
);
1033 WIN_ReleaseWndPtr( wndPtr
); /* Release WIN_FindWndPtr lock */
1035 else /* non-fatal but shouldn't happen */
1036 WARN("DC is not in use!\n");
1041 * Windows will not let you delete a DC that is busy
1042 * (between GetDC and ReleaseDC)
1045 if ( dce
->DCXflags
& DCX_DCEBUSY
)
1047 WARN("Application trying to delete a busy DC\n");
1053 FIXME("unknown code\n");
1056 WIN_UnlockWnds(); /* Release the wnd lock */
1061 /**********************************************************************
1062 * WindowFromDC16 (USER.117)
1064 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
1066 return (HWND16
)WindowFromDC( hDC
);
1070 /**********************************************************************
1071 * WindowFromDC (USER32.581)
1073 HWND WINAPI
WindowFromDC( HDC hDC
)
1081 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
1083 hwnd
= dce
? dce
->hwndCurrent
: 0;
1090 /***********************************************************************
1091 * LockWindowUpdate16 (USER.294)
1093 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
1095 return LockWindowUpdate( hwnd
);
1099 /***********************************************************************
1100 * LockWindowUpdate (USER32.378)
1102 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
1104 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */