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