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 = CreateDC16( "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 ERR("[%04x] GetDC() without ReleaseDC()!\n",
183 DCE_ReleaseDC( pDCE );
186 pDCE->DCXflags &= DCX_CACHE;
187 pDCE->DCXflags |= DCX_DCEEMPTY;
188 pDCE->hwndCurrent = 0;
198 /***********************************************************************
201 static void DCE_DeleteClipRgn( DCE* dce )
203 dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
205 if( dce->DCXflags & DCX_KEEPCLIPRGN )
206 dce->DCXflags &= ~DCX_KEEPCLIPRGN;
208 if( dce->hClipRgn > 1 )
209 DeleteObject( dce->hClipRgn );
213 TRACE("\trestoring VisRgn\n");
215 RestoreVisRgn16(dce->hDC);
219 /***********************************************************************
222 static INT DCE_ReleaseDC( DCE* dce )
224 if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
226 /* restore previous visible region */
228 if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
229 (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
230 DCE_DeleteClipRgn( dce );
232 if (dce->DCXflags & DCX_CACHE)
234 SetDCState16( dce->hDC, defaultDCstate );
235 dce->DCXflags &= ~DCX_DCEBUSY;
236 if (dce->DCXflags & DCX_DCEDIRTY)
238 /* don't keep around invalidated entries
239 * because SetDCState() disables hVisRgn updates
240 * by removing dirty bit. */
242 dce->hwndCurrent = 0;
243 dce->DCXflags &= DCX_CACHE;
244 dce->DCXflags |= DCX_DCEEMPTY;
251 /***********************************************************************
254 * It is called from SetWindowPos() and EVENT_MapNotify - we have to
255 * mark as dirty all busy DCEs for windows that have pWnd->parent as
256 * an ansector and whose client rect intersects with specified update
257 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
258 * DCX_CLIPCHILDREN flag is set. */
259 BOOL DCE_InvalidateDCE(WND* pWnd, const RECT* pRectUpdate)
261 WND* wndScope = WIN_LockWndPtr(pWnd->parent);
262 WND *pDesktop = WIN_GetDesktop();
269 TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
270 wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
271 pRectUpdate->right,pRectUpdate->bottom);
275 /* walk all DCEs and fixup non-empty entries */
277 for (dce = firstDCE; (dce); dce = dce->next)
279 if( !(dce->DCXflags & DCX_DCEEMPTY) )
281 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
286 INT xoffset = 0, yoffset = 0;
288 if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) )
290 /* child window positions don't bother us */
291 WIN_ReleaseWndPtr(wndCurrent);
295 if( !Options.desktopGeometry && wndCurrent == pDesktop )
297 /* don't bother with fake desktop */
298 WIN_ReleaseWndPtr(wndCurrent);
302 /* check if DCE window is within the z-order scope */
304 for( wnd = WIN_LockWndPtr(wndCurrent); wnd; WIN_UpdateWndPtr(&wnd,wnd->parent))
306 if( wnd == wndScope )
310 wndRect = wndCurrent->rectWindow;
312 OffsetRect( &wndRect, xoffset - wndCurrent->rectClient.left,
313 yoffset - wndCurrent->rectClient.top);
315 if (pWnd == wndCurrent ||
316 IntersectRect( &wndRect, &wndRect, pRectUpdate ))
318 if( !(dce->DCXflags & DCX_DCEBUSY) )
320 /* Don't bother with visible regions of unused DCEs */
322 TRACE("\tpurged %08x dce [%04x]\n",
323 (unsigned)dce, wndCurrent->hwndSelf);
325 dce->hwndCurrent = 0;
326 dce->DCXflags &= DCX_CACHE;
327 dce->DCXflags |= DCX_DCEEMPTY;
331 /* Set dirty bits in the hDC and DCE structs */
333 TRACE("\tfixed up %08x dce [%04x]\n",
334 (unsigned)dce, wndCurrent->hwndSelf);
336 dce->DCXflags |= DCX_DCEDIRTY;
337 SetHookFlags16(dce->hDC, DCHF_INVALIDATEVISRGN);
341 WIN_ReleaseWndPtr(wnd);
344 xoffset += wnd->rectClient.left;
345 yoffset += wnd->rectClient.top;
348 WIN_ReleaseWndPtr(wndCurrent);
351 WIN_ReleaseWndPtr(wndScope);
353 WIN_ReleaseDesktop();
357 /***********************************************************************
365 for (i = 0; i < NB_DCE; i++)
367 if (!(dce = DCE_AllocDCE( 0, DCE_CACHE_DC ))) return;
368 if (!defaultDCstate) defaultDCstate = GetDCState16( dce->hDC );
373 /***********************************************************************
376 * Calculate the visible rectangle of a window (i.e. the client or
377 * window area clipped by the client area of all ancestors) in the
378 * corresponding coordinates. Return FALSE if the visible region is empty.
380 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
382 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
384 if (wndPtr->dwStyle & WS_VISIBLE)
386 INT xoffset = lprect->left;
387 INT yoffset = lprect->top;
389 while( !(wndPtr->flags & WIN_NATIVE) &&
390 ( wndPtr = WIN_LockWndPtr(wndPtr->parent)) )
392 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
394 WIN_ReleaseWndPtr(wndPtr);
398 xoffset += wndPtr->rectClient.left;
399 yoffset += wndPtr->rectClient.top;
400 OffsetRect( lprect, wndPtr->rectClient.left,
401 wndPtr->rectClient.top );
403 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
404 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
405 (lprect->left >= wndPtr->rectClient.right) ||
406 (lprect->right <= wndPtr->rectClient.left) ||
407 (lprect->top >= wndPtr->rectClient.bottom) ||
408 (lprect->bottom <= wndPtr->rectClient.top) )
410 WIN_ReleaseWndPtr(wndPtr);
414 lprect->left = max( lprect->left, wndPtr->rectClient.left );
415 lprect->right = min( lprect->right, wndPtr->rectClient.right );
416 lprect->top = max( lprect->top, wndPtr->rectClient.top );
417 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
419 WIN_ReleaseWndPtr(wndPtr);
421 OffsetRect( lprect, -xoffset, -yoffset );
426 SetRectEmpty( lprect );
431 /***********************************************************************
434 * Go through the linked list of windows from pWndStart to pWndEnd,
435 * adding to the clip region the intersection of the target rectangle
436 * with an offset window rectangle.
438 static BOOL DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
439 HRGN hrgnClip, LPRECT lpRect, int x, int y )
443 if( pWndStart->pDriver->pIsSelfClipping( pWndStart ) )
444 return TRUE; /* The driver itself will do the clipping */
446 for (WIN_LockWndPtr(pWndStart); pWndStart != pWndEnd; WIN_UpdateWndPtr(&pWndStart,pWndStart->next))
448 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
450 rect.left = pWndStart->rectWindow.left + x;
451 rect.top = pWndStart->rectWindow.top + y;
452 rect.right = pWndStart->rectWindow.right + x;
453 rect.bottom = pWndStart->rectWindow.bottom + y;
455 if( IntersectRect( &rect, &rect, lpRect ))
457 if(!REGION_UnionRectWithRgn( hrgnClip, &rect )) break;
460 WIN_ReleaseWndPtr(pWndStart);
461 return (pWndStart == pWndEnd);
465 /***********************************************************************
468 * Return the visible region of a window, i.e. the client or window area
469 * clipped by the client area of all ancestors, and then optionally
470 * by siblings and children.
472 HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
476 WND *wndPtr = WIN_FindWndPtr( hwnd );
477 WND *childWnd = WIN_FindWndPtr( hwndChild );
479 /* Get visible rectangle and create a region with it. */
481 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
483 if((hrgnVis = CreateRectRgnIndirect( &rect )))
485 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
486 INT xoffset, yoffset;
490 /* Compute obscured region for the visible rectangle by
491 * clipping children, siblings, and ancestors. Note that
492 * DCE_GetVisRect() returns a rectangle either in client
493 * or in window coordinates (for DCX_WINDOW request). */
495 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
497 if( flags & DCX_WINDOW )
499 /* adjust offsets since child window rectangles are
500 * in client coordinates */
502 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
503 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
506 xoffset = yoffset = 0;
508 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip,
509 &rect, xoffset, yoffset );
512 /* We may need to clip children of child window, if a window with PARENTDC
513 * class style and CLIPCHILDREN window style (like in Free Agent 16
514 * preference dialogs) gets here, we take the region for the parent window
515 * but apparently still need to clip the children of the child window... */
517 if( (cflags & DCX_CLIPCHILDREN) && childWnd && childWnd->child )
519 if( flags & DCX_WINDOW )
521 /* adjust offsets since child window rectangles are
522 * in client coordinates */
524 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
525 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
528 xoffset = yoffset = 0;
530 /* client coordinates of child window */
531 xoffset += childWnd->rectClient.left;
532 yoffset += childWnd->rectClient.top;
534 DCE_AddClipRects( childWnd->child, NULL, hrgnClip,
535 &rect, xoffset, yoffset );
538 /* sibling window rectangles are in client
539 * coordinates of the parent window */
541 if (flags & DCX_WINDOW)
543 xoffset = -wndPtr->rectWindow.left;
544 yoffset = -wndPtr->rectWindow.top;
548 xoffset = -wndPtr->rectClient.left;
549 yoffset = -wndPtr->rectClient.top;
552 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
553 DCE_AddClipRects( wndPtr->parent->child,
554 wndPtr, hrgnClip, &rect, xoffset, yoffset );
556 /* Clip siblings of all ancestors that have the
557 * WS_CLIPSIBLINGS style
560 while (wndPtr->dwStyle & WS_CHILD)
562 WIN_UpdateWndPtr(&wndPtr,wndPtr->parent);
563 xoffset -= wndPtr->rectClient.left;
564 yoffset -= wndPtr->rectClient.top;
565 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
567 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
568 hrgnClip, &rect, xoffset, yoffset );
572 /* Now once we've got a jumbo clip region we have
573 * to substract it from the visible rectangle.
576 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
577 DeleteObject( hrgnClip );
581 DeleteObject( hrgnVis );
587 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
588 WIN_ReleaseWndPtr(wndPtr);
589 WIN_ReleaseWndPtr(childWnd);
593 /***********************************************************************
596 * Change region from DC-origin relative coordinates to screen coords.
599 static void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn )
602 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return;
604 OffsetRgn( hVisRgn, dc->w.DCOrgX, dc->w.DCOrgY );
606 GDI_HEAP_UNLOCK( hDC );
609 /***********************************************************************
612 * Translate given region from the wnd client to the DC coordinates
613 * and add it to the clipping region.
615 INT16 DCE_ExcludeRgn( HDC hDC, WND* wnd, HRGN hRgn )
620 while (dce && (dce->hDC != hDC)) dce = dce->next;
623 MapWindowPoints( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
624 if( dce->DCXflags & DCX_WINDOW )
626 wnd = WIN_FindWndPtr(dce->hwndCurrent);
627 pt.x += wnd->rectClient.left - wnd->rectWindow.left;
628 pt.y += wnd->rectClient.top - wnd->rectWindow.top;
629 WIN_ReleaseWndPtr(wnd);
633 OffsetRgn(hRgn, pt.x, pt.y);
635 return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
639 /***********************************************************************
640 * GetDCEx16 (USER.359)
642 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
644 return (HDC16)GetDCEx( hwnd, hrgnClip, flags );
648 /***********************************************************************
649 * GetDCEx (USER32.231)
651 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
653 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
655 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
657 HRGN hrgnVisible = 0;
663 BOOL bUpdateVisRgn = TRUE;
664 BOOL bUpdateClipOrigin = FALSE;
666 TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n",
667 hwnd, hrgnClip, (unsigned)flags);
669 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
673 if (!(wndPtr->class->style & (CS_OWNDC | CS_CLASSDC))) flags |= DCX_CACHE;
675 if (flags & DCX_USESTYLE)
677 flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
679 if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
680 flags |= DCX_CLIPSIBLINGS;
682 if ( !(flags & DCX_WINDOW) )
684 if (wndPtr->class->style & CS_PARENTDC) flags |= DCX_PARENTCLIP;
686 if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
687 !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
689 else flags |= DCX_CACHE;
692 if( flags & DCX_NOCLIPCHILDREN )
695 flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
698 if (flags & DCX_WINDOW)
699 flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
701 if (!(wndPtr->dwStyle & WS_CHILD) || !wndPtr->parent )
702 flags &= ~DCX_PARENTCLIP;
703 else if( flags & DCX_PARENTCLIP )
706 if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
707 if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
709 flags &= ~DCX_CLIPCHILDREN;
710 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
711 flags |= DCX_CLIPSIBLINGS;
715 /* find a suitable DCE */
717 dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
718 DCX_CACHE | DCX_WINDOW);
720 if (flags & DCX_CACHE)
725 dceEmpty = dceUnused = NULL;
727 /* Strategy: First, we attempt to find a non-empty but unused DCE with
728 * compatible flags. Next, we look for an empty entry. If the cache is
729 * full we have to purge one of the unused entries.
732 for (dce = firstDCE; (dce); dce = dce->next)
734 if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
738 if (dce->DCXflags & DCX_DCEEMPTY)
741 if ((dce->hwndCurrent == hwnd) &&
742 ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
743 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
745 TRACE("\tfound valid %08x dce [%04x], flags %08x\n",
746 (unsigned)dce, hwnd, (unsigned)dcxFlags );
747 bUpdateVisRgn = FALSE;
748 bUpdateClipOrigin = TRUE;
754 if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
756 /* if there's no dce empty or unused, allocate a new one */
759 dce = DCE_AllocDCE( 0, DCE_CACHE_DC );
764 dce = (wndPtr->class->style & CS_OWNDC) ? wndPtr->dce : wndPtr->class->dce;
765 if( dce->hwndCurrent == hwnd )
767 TRACE("\tskipping hVisRgn update\n");
768 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
770 /* Abey - 16Jul99. to take care of the nested GetDC. first one
771 with DCX_EXCLUDERGN or DCX_INTERSECTRGN flags and the next
772 one with or without these flags. */
774 if(dce->DCXflags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
776 /* This is likely to be a nested BeginPaint().
777 or a BeginPaint() followed by a GetDC()*/
779 if( dce->hClipRgn != hrgnClip )
781 FIXME("new hrgnClip[%04x] smashes the previous[%04x]\n",
782 hrgnClip, dce->hClipRgn );
783 DCE_DeleteClipRgn( dce );
786 RestoreVisRgn16(dce->hDC);
796 dce->hwndCurrent = hwnd;
798 dce->DCXflags = dcxFlags | (flags & DCX_WINDOWPAINT) | DCX_DCEBUSY;
801 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )))
806 bUpdateVisRgn = bUpdateVisRgn || (dc->w.flags & DC_DIRTY);
808 /* recompute visible region */
809 wndPtr->pDriver->pSetDrawable( wndPtr, dc, flags, bUpdateClipOrigin );
813 TRACE("updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
815 if (flags & DCX_PARENTCLIP)
817 WND *parentPtr = WIN_LockWndPtr(wndPtr->parent);
819 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
821 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
822 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
824 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
826 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
827 wndPtr->hwndSelf, flags );
828 if( flags & DCX_WINDOW )
829 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
830 -wndPtr->rectWindow.top );
832 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
833 -wndPtr->rectClient.top );
834 DCE_OffsetVisRgn( hdc, hrgnVisible );
837 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
838 WIN_ReleaseWndPtr(parentPtr);
841 if ((hwnd == GetDesktopWindow()) && !USER_Driver->pIsSingleWindow())
842 hrgnVisible = CreateRectRgn( 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) );
845 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
846 DCE_OffsetVisRgn( hdc, hrgnVisible );
849 dc->w.flags &= ~DC_DIRTY;
850 dce->DCXflags &= ~DCX_DCEDIRTY;
851 SelectVisRgn16( hdc, hrgnVisible );
854 TRACE("no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
856 /* apply additional region operation (if any) */
858 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
860 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
862 dce->DCXflags |= flags & (DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
863 dce->hClipRgn = hrgnClip;
865 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgnClip);
868 CombineRgn( hrgnVisible, hrgnClip, 0, RGN_COPY );
869 DCE_OffsetVisRgn( hdc, hrgnVisible );
870 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
871 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
872 SelectVisRgn16( hdc, hrgnVisible );
875 if( hrgnVisible ) DeleteObject( hrgnVisible );
877 TRACE("(%04x,%04x,0x%lx): returning %04x\n",
878 hwnd, hrgnClip, flags, hdc);
880 WIN_ReleaseWndPtr(wndPtr);
885 /***********************************************************************
888 HDC16 WINAPI GetDC16( HWND16 hwnd )
890 return (HDC16)GetDC( hwnd );
894 /***********************************************************************
901 HWND hwnd /* handle of window */
904 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE | DCX_WINDOW );
905 return GetDCEx( hwnd, 0, DCX_USESTYLE );
909 /***********************************************************************
910 * GetWindowDC16 (USER.67)
912 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
914 if (!hwnd) hwnd = GetDesktopWindow16();
915 return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
919 /***********************************************************************
920 * GetWindowDC (USER32.304)
922 HDC WINAPI GetWindowDC( HWND hwnd )
924 if (!hwnd) hwnd = GetDesktopWindow();
925 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
929 /***********************************************************************
930 * ReleaseDC16 (USER.68)
932 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
934 return (INT16)ReleaseDC( hwnd, hdc );
938 /***********************************************************************
939 * ReleaseDC (USER32.440)
945 INT WINAPI ReleaseDC(
946 HWND hwnd /* Handle of window - ignored */,
947 HDC hdc /* Handle of device context */
955 TRACE("%04x %04x\n", hwnd, hdc );
957 while (dce && (dce->hDC != hdc)) dce = dce->next;
960 if ( dce->DCXflags & DCX_DCEBUSY )
961 nRet = DCE_ReleaseDC( dce );
968 /***********************************************************************
971 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
973 BOOL16 WINAPI DCHook16( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
977 DCE *dce = (DCE *)data;
981 TRACE("hDC = %04x, %i\n", hDC, code);
984 assert(dce->hDC == hDC);
986 /* Grab the windows lock before doing anything else */
991 case DCHC_INVALIDVISRGN:
993 /* GDI code calls this when it detects that the
994 * DC is dirty (usually after SetHookFlags()). This
995 * means that we have to recompute the visible region.
998 if( dce->DCXflags & DCX_DCEBUSY )
1001 /* Update stale DC in DCX */
1002 wndPtr = WIN_FindWndPtr( dce->hwndCurrent);
1003 dc = (DC *) GDI_GetObjPtr( dce->hDC, DC_MAGIC);
1005 wndPtr->pDriver->pSetDrawable( wndPtr, dc,dce->DCXflags,TRUE);
1007 SetHookFlags16(hDC, DCHF_VALIDATEVISRGN);
1008 hVisRgn = DCE_GetVisRgn(dce->hwndCurrent, dce->DCXflags, 0, 0);
1010 TRACE("\tapplying saved clipRgn\n");
1012 /* clip this region with saved clipping region */
1014 if ( (dce->DCXflags & DCX_INTERSECTRGN && dce->hClipRgn != 1) ||
1015 ( dce->DCXflags & DCX_EXCLUDERGN && dce->hClipRgn) )
1018 if( (!dce->hClipRgn && dce->DCXflags & DCX_INTERSECTRGN) ||
1019 (dce->hClipRgn == 1 && dce->DCXflags & DCX_EXCLUDERGN) )
1020 SetRectRgn(hVisRgn,0,0,0,0);
1022 CombineRgn(hVisRgn, hVisRgn, dce->hClipRgn,
1023 (dce->DCXflags & DCX_EXCLUDERGN)? RGN_DIFF:RGN_AND);
1025 dce->DCXflags &= ~DCX_DCEDIRTY;
1026 DCE_OffsetVisRgn( hDC, hVisRgn );
1027 SelectVisRgn16(hDC, hVisRgn);
1028 DeleteObject( hVisRgn );
1029 WIN_ReleaseWndPtr( wndPtr ); /* Release WIN_FindWndPtr lock */
1031 else /* non-fatal but shouldn't happen */
1032 WARN("DC is not in use!\n");
1037 * Windows will not let you delete a DC that is busy
1038 * (between GetDC and ReleaseDC)
1041 if ( dce->DCXflags & DCX_DCEBUSY )
1043 WARN("Application trying to delete a busy DC\n");
1049 FIXME("unknown code\n");
1052 WIN_UnlockWnds(); /* Release the wnd lock */
1057 /**********************************************************************
1058 * WindowFromDC16 (USER.117)
1060 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
1062 return (HWND16)WindowFromDC( hDC );
1066 /**********************************************************************
1067 * WindowFromDC (USER32.581)
1069 HWND WINAPI WindowFromDC( HDC hDC )
1077 while (dce && (dce->hDC != hDC)) dce = dce->next;
1079 hwnd = dce ? dce->hwndCurrent : 0;
1086 /***********************************************************************
1087 * LockWindowUpdate16 (USER.294)
1089 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
1091 return LockWindowUpdate( hwnd );
1095 /***********************************************************************
1096 * LockWindowUpdate (USER32.378)
1098 BOOL WINAPI LockWindowUpdate( HWND hwnd )
1100 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */