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