Rewrite of configuration system to support "regular" curses as well as
[wine/multimedia.git] / windows / dce.c
blobdb0f19af7df4622dccd05a85b719f0a857198e8e
1 /*
2 * USER DCE functions
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.
11 * Internal DCX flags:
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
20 #include "options.h"
21 #include "dce.h"
22 #include "class.h"
23 #include "win.h"
24 #include "gdi.h"
25 #include "region.h"
26 #include "heap.h"
27 #include "sysmetrics.h"
28 #include "debug.h"
29 #include "wine/winuser16.h"
31 #define NB_DCE 5 /* Number of DCEs created at startup */
33 static DCE *firstDCE = 0;
34 static HDC32 defaultDCstate = 0;
36 static void DCE_DeleteClipRgn( DCE* );
37 static INT32 DCE_ReleaseDC( DCE* );
40 /***********************************************************************
41 * DCE_DumpCache
43 static void DCE_DumpCache(void)
45 DCE* dce = firstDCE;
47 DUMP("DCE:\n");
48 while( dce )
50 DUMP("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
51 (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags,
52 (dce->DCXflags & DCX_CACHE) ? "Cache" : "Owned",
53 (dce->DCXflags & DCX_DCEBUSY) ? "InUse" : "" );
54 dce = dce->next;
58 /***********************************************************************
59 * DCE_AllocDCE
61 * Allocate a new DCE.
63 DCE *DCE_AllocDCE( HWND32 hWnd, DCE_TYPE type )
65 DCE * dce;
66 if (!(dce = HeapAlloc( SystemHeap, 0, sizeof(DCE) ))) return NULL;
67 if (!(dce->hDC = CreateDC16( "DISPLAY", NULL, NULL, NULL )))
69 HeapFree( SystemHeap, 0, dce );
70 return 0;
73 /* store DCE handle in DC hook data field */
75 SetDCHook( dce->hDC, (FARPROC16)DCHook, (DWORD)dce );
77 dce->hwndCurrent = hWnd;
78 dce->hClipRgn = 0;
79 dce->next = firstDCE;
80 firstDCE = dce;
82 if( type != DCE_CACHE_DC ) /* owned or class DC */
84 dce->DCXflags = DCX_DCEBUSY;
85 if( hWnd )
87 WND* wnd = WIN_FindWndPtr(hWnd);
89 if( wnd->dwStyle & WS_CLIPCHILDREN ) dce->DCXflags |= DCX_CLIPCHILDREN;
90 if( wnd->dwStyle & WS_CLIPSIBLINGS ) dce->DCXflags |= DCX_CLIPSIBLINGS;
92 SetHookFlags(dce->hDC,DCHF_INVALIDATEVISRGN);
94 else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY;
96 return dce;
100 /***********************************************************************
101 * DCE_FreeDCE
103 DCE* DCE_FreeDCE( DCE *dce )
105 DCE **ppDCE = &firstDCE;
107 if (!dce) return NULL;
108 while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next;
109 if (*ppDCE == dce) *ppDCE = dce->next;
111 SetDCHook(dce->hDC, NULL, 0L);
113 DeleteDC32( dce->hDC );
114 if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
115 DeleteObject32(dce->hClipRgn);
116 HeapFree( SystemHeap, 0, dce );
117 return *ppDCE;
120 /***********************************************************************
121 * DCE_FreeWindowDCE
123 * Remove owned DCE and reset unreleased cache DCEs.
125 void DCE_FreeWindowDCE( WND* pWnd )
127 DCE *pDCE = firstDCE;
129 while( pDCE )
131 if( pDCE->hwndCurrent == pWnd->hwndSelf )
133 if( pDCE == pWnd->dce ) /* owned DCE */
135 pDCE = DCE_FreeDCE( pDCE );
136 pWnd->dce = NULL;
137 continue;
139 else
141 if(!(pDCE->DCXflags & DCX_CACHE) ) /* class DCE */
143 if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) )
144 DCE_DeleteClipRgn( pDCE );
146 else if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
148 ERR(dc,"[%04x] GetDC() without ReleaseDC()!\n",
149 pWnd->hwndSelf);
150 DCE_ReleaseDC( pDCE );
153 pDCE->DCXflags &= DCX_CACHE;
154 pDCE->DCXflags |= DCX_DCEEMPTY;
155 pDCE->hwndCurrent = 0;
158 pDCE = pDCE->next;
163 /***********************************************************************
164 * DCE_DeleteClipRgn
166 static void DCE_DeleteClipRgn( DCE* dce )
168 dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
170 if( dce->DCXflags & DCX_KEEPCLIPRGN )
171 dce->DCXflags &= ~DCX_KEEPCLIPRGN;
172 else
173 if( dce->hClipRgn > 1 )
174 DeleteObject32( dce->hClipRgn );
176 dce->hClipRgn = 0;
178 TRACE(dc,"\trestoring VisRgn\n");
180 RestoreVisRgn(dce->hDC);
184 /***********************************************************************
185 * DCE_ReleaseDC
187 static INT32 DCE_ReleaseDC( DCE* dce )
189 if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
191 /* restore previous visible region */
193 if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
194 (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
195 DCE_DeleteClipRgn( dce );
197 if (dce->DCXflags & DCX_CACHE)
199 SetDCState( dce->hDC, defaultDCstate );
200 dce->DCXflags &= ~DCX_DCEBUSY;
201 if (dce->DCXflags & DCX_DCEDIRTY)
203 /* don't keep around invalidated entries
204 * because SetDCState() disables hVisRgn updates
205 * by removing dirty bit. */
207 dce->hwndCurrent = 0;
208 dce->DCXflags &= DCX_CACHE;
209 dce->DCXflags |= DCX_DCEEMPTY;
212 return 1;
216 /***********************************************************************
217 * DCE_InvalidateDCE
219 * It is called from SetWindowPos() - we have to mark as dirty all busy
220 * DCE's for windows that have pWnd->parent as an ansector and whose client
221 * rect intersects with specified update rectangle.
223 BOOL32 DCE_InvalidateDCE(WND* pWnd, const RECT32* pRectUpdate)
225 WND* wndScope = pWnd->parent;
226 BOOL32 bRet = FALSE;
228 if( wndScope )
230 DCE *dce;
232 TRACE(dc,"scope hwnd = %04x, (%i,%i - %i,%i)\n",
233 wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
234 pRectUpdate->right,pRectUpdate->bottom);
235 if(TRACE_ON(dc))
236 DCE_DumpCache();
238 /* walk all DCEs and fixup non-empty entries */
240 for (dce = firstDCE; (dce); dce = dce->next)
242 if( !(dce->DCXflags & DCX_DCEEMPTY) )
244 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
246 if( wndCurrent && wndCurrent != WIN_GetDesktop() )
248 WND* wnd = wndCurrent;
249 INT32 xoffset = 0, yoffset = 0;
251 if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) ) continue;
253 /* check if DCE window is within the z-order scope */
255 for( wnd = wndCurrent; wnd; wnd = wnd->parent )
257 if( wnd == wndScope )
259 RECT32 wndRect;
261 wndRect = wndCurrent->rectWindow;
263 OffsetRect32( &wndRect, xoffset - wndCurrent->rectClient.left,
264 yoffset - wndCurrent->rectClient.top);
266 if (pWnd == wndCurrent ||
267 IntersectRect32( &wndRect, &wndRect, pRectUpdate ))
269 if( !(dce->DCXflags & DCX_DCEBUSY) )
271 /* Don't bother with visible regions of unused DCEs */
273 TRACE(dc,"\tpurged %08x dce [%04x]\n",
274 (unsigned)dce, wndCurrent->hwndSelf);
276 dce->hwndCurrent = 0;
277 dce->DCXflags &= DCX_CACHE;
278 dce->DCXflags |= DCX_DCEEMPTY;
280 else
282 /* Set dirty bits in the hDC and DCE structs */
284 TRACE(dc,"\tfixed up %08x dce [%04x]\n",
285 (unsigned)dce, wndCurrent->hwndSelf);
287 dce->DCXflags |= DCX_DCEDIRTY;
288 SetHookFlags(dce->hDC, DCHF_INVALIDATEVISRGN);
289 bRet = TRUE;
292 break;
294 xoffset += wnd->rectClient.left;
295 yoffset += wnd->rectClient.top;
299 } /* dce list */
301 return bRet;
304 /***********************************************************************
305 * DCE_Init
307 void DCE_Init(void)
309 int i;
310 DCE * dce;
312 for (i = 0; i < NB_DCE; i++)
314 if (!(dce = DCE_AllocDCE( 0, DCE_CACHE_DC ))) return;
315 if (!defaultDCstate) defaultDCstate = GetDCState( dce->hDC );
320 /***********************************************************************
321 * DCE_GetVisRect
323 * Calculate the visible rectangle of a window (i.e. the client or
324 * window area clipped by the client area of all ancestors) in the
325 * corresponding coordinates. Return FALSE if the visible region is empty.
327 static BOOL32 DCE_GetVisRect( WND *wndPtr, BOOL32 clientArea, RECT32 *lprect )
329 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
331 if (wndPtr->dwStyle & WS_VISIBLE)
333 INT32 xoffset = lprect->left;
334 INT32 yoffset = lprect->top;
336 while (wndPtr->dwStyle & WS_CHILD)
338 wndPtr = wndPtr->parent;
340 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
341 goto fail;
343 xoffset += wndPtr->rectClient.left;
344 yoffset += wndPtr->rectClient.top;
345 OffsetRect32( lprect, wndPtr->rectClient.left,
346 wndPtr->rectClient.top );
348 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
349 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
350 (lprect->left >= wndPtr->rectClient.right) ||
351 (lprect->right <= wndPtr->rectClient.left) ||
352 (lprect->top >= wndPtr->rectClient.bottom) ||
353 (lprect->bottom <= wndPtr->rectClient.top) )
354 goto fail;
356 lprect->left = MAX( lprect->left, wndPtr->rectClient.left );
357 lprect->right = MIN( lprect->right, wndPtr->rectClient.right );
358 lprect->top = MAX( lprect->top, wndPtr->rectClient.top );
359 lprect->bottom = MIN( lprect->bottom, wndPtr->rectClient.bottom );
361 OffsetRect32( lprect, -xoffset, -yoffset );
362 return TRUE;
365 fail:
366 SetRectEmpty32( lprect );
367 return FALSE;
371 /***********************************************************************
372 * DCE_AddClipRects
374 * Go through the linked list of windows from pWndStart to pWndEnd,
375 * adding to the clip region the intersection of the target rectangle
376 * with an offset window rectangle.
378 static BOOL32 DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
379 HRGN32 hrgnClip, LPRECT32 lpRect, int x, int y )
381 RECT32 rect;
383 if( pWndStart->pDriver->pIsSelfClipping( pWndStart ) )
384 return TRUE; /* The driver itself will do the clipping */
386 for (; pWndStart != pWndEnd; pWndStart = pWndStart->next)
388 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
390 rect.left = pWndStart->rectWindow.left + x;
391 rect.top = pWndStart->rectWindow.top + y;
392 rect.right = pWndStart->rectWindow.right + x;
393 rect.bottom = pWndStart->rectWindow.bottom + y;
395 if( IntersectRect32( &rect, &rect, lpRect ))
396 if(!REGION_UnionRectWithRgn( hrgnClip, &rect ))
397 break;
399 return (pWndStart == pWndEnd);
403 /***********************************************************************
404 * DCE_GetVisRgn
406 * Return the visible region of a window, i.e. the client or window area
407 * clipped by the client area of all ancestors, and then optionally
408 * by siblings and children.
410 HRGN32 DCE_GetVisRgn( HWND32 hwnd, WORD flags )
412 HRGN32 hrgnVis = 0;
413 RECT32 rect;
414 WND *wndPtr = WIN_FindWndPtr( hwnd );
416 /* Get visible rectangle and create a region with it. */
418 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
420 if((hrgnVis = CreateRectRgnIndirect32( &rect )))
422 HRGN32 hrgnClip = CreateRectRgn32( 0, 0, 0, 0 );
423 INT32 xoffset, yoffset;
425 if( hrgnClip )
427 /* Compute obscured region for the visible rectangle by
428 * clipping children, siblings, and ancestors. Note that
429 * DCE_GetVisRect() returns a rectangle either in client
430 * or in window coordinates (for DCX_WINDOW request). */
432 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
434 if( flags & DCX_WINDOW )
436 /* adjust offsets since child window rectangles are
437 * in client coordinates */
439 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
440 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
442 else
443 xoffset = yoffset = 0;
445 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip,
446 &rect, xoffset, yoffset );
449 /* sibling window rectangles are in client
450 * coordinates of the parent window */
452 if (flags & DCX_WINDOW)
454 xoffset = -wndPtr->rectWindow.left;
455 yoffset = -wndPtr->rectWindow.top;
457 else
459 xoffset = -wndPtr->rectClient.left;
460 yoffset = -wndPtr->rectClient.top;
463 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
464 DCE_AddClipRects( wndPtr->parent->child,
465 wndPtr, hrgnClip, &rect, xoffset, yoffset );
467 /* Clip siblings of all ancestors that have the
468 * WS_CLIPSIBLINGS style
471 while (wndPtr->dwStyle & WS_CHILD)
473 wndPtr = wndPtr->parent;
474 xoffset -= wndPtr->rectClient.left;
475 yoffset -= wndPtr->rectClient.top;
476 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
478 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
479 hrgnClip, &rect, xoffset, yoffset );
483 /* Now once we've got a jumbo clip region we have
484 * to substract it from the visible rectangle.
487 CombineRgn32( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
488 DeleteObject32( hrgnClip );
490 else
492 DeleteObject32( hrgnVis );
493 hrgnVis = 0;
497 else
498 hrgnVis = CreateRectRgn32(0, 0, 0, 0); /* empty */
499 return hrgnVis;
502 /***********************************************************************
503 * DCE_OffsetVisRgn
505 * Change region from DC-origin relative coordinates to screen coords.
508 static void DCE_OffsetVisRgn( HDC32 hDC, HRGN32 hVisRgn )
510 DC *dc;
511 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return;
513 OffsetRgn32( hVisRgn, dc->w.DCOrgX, dc->w.DCOrgY );
515 GDI_HEAP_UNLOCK( hDC );
518 /***********************************************************************
519 * DCE_ExcludeRgn
521 * Translate given region from the wnd client to the DC coordinates
522 * and add it to the clipping region.
524 INT16 DCE_ExcludeRgn( HDC32 hDC, WND* wnd, HRGN32 hRgn )
526 POINT32 pt = {0, 0};
527 DCE *dce = firstDCE;
529 while (dce && (dce->hDC != hDC)) dce = dce->next;
530 if( dce )
532 MapWindowPoints32( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
533 if( dce->DCXflags & DCX_WINDOW )
535 wnd = WIN_FindWndPtr(dce->hwndCurrent);
536 pt.x += wnd->rectClient.left - wnd->rectWindow.left;
537 pt.y += wnd->rectClient.top - wnd->rectWindow.top;
540 else return ERROR;
541 OffsetRgn32(hRgn, pt.x, pt.y);
543 return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
546 /***********************************************************************
547 * GetDCEx16 (USER.359)
549 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
551 return (HDC16)GetDCEx32( hwnd, hrgnClip, flags );
555 /***********************************************************************
556 * GetDCEx32 (USER32.231)
558 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
560 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
562 HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
564 HRGN32 hrgnVisible = 0;
565 HDC32 hdc = 0;
566 DCE * dce;
567 DC * dc;
568 WND * wndPtr;
569 DWORD dcxFlags = 0;
570 BOOL32 bUpdateVisRgn = TRUE;
571 BOOL32 bUpdateClipOrigin = FALSE;
573 TRACE(dc,"hwnd %04x, hrgnClip %04x, flags %08x\n",
574 hwnd, hrgnClip, (unsigned)flags);
576 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
578 /* fixup flags */
580 if (!(wndPtr->class->style & (CS_OWNDC | CS_CLASSDC))) flags |= DCX_CACHE;
582 if (flags & DCX_USESTYLE)
584 flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
586 if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
587 flags |= DCX_CLIPSIBLINGS;
589 if ( !(flags & DCX_WINDOW) )
591 if (wndPtr->class->style & CS_PARENTDC) flags |= DCX_PARENTCLIP;
593 if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
594 !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
596 else flags |= DCX_CACHE;
599 if( flags & DCX_NOCLIPCHILDREN )
601 flags |= DCX_CACHE;
602 flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
605 if (flags & DCX_WINDOW)
606 flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
608 if (!(wndPtr->dwStyle & WS_CHILD) || !wndPtr->parent )
609 flags &= ~DCX_PARENTCLIP;
610 else if( flags & DCX_PARENTCLIP )
612 flags |= DCX_CACHE;
613 if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
614 if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
616 flags &= ~DCX_CLIPCHILDREN;
617 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
618 flags |= DCX_CLIPSIBLINGS;
622 /* find a suitable DCE */
624 dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
625 DCX_CACHE | DCX_WINDOW);
627 if (flags & DCX_CACHE)
629 DCE* dceEmpty;
630 DCE* dceUnused;
632 dceEmpty = dceUnused = NULL;
634 /* Strategy: First, we attempt to find a non-empty but unused DCE with
635 * compatible flags. Next, we look for an empty entry. If the cache is
636 * full we have to purge one of the unused entries.
639 for (dce = firstDCE; (dce); dce = dce->next)
641 if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
643 dceUnused = dce;
645 if (dce->DCXflags & DCX_DCEEMPTY)
646 dceEmpty = dce;
647 else
648 if ((dce->hwndCurrent == hwnd) &&
649 ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
650 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
652 TRACE(dc,"\tfound valid %08x dce [%04x], flags %08x\n",
653 (unsigned)dce, hwnd, (unsigned)dcxFlags );
654 bUpdateVisRgn = FALSE;
655 bUpdateClipOrigin = TRUE;
656 break;
660 if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
662 else
664 dce = (wndPtr->class->style & CS_OWNDC) ? wndPtr->dce : wndPtr->class->dce;
665 if( dce->hwndCurrent == hwnd )
667 TRACE(dc,"\tskipping hVisRgn update\n");
668 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
670 if( (dce->DCXflags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) &&
671 (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) )
673 /* This is likely to be a nested BeginPaint(). */
675 if( dce->hClipRgn != hrgnClip )
677 FIXME(dc,"new hrgnClip[%04x] smashes the previous[%04x]\n",
678 hrgnClip, dce->hClipRgn );
679 DCE_DeleteClipRgn( dce );
681 else
682 RestoreVisRgn(dce->hDC);
686 if (!dce) return 0;
688 dce->hwndCurrent = hwnd;
689 dce->hClipRgn = 0;
690 dce->DCXflags = dcxFlags | (flags & DCX_WINDOWPAINT) | DCX_DCEBUSY;
691 hdc = dce->hDC;
693 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
694 bUpdateVisRgn = bUpdateVisRgn || (dc->w.flags & DC_DIRTY);
696 /* recompute visible region */
698 wndPtr->pDriver->pSetDrawable( wndPtr, dc, flags, bUpdateClipOrigin );
699 if( bUpdateVisRgn )
701 TRACE(dc,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
703 if (flags & DCX_PARENTCLIP)
705 WND *parentPtr = wndPtr->parent;
707 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
709 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
710 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
711 else
712 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
714 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags );
715 if( flags & DCX_WINDOW )
716 OffsetRgn32( hrgnVisible, -wndPtr->rectWindow.left,
717 -wndPtr->rectWindow.top );
718 else
719 OffsetRgn32( hrgnVisible, -wndPtr->rectClient.left,
720 -wndPtr->rectClient.top );
721 DCE_OffsetVisRgn( hdc, hrgnVisible );
723 else
724 hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
726 else
727 if ((hwnd == GetDesktopWindow32()) &&
728 (rootWindow == DefaultRootWindow(display)))
729 hrgnVisible = CreateRectRgn32( 0, 0, SYSMETRICS_CXSCREEN,
730 SYSMETRICS_CYSCREEN );
731 else
733 hrgnVisible = DCE_GetVisRgn( hwnd, flags );
734 DCE_OffsetVisRgn( hdc, hrgnVisible );
737 dc->w.flags &= ~DC_DIRTY;
738 dce->DCXflags &= ~DCX_DCEDIRTY;
739 SelectVisRgn( hdc, hrgnVisible );
741 else
742 TRACE(dc,"no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
744 /* apply additional region operation (if any) */
746 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
748 if( !hrgnVisible ) hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
750 dce->DCXflags |= flags & (DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
751 dce->hClipRgn = hrgnClip;
753 TRACE(dc, "\tsaved VisRgn, clipRgn = %04x\n", hrgnClip);
755 SaveVisRgn( hdc );
756 CombineRgn32( hrgnVisible, hrgnClip, 0, RGN_COPY );
757 DCE_OffsetVisRgn( hdc, hrgnVisible );
758 CombineRgn32( hrgnVisible, InquireVisRgn( hdc ), hrgnVisible,
759 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
760 SelectVisRgn( hdc, hrgnVisible );
763 if( hrgnVisible ) DeleteObject32( hrgnVisible );
765 TRACE(dc, "(%04x,%04x,0x%lx): returning %04x\n",
766 hwnd, hrgnClip, flags, hdc);
767 return hdc;
771 /***********************************************************************
772 * GetDC16 (USER.66)
774 HDC16 WINAPI GetDC16( HWND16 hwnd )
776 return (HDC16)GetDC32( hwnd );
780 /***********************************************************************
781 * GetDC32 (USER32.230)
782 * RETURNS
783 * :Handle to DC
784 * NULL: Failure
786 HDC32 WINAPI GetDC32(
787 HWND32 hwnd /* handle of window */
789 if (!hwnd)
790 return GetDCEx32( GetDesktopWindow32(), 0, DCX_CACHE | DCX_WINDOW );
791 return GetDCEx32( hwnd, 0, DCX_USESTYLE );
795 /***********************************************************************
796 * GetWindowDC16 (USER.67)
798 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
800 if (!hwnd) hwnd = GetDesktopWindow16();
801 return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
805 /***********************************************************************
806 * GetWindowDC32 (USER32.304)
808 HDC32 WINAPI GetWindowDC32( HWND32 hwnd )
810 if (!hwnd) hwnd = GetDesktopWindow32();
811 return GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
815 /***********************************************************************
816 * ReleaseDC16 (USER.68)
818 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
820 return (INT16)ReleaseDC32( hwnd, hdc );
824 /***********************************************************************
825 * ReleaseDC32 (USER32.440)
827 * RETURNS
828 * 1: Success
829 * 0: Failure
831 INT32 WINAPI ReleaseDC32(
832 HWND32 hwnd /* Handle of window - ignored */,
833 HDC32 hdc /* Handle of device context */
835 DCE * dce = firstDCE;
837 TRACE(dc, "%04x %04x\n", hwnd, hdc );
839 while (dce && (dce->hDC != hdc)) dce = dce->next;
841 if ( dce )
842 if ( dce->DCXflags & DCX_DCEBUSY )
843 return DCE_ReleaseDC( dce );
844 return 0;
847 /***********************************************************************
848 * DCHook (USER.362)
850 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
852 BOOL16 WINAPI DCHook( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
854 HRGN32 hVisRgn;
855 DCE *dce = firstDCE;;
857 TRACE(dc,"hDC = %04x, %i\n", hDC, code);
859 while (dce && (dce->hDC != hDC)) dce = dce->next;
860 if (!dce) return 0;
862 switch( code )
864 case DCHC_INVALIDVISRGN:
866 /* GDI code calls this when it detects that the
867 * DC is dirty (usually after SetHookFlags()). This
868 * means that we have to recompute the visible region.
871 if( dce->DCXflags & DCX_DCEBUSY )
873 SetHookFlags(hDC, DCHF_VALIDATEVISRGN);
874 hVisRgn = DCE_GetVisRgn(dce->hwndCurrent, dce->DCXflags);
876 TRACE(dc,"\tapplying saved clipRgn\n");
878 /* clip this region with saved clipping region */
880 if ( (dce->DCXflags & DCX_INTERSECTRGN && dce->hClipRgn != 1) ||
881 ( dce->DCXflags & DCX_EXCLUDERGN && dce->hClipRgn) )
884 if( (!dce->hClipRgn && dce->DCXflags & DCX_INTERSECTRGN) ||
885 (dce->hClipRgn == 1 && dce->DCXflags & DCX_EXCLUDERGN) )
886 SetRectRgn32(hVisRgn,0,0,0,0);
887 else
888 CombineRgn32(hVisRgn, hVisRgn, dce->hClipRgn,
889 (dce->DCXflags & DCX_EXCLUDERGN)? RGN_DIFF:RGN_AND);
891 dce->DCXflags &= ~DCX_DCEDIRTY;
892 DCE_OffsetVisRgn( hDC, hVisRgn );
893 SelectVisRgn(hDC, hVisRgn);
894 DeleteObject32( hVisRgn );
896 else /* non-fatal but shouldn't happen */
897 WARN(dc, "DC is not in use!\n");
898 break;
900 case DCHC_DELETEDC: /* FIXME: ?? */
901 break;
903 default:
904 FIXME(dc,"unknown code\n");
906 return 0;
910 /**********************************************************************
911 * WindowFromDC16 (USER.117)
913 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
915 return (HWND16)WindowFromDC32( hDC );
919 /**********************************************************************
920 * WindowFromDC32 (USER32.581)
922 HWND32 WINAPI WindowFromDC32( HDC32 hDC )
924 DCE *dce = firstDCE;
925 while (dce && (dce->hDC != hDC)) dce = dce->next;
926 return dce ? dce->hwndCurrent : 0;
930 /***********************************************************************
931 * LockWindowUpdate16 (USER.294)
933 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
935 return LockWindowUpdate32( hwnd );
939 /***********************************************************************
940 * LockWindowUpdate32 (USER32.378)
942 BOOL32 WINAPI LockWindowUpdate32( HWND32 hwnd )
944 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */
945 return TRUE;