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 "debugtools.h"
30 #include "wine/winbase16.h"
31 #include "wine/winuser16.h"
33 DEFAULT_DEBUG_CHANNEL(dc
);
35 #define NB_DCE 5 /* Number of DCEs created at startup */
37 static DCE
*firstDCE
= 0;
38 static HDC defaultDCstate
= 0;
40 static void DCE_DeleteClipRgn( DCE
* );
41 static INT
DCE_ReleaseDC( DCE
* );
44 /***********************************************************************
47 static void DCE_DumpCache(void)
57 DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
58 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
,
59 (dce
->DCXflags
& DCX_CACHE
) ? "Cache" : "Owned",
60 (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
67 /***********************************************************************
72 DCE
*DCE_AllocDCE( HWND hWnd
, DCE_TYPE type
)
78 if (!(dce
= HeapAlloc( GetProcessHeap(), 0, sizeof(DCE
) ))) return NULL
;
79 if (!(dce
->hDC
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
)))
81 HeapFree( GetProcessHeap(), 0, dce
);
85 wnd
= WIN_FindWndPtr(hWnd
);
87 /* store DCE handle in DC hook data field */
89 hookProc
= GetProcAddress16( GetModuleHandle16("USER"), (LPCSTR
)362 );
90 SetDCHook( dce
->hDC
, hookProc
, (DWORD
)dce
);
92 dce
->hwndCurrent
= hWnd
;
97 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
99 dce
->DCXflags
= DCX_DCEBUSY
;
102 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
103 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
105 SetHookFlags16(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
107 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
109 WIN_ReleaseWndPtr(wnd
);
115 /***********************************************************************
118 DCE
* DCE_FreeDCE( DCE
*dce
)
122 if (!dce
) return NULL
;
128 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
129 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
131 SetDCHook(dce
->hDC
, NULL
, 0L);
133 DeleteDC( dce
->hDC
);
134 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
135 DeleteObject(dce
->hClipRgn
);
136 HeapFree( GetProcessHeap(), 0, dce
);
143 /***********************************************************************
146 * Remove owned DCE and reset unreleased cache DCEs.
148 void DCE_FreeWindowDCE( WND
* pWnd
)
157 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
159 if( pDCE
== pWnd
->dce
) /* owned or Class DCE*/
161 if (pWnd
->clsStyle
& CS_OWNDC
) /* owned DCE*/
163 pDCE
= DCE_FreeDCE( pDCE
);
167 else if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) ) /* Class DCE*/
169 DCE_DeleteClipRgn( pDCE
);
170 pDCE
->hwndCurrent
= 0;
175 if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
177 /* FIXME: AFAICS we are doing the right thing here so
178 * this should be a WARN. But this is best left as an ERR
179 * because the 'application error' is likely to come from
180 * another part of Wine (i.e. it's our fault after all).
181 * We should change this to WARN when Wine is more stable
184 ERR("[%04x] GetDC() without ReleaseDC()!\n",
186 DCE_ReleaseDC( pDCE
);
189 pDCE
->DCXflags
&= DCX_CACHE
;
190 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
191 pDCE
->hwndCurrent
= 0;
201 /***********************************************************************
204 static void DCE_DeleteClipRgn( DCE
* dce
)
206 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
208 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
209 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
211 if( dce
->hClipRgn
> 1 )
212 DeleteObject( dce
->hClipRgn
);
216 TRACE("\trestoring VisRgn\n");
218 RestoreVisRgn16(dce
->hDC
);
222 /***********************************************************************
225 static INT
DCE_ReleaseDC( DCE
* dce
)
227 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
229 /* restore previous visible region */
231 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
232 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
233 DCE_DeleteClipRgn( dce
);
235 if (dce
->DCXflags
& DCX_CACHE
)
237 SetDCState16( dce
->hDC
, defaultDCstate
);
238 dce
->DCXflags
&= ~DCX_DCEBUSY
;
239 if (dce
->DCXflags
& DCX_DCEDIRTY
)
241 /* don't keep around invalidated entries
242 * because SetDCState() disables hVisRgn updates
243 * by removing dirty bit. */
245 dce
->hwndCurrent
= 0;
246 dce
->DCXflags
&= DCX_CACHE
;
247 dce
->DCXflags
|= DCX_DCEEMPTY
;
254 /***********************************************************************
257 * It is called from SetWindowPos() and EVENT_MapNotify - we have to
258 * mark as dirty all busy DCEs for windows that have pWnd->parent as
259 * an ancestor and whose client rect intersects with specified update
260 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
261 * DCX_CLIPCHILDREN flag is set. */
262 BOOL
DCE_InvalidateDCE(WND
* pWnd
, const RECT
* pRectUpdate
)
264 WND
* wndScope
= WIN_LockWndPtr(pWnd
->parent
);
265 WND
*pDesktop
= WIN_GetDesktop();
272 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
273 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
274 pRectUpdate
->right
,pRectUpdate
->bottom
);
278 /* walk all DCEs and fixup non-empty entries */
280 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
282 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
284 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
289 INT xoffset
= 0, yoffset
= 0;
291 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) )
293 /* child window positions don't bother us */
294 WIN_ReleaseWndPtr(wndCurrent
);
298 if( !Options
.desktopGeometry
&& wndCurrent
== pDesktop
)
300 /* don't bother with fake desktop */
301 WIN_ReleaseWndPtr(wndCurrent
);
305 /* check if DCE window is within the z-order scope */
307 for( wnd
= WIN_LockWndPtr(wndCurrent
); wnd
; WIN_UpdateWndPtr(&wnd
,wnd
->parent
))
309 if( wnd
== wndScope
)
313 wndRect
= wndCurrent
->rectWindow
;
315 OffsetRect( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
316 yoffset
- wndCurrent
->rectClient
.top
);
318 if (pWnd
== wndCurrent
||
319 IntersectRect( &wndRect
, &wndRect
, pRectUpdate
))
321 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
323 /* Don't bother with visible regions of unused DCEs */
325 TRACE("\tpurged %08x dce [%04x]\n",
326 (unsigned)dce
, wndCurrent
->hwndSelf
);
328 dce
->hwndCurrent
= 0;
329 dce
->DCXflags
&= DCX_CACHE
;
330 dce
->DCXflags
|= DCX_DCEEMPTY
;
334 /* Set dirty bits in the hDC and DCE structs */
336 TRACE("\tfixed up %08x dce [%04x]\n",
337 (unsigned)dce
, wndCurrent
->hwndSelf
);
339 dce
->DCXflags
|= DCX_DCEDIRTY
;
340 SetHookFlags16(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
344 WIN_ReleaseWndPtr(wnd
);
347 xoffset
+= wnd
->rectClient
.left
;
348 yoffset
+= wnd
->rectClient
.top
;
351 WIN_ReleaseWndPtr(wndCurrent
);
354 WIN_ReleaseWndPtr(wndScope
);
356 WIN_ReleaseDesktop();
360 /***********************************************************************
368 for (i
= 0; i
< NB_DCE
; i
++)
370 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
371 if (!defaultDCstate
) defaultDCstate
= GetDCState16( dce
->hDC
);
376 /***********************************************************************
379 * Calculate the visible rectangle of a window (i.e. the client or
380 * window area clipped by the client area of all ancestors) in the
381 * corresponding coordinates. Return FALSE if the visible region is empty.
383 static BOOL
DCE_GetVisRect( WND
*wndPtr
, BOOL clientArea
, RECT
*lprect
)
385 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
387 if (wndPtr
->dwStyle
& WS_VISIBLE
)
389 INT xoffset
= lprect
->left
;
390 INT yoffset
= lprect
->top
;
392 while( !(wndPtr
->flags
& WIN_NATIVE
) &&
393 ( wndPtr
= WIN_LockWndPtr(wndPtr
->parent
)) )
395 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
397 WIN_ReleaseWndPtr(wndPtr
);
401 xoffset
+= wndPtr
->rectClient
.left
;
402 yoffset
+= wndPtr
->rectClient
.top
;
403 OffsetRect( lprect
, wndPtr
->rectClient
.left
,
404 wndPtr
->rectClient
.top
);
406 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
407 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
408 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
409 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
410 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
411 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
413 WIN_ReleaseWndPtr(wndPtr
);
417 lprect
->left
= max( lprect
->left
, wndPtr
->rectClient
.left
);
418 lprect
->right
= min( lprect
->right
, wndPtr
->rectClient
.right
);
419 lprect
->top
= max( lprect
->top
, wndPtr
->rectClient
.top
);
420 lprect
->bottom
= min( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
422 WIN_ReleaseWndPtr(wndPtr
);
424 OffsetRect( lprect
, -xoffset
, -yoffset
);
429 SetRectEmpty( lprect
);
434 /***********************************************************************
437 * Go through the linked list of windows from pWndStart to pWndEnd,
438 * adding to the clip region the intersection of the target rectangle
439 * with an offset window rectangle.
441 static BOOL
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
442 HRGN hrgnClip
, LPRECT lpRect
, int x
, int y
)
446 if( pWndStart
->pDriver
->pIsSelfClipping( pWndStart
) )
447 return TRUE
; /* The driver itself will do the clipping */
449 for (WIN_LockWndPtr(pWndStart
); (pWndStart
&& (pWndStart
!= pWndEnd
)); WIN_UpdateWndPtr(&pWndStart
,pWndStart
->next
))
451 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
453 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
454 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
455 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
456 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
458 if( IntersectRect( &rect
, &rect
, lpRect
))
460 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
)) break;
463 WIN_ReleaseWndPtr(pWndStart
);
464 return (pWndStart
== pWndEnd
);
468 /***********************************************************************
471 * Return the visible region of a window, i.e. the client or window area
472 * clipped by the client area of all ancestors, and then optionally
473 * by siblings and children.
475 HRGN
DCE_GetVisRgn( HWND hwnd
, WORD flags
, HWND hwndChild
, WORD cflags
)
479 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
480 WND
*childWnd
= WIN_FindWndPtr( hwndChild
);
482 /* Get visible rectangle and create a region with it. */
484 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
486 if((hrgnVis
= CreateRectRgnIndirect( &rect
)))
488 HRGN hrgnClip
= CreateRectRgn( 0, 0, 0, 0 );
489 INT xoffset
, yoffset
;
493 /* Compute obscured region for the visible rectangle by
494 * clipping children, siblings, and ancestors. Note that
495 * DCE_GetVisRect() returns a rectangle either in client
496 * or in window coordinates (for DCX_WINDOW request). */
498 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
500 if( flags
& DCX_WINDOW
)
502 /* adjust offsets since child window rectangles are
503 * in client coordinates */
505 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
506 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
509 xoffset
= yoffset
= 0;
511 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
512 &rect
, xoffset
, yoffset
);
515 /* We may need to clip children of child window, if a window with PARENTDC
516 * class style and CLIPCHILDREN window style (like in Free Agent 16
517 * preference dialogs) gets here, we take the region for the parent window
518 * but apparently still need to clip the children of the child window... */
520 if( (cflags
& DCX_CLIPCHILDREN
) && childWnd
&& childWnd
->child
)
522 if( flags
& DCX_WINDOW
)
524 /* adjust offsets since child window rectangles are
525 * in client coordinates */
527 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
528 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
531 xoffset
= yoffset
= 0;
533 /* client coordinates of child window */
534 xoffset
+= childWnd
->rectClient
.left
;
535 yoffset
+= childWnd
->rectClient
.top
;
537 DCE_AddClipRects( childWnd
->child
, NULL
, hrgnClip
,
538 &rect
, xoffset
, yoffset
);
541 /* sibling window rectangles are in client
542 * coordinates of the parent window */
544 if (flags
& DCX_WINDOW
)
546 xoffset
= -wndPtr
->rectWindow
.left
;
547 yoffset
= -wndPtr
->rectWindow
.top
;
551 xoffset
= -wndPtr
->rectClient
.left
;
552 yoffset
= -wndPtr
->rectClient
.top
;
555 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
556 DCE_AddClipRects( wndPtr
->parent
->child
,
557 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
559 /* Clip siblings of all ancestors that have the
560 * WS_CLIPSIBLINGS style
563 while (wndPtr
->parent
)
565 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
566 xoffset
-= wndPtr
->rectClient
.left
;
567 yoffset
-= wndPtr
->rectClient
.top
;
568 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
570 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
571 hrgnClip
, &rect
, xoffset
, yoffset
);
575 /* Now once we've got a jumbo clip region we have
576 * to substract it from the visible rectangle.
579 CombineRgn( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
580 DeleteObject( hrgnClip
);
584 DeleteObject( hrgnVis
);
590 hrgnVis
= CreateRectRgn(0, 0, 0, 0); /* empty */
591 WIN_ReleaseWndPtr(wndPtr
);
592 WIN_ReleaseWndPtr(childWnd
);
596 /***********************************************************************
599 * Change region from DC-origin relative coordinates to screen coords.
602 static void DCE_OffsetVisRgn( HDC hDC
, HRGN hVisRgn
)
605 if (!(dc
= DC_GetDCPtr( hDC
))) return;
607 OffsetRgn( hVisRgn
, dc
->DCOrgX
, dc
->DCOrgY
);
609 GDI_ReleaseObj( hDC
);
612 /***********************************************************************
615 * Translate given region from the wnd client to the DC coordinates
616 * and add it to the clipping region.
618 INT
DCE_ExcludeRgn( HDC hDC
, WND
* wnd
, HRGN hRgn
)
623 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
626 MapWindowPoints( wnd
->hwndSelf
, dce
->hwndCurrent
, &pt
, 1);
627 if( dce
->DCXflags
& DCX_WINDOW
)
629 wnd
= WIN_FindWndPtr(dce
->hwndCurrent
);
630 pt
.x
+= wnd
->rectClient
.left
- wnd
->rectWindow
.left
;
631 pt
.y
+= wnd
->rectClient
.top
- wnd
->rectWindow
.top
;
632 WIN_ReleaseWndPtr(wnd
);
636 OffsetRgn(hRgn
, pt
.x
, pt
.y
);
638 return ExtSelectClipRgn( hDC
, hRgn
, RGN_DIFF
);
642 /***********************************************************************
645 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
647 return (HDC16
)GetDCEx( hwnd
, hrgnClip
, flags
);
651 /***********************************************************************
654 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
656 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
658 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
660 HRGN hrgnVisible
= 0;
666 BOOL bUpdateVisRgn
= TRUE
;
667 BOOL bUpdateClipOrigin
= FALSE
;
669 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
670 hwnd
, hrgnClip
, (unsigned)flags
);
672 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
676 if (!wndPtr
->dce
) flags
|= DCX_CACHE
;
678 if (flags
& DCX_USESTYLE
)
680 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
682 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
683 flags
|= DCX_CLIPSIBLINGS
;
685 if ( !(flags
& DCX_WINDOW
) )
687 if (wndPtr
->clsStyle
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
689 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
690 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
692 else flags
|= DCX_CACHE
;
695 if( flags
& DCX_NOCLIPCHILDREN
)
698 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
701 if (flags
& DCX_WINDOW
)
702 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
704 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
705 flags
&= ~DCX_PARENTCLIP
;
706 else if( flags
& DCX_PARENTCLIP
)
709 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
710 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
712 flags
&= ~DCX_CLIPCHILDREN
;
713 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
714 flags
|= DCX_CLIPSIBLINGS
;
718 /* find a suitable DCE */
720 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
721 DCX_CACHE
| DCX_WINDOW
);
723 if (flags
& DCX_CACHE
)
728 dceEmpty
= dceUnused
= NULL
;
730 /* Strategy: First, we attempt to find a non-empty but unused DCE with
731 * compatible flags. Next, we look for an empty entry. If the cache is
732 * full we have to purge one of the unused entries.
735 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
737 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
741 if (dce
->DCXflags
& DCX_DCEEMPTY
)
744 if ((dce
->hwndCurrent
== hwnd
) &&
745 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
746 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
748 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
749 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
750 bUpdateVisRgn
= FALSE
;
751 bUpdateClipOrigin
= TRUE
;
757 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
759 /* if there's no dce empty or unused, allocate a new one */
762 dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
);
768 if( dce
->hwndCurrent
== hwnd
)
770 TRACE("\tskipping hVisRgn update\n");
771 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
773 /* Abey - 16Jul99. to take care of the nested GetDC. first one
774 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
775 one with or without these flags. */
777 if(dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
779 /* This is likely to be a nested BeginPaint().
780 or a BeginPaint() followed by a GetDC()*/
782 if( dce
->hClipRgn
!= hrgnClip
)
784 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
785 hrgnClip
, dce
->hClipRgn
);
786 DCE_DeleteClipRgn( dce
);
789 RestoreVisRgn16(dce
->hDC
);
799 dce
->hwndCurrent
= hwnd
;
801 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
804 if (!(dc
= DC_GetDCPtr( hdc
)))
809 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->flags
& DC_DIRTY
);
811 /* recompute visible region */
812 wndPtr
->pDriver
->pSetDrawable( wndPtr
, hdc
, flags
, bUpdateClipOrigin
);
813 dc
->flags
&= ~DC_DIRTY
;
814 GDI_ReleaseObj( hdc
);
818 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
820 if (flags
& DCX_PARENTCLIP
)
822 WND
*parentPtr
= WIN_LockWndPtr(wndPtr
->parent
);
824 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
826 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
827 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
829 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
831 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
832 wndPtr
->hwndSelf
, flags
);
833 if( flags
& DCX_WINDOW
)
834 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
835 -wndPtr
->rectWindow
.top
);
837 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
838 -wndPtr
->rectClient
.top
);
839 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
842 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
843 WIN_ReleaseWndPtr(parentPtr
);
846 if ((hwnd
== GetDesktopWindow()) && !USER_Driver
.pIsSingleWindow())
847 hrgnVisible
= CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
) );
850 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
851 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
854 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
855 SelectVisRgn16( hdc
, hrgnVisible
);
858 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
860 /* apply additional region operation (if any) */
862 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
864 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
866 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
867 dce
->hClipRgn
= hrgnClip
;
869 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
872 CombineRgn( hrgnVisible
, hrgnClip
, 0, RGN_COPY
);
873 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
874 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
875 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
876 SelectVisRgn16( hdc
, hrgnVisible
);
879 if( hrgnVisible
) DeleteObject( hrgnVisible
);
881 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
882 hwnd
, hrgnClip
, flags
, hdc
);
884 WIN_ReleaseWndPtr(wndPtr
);
889 /***********************************************************************
892 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
894 return (HDC16
)GetDC( hwnd
);
898 /***********************************************************************
905 HWND hwnd
/* [in] handle of window */
908 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE
| DCX_WINDOW
);
909 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
913 /***********************************************************************
914 * GetWindowDC (USER.67)
916 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
918 if (!hwnd
) hwnd
= GetDesktopWindow16();
919 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
923 /***********************************************************************
924 * GetWindowDC (USER32.@)
926 HDC WINAPI
GetWindowDC( HWND hwnd
)
928 if (!hwnd
) hwnd
= GetDesktopWindow();
929 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
933 /***********************************************************************
934 * ReleaseDC (USER.68)
936 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
938 return (INT16
)ReleaseDC( hwnd
, hdc
);
942 /***********************************************************************
943 * ReleaseDC (USER32.@)
949 INT WINAPI
ReleaseDC(
950 HWND hwnd
/* [in] Handle of window - ignored */,
951 HDC hdc
/* [in] Handle of device context */
959 TRACE("%04x %04x\n", hwnd
, hdc
);
961 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
964 if ( dce
->DCXflags
& DCX_DCEBUSY
)
965 nRet
= DCE_ReleaseDC( dce
);
972 /***********************************************************************
975 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
977 BOOL16 WINAPI
DCHook16( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
981 DCE
*dce
= (DCE
*)data
;
984 TRACE("hDC = %04x, %i\n", hDC
, code
);
987 assert(dce
->hDC
== hDC
);
989 /* Grab the windows lock before doing anything else */
994 case DCHC_INVALIDVISRGN
:
996 /* GDI code calls this when it detects that the
997 * DC is dirty (usually after SetHookFlags()). This
998 * means that we have to recompute the visible region.
1001 if( dce
->DCXflags
& DCX_DCEBUSY
)
1004 /* Update stale DC in DCX */
1005 wndPtr
= WIN_FindWndPtr( dce
->hwndCurrent
);
1006 if (wndPtr
) wndPtr
->pDriver
->pSetDrawable( wndPtr
, dce
->hDC
, dce
->DCXflags
, TRUE
);
1008 SetHookFlags16(hDC
, DCHF_VALIDATEVISRGN
);
1009 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
, 0, 0);
1011 TRACE("\tapplying saved clipRgn\n");
1013 /* clip this region with saved clipping region */
1015 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
1016 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
1019 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
1020 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
1021 SetRectRgn(hVisRgn
,0,0,0,0);
1023 CombineRgn(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
1024 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
1026 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
1027 DCE_OffsetVisRgn( hDC
, hVisRgn
);
1028 SelectVisRgn16(hDC
, hVisRgn
);
1029 DeleteObject( hVisRgn
);
1030 WIN_ReleaseWndPtr( wndPtr
); /* Release WIN_FindWndPtr lock */
1032 else /* non-fatal but shouldn't happen */
1033 WARN("DC is not in use!\n");
1038 * Windows will not let you delete a DC that is busy
1039 * (between GetDC and ReleaseDC)
1042 if ( dce
->DCXflags
& DCX_DCEBUSY
)
1044 WARN("Application trying to delete a busy DC\n");
1050 FIXME("unknown code\n");
1053 WIN_UnlockWnds(); /* Release the wnd lock */
1058 /**********************************************************************
1059 * WindowFromDC (USER.117)
1061 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
1063 return (HWND16
)WindowFromDC( hDC
);
1067 /**********************************************************************
1068 * WindowFromDC (USER32.@)
1070 HWND WINAPI
WindowFromDC( HDC hDC
)
1078 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
1080 hwnd
= dce
? dce
->hwndCurrent
: 0;
1087 /***********************************************************************
1088 * LockWindowUpdate (USER.294)
1090 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
1092 return LockWindowUpdate( hwnd
);
1096 /***********************************************************************
1097 * LockWindowUpdate (USER32.@)
1099 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
1101 FIXME("DCX_LOCKWINDOWUPDATE is unimplemented\n");