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