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