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
29 #include "sysmetrics.h"
32 #include "wine/winuser16.h"
34 #define NB_DCE 5 /* Number of DCEs created at startup */
36 static DCE *firstDCE = 0;
37 static HDC32 defaultDCstate = 0;
39 static void DCE_DeleteClipRgn( DCE* );
40 static INT32 DCE_ReleaseDC( DCE* );
43 /***********************************************************************
46 static void DCE_DumpCache(void)
53 DUMP("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
54 (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags,
55 (dce->DCXflags & DCX_CACHE) ? "Cache" : "Owned",
56 (dce->DCXflags & DCX_DCEBUSY) ? "InUse" : "" );
61 /***********************************************************************
66 DCE *DCE_AllocDCE( HWND32 hWnd, DCE_TYPE type )
69 if (!(dce = HeapAlloc( SystemHeap, 0, sizeof(DCE) ))) return NULL;
70 if (!(dce->hDC = CreateDC16( "DISPLAY", NULL, NULL, NULL )))
72 HeapFree( SystemHeap, 0, dce );
76 /* store DCE handle in DC hook data field */
78 SetDCHook( dce->hDC, (FARPROC16)DCHook, (DWORD)dce );
80 dce->hwndCurrent = hWnd;
85 if( type != DCE_CACHE_DC ) /* owned or class DC */
87 dce->DCXflags = DCX_DCEBUSY;
90 WND* wnd = WIN_FindWndPtr(hWnd);
92 if( wnd->dwStyle & WS_CLIPCHILDREN ) dce->DCXflags |= DCX_CLIPCHILDREN;
93 if( wnd->dwStyle & WS_CLIPSIBLINGS ) dce->DCXflags |= DCX_CLIPSIBLINGS;
95 SetHookFlags(dce->hDC,DCHF_INVALIDATEVISRGN);
97 else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY;
103 /***********************************************************************
106 DCE* DCE_FreeDCE( DCE *dce )
108 DCE **ppDCE = &firstDCE;
110 if (!dce) return NULL;
111 while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next;
112 if (*ppDCE == dce) *ppDCE = dce->next;
114 SetDCHook(dce->hDC, NULL, 0L);
116 DeleteDC32( dce->hDC );
117 if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
118 DeleteObject32(dce->hClipRgn);
119 HeapFree( SystemHeap, 0, dce );
123 /***********************************************************************
126 * Remove owned DCE and reset unreleased cache DCEs.
128 void DCE_FreeWindowDCE( WND* pWnd )
130 DCE *pDCE = firstDCE;
134 if( pDCE->hwndCurrent == pWnd->hwndSelf )
136 if( pDCE == pWnd->dce ) /* owned DCE */
138 pDCE = DCE_FreeDCE( pDCE );
144 if(!(pDCE->DCXflags & DCX_CACHE) ) /* class DCE */
146 if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) )
147 DCE_DeleteClipRgn( pDCE );
149 else if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
151 ERR(dc,"[%04x] GetDC() without ReleaseDC()!\n",
153 DCE_ReleaseDC( pDCE );
156 pDCE->DCXflags &= DCX_CACHE;
157 pDCE->DCXflags |= DCX_DCEEMPTY;
158 pDCE->hwndCurrent = 0;
166 /***********************************************************************
169 static void DCE_DeleteClipRgn( DCE* dce )
171 dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
173 if( dce->DCXflags & DCX_KEEPCLIPRGN )
174 dce->DCXflags &= ~DCX_KEEPCLIPRGN;
176 if( dce->hClipRgn > 1 )
177 DeleteObject32( dce->hClipRgn );
181 TRACE(dc,"\trestoring VisRgn\n");
183 RestoreVisRgn(dce->hDC);
187 /***********************************************************************
190 static INT32 DCE_ReleaseDC( DCE* dce )
192 if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
194 /* restore previous visible region */
196 if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
197 (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
198 DCE_DeleteClipRgn( dce );
200 if (dce->DCXflags & DCX_CACHE)
202 SetDCState( dce->hDC, defaultDCstate );
203 dce->DCXflags &= ~DCX_DCEBUSY;
204 if (dce->DCXflags & DCX_DCEDIRTY)
206 /* don't keep around invalidated entries
207 * because SetDCState() disables hVisRgn updates
208 * by removing dirty bit. */
210 dce->hwndCurrent = 0;
211 dce->DCXflags &= DCX_CACHE;
212 dce->DCXflags |= DCX_DCEEMPTY;
219 /***********************************************************************
222 * It is called from SetWindowPos() - we have to mark as dirty all busy
223 * DCE's for windows that have pWnd->parent as an ansector and whose client
224 * rect intersects with specified update rectangle.
226 BOOL32 DCE_InvalidateDCE(WND* pWnd, const RECT32* pRectUpdate)
228 WND* wndScope = pWnd->parent;
235 TRACE(dc,"scope hwnd = %04x, (%i,%i - %i,%i)\n",
236 wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
237 pRectUpdate->right,pRectUpdate->bottom);
241 /* walk all DCEs and fixup non-empty entries */
243 for (dce = firstDCE; (dce); dce = dce->next)
245 if( !(dce->DCXflags & DCX_DCEEMPTY) )
247 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
249 if( wndCurrent && wndCurrent != WIN_GetDesktop() )
251 WND* wnd = wndCurrent;
252 INT32 xoffset = 0, yoffset = 0;
254 if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) ) continue;
256 /* check if DCE window is within the z-order scope */
258 for( wnd = wndCurrent; wnd; wnd = wnd->parent )
260 if( wnd == wndScope )
264 wndRect = wndCurrent->rectWindow;
266 OffsetRect32( &wndRect, xoffset - wndCurrent->rectClient.left,
267 yoffset - wndCurrent->rectClient.top);
269 if (pWnd == wndCurrent ||
270 IntersectRect32( &wndRect, &wndRect, pRectUpdate ))
272 if( !(dce->DCXflags & DCX_DCEBUSY) )
274 /* Don't bother with visible regions of unused DCEs */
276 TRACE(dc,"\tpurged %08x dce [%04x]\n",
277 (unsigned)dce, wndCurrent->hwndSelf);
279 dce->hwndCurrent = 0;
280 dce->DCXflags &= DCX_CACHE;
281 dce->DCXflags |= DCX_DCEEMPTY;
285 /* Set dirty bits in the hDC and DCE structs */
287 TRACE(dc,"\tfixed up %08x dce [%04x]\n",
288 (unsigned)dce, wndCurrent->hwndSelf);
290 dce->DCXflags |= DCX_DCEDIRTY;
291 SetHookFlags(dce->hDC, DCHF_INVALIDATEVISRGN);
297 xoffset += wnd->rectClient.left;
298 yoffset += wnd->rectClient.top;
307 /***********************************************************************
315 for (i = 0; i < NB_DCE; i++)
317 if (!(dce = DCE_AllocDCE( 0, DCE_CACHE_DC ))) return;
318 if (!defaultDCstate) defaultDCstate = GetDCState( dce->hDC );
323 /***********************************************************************
326 * Calculate the visible rectangle of a window (i.e. the client or
327 * window area clipped by the client area of all ancestors) in the
328 * corresponding coordinates. Return FALSE if the visible region is empty.
330 static BOOL32 DCE_GetVisRect( WND *wndPtr, BOOL32 clientArea, RECT32 *lprect )
332 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
334 if (wndPtr->dwStyle & WS_VISIBLE)
336 INT32 xoffset = lprect->left;
337 INT32 yoffset = lprect->top;
339 while (wndPtr->dwStyle & WS_CHILD)
341 wndPtr = wndPtr->parent;
343 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
346 xoffset += wndPtr->rectClient.left;
347 yoffset += wndPtr->rectClient.top;
348 OffsetRect32( lprect, wndPtr->rectClient.left,
349 wndPtr->rectClient.top );
351 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
352 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
353 (lprect->left >= wndPtr->rectClient.right) ||
354 (lprect->right <= wndPtr->rectClient.left) ||
355 (lprect->top >= wndPtr->rectClient.bottom) ||
356 (lprect->bottom <= wndPtr->rectClient.top) )
359 lprect->left = MAX( lprect->left, wndPtr->rectClient.left );
360 lprect->right = MIN( lprect->right, wndPtr->rectClient.right );
361 lprect->top = MAX( lprect->top, wndPtr->rectClient.top );
362 lprect->bottom = MIN( lprect->bottom, wndPtr->rectClient.bottom );
364 OffsetRect32( lprect, -xoffset, -yoffset );
369 SetRectEmpty32( lprect );
374 /***********************************************************************
377 * Go through the linked list of windows from pWndStart to pWndEnd,
378 * adding to the clip region the intersection of the target rectangle
379 * with an offset window rectangle.
381 static BOOL32 DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
382 HRGN32 hrgnClip, LPRECT32 lpRect, int x, int y )
386 if( pWndStart->pDriver->pIsSelfClipping( pWndStart ) )
387 return TRUE; /* The driver itself will do the clipping */
389 for (; pWndStart != pWndEnd; pWndStart = pWndStart->next)
391 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
393 rect.left = pWndStart->rectWindow.left + x;
394 rect.top = pWndStart->rectWindow.top + y;
395 rect.right = pWndStart->rectWindow.right + x;
396 rect.bottom = pWndStart->rectWindow.bottom + y;
398 if( IntersectRect32( &rect, &rect, lpRect ))
399 if(!REGION_UnionRectWithRgn( hrgnClip, &rect ))
402 return (pWndStart == pWndEnd);
406 /***********************************************************************
409 * Return the visible region of a window, i.e. the client or window area
410 * clipped by the client area of all ancestors, and then optionally
411 * by siblings and children.
413 HRGN32 DCE_GetVisRgn( HWND32 hwnd, WORD flags )
417 WND *wndPtr = WIN_FindWndPtr( hwnd );
419 /* Get visible rectangle and create a region with it. */
421 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
423 if((hrgnVis = CreateRectRgnIndirect32( &rect )))
425 HRGN32 hrgnClip = CreateRectRgn32( 0, 0, 0, 0 );
426 INT32 xoffset, yoffset;
430 /* Compute obscured region for the visible rectangle by
431 * clipping children, siblings, and ancestors. Note that
432 * DCE_GetVisRect() returns a rectangle either in client
433 * or in window coordinates (for DCX_WINDOW request). */
435 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
437 if( flags & DCX_WINDOW )
439 /* adjust offsets since child window rectangles are
440 * in client coordinates */
442 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
443 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
446 xoffset = yoffset = 0;
448 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip,
449 &rect, xoffset, yoffset );
452 /* sibling window rectangles are in client
453 * coordinates of the parent window */
455 if (flags & DCX_WINDOW)
457 xoffset = -wndPtr->rectWindow.left;
458 yoffset = -wndPtr->rectWindow.top;
462 xoffset = -wndPtr->rectClient.left;
463 yoffset = -wndPtr->rectClient.top;
466 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
467 DCE_AddClipRects( wndPtr->parent->child,
468 wndPtr, hrgnClip, &rect, xoffset, yoffset );
470 /* Clip siblings of all ancestors that have the
471 * WS_CLIPSIBLINGS style
474 while (wndPtr->dwStyle & WS_CHILD)
476 wndPtr = wndPtr->parent;
477 xoffset -= wndPtr->rectClient.left;
478 yoffset -= wndPtr->rectClient.top;
479 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
481 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
482 hrgnClip, &rect, xoffset, yoffset );
486 /* Now once we've got a jumbo clip region we have
487 * to substract it from the visible rectangle.
490 CombineRgn32( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
491 DeleteObject32( hrgnClip );
495 DeleteObject32( hrgnVis );
501 hrgnVis = CreateRectRgn32(0, 0, 0, 0); /* empty */
505 /***********************************************************************
508 * Change region from DC-origin relative coordinates to screen coords.
511 static void DCE_OffsetVisRgn( HDC32 hDC, HRGN32 hVisRgn )
514 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return;
516 OffsetRgn32( hVisRgn, dc->w.DCOrgX, dc->w.DCOrgY );
518 GDI_HEAP_UNLOCK( hDC );
521 /***********************************************************************
524 * Translate given region from the wnd client to the DC coordinates
525 * and add it to the clipping region.
527 INT16 DCE_ExcludeRgn( HDC32 hDC, WND* wnd, HRGN32 hRgn )
532 while (dce && (dce->hDC != hDC)) dce = dce->next;
535 MapWindowPoints32( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
536 if( dce->DCXflags & DCX_WINDOW )
538 wnd = WIN_FindWndPtr(dce->hwndCurrent);
539 pt.x += wnd->rectClient.left - wnd->rectWindow.left;
540 pt.y += wnd->rectClient.top - wnd->rectWindow.top;
544 OffsetRgn32(hRgn, pt.x, pt.y);
546 return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
549 /***********************************************************************
550 * GetDCEx16 (USER.359)
552 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
554 return (HDC16)GetDCEx32( hwnd, hrgnClip, flags );
558 /***********************************************************************
559 * GetDCEx32 (USER32.231)
561 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
563 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
565 HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
567 HRGN32 hrgnVisible = 0;
573 BOOL32 bUpdateVisRgn = TRUE;
574 BOOL32 bUpdateClipOrigin = FALSE;
576 TRACE(dc,"hwnd %04x, hrgnClip %04x, flags %08x\n",
577 hwnd, hrgnClip, (unsigned)flags);
579 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
583 if (!(wndPtr->class->style & (CS_OWNDC | CS_CLASSDC))) flags |= DCX_CACHE;
585 if (flags & DCX_USESTYLE)
587 flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
589 if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
590 flags |= DCX_CLIPSIBLINGS;
592 if ( !(flags & DCX_WINDOW) )
594 if (wndPtr->class->style & CS_PARENTDC) flags |= DCX_PARENTCLIP;
596 if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
597 !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
599 else flags |= DCX_CACHE;
602 if( flags & DCX_NOCLIPCHILDREN )
605 flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
608 if (flags & DCX_WINDOW)
609 flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
611 if (!(wndPtr->dwStyle & WS_CHILD) || !wndPtr->parent )
612 flags &= ~DCX_PARENTCLIP;
613 else if( flags & DCX_PARENTCLIP )
616 if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
617 if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
619 flags &= ~DCX_CLIPCHILDREN;
620 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
621 flags |= DCX_CLIPSIBLINGS;
625 /* find a suitable DCE */
627 dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
628 DCX_CACHE | DCX_WINDOW);
630 if (flags & DCX_CACHE)
635 dceEmpty = dceUnused = NULL;
637 /* Strategy: First, we attempt to find a non-empty but unused DCE with
638 * compatible flags. Next, we look for an empty entry. If the cache is
639 * full we have to purge one of the unused entries.
642 for (dce = firstDCE; (dce); dce = dce->next)
644 if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
648 if (dce->DCXflags & DCX_DCEEMPTY)
651 if ((dce->hwndCurrent == hwnd) &&
652 ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
653 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
655 TRACE(dc,"\tfound valid %08x dce [%04x], flags %08x\n",
656 (unsigned)dce, hwnd, (unsigned)dcxFlags );
657 bUpdateVisRgn = FALSE;
658 bUpdateClipOrigin = TRUE;
663 if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
667 dce = (wndPtr->class->style & CS_OWNDC) ? wndPtr->dce : wndPtr->class->dce;
668 if( dce->hwndCurrent == hwnd )
670 TRACE(dc,"\tskipping hVisRgn update\n");
671 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
673 if( (dce->DCXflags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) &&
674 (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) )
676 /* This is likely to be a nested BeginPaint(). */
678 if( dce->hClipRgn != hrgnClip )
680 FIXME(dc,"new hrgnClip[%04x] smashes the previous[%04x]\n",
681 hrgnClip, dce->hClipRgn );
682 DCE_DeleteClipRgn( dce );
685 RestoreVisRgn(dce->hDC);
691 dce->hwndCurrent = hwnd;
693 dce->DCXflags = dcxFlags | (flags & DCX_WINDOWPAINT) | DCX_DCEBUSY;
696 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
697 bUpdateVisRgn = bUpdateVisRgn || (dc->w.flags & DC_DIRTY);
699 /* recompute visible region */
701 wndPtr->pDriver->pSetDrawable( wndPtr, dc, flags, bUpdateClipOrigin );
704 TRACE(dc,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
706 if (flags & DCX_PARENTCLIP)
708 WND *parentPtr = wndPtr->parent;
710 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
712 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
713 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
715 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
717 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags );
718 if( flags & DCX_WINDOW )
719 OffsetRgn32( hrgnVisible, -wndPtr->rectWindow.left,
720 -wndPtr->rectWindow.top );
722 OffsetRgn32( hrgnVisible, -wndPtr->rectClient.left,
723 -wndPtr->rectClient.top );
724 DCE_OffsetVisRgn( hdc, hrgnVisible );
727 hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
730 if ((hwnd == GetDesktopWindow32()) &&
731 (X11DRV_WND_GetXRootWindow(wndPtr) == DefaultRootWindow(display)))
732 hrgnVisible = CreateRectRgn32( 0, 0, SYSMETRICS_CXSCREEN,
733 SYSMETRICS_CYSCREEN );
736 hrgnVisible = DCE_GetVisRgn( hwnd, flags );
737 DCE_OffsetVisRgn( hdc, hrgnVisible );
740 dc->w.flags &= ~DC_DIRTY;
741 dce->DCXflags &= ~DCX_DCEDIRTY;
742 SelectVisRgn( hdc, hrgnVisible );
745 TRACE(dc,"no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
747 /* apply additional region operation (if any) */
749 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
751 if( !hrgnVisible ) hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
753 dce->DCXflags |= flags & (DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
754 dce->hClipRgn = hrgnClip;
756 TRACE(dc, "\tsaved VisRgn, clipRgn = %04x\n", hrgnClip);
759 CombineRgn32( hrgnVisible, hrgnClip, 0, RGN_COPY );
760 DCE_OffsetVisRgn( hdc, hrgnVisible );
761 CombineRgn32( hrgnVisible, InquireVisRgn( hdc ), hrgnVisible,
762 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
763 SelectVisRgn( hdc, hrgnVisible );
766 if( hrgnVisible ) DeleteObject32( hrgnVisible );
768 TRACE(dc, "(%04x,%04x,0x%lx): returning %04x\n",
769 hwnd, hrgnClip, flags, hdc);
774 /***********************************************************************
777 HDC16 WINAPI GetDC16( HWND16 hwnd )
779 return (HDC16)GetDC32( hwnd );
783 /***********************************************************************
784 * GetDC32 (USER32.230)
789 HDC32 WINAPI GetDC32(
790 HWND32 hwnd /* handle of window */
793 return GetDCEx32( GetDesktopWindow32(), 0, DCX_CACHE | DCX_WINDOW );
794 return GetDCEx32( hwnd, 0, DCX_USESTYLE );
798 /***********************************************************************
799 * GetWindowDC16 (USER.67)
801 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
803 if (!hwnd) hwnd = GetDesktopWindow16();
804 return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
808 /***********************************************************************
809 * GetWindowDC32 (USER32.304)
811 HDC32 WINAPI GetWindowDC32( HWND32 hwnd )
813 if (!hwnd) hwnd = GetDesktopWindow32();
814 return GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
818 /***********************************************************************
819 * ReleaseDC16 (USER.68)
821 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
823 return (INT16)ReleaseDC32( hwnd, hdc );
827 /***********************************************************************
828 * ReleaseDC32 (USER32.440)
834 INT32 WINAPI ReleaseDC32(
835 HWND32 hwnd /* Handle of window - ignored */,
836 HDC32 hdc /* Handle of device context */
838 DCE * dce = firstDCE;
840 TRACE(dc, "%04x %04x\n", hwnd, hdc );
842 while (dce && (dce->hDC != hdc)) dce = dce->next;
845 if ( dce->DCXflags & DCX_DCEBUSY )
846 return DCE_ReleaseDC( dce );
850 /***********************************************************************
853 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
855 BOOL16 WINAPI DCHook( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
858 DCE *dce = firstDCE;;
860 TRACE(dc,"hDC = %04x, %i\n", hDC, code);
862 while (dce && (dce->hDC != hDC)) dce = dce->next;
867 case DCHC_INVALIDVISRGN:
869 /* GDI code calls this when it detects that the
870 * DC is dirty (usually after SetHookFlags()). This
871 * means that we have to recompute the visible region.
874 if( dce->DCXflags & DCX_DCEBUSY )
876 SetHookFlags(hDC, DCHF_VALIDATEVISRGN);
877 hVisRgn = DCE_GetVisRgn(dce->hwndCurrent, dce->DCXflags);
879 TRACE(dc,"\tapplying saved clipRgn\n");
881 /* clip this region with saved clipping region */
883 if ( (dce->DCXflags & DCX_INTERSECTRGN && dce->hClipRgn != 1) ||
884 ( dce->DCXflags & DCX_EXCLUDERGN && dce->hClipRgn) )
887 if( (!dce->hClipRgn && dce->DCXflags & DCX_INTERSECTRGN) ||
888 (dce->hClipRgn == 1 && dce->DCXflags & DCX_EXCLUDERGN) )
889 SetRectRgn32(hVisRgn,0,0,0,0);
891 CombineRgn32(hVisRgn, hVisRgn, dce->hClipRgn,
892 (dce->DCXflags & DCX_EXCLUDERGN)? RGN_DIFF:RGN_AND);
894 dce->DCXflags &= ~DCX_DCEDIRTY;
895 DCE_OffsetVisRgn( hDC, hVisRgn );
896 SelectVisRgn(hDC, hVisRgn);
897 DeleteObject32( hVisRgn );
899 else /* non-fatal but shouldn't happen */
900 WARN(dc, "DC is not in use!\n");
903 case DCHC_DELETEDC: /* FIXME: ?? */
907 FIXME(dc,"unknown code\n");
913 /**********************************************************************
914 * WindowFromDC16 (USER.117)
916 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
918 return (HWND16)WindowFromDC32( hDC );
922 /**********************************************************************
923 * WindowFromDC32 (USER32.581)
925 HWND32 WINAPI WindowFromDC32( HDC32 hDC )
928 while (dce && (dce->hDC != hDC)) dce = dce->next;
929 return dce ? dce->hwndCurrent : 0;
933 /***********************************************************************
934 * LockWindowUpdate16 (USER.294)
936 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
938 return LockWindowUpdate32( hwnd );
942 /***********************************************************************
943 * LockWindowUpdate32 (USER32.378)
945 BOOL32 WINAPI LockWindowUpdate32( HWND32 hwnd )
947 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */