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