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