2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
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).
20 /* #define DEBUG_WIN */
23 /* Last CTLCOLOR id */
24 #define CTLCOLOR_MAX CTLCOLOR_STATIC
26 /***********************************************************************
30 void WIN_UpdateNCArea(WND* wnd, BOOL32 bUpdate)
35 dprintf_nonclient(stddeb,"NCUpdate: hwnd %04x, hrgnUpdate %04x\n",
36 wnd->hwndSelf, wnd->hrgnUpdate );
38 /* desktop window doesn't have nonclient area */
39 if(wnd == WIN_GetDesktop())
41 wnd->flags &= ~WIN_NEEDS_NCPAINT;
45 if( wnd->hrgnUpdate > 1 )
47 ClientToScreen16(wnd->hwndSelf, &pt);
49 hClip = CreateRectRgn32( 0, 0, 0, 0 );
50 if (!CombineRgn32( hClip, wnd->hrgnUpdate, 0, RGN_COPY ))
52 DeleteObject32(hClip);
56 OffsetRgn32( hClip, pt.x, pt.y );
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);
65 if (hrgn && (CombineRgn32( wnd->hrgnUpdate, wnd->hrgnUpdate,
66 hrgn, RGN_AND) == NULLREGION))
68 DeleteObject32( wnd->hrgnUpdate );
72 DeleteObject32( hrgn );
76 wnd->flags &= ~WIN_NEEDS_NCPAINT;
78 if ((wnd->hwndSelf == GetActiveWindow32()) &&
79 !(wnd->flags & WIN_NCACTIVATED))
81 wnd->flags |= WIN_NCACTIVATED;
82 if( hClip > 1) DeleteObject32( hClip );
86 if (hClip) SendMessage16( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
88 if (hClip > 1) DeleteObject32( hClip );
92 /***********************************************************************
93 * BeginPaint16 (USER.39)
95 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
99 WND *wndPtr = WIN_FindWndPtr( hwnd );
100 if (!wndPtr) return 0;
102 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
104 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
106 if (wndPtr->flags & WIN_NEEDS_NCPAINT) WIN_UpdateNCArea( wndPtr, TRUE );
108 if (((hrgnUpdate = wndPtr->hrgnUpdate) != 0) ||
109 (wndPtr->flags & WIN_INTERNAL_PAINT))
110 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
112 wndPtr->hrgnUpdate = 0;
113 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
117 dprintf_win(stddeb,"hrgnUpdate = %04x, ", hrgnUpdate);
119 /* When bIcon is TRUE hrgnUpdate is automatically in window coordinates
120 * (because rectClient == rectWindow for WS_MINIMIZE windows).
123 if (wndPtr->class->style & CS_PARENTDC)
125 /* Don't clip the output to the update region for CS_PARENTDC window */
127 DeleteObject32(hrgnUpdate);
128 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
129 (bIcon ? DCX_WINDOW : 0) );
133 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
134 DCX_WINDOWPAINT | DCX_USESTYLE |
135 (bIcon ? DCX_WINDOW : 0) );
138 dprintf_win(stddeb,"hdc = %04x\n", lps->hdc);
142 fprintf(stderr, "GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
146 GetRgnBox16( InquireVisRgn(lps->hdc), &lps->rcPaint );
148 dprintf_win(stddeb,"box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
149 lps->rcPaint.right, lps->rcPaint.bottom );
151 DPtoLP16( lps->hdc, (LPPOINT16)&lps->rcPaint, 2 );
153 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
155 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
156 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
158 (WPARAM16)lps->hdc, 0 );
160 else lps->fErase = TRUE;
166 /***********************************************************************
167 * BeginPaint32 (USER32.9)
169 HDC32 WINAPI BeginPaint32( HWND32 hwnd, PAINTSTRUCT32 *lps )
173 BeginPaint16( hwnd, &ps );
174 lps->hdc = (HDC32)ps.hdc;
175 lps->fErase = ps.fErase;
176 lps->rcPaint.top = ps.rcPaint.top;
177 lps->rcPaint.left = ps.rcPaint.left;
178 lps->rcPaint.right = ps.rcPaint.right;
179 lps->rcPaint.bottom = ps.rcPaint.bottom;
180 lps->fRestore = ps.fRestore;
181 lps->fIncUpdate = ps.fIncUpdate;
186 /***********************************************************************
187 * EndPaint16 (USER.40)
189 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
191 ReleaseDC16( hwnd, lps->hdc );
197 /***********************************************************************
198 * EndPaint32 (USER32.175)
200 BOOL32 WINAPI EndPaint32( HWND32 hwnd, const PAINTSTRUCT32 *lps )
202 ReleaseDC32( hwnd, lps->hdc );
208 /***********************************************************************
209 * FillWindow (USER.324)
211 void WINAPI FillWindow( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
214 GetClientRect16( hwnd, &rect );
215 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
216 PaintRect( hwndParent, hwnd, hdc, hbrush, &rect );
220 /***********************************************************************
221 * PAINT_GetControlBrush
223 static HBRUSH16 PAINT_GetControlBrush( HWND32 hParent, HWND32 hWnd, HDC16 hDC, UINT16 ctlType )
225 HBRUSH16 bkgBrush = (HBRUSH16)SendMessage32A( hParent, WM_CTLCOLORMSGBOX + ctlType,
226 (WPARAM32)hDC, (LPARAM)hWnd );
227 if( !IsGDIObject(bkgBrush) )
228 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
233 /***********************************************************************
234 * PaintRect (USER.325)
236 void WINAPI PaintRect( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
237 HBRUSH16 hbrush, const RECT16 *rect)
239 if( hbrush <= CTLCOLOR_MAX )
241 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
245 FillRect16( hdc, rect, hbrush );
249 /***********************************************************************
250 * GetControlBrush (USER.326)
252 HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
254 WND* wndPtr = WIN_FindWndPtr( hwnd );
256 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
259 if( wndPtr->dwStyle & WS_POPUP ) parent = wndPtr->owner;
260 else parent = wndPtr->parent;
261 if( !parent ) parent = wndPtr;
262 return (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
268 /***********************************************************************
271 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
272 * SendMessage() calls. This is a comment inside DefWindowProc() source
275 * This message avoids lots of inter-app message traffic
276 * by switching to the other task and continuing the
280 * LOWORD(lParam) = hrgnClip
281 * HIWORD(lParam) = hwndSkip (not used; always NULL)
283 * All in all, a prime candidate for a rewrite.
285 BOOL32 PAINT_RedrawWindow( HWND32 hwnd, const RECT32 *rectUpdate,
286 HRGN32 hrgnUpdate, UINT32 flags, UINT32 control )
294 if (!hwnd) hwnd = GetDesktopWindow32();
295 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
296 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
297 return TRUE; /* No redraw needed */
299 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
302 dprintf_win(stddeb, "RedrawWindow: %04x %d,%d-%d,%d %04x flags=%04x\n",
303 hwnd, rectUpdate->left, rectUpdate->top,
304 rectUpdate->right, rectUpdate->bottom, hrgnUpdate, flags );
308 dprintf_win(stddeb, "RedrawWindow: %04x NULL %04x flags=%04x\n",
309 hwnd, hrgnUpdate, flags);
312 GetClientRect32( hwnd, &rectClient );
314 if (flags & RDW_INVALIDATE) /* Invalidate */
316 int rgnNotEmpty = COMPLEXREGION;
318 if (wndPtr->hrgnUpdate > 1) /* Is there already an update region? */
320 if ((hrgn = hrgnUpdate) == 0)
321 hrgn = CreateRectRgnIndirect32( rectUpdate ? rectUpdate :
323 rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
325 if (!hrgnUpdate) DeleteObject32( hrgn );
327 else /* No update region yet */
329 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
330 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
333 wndPtr->hrgnUpdate = CreateRectRgn32( 0, 0, 0, 0 );
334 rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, hrgnUpdate,
337 else wndPtr->hrgnUpdate = CreateRectRgnIndirect32( rectUpdate ?
338 rectUpdate : &rectClient );
341 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
343 /* restrict update region to client area (FIXME: correct?) */
344 if (wndPtr->hrgnUpdate)
346 HRGN32 clientRgn = CreateRectRgnIndirect32( &rectClient );
347 rgnNotEmpty = CombineRgn32( wndPtr->hrgnUpdate, clientRgn,
348 wndPtr->hrgnUpdate, RGN_AND );
349 DeleteObject32( clientRgn );
352 /* check for bogus update region */
353 if ( rgnNotEmpty == NULLREGION )
355 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
356 DeleteObject32( wndPtr->hrgnUpdate );
357 wndPtr->hrgnUpdate=0;
358 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
359 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
362 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
363 flags |= RDW_FRAME; /* Force children frame invalidation */
365 else if (flags & RDW_VALIDATE) /* Validate */
367 /* We need an update region in order to validate anything */
368 if (wndPtr->hrgnUpdate > 1)
370 if (!hrgnUpdate && !rectUpdate)
372 /* Special case: validate everything */
373 DeleteObject32( wndPtr->hrgnUpdate );
374 wndPtr->hrgnUpdate = 0;
378 if ((hrgn = hrgnUpdate) == 0)
379 hrgn = CreateRectRgnIndirect32( rectUpdate );
380 if (CombineRgn32( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate,
381 hrgn, RGN_DIFF ) == NULLREGION)
383 DeleteObject32( wndPtr->hrgnUpdate );
384 wndPtr->hrgnUpdate = 0;
386 if (!hrgnUpdate) DeleteObject32( hrgn );
388 if (!wndPtr->hrgnUpdate) /* No more update region */
389 if (!(wndPtr->flags & WIN_INTERNAL_PAINT))
390 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
392 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
393 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
396 /* Set/clear internal paint flag */
398 if (flags & RDW_INTERNALPAINT)
400 if ( wndPtr->hrgnUpdate <= 1 && !(wndPtr->flags & WIN_INTERNAL_PAINT))
401 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
402 wndPtr->flags |= WIN_INTERNAL_PAINT;
404 else if (flags & RDW_NOINTERNALPAINT)
406 if ( wndPtr->hrgnUpdate <= 1 && (wndPtr->flags & WIN_INTERNAL_PAINT))
407 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
408 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
411 /* Erase/update window */
413 if (flags & RDW_UPDATENOW)
415 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
416 SendMessage16( hwnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
418 else if (flags & RDW_ERASENOW)
420 if (wndPtr->flags & WIN_NEEDS_NCPAINT)
421 WIN_UpdateNCArea( wndPtr, FALSE);
423 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
425 HDC32 hdc = GetDCEx32( hwnd, wndPtr->hrgnUpdate,
426 DCX_INTERSECTRGN | DCX_USESTYLE |
427 DCX_KEEPCLIPRGN | DCX_WINDOWPAINT |
428 (bIcon ? DCX_WINDOW : 0) );
431 if (SendMessage16( hwnd, (bIcon) ? WM_ICONERASEBKGND
434 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
435 ReleaseDC32( hwnd, hdc );
440 /* Recursively process children */
442 if (!(flags & RDW_NOCHILDREN) &&
443 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) &&
444 !(wndPtr->dwStyle & WS_MINIMIZE) )
446 if ( hrgnUpdate || rectUpdate )
448 if (!(hrgn = CreateRectRgn32( 0, 0, 0, 0 ))) return TRUE;
451 control |= (RDW_C_DELETEHRGN | RDW_C_USEHRGN);
452 if( !(hrgnUpdate = CreateRectRgnIndirect32( rectUpdate )) )
454 DeleteObject32( hrgn );
458 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
460 for (ppWnd = list; *ppWnd; ppWnd++)
463 if (!IsWindow32(wndPtr->hwndSelf)) continue;
464 if (wndPtr->dwStyle & WS_VISIBLE)
467 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
468 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom );
469 if (CombineRgn32( hrgn, hrgn, hrgnUpdate, RGN_AND ))
471 OffsetRgn32( hrgn, -wndPtr->rectClient.left,
472 -wndPtr->rectClient.top );
473 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, hrgn, flags,
478 HeapFree( SystemHeap, 0, list );
480 DeleteObject32( hrgn );
481 if (control & RDW_C_DELETEHRGN) DeleteObject32( hrgnUpdate );
485 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
487 for (ppWnd = list; *ppWnd; ppWnd++)
490 if (IsWindow32( wndPtr->hwndSelf ))
491 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, flags, 0 );
493 HeapFree( SystemHeap, 0, list );
502 /***********************************************************************
503 * RedrawWindow32 (USER32.425)
505 BOOL32 WINAPI RedrawWindow32( HWND32 hwnd, const RECT32 *rectUpdate,
506 HRGN32 hrgnUpdate, UINT32 flags )
508 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
512 /***********************************************************************
513 * RedrawWindow16 (USER.290)
515 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
516 HRGN16 hrgnUpdate, UINT16 flags )
521 CONV_RECT16TO32( rectUpdate, &r );
522 return (BOOL16)RedrawWindow32( (HWND32)hwnd, &r, hrgnUpdate, flags );
524 return (BOOL16)PAINT_RedrawWindow( (HWND32)hwnd, NULL,
525 (HRGN32)hrgnUpdate, flags, 0 );
529 /***********************************************************************
530 * UpdateWindow16 (USER.124)
532 void WINAPI UpdateWindow16( HWND16 hwnd )
534 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
537 /***********************************************************************
538 * UpdateWindow32 (USER32.566)
540 void WINAPI UpdateWindow32( HWND32 hwnd )
542 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
545 /***********************************************************************
546 * InvalidateRgn16 (USER.126)
548 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
550 PAINT_RedrawWindow((HWND32)hwnd, NULL, (HRGN32)hrgn,
551 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
555 /***********************************************************************
556 * InvalidateRgn32 (USER32.328)
558 void WINAPI InvalidateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
560 PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
564 /***********************************************************************
565 * InvalidateRect16 (USER.125)
567 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
569 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
573 /***********************************************************************
574 * InvalidateRect32 (USER32.327)
576 void WINAPI InvalidateRect32( HWND32 hwnd, const RECT32 *rect, BOOL32 erase )
578 PAINT_RedrawWindow( hwnd, rect, 0,
579 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
583 /***********************************************************************
584 * ValidateRgn16 (USER.128)
586 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
588 PAINT_RedrawWindow( (HWND32)hwnd, NULL, (HRGN32)hrgn,
589 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
593 /***********************************************************************
594 * ValidateRgn32 (USER32.571)
596 void WINAPI ValidateRgn32( HWND32 hwnd, HRGN32 hrgn )
598 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
602 /***********************************************************************
603 * ValidateRect16 (USER.127)
605 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
607 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
611 /***********************************************************************
612 * ValidateRect32 (USER32.570)
614 void WINAPI ValidateRect32( HWND32 hwnd, const RECT32 *rect )
616 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
620 /***********************************************************************
621 * GetUpdateRect16 (USER.190)
623 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
628 if (!rect) return GetUpdateRect32( hwnd, NULL, erase );
629 ret = GetUpdateRect32( hwnd, &r, erase );
630 CONV_RECT32TO16( &r, rect );
635 /***********************************************************************
636 * GetUpdateRect32 (USER32.296)
638 BOOL32 WINAPI GetUpdateRect32( HWND32 hwnd, LPRECT32 rect, BOOL32 erase )
640 WND * wndPtr = WIN_FindWndPtr( hwnd );
641 if (!wndPtr) return FALSE;
645 if (wndPtr->hrgnUpdate > 1)
647 HRGN32 hrgn = CreateRectRgn32( 0, 0, 0, 0 );
648 if (GetUpdateRgn32( hwnd, hrgn, erase ) == ERROR) return FALSE;
649 GetRgnBox32( hrgn, rect );
650 DeleteObject32( hrgn );
652 else SetRectEmpty32( rect );
654 return (wndPtr->hrgnUpdate > 1);
658 /***********************************************************************
659 * GetUpdateRgn16 (USER.237)
661 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
663 return GetUpdateRgn32( hwnd, hrgn, erase );
667 /***********************************************************************
668 * GetUpdateRgn32 (USER32.297)
670 INT32 WINAPI GetUpdateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
673 WND * wndPtr = WIN_FindWndPtr( hwnd );
674 if (!wndPtr) return ERROR;
676 if (wndPtr->hrgnUpdate <= 1)
678 SetRectRgn32( hrgn, 0, 0, 0, 0 );
681 retval = CombineRgn32( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
682 if (erase) RedrawWindow32( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
687 /***********************************************************************
688 * ExcludeUpdateRgn16 (USER.238)
690 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
692 return ExcludeUpdateRgn32( hdc, hwnd );
696 /***********************************************************************
697 * ExcludeUpdateRgn32 (USER32.194)
699 INT32 WINAPI ExcludeUpdateRgn32( HDC32 hdc, HWND32 hwnd )
704 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
706 if (wndPtr->hrgnUpdate)
709 HRGN32 hrgn = CreateRectRgn32(wndPtr->rectWindow.left - wndPtr->rectClient.left,
710 wndPtr->rectWindow.top - wndPtr->rectClient.top,
711 wndPtr->rectClient.right - wndPtr->rectClient.left,
712 wndPtr->rectClient.bottom - wndPtr->rectClient.top);
713 if( wndPtr->hrgnUpdate > 1 )
714 CombineRgn32(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
716 /* do ugly coordinate translations in dce.c */
718 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
719 DeleteObject32( hrgn );
722 return GetClipBox32( hdc, &rect );