Various ANSI C compability fixes.
[wine] / windows / painting.c
1 /*
2  * Window painting functions
3  *
4  * Copyright 1993, 1994, 1995 Alexandre Julliard
5  *                       1999 Alex Korobka
6  */
7
8 #include "region.h"
9 #include "win.h"
10 #include "queue.h"
11 #include "dce.h"
12 #include "heap.h"
13 #include "debugtools.h"
14 #include "wine/winuser16.h"
15
16 DECLARE_DEBUG_CHANNEL(nonclient)
17 DECLARE_DEBUG_CHANNEL(win)
18
19 /* client rect in window coordinates */
20
21 #define GETCLIENTRECTW( wnd, r )        (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
22                                         (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
23                                         (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
24                                         (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
25
26   /* Last CTLCOLOR id */
27 #define CTLCOLOR_MAX   CTLCOLOR_STATIC
28
29
30 /***********************************************************************
31  *           WIN_HaveToDelayNCPAINT
32  *
33  * Currently, in the Wine painting mechanism, the WM_NCPAINT message
34  * is generated as soon as a region intersecting the non-client area 
35  * of a window is invalidated.
36  *
37  * This technique will work fine for all windows whose parents
38  * have the WS_CLIPCHILDREN style. When the parents have that style,
39  * they are not going to override the contents of their children.
40  * However, when the parent doesn't have that style, Windows relies
41  * on a "painter's algorithm" to display the contents of the windows.
42  * That is, windows are painted from back to front. This includes the
43  * non-client area.
44  *
45  * This method looks at the current state of a window to determine
46  * if the sending of the WM_NCPAINT message should be delayed until 
47  * the BeginPaint call.
48  *
49  * PARAMS:
50  *   wndPtr   - A Locked window pointer to the window we're
51  *              examining.
52  *   uncFlags - This is the flag passed to the WIN_UpdateNCRgn
53  *              function. This is a shortcut for the cases when
54  *              we already know when to avoid scanning all the
55  *              parents of a window. If you already know that this
56  *              window's NCPAINT should be delayed, set the 
57  *              UNC_DELAY_NCPAINT flag for this parameter. 
58  *
59  *              This shortcut behavior is implemented in the
60  *              RDW_Paint() method.
61  * 
62  */
63 static BOOL WIN_HaveToDelayNCPAINT(
64   WND* wndPtr, 
65   UINT uncFlags)
66 {
67   WND* parentWnd = NULL;
68
69   /*
70    * Test the shortcut first. (duh)
71    */
72   if (uncFlags & UNC_DELAY_NCPAINT)
73     return TRUE;
74
75   /*
76    * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
77    * method only. This is another shortcut to avoid going
78    * up the parent's chain of the window to finally
79    * figure-out that none of them has an invalid region.
80    */
81   if (uncFlags & UNC_IN_BEGINPAINT)
82     return FALSE;
83
84   /*
85    * Scan all the parents of this window to find a window
86    * that doesn't have the WS_CLIPCHILDREN style and that
87    * has an invalid region. 
88    */
89   parentWnd = WIN_LockWndPtr(wndPtr->parent);
90
91   while (parentWnd!=NULL)
92   {
93     if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
94          (parentWnd->hrgnUpdate != 0) )
95     {
96       WIN_ReleaseWndPtr(parentWnd);
97       return TRUE;
98     }
99
100     WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);    
101   }
102
103   WIN_ReleaseWndPtr(parentWnd);
104
105   return FALSE;
106 }
107
108 /***********************************************************************
109  *           WIN_UpdateNCRgn
110  *
111  *  Things to do:
112  *      Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
113  *      Crop hrgnUpdate to a client rect, especially if it 1.
114  *      If UNC_REGION is set return update region for the client rect.
115  *
116  *  NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
117  *        The trick is that when the returned region handle may be different from hRgn.
118  *        In this case the old hRgn must be considered gone. BUT, if the returned value
119  *        is 1 then the hRgn is preserved and RDW_Paint() will have to get 
120  *        a DC without extra clipping region.
121  */
122 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
123 {
124     RECT  r;
125     HRGN  hClip = 0;
126     HRGN  hrgnRet = 0;
127
128     TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n", 
129                       wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
130
131     /* desktop window doesn't have a nonclient area */
132     if(wnd == WIN_GetDesktop()) 
133     {
134         wnd->flags &= ~WIN_NEEDS_NCPAINT;
135         if( wnd->hrgnUpdate > 1 )
136             hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
137         else 
138         {
139             hrgnRet = wnd->hrgnUpdate;
140         }
141         WIN_ReleaseDesktop();
142         return hrgnRet;
143     }
144     WIN_ReleaseDesktop();
145
146     if ((wnd->hwndSelf == GetForegroundWindow()) &&
147         !(wnd->flags & WIN_NCACTIVATED) )
148     {
149         wnd->flags |= WIN_NCACTIVATED;
150         uncFlags |= UNC_ENTIRE; 
151     }
152
153     /*
154      * If the window's non-client area needs to be painted, 
155      */
156     if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
157          !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
158     {
159             RECT r2, r3;
160
161             wnd->flags &= ~WIN_NEEDS_NCPAINT;  
162             GETCLIENTRECTW( wnd, r );
163
164             TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n", 
165                                 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
166             if( wnd->hrgnUpdate > 1 )
167             {
168                 /* Check if update rgn overlaps with nonclient area */
169
170                 GetRgnBox( wnd->hrgnUpdate, &r2 );
171                 UnionRect( &r3, &r2, &r );
172                 if( r3.left != r.left || r3.top != r.top || 
173                     r3.right != r.right || r3.bottom != r.bottom ) /* it does */
174                 {
175                     /* crop hrgnUpdate, save old one in hClip - the only
176                      * case that places a valid region handle in hClip */
177
178                     hClip = wnd->hrgnUpdate;
179                     wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
180                     if( uncFlags & UNC_REGION ) hrgnRet = hClip;
181                 }
182
183                 if( uncFlags & UNC_CHECK )
184                 {
185                     GetRgnBox( wnd->hrgnUpdate, &r3 );
186                     if( IsRectEmpty( &r3 ) )
187                     {
188                         /* delete the update region since all invalid 
189                          * parts were in the nonclient area */
190
191                         DeleteObject( wnd->hrgnUpdate );
192                         wnd->hrgnUpdate = 0;
193                         if(!(wnd->flags & WIN_INTERNAL_PAINT))
194                             QUEUE_DecPaintCount( wnd->hmemTaskQ );
195
196                         wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
197                     }
198                 }
199
200                 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
201             }
202             else 
203             if( wnd->hrgnUpdate == 1 )/* entire window */
204             {
205                 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
206                 if( uncFlags & UNC_REGION ) hrgnRet = 1;
207                 uncFlags |= UNC_ENTIRE;
208             }
209     }
210     else /* no WM_NCPAINT unless forced */
211     {
212         if( wnd->hrgnUpdate >  1 )
213         {
214 copyrgn:
215             if( uncFlags & UNC_REGION )
216                 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
217         }
218         else
219         if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
220         {
221             GETCLIENTRECTW( wnd, r ); 
222             wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
223             if( uncFlags & UNC_REGION ) hrgnRet = 1;
224         }
225     }
226
227     if(!hClip && (uncFlags & UNC_ENTIRE) )
228     {
229         /* still don't do anything if there is no nonclient area */
230         hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
231     }
232
233     if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
234     {
235         if ( hClip == hrgnRet && hrgnRet > 1 ) {
236             hClip = CreateRectRgn( 0, 0, 0, 0 );
237             CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
238         }
239
240         SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
241         if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
242             DeleteObject( hClip );
243         /*
244          * Since all Window locks are suspended while processing the WM_NCPAINT
245          * we want to make sure the window still exists before continuing.
246          */
247         if (!IsWindow(wnd->hwndSelf))
248         {
249           DeleteObject(hrgnRet);
250           hrgnRet=0;
251         }
252     }
253
254     TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
255
256     return hrgnRet;
257 }
258
259
260 /***********************************************************************
261  *           BeginPaint16    (USER.39)
262  */
263 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps ) 
264 {
265     BOOL bIcon;
266     HRGN hrgnUpdate;
267     WND *wndPtr = WIN_FindWndPtr( hwnd );
268     if (!wndPtr) return 0;
269
270     bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
271
272     wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
273
274     /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
275     WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
276
277     /*
278      * Make sure the window is still a window. All window locks are suspended
279      * when the WM_NCPAINT is sent.
280      */
281     if (!IsWindow(wndPtr->hwndSelf))
282     {
283         WIN_ReleaseWndPtr(wndPtr);
284         return 0;
285     }
286
287     if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
288         QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
289
290     wndPtr->hrgnUpdate = 0;
291     wndPtr->flags &= ~WIN_INTERNAL_PAINT;
292
293     HideCaret( hwnd );
294
295     TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
296
297     if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
298     {
299         /* Don't clip the output to the update region for CS_PARENTDC window */
300         if( hrgnUpdate ) 
301             DeleteObject(hrgnUpdate);
302         lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
303                               (bIcon ? DCX_WINDOW : 0) );
304     }
305     else
306     {
307         if( hrgnUpdate ) /* convert to client coordinates */
308             OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
309                                    wndPtr->rectWindow.top - wndPtr->rectClient.top );
310         lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
311                              DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
312         /* ReleaseDC() in EndPaint() will delete the region */
313     }
314
315     TRACE_(win)("hdc = %04x\n", lps->hdc);
316
317     if (!lps->hdc)
318     {
319         WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
320         WIN_ReleaseWndPtr(wndPtr);
321         return 0;
322     }
323
324     GetClipBox16( lps->hdc, &lps->rcPaint );
325
326     TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
327                     lps->rcPaint.right, lps->rcPaint.bottom );
328
329     if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
330     {
331         wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
332         lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
333                                                    : WM_ERASEBKGND,
334                                      (WPARAM16)lps->hdc, 0 );
335     }
336     else lps->fErase = TRUE;
337
338     WIN_ReleaseWndPtr(wndPtr);
339     return lps->hdc;
340 }
341
342
343 /***********************************************************************
344  *           BeginPaint32    (USER32.10)
345  */
346 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
347 {
348     PAINTSTRUCT16 ps;
349
350     BeginPaint16( hwnd, &ps );
351     lps->hdc            = (HDC)ps.hdc;
352     lps->fErase         = ps.fErase;
353     lps->rcPaint.top    = ps.rcPaint.top;
354     lps->rcPaint.left   = ps.rcPaint.left;
355     lps->rcPaint.right  = ps.rcPaint.right;
356     lps->rcPaint.bottom = ps.rcPaint.bottom;
357     lps->fRestore       = ps.fRestore;
358     lps->fIncUpdate     = ps.fIncUpdate;
359     return lps->hdc;
360 }
361
362
363 /***********************************************************************
364  *           EndPaint16    (USER.40)
365  */
366 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
367 {
368     ReleaseDC16( hwnd, lps->hdc );
369     ShowCaret( hwnd );
370     return TRUE;
371 }
372
373
374 /***********************************************************************
375  *           EndPaint32    (USER32.176)
376  */
377 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
378 {
379     ReleaseDC( hwnd, lps->hdc );
380     ShowCaret( hwnd );
381     return TRUE;
382 }
383
384
385 /***********************************************************************
386  *           FillWindow    (USER.324)
387  */
388 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
389 {
390     RECT16 rect;
391     GetClientRect16( hwnd, &rect );
392     DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
393     PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
394 }
395
396
397 /***********************************************************************
398  *           PAINT_GetControlBrush
399  */
400 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
401 {
402     HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType, 
403                                                              (WPARAM)hDC, (LPARAM)hWnd );
404     if( !IsGDIObject16(bkgBrush) )
405         bkgBrush = DEFWND_ControlColor( hDC, ctlType );
406     return bkgBrush;
407 }
408
409
410 /***********************************************************************
411  *           PaintRect    (USER.325)
412  */
413 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
414                        HBRUSH16 hbrush, const RECT16 *rect)
415 {
416     if( hbrush <= CTLCOLOR_MAX ) 
417     {
418         if( hwndParent )
419             hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
420         else 
421             return;
422     }
423     if( hbrush ) 
424         FillRect16( hdc, rect, hbrush );
425 }
426
427
428 /***********************************************************************
429  *           GetControlBrush    (USER.326)
430  */
431 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
432 {
433     WND* wndPtr = WIN_FindWndPtr( hwnd );
434     HBRUSH16 retvalue;
435
436     if((ctlType <= CTLCOLOR_MAX) && wndPtr )
437     {
438         WND* parent;
439         if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
440         else parent = WIN_LockWndPtr(wndPtr->parent);
441         if( !parent ) parent = wndPtr;
442         retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
443         WIN_ReleaseWndPtr(parent);
444         goto END;
445     }
446     retvalue = (HBRUSH16)0;
447 END:
448     WIN_ReleaseWndPtr(wndPtr);
449     return retvalue;
450 }
451
452
453 /***********************************************************************
454  *              RDW_ValidateParent [RDW_UpdateRgns() helper] 
455  *
456  *  Validate the portions of parent that are covered by a validated child
457  *  wndPtr = child
458  */
459 void  RDW_ValidateParent(WND *wndChild)  
460 {
461     WND *wndParent = WIN_LockWndPtr(wndChild->parent);
462     WND *wndDesktop = WIN_GetDesktop();
463
464     if ((wndParent) && (wndParent != wndDesktop) && !(wndParent->dwStyle & WS_CLIPCHILDREN))
465     {
466         HRGN hrg;
467         if (wndChild->hrgnUpdate == 1 )
468         {
469             RECT r;
470
471             r.left = 0;
472             r.top = 0;
473             r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
474             r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
475
476             hrg = CreateRectRgnIndirect( &r );
477         }
478         else
479            hrg = wndChild->hrgnUpdate;
480         if (wndParent->hrgnUpdate != 0)
481         {
482             POINT ptOffset;
483             RECT rect, rectParent;
484             if( wndParent->hrgnUpdate == 1 )
485             {
486                RECT r;
487
488                r.left = 0;
489                r.top = 0;
490                r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
491                r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
492
493                wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
494             }
495             /* we must offset the child region by the offset of the child rect in the parent */
496             GetWindowRect(wndParent->hwndSelf, &rectParent);
497             GetWindowRect(wndChild->hwndSelf, &rect);
498             ptOffset.x = rect.left - rectParent.left;
499             ptOffset.y = rect.top - rectParent.top;
500             OffsetRgn( hrg, ptOffset.x, ptOffset.y );
501             CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
502             OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
503         }
504         if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
505     }
506     WIN_ReleaseWndPtr(wndParent);
507     WIN_ReleaseDesktop();
508 }
509
510 /***********************************************************************
511  *              RDW_UpdateRgns [RedrawWindow() helper] 
512  *
513  *  Walks the window tree and adds/removes parts of the hRgn to/from update
514  *  regions of windows that overlap it. Also, manages internal paint flags.
515  *
516  *  NOTE: Walks the window tree so the caller must lock it.
517  *        MUST preserve hRgn (can modify but then has to restore).
518  */
519 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
520 {
521     /* 
522      * Called only when one of the following is set:
523      * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
524      */
525
526     BOOL bHadOne =  wndPtr->hrgnUpdate && hRgn;
527     BOOL bChildren =  ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) 
528                         && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
529     RECT r;
530
531     r.left = 0;
532     r.top = 0;
533     r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
534     r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
535
536     TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
537
538     if( flags & RDW_INVALIDATE )
539     {
540         if( hRgn > 1 )
541         {
542             switch( wndPtr->hrgnUpdate )
543             {
544                 default:
545                         CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
546                         /* fall through */
547                 case 0:
548                         wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate, 
549                                                              wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn, 
550                                                              &r, NULL );
551                         if( !bHadOne )
552                         {
553                             GetRgnBox( wndPtr->hrgnUpdate, &r );
554                             if( IsRectEmpty( &r ) )
555                             {
556                                 DeleteObject( wndPtr->hrgnUpdate );
557                                 wndPtr->hrgnUpdate = 0;
558                                 goto OUT;
559                             }
560                         }
561                         break;
562                 case 1: /* already an entire window */
563                         break;
564             }
565         }
566         else if( hRgn == 1 )
567         {
568             if( wndPtr->hrgnUpdate > 1 )
569                 DeleteObject( wndPtr->hrgnUpdate );
570             wndPtr->hrgnUpdate = 1;
571         }
572         else
573             hRgn = wndPtr->hrgnUpdate;  /* this is a trick that depends on code in PAINT_RedrawWindow() */
574
575         if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
576             QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
577
578         if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
579         if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
580         flags    |= RDW_FRAME;
581     }
582     else if( flags & RDW_VALIDATE )
583     {
584         if( wndPtr->hrgnUpdate )
585         {
586             if( hRgn > 1 )
587             {
588                 if( wndPtr->hrgnUpdate == 1 )
589                     wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
590
591                 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
592                     == NULLREGION )
593                     goto EMPTY;
594             }
595             else /* validate everything */
596             {
597                 if( wndPtr->hrgnUpdate > 1 )
598                 {
599 EMPTY:
600                     DeleteObject( wndPtr->hrgnUpdate );
601                 }
602                 wndPtr->hrgnUpdate = 0;
603             }
604
605             if( !wndPtr->hrgnUpdate )
606             {
607                 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
608                 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
609                     QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
610             }
611         }
612
613         if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
614         if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
615
616     }
617
618     if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
619         RDW_ValidateParent(wndPtr); /* validate parent covered by region */
620
621     /* in/validate child windows that intersect with the region if it
622      * is a valid handle. */
623
624     if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
625     {
626         if( hRgn > 1 && bChildren )
627         {
628             WND* wnd = wndPtr->child;
629             POINT ptTotal, prevOrigin = {0,0};
630             POINT ptClient;
631
632             ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
633             ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
634
635             for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
636             {
637                 if( wnd->dwStyle & WS_VISIBLE )
638                 {
639                     POINT ptOffset;
640
641                     r.left = wnd->rectWindow.left + ptClient.x;
642                     r.right = wnd->rectWindow.right + ptClient.x;
643                     r.top = wnd->rectWindow.top + ptClient.y;
644                     r.bottom = wnd->rectWindow.bottom + ptClient.y;
645
646                     ptOffset.x = r.left - prevOrigin.x; 
647                     ptOffset.y = r.top - prevOrigin.y;
648                     OffsetRect( &r, -ptTotal.x, -ptTotal.y );
649
650                     if( RectInRegion( hRgn, &r ) )
651                     {
652                         OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
653                         RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
654                         prevOrigin.x = r.left + ptTotal.x;
655                         prevOrigin.y = r.top + ptTotal.y;
656                         ptTotal.x += ptOffset.x;
657                         ptTotal.y += ptOffset.y;
658                     }
659                 }
660             }
661             OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
662             bChildren = 0;
663         }
664     }
665
666     /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
667
668     if( bChildren )
669     {
670         WND* wnd;
671         for( wnd = wndPtr->child; wnd; wnd = wnd->next )
672              if( wnd->dwStyle & WS_VISIBLE )
673                  RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
674     }
675
676 OUT:
677
678     /* Set/clear internal paint flag */
679
680     if (flags & RDW_INTERNALPAINT)
681     {
682         if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
683             QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
684         wndPtr->flags |= WIN_INTERNAL_PAINT;
685     }
686     else if (flags & RDW_NOINTERNALPAINT)
687     {
688         if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
689             QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
690         wndPtr->flags &= ~WIN_INTERNAL_PAINT;
691     }
692 }
693
694 /***********************************************************************
695  *           RDW_Paint [RedrawWindow() helper]
696  *
697  * Walks the window tree and paints/erases windows that have
698  * nonzero update regions according to redraw flags. hrgn is a scratch
699  * region passed down during recursion. Must not be 1.
700  *
701  */
702 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
703 {
704 /* NOTE: wndPtr is locked by caller.
705  * 
706  * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
707  * SendMessage() calls. This is a comment inside DefWindowProc() source
708  * from 16-bit SDK:
709  *
710  *   This message avoids lots of inter-app message traffic
711  *   by switching to the other task and continuing the
712  *   recursion there.
713  *
714  * wParam         = flags
715  * LOWORD(lParam) = hrgnClip
716  * HIWORD(lParam) = hwndSkip  (not used; always NULL)
717  *
718  */
719     HDC  hDC;
720     HWND hWnd = wndPtr->hwndSelf;
721     BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON)); 
722
723       /* Erase/update the window itself ... */
724
725     TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
726
727     /*
728      * Check if this window should delay it's processing of WM_NCPAINT.
729      * See WIN_HaveToDelayNCPAINT for a description of the mechanism
730      */
731     if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
732         ex |= RDW_EX_DELAY_NCPAINT;
733
734     if (flags & RDW_UPDATENOW)
735     {
736         if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
737             SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
738     }
739     else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
740     {
741         UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
742         HRGN hrgnRet;
743
744         hrgnRet = WIN_UpdateNCRgn(wndPtr, 
745                                   hrgn, 
746                                   UNC_REGION | UNC_CHECK | 
747                                   ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) |
748                                   ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) ); 
749
750         if( hrgnRet )
751         {
752             if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
753             if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
754             {
755                 if( bIcon ) dcx |= DCX_WINDOW;
756                 else 
757                 if( hrgnRet )
758                     OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left, 
759                                         wndPtr->rectWindow.top  - wndPtr->rectClient.top);
760                 else
761                     dcx &= ~DCX_INTERSECTRGN;
762                 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
763                 {
764                     if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
765                                        : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
766                     wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
767                     ReleaseDC( hWnd, hDC );
768                 }
769             }
770         }
771     }
772
773     if( !IsWindow(hWnd) ) return hrgn;
774     ex &= ~RDW_EX_TOPFRAME;
775
776       /* ... and its child windows */
777
778     if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) 
779         && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
780     {
781         WND** list, **ppWnd;
782
783         if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
784         {
785             wndPtr = NULL;
786             for (ppWnd = list; *ppWnd; ppWnd++)
787             {
788                 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
789                 if (!IsWindow(wndPtr->hwndSelf)) continue;
790                     if ( (wndPtr->dwStyle & WS_VISIBLE) &&
791                          (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
792                         hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
793             }
794             WIN_ReleaseWndPtr(wndPtr);
795             WIN_ReleaseWinArray(list);
796         }
797     }
798
799     return hrgn;
800 }
801
802 /***********************************************************************
803  *           PAINT_RedrawWindow
804  *
805  */
806 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
807                            HRGN hrgnUpdate, UINT flags, UINT ex )
808 {
809     HRGN hRgn = 0;
810     RECT r, r2;
811     POINT pt;
812     WND* wndPtr;
813
814     if (!hwnd) hwnd = GetDesktopWindow();
815     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
816
817     /* check if the window or its parents are visible/not minimized */
818
819     if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
820     {
821         WIN_ReleaseWndPtr(wndPtr);
822         return TRUE; 
823     }
824
825     if (TRACE_ON(win))
826     {
827         if( hrgnUpdate )
828         {
829             GetRgnBox( hrgnUpdate, &r );
830             TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n", 
831                   hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
832         }
833         else
834         {
835             if( rectUpdate )
836                 r = *rectUpdate;
837             else
838                 SetRectEmpty( &r );
839             TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
840                         hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left, 
841                         r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
842         }
843     }
844
845     /* prepare an update region in window coordinates */
846
847     if( flags & RDW_FRAME )
848         r = wndPtr->rectWindow;
849     else
850         r = wndPtr->rectClient;
851
852     if( ex & RDW_EX_XYWINDOW )
853     {
854         pt.x = pt.y = 0;
855         OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
856     }
857     else
858     {
859         pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
860         pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
861         OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
862     }
863
864     if (flags & RDW_INVALIDATE)  /* ------------------------- Invalidate */
865     {
866         /* If the window doesn't have hrgnUpdate we leave hRgn zero
867          * and put a new region straight into wndPtr->hrgnUpdate
868          * so that RDW_UpdateRgns() won't have to do any extra work.
869          */
870
871         if( hrgnUpdate )
872         {
873             if( wndPtr->hrgnUpdate )
874                 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
875             else 
876                 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt ); 
877         }
878         else if( rectUpdate )
879         {
880             if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
881             OffsetRect( &r2, pt.x, pt.y );
882
883 rect2i:
884             if( wndPtr->hrgnUpdate == 0 )
885                 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
886             else
887                 hRgn = CreateRectRgnIndirect( &r2 );
888         }
889         else /* entire window or client depending on RDW_FRAME */
890         {
891             if( flags & RDW_FRAME )
892             {
893                 if( wndPtr->hrgnUpdate )
894                     DeleteObject( wndPtr->hrgnUpdate );
895                 wndPtr->hrgnUpdate = 1;
896             }
897             else
898             {
899                 GETCLIENTRECTW( wndPtr, r2 );
900                 goto rect2i;
901             }
902         }
903     }
904     else if (flags & RDW_VALIDATE)  /* ------------------------- Validate */
905     {
906         /* In this we cannot leave with zero hRgn */
907         if( hrgnUpdate )
908         {
909             hRgn = REGION_CropRgn( hRgn, hrgnUpdate,  &r, &pt );
910             GetRgnBox( hRgn, &r2 );
911             if( IsRectEmpty( &r2 ) ) goto END;
912         }
913         else if( rectUpdate )
914         {
915             if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
916                 OffsetRect( &r2, pt.x, pt.y );
917 rect2v:
918             hRgn = CreateRectRgnIndirect( &r2 );
919         }
920         else /* entire window or client depending on RDW_FRAME */
921         {
922             if( flags & RDW_FRAME ) 
923                 hRgn = 1;
924             else
925             {
926                 GETCLIENTRECTW( wndPtr, r2 );
927                 goto rect2v;
928             }
929         }
930     }
931
932     /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
933
934     RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
935
936     /* Erase/update windows, from now on hRgn is a scratch region */
937
938     hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
939
940 END:
941     if( hRgn > 1 && (hRgn != hrgnUpdate) )
942         DeleteObject(hRgn );
943     WIN_ReleaseWndPtr(wndPtr);
944     return TRUE;
945 }
946
947
948 /***********************************************************************
949  *           RedrawWindow32    (USER32.426)
950  */
951 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
952                               HRGN hrgnUpdate, UINT flags )
953 {
954     return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
955 }
956
957
958 /***********************************************************************
959  *           RedrawWindow16    (USER.290)
960  */
961 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
962                               HRGN16 hrgnUpdate, UINT16 flags )
963 {
964     if (rectUpdate)
965     {
966         RECT r;
967         CONV_RECT16TO32( rectUpdate, &r );
968         return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
969     }
970     return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL, 
971                                        (HRGN)hrgnUpdate, flags, 0 );
972 }
973
974
975 /***********************************************************************
976  *           UpdateWindow16   (USER.124)
977  */
978 void WINAPI UpdateWindow16( HWND16 hwnd )
979 {
980     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
981 }
982
983 /***********************************************************************
984  *           UpdateWindow32   (USER32.567)
985  */
986 void WINAPI UpdateWindow( HWND hwnd )
987 {
988     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
989 }
990
991 /***********************************************************************
992  *           InvalidateRgn16   (USER.126)
993  */
994 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
995 {
996     PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn, 
997                        RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
998 }
999
1000
1001 /***********************************************************************
1002  *           InvalidateRgn32   (USER32.329)
1003  */
1004 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1005 {
1006     return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1007 }
1008
1009
1010 /***********************************************************************
1011  *           InvalidateRect16   (USER.125)
1012  */
1013 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1014 {
1015     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1016 }
1017
1018
1019 /***********************************************************************
1020  *           InvalidateRect32   (USER32.328)
1021  */
1022 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1023 {
1024     return PAINT_RedrawWindow( hwnd, rect, 0, 
1025                                RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1026 }
1027
1028
1029 /***********************************************************************
1030  *           ValidateRgn16   (USER.128)
1031  */
1032 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1033 {
1034     PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn, 
1035                         RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1036 }
1037
1038
1039 /***********************************************************************
1040  *           ValidateRgn32   (USER32.572)
1041  */
1042 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1043 {
1044     PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1045 }
1046
1047
1048 /***********************************************************************
1049  *           ValidateRect16   (USER.127)
1050  */
1051 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1052 {
1053     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1054 }
1055
1056
1057 /***********************************************************************
1058  *           ValidateRect32   (USER32.571)
1059  */
1060 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1061 {
1062     PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1063 }
1064
1065
1066 /***********************************************************************
1067  *           GetUpdateRect16   (USER.190)
1068  */
1069 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1070 {
1071     RECT r;
1072     BOOL16 ret;
1073
1074     if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1075     ret = GetUpdateRect( hwnd, &r, erase );
1076     CONV_RECT32TO16( &r, rect );
1077     return ret;
1078 }
1079
1080
1081 /***********************************************************************
1082  *           GetUpdateRect32   (USER32.297)
1083  */
1084 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1085 {
1086     BOOL retvalue;
1087     WND * wndPtr = WIN_FindWndPtr( hwnd );
1088     if (!wndPtr) return FALSE;
1089
1090     if (rect)
1091     {
1092         if (wndPtr->hrgnUpdate > 1)
1093         {
1094             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1095             if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1096             {
1097                 retvalue = FALSE;
1098                 goto END;
1099             }
1100             GetRgnBox( hrgn, rect );
1101             DeleteObject( hrgn );
1102             if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1103             {
1104                 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1105                 {
1106                     DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect,  2);
1107                 }
1108             }
1109         }
1110         else
1111         if( wndPtr->hrgnUpdate == 1 )
1112         {
1113             GetClientRect( hwnd, rect );
1114             if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1115         }
1116         else 
1117             SetRectEmpty( rect );
1118     }
1119     retvalue = (wndPtr->hrgnUpdate >= 1);
1120 END:
1121     WIN_ReleaseWndPtr(wndPtr);
1122     return retvalue;
1123 }
1124
1125
1126 /***********************************************************************
1127  *           GetUpdateRgn16   (USER.237)
1128  */
1129 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1130 {
1131     return GetUpdateRgn( hwnd, hrgn, erase );
1132 }
1133
1134
1135 /***********************************************************************
1136  *           GetUpdateRgn    (USER32.298)
1137  */
1138 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1139 {
1140     INT retval;
1141     WND * wndPtr = WIN_FindWndPtr( hwnd );
1142     if (!wndPtr) return ERROR;
1143
1144     if (wndPtr->hrgnUpdate == 0)
1145     {
1146         SetRectRgn( hrgn, 0, 0, 0, 0 );
1147         retval = NULLREGION;
1148         goto END;
1149     }
1150     else
1151     if (wndPtr->hrgnUpdate == 1)
1152     {
1153         SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1154                                 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1155         retval = SIMPLEREGION;
1156     }
1157     else
1158     {
1159         retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1160         OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1161                          wndPtr->rectWindow.top - wndPtr->rectClient.top );
1162     }
1163     if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1164 END:
1165     WIN_ReleaseWndPtr(wndPtr);
1166     return retval;
1167 }
1168
1169
1170 /***********************************************************************
1171  *           ExcludeUpdateRgn16   (USER.238)
1172  */
1173 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1174 {
1175     return ExcludeUpdateRgn( hdc, hwnd );
1176 }
1177
1178
1179 /***********************************************************************
1180  *           ExcludeUpdateRgn32   (USER32.195)
1181  */
1182 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1183 {
1184     RECT rect;
1185     WND * wndPtr;
1186
1187     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1188
1189     if (wndPtr->hrgnUpdate)
1190     {
1191         INT ret;
1192         HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1193                                       wndPtr->rectWindow.top - wndPtr->rectClient.top,
1194                                       wndPtr->rectWindow.right - wndPtr->rectClient.left,
1195                                       wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1196         if( wndPtr->hrgnUpdate > 1 )
1197         {
1198             CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1199             OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left, 
1200                             wndPtr->rectWindow.top - wndPtr->rectClient.top );
1201         }
1202
1203         /* do ugly coordinate translations in dce.c */
1204
1205         ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1206         DeleteObject( hrgn );
1207         WIN_ReleaseWndPtr(wndPtr);
1208         return ret;
1209     } 
1210     WIN_ReleaseWndPtr(wndPtr);
1211     return GetClipBox( hdc, &rect );
1212 }
1213
1214