egcs 'ambiguous else' warnings fixes.
[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     {
234         if( hwndParent )
235             hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
236         else 
237             return;
238     }
239     if( hbrush ) 
240         FillRect16( hdc, rect, hbrush );
241 }
242
243
244 /***********************************************************************
245  *           GetControlBrush    (USER.326)
246  */
247 HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
248 {
249     WND* wndPtr = WIN_FindWndPtr( hwnd );
250
251     if((ctlType <= CTLCOLOR_MAX) && wndPtr )
252     {
253         WND* parent;
254         if( wndPtr->dwStyle & WS_POPUP ) parent = wndPtr->owner;
255         else parent = wndPtr->parent;
256         if( !parent ) parent = wndPtr;
257         return (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
258     }
259     return (HBRUSH16)0;
260 }
261
262
263 /***********************************************************************
264  *           PAINT_RedrawWindow
265  *
266  * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
267  * SendMessage() calls. This is a comment inside DefWindowProc() source 
268  * from 16-bit SDK:
269  *
270  *   This message avoids lots of inter-app message traffic
271  *   by switching to the other task and continuing the
272  *   recursion there.
273  * 
274  * wParam         = flags
275  * LOWORD(lParam) = hrgnClip
276  * HIWORD(lParam) = hwndSkip  (not used; always NULL)
277  *
278  * All in all, a prime candidate for a rewrite.
279  */
280 BOOL32 PAINT_RedrawWindow( HWND32 hwnd, const RECT32 *rectUpdate,
281                            HRGN32 hrgnUpdate, UINT32 flags, UINT32 control )
282 {
283     BOOL32 bIcon;
284     HRGN32 hrgn;
285     RECT32 rectClient;
286     WND* wndPtr;
287     WND **list, **ppWnd;
288
289     if (!hwnd) hwnd = GetDesktopWindow32();
290     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
291     if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
292         return TRUE;  /* No redraw needed */
293
294     bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
295     if (rectUpdate)
296     {
297         TRACE(win, "%04x %d,%d-%d,%d %04x flags=%04x\n",
298                     hwnd, rectUpdate->left, rectUpdate->top,
299                     rectUpdate->right, rectUpdate->bottom, hrgnUpdate, flags );
300     }
301     else
302     {
303         TRACE(win, "%04x NULL %04x flags=%04x\n", hwnd, hrgnUpdate, flags);
304     }
305
306     GetClientRect32( hwnd, &rectClient );
307
308     if (flags & RDW_INVALIDATE)  /* Invalidate */
309     {
310         int rgnNotEmpty = COMPLEXREGION;
311
312         if (wndPtr->hrgnUpdate > 1)  /* Is there already an update region? */
313         {
314             if ((hrgn = hrgnUpdate) == 0)
315                 hrgn = CreateRectRgnIndirect32( rectUpdate ? rectUpdate :
316                                                 &rectClient );
317             rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
318                                         hrgn, RGN_OR );
319             if (!hrgnUpdate) DeleteObject32( hrgn );
320         }
321         else  /* No update region yet */
322         {
323             if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
324                 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
325             if (hrgnUpdate)
326             {
327                 wndPtr->hrgnUpdate = CreateRectRgn32( 0, 0, 0, 0 );
328                 rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, hrgnUpdate,
329                                             0, RGN_COPY );
330             }
331             else wndPtr->hrgnUpdate = CreateRectRgnIndirect32( rectUpdate ?
332                                                     rectUpdate : &rectClient );
333         }
334         
335         if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
336
337         /* restrict update region to client area (FIXME: correct?) */
338         if (wndPtr->hrgnUpdate)
339         {
340             HRGN32 clientRgn = CreateRectRgnIndirect32( &rectClient );
341             rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, clientRgn, 
342                                         wndPtr->hrgnUpdate, RGN_AND );
343             DeleteObject32( clientRgn );
344         }
345
346         /* check for bogus update region */ 
347         if ( rgnNotEmpty == NULLREGION )
348            {
349              wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
350              DeleteObject32( wndPtr->hrgnUpdate );
351              wndPtr->hrgnUpdate=0;
352              if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
353                    QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
354            }
355         else
356              if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
357         flags |= RDW_FRAME;  /* Force children frame invalidation */
358     }
359     else if (flags & RDW_VALIDATE)  /* Validate */
360     {
361           /* We need an update region in order to validate anything */
362         if (wndPtr->hrgnUpdate > 1)
363         {
364             if (!hrgnUpdate && !rectUpdate)
365             {
366                   /* Special case: validate everything */
367                 DeleteObject32( wndPtr->hrgnUpdate );
368                 wndPtr->hrgnUpdate = 0;
369             }
370             else
371             {
372                 if ((hrgn = hrgnUpdate) == 0)
373                     hrgn = CreateRectRgnIndirect32( rectUpdate );
374                 if (CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
375                                   hrgn, RGN_DIFF ) == NULLREGION)
376                 {
377                     DeleteObject32( wndPtr->hrgnUpdate );
378                     wndPtr->hrgnUpdate = 0;
379                 }
380                 if (!hrgnUpdate) DeleteObject32( hrgn );
381             }
382             if (!wndPtr->hrgnUpdate)  /* No more update region */
383                 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
384                     QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
385         }
386         if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
387         if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
388     }
389
390       /* Set/clear internal paint flag */
391
392     if (flags & RDW_INTERNALPAINT)
393     {
394         if ( wndPtr->hrgnUpdate <= 1 && !(wndPtr->flags & WIN_INTERNAL_PAINT))
395             QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
396         wndPtr->flags |= WIN_INTERNAL_PAINT;        
397     }
398     else if (flags & RDW_NOINTERNALPAINT)
399     {
400         if ( wndPtr->hrgnUpdate <= 1 && (wndPtr->flags & WIN_INTERNAL_PAINT))
401             QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
402         wndPtr->flags &= ~WIN_INTERNAL_PAINT;
403     }
404
405       /* Erase/update window */
406
407     if (flags & RDW_UPDATENOW)
408     {
409         if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
410             SendMessage16( hwnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
411     }
412     else if (flags & RDW_ERASENOW)
413     {
414         if (wndPtr->flags & WIN_NEEDS_NCPAINT)
415             WIN_UpdateNCArea( wndPtr, FALSE);
416
417         if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
418         {
419             HDC32 hdc = GetDCEx32( hwnd, wndPtr->hrgnUpdate,
420                                    DCX_INTERSECTRGN | DCX_USESTYLE |
421                                    DCX_KEEPCLIPRGN | DCX_WINDOWPAINT |
422                                    (bIcon ? DCX_WINDOW : 0) );
423             if (hdc)
424             {
425                if (SendMessage16( hwnd, (bIcon) ? WM_ICONERASEBKGND
426                                                 : WM_ERASEBKGND,
427                                   (WPARAM16)hdc, 0 ))
428                   wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
429                ReleaseDC32( hwnd, hdc );
430             }
431         }
432     }
433
434       /* Recursively process children */
435
436     if (!(flags & RDW_NOCHILDREN) &&
437         ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) &&
438         !(wndPtr->dwStyle & WS_MINIMIZE) )
439     {
440         if ( hrgnUpdate || rectUpdate )
441         {
442            if (!(hrgn = CreateRectRgn32( 0, 0, 0, 0 ))) return TRUE;
443            if( !hrgnUpdate )
444            {
445                 control |= (RDW_C_DELETEHRGN | RDW_C_USEHRGN);
446                 if( !(hrgnUpdate = CreateRectRgnIndirect32( rectUpdate )) )
447                 {
448                     DeleteObject32( hrgn );
449                     return TRUE;
450                 }
451            }
452            if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
453            {
454                 for (ppWnd = list; *ppWnd; ppWnd++)
455                 {
456                     wndPtr = *ppWnd;
457                     if (!IsWindow32(wndPtr->hwndSelf)) continue;
458                     if (wndPtr->dwStyle & WS_VISIBLE)
459                     {
460                         SetRectRgn32( hrgn, 
461                                 wndPtr->rectWindow.left, wndPtr->rectWindow.top, 
462                                 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom );
463                         if (CombineRgn32( hrgn, hrgn, hrgnUpdate, RGN_AND ))
464                         {
465                             OffsetRgn32( hrgn, -wndPtr->rectClient.left,
466                                         -wndPtr->rectClient.top );
467                             PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, hrgn, flags,
468                                          RDW_C_USEHRGN );
469                         }
470                     }
471                 }
472                 HeapFree( SystemHeap, 0, list );
473            }
474            DeleteObject32( hrgn );
475            if (control & RDW_C_DELETEHRGN) DeleteObject32( hrgnUpdate );
476         }
477         else
478         {
479             if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
480             {
481                 for (ppWnd = list; *ppWnd; ppWnd++)
482                 {
483                     wndPtr = *ppWnd;
484                     if (IsWindow32( wndPtr->hwndSelf ))
485                         PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, flags, 0 );
486                 }
487                 HeapFree( SystemHeap, 0, list );
488             }
489         }
490
491     }
492     return TRUE;
493 }
494
495
496 /***********************************************************************
497  *           RedrawWindow32    (USER32.426)
498  */
499 BOOL32 WINAPI RedrawWindow32( HWND32 hwnd, const RECT32 *rectUpdate,
500                               HRGN32 hrgnUpdate, UINT32 flags )
501 {
502     return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
503 }
504
505
506 /***********************************************************************
507  *           RedrawWindow16    (USER.290)
508  */
509 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
510                               HRGN16 hrgnUpdate, UINT16 flags )
511 {
512     if (rectUpdate)
513     {
514         RECT32 r;
515         CONV_RECT16TO32( rectUpdate, &r );
516         return (BOOL16)RedrawWindow32( (HWND32)hwnd, &r, hrgnUpdate, flags );
517     }
518     return (BOOL16)PAINT_RedrawWindow( (HWND32)hwnd, NULL, 
519                                        (HRGN32)hrgnUpdate, flags, 0 );
520 }
521
522
523 /***********************************************************************
524  *           UpdateWindow16   (USER.124)
525  */
526 void WINAPI UpdateWindow16( HWND16 hwnd )
527 {
528     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
529 }
530
531 /***********************************************************************
532  *           UpdateWindow32   (USER32.567)
533  */
534 void WINAPI UpdateWindow32( HWND32 hwnd )
535 {
536     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
537 }
538
539 /***********************************************************************
540  *           InvalidateRgn16   (USER.126)
541  */
542 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
543 {
544     PAINT_RedrawWindow((HWND32)hwnd, NULL, (HRGN32)hrgn, 
545                        RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
546 }
547
548
549 /***********************************************************************
550  *           InvalidateRgn32   (USER32.329)
551  */
552 void WINAPI InvalidateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
553 {
554     PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
555 }
556
557
558 /***********************************************************************
559  *           InvalidateRect16   (USER.125)
560  */
561 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
562 {
563     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
564 }
565
566
567 /***********************************************************************
568  *           InvalidateRect32   (USER32.328)
569  */
570 void WINAPI InvalidateRect32( HWND32 hwnd, const RECT32 *rect, BOOL32 erase )
571 {
572     PAINT_RedrawWindow( hwnd, rect, 0, 
573                         RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
574 }
575
576
577 /***********************************************************************
578  *           ValidateRgn16   (USER.128)
579  */
580 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
581 {
582     PAINT_RedrawWindow( (HWND32)hwnd, NULL, (HRGN32)hrgn, 
583                         RDW_VALIDATE | RDW_NOCHILDREN, 0 );
584 }
585
586
587 /***********************************************************************
588  *           ValidateRgn32   (USER32.572)
589  */
590 void WINAPI ValidateRgn32( HWND32 hwnd, HRGN32 hrgn )
591 {
592     PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
593 }
594
595
596 /***********************************************************************
597  *           ValidateRect16   (USER.127)
598  */
599 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
600 {
601     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
602 }
603
604
605 /***********************************************************************
606  *           ValidateRect32   (USER32.571)
607  */
608 void WINAPI ValidateRect32( HWND32 hwnd, const RECT32 *rect )
609 {
610     PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
611 }
612
613
614 /***********************************************************************
615  *           GetUpdateRect16   (USER.190)
616  */
617 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
618 {
619     RECT32 r;
620     BOOL16 ret;
621
622     if (!rect) return GetUpdateRect32( hwnd, NULL, erase );
623     ret = GetUpdateRect32( hwnd, &r, erase );
624     CONV_RECT32TO16( &r, rect );
625     return ret;
626 }
627
628
629 /***********************************************************************
630  *           GetUpdateRect32   (USER32.297)
631  */
632 BOOL32 WINAPI GetUpdateRect32( HWND32 hwnd, LPRECT32 rect, BOOL32 erase )
633 {
634     WND * wndPtr = WIN_FindWndPtr( hwnd );
635     if (!wndPtr) return FALSE;
636
637     if (rect)
638     {
639         if (wndPtr->hrgnUpdate > 1)
640         {
641             HRGN32 hrgn = CreateRectRgn32( 0, 0, 0, 0 );
642             if (GetUpdateRgn32( hwnd, hrgn, erase ) == ERROR) return FALSE;
643             GetRgnBox32( hrgn, rect );
644             DeleteObject32( hrgn );
645         }
646         else SetRectEmpty32( rect );
647     }
648     return (wndPtr->hrgnUpdate > 1);
649 }
650
651
652 /***********************************************************************
653  *           GetUpdateRgn16   (USER.237)
654  */
655 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
656 {
657     return GetUpdateRgn32( hwnd, hrgn, erase );
658 }
659
660
661 /***********************************************************************
662  *           GetUpdateRgn32   (USER32.298)
663  */
664 INT32 WINAPI GetUpdateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
665 {
666     INT32 retval;
667     WND * wndPtr = WIN_FindWndPtr( hwnd );
668     if (!wndPtr) return ERROR;
669
670     if (wndPtr->hrgnUpdate <= 1)
671     {
672         SetRectRgn32( hrgn, 0, 0, 0, 0 );
673         return NULLREGION;
674     }
675     retval = CombineRgn32( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
676     if (erase) RedrawWindow32( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
677     return retval;
678 }
679
680
681 /***********************************************************************
682  *           ExcludeUpdateRgn16   (USER.238)
683  */
684 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
685 {
686     return ExcludeUpdateRgn32( hdc, hwnd );
687 }
688
689
690 /***********************************************************************
691  *           ExcludeUpdateRgn32   (USER32.195)
692  */
693 INT32 WINAPI ExcludeUpdateRgn32( HDC32 hdc, HWND32 hwnd )
694 {
695     RECT32 rect;
696     WND * wndPtr;
697
698     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
699
700     if (wndPtr->hrgnUpdate)
701     {
702         INT32 ret;
703         HRGN32 hrgn = CreateRectRgn32(wndPtr->rectWindow.left - wndPtr->rectClient.left,
704                                       wndPtr->rectWindow.top - wndPtr->rectClient.top,
705                                       wndPtr->rectClient.right - wndPtr->rectClient.left,
706                                       wndPtr->rectClient.bottom - wndPtr->rectClient.top);
707         if( wndPtr->hrgnUpdate > 1 )
708             CombineRgn32(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
709
710         /* do ugly coordinate translations in dce.c */
711
712         ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
713         DeleteObject32( hrgn );
714         return ret;
715     } 
716     return GetClipBox32( hdc, &rect );
717 }
718
719