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
31 #include "debugtools.h"
34 #include "wine/winbase16.h"
35 #include "wine/winuser16.h"
37 DEFAULT_DEBUG_CHANNEL(dc
);
39 #define NB_DCE 5 /* Number of DCEs created at startup */
41 static DCE
*firstDCE
= 0;
42 static HDC defaultDCstate
= 0;
44 static void DCE_DeleteClipRgn( DCE
* );
45 static INT
DCE_ReleaseDC( DCE
* );
48 /***********************************************************************
51 static void DCE_DumpCache(void)
61 DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
62 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
,
63 (dce
->DCXflags
& DCX_CACHE
) ? "Cache" : "Owned",
64 (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
71 /***********************************************************************
76 DCE
*DCE_AllocDCE( HWND hWnd
, DCE_TYPE type
)
82 if (!(dce
= HeapAlloc( SystemHeap
, 0, sizeof(DCE
) ))) return NULL
;
83 if (!(dce
->hDC
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
)))
85 HeapFree( SystemHeap
, 0, dce
);
89 wnd
= WIN_FindWndPtr(hWnd
);
91 /* store DCE handle in DC hook data field */
93 hookProc
= (FARPROC16
)NE_GetEntryPoint( GetModuleHandle16("USER"), 362 );
94 SetDCHook( dce
->hDC
, hookProc
, (DWORD
)dce
);
96 dce
->hwndCurrent
= hWnd
;
101 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
103 dce
->DCXflags
= DCX_DCEBUSY
;
106 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
107 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
109 SetHookFlags16(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
111 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
113 WIN_ReleaseWndPtr(wnd
);
119 /***********************************************************************
122 DCE
* DCE_FreeDCE( DCE
*dce
)
126 if (!dce
) return NULL
;
132 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
133 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
135 SetDCHook(dce
->hDC
, NULL
, 0L);
137 DeleteDC( dce
->hDC
);
138 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
139 DeleteObject(dce
->hClipRgn
);
140 HeapFree( SystemHeap
, 0, dce
);
147 /***********************************************************************
150 * Remove owned DCE and reset unreleased cache DCEs.
152 void DCE_FreeWindowDCE( WND
* pWnd
)
161 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
163 if( pDCE
== pWnd
->dce
) /* owned or Class DCE*/
165 if (pWnd
->class->style
& CS_OWNDC
) /* owned DCE*/
167 pDCE
= DCE_FreeDCE( pDCE
);
171 else if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) ) /* Class DCE*/
173 DCE_DeleteClipRgn( pDCE
);
174 pDCE
->hwndCurrent
= 0;
179 if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
181 /* FIXME: AFAICS we are doing the right thing here so
182 * this should be a WARN. But this is best left as an ERR
183 * because the 'application error' is likely to come from
184 * another part of Wine (i.e. it's our fault after all).
185 * We should change this to WARN when Wine is more stable
188 ERR("[%04x] GetDC() without ReleaseDC()!\n",
190 DCE_ReleaseDC( pDCE
);
193 pDCE
->DCXflags
&= DCX_CACHE
;
194 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
195 pDCE
->hwndCurrent
= 0;
205 /***********************************************************************
208 static void DCE_DeleteClipRgn( DCE
* dce
)
210 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
212 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
213 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
215 if( dce
->hClipRgn
> 1 )
216 DeleteObject( dce
->hClipRgn
);
220 TRACE("\trestoring VisRgn\n");
222 RestoreVisRgn16(dce
->hDC
);
226 /***********************************************************************
229 static INT
DCE_ReleaseDC( DCE
* dce
)
231 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
233 /* restore previous visible region */
235 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
236 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
237 DCE_DeleteClipRgn( dce
);
239 if (dce
->DCXflags
& DCX_CACHE
)
241 SetDCState16( dce
->hDC
, defaultDCstate
);
242 dce
->DCXflags
&= ~DCX_DCEBUSY
;
243 if (dce
->DCXflags
& DCX_DCEDIRTY
)
245 /* don't keep around invalidated entries
246 * because SetDCState() disables hVisRgn updates
247 * by removing dirty bit. */
249 dce
->hwndCurrent
= 0;
250 dce
->DCXflags
&= DCX_CACHE
;
251 dce
->DCXflags
|= DCX_DCEEMPTY
;
258 /***********************************************************************
261 * It is called from SetWindowPos() and EVENT_MapNotify - we have to
262 * mark as dirty all busy DCEs for windows that have pWnd->parent as
263 * an ansector and whose client rect intersects with specified update
264 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
265 * DCX_CLIPCHILDREN flag is set. */
266 BOOL
DCE_InvalidateDCE(WND
* pWnd
, const RECT
* pRectUpdate
)
268 WND
* wndScope
= WIN_LockWndPtr(pWnd
->parent
);
269 WND
*pDesktop
= WIN_GetDesktop();
276 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
277 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
278 pRectUpdate
->right
,pRectUpdate
->bottom
);
282 /* walk all DCEs and fixup non-empty entries */
284 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
286 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
288 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
293 INT xoffset
= 0, yoffset
= 0;
295 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) )
297 /* child window positions don't bother us */
298 WIN_ReleaseWndPtr(wndCurrent
);
302 if( !Options
.desktopGeometry
&& wndCurrent
== pDesktop
)
304 /* don't bother with fake desktop */
305 WIN_ReleaseWndPtr(wndCurrent
);
309 /* check if DCE window is within the z-order scope */
311 for( wnd
= WIN_LockWndPtr(wndCurrent
); wnd
; WIN_UpdateWndPtr(&wnd
,wnd
->parent
))
313 if( wnd
== wndScope
)
317 wndRect
= wndCurrent
->rectWindow
;
319 OffsetRect( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
320 yoffset
- wndCurrent
->rectClient
.top
);
322 if (pWnd
== wndCurrent
||
323 IntersectRect( &wndRect
, &wndRect
, pRectUpdate
))
325 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
327 /* Don't bother with visible regions of unused DCEs */
329 TRACE("\tpurged %08x dce [%04x]\n",
330 (unsigned)dce
, wndCurrent
->hwndSelf
);
332 dce
->hwndCurrent
= 0;
333 dce
->DCXflags
&= DCX_CACHE
;
334 dce
->DCXflags
|= DCX_DCEEMPTY
;
338 /* Set dirty bits in the hDC and DCE structs */
340 TRACE("\tfixed up %08x dce [%04x]\n",
341 (unsigned)dce
, wndCurrent
->hwndSelf
);
343 dce
->DCXflags
|= DCX_DCEDIRTY
;
344 SetHookFlags16(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
348 WIN_ReleaseWndPtr(wnd
);
351 xoffset
+= wnd
->rectClient
.left
;
352 yoffset
+= wnd
->rectClient
.top
;
355 WIN_ReleaseWndPtr(wndCurrent
);
358 WIN_ReleaseWndPtr(wndScope
);
360 WIN_ReleaseDesktop();
364 /***********************************************************************
372 for (i
= 0; i
< NB_DCE
; i
++)
374 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
375 if (!defaultDCstate
) defaultDCstate
= GetDCState16( dce
->hDC
);
380 /***********************************************************************
383 * Calculate the visible rectangle of a window (i.e. the client or
384 * window area clipped by the client area of all ancestors) in the
385 * corresponding coordinates. Return FALSE if the visible region is empty.
387 static BOOL
DCE_GetVisRect( WND
*wndPtr
, BOOL clientArea
, RECT
*lprect
)
389 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
391 if (wndPtr
->dwStyle
& WS_VISIBLE
)
393 INT xoffset
= lprect
->left
;
394 INT yoffset
= lprect
->top
;
396 while( !(wndPtr
->flags
& WIN_NATIVE
) &&
397 ( wndPtr
= WIN_LockWndPtr(wndPtr
->parent
)) )
399 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
401 WIN_ReleaseWndPtr(wndPtr
);
405 xoffset
+= wndPtr
->rectClient
.left
;
406 yoffset
+= wndPtr
->rectClient
.top
;
407 OffsetRect( lprect
, wndPtr
->rectClient
.left
,
408 wndPtr
->rectClient
.top
);
410 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
411 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
412 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
413 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
414 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
415 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
417 WIN_ReleaseWndPtr(wndPtr
);
421 lprect
->left
= max( lprect
->left
, wndPtr
->rectClient
.left
);
422 lprect
->right
= min( lprect
->right
, wndPtr
->rectClient
.right
);
423 lprect
->top
= max( lprect
->top
, wndPtr
->rectClient
.top
);
424 lprect
->bottom
= min( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
426 WIN_ReleaseWndPtr(wndPtr
);
428 OffsetRect( lprect
, -xoffset
, -yoffset
);
433 SetRectEmpty( lprect
);
438 /***********************************************************************
441 * Go through the linked list of windows from pWndStart to pWndEnd,
442 * adding to the clip region the intersection of the target rectangle
443 * with an offset window rectangle.
445 static BOOL
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
446 HRGN hrgnClip
, LPRECT lpRect
, int x
, int y
)
450 if( pWndStart
->pDriver
->pIsSelfClipping( pWndStart
) )
451 return TRUE
; /* The driver itself will do the clipping */
453 for (WIN_LockWndPtr(pWndStart
); (pWndStart
&& (pWndStart
!= pWndEnd
)); WIN_UpdateWndPtr(&pWndStart
,pWndStart
->next
))
455 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
457 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
458 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
459 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
460 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
462 if( IntersectRect( &rect
, &rect
, lpRect
))
464 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
)) break;
467 WIN_ReleaseWndPtr(pWndStart
);
468 return (pWndStart
== pWndEnd
);
472 /***********************************************************************
475 * Return the visible region of a window, i.e. the client or window area
476 * clipped by the client area of all ancestors, and then optionally
477 * by siblings and children.
479 HRGN
DCE_GetVisRgn( HWND hwnd
, WORD flags
, HWND hwndChild
, WORD cflags
)
483 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
484 WND
*childWnd
= WIN_FindWndPtr( hwndChild
);
486 /* Get visible rectangle and create a region with it. */
488 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
490 if((hrgnVis
= CreateRectRgnIndirect( &rect
)))
492 HRGN hrgnClip
= CreateRectRgn( 0, 0, 0, 0 );
493 INT xoffset
, yoffset
;
497 /* Compute obscured region for the visible rectangle by
498 * clipping children, siblings, and ancestors. Note that
499 * DCE_GetVisRect() returns a rectangle either in client
500 * or in window coordinates (for DCX_WINDOW request). */
502 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
504 if( flags
& DCX_WINDOW
)
506 /* adjust offsets since child window rectangles are
507 * in client coordinates */
509 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
510 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
513 xoffset
= yoffset
= 0;
515 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
516 &rect
, xoffset
, yoffset
);
519 /* We may need to clip children of child window, if a window with PARENTDC
520 * class style and CLIPCHILDREN window style (like in Free Agent 16
521 * preference dialogs) gets here, we take the region for the parent window
522 * but apparently still need to clip the children of the child window... */
524 if( (cflags
& DCX_CLIPCHILDREN
) && childWnd
&& childWnd
->child
)
526 if( flags
& DCX_WINDOW
)
528 /* adjust offsets since child window rectangles are
529 * in client coordinates */
531 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
532 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
535 xoffset
= yoffset
= 0;
537 /* client coordinates of child window */
538 xoffset
+= childWnd
->rectClient
.left
;
539 yoffset
+= childWnd
->rectClient
.top
;
541 DCE_AddClipRects( childWnd
->child
, NULL
, hrgnClip
,
542 &rect
, xoffset
, yoffset
);
545 /* sibling window rectangles are in client
546 * coordinates of the parent window */
548 if (flags
& DCX_WINDOW
)
550 xoffset
= -wndPtr
->rectWindow
.left
;
551 yoffset
= -wndPtr
->rectWindow
.top
;
555 xoffset
= -wndPtr
->rectClient
.left
;
556 yoffset
= -wndPtr
->rectClient
.top
;
559 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
560 DCE_AddClipRects( wndPtr
->parent
->child
,
561 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
563 /* Clip siblings of all ancestors that have the
564 * WS_CLIPSIBLINGS style
567 while (wndPtr
->dwStyle
& WS_CHILD
)
569 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
570 xoffset
-= wndPtr
->rectClient
.left
;
571 yoffset
-= wndPtr
->rectClient
.top
;
572 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
574 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
575 hrgnClip
, &rect
, xoffset
, yoffset
);
579 /* Now once we've got a jumbo clip region we have
580 * to substract it from the visible rectangle.
583 CombineRgn( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
584 DeleteObject( hrgnClip
);
588 DeleteObject( hrgnVis
);
594 hrgnVis
= CreateRectRgn(0, 0, 0, 0); /* empty */
595 WIN_ReleaseWndPtr(wndPtr
);
596 WIN_ReleaseWndPtr(childWnd
);
600 /***********************************************************************
603 * Change region from DC-origin relative coordinates to screen coords.
606 static void DCE_OffsetVisRgn( HDC hDC
, HRGN hVisRgn
)
609 if (!(dc
= DC_GetDCPtr( hDC
))) return;
611 OffsetRgn( hVisRgn
, dc
->DCOrgX
, dc
->DCOrgY
);
613 GDI_ReleaseObj( hDC
);
616 /***********************************************************************
619 * Translate given region from the wnd client to the DC coordinates
620 * and add it to the clipping region.
622 INT
DCE_ExcludeRgn( HDC hDC
, WND
* wnd
, HRGN hRgn
)
627 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
630 MapWindowPoints( wnd
->hwndSelf
, dce
->hwndCurrent
, &pt
, 1);
631 if( dce
->DCXflags
& DCX_WINDOW
)
633 wnd
= WIN_FindWndPtr(dce
->hwndCurrent
);
634 pt
.x
+= wnd
->rectClient
.left
- wnd
->rectWindow
.left
;
635 pt
.y
+= wnd
->rectClient
.top
- wnd
->rectWindow
.top
;
636 WIN_ReleaseWndPtr(wnd
);
640 OffsetRgn(hRgn
, pt
.x
, pt
.y
);
642 return ExtSelectClipRgn( hDC
, hRgn
, RGN_DIFF
);
646 /***********************************************************************
647 * GetDCEx16 (USER.359)
649 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
651 return (HDC16
)GetDCEx( hwnd
, hrgnClip
, flags
);
655 /***********************************************************************
656 * GetDCEx (USER32.231)
658 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
660 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
662 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
664 HRGN hrgnVisible
= 0;
670 BOOL bUpdateVisRgn
= TRUE
;
671 BOOL bUpdateClipOrigin
= FALSE
;
673 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
674 hwnd
, hrgnClip
, (unsigned)flags
);
676 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
680 if (!(wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
))) flags
|= DCX_CACHE
;
682 if (flags
& DCX_USESTYLE
)
684 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
686 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
687 flags
|= DCX_CLIPSIBLINGS
;
689 if ( !(flags
& DCX_WINDOW
) )
691 if (wndPtr
->class->style
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
693 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
694 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
696 else flags
|= DCX_CACHE
;
699 if( flags
& DCX_NOCLIPCHILDREN
)
702 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
705 if (flags
& DCX_WINDOW
)
706 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
708 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
709 flags
&= ~DCX_PARENTCLIP
;
710 else if( flags
& DCX_PARENTCLIP
)
713 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
714 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
716 flags
&= ~DCX_CLIPCHILDREN
;
717 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
718 flags
|= DCX_CLIPSIBLINGS
;
722 /* find a suitable DCE */
724 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
725 DCX_CACHE
| DCX_WINDOW
);
727 if (flags
& DCX_CACHE
)
732 dceEmpty
= dceUnused
= NULL
;
734 /* Strategy: First, we attempt to find a non-empty but unused DCE with
735 * compatible flags. Next, we look for an empty entry. If the cache is
736 * full we have to purge one of the unused entries.
739 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
741 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
745 if (dce
->DCXflags
& DCX_DCEEMPTY
)
748 if ((dce
->hwndCurrent
== hwnd
) &&
749 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
750 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
752 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
753 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
754 bUpdateVisRgn
= FALSE
;
755 bUpdateClipOrigin
= TRUE
;
761 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
763 /* if there's no dce empty or unused, allocate a new one */
766 dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
);
771 dce
= (wndPtr
->class->style
& CS_OWNDC
) ? wndPtr
->dce
: wndPtr
->class->dce
;
772 if( dce
->hwndCurrent
== hwnd
)
774 TRACE("\tskipping hVisRgn update\n");
775 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
777 /* Abey - 16Jul99. to take care of the nested GetDC. first one
778 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
779 one with or without these flags. */
781 if(dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
783 /* This is likely to be a nested BeginPaint().
784 or a BeginPaint() followed by a GetDC()*/
786 if( dce
->hClipRgn
!= hrgnClip
)
788 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
789 hrgnClip
, dce
->hClipRgn
);
790 DCE_DeleteClipRgn( dce
);
793 RestoreVisRgn16(dce
->hDC
);
803 dce
->hwndCurrent
= hwnd
;
805 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
808 if (!(dc
= DC_GetDCPtr( hdc
)))
813 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->flags
& DC_DIRTY
);
815 /* recompute visible region */
816 wndPtr
->pDriver
->pSetDrawable( wndPtr
, hdc
, flags
, bUpdateClipOrigin
);
817 dc
->flags
&= ~DC_DIRTY
;
818 GDI_ReleaseObj( hdc
);
822 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
824 if (flags
& DCX_PARENTCLIP
)
826 WND
*parentPtr
= WIN_LockWndPtr(wndPtr
->parent
);
828 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
830 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
831 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
833 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
835 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
836 wndPtr
->hwndSelf
, flags
);
837 if( flags
& DCX_WINDOW
)
838 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
839 -wndPtr
->rectWindow
.top
);
841 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
842 -wndPtr
->rectClient
.top
);
843 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
846 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
847 WIN_ReleaseWndPtr(parentPtr
);
850 if ((hwnd
== GetDesktopWindow()) && !USER_Driver
.pIsSingleWindow())
851 hrgnVisible
= CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
) );
854 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
855 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
858 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
859 SelectVisRgn16( hdc
, hrgnVisible
);
862 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
864 /* apply additional region operation (if any) */
866 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
868 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
870 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
871 dce
->hClipRgn
= hrgnClip
;
873 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
876 CombineRgn( hrgnVisible
, hrgnClip
, 0, RGN_COPY
);
877 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
878 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
879 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
880 SelectVisRgn16( hdc
, hrgnVisible
);
883 if( hrgnVisible
) DeleteObject( hrgnVisible
);
885 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
886 hwnd
, hrgnClip
, flags
, hdc
);
888 WIN_ReleaseWndPtr(wndPtr
);
893 /***********************************************************************
896 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
898 return (HDC16
)GetDC( hwnd
);
902 /***********************************************************************
909 HWND hwnd
/* handle of window */
912 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE
| DCX_WINDOW
);
913 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
917 /***********************************************************************
918 * GetWindowDC16 (USER.67)
920 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
922 if (!hwnd
) hwnd
= GetDesktopWindow16();
923 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
927 /***********************************************************************
928 * GetWindowDC (USER32.304)
930 HDC WINAPI
GetWindowDC( HWND hwnd
)
932 if (!hwnd
) hwnd
= GetDesktopWindow();
933 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
937 /***********************************************************************
938 * ReleaseDC16 (USER.68)
940 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
942 return (INT16
)ReleaseDC( hwnd
, hdc
);
946 /***********************************************************************
947 * ReleaseDC (USER32.440)
953 INT WINAPI
ReleaseDC(
954 HWND hwnd
/* Handle of window - ignored */,
955 HDC hdc
/* Handle of device context */
963 TRACE("%04x %04x\n", hwnd
, hdc
);
965 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
968 if ( dce
->DCXflags
& DCX_DCEBUSY
)
969 nRet
= DCE_ReleaseDC( dce
);
976 /***********************************************************************
979 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
981 BOOL16 WINAPI
DCHook16( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
985 DCE
*dce
= (DCE
*)data
;
988 TRACE("hDC = %04x, %i\n", hDC
, code
);
991 assert(dce
->hDC
== hDC
);
993 /* Grab the windows lock before doing anything else */
998 case DCHC_INVALIDVISRGN
:
1000 /* GDI code calls this when it detects that the
1001 * DC is dirty (usually after SetHookFlags()). This
1002 * means that we have to recompute the visible region.
1005 if( dce
->DCXflags
& DCX_DCEBUSY
)
1008 /* Update stale DC in DCX */
1009 wndPtr
= WIN_FindWndPtr( dce
->hwndCurrent
);
1010 if (wndPtr
) wndPtr
->pDriver
->pSetDrawable( wndPtr
, dce
->hDC
, dce
->DCXflags
, TRUE
);
1012 SetHookFlags16(hDC
, DCHF_VALIDATEVISRGN
);
1013 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
, 0, 0);
1015 TRACE("\tapplying saved clipRgn\n");
1017 /* clip this region with saved clipping region */
1019 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
1020 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
1023 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
1024 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
1025 SetRectRgn(hVisRgn
,0,0,0,0);
1027 CombineRgn(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
1028 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
1030 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
1031 DCE_OffsetVisRgn( hDC
, hVisRgn
);
1032 SelectVisRgn16(hDC
, hVisRgn
);
1033 DeleteObject( hVisRgn
);
1034 WIN_ReleaseWndPtr( wndPtr
); /* Release WIN_FindWndPtr lock */
1036 else /* non-fatal but shouldn't happen */
1037 WARN("DC is not in use!\n");
1042 * Windows will not let you delete a DC that is busy
1043 * (between GetDC and ReleaseDC)
1046 if ( dce
->DCXflags
& DCX_DCEBUSY
)
1048 WARN("Application trying to delete a busy DC\n");
1054 FIXME("unknown code\n");
1057 WIN_UnlockWnds(); /* Release the wnd lock */
1062 /**********************************************************************
1063 * WindowFromDC16 (USER.117)
1065 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
1067 return (HWND16
)WindowFromDC( hDC
);
1071 /**********************************************************************
1072 * WindowFromDC (USER32.581)
1074 HWND WINAPI
WindowFromDC( HDC hDC
)
1082 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
1084 hwnd
= dce
? dce
->hwndCurrent
: 0;
1091 /***********************************************************************
1092 * LockWindowUpdate16 (USER.294)
1094 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
1096 return LockWindowUpdate( hwnd
);
1100 /***********************************************************************
1101 * LockWindowUpdate (USER32.378)
1103 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
1105 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */