Release 971130
[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 <stdio.h>
12 #include <X11/Xlib.h>
13
14 #include "win.h"
15 #include "queue.h"
16 #include "gdi.h"
17 #include "dce.h"
18 #include "heap.h"
19 #include "stddebug.h"
20 /* #define DEBUG_WIN */
21 #include "debug.h"
22
23   /* Last CTLCOLOR id */
24 #define CTLCOLOR_MAX   CTLCOLOR_STATIC
25
26 /***********************************************************************
27  *           WIN_UpdateNCArea
28  *
29  */
30 void WIN_UpdateNCArea(WND* wnd, BOOL32 bUpdate)
31 {
32     POINT16 pt = {0, 0}; 
33     HRGN32 hClip = 1;
34
35     dprintf_nonclient(stddeb,"NCUpdate: hwnd %04x, hrgnUpdate %04x\n", 
36                       wnd->hwndSelf, wnd->hrgnUpdate );
37
38     /* desktop window doesn't have nonclient area */
39     if(wnd == WIN_GetDesktop()) 
40     {
41         wnd->flags &= ~WIN_NEEDS_NCPAINT;
42         return;
43     }
44
45     if( wnd->hrgnUpdate > 1 )
46     {
47         ClientToScreen16(wnd->hwndSelf, &pt);
48
49         hClip = CreateRectRgn32( 0, 0, 0, 0 );
50         if (!CombineRgn32( hClip, wnd->hrgnUpdate, 0, RGN_COPY ))
51         {
52             DeleteObject32(hClip);
53             hClip = 1;
54         }
55         else
56             OffsetRgn32( hClip, pt.x, pt.y );
57
58         if (bUpdate)
59         {
60             /* exclude non-client area from update region */
61             HRGN32 hrgn = CreateRectRgn32( 0, 0,
62                                  wnd->rectClient.right - wnd->rectClient.left,
63                                  wnd->rectClient.bottom - wnd->rectClient.top);
64
65             if (hrgn && (CombineRgn32( wnd->hrgnUpdate, wnd->hrgnUpdate,
66                                        hrgn, RGN_AND) == NULLREGION))
67             {
68                 DeleteObject32( wnd->hrgnUpdate );
69                 wnd->hrgnUpdate = 1;
70             }
71
72             DeleteObject32( hrgn );
73         }
74     }
75
76     wnd->flags &= ~WIN_NEEDS_NCPAINT;
77
78     if ((wnd->hwndSelf == GetActiveWindow32()) &&
79         !(wnd->flags & WIN_NCACTIVATED))
80     {
81         wnd->flags |= WIN_NCACTIVATED;
82         if( hClip > 1) DeleteObject32( hClip );
83         hClip = 1;
84     }
85
86     if (hClip) SendMessage16( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
87
88     if (hClip > 1) DeleteObject32( hClip );
89 }
90
91
92 /***********************************************************************
93  *           BeginPaint16    (USER.39)
94  */
95 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps ) 
96 {
97     BOOL32 bIcon;
98     HRGN32 hrgnUpdate;
99     WND *wndPtr = WIN_FindWndPtr( hwnd );
100     if (!wndPtr) return 0;
101
102     bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
103
104     wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
105
106     if (wndPtr->flags & WIN_NEEDS_NCPAINT) WIN_UpdateNCArea( wndPtr, TRUE );
107
108     if (((hrgnUpdate = wndPtr->hrgnUpdate) != 0) ||
109         (wndPtr->flags & WIN_INTERNAL_PAINT))
110         QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
111
112     wndPtr->hrgnUpdate = 0;
113     wndPtr->flags &= ~WIN_INTERNAL_PAINT;
114
115     HideCaret32( hwnd );
116
117     dprintf_win(stddeb,"hrgnUpdate = %04x, ", hrgnUpdate);
118
119     /* When bIcon is TRUE hrgnUpdate is automatically in window coordinates
120      * (because rectClient == rectWindow for WS_MINIMIZE windows).
121      */
122
123     if (wndPtr->class->style & CS_PARENTDC)
124     {
125         /* Don't clip the output to the update region for CS_PARENTDC window */
126         if(hrgnUpdate > 1)
127             DeleteObject32(hrgnUpdate);
128         lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
129                               (bIcon ? DCX_WINDOW : 0) );
130     }
131     else
132     {
133         lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
134                              DCX_WINDOWPAINT | DCX_USESTYLE |
135                              (bIcon ? DCX_WINDOW : 0) );
136     }
137
138     dprintf_win(stddeb,"hdc = %04x\n", lps->hdc);
139
140     if (!lps->hdc)
141     {
142         fprintf(stderr, "GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
143         return 0;
144     }
145
146     GetRgnBox16( InquireVisRgn(lps->hdc), &lps->rcPaint );
147     DPtoLP16( lps->hdc, (LPPOINT16)&lps->rcPaint, 2 );
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     return lps->hdc;
159 }
160
161
162 /***********************************************************************
163  *           BeginPaint32    (USER32.9)
164  */
165 HDC32 WINAPI BeginPaint32( HWND32 hwnd, PAINTSTRUCT32 *lps )
166 {
167     PAINTSTRUCT16 ps;
168
169     BeginPaint16( hwnd, &ps );
170     lps->hdc            = (HDC32)ps.hdc;
171     lps->fErase         = ps.fErase;
172     lps->rcPaint.top    = ps.rcPaint.top;
173     lps->rcPaint.left   = ps.rcPaint.left;
174     lps->rcPaint.right  = ps.rcPaint.right;
175     lps->rcPaint.bottom = ps.rcPaint.bottom;
176     lps->fRestore       = ps.fRestore;
177     lps->fIncUpdate     = ps.fIncUpdate;
178     return lps->hdc;
179 }
180
181
182 /***********************************************************************
183  *           EndPaint16    (USER.40)
184  */
185 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
186 {
187     ReleaseDC16( hwnd, lps->hdc );
188     ShowCaret32( hwnd );
189     return TRUE;
190 }
191
192
193 /***********************************************************************
194  *           EndPaint32    (USER32.175)
195  */
196 BOOL32 WINAPI EndPaint32( HWND32 hwnd, const PAINTSTRUCT32 *lps )
197 {
198     ReleaseDC32( hwnd, lps->hdc );
199     ShowCaret32( hwnd );
200     return TRUE;
201 }
202
203
204 /***********************************************************************
205  *           FillWindow    (USER.324)
206  */
207 void WINAPI FillWindow( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
208 {
209     RECT16 rect;
210     GetClientRect16( hwnd, &rect );
211     DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
212     PaintRect( hwndParent, hwnd, hdc, hbrush, &rect );
213 }
214
215
216 /***********************************************************************
217  *           PAINT_GetControlBrush
218  */
219 static HBRUSH16 PAINT_GetControlBrush( HWND32 hParent, HWND32 hWnd, HDC16 hDC, UINT16 ctlType )
220 {
221     HBRUSH16 bkgBrush = (HBRUSH16)SendMessage32A( hParent, WM_CTLCOLORMSGBOX + ctlType, 
222                                                              (WPARAM32)hDC, (LPARAM)hWnd );
223     if( !IsGDIObject(bkgBrush) )
224         bkgBrush = DEFWND_ControlColor( hDC, ctlType );
225     return bkgBrush;
226 }
227
228
229 /***********************************************************************
230  *           PaintRect    (USER.325)
231  */
232 void WINAPI PaintRect( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
233                        HBRUSH16 hbrush, const RECT16 *rect)
234 {
235     if( hbrush <= CTLCOLOR_MAX ) 
236         if( hwndParent )
237             hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
238         else 
239             return;
240     if( hbrush ) 
241         FillRect16( hdc, rect, hbrush );
242 }
243
244
245 /***********************************************************************
246  *           GetControlBrush    (USER.326)
247  */
248 HBRUSH16 WINAPI GetControlBrush( 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 BOOL32 PAINT_RedrawWindow( HWND32 hwnd, const RECT32 *rectUpdate,
282                            HRGN32 hrgnUpdate, UINT32 flags, UINT32 control )
283 {
284     BOOL32 bIcon;
285     HRGN32 hrgn;
286     RECT32 rectClient;
287     WND* wndPtr;
288     WND **list, **ppWnd;
289
290     if (!hwnd) hwnd = GetDesktopWindow32();
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         dprintf_win(stddeb, "RedrawWindow: %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         dprintf_win(stddeb, "RedrawWindow: %04x NULL %04x flags=%04x\n",
305                      hwnd, hrgnUpdate, flags);
306     }
307
308     GetClientRect32( hwnd, &rectClient );
309
310     if (flags & RDW_INVALIDATE)  /* Invalidate */
311     {
312         int rgnNotEmpty = COMPLEXREGION;
313
314         if (wndPtr->hrgnUpdate > 1)  /* Is there already an update region? */
315         {
316             if ((hrgn = hrgnUpdate) == 0)
317                 hrgn = CreateRectRgnIndirect32( rectUpdate ? rectUpdate :
318                                                 &rectClient );
319             rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
320                                         hrgn, RGN_OR );
321             if (!hrgnUpdate) DeleteObject32( hrgn );
322         }
323         else  /* No update region yet */
324         {
325             if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
326                 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
327             if (hrgnUpdate)
328             {
329                 wndPtr->hrgnUpdate = CreateRectRgn32( 0, 0, 0, 0 );
330                 rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, hrgnUpdate,
331                                             0, RGN_COPY );
332             }
333             else wndPtr->hrgnUpdate = CreateRectRgnIndirect32( rectUpdate ?
334                                                     rectUpdate : &rectClient );
335         }
336         
337         if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
338
339         /* check for bogus update region */ 
340         if ( rgnNotEmpty == NULLREGION )
341            {
342              wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
343              DeleteObject32( wndPtr->hrgnUpdate );
344              wndPtr->hrgnUpdate=0;
345              if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
346                    QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
347            }
348         else
349              if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
350         flags |= RDW_FRAME;  /* Force children frame invalidation */
351     }
352     else if (flags & RDW_VALIDATE)  /* Validate */
353     {
354           /* We need an update region in order to validate anything */
355         if (wndPtr->hrgnUpdate > 1)
356         {
357             if (!hrgnUpdate && !rectUpdate)
358             {
359                   /* Special case: validate everything */
360                 DeleteObject32( wndPtr->hrgnUpdate );
361                 wndPtr->hrgnUpdate = 0;
362             }
363             else
364             {
365                 if ((hrgn = hrgnUpdate) == 0)
366                     hrgn = CreateRectRgnIndirect32( rectUpdate );
367                 if (CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
368                                   hrgn, RGN_DIFF ) == NULLREGION)
369                 {
370                     DeleteObject32( wndPtr->hrgnUpdate );
371                     wndPtr->hrgnUpdate = 0;
372                 }
373                 if (!hrgnUpdate) DeleteObject32( hrgn );
374             }
375             if (!wndPtr->hrgnUpdate)  /* No more update region */
376                 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
377                     QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
378         }
379         if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
380         if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
381     }
382
383       /* Set/clear internal paint flag */
384
385     if (flags & RDW_INTERNALPAINT)
386     {
387         if ( wndPtr->hrgnUpdate <= 1 && !(wndPtr->flags & WIN_INTERNAL_PAINT))
388             QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
389         wndPtr->flags |= WIN_INTERNAL_PAINT;        
390     }
391     else if (flags & RDW_NOINTERNALPAINT)
392     {
393         if ( wndPtr->hrgnUpdate <= 1 && (wndPtr->flags & WIN_INTERNAL_PAINT))
394             QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
395         wndPtr->flags &= ~WIN_INTERNAL_PAINT;
396     }
397
398       /* Erase/update window */
399
400     if (flags & RDW_UPDATENOW)
401     {
402         if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
403             SendMessage16( hwnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
404     }
405     else if (flags & RDW_ERASENOW)
406     {
407         if (wndPtr->flags & WIN_NEEDS_NCPAINT)
408             WIN_UpdateNCArea( wndPtr, FALSE);
409
410         if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
411         {
412             HDC32 hdc = GetDCEx32( hwnd, wndPtr->hrgnUpdate,
413                                    DCX_INTERSECTRGN | DCX_USESTYLE |
414                                    DCX_KEEPCLIPRGN | DCX_WINDOWPAINT |
415                                    (bIcon ? DCX_WINDOW : 0) );
416             if (hdc)
417             {
418                if (SendMessage16( hwnd, (bIcon) ? WM_ICONERASEBKGND
419                                                 : WM_ERASEBKGND,
420                                   (WPARAM16)hdc, 0 ))
421                   wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
422                ReleaseDC32( hwnd, hdc );
423             }
424         }
425     }
426
427       /* Recursively process children */
428
429     if (!(flags & RDW_NOCHILDREN) &&
430         ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) &&
431         !(wndPtr->dwStyle & WS_MINIMIZE) )
432     {
433         if ( hrgnUpdate || rectUpdate )
434         {
435            if (!(hrgn = CreateRectRgn32( 0, 0, 0, 0 ))) return TRUE;
436            if( !hrgnUpdate )
437            {
438                 control |= (RDW_C_DELETEHRGN | RDW_C_USEHRGN);
439                 if( !(hrgnUpdate = CreateRectRgnIndirect32( rectUpdate )) )
440                 {
441                     DeleteObject32( hrgn );
442                     return TRUE;
443                 }
444            }
445            if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
446            {
447                 for (ppWnd = list; *ppWnd; ppWnd++)
448                 {
449                     wndPtr = *ppWnd;
450                     if (!IsWindow32(wndPtr->hwndSelf)) continue;
451                     if (wndPtr->dwStyle & WS_VISIBLE)
452                     {
453                         SetRectRgn32( hrgn, 
454                                 wndPtr->rectWindow.left, wndPtr->rectWindow.top, 
455                                 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom );
456                         if (CombineRgn32( hrgn, hrgn, hrgnUpdate, RGN_AND ))
457                         {
458                             OffsetRgn32( hrgn, -wndPtr->rectClient.left,
459                                         -wndPtr->rectClient.top );
460                             PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, hrgn, flags,
461                                          RDW_C_USEHRGN );
462                         }
463                     }
464                 }
465                 HeapFree( SystemHeap, 0, list );
466            }
467            DeleteObject32( hrgn );
468            if (control & RDW_C_DELETEHRGN) DeleteObject32( hrgnUpdate );
469         }
470         else
471         {
472             if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
473             {
474                 for (ppWnd = list; *ppWnd; ppWnd++)
475                 {
476                     wndPtr = *ppWnd;
477                     if (IsWindow32( wndPtr->hwndSelf ))
478                         PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, flags, 0 );
479                 }
480                 HeapFree( SystemHeap, 0, list );
481             }
482         }
483
484     }
485     return TRUE;
486 }
487
488
489 /***********************************************************************
490  *           RedrawWindow32    (USER32.425)
491  */
492 BOOL32 WINAPI RedrawWindow32( HWND32 hwnd, const RECT32 *rectUpdate,
493                               HRGN32 hrgnUpdate, UINT32 flags )
494 {
495     return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
496 }
497
498
499 /***********************************************************************
500  *           RedrawWindow16    (USER.290)
501  */
502 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
503                               HRGN16 hrgnUpdate, UINT16 flags )
504 {
505     if (rectUpdate)
506     {
507         RECT32 r;
508         CONV_RECT16TO32( rectUpdate, &r );
509         return (BOOL16)RedrawWindow32( (HWND32)hwnd, &r, hrgnUpdate, flags );
510     }
511     return (BOOL16)PAINT_RedrawWindow( (HWND32)hwnd, NULL, 
512                                        (HRGN32)hrgnUpdate, flags, 0 );
513 }
514
515
516 /***********************************************************************
517  *           UpdateWindow16   (USER.124)
518  */
519 void WINAPI UpdateWindow16( HWND16 hwnd )
520 {
521     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
522 }
523
524 /***********************************************************************
525  *           UpdateWindow32   (USER32.566)
526  */
527 void WINAPI UpdateWindow32( HWND32 hwnd )
528 {
529     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
530 }
531
532 /***********************************************************************
533  *           InvalidateRgn16   (USER.126)
534  */
535 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
536 {
537     PAINT_RedrawWindow((HWND32)hwnd, NULL, (HRGN32)hrgn, 
538                        RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
539 }
540
541
542 /***********************************************************************
543  *           InvalidateRgn32   (USER32.328)
544  */
545 void WINAPI InvalidateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
546 {
547     PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
548 }
549
550
551 /***********************************************************************
552  *           InvalidateRect16   (USER.125)
553  */
554 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
555 {
556     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
557 }
558
559
560 /***********************************************************************
561  *           InvalidateRect32   (USER32.327)
562  */
563 void WINAPI InvalidateRect32( HWND32 hwnd, const RECT32 *rect, BOOL32 erase )
564 {
565     PAINT_RedrawWindow( hwnd, rect, 0, 
566                         RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
567 }
568
569
570 /***********************************************************************
571  *           ValidateRgn16   (USER.128)
572  */
573 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
574 {
575     PAINT_RedrawWindow( (HWND32)hwnd, NULL, (HRGN32)hrgn, 
576                         RDW_VALIDATE | RDW_NOCHILDREN, 0 );
577 }
578
579
580 /***********************************************************************
581  *           ValidateRgn32   (USER32.571)
582  */
583 void WINAPI ValidateRgn32( HWND32 hwnd, HRGN32 hrgn )
584 {
585     PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
586 }
587
588
589 /***********************************************************************
590  *           ValidateRect16   (USER.127)
591  */
592 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
593 {
594     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
595 }
596
597
598 /***********************************************************************
599  *           ValidateRect32   (USER32.570)
600  */
601 void WINAPI ValidateRect32( HWND32 hwnd, const RECT32 *rect )
602 {
603     PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
604 }
605
606
607 /***********************************************************************
608  *           GetUpdateRect16   (USER.190)
609  */
610 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
611 {
612     RECT32 r;
613     BOOL16 ret;
614
615     if (!rect) return GetUpdateRect32( hwnd, NULL, erase );
616     ret = GetUpdateRect32( hwnd, &r, erase );
617     CONV_RECT32TO16( &r, rect );
618     return ret;
619 }
620
621
622 /***********************************************************************
623  *           GetUpdateRect32   (USER32.296)
624  */
625 BOOL32 WINAPI GetUpdateRect32( HWND32 hwnd, LPRECT32 rect, BOOL32 erase )
626 {
627     WND * wndPtr = WIN_FindWndPtr( hwnd );
628     if (!wndPtr) return FALSE;
629
630     if (rect)
631     {
632         if (wndPtr->hrgnUpdate > 1)
633         {
634             HRGN32 hrgn = CreateRectRgn32( 0, 0, 0, 0 );
635             if (GetUpdateRgn32( hwnd, hrgn, erase ) == ERROR) return FALSE;
636             GetRgnBox32( hrgn, rect );
637             DeleteObject32( hrgn );
638         }
639         else SetRectEmpty32( rect );
640     }
641     return (wndPtr->hrgnUpdate > 1);
642 }
643
644
645 /***********************************************************************
646  *           GetUpdateRgn16   (USER.237)
647  */
648 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
649 {
650     return GetUpdateRgn32( hwnd, hrgn, erase );
651 }
652
653
654 /***********************************************************************
655  *           GetUpdateRgn32   (USER32.297)
656  */
657 INT32 WINAPI GetUpdateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
658 {
659     INT32 retval;
660     WND * wndPtr = WIN_FindWndPtr( hwnd );
661     if (!wndPtr) return ERROR;
662
663     if (wndPtr->hrgnUpdate <= 1)
664     {
665         SetRectRgn32( hrgn, 0, 0, 0, 0 );
666         return NULLREGION;
667     }
668     retval = CombineRgn32( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
669     if (erase) RedrawWindow32( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
670     return retval;
671 }
672
673
674 /***********************************************************************
675  *           ExcludeUpdateRgn16   (USER.238)
676  */
677 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
678 {
679     return ExcludeUpdateRgn32( hdc, hwnd );
680 }
681
682
683 /***********************************************************************
684  *           ExcludeUpdateRgn32   (USER32.194)
685  */
686 INT32 WINAPI ExcludeUpdateRgn32( HDC32 hdc, HWND32 hwnd )
687 {
688     RECT32 rect;
689     WND * wndPtr;
690
691     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
692
693     if (wndPtr->hrgnUpdate)
694     {
695         INT32 ret;
696         HRGN32 hrgn = CreateRectRgn32(wndPtr->rectWindow.left - wndPtr->rectClient.left,
697                                       wndPtr->rectWindow.top - wndPtr->rectClient.top,
698                                       wndPtr->rectClient.right - wndPtr->rectClient.left,
699                                       wndPtr->rectClient.bottom - wndPtr->rectClient.top);
700         if( wndPtr->hrgnUpdate > 1 )
701             CombineRgn32(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
702
703         /* do ugly coordinate translations in dce.c */
704
705         ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
706         DeleteObject32( hrgn );
707         return ret;
708     } 
709     return GetClipBox32( hdc, &rect );
710 }
711
712