Made access to the wnd struct thread-safe.
[wine] / windows / painting.c
1 /*
2  * Window painting functions
3  *
4  * Copyright 1993, 1994, 1995 Alexandre Julliard
5  *
6  * FIXME: Do not repaint full nonclient area all the time. Instead, compute 
7  *        intersection with hrgnUpdate (which should be moved from client to 
8  *        window coords as well, lookup 'the pain' comment in the winpos.c).
9  */
10
11 #include "win.h"
12 #include "queue.h"
13 #include "gdi.h"
14 #include "dce.h"
15 #include "heap.h"
16 #include "debug.h"
17 #include "wine/winuser16.h"
18
19   /* Last CTLCOLOR id */
20 #define CTLCOLOR_MAX   CTLCOLOR_STATIC
21
22 /***********************************************************************
23  *           WIN_UpdateNCArea
24  *
25  */
26 void WIN_UpdateNCArea(WND* wnd, BOOL bUpdate)
27 {
28     POINT16 pt = {0, 0}; 
29     HRGN hClip = 1;
30
31     TRACE(nonclient,"hwnd %04x, hrgnUpdate %04x\n", 
32                       wnd->hwndSelf, wnd->hrgnUpdate );
33
34     /* desktop window doesn't have nonclient area */
35     if(wnd == WIN_GetDesktop()) 
36     {
37         wnd->flags &= ~WIN_NEEDS_NCPAINT;
38         WIN_ReleaseDesktop();
39         return;
40     }
41     WIN_ReleaseDesktop();
42
43     if( wnd->hrgnUpdate > 1 )
44     {
45         ClientToScreen16(wnd->hwndSelf, &pt);
46
47         hClip = CreateRectRgn( 0, 0, 0, 0 );
48         if (!CombineRgn( hClip, wnd->hrgnUpdate, 0, RGN_COPY ))
49         {
50             DeleteObject(hClip);
51             hClip = 1;
52         }
53         else
54             OffsetRgn( hClip, pt.x, pt.y );
55
56         if (bUpdate)
57         {
58             /* exclude non-client area from update region */
59             HRGN hrgn = CreateRectRgn( 0, 0,
60                                  wnd->rectClient.right - wnd->rectClient.left,
61                                  wnd->rectClient.bottom - wnd->rectClient.top);
62
63             if (hrgn && (CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate,
64                                        hrgn, RGN_AND) == NULLREGION))
65             {
66                 DeleteObject( wnd->hrgnUpdate );
67                 wnd->hrgnUpdate = 1;
68             }
69
70             DeleteObject( hrgn );
71         }
72     }
73
74     wnd->flags &= ~WIN_NEEDS_NCPAINT;
75
76     if ((wnd->hwndSelf == GetActiveWindow()) &&
77         !(wnd->flags & WIN_NCACTIVATED))
78     {
79         wnd->flags |= WIN_NCACTIVATED;
80         if( hClip > 1) DeleteObject( hClip );
81         hClip = 1;
82     }
83
84     if (hClip) SendMessage16( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
85
86     if (hClip > 1) DeleteObject( hClip );
87 }
88
89
90 /***********************************************************************
91  *           BeginPaint16    (USER.39)
92  */
93 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps ) 
94 {
95     BOOL bIcon;
96     HRGN hrgnUpdate;
97     WND *wndPtr = WIN_FindWndPtr( hwnd );
98     if (!wndPtr) return 0;
99
100     bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
101
102     wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
103
104     if (wndPtr->flags & WIN_NEEDS_NCPAINT) WIN_UpdateNCArea( wndPtr, TRUE );
105
106     if (((hrgnUpdate = wndPtr->hrgnUpdate) != 0) ||
107         (wndPtr->flags & WIN_INTERNAL_PAINT))
108         QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
109
110     wndPtr->hrgnUpdate = 0;
111     wndPtr->flags &= ~WIN_INTERNAL_PAINT;
112
113     HideCaret( hwnd );
114
115     TRACE(win,"hrgnUpdate = %04x, \n", hrgnUpdate);
116
117     /* When bIcon is TRUE hrgnUpdate is automatically in window coordinates
118      * (because rectClient == rectWindow for WS_MINIMIZE windows).
119      */
120
121     if (wndPtr->class->style & CS_PARENTDC)
122     {
123         /* Don't clip the output to the update region for CS_PARENTDC window */
124         if(hrgnUpdate > 1)
125             DeleteObject(hrgnUpdate);
126         lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
127                               (bIcon ? DCX_WINDOW : 0) );
128     }
129     else
130     {
131         lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
132                              DCX_WINDOWPAINT | DCX_USESTYLE |
133                              (bIcon ? DCX_WINDOW : 0) );
134     }
135
136     TRACE(win,"hdc = %04x\n", lps->hdc);
137
138     if (!lps->hdc)
139     {
140         WARN(win, "GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
141         WIN_ReleaseWndPtr(wndPtr);
142         return 0;
143     }
144
145     GetClipBox16( lps->hdc, &lps->rcPaint );
146
147 TRACE(win,"box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
148                     lps->rcPaint.right, lps->rcPaint.bottom );
149
150     if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
151     {
152         wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
153         lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
154                                                    : WM_ERASEBKGND,
155                                      (WPARAM16)lps->hdc, 0 );
156     }
157     else lps->fErase = TRUE;
158
159     WIN_ReleaseWndPtr(wndPtr);
160     return lps->hdc;
161 }
162
163
164 /***********************************************************************
165  *           BeginPaint32    (USER32.10)
166  */
167 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
168 {
169     PAINTSTRUCT16 ps;
170
171     BeginPaint16( hwnd, &ps );
172     lps->hdc            = (HDC)ps.hdc;
173     lps->fErase         = ps.fErase;
174     lps->rcPaint.top    = ps.rcPaint.top;
175     lps->rcPaint.left   = ps.rcPaint.left;
176     lps->rcPaint.right  = ps.rcPaint.right;
177     lps->rcPaint.bottom = ps.rcPaint.bottom;
178     lps->fRestore       = ps.fRestore;
179     lps->fIncUpdate     = ps.fIncUpdate;
180     return lps->hdc;
181 }
182
183
184 /***********************************************************************
185  *           EndPaint16    (USER.40)
186  */
187 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
188 {
189     ReleaseDC16( hwnd, lps->hdc );
190     ShowCaret( hwnd );
191     return TRUE;
192 }
193
194
195 /***********************************************************************
196  *           EndPaint32    (USER32.176)
197  */
198 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
199 {
200     ReleaseDC( hwnd, lps->hdc );
201     ShowCaret( hwnd );
202     return TRUE;
203 }
204
205
206 /***********************************************************************
207  *           FillWindow    (USER.324)
208  */
209 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
210 {
211     RECT16 rect;
212     GetClientRect16( hwnd, &rect );
213     DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
214     PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
215 }
216
217
218 /***********************************************************************
219  *           PAINT_GetControlBrush
220  */
221 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
222 {
223     HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType, 
224                                                              (WPARAM)hDC, (LPARAM)hWnd );
225     if( !IsGDIObject16(bkgBrush) )
226         bkgBrush = DEFWND_ControlColor( hDC, ctlType );
227     return bkgBrush;
228 }
229
230
231 /***********************************************************************
232  *           PaintRect    (USER.325)
233  */
234 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
235                        HBRUSH16 hbrush, const RECT16 *rect)
236 {
237     if( hbrush <= CTLCOLOR_MAX ) 
238     {
239         if( hwndParent )
240             hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
241         else 
242             return;
243     }
244     if( hbrush ) 
245         FillRect16( hdc, rect, hbrush );
246 }
247
248
249 /***********************************************************************
250  *           GetControlBrush    (USER.326)
251  */
252 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
253 {
254     WND* wndPtr = WIN_FindWndPtr( hwnd );
255     HBRUSH16 retvalue;
256
257     if((ctlType <= CTLCOLOR_MAX) && wndPtr )
258     {
259         WND* parent;
260         if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
261         else parent = WIN_LockWndPtr(wndPtr->parent);
262         if( !parent ) parent = wndPtr;
263         retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
264         WIN_ReleaseWndPtr(parent);
265         goto END;
266     }
267     retvalue = (HBRUSH16)0;
268 END:
269     WIN_ReleaseWndPtr(wndPtr);
270     return retvalue;
271     }
272
273
274 /***********************************************************************
275  *           PAINT_RedrawWindow
276  *
277  * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
278  * SendMessage() calls. This is a comment inside DefWindowProc() source 
279  * from 16-bit SDK:
280  *
281  *   This message avoids lots of inter-app message traffic
282  *   by switching to the other task and continuing the
283  *   recursion there.
284  * 
285  * wParam         = flags
286  * LOWORD(lParam) = hrgnClip
287  * HIWORD(lParam) = hwndSkip  (not used; always NULL)
288  *
289  * All in all, a prime candidate for a rewrite.
290  */
291 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
292                            HRGN hrgnUpdate, UINT flags, UINT control )
293 {
294     BOOL bIcon;
295     HRGN hrgn;
296     RECT rectClient;
297     WND* wndPtr;
298     WND **list, **ppWnd;
299
300     if (!hwnd) hwnd = GetDesktopWindow();
301     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
302     if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
303     {
304         WIN_ReleaseWndPtr(wndPtr);
305         return TRUE;  /* No redraw needed */
306     }
307
308     bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
309     if (rectUpdate)
310     {
311         TRACE(win, "%04x %d,%d-%d,%d %04x flags=%04x\n",
312                     hwnd, rectUpdate->left, rectUpdate->top,
313                     rectUpdate->right, rectUpdate->bottom, hrgnUpdate, flags );
314     }
315     else
316     {
317         TRACE(win, "%04x NULL %04x flags=%04x\n", hwnd, hrgnUpdate, flags);
318     }
319
320     GetClientRect( hwnd, &rectClient );
321
322     if (flags & RDW_INVALIDATE)  /* Invalidate */
323     {
324         int rgnNotEmpty = COMPLEXREGION;
325
326         if (wndPtr->hrgnUpdate > 1)  /* Is there already an update region? */
327         {
328             if ((hrgn = hrgnUpdate) == 0)
329                 hrgn = CreateRectRgnIndirect( rectUpdate ? rectUpdate :
330                                                 &rectClient );
331             rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
332                                         hrgn, RGN_OR );
333             if (!hrgnUpdate) DeleteObject( hrgn );
334         }
335         else  /* No update region yet */
336         {
337             if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
338                 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
339             if (hrgnUpdate)
340             {
341                 wndPtr->hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
342                 rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, hrgnUpdate,
343                                             0, RGN_COPY );
344             }
345             else wndPtr->hrgnUpdate = CreateRectRgnIndirect( rectUpdate ?
346                                                     rectUpdate : &rectClient );
347         }
348         
349         if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
350
351         /* restrict update region to client area (FIXME: correct?) */
352         if (wndPtr->hrgnUpdate)
353         {
354             HRGN clientRgn = CreateRectRgnIndirect( &rectClient );
355             rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, clientRgn, 
356                                         wndPtr->hrgnUpdate, RGN_AND );
357             DeleteObject( clientRgn );
358         }
359
360         /* check for bogus update region */ 
361         if ( rgnNotEmpty == NULLREGION )
362            {
363              wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
364              DeleteObject( wndPtr->hrgnUpdate );
365              wndPtr->hrgnUpdate=0;
366              if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
367                    QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
368            }
369         else
370              if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
371         flags |= RDW_FRAME;  /* Force children frame invalidation */
372     }
373     else if (flags & RDW_VALIDATE)  /* Validate */
374     {
375           /* We need an update region in order to validate anything */
376         if (wndPtr->hrgnUpdate > 1)
377         {
378             if (!hrgnUpdate && !rectUpdate)
379             {
380                   /* Special case: validate everything */
381                 DeleteObject( wndPtr->hrgnUpdate );
382                 wndPtr->hrgnUpdate = 0;
383             }
384             else
385             {
386                 if ((hrgn = hrgnUpdate) == 0)
387                     hrgn = CreateRectRgnIndirect( rectUpdate );
388                 if (CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
389                                   hrgn, RGN_DIFF ) == NULLREGION)
390                 {
391                     DeleteObject( wndPtr->hrgnUpdate );
392                     wndPtr->hrgnUpdate = 0;
393                 }
394                 if (!hrgnUpdate) DeleteObject( hrgn );
395             }
396             if (!wndPtr->hrgnUpdate)  /* No more update region */
397                 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
398                     QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
399         }
400         if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
401         if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
402     }
403
404       /* Set/clear internal paint flag */
405
406     if (flags & RDW_INTERNALPAINT)
407     {
408         if ( wndPtr->hrgnUpdate <= 1 && !(wndPtr->flags & WIN_INTERNAL_PAINT))
409             QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
410         wndPtr->flags |= WIN_INTERNAL_PAINT;        
411     }
412     else if (flags & RDW_NOINTERNALPAINT)
413     {
414         if ( wndPtr->hrgnUpdate <= 1 && (wndPtr->flags & WIN_INTERNAL_PAINT))
415             QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
416         wndPtr->flags &= ~WIN_INTERNAL_PAINT;
417     }
418
419       /* Erase/update window */
420
421     if (flags & RDW_UPDATENOW)
422     {
423         if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
424             SendMessage16( hwnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
425     }
426     else if (flags & RDW_ERASENOW)
427     {
428         if (wndPtr->flags & WIN_NEEDS_NCPAINT)
429             WIN_UpdateNCArea( wndPtr, FALSE);
430
431         if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
432         {
433             HDC hdc = GetDCEx( hwnd, wndPtr->hrgnUpdate,
434                                    DCX_INTERSECTRGN | DCX_USESTYLE |
435                                    DCX_KEEPCLIPRGN | DCX_WINDOWPAINT |
436                                    (bIcon ? DCX_WINDOW : 0) );
437             if (hdc)
438             {
439                if (SendMessage16( hwnd, (bIcon) ? WM_ICONERASEBKGND
440                                                 : WM_ERASEBKGND,
441                                   (WPARAM16)hdc, 0 ))
442                   wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
443                ReleaseDC( hwnd, hdc );
444             }
445         }
446     }
447
448       /* Recursively process children */
449
450     if (!(flags & RDW_NOCHILDREN) &&
451         ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) &&
452         !(wndPtr->dwStyle & WS_MINIMIZE) )
453     {
454         if ( hrgnUpdate || rectUpdate )
455         {
456             if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 )))
457         {
458                 WIN_ReleaseWndPtr(wndPtr);
459                 return TRUE;
460             }
461            if( !hrgnUpdate )
462            {
463                 control |= (RDW_C_DELETEHRGN | RDW_C_USEHRGN);
464                 if( !(hrgnUpdate = CreateRectRgnIndirect( rectUpdate )) )
465                 {
466                     DeleteObject( hrgn );
467                     WIN_ReleaseWndPtr(wndPtr);
468                     return TRUE;
469                 }
470            }
471            if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
472            {
473                 for (ppWnd = list; *ppWnd; ppWnd++)
474                 {
475                     WIN_UpdateWndPtr(&wndPtr,*ppWnd);
476                     if (!IsWindow(wndPtr->hwndSelf)) continue;
477                     if (wndPtr->dwStyle & WS_VISIBLE)
478                     {
479                         SetRectRgn( hrgn, 
480                                 wndPtr->rectWindow.left, wndPtr->rectWindow.top, 
481                                 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom );
482                         if (CombineRgn( hrgn, hrgn, hrgnUpdate, RGN_AND ))
483                         {
484                             OffsetRgn( hrgn, -wndPtr->rectClient.left,
485                                         -wndPtr->rectClient.top );
486                             PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, hrgn, flags,
487                                          RDW_C_USEHRGN );
488                         }
489                     }
490                 }
491                 WIN_ReleaseWinArray(list);
492            }
493            DeleteObject( hrgn );
494            if (control & RDW_C_DELETEHRGN) DeleteObject( hrgnUpdate );
495         }
496         else
497         {
498             if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
499             {
500                 for (ppWnd = list; *ppWnd; ppWnd++)
501                 {
502                     WIN_UpdateWndPtr(&wndPtr,*ppWnd);
503                     if (IsWindow( wndPtr->hwndSelf ))
504                         PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, flags, 0 );
505                 }
506                 WIN_ReleaseWinArray(list);
507             }
508         }
509
510     }
511     WIN_ReleaseWndPtr(wndPtr);
512     return TRUE;
513 }
514
515
516 /***********************************************************************
517  *           RedrawWindow32    (USER32.426)
518  */
519 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
520                               HRGN hrgnUpdate, UINT flags )
521 {
522     return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
523 }
524
525
526 /***********************************************************************
527  *           RedrawWindow16    (USER.290)
528  */
529 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
530                               HRGN16 hrgnUpdate, UINT16 flags )
531 {
532     if (rectUpdate)
533     {
534         RECT r;
535         CONV_RECT16TO32( rectUpdate, &r );
536         return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
537     }
538     return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL, 
539                                        (HRGN)hrgnUpdate, flags, 0 );
540 }
541
542
543 /***********************************************************************
544  *           UpdateWindow16   (USER.124)
545  */
546 void WINAPI UpdateWindow16( HWND16 hwnd )
547 {
548     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
549 }
550
551 /***********************************************************************
552  *           UpdateWindow32   (USER32.567)
553  */
554 void WINAPI UpdateWindow( HWND hwnd )
555 {
556     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
557 }
558
559 /***********************************************************************
560  *           InvalidateRgn16   (USER.126)
561  */
562 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
563 {
564     PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn, 
565                        RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
566 }
567
568
569 /***********************************************************************
570  *           InvalidateRgn32   (USER32.329)
571  */
572 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
573 {
574     return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
575 }
576
577
578 /***********************************************************************
579  *           InvalidateRect16   (USER.125)
580  */
581 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
582 {
583     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
584 }
585
586
587 /***********************************************************************
588  *           InvalidateRect32   (USER32.328)
589  */
590 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
591 {
592     return PAINT_RedrawWindow( hwnd, rect, 0, 
593                                RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
594 }
595
596
597 /***********************************************************************
598  *           ValidateRgn16   (USER.128)
599  */
600 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
601 {
602     PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn, 
603                         RDW_VALIDATE | RDW_NOCHILDREN, 0 );
604 }
605
606
607 /***********************************************************************
608  *           ValidateRgn32   (USER32.572)
609  */
610 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
611 {
612     PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
613 }
614
615
616 /***********************************************************************
617  *           ValidateRect16   (USER.127)
618  */
619 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
620 {
621     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
622 }
623
624
625 /***********************************************************************
626  *           ValidateRect32   (USER32.571)
627  */
628 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
629 {
630     PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
631 }
632
633
634 /***********************************************************************
635  *           GetUpdateRect16   (USER.190)
636  */
637 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
638 {
639     RECT r;
640     BOOL16 ret;
641
642     if (!rect) return GetUpdateRect( hwnd, NULL, erase );
643     ret = GetUpdateRect( hwnd, &r, erase );
644     CONV_RECT32TO16( &r, rect );
645     return ret;
646 }
647
648
649 /***********************************************************************
650  *           GetUpdateRect32   (USER32.297)
651  */
652 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
653 {
654     BOOL retvalue;
655     WND * wndPtr = WIN_FindWndPtr( hwnd );
656     if (!wndPtr) return FALSE;
657
658     if (rect)
659     {
660         if (wndPtr->hrgnUpdate > 1)
661         {
662             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
663             if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
664             {
665                 retvalue = FALSE;
666                 goto END;
667             }
668             GetRgnBox( hrgn, rect );
669             DeleteObject( hrgn );
670             if (wndPtr->class->style & CS_OWNDC)
671             {
672                 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
673                 {
674                     DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect,  2);
675                 }
676             }
677         }
678         else SetRectEmpty( rect );
679     }
680     retvalue = (wndPtr->hrgnUpdate > 1);
681 END:
682     WIN_ReleaseWndPtr(wndPtr);
683     return retvalue;
684 }
685
686
687 /***********************************************************************
688  *           GetUpdateRgn16   (USER.237)
689  */
690 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
691 {
692     return GetUpdateRgn( hwnd, hrgn, erase );
693 }
694
695
696 /***********************************************************************
697  *           GetUpdateRgn32   (USER32.298)
698  */
699 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
700 {
701     INT retval;
702     WND * wndPtr = WIN_FindWndPtr( hwnd );
703     if (!wndPtr) return ERROR;
704
705     if (wndPtr->hrgnUpdate <= 1)
706     {
707         SetRectRgn( hrgn, 0, 0, 0, 0 );
708         retval = NULLREGION;
709         goto END;
710     }
711     retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
712     if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
713 END:
714     WIN_ReleaseWndPtr(wndPtr);
715     return retval;
716 }
717
718
719 /***********************************************************************
720  *           ExcludeUpdateRgn16   (USER.238)
721  */
722 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
723 {
724     return ExcludeUpdateRgn( hdc, hwnd );
725 }
726
727
728 /***********************************************************************
729  *           ExcludeUpdateRgn32   (USER32.195)
730  */
731 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
732 {
733     RECT rect;
734     WND * wndPtr;
735
736     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
737
738     if (wndPtr->hrgnUpdate)
739     {
740         INT ret;
741         HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
742                                       wndPtr->rectWindow.top - wndPtr->rectClient.top,
743                                       wndPtr->rectClient.right - wndPtr->rectClient.left,
744                                       wndPtr->rectClient.bottom - wndPtr->rectClient.top);
745         if( wndPtr->hrgnUpdate > 1 )
746             CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
747
748         /* do ugly coordinate translations in dce.c */
749
750         ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
751         DeleteObject( hrgn );
752         WIN_ReleaseWndPtr(wndPtr);
753         return ret;
754     } 
755     WIN_ReleaseWndPtr(wndPtr);
756     return GetClipBox( hdc, &rect );
757 }
758
759