Release 980201
[wine/multimedia.git] / windows / dce.c
blob9ff60c50dcc6aae5d0c92904cc36210bee02e8dd
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 "stddebug.h"
29 /* #define DEBUG_DC */
30 #include "debug.h"
32 #define NB_DCE 5 /* Number of DCEs created at startup */
34 static DCE *firstDCE = 0;
35 static HDC32 defaultDCstate = 0;
37 static void DCE_DeleteClipRgn( DCE* );
38 static INT32 DCE_ReleaseDC( DCE* );
41 /***********************************************************************
42 * DCE_DumpCache
44 static void DCE_DumpCache(void)
46 DCE* dce = firstDCE;
48 printf("DCE:\n");
49 while( dce )
51 printf("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
52 (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags, (dce->DCXflags & DCX_CACHE) ?
53 "Cache" : "Owned", (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 fprintf(stderr,"[%04x] GetDC() without ReleaseDC()!\n", pWnd->hwndSelf);
149 DCE_ReleaseDC( pDCE );
152 pDCE->DCXflags &= DCX_CACHE;
153 pDCE->DCXflags |= DCX_DCEEMPTY;
154 pDCE->hwndCurrent = 0;
157 pDCE = pDCE->next;
162 /***********************************************************************
163 * DCE_DeleteClipRgn
165 static void DCE_DeleteClipRgn( DCE* dce )
167 dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
169 if( dce->DCXflags & DCX_KEEPCLIPRGN )
170 dce->DCXflags &= ~DCX_KEEPCLIPRGN;
171 else
172 if( dce->hClipRgn > 1 )
173 DeleteObject32( dce->hClipRgn );
175 dce->hClipRgn = 0;
177 dprintf_dc(stddeb,"\trestoring VisRgn\n");
179 RestoreVisRgn(dce->hDC);
183 /***********************************************************************
184 * DCE_ReleaseDC
186 static INT32 DCE_ReleaseDC( DCE* dce )
188 if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
190 /* restore previous visible region */
192 if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
193 (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
194 DCE_DeleteClipRgn( dce );
196 if (dce->DCXflags & DCX_CACHE)
198 SetDCState( dce->hDC, defaultDCstate );
199 dce->DCXflags &= ~DCX_DCEBUSY;
200 if (dce->DCXflags & DCX_DCEDIRTY)
202 /* don't keep around invalidated entries
203 * because SetDCState() disables hVisRgn updates
204 * by removing dirty bit. */
206 dce->hwndCurrent = 0;
207 dce->DCXflags &= DCX_CACHE;
208 dce->DCXflags |= DCX_DCEEMPTY;
211 return 1;
215 /***********************************************************************
216 * DCE_InvalidateDCE
218 * It is called from SetWindowPos() - we have to mark as dirty all busy
219 * DCE's for windows that have pWnd->parent as an ansector and whose client
220 * rect intersects with specified update rectangle.
222 BOOL32 DCE_InvalidateDCE(WND* pWnd, const RECT32* pRectUpdate)
224 WND* wndScope = pWnd->parent;
225 BOOL32 bRet = FALSE;
227 if( wndScope )
229 DCE *dce;
231 dprintf_dc(stddeb,"InvalidateDCE: scope hwnd = %04x, (%i,%i - %i,%i)\n",
232 wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
233 pRectUpdate->right,pRectUpdate->bottom);
234 if( debugging_dc ) DCE_DumpCache();
236 /* walk all DCEs and fixup non-empty entries */
238 for (dce = firstDCE; (dce); dce = dce->next)
240 if( !(dce->DCXflags & DCX_DCEEMPTY) )
242 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
244 if( wndCurrent && wndCurrent != WIN_GetDesktop() )
246 WND* wnd = wndCurrent;
247 INT32 xoffset = 0, yoffset = 0;
249 if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) ) continue;
251 /* check if DCE window is within the z-order scope */
253 for( wnd = wndCurrent; wnd; wnd = wnd->parent )
255 if( wnd == wndScope )
257 RECT32 wndRect;
259 wndRect = wndCurrent->rectWindow;
261 OffsetRect32( &wndRect, xoffset - wndCurrent->rectClient.left,
262 yoffset - wndCurrent->rectClient.top);
264 if (pWnd == wndCurrent ||
265 IntersectRect32( &wndRect, &wndRect, pRectUpdate ))
267 if( !(dce->DCXflags & DCX_DCEBUSY) )
269 /* Don't bother with visible regions of unused DCEs */
271 dprintf_dc(stddeb,"\tpurged %08x dce [%04x]\n",
272 (unsigned)dce, wndCurrent->hwndSelf);
274 dce->hwndCurrent = 0;
275 dce->DCXflags &= DCX_CACHE;
276 dce->DCXflags |= DCX_DCEEMPTY;
278 else
280 /* Set dirty bits in the hDC and DCE structs */
282 dprintf_dc(stddeb,"\tfixed up %08x dce [%04x]\n",
283 (unsigned)dce, wndCurrent->hwndSelf);
285 dce->DCXflags |= DCX_DCEDIRTY;
286 SetHookFlags(dce->hDC, DCHF_INVALIDATEVISRGN);
287 bRet = TRUE;
290 break;
292 xoffset += wnd->rectClient.left;
293 yoffset += wnd->rectClient.top;
297 } /* dce list */
299 return bRet;
302 /***********************************************************************
303 * DCE_Init
305 void DCE_Init(void)
307 int i;
308 DCE * dce;
310 for (i = 0; i < NB_DCE; i++)
312 if (!(dce = DCE_AllocDCE( 0, DCE_CACHE_DC ))) return;
313 if (!defaultDCstate) defaultDCstate = GetDCState( dce->hDC );
318 /***********************************************************************
319 * DCE_GetVisRect
321 * Calculate the visible rectangle of a window (i.e. the client or
322 * window area clipped by the client area of all ancestors) in the
323 * corresponding coordinates. Return FALSE if the visible region is empty.
325 static BOOL32 DCE_GetVisRect( WND *wndPtr, BOOL32 clientArea, RECT32 *lprect )
327 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
329 if (wndPtr->dwStyle & WS_VISIBLE)
331 INT32 xoffset = lprect->left;
332 INT32 yoffset = lprect->top;
334 while (wndPtr->parent)
336 wndPtr = wndPtr->parent;
338 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
339 goto fail;
341 xoffset += wndPtr->rectClient.left;
342 yoffset += wndPtr->rectClient.top;
343 OffsetRect32( lprect, wndPtr->rectClient.left,
344 wndPtr->rectClient.top );
346 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
347 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
348 (lprect->left >= wndPtr->rectClient.right) ||
349 (lprect->right <= wndPtr->rectClient.left) ||
350 (lprect->top >= wndPtr->rectClient.bottom) ||
351 (lprect->bottom <= wndPtr->rectClient.top) )
352 goto fail;
354 lprect->left = MAX( lprect->left, wndPtr->rectClient.left );
355 lprect->right = MIN( lprect->right, wndPtr->rectClient.right );
356 lprect->top = MAX( lprect->top, wndPtr->rectClient.top );
357 lprect->bottom = MIN( lprect->bottom, wndPtr->rectClient.bottom );
359 OffsetRect32( lprect, -xoffset, -yoffset );
360 return TRUE;
363 fail:
364 SetRectEmpty32( lprect );
365 return FALSE;
369 /***********************************************************************
370 * DCE_AddClipRects
372 * Go through the linked list of windows from pWndStart to pWndEnd,
373 * adding to the clip region the intersection of the target rectangle
374 * with an offset window rectangle.
376 static BOOL32 DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
377 HRGN32 hrgnClip, LPRECT32 lpRect, int x, int y )
379 RECT32 rect;
381 if (pWndStart->window) return TRUE; /* X itself will do the clipping */
383 for (; pWndStart != pWndEnd; pWndStart = pWndStart->next)
385 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
387 rect.left = pWndStart->rectWindow.left + x;
388 rect.top = pWndStart->rectWindow.top + y;
389 rect.right = pWndStart->rectWindow.right + x;
390 rect.bottom = pWndStart->rectWindow.bottom + y;
392 if( IntersectRect32( &rect, &rect, lpRect ))
393 if(!REGION_UnionRectWithRgn( hrgnClip, &rect ))
394 break;
396 return (pWndStart == pWndEnd);
400 /***********************************************************************
401 * DCE_GetVisRgn
403 * Return the visible region of a window, i.e. the client or window area
404 * clipped by the client area of all ancestors, and then optionally
405 * by siblings and children.
407 HRGN32 DCE_GetVisRgn( HWND32 hwnd, WORD flags )
409 HRGN32 hrgnVis = 0;
410 RECT32 rect;
411 WND *wndPtr = WIN_FindWndPtr( hwnd );
413 /* Get visible rectangle and create a region with it. */
415 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
417 if((hrgnVis = CreateRectRgnIndirect32( &rect )))
419 HRGN32 hrgnClip = CreateRectRgn32( 0, 0, 0, 0 );
420 INT32 xoffset, yoffset;
422 if( hrgnClip )
424 /* Compute obscured region for the visible rectangle by
425 * clipping children, siblings, and ancestors. Note that
426 * DCE_GetVisRect() returns a rectangle either in client
427 * or in window coordinates (for DCX_WINDOW request). */
429 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
431 if( flags & DCX_WINDOW )
433 /* adjust offsets since child window rectangles are
434 * in client coordinates */
436 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
437 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
439 else
440 xoffset = yoffset = 0;
442 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip,
443 &rect, xoffset, yoffset );
446 /* sibling window rectangles are in client
447 * coordinates of the parent window */
449 if (flags & DCX_WINDOW)
451 xoffset = -wndPtr->rectWindow.left;
452 yoffset = -wndPtr->rectWindow.top;
454 else
456 xoffset = -wndPtr->rectClient.left;
457 yoffset = -wndPtr->rectClient.top;
460 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
461 DCE_AddClipRects( wndPtr->parent->child,
462 wndPtr, hrgnClip, &rect, xoffset, yoffset );
464 /* Clip siblings of all ancestors that have the
465 * WS_CLIPSIBLINGS style
468 while (wndPtr->dwStyle & WS_CHILD)
470 wndPtr = wndPtr->parent;
471 xoffset -= wndPtr->rectClient.left;
472 yoffset -= wndPtr->rectClient.top;
473 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
475 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
476 hrgnClip, &rect, xoffset, yoffset );
480 /* Now once we've got a jumbo clip region we have
481 * to substract it from the visible rectangle.
484 CombineRgn32( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
485 DeleteObject32( hrgnClip );
487 else
489 DeleteObject32( hrgnVis );
490 hrgnVis = 0;
494 else
495 hrgnVis = CreateRectRgn32(0, 0, 0, 0); /* empty */
496 return hrgnVis;
500 /***********************************************************************
501 * DCE_SetDrawable
503 * Set the drawable, origin and dimensions for the DC associated to
504 * a given window.
506 static void DCE_SetDrawable( WND *wndPtr, DC *dc, WORD flags, BOOL32 bSetClipOrigin )
508 if (!wndPtr) /* Get a DC for the whole screen */
510 dc->w.DCOrgX = 0;
511 dc->w.DCOrgY = 0;
512 dc->u.x.drawable = rootWindow;
513 TSXSetSubwindowMode( display, dc->u.x.gc, IncludeInferiors );
515 else
517 if (flags & DCX_WINDOW)
519 dc->w.DCOrgX = wndPtr->rectWindow.left;
520 dc->w.DCOrgY = wndPtr->rectWindow.top;
522 else
524 dc->w.DCOrgX = wndPtr->rectClient.left;
525 dc->w.DCOrgY = wndPtr->rectClient.top;
527 while (!wndPtr->window)
529 wndPtr = wndPtr->parent;
530 dc->w.DCOrgX += wndPtr->rectClient.left;
531 dc->w.DCOrgY += wndPtr->rectClient.top;
533 dc->w.DCOrgX -= wndPtr->rectWindow.left;
534 dc->w.DCOrgY -= wndPtr->rectWindow.top;
535 dc->u.x.drawable = wndPtr->window;
537 /* This is needed when we reuse a cached DC because
538 * SetDCState() called by ReleaseDC() screws up DC
539 * origins for child windows.
542 if( bSetClipOrigin )
543 TSXSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
546 /***********************************************************************
547 * DCE_ExcludeRgn
549 * Translate given region from the wnd client to the DC coordinates
550 * and add it to the clipping region.
552 INT16 DCE_ExcludeRgn( HDC32 hDC, WND* wnd, HRGN32 hRgn )
554 INT16 ret;
555 POINT32 pt = {0, 0};
556 HRGN32 hRgnClip = GetClipRgn16( hDC );
557 DCE *dce = firstDCE;
559 while (dce && (dce->hDC != hDC)) dce = dce->next;
560 if( dce )
562 MapWindowPoints32( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
563 if( dce->DCXflags & DCX_WINDOW )
565 wnd = WIN_FindWndPtr(dce->hwndCurrent);
566 pt.x += wnd->rectClient.left - wnd->rectWindow.left;
567 pt.y += wnd->rectClient.top - wnd->rectWindow.top;
570 else return ERROR;
571 OffsetRgn32(hRgn, pt.x, pt.y);
572 if( hRgnClip ) ret = CombineRgn32( hRgnClip, hRgnClip, hRgn, RGN_DIFF );
573 else
575 hRgnClip = InquireVisRgn( hDC );
576 ret = CombineRgn32( hRgn, hRgnClip, hRgn, RGN_DIFF );
577 SelectClipRgn32( hDC, hRgn );
579 return ret;
582 /***********************************************************************
583 * GetDCEx16 (USER.359)
585 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
587 return (HDC16)GetDCEx32( hwnd, hrgnClip, flags );
591 /***********************************************************************
592 * GetDCEx32 (USER32.230)
594 * Unimplemented flags: DCX_LOCKWINDOWUPDATE
596 * FIXME: Full support for hrgnClip == 1 (alias for entire window).
598 HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
600 HRGN32 hrgnVisible = 0;
601 HDC32 hdc = 0;
602 DCE * dce;
603 DC * dc;
604 WND * wndPtr;
605 DWORD dcxFlags = 0;
606 BOOL32 bUpdateVisRgn = TRUE;
607 BOOL32 bUpdateClipOrigin = FALSE;
609 dprintf_dc(stddeb,"GetDCEx: hwnd %04x, hrgnClip %04x, flags %08x\n",
610 hwnd, hrgnClip, (unsigned)flags);
612 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
614 /* fixup flags */
616 if (!(wndPtr->class->style & (CS_OWNDC | CS_CLASSDC))) flags |= DCX_CACHE;
618 if (flags & DCX_USESTYLE)
620 flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
622 if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
623 flags |= DCX_CLIPSIBLINGS;
625 if ( !(flags & DCX_WINDOW) )
627 if (wndPtr->class->style & CS_PARENTDC) flags |= DCX_PARENTCLIP;
629 if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
630 !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
632 else flags |= DCX_CACHE;
635 if( flags & DCX_NOCLIPCHILDREN )
637 flags |= DCX_CACHE;
638 flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
641 if (flags & DCX_WINDOW)
642 flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
644 if (!(wndPtr->dwStyle & WS_CHILD) || !wndPtr->parent )
645 flags &= ~DCX_PARENTCLIP;
646 else if( flags & DCX_PARENTCLIP )
648 flags |= DCX_CACHE;
649 if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
650 if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
652 flags &= ~DCX_CLIPCHILDREN;
653 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
654 flags |= DCX_CLIPSIBLINGS;
658 /* find a suitable DCE */
660 dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
661 DCX_CACHE | DCX_WINDOW);
663 if (flags & DCX_CACHE)
665 DCE* dceEmpty;
666 DCE* dceUnused;
668 dceEmpty = dceUnused = NULL;
670 /* Strategy: First, we attempt to find a non-empty but unused DCE with
671 * compatible flags. Next, we look for an empty entry. If the cache is
672 * full we have to purge one of the unused entries.
675 for (dce = firstDCE; (dce); dce = dce->next)
677 if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
679 dceUnused = dce;
681 if (dce->DCXflags & DCX_DCEEMPTY)
682 dceEmpty = dce;
683 else
684 if ((dce->hwndCurrent == hwnd) &&
685 ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
686 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
688 dprintf_dc(stddeb,"\tfound valid %08x dce [%04x], flags %08x\n",
689 (unsigned)dce, hwnd, (unsigned)dcxFlags );
690 bUpdateVisRgn = FALSE;
691 bUpdateClipOrigin = TRUE;
692 break;
696 if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
698 else
700 dce = (wndPtr->class->style & CS_OWNDC) ? wndPtr->dce : wndPtr->class->dce;
701 if( dce->hwndCurrent == hwnd )
703 dprintf_dc(stddeb,"\tskipping hVisRgn update\n");
704 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
706 if( (dce->DCXflags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) &&
707 (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) )
709 /* This is likely to be a nested BeginPaint(). */
711 if( dce->hClipRgn != hrgnClip )
713 fprintf(stdnimp,"GetDCEx: new hrgnClip [%04x] smashes the previous [%04x]!\n",
714 hrgnClip, dce->hClipRgn );
715 DCE_DeleteClipRgn( dce );
717 else
718 RestoreVisRgn(dce->hDC);
722 if (!dce) return 0;
724 dce->hwndCurrent = hwnd;
725 dce->hClipRgn = 0;
726 dce->DCXflags = dcxFlags | (flags & DCX_WINDOWPAINT) | DCX_DCEBUSY;
727 hdc = dce->hDC;
729 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
730 bUpdateVisRgn = bUpdateVisRgn || (dc->w.flags & DC_DIRTY);
732 /* recompute visible region */
734 DCE_SetDrawable( wndPtr, dc, flags, bUpdateClipOrigin );
735 if( bUpdateVisRgn )
737 dprintf_dc(stddeb,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
739 if (flags & DCX_PARENTCLIP)
741 WND *parentPtr = wndPtr->parent;
743 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
745 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
746 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
747 else
748 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
750 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags );
751 if( flags & DCX_WINDOW )
752 OffsetRgn32( hrgnVisible, -wndPtr->rectWindow.left,
753 -wndPtr->rectWindow.top );
754 else
755 OffsetRgn32( hrgnVisible, -wndPtr->rectClient.left,
756 -wndPtr->rectClient.top );
758 else
759 hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
761 else
762 if ((hwnd == GetDesktopWindow32()) &&
763 (rootWindow == DefaultRootWindow(display)))
764 hrgnVisible = CreateRectRgn32( 0, 0, SYSMETRICS_CXSCREEN,
765 SYSMETRICS_CYSCREEN );
766 else hrgnVisible = DCE_GetVisRgn( hwnd, flags );
768 dc->w.flags &= ~DC_DIRTY;
769 dce->DCXflags &= ~DCX_DCEDIRTY;
770 SelectVisRgn( hdc, hrgnVisible );
772 else
773 dprintf_dc(stddeb,"no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
775 /* apply additional region operation (if any) */
777 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
779 if( !hrgnVisible ) hrgnVisible = CreateRectRgn32( 0, 0, 0, 0 );
781 dce->DCXflags |= flags & (DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
782 dce->hClipRgn = hrgnClip;
784 dprintf_dc(stddeb, "\tsaved VisRgn, clipRgn = %04x\n", hrgnClip);
786 SaveVisRgn( hdc );
787 CombineRgn32( hrgnVisible, InquireVisRgn( hdc ), hrgnClip,
788 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
789 SelectVisRgn( hdc, hrgnVisible );
792 if( hrgnVisible ) DeleteObject32( hrgnVisible );
794 dprintf_dc(stddeb, "GetDCEx(%04x,%04x,0x%lx): returning %04x\n",
795 hwnd, hrgnClip, flags, hdc);
796 return hdc;
800 /***********************************************************************
801 * GetDC16 (USER.66)
803 HDC16 WINAPI GetDC16( HWND16 hwnd )
805 return (HDC16)GetDC32( hwnd );
809 /***********************************************************************
810 * GetDC32 (USER32.229)
812 HDC32 WINAPI GetDC32( HWND32 hwnd )
814 if (!hwnd)
815 return GetDCEx32( GetDesktopWindow32(), 0, DCX_CACHE | DCX_WINDOW );
816 return GetDCEx32( hwnd, 0, DCX_USESTYLE );
820 /***********************************************************************
821 * GetWindowDC16 (USER.67)
823 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
825 if (!hwnd) hwnd = GetDesktopWindow16();
826 return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
830 /***********************************************************************
831 * GetWindowDC32 (USER32.)
833 HDC32 WINAPI GetWindowDC32( HWND32 hwnd )
835 if (!hwnd) hwnd = GetDesktopWindow32();
836 return GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
840 /***********************************************************************
841 * ReleaseDC16 (USER.68)
843 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
845 return (INT32)ReleaseDC32( hwnd, hdc );
849 /***********************************************************************
850 * ReleaseDC32 (USER32.439)
852 INT32 WINAPI ReleaseDC32( HWND32 hwnd, HDC32 hdc )
854 DCE * dce = firstDCE;
856 dprintf_dc(stddeb, "ReleaseDC: %04x %04x\n", hwnd, hdc );
858 while (dce && (dce->hDC != hdc)) dce = dce->next;
860 if ( dce )
861 if ( dce->DCXflags & DCX_DCEBUSY )
862 return DCE_ReleaseDC( dce );
863 return 0;
866 /***********************************************************************
867 * DCHook (USER.362)
869 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
871 BOOL16 WINAPI DCHook( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
873 HRGN32 hVisRgn;
874 DCE *dce = firstDCE;;
876 dprintf_dc(stddeb,"DCHook: hDC = %04x, %i\n", hDC, code);
878 while (dce && (dce->hDC != hDC)) dce = dce->next;
879 if (!dce) return 0;
881 switch( code )
883 case DCHC_INVALIDVISRGN:
885 /* GDI code calls this when it detects that the
886 * DC is dirty (usually after SetHookFlags()). This
887 * means that we have to recompute the visible region.
890 if( dce->DCXflags & DCX_DCEBUSY )
892 SetHookFlags(hDC, DCHF_VALIDATEVISRGN);
893 hVisRgn = DCE_GetVisRgn(dce->hwndCurrent, dce->DCXflags);
895 dprintf_dc(stddeb,"\tapplying saved clipRgn\n");
897 /* clip this region with saved clipping region */
899 if ( (dce->DCXflags & DCX_INTERSECTRGN && dce->hClipRgn != 1) ||
900 ( dce->DCXflags & DCX_EXCLUDERGN && dce->hClipRgn) )
903 if( (!dce->hClipRgn && dce->DCXflags & DCX_INTERSECTRGN) ||
904 (dce->hClipRgn == 1 && dce->DCXflags & DCX_EXCLUDERGN) )
905 SetRectRgn32(hVisRgn,0,0,0,0);
906 else
907 CombineRgn32(hVisRgn, hVisRgn, dce->hClipRgn,
908 (dce->DCXflags & DCX_EXCLUDERGN)? RGN_DIFF:RGN_AND);
910 dce->DCXflags &= ~DCX_DCEDIRTY;
911 SelectVisRgn(hDC, hVisRgn);
912 DeleteObject32( hVisRgn );
914 else /* non-fatal but shouldn't happen */
915 dprintf_dc(stddeb,"DCHook: DC is not in use!\n");
916 break;
918 case DCHC_DELETEDC: /* FIXME: ?? */
919 break;
921 default:
922 fprintf(stdnimp,"DCHook: unknown code\n");
924 return 0;
928 /**********************************************************************
929 * WindowFromDC16 (USER32.580)
931 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
933 return (HWND16)WindowFromDC32( hDC );
937 /**********************************************************************
938 * WindowFromDC32 (USER32.580)
940 HWND32 WINAPI WindowFromDC32( HDC32 hDC )
942 DCE *dce = firstDCE;
943 while (dce && (dce->hDC != hDC)) dce = dce->next;
944 return dce ? dce->hwndCurrent : 0;
948 /***********************************************************************
949 * LockWindowUpdate16 (USER.294)
951 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
953 return LockWindowUpdate32( hwnd );
957 /***********************************************************************
958 * LockWindowUpdate32 (USER32.377)
960 BOOL32 WINAPI LockWindowUpdate32( HWND32 hwnd )
962 /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */
963 return TRUE;