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"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
35 DEFAULT_DEBUG_CHANNEL(dc
)
37 #define NB_DCE 5 /* Number of DCEs created at startup */
39 static DCE
*firstDCE
= 0;
40 static HDC defaultDCstate
= 0;
42 static void DCE_DeleteClipRgn( DCE
* );
43 static INT
DCE_ReleaseDC( DCE
* );
46 /***********************************************************************
49 static void DCE_DumpCache(void)
59 DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
60 (unsigned)dce
, dce
->hwndCurrent
, (unsigned)dce
->DCXflags
,
61 (dce
->DCXflags
& DCX_CACHE
) ? "Cache" : "Owned",
62 (dce
->DCXflags
& DCX_DCEBUSY
) ? "InUse" : "" );
69 /***********************************************************************
74 DCE
*DCE_AllocDCE( HWND hWnd
, DCE_TYPE type
)
80 if (!(dce
= HeapAlloc( SystemHeap
, 0, sizeof(DCE
) ))) return NULL
;
81 if (!(dce
->hDC
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
)))
83 HeapFree( SystemHeap
, 0, dce
);
87 wnd
= WIN_FindWndPtr(hWnd
);
89 /* store DCE handle in DC hook data field */
91 hookProc
= (FARPROC16
)NE_GetEntryPoint( GetModuleHandle16("USER"), 362 );
92 SetDCHook( dce
->hDC
, hookProc
, (DWORD
)dce
);
94 dce
->hwndCurrent
= hWnd
;
99 if( type
!= DCE_CACHE_DC
) /* owned or class DC */
101 dce
->DCXflags
= DCX_DCEBUSY
;
104 if( wnd
->dwStyle
& WS_CLIPCHILDREN
) dce
->DCXflags
|= DCX_CLIPCHILDREN
;
105 if( wnd
->dwStyle
& WS_CLIPSIBLINGS
) dce
->DCXflags
|= DCX_CLIPSIBLINGS
;
107 SetHookFlags16(dce
->hDC
,DCHF_INVALIDATEVISRGN
);
109 else dce
->DCXflags
= DCX_CACHE
| DCX_DCEEMPTY
;
111 WIN_ReleaseWndPtr(wnd
);
117 /***********************************************************************
120 DCE
* DCE_FreeDCE( DCE
*dce
)
124 if (!dce
) return NULL
;
130 while (*ppDCE
&& (*ppDCE
!= dce
)) ppDCE
= &(*ppDCE
)->next
;
131 if (*ppDCE
== dce
) *ppDCE
= dce
->next
;
133 SetDCHook(dce
->hDC
, NULL
, 0L);
135 DeleteDC( dce
->hDC
);
136 if( dce
->hClipRgn
&& !(dce
->DCXflags
& DCX_KEEPCLIPRGN
) )
137 DeleteObject(dce
->hClipRgn
);
138 HeapFree( SystemHeap
, 0, dce
);
145 /***********************************************************************
148 * Remove owned DCE and reset unreleased cache DCEs.
150 void DCE_FreeWindowDCE( WND
* pWnd
)
159 if( pDCE
->hwndCurrent
== pWnd
->hwndSelf
)
161 if( pDCE
== pWnd
->dce
) /* owned DCE */
163 pDCE
= DCE_FreeDCE( pDCE
);
169 if(!(pDCE
->DCXflags
& DCX_CACHE
) ) /* class DCE */
171 if( pDCE
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
) )
172 DCE_DeleteClipRgn( pDCE
);
174 else if( pDCE
->DCXflags
& DCX_DCEBUSY
) /* shared cache DCE */
176 ERR("[%04x] GetDC() without ReleaseDC()!\n",
178 DCE_ReleaseDC( pDCE
);
181 pDCE
->DCXflags
&= DCX_CACHE
;
182 pDCE
->DCXflags
|= DCX_DCEEMPTY
;
183 pDCE
->hwndCurrent
= 0;
193 /***********************************************************************
196 static void DCE_DeleteClipRgn( DCE
* dce
)
198 dce
->DCXflags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
| DCX_WINDOWPAINT
);
200 if( dce
->DCXflags
& DCX_KEEPCLIPRGN
)
201 dce
->DCXflags
&= ~DCX_KEEPCLIPRGN
;
203 if( dce
->hClipRgn
> 1 )
204 DeleteObject( dce
->hClipRgn
);
208 TRACE("\trestoring VisRgn\n");
210 RestoreVisRgn16(dce
->hDC
);
214 /***********************************************************************
217 static INT
DCE_ReleaseDC( DCE
* dce
)
219 if ((dce
->DCXflags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)) != DCX_DCEBUSY
) return 0;
221 /* restore previous visible region */
223 if ((dce
->DCXflags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
224 (dce
->DCXflags
& (DCX_CACHE
| DCX_WINDOWPAINT
)) )
225 DCE_DeleteClipRgn( dce
);
227 if (dce
->DCXflags
& DCX_CACHE
)
229 SetDCState16( dce
->hDC
, defaultDCstate
);
230 dce
->DCXflags
&= ~DCX_DCEBUSY
;
231 if (dce
->DCXflags
& DCX_DCEDIRTY
)
233 /* don't keep around invalidated entries
234 * because SetDCState() disables hVisRgn updates
235 * by removing dirty bit. */
237 dce
->hwndCurrent
= 0;
238 dce
->DCXflags
&= DCX_CACHE
;
239 dce
->DCXflags
|= DCX_DCEEMPTY
;
246 /***********************************************************************
249 * It is called from SetWindowPos() - we have to mark as dirty all busy
250 * DCEs for windows that have pWnd->parent as an ansector and whose client
251 * rect intersects with specified update rectangle. In addition, pWnd->parent
252 * DCEs may need to be updated if DCX_CLIPCHILDREN flag is set.
254 BOOL
DCE_InvalidateDCE(WND
* pWnd
, const RECT
* pRectUpdate
)
256 WND
* wndScope
= WIN_LockWndPtr(pWnd
->parent
);
257 WND
*pDesktop
= WIN_GetDesktop();
264 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
265 wndScope
->hwndSelf
, pRectUpdate
->left
,pRectUpdate
->top
,
266 pRectUpdate
->right
,pRectUpdate
->bottom
);
270 /* walk all DCEs and fixup non-empty entries */
272 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
274 if( !(dce
->DCXflags
& DCX_DCEEMPTY
) )
276 WND
* wndCurrent
= WIN_FindWndPtr(dce
->hwndCurrent
);
281 INT xoffset
= 0, yoffset
= 0;
283 if( (wndCurrent
== wndScope
) && !(dce
->DCXflags
& DCX_CLIPCHILDREN
) )
285 /* child window positions don't bother us */
286 WIN_ReleaseWndPtr(wndCurrent
);
290 if( !Options
.desktopGeometry
&& wndCurrent
== pDesktop
)
292 /* don't bother with fake desktop */
293 WIN_ReleaseWndPtr(wndCurrent
);
297 /* check if DCE window is within the z-order scope */
299 for( wnd
= WIN_LockWndPtr(wndCurrent
); wnd
; WIN_UpdateWndPtr(&wnd
,wnd
->parent
))
301 if( wnd
== wndScope
)
305 wndRect
= wndCurrent
->rectWindow
;
307 OffsetRect( &wndRect
, xoffset
- wndCurrent
->rectClient
.left
,
308 yoffset
- wndCurrent
->rectClient
.top
);
310 if (pWnd
== wndCurrent
||
311 IntersectRect( &wndRect
, &wndRect
, pRectUpdate
))
313 if( !(dce
->DCXflags
& DCX_DCEBUSY
) )
315 /* Don't bother with visible regions of unused DCEs */
317 TRACE("\tpurged %08x dce [%04x]\n",
318 (unsigned)dce
, wndCurrent
->hwndSelf
);
320 dce
->hwndCurrent
= 0;
321 dce
->DCXflags
&= DCX_CACHE
;
322 dce
->DCXflags
|= DCX_DCEEMPTY
;
326 /* Set dirty bits in the hDC and DCE structs */
328 TRACE("\tfixed up %08x dce [%04x]\n",
329 (unsigned)dce
, wndCurrent
->hwndSelf
);
331 dce
->DCXflags
|= DCX_DCEDIRTY
;
332 SetHookFlags16(dce
->hDC
, DCHF_INVALIDATEVISRGN
);
336 WIN_ReleaseWndPtr(wnd
);
339 xoffset
+= wnd
->rectClient
.left
;
340 yoffset
+= wnd
->rectClient
.top
;
343 WIN_ReleaseWndPtr(wndCurrent
);
346 WIN_ReleaseWndPtr(wndScope
);
348 WIN_ReleaseDesktop();
352 /***********************************************************************
360 for (i
= 0; i
< NB_DCE
; i
++)
362 if (!(dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
))) return;
363 if (!defaultDCstate
) defaultDCstate
= GetDCState16( dce
->hDC
);
368 /***********************************************************************
371 * Calculate the visible rectangle of a window (i.e. the client or
372 * window area clipped by the client area of all ancestors) in the
373 * corresponding coordinates. Return FALSE if the visible region is empty.
375 static BOOL
DCE_GetVisRect( WND
*wndPtr
, BOOL clientArea
, RECT
*lprect
)
377 *lprect
= clientArea
? wndPtr
->rectClient
: wndPtr
->rectWindow
;
379 if (wndPtr
->dwStyle
& WS_VISIBLE
)
381 INT xoffset
= lprect
->left
;
382 INT yoffset
= lprect
->top
;
384 while( !(wndPtr
->flags
& WIN_NATIVE
) &&
385 ( wndPtr
= WIN_LockWndPtr(wndPtr
->parent
)) )
387 if ( (wndPtr
->dwStyle
& (WS_ICONIC
| WS_VISIBLE
)) != WS_VISIBLE
)
389 WIN_ReleaseWndPtr(wndPtr
);
393 xoffset
+= wndPtr
->rectClient
.left
;
394 yoffset
+= wndPtr
->rectClient
.top
;
395 OffsetRect( lprect
, wndPtr
->rectClient
.left
,
396 wndPtr
->rectClient
.top
);
398 if( (wndPtr
->rectClient
.left
>= wndPtr
->rectClient
.right
) ||
399 (wndPtr
->rectClient
.top
>= wndPtr
->rectClient
.bottom
) ||
400 (lprect
->left
>= wndPtr
->rectClient
.right
) ||
401 (lprect
->right
<= wndPtr
->rectClient
.left
) ||
402 (lprect
->top
>= wndPtr
->rectClient
.bottom
) ||
403 (lprect
->bottom
<= wndPtr
->rectClient
.top
) )
405 WIN_ReleaseWndPtr(wndPtr
);
409 lprect
->left
= MAX( lprect
->left
, wndPtr
->rectClient
.left
);
410 lprect
->right
= MIN( lprect
->right
, wndPtr
->rectClient
.right
);
411 lprect
->top
= MAX( lprect
->top
, wndPtr
->rectClient
.top
);
412 lprect
->bottom
= MIN( lprect
->bottom
, wndPtr
->rectClient
.bottom
);
414 WIN_ReleaseWndPtr(wndPtr
);
416 OffsetRect( lprect
, -xoffset
, -yoffset
);
421 SetRectEmpty( lprect
);
426 /***********************************************************************
429 * Go through the linked list of windows from pWndStart to pWndEnd,
430 * adding to the clip region the intersection of the target rectangle
431 * with an offset window rectangle.
433 static BOOL
DCE_AddClipRects( WND
*pWndStart
, WND
*pWndEnd
,
434 HRGN hrgnClip
, LPRECT lpRect
, int x
, int y
)
438 if( pWndStart
->pDriver
->pIsSelfClipping( pWndStart
) )
439 return TRUE
; /* The driver itself will do the clipping */
441 for (WIN_LockWndPtr(pWndStart
); pWndStart
!= pWndEnd
; WIN_UpdateWndPtr(&pWndStart
,pWndStart
->next
))
443 if( !(pWndStart
->dwStyle
& WS_VISIBLE
) ) continue;
445 rect
.left
= pWndStart
->rectWindow
.left
+ x
;
446 rect
.top
= pWndStart
->rectWindow
.top
+ y
;
447 rect
.right
= pWndStart
->rectWindow
.right
+ x
;
448 rect
.bottom
= pWndStart
->rectWindow
.bottom
+ y
;
450 if( IntersectRect( &rect
, &rect
, lpRect
))
452 if(!REGION_UnionRectWithRgn( hrgnClip
, &rect
)) break;
455 WIN_ReleaseWndPtr(pWndStart
);
456 return (pWndStart
== pWndEnd
);
460 /***********************************************************************
463 * Return the visible region of a window, i.e. the client or window area
464 * clipped by the client area of all ancestors, and then optionally
465 * by siblings and children.
467 HRGN
DCE_GetVisRgn( HWND hwnd
, WORD flags
, HWND hwndChild
, WORD cflags
)
471 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
472 WND
*childWnd
= WIN_FindWndPtr( hwndChild
);
474 /* Get visible rectangle and create a region with it. */
476 if (wndPtr
&& DCE_GetVisRect(wndPtr
, !(flags
& DCX_WINDOW
), &rect
))
478 if((hrgnVis
= CreateRectRgnIndirect( &rect
)))
480 HRGN hrgnClip
= CreateRectRgn( 0, 0, 0, 0 );
481 INT xoffset
, yoffset
;
485 /* Compute obscured region for the visible rectangle by
486 * clipping children, siblings, and ancestors. Note that
487 * DCE_GetVisRect() returns a rectangle either in client
488 * or in window coordinates (for DCX_WINDOW request). */
490 if( (flags
& DCX_CLIPCHILDREN
) && wndPtr
->child
)
492 if( flags
& DCX_WINDOW
)
494 /* adjust offsets since child window rectangles are
495 * in client coordinates */
497 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
498 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
501 xoffset
= yoffset
= 0;
503 DCE_AddClipRects( wndPtr
->child
, NULL
, hrgnClip
,
504 &rect
, xoffset
, yoffset
);
507 /* We may need to clip children of child window, if a window with PARENTDC
508 * class style and CLIPCHILDREN window style (like in Free Agent 16
509 * preference dialogs) gets here, we take the region for the parent window
510 * but apparently still need to clip the children of the child window... */
512 if( (cflags
& DCX_CLIPCHILDREN
) && childWnd
&& childWnd
->child
)
514 if( flags
& DCX_WINDOW
)
516 /* adjust offsets since child window rectangles are
517 * in client coordinates */
519 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
520 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
523 xoffset
= yoffset
= 0;
525 /* client coordinates of child window */
526 xoffset
+= childWnd
->rectClient
.left
;
527 yoffset
+= childWnd
->rectClient
.top
;
529 DCE_AddClipRects( childWnd
->child
, NULL
, hrgnClip
,
530 &rect
, xoffset
, yoffset
);
533 /* sibling window rectangles are in client
534 * coordinates of the parent window */
536 if (flags
& DCX_WINDOW
)
538 xoffset
= -wndPtr
->rectWindow
.left
;
539 yoffset
= -wndPtr
->rectWindow
.top
;
543 xoffset
= -wndPtr
->rectClient
.left
;
544 yoffset
= -wndPtr
->rectClient
.top
;
547 if (flags
& DCX_CLIPSIBLINGS
&& wndPtr
->parent
)
548 DCE_AddClipRects( wndPtr
->parent
->child
,
549 wndPtr
, hrgnClip
, &rect
, xoffset
, yoffset
);
551 /* Clip siblings of all ancestors that have the
552 * WS_CLIPSIBLINGS style
555 while (wndPtr
->dwStyle
& WS_CHILD
)
557 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
558 xoffset
-= wndPtr
->rectClient
.left
;
559 yoffset
-= wndPtr
->rectClient
.top
;
560 if(wndPtr
->dwStyle
& WS_CLIPSIBLINGS
&& wndPtr
->parent
)
562 DCE_AddClipRects( wndPtr
->parent
->child
, wndPtr
,
563 hrgnClip
, &rect
, xoffset
, yoffset
);
567 /* Now once we've got a jumbo clip region we have
568 * to substract it from the visible rectangle.
571 CombineRgn( hrgnVis
, hrgnVis
, hrgnClip
, RGN_DIFF
);
572 DeleteObject( hrgnClip
);
576 DeleteObject( hrgnVis
);
582 hrgnVis
= CreateRectRgn(0, 0, 0, 0); /* empty */
583 WIN_ReleaseWndPtr(wndPtr
);
584 WIN_ReleaseWndPtr(childWnd
);
588 /***********************************************************************
591 * Change region from DC-origin relative coordinates to screen coords.
594 static void DCE_OffsetVisRgn( HDC hDC
, HRGN hVisRgn
)
597 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return;
599 OffsetRgn( hVisRgn
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
601 GDI_HEAP_UNLOCK( hDC
);
604 /***********************************************************************
607 * Translate given region from the wnd client to the DC coordinates
608 * and add it to the clipping region.
610 INT16
DCE_ExcludeRgn( HDC hDC
, WND
* wnd
, HRGN hRgn
)
615 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
618 MapWindowPoints( wnd
->hwndSelf
, dce
->hwndCurrent
, &pt
, 1);
619 if( dce
->DCXflags
& DCX_WINDOW
)
621 wnd
= WIN_FindWndPtr(dce
->hwndCurrent
);
622 pt
.x
+= wnd
->rectClient
.left
- wnd
->rectWindow
.left
;
623 pt
.y
+= wnd
->rectClient
.top
- wnd
->rectWindow
.top
;
624 WIN_ReleaseWndPtr(wnd
);
628 OffsetRgn(hRgn
, pt
.x
, pt
.y
);
630 return ExtSelectClipRgn( hDC
, hRgn
, RGN_DIFF
);
634 /***********************************************************************
635 * GetDCEx16 (USER.359)
637 HDC16 WINAPI
GetDCEx16( HWND16 hwnd
, HRGN16 hrgnClip
, DWORD flags
)
639 return (HDC16
)GetDCEx( hwnd
, hrgnClip
, flags
);
643 /***********************************************************************
644 * GetDCEx32 (USER32.231)
646 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
648 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
650 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
652 HRGN hrgnVisible
= 0;
658 BOOL bUpdateVisRgn
= TRUE
;
659 BOOL bUpdateClipOrigin
= FALSE
;
661 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
662 hwnd
, hrgnClip
, (unsigned)flags
);
664 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
668 if (!(wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
))) flags
|= DCX_CACHE
;
670 if (flags
& DCX_USESTYLE
)
672 flags
&= ~( DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
674 if( wndPtr
->dwStyle
& WS_CLIPSIBLINGS
)
675 flags
|= DCX_CLIPSIBLINGS
;
677 if ( !(flags
& DCX_WINDOW
) )
679 if (wndPtr
->class->style
& CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
681 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
&&
682 !(wndPtr
->dwStyle
& WS_MINIMIZE
) ) flags
|= DCX_CLIPCHILDREN
;
684 else flags
|= DCX_CACHE
;
687 if( flags
& DCX_NOCLIPCHILDREN
)
690 flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
693 if (flags
& DCX_WINDOW
)
694 flags
= (flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
696 if (!(wndPtr
->dwStyle
& WS_CHILD
) || !wndPtr
->parent
)
697 flags
&= ~DCX_PARENTCLIP
;
698 else if( flags
& DCX_PARENTCLIP
)
701 if( !(flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) )
702 if( (wndPtr
->dwStyle
& WS_VISIBLE
) && (wndPtr
->parent
->dwStyle
& WS_VISIBLE
) )
704 flags
&= ~DCX_CLIPCHILDREN
;
705 if( wndPtr
->parent
->dwStyle
& WS_CLIPSIBLINGS
)
706 flags
|= DCX_CLIPSIBLINGS
;
710 /* find a suitable DCE */
712 dcxFlags
= flags
& (DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
713 DCX_CACHE
| DCX_WINDOW
);
715 if (flags
& DCX_CACHE
)
720 dceEmpty
= dceUnused
= NULL
;
722 /* Strategy: First, we attempt to find a non-empty but unused DCE with
723 * compatible flags. Next, we look for an empty entry. If the cache is
724 * full we have to purge one of the unused entries.
727 for (dce
= firstDCE
; (dce
); dce
= dce
->next
)
729 if ((dce
->DCXflags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
733 if (dce
->DCXflags
& DCX_DCEEMPTY
)
736 if ((dce
->hwndCurrent
== hwnd
) &&
737 ((dce
->DCXflags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
|
738 DCX_CACHE
| DCX_WINDOW
| DCX_PARENTCLIP
)) == dcxFlags
))
740 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
741 (unsigned)dce
, hwnd
, (unsigned)dcxFlags
);
742 bUpdateVisRgn
= FALSE
;
743 bUpdateClipOrigin
= TRUE
;
749 if (!dce
) dce
= (dceEmpty
) ? dceEmpty
: dceUnused
;
751 /* if there's no dce empty or unused, allocate a new one */
754 dce
= DCE_AllocDCE( 0, DCE_CACHE_DC
);
759 dce
= (wndPtr
->class->style
& CS_OWNDC
) ? wndPtr
->dce
: wndPtr
->class->dce
;
760 if( dce
->hwndCurrent
== hwnd
)
762 TRACE("\tskipping hVisRgn update\n");
763 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
765 /* Abey - 16Jul99. to take care of the nested GetDC. first one
766 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
767 one with or without these flags. */
769 if(dce
->DCXflags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
771 /* This is likely to be a nested BeginPaint().
772 or a BeginPaint() followed by a GetDC()*/
774 if( dce
->hClipRgn
!= hrgnClip
)
776 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
777 hrgnClip
, dce
->hClipRgn
);
778 DCE_DeleteClipRgn( dce
);
781 RestoreVisRgn16(dce
->hDC
);
791 dce
->hwndCurrent
= hwnd
;
793 dce
->DCXflags
= dcxFlags
| (flags
& DCX_WINDOWPAINT
) | DCX_DCEBUSY
;
796 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
)))
801 bUpdateVisRgn
= bUpdateVisRgn
|| (dc
->w
.flags
& DC_DIRTY
);
803 /* recompute visible region */
804 wndPtr
->pDriver
->pSetDrawable( wndPtr
, dc
, flags
, bUpdateClipOrigin
);
808 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
810 if (flags
& DCX_PARENTCLIP
)
812 WND
*parentPtr
= WIN_LockWndPtr(wndPtr
->parent
);
814 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
816 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
817 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
819 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
821 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
822 wndPtr
->hwndSelf
, flags
);
823 if( flags
& DCX_WINDOW
)
824 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
825 -wndPtr
->rectWindow
.top
);
827 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
828 -wndPtr
->rectClient
.top
);
829 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
832 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
833 WIN_ReleaseWndPtr(parentPtr
);
836 if ((hwnd
== GetDesktopWindow()) && !DESKTOP_IsSingleWindow())
837 hrgnVisible
= CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
) );
840 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
841 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
844 dc
->w
.flags
&= ~DC_DIRTY
;
845 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
846 SelectVisRgn16( hdc
, hrgnVisible
);
849 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce
, hwnd
);
851 /* apply additional region operation (if any) */
853 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
855 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
857 dce
->DCXflags
|= flags
& (DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
858 dce
->hClipRgn
= hrgnClip
;
860 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip
);
863 CombineRgn( hrgnVisible
, hrgnClip
, 0, RGN_COPY
);
864 DCE_OffsetVisRgn( hdc
, hrgnVisible
);
865 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
866 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
867 SelectVisRgn16( hdc
, hrgnVisible
);
870 if( hrgnVisible
) DeleteObject( hrgnVisible
);
872 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
873 hwnd
, hrgnClip
, flags
, hdc
);
875 WIN_ReleaseWndPtr(wndPtr
);
880 /***********************************************************************
883 HDC16 WINAPI
GetDC16( HWND16 hwnd
)
885 return (HDC16
)GetDC( hwnd
);
889 /***********************************************************************
890 * GetDC32 (USER32.230)
896 HWND hwnd
/* handle of window */
899 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE
| DCX_WINDOW
);
900 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
904 /***********************************************************************
905 * GetWindowDC16 (USER.67)
907 HDC16 WINAPI
GetWindowDC16( HWND16 hwnd
)
909 if (!hwnd
) hwnd
= GetDesktopWindow16();
910 return GetDCEx16( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
914 /***********************************************************************
915 * GetWindowDC32 (USER32.304)
917 HDC WINAPI
GetWindowDC( HWND hwnd
)
919 if (!hwnd
) hwnd
= GetDesktopWindow();
920 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
924 /***********************************************************************
925 * ReleaseDC16 (USER.68)
927 INT16 WINAPI
ReleaseDC16( HWND16 hwnd
, HDC16 hdc
)
929 return (INT16
)ReleaseDC( hwnd
, hdc
);
933 /***********************************************************************
934 * ReleaseDC32 (USER32.440)
940 INT WINAPI
ReleaseDC(
941 HWND hwnd
/* Handle of window - ignored */,
942 HDC hdc
/* Handle of device context */
950 TRACE("%04x %04x\n", hwnd
, hdc
);
952 while (dce
&& (dce
->hDC
!= hdc
)) dce
= dce
->next
;
955 if ( dce
->DCXflags
& DCX_DCEBUSY
)
956 nRet
= DCE_ReleaseDC( dce
);
963 /***********************************************************************
966 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
968 BOOL16 WINAPI
DCHook16( HDC16 hDC
, WORD code
, DWORD data
, LPARAM lParam
)
972 DCE
*dce
= (DCE
*)data
;
976 TRACE("hDC = %04x, %i\n", hDC
, code
);
979 assert(dce
->hDC
== hDC
);
981 /* Grab the windows lock before doing anything else */
986 case DCHC_INVALIDVISRGN
:
988 /* GDI code calls this when it detects that the
989 * DC is dirty (usually after SetHookFlags()). This
990 * means that we have to recompute the visible region.
993 if( dce
->DCXflags
& DCX_DCEBUSY
)
996 /* Update stale DC in DCX */
997 wndPtr
= WIN_FindWndPtr( dce
->hwndCurrent
);
998 dc
= (DC
*) GDI_GetObjPtr( dce
->hDC
, DC_MAGIC
);
1000 wndPtr
->pDriver
->pSetDrawable( wndPtr
, dc
,dce
->DCXflags
,TRUE
);
1002 SetHookFlags16(hDC
, DCHF_VALIDATEVISRGN
);
1003 hVisRgn
= DCE_GetVisRgn(dce
->hwndCurrent
, dce
->DCXflags
, 0, 0);
1005 TRACE("\tapplying saved clipRgn\n");
1007 /* clip this region with saved clipping region */
1009 if ( (dce
->DCXflags
& DCX_INTERSECTRGN
&& dce
->hClipRgn
!= 1) ||
1010 ( dce
->DCXflags
& DCX_EXCLUDERGN
&& dce
->hClipRgn
) )
1013 if( (!dce
->hClipRgn
&& dce
->DCXflags
& DCX_INTERSECTRGN
) ||
1014 (dce
->hClipRgn
== 1 && dce
->DCXflags
& DCX_EXCLUDERGN
) )
1015 SetRectRgn(hVisRgn
,0,0,0,0);
1017 CombineRgn(hVisRgn
, hVisRgn
, dce
->hClipRgn
,
1018 (dce
->DCXflags
& DCX_EXCLUDERGN
)? RGN_DIFF
:RGN_AND
);
1020 dce
->DCXflags
&= ~DCX_DCEDIRTY
;
1021 DCE_OffsetVisRgn( hDC
, hVisRgn
);
1022 SelectVisRgn16(hDC
, hVisRgn
);
1023 DeleteObject( hVisRgn
);
1024 WIN_ReleaseWndPtr( wndPtr
); /* Release WIN_FindWndPtr lock */
1026 else /* non-fatal but shouldn't happen */
1027 WARN("DC is not in use!\n");
1032 * Windows will not let you delete a DC that is busy
1033 * (between GetDC and ReleaseDC)
1036 if ( dce
->DCXflags
& DCX_DCEBUSY
)
1038 WARN("Application trying to delete a busy DC\n");
1044 FIXME("unknown code\n");
1047 WIN_UnlockWnds(); /* Release the wnd lock */
1052 /**********************************************************************
1053 * WindowFromDC16 (USER.117)
1055 HWND16 WINAPI
WindowFromDC16( HDC16 hDC
)
1057 return (HWND16
)WindowFromDC( hDC
);
1061 /**********************************************************************
1062 * WindowFromDC32 (USER32.581)
1064 HWND WINAPI
WindowFromDC( HDC hDC
)
1072 while (dce
&& (dce
->hDC
!= hDC
)) dce
= dce
->next
;
1074 hwnd
= dce
? dce
->hwndCurrent
: 0;
1081 /***********************************************************************
1082 * LockWindowUpdate16 (USER.294)
1084 BOOL16 WINAPI
LockWindowUpdate16( HWND16 hwnd
)
1086 return LockWindowUpdate( hwnd
);
1090 /***********************************************************************
1091 * LockWindowUpdate32 (USER32.378)
1093 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
1095 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */