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
28 #include "debugtools.h"
31 #include "wine/winbase16.h"
32 #include "wine/winuser16.h"
34 DEFAULT_DEBUG_CHANNEL(dc);
36 #define NB_DCE 5 /* Number of DCEs created at startup */
38 static DCE *firstDCE = 0;
39 static HDC defaultDCstate = 0;
41 static void DCE_DeleteClipRgn( DCE* );
42 static INT DCE_ReleaseDC( DCE* );
45 /***********************************************************************
48 static void DCE_DumpCache(void)
58 DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
59 (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags,
60 (dce->DCXflags & DCX_CACHE) ? "Cache" : "Owned",
61 (dce->DCXflags & DCX_DCEBUSY) ? "InUse" : "" );
68 /***********************************************************************
73 DCE *DCE_AllocDCE( HWND hWnd, DCE_TYPE type )
79 if (!(dce = HeapAlloc( SystemHeap, 0, sizeof(DCE) ))) return NULL;
80 if (!(dce->hDC = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
82 HeapFree( SystemHeap, 0, dce );
86 wnd = WIN_FindWndPtr(hWnd);
88 /* store DCE handle in DC hook data field */
90 hookProc = GetProcAddress16( GetModuleHandle16("USER"), (LPCSTR)362 );
91 SetDCHook( dce->hDC, hookProc, (DWORD)dce );
93 dce->hwndCurrent = hWnd;
98 if( type != DCE_CACHE_DC ) /* owned or class DC */
100 dce->DCXflags = DCX_DCEBUSY;
103 if( wnd->dwStyle & WS_CLIPCHILDREN ) dce->DCXflags |= DCX_CLIPCHILDREN;
104 if( wnd->dwStyle & WS_CLIPSIBLINGS ) dce->DCXflags |= DCX_CLIPSIBLINGS;
106 SetHookFlags16(dce->hDC,DCHF_INVALIDATEVISRGN);
108 else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY;
110 WIN_ReleaseWndPtr(wnd);
116 /***********************************************************************
119 DCE* DCE_FreeDCE( DCE *dce )
123 if (!dce) return NULL;
129 while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next;
130 if (*ppDCE == dce) *ppDCE = dce->next;
132 SetDCHook(dce->hDC, NULL, 0L);
134 DeleteDC( dce->hDC );
135 if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
136 DeleteObject(dce->hClipRgn);
137 HeapFree( SystemHeap, 0, dce );
144 /***********************************************************************
147 * Remove owned DCE and reset unreleased cache DCEs.
149 void DCE_FreeWindowDCE( WND* pWnd )
158 if( pDCE->hwndCurrent == pWnd->hwndSelf )
160 if( pDCE == pWnd->dce ) /* owned or Class DCE*/
162 if (pWnd->clsStyle & CS_OWNDC) /* owned DCE*/
164 pDCE = DCE_FreeDCE( pDCE );
168 else if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) ) /* Class DCE*/
170 DCE_DeleteClipRgn( pDCE );
171 pDCE->hwndCurrent = 0;
176 if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
178 /* FIXME: AFAICS we are doing the right thing here so
179 * this should be a WARN. But this is best left as an ERR
180 * because the 'application error' is likely to come from
181 * another part of Wine (i.e. it's our fault after all).
182 * We should change this to WARN when Wine is more stable
185 ERR("[%04x] GetDC() without ReleaseDC()!\n",
187 DCE_ReleaseDC( pDCE );
190 pDCE->DCXflags &= DCX_CACHE;
191 pDCE->DCXflags |= DCX_DCEEMPTY;
192 pDCE->hwndCurrent = 0;
202 /***********************************************************************
205 static void DCE_DeleteClipRgn( DCE* dce )
207 dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
209 if( dce->DCXflags & DCX_KEEPCLIPRGN )
210 dce->DCXflags &= ~DCX_KEEPCLIPRGN;
212 if( dce->hClipRgn > 1 )
213 DeleteObject( dce->hClipRgn );
217 TRACE("\trestoring VisRgn\n");
219 RestoreVisRgn16(dce->hDC);
223 /***********************************************************************
226 static INT DCE_ReleaseDC( DCE* dce )
228 if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
230 /* restore previous visible region */
232 if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
233 (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
234 DCE_DeleteClipRgn( dce );
236 if (dce->DCXflags & DCX_CACHE)
238 SetDCState16( dce->hDC, defaultDCstate );
239 dce->DCXflags &= ~DCX_DCEBUSY;
240 if (dce->DCXflags & DCX_DCEDIRTY)
242 /* don't keep around invalidated entries
243 * because SetDCState() disables hVisRgn updates
244 * by removing dirty bit. */
246 dce->hwndCurrent = 0;
247 dce->DCXflags &= DCX_CACHE;
248 dce->DCXflags |= DCX_DCEEMPTY;
255 /***********************************************************************
258 * It is called from SetWindowPos() and EVENT_MapNotify - we have to
259 * mark as dirty all busy DCEs for windows that have pWnd->parent as
260 * an ansector and whose client rect intersects with specified update
261 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
262 * DCX_CLIPCHILDREN flag is set. */
263 BOOL DCE_InvalidateDCE(WND* pWnd, const RECT* pRectUpdate)
265 WND* wndScope = WIN_LockWndPtr(pWnd->parent);
266 WND *pDesktop = WIN_GetDesktop();
273 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
274 wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
275 pRectUpdate->right,pRectUpdate->bottom);
279 /* walk all DCEs and fixup non-empty entries */
281 for (dce = firstDCE; (dce); dce = dce->next)
283 if( !(dce->DCXflags & DCX_DCEEMPTY) )
285 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
290 INT xoffset = 0, yoffset = 0;
292 if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) )
294 /* child window positions don't bother us */
295 WIN_ReleaseWndPtr(wndCurrent);
299 if( !Options.desktopGeometry && wndCurrent == pDesktop )
301 /* don't bother with fake desktop */
302 WIN_ReleaseWndPtr(wndCurrent);
306 /* check if DCE window is within the z-order scope */
308 for( wnd = WIN_LockWndPtr(wndCurrent); wnd; WIN_UpdateWndPtr(&wnd,wnd->parent))
310 if( wnd == wndScope )
314 wndRect = wndCurrent->rectWindow;
316 OffsetRect( &wndRect, xoffset - wndCurrent->rectClient.left,
317 yoffset - wndCurrent->rectClient.top);
319 if (pWnd == wndCurrent ||
320 IntersectRect( &wndRect, &wndRect, pRectUpdate ))
322 if( !(dce->DCXflags & DCX_DCEBUSY) )
324 /* Don't bother with visible regions of unused DCEs */
326 TRACE("\tpurged %08x dce [%04x]\n",
327 (unsigned)dce, wndCurrent->hwndSelf);
329 dce->hwndCurrent = 0;
330 dce->DCXflags &= DCX_CACHE;
331 dce->DCXflags |= DCX_DCEEMPTY;
335 /* Set dirty bits in the hDC and DCE structs */
337 TRACE("\tfixed up %08x dce [%04x]\n",
338 (unsigned)dce, wndCurrent->hwndSelf);
340 dce->DCXflags |= DCX_DCEDIRTY;
341 SetHookFlags16(dce->hDC, DCHF_INVALIDATEVISRGN);
345 WIN_ReleaseWndPtr(wnd);
348 xoffset += wnd->rectClient.left;
349 yoffset += wnd->rectClient.top;
352 WIN_ReleaseWndPtr(wndCurrent);
355 WIN_ReleaseWndPtr(wndScope);
357 WIN_ReleaseDesktop();
361 /***********************************************************************
369 for (i = 0; i < NB_DCE; i++)
371 if (!(dce = DCE_AllocDCE( 0, DCE_CACHE_DC ))) return;
372 if (!defaultDCstate) defaultDCstate = GetDCState16( dce->hDC );
377 /***********************************************************************
380 * Calculate the visible rectangle of a window (i.e. the client or
381 * window area clipped by the client area of all ancestors) in the
382 * corresponding coordinates. Return FALSE if the visible region is empty.
384 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
386 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
388 if (wndPtr->dwStyle & WS_VISIBLE)
390 INT xoffset = lprect->left;
391 INT yoffset = lprect->top;
393 while( !(wndPtr->flags & WIN_NATIVE) &&
394 ( wndPtr = WIN_LockWndPtr(wndPtr->parent)) )
396 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
398 WIN_ReleaseWndPtr(wndPtr);
402 xoffset += wndPtr->rectClient.left;
403 yoffset += wndPtr->rectClient.top;
404 OffsetRect( lprect, wndPtr->rectClient.left,
405 wndPtr->rectClient.top );
407 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
408 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
409 (lprect->left >= wndPtr->rectClient.right) ||
410 (lprect->right <= wndPtr->rectClient.left) ||
411 (lprect->top >= wndPtr->rectClient.bottom) ||
412 (lprect->bottom <= wndPtr->rectClient.top) )
414 WIN_ReleaseWndPtr(wndPtr);
418 lprect->left = max( lprect->left, wndPtr->rectClient.left );
419 lprect->right = min( lprect->right, wndPtr->rectClient.right );
420 lprect->top = max( lprect->top, wndPtr->rectClient.top );
421 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
423 WIN_ReleaseWndPtr(wndPtr);
425 OffsetRect( lprect, -xoffset, -yoffset );
430 SetRectEmpty( lprect );
435 /***********************************************************************
438 * Go through the linked list of windows from pWndStart to pWndEnd,
439 * adding to the clip region the intersection of the target rectangle
440 * with an offset window rectangle.
442 static BOOL DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
443 HRGN hrgnClip, LPRECT lpRect, int x, int y )
447 if( pWndStart->pDriver->pIsSelfClipping( pWndStart ) )
448 return TRUE; /* The driver itself will do the clipping */
450 for (WIN_LockWndPtr(pWndStart); (pWndStart && (pWndStart != pWndEnd)); WIN_UpdateWndPtr(&pWndStart,pWndStart->next))
452 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
454 rect.left = pWndStart->rectWindow.left + x;
455 rect.top = pWndStart->rectWindow.top + y;
456 rect.right = pWndStart->rectWindow.right + x;
457 rect.bottom = pWndStart->rectWindow.bottom + y;
459 if( IntersectRect( &rect, &rect, lpRect ))
461 if(!REGION_UnionRectWithRgn( hrgnClip, &rect )) break;
464 WIN_ReleaseWndPtr(pWndStart);
465 return (pWndStart == pWndEnd);
469 /***********************************************************************
472 * Return the visible region of a window, i.e. the client or window area
473 * clipped by the client area of all ancestors, and then optionally
474 * by siblings and children.
476 HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
480 WND *wndPtr = WIN_FindWndPtr( hwnd );
481 WND *childWnd = WIN_FindWndPtr( hwndChild );
483 /* Get visible rectangle and create a region with it. */
485 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
487 if((hrgnVis = CreateRectRgnIndirect( &rect )))
489 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
490 INT xoffset, yoffset;
494 /* Compute obscured region for the visible rectangle by
495 * clipping children, siblings, and ancestors. Note that
496 * DCE_GetVisRect() returns a rectangle either in client
497 * or in window coordinates (for DCX_WINDOW request). */
499 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
501 if( flags & DCX_WINDOW )
503 /* adjust offsets since child window rectangles are
504 * in client coordinates */
506 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
507 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
510 xoffset = yoffset = 0;
512 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip,
513 &rect, xoffset, yoffset );
516 /* We may need to clip children of child window, if a window with PARENTDC
517 * class style and CLIPCHILDREN window style (like in Free Agent 16
518 * preference dialogs) gets here, we take the region for the parent window
519 * but apparently still need to clip the children of the child window... */
521 if( (cflags & DCX_CLIPCHILDREN) && childWnd && childWnd->child )
523 if( flags & DCX_WINDOW )
525 /* adjust offsets since child window rectangles are
526 * in client coordinates */
528 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
529 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
532 xoffset = yoffset = 0;
534 /* client coordinates of child window */
535 xoffset += childWnd->rectClient.left;
536 yoffset += childWnd->rectClient.top;
538 DCE_AddClipRects( childWnd->child, NULL, hrgnClip,
539 &rect, xoffset, yoffset );
542 /* sibling window rectangles are in client
543 * coordinates of the parent window */
545 if (flags & DCX_WINDOW)
547 xoffset = -wndPtr->rectWindow.left;
548 yoffset = -wndPtr->rectWindow.top;
552 xoffset = -wndPtr->rectClient.left;
553 yoffset = -wndPtr->rectClient.top;
556 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
557 DCE_AddClipRects( wndPtr->parent->child,
558 wndPtr, hrgnClip, &rect, xoffset, yoffset );
560 /* Clip siblings of all ancestors that have the
561 * WS_CLIPSIBLINGS style
564 while (wndPtr->dwStyle & WS_CHILD)
566 WIN_UpdateWndPtr(&wndPtr,wndPtr->parent);
567 xoffset -= wndPtr->rectClient.left;
568 yoffset -= wndPtr->rectClient.top;
569 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
571 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
572 hrgnClip, &rect, xoffset, yoffset );
576 /* Now once we've got a jumbo clip region we have
577 * to substract it from the visible rectangle.
580 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
581 DeleteObject( hrgnClip );
585 DeleteObject( hrgnVis );
591 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
592 WIN_ReleaseWndPtr(wndPtr);
593 WIN_ReleaseWndPtr(childWnd);
597 /***********************************************************************
600 * Change region from DC-origin relative coordinates to screen coords.
603 static void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn )
606 if (!(dc = DC_GetDCPtr( hDC ))) return;
608 OffsetRgn( hVisRgn, dc->DCOrgX, dc->DCOrgY );
610 GDI_ReleaseObj( hDC );
613 /***********************************************************************
616 * Translate given region from the wnd client to the DC coordinates
617 * and add it to the clipping region.
619 INT DCE_ExcludeRgn( HDC hDC, WND* wnd, HRGN hRgn )
624 while (dce && (dce->hDC != hDC)) dce = dce->next;
627 MapWindowPoints( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
628 if( dce->DCXflags & DCX_WINDOW )
630 wnd = WIN_FindWndPtr(dce->hwndCurrent);
631 pt.x += wnd->rectClient.left - wnd->rectWindow.left;
632 pt.y += wnd->rectClient.top - wnd->rectWindow.top;
633 WIN_ReleaseWndPtr(wnd);
637 OffsetRgn(hRgn, pt.x, pt.y);
639 return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
643 /***********************************************************************
646 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
648 return (HDC16)GetDCEx( hwnd, hrgnClip, flags );
652 /***********************************************************************
655 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
657 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
659 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
661 HRGN hrgnVisible = 0;
667 BOOL bUpdateVisRgn = TRUE;
668 BOOL bUpdateClipOrigin = FALSE;
670 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
671 hwnd, hrgnClip, (unsigned)flags);
673 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
677 if (!wndPtr->dce) flags |= DCX_CACHE;
679 if (flags & DCX_USESTYLE)
681 flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
683 if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
684 flags |= DCX_CLIPSIBLINGS;
686 if ( !(flags & DCX_WINDOW) )
688 if (wndPtr->clsStyle & CS_PARENTDC) flags |= DCX_PARENTCLIP;
690 if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
691 !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
693 else flags |= DCX_CACHE;
696 if( flags & DCX_NOCLIPCHILDREN )
699 flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
702 if (flags & DCX_WINDOW)
703 flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
705 if (!(wndPtr->dwStyle & WS_CHILD) || !wndPtr->parent )
706 flags &= ~DCX_PARENTCLIP;
707 else if( flags & DCX_PARENTCLIP )
710 if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
711 if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
713 flags &= ~DCX_CLIPCHILDREN;
714 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
715 flags |= DCX_CLIPSIBLINGS;
719 /* find a suitable DCE */
721 dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
722 DCX_CACHE | DCX_WINDOW);
724 if (flags & DCX_CACHE)
729 dceEmpty = dceUnused = NULL;
731 /* Strategy: First, we attempt to find a non-empty but unused DCE with
732 * compatible flags. Next, we look for an empty entry. If the cache is
733 * full we have to purge one of the unused entries.
736 for (dce = firstDCE; (dce); dce = dce->next)
738 if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
742 if (dce->DCXflags & DCX_DCEEMPTY)
745 if ((dce->hwndCurrent == hwnd) &&
746 ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
747 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
749 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
750 (unsigned)dce, hwnd, (unsigned)dcxFlags );
751 bUpdateVisRgn = FALSE;
752 bUpdateClipOrigin = TRUE;
758 if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
760 /* if there's no dce empty or unused, allocate a new one */
763 dce = DCE_AllocDCE( 0, DCE_CACHE_DC );
769 if( dce->hwndCurrent == hwnd )
771 TRACE("\tskipping hVisRgn update\n");
772 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
774 /* Abey - 16Jul99. to take care of the nested GetDC. first one
775 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
776 one with or without these flags. */
778 if(dce->DCXflags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
780 /* This is likely to be a nested BeginPaint().
781 or a BeginPaint() followed by a GetDC()*/
783 if( dce->hClipRgn != hrgnClip )
785 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
786 hrgnClip, dce->hClipRgn );
787 DCE_DeleteClipRgn( dce );
790 RestoreVisRgn16(dce->hDC);
800 dce->hwndCurrent = hwnd;
802 dce->DCXflags = dcxFlags | (flags & DCX_WINDOWPAINT) | DCX_DCEBUSY;
805 if (!(dc = DC_GetDCPtr( hdc )))
810 bUpdateVisRgn = bUpdateVisRgn || (dc->flags & DC_DIRTY);
812 /* recompute visible region */
813 wndPtr->pDriver->pSetDrawable( wndPtr, hdc, flags, bUpdateClipOrigin );
814 dc->flags &= ~DC_DIRTY;
815 GDI_ReleaseObj( hdc );
819 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
821 if (flags & DCX_PARENTCLIP)
823 WND *parentPtr = WIN_LockWndPtr(wndPtr->parent);
825 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
827 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
828 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
830 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
832 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
833 wndPtr->hwndSelf, flags );
834 if( flags & DCX_WINDOW )
835 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
836 -wndPtr->rectWindow.top );
838 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
839 -wndPtr->rectClient.top );
840 DCE_OffsetVisRgn( hdc, hrgnVisible );
843 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
844 WIN_ReleaseWndPtr(parentPtr);
847 if ((hwnd == GetDesktopWindow()) && !USER_Driver.pIsSingleWindow())
848 hrgnVisible = CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) );
851 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
852 DCE_OffsetVisRgn( hdc, hrgnVisible );
855 dce->DCXflags &= ~DCX_DCEDIRTY;
856 SelectVisRgn16( hdc, hrgnVisible );
859 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
861 /* apply additional region operation (if any) */
863 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
865 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
867 dce->DCXflags |= flags & (DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
868 dce->hClipRgn = hrgnClip;
870 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip);
873 CombineRgn( hrgnVisible, hrgnClip, 0, RGN_COPY );
874 DCE_OffsetVisRgn( hdc, hrgnVisible );
875 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
876 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
877 SelectVisRgn16( hdc, hrgnVisible );
880 if( hrgnVisible ) DeleteObject( hrgnVisible );
882 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
883 hwnd, hrgnClip, flags, hdc);
885 WIN_ReleaseWndPtr(wndPtr);
890 /***********************************************************************
893 HDC16 WINAPI GetDC16( HWND16 hwnd )
895 return (HDC16)GetDC( hwnd );
899 /***********************************************************************
906 HWND hwnd /* [in] handle of window */
909 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE | DCX_WINDOW );
910 return GetDCEx( hwnd, 0, DCX_USESTYLE );
914 /***********************************************************************
915 * GetWindowDC (USER.67)
917 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
919 if (!hwnd) hwnd = GetDesktopWindow16();
920 return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
924 /***********************************************************************
925 * GetWindowDC (USER32.@)
927 HDC WINAPI GetWindowDC( HWND hwnd )
929 if (!hwnd) hwnd = GetDesktopWindow();
930 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
934 /***********************************************************************
935 * ReleaseDC (USER.68)
937 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
939 return (INT16)ReleaseDC( hwnd, hdc );
943 /***********************************************************************
944 * ReleaseDC (USER32.@)
950 INT WINAPI ReleaseDC(
951 HWND hwnd /* [in] Handle of window - ignored */,
952 HDC hdc /* [in] Handle of device context */
960 TRACE("%04x %04x\n", hwnd, hdc );
962 while (dce && (dce->hDC != hdc)) dce = dce->next;
965 if ( dce->DCXflags & DCX_DCEBUSY )
966 nRet = DCE_ReleaseDC( dce );
973 /***********************************************************************
976 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
978 BOOL16 WINAPI DCHook16( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
982 DCE *dce = (DCE *)data;
985 TRACE("hDC = %04x, %i\n", hDC, code);
988 assert(dce->hDC == hDC);
990 /* Grab the windows lock before doing anything else */
995 case DCHC_INVALIDVISRGN:
997 /* GDI code calls this when it detects that the
998 * DC is dirty (usually after SetHookFlags()). This
999 * means that we have to recompute the visible region.
1002 if( dce->DCXflags & DCX_DCEBUSY )
1005 /* Update stale DC in DCX */
1006 wndPtr = WIN_FindWndPtr( dce->hwndCurrent);
1007 if (wndPtr) wndPtr->pDriver->pSetDrawable( wndPtr, dce->hDC, dce->DCXflags, TRUE);
1009 SetHookFlags16(hDC, DCHF_VALIDATEVISRGN);
1010 hVisRgn = DCE_GetVisRgn(dce->hwndCurrent, dce->DCXflags, 0, 0);
1012 TRACE("\tapplying saved clipRgn\n");
1014 /* clip this region with saved clipping region */
1016 if ( (dce->DCXflags & DCX_INTERSECTRGN && dce->hClipRgn != 1) ||
1017 ( dce->DCXflags & DCX_EXCLUDERGN && dce->hClipRgn) )
1020 if( (!dce->hClipRgn && dce->DCXflags & DCX_INTERSECTRGN) ||
1021 (dce->hClipRgn == 1 && dce->DCXflags & DCX_EXCLUDERGN) )
1022 SetRectRgn(hVisRgn,0,0,0,0);
1024 CombineRgn(hVisRgn, hVisRgn, dce->hClipRgn,
1025 (dce->DCXflags & DCX_EXCLUDERGN)? RGN_DIFF:RGN_AND);
1027 dce->DCXflags &= ~DCX_DCEDIRTY;
1028 DCE_OffsetVisRgn( hDC, hVisRgn );
1029 SelectVisRgn16(hDC, hVisRgn);
1030 DeleteObject( hVisRgn );
1031 WIN_ReleaseWndPtr( wndPtr ); /* Release WIN_FindWndPtr lock */
1033 else /* non-fatal but shouldn't happen */
1034 WARN("DC is not in use!\n");
1039 * Windows will not let you delete a DC that is busy
1040 * (between GetDC and ReleaseDC)
1043 if ( dce->DCXflags & DCX_DCEBUSY )
1045 WARN("Application trying to delete a busy DC\n");
1051 FIXME("unknown code\n");
1054 WIN_UnlockWnds(); /* Release the wnd lock */
1059 /**********************************************************************
1060 * WindowFromDC (USER.117)
1062 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
1064 return (HWND16)WindowFromDC( hDC );
1068 /**********************************************************************
1069 * WindowFromDC (USER32.@)
1071 HWND WINAPI WindowFromDC( HDC hDC )
1079 while (dce && (dce->hDC != hDC)) dce = dce->next;
1081 hwnd = dce ? dce->hwndCurrent : 0;
1088 /***********************************************************************
1089 * LockWindowUpdate (USER.294)
1091 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
1093 return LockWindowUpdate( hwnd );
1097 /***********************************************************************
1098 * LockWindowUpdate (USER32.@)
1100 BOOL WINAPI LockWindowUpdate( HWND hwnd )
1102 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */