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