Revert last change in window activation on mouse click.
[wine/dcerpc.git] / windows / painting.c
blob569c3bf98d5928731d526b554e23a1248da96594
1 /*
2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1999 Alex Korobka
6 */
8 #include "region.h"
9 #include "win.h"
10 #include "queue.h"
11 #include "dce.h"
12 #include "heap.h"
13 #include "debugtools.h"
14 #include "wine/winuser16.h"
16 DECLARE_DEBUG_CHANNEL(nonclient)
17 DECLARE_DEBUG_CHANNEL(win)
19 /* client rect in window coordinates */
21 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
22 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
23 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
24 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
26 /* Last CTLCOLOR id */
27 #define CTLCOLOR_MAX CTLCOLOR_STATIC
30 /***********************************************************************
31 * WIN_UpdateNCRgn
33 * Things to do:
34 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
35 * Crop hrgnUpdate to a client rect, especially if it 1.
36 * If UNC_REGION is set return update region for the client rect.
38 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
39 * The trick is that when the returned region handle may be different from hRgn.
40 * In this case the old hRgn must be considered gone. BUT, if the returned value
41 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
42 * a DC without extra clipping region.
44 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
46 RECT r;
47 HRGN hClip = 0;
48 HRGN hrgnRet = 0;
50 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
51 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
53 /* desktop window doesn't have a nonclient area */
54 if(wnd == WIN_GetDesktop())
56 wnd->flags &= ~WIN_NEEDS_NCPAINT;
57 if( wnd->hrgnUpdate > 1 )
58 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
59 else
61 hrgnRet = wnd->hrgnUpdate;
63 WIN_ReleaseDesktop();
64 return hrgnRet;
66 WIN_ReleaseDesktop();
68 if ((wnd->hwndSelf == GetForegroundWindow()) &&
69 !(wnd->flags & WIN_NCACTIVATED) )
71 wnd->flags |= WIN_NCACTIVATED;
72 uncFlags |= UNC_ENTIRE;
75 if( wnd->flags & WIN_NEEDS_NCPAINT )
77 RECT r2, r3;
79 wnd->flags &= ~WIN_NEEDS_NCPAINT;
80 GETCLIENTRECTW( wnd, r );
82 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
83 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
84 if( wnd->hrgnUpdate > 1 )
86 /* Check if update rgn overlaps with nonclient area */
88 GetRgnBox( wnd->hrgnUpdate, &r2 );
89 UnionRect( &r3, &r2, &r );
90 if( r3.left != r.left || r3.top != r.top ||
91 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
93 /* crop hrgnUpdate, save old one in hClip - the only
94 * case that places a valid region handle in hClip */
96 hClip = wnd->hrgnUpdate;
97 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
98 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
101 if( uncFlags & UNC_CHECK )
103 GetRgnBox( wnd->hrgnUpdate, &r3 );
104 if( IsRectEmpty( &r3 ) )
106 /* delete the update region since all invalid
107 * parts were in the nonclient area */
109 DeleteObject( wnd->hrgnUpdate );
110 wnd->hrgnUpdate = 0;
111 if(!(wnd->flags & WIN_INTERNAL_PAINT))
112 QUEUE_DecPaintCount( wnd->hmemTaskQ );
114 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
118 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
120 else
121 if( wnd->hrgnUpdate == 1 )/* entire window */
123 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
124 if( uncFlags & UNC_REGION ) hrgnRet = 1;
125 uncFlags |= UNC_ENTIRE;
128 else /* no WM_NCPAINT unless forced */
130 if( wnd->hrgnUpdate > 1 )
132 copyrgn:
133 if( uncFlags & UNC_REGION )
134 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
136 else
137 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
139 GETCLIENTRECTW( wnd, r );
140 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
141 if( uncFlags & UNC_REGION ) hrgnRet = 1;
145 if(!hClip && (uncFlags & UNC_ENTIRE) )
147 /* still don't do anything if there is no nonclient area */
148 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
151 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
153 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
154 if( (hClip > 1)&& (hClip != hRgn) && (hClip != hrgnRet) ) DeleteObject( hClip );
156 * Since all Window locks are suspended while processing the WM_NCPAINT
157 * we want to make sure the window still exists before continuing.
159 if (!IsWindow(wnd->hwndSelf))
161 DeleteObject(hrgnRet);
162 hrgnRet=0;
166 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
168 return hrgnRet;
172 /***********************************************************************
173 * BeginPaint16 (USER.39)
175 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
177 BOOL bIcon;
178 HRGN hrgnUpdate;
179 WND *wndPtr = WIN_FindWndPtr( hwnd );
180 if (!wndPtr) return 0;
182 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
184 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
186 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
187 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE );
190 * Make sure the window is still a window. All window locks are suspended
191 * when the WM_NCPAINT is sent.
193 if (!IsWindow(wndPtr->hwndSelf))
195 WIN_ReleaseWndPtr(wndPtr);
196 return 0;
199 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
200 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
202 wndPtr->hrgnUpdate = 0;
203 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
205 HideCaret( hwnd );
207 TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
209 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
211 /* Don't clip the output to the update region for CS_PARENTDC window */
212 if( hrgnUpdate )
213 DeleteObject(hrgnUpdate);
214 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
215 (bIcon ? DCX_WINDOW : 0) );
217 else
219 if( hrgnUpdate ) /* convert to client coordinates */
220 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
221 wndPtr->rectWindow.top - wndPtr->rectClient.top );
222 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
223 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
224 /* ReleaseDC() in EndPaint() will delete the region */
227 TRACE_(win)("hdc = %04x\n", lps->hdc);
229 if (!lps->hdc)
231 WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
232 WIN_ReleaseWndPtr(wndPtr);
233 return 0;
236 GetClipBox16( lps->hdc, &lps->rcPaint );
238 TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
239 lps->rcPaint.right, lps->rcPaint.bottom );
241 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
243 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
244 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
245 : WM_ERASEBKGND,
246 (WPARAM16)lps->hdc, 0 );
248 else lps->fErase = TRUE;
250 WIN_ReleaseWndPtr(wndPtr);
251 return lps->hdc;
255 /***********************************************************************
256 * BeginPaint32 (USER32.10)
258 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
260 PAINTSTRUCT16 ps;
262 BeginPaint16( hwnd, &ps );
263 lps->hdc = (HDC)ps.hdc;
264 lps->fErase = ps.fErase;
265 lps->rcPaint.top = ps.rcPaint.top;
266 lps->rcPaint.left = ps.rcPaint.left;
267 lps->rcPaint.right = ps.rcPaint.right;
268 lps->rcPaint.bottom = ps.rcPaint.bottom;
269 lps->fRestore = ps.fRestore;
270 lps->fIncUpdate = ps.fIncUpdate;
271 return lps->hdc;
275 /***********************************************************************
276 * EndPaint16 (USER.40)
278 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
280 ReleaseDC16( hwnd, lps->hdc );
281 ShowCaret( hwnd );
282 return TRUE;
286 /***********************************************************************
287 * EndPaint32 (USER32.176)
289 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
291 ReleaseDC( hwnd, lps->hdc );
292 ShowCaret( hwnd );
293 return TRUE;
297 /***********************************************************************
298 * FillWindow (USER.324)
300 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
302 RECT16 rect;
303 GetClientRect16( hwnd, &rect );
304 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
305 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
309 /***********************************************************************
310 * PAINT_GetControlBrush
312 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
314 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
315 (WPARAM)hDC, (LPARAM)hWnd );
316 if( !IsGDIObject16(bkgBrush) )
317 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
318 return bkgBrush;
322 /***********************************************************************
323 * PaintRect (USER.325)
325 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
326 HBRUSH16 hbrush, const RECT16 *rect)
328 if( hbrush <= CTLCOLOR_MAX )
330 if( hwndParent )
331 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
332 else
333 return;
335 if( hbrush )
336 FillRect16( hdc, rect, hbrush );
340 /***********************************************************************
341 * GetControlBrush (USER.326)
343 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
345 WND* wndPtr = WIN_FindWndPtr( hwnd );
346 HBRUSH16 retvalue;
348 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
350 WND* parent;
351 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
352 else parent = WIN_LockWndPtr(wndPtr->parent);
353 if( !parent ) parent = wndPtr;
354 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
355 WIN_ReleaseWndPtr(parent);
356 goto END;
358 retvalue = (HBRUSH16)0;
359 END:
360 WIN_ReleaseWndPtr(wndPtr);
361 return retvalue;
365 /***********************************************************************
366 * RDW_ValidateParent [RDW_UpdateRgns() helper]
368 * Validate the portions of parent that are covered by a validated child
369 * wndPtr = child
371 void RDW_ValidateParent(WND *wndChild)
373 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
374 WND *wndDesktop = WIN_GetDesktop();
376 if ((wndParent) && (wndParent != wndDesktop) && !(wndParent->dwStyle & WS_CLIPCHILDREN))
378 HRGN hrg;
379 if (wndChild->hrgnUpdate == 1 )
381 RECT r = {0, 0, wndChild->rectWindow.right - wndChild->rectWindow.left,
382 wndChild->rectWindow.bottom - wndChild->rectWindow.top };
383 hrg = CreateRectRgnIndirect( &r );
385 else
386 hrg = wndChild->hrgnUpdate;
387 if (wndParent->hrgnUpdate != 0)
389 POINT ptOffset;
390 RECT rect, rectParent;
391 if( wndParent->hrgnUpdate == 1 )
393 RECT r = {0, 0, wndParent->rectWindow.right - wndParent->rectWindow.left,
394 wndParent->rectWindow.bottom - wndParent->rectWindow.top };
395 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
397 /* we must offset the child region by the offset of the child rect in the parent */
398 GetWindowRect(wndParent->hwndSelf, &rectParent);
399 GetWindowRect(wndChild->hwndSelf, &rect);
400 ptOffset.x = rect.left - rectParent.left;
401 ptOffset.y = rect.top - rectParent.top;
402 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
403 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
404 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
406 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
408 WIN_ReleaseWndPtr(wndParent);
409 WIN_ReleaseDesktop();
412 /***********************************************************************
413 * RDW_UpdateRgns [RedrawWindow() helper]
415 * Walks the window tree and adds/removes parts of the hRgn to/from update
416 * regions of windows that overlap it. Also, manages internal paint flags.
418 * NOTE: Walks the window tree so the caller must lock it.
419 * MUST preserve hRgn (can modify but then has to restore).
421 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
424 * Called only when one of the following is set:
425 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
428 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
429 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
430 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
431 RECT r;
433 r.left = 0;
434 r.top = 0;
435 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
436 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
438 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
440 if( flags & RDW_INVALIDATE )
442 if( hRgn > 1 )
444 switch( wndPtr->hrgnUpdate )
446 default:
447 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
448 /* fall through */
449 case 0:
450 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
451 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
452 &r, NULL );
453 if( !bHadOne )
455 GetRgnBox( wndPtr->hrgnUpdate, &r );
456 if( IsRectEmpty( &r ) )
458 DeleteObject( wndPtr->hrgnUpdate );
459 wndPtr->hrgnUpdate = 0;
460 goto OUT;
463 break;
464 case 1: /* already an entire window */
465 break;
468 else if( hRgn == 1 )
470 if( wndPtr->hrgnUpdate > 1 )
471 DeleteObject( wndPtr->hrgnUpdate );
472 wndPtr->hrgnUpdate = 1;
474 else
475 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
477 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
478 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
480 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
481 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
482 flags |= RDW_FRAME;
484 else if( flags & RDW_VALIDATE )
486 if( wndPtr->hrgnUpdate )
488 if( hRgn > 1 )
490 if( wndPtr->hrgnUpdate == 1 )
491 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
493 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
494 == NULLREGION )
495 goto EMPTY;
497 else /* validate everything */
499 if( wndPtr->hrgnUpdate > 1 )
501 EMPTY:
502 DeleteObject( wndPtr->hrgnUpdate );
504 wndPtr->hrgnUpdate = 0;
507 if( !wndPtr->hrgnUpdate )
509 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
510 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
511 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
515 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
516 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
520 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
521 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
523 /* in/validate child windows that intersect with the region if it
524 * is a valid handle. */
526 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
528 if( hRgn > 1 && bChildren )
530 WND* wnd = wndPtr->child;
531 POINT ptTotal, prevOrigin = {0,0};
532 POINT ptClient;
534 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
535 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
537 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
539 if( wnd->dwStyle & WS_VISIBLE )
541 POINT ptOffset;
543 r.left = wnd->rectWindow.left + ptClient.x;
544 r.right = wnd->rectWindow.right + ptClient.x;
545 r.top = wnd->rectWindow.top + ptClient.y;
546 r.bottom = wnd->rectWindow.bottom + ptClient.y;
548 ptOffset.x = r.left - prevOrigin.x;
549 ptOffset.y = r.top - prevOrigin.y;
550 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
552 if( RectInRegion( hRgn, &r ) )
554 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
555 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
556 prevOrigin.x = r.left + ptTotal.x;
557 prevOrigin.y = r.top + ptTotal.y;
558 ptTotal.x += ptOffset.x;
559 ptTotal.y += ptOffset.y;
563 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
564 bChildren = 0;
568 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
570 if( bChildren )
572 WND* wnd;
573 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
574 if( wnd->dwStyle & WS_VISIBLE )
575 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
578 OUT:
580 /* Set/clear internal paint flag */
582 if (flags & RDW_INTERNALPAINT)
584 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
585 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
586 wndPtr->flags |= WIN_INTERNAL_PAINT;
588 else if (flags & RDW_NOINTERNALPAINT)
590 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
591 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
592 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
596 /***********************************************************************
597 * RDW_Paint [RedrawWindow() helper]
599 * Walks the window tree and paints/erases windows that have
600 * nonzero update regions according to redraw flags. hrgn is a scratch
601 * region passed down during recursion. Must not be 1.
604 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
606 /* NOTE: wndPtr is locked by caller.
608 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
609 * SendMessage() calls. This is a comment inside DefWindowProc() source
610 * from 16-bit SDK:
612 * This message avoids lots of inter-app message traffic
613 * by switching to the other task and continuing the
614 * recursion there.
616 * wParam = flags
617 * LOWORD(lParam) = hrgnClip
618 * HIWORD(lParam) = hwndSkip (not used; always NULL)
621 HDC hDC;
622 HWND hWnd = wndPtr->hwndSelf;
623 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
625 /* Erase/update the window itself ... */
627 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
629 if (flags & RDW_UPDATENOW)
631 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
632 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
634 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
636 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
637 HRGN hrgnRet = WIN_UpdateNCRgn( wndPtr, hrgn, UNC_REGION | UNC_CHECK |
638 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) );
639 if( hrgnRet )
641 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
642 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
644 if( bIcon ) dcx |= DCX_WINDOW;
645 else
646 if( hrgnRet )
647 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
648 wndPtr->rectWindow.top - wndPtr->rectClient.top);
649 else
650 dcx &= ~DCX_INTERSECTRGN;
651 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
653 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
654 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
655 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
656 ReleaseDC( hWnd, hDC );
662 if( !IsWindow(hWnd) ) return hrgn;
663 ex &= ~RDW_EX_TOPFRAME;
665 /* ... and its child windows */
667 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
668 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
670 WND** list, **ppWnd;
672 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
674 wndPtr = NULL;
675 for (ppWnd = list; *ppWnd; ppWnd++)
677 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
678 if (!IsWindow(wndPtr->hwndSelf)) continue;
679 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
680 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
681 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
683 WIN_ReleaseWndPtr(wndPtr);
684 WIN_ReleaseWinArray(list);
688 return hrgn;
691 /***********************************************************************
692 * PAINT_RedrawWindow
695 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
696 HRGN hrgnUpdate, UINT flags, UINT ex )
698 HRGN hRgn = 0;
699 RECT r, r2;
700 POINT pt;
701 WND* wndPtr;
703 if (!hwnd) hwnd = GetDesktopWindow();
704 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
706 /* check if the window or its parents are visible/not minimized */
708 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
710 WIN_ReleaseWndPtr(wndPtr);
711 return TRUE;
714 if (TRACE_ON(win))
716 if( hrgnUpdate )
718 GetRgnBox( hrgnUpdate, &r );
719 TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
720 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
722 else
724 if( rectUpdate )
725 r = *rectUpdate;
726 else
727 SetRectEmpty( &r );
728 TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
729 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
730 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
734 /* prepare an update region in window coordinates */
736 if( flags & RDW_FRAME )
737 r = wndPtr->rectWindow;
738 else
739 r = wndPtr->rectClient;
741 if( ex & RDW_EX_XYWINDOW )
743 pt.x = pt.y = 0;
744 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
746 else
748 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
749 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
750 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
753 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
755 /* If the window doesn't have hrgnUpdate we leave hRgn zero
756 * and put a new region straight into wndPtr->hrgnUpdate
757 * so that RDW_UpdateRgns() won't have to do any extra work.
760 if( hrgnUpdate )
762 if( wndPtr->hrgnUpdate )
763 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
764 else
765 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
767 else if( rectUpdate )
769 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
770 OffsetRect( &r2, pt.x, pt.y );
772 rect2i:
773 if( wndPtr->hrgnUpdate == 0 )
774 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
775 else
776 hRgn = CreateRectRgnIndirect( &r2 );
778 else /* entire window or client depending on RDW_FRAME */
780 if( flags & RDW_FRAME )
782 if( wndPtr->hrgnUpdate )
783 DeleteObject( wndPtr->hrgnUpdate );
784 wndPtr->hrgnUpdate = 1;
786 else
788 GETCLIENTRECTW( wndPtr, r2 );
789 goto rect2i;
793 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
795 /* In this we cannot leave with zero hRgn */
796 if( hrgnUpdate )
798 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
799 GetRgnBox( hRgn, &r2 );
800 if( IsRectEmpty( &r2 ) ) goto END;
802 else if( rectUpdate )
804 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
805 OffsetRect( &r2, pt.x, pt.y );
806 rect2v:
807 hRgn = CreateRectRgnIndirect( &r2 );
809 else /* entire window or client depending on RDW_FRAME */
811 if( flags & RDW_FRAME )
812 hRgn = 1;
813 else
815 GETCLIENTRECTW( wndPtr, r2 );
816 goto rect2v;
821 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
823 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
825 /* Erase/update windows, from now on hRgn is a scratch region */
827 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
829 END:
830 if( hRgn > 1 && (hRgn != hrgnUpdate) )
831 DeleteObject(hRgn );
832 WIN_ReleaseWndPtr(wndPtr);
833 return TRUE;
837 /***********************************************************************
838 * RedrawWindow32 (USER32.426)
840 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
841 HRGN hrgnUpdate, UINT flags )
843 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
847 /***********************************************************************
848 * RedrawWindow16 (USER.290)
850 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
851 HRGN16 hrgnUpdate, UINT16 flags )
853 if (rectUpdate)
855 RECT r;
856 CONV_RECT16TO32( rectUpdate, &r );
857 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
859 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
860 (HRGN)hrgnUpdate, flags, 0 );
864 /***********************************************************************
865 * UpdateWindow16 (USER.124)
867 void WINAPI UpdateWindow16( HWND16 hwnd )
869 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
872 /***********************************************************************
873 * UpdateWindow32 (USER32.567)
875 void WINAPI UpdateWindow( HWND hwnd )
877 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
880 /***********************************************************************
881 * InvalidateRgn16 (USER.126)
883 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
885 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
886 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
890 /***********************************************************************
891 * InvalidateRgn32 (USER32.329)
893 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
895 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
899 /***********************************************************************
900 * InvalidateRect16 (USER.125)
902 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
904 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
908 /***********************************************************************
909 * InvalidateRect32 (USER32.328)
911 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
913 return PAINT_RedrawWindow( hwnd, rect, 0,
914 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
918 /***********************************************************************
919 * ValidateRgn16 (USER.128)
921 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
923 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
924 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
928 /***********************************************************************
929 * ValidateRgn32 (USER32.572)
931 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
933 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
937 /***********************************************************************
938 * ValidateRect16 (USER.127)
940 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
942 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
946 /***********************************************************************
947 * ValidateRect32 (USER32.571)
949 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
951 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
955 /***********************************************************************
956 * GetUpdateRect16 (USER.190)
958 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
960 RECT r;
961 BOOL16 ret;
963 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
964 ret = GetUpdateRect( hwnd, &r, erase );
965 CONV_RECT32TO16( &r, rect );
966 return ret;
970 /***********************************************************************
971 * GetUpdateRect32 (USER32.297)
973 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
975 BOOL retvalue;
976 WND * wndPtr = WIN_FindWndPtr( hwnd );
977 if (!wndPtr) return FALSE;
979 if (rect)
981 if (wndPtr->hrgnUpdate > 1)
983 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
984 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
986 retvalue = FALSE;
987 goto END;
989 GetRgnBox( hrgn, rect );
990 DeleteObject( hrgn );
991 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
993 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
995 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
999 else
1000 if( wndPtr->hrgnUpdate == 1 )
1002 GetClientRect( hwnd, rect );
1003 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1005 else
1006 SetRectEmpty( rect );
1008 retvalue = (wndPtr->hrgnUpdate >= 1);
1009 END:
1010 WIN_ReleaseWndPtr(wndPtr);
1011 return retvalue;
1015 /***********************************************************************
1016 * GetUpdateRgn16 (USER.237)
1018 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1020 return GetUpdateRgn( hwnd, hrgn, erase );
1024 /***********************************************************************
1025 * GetUpdateRgn (USER32.298)
1027 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1029 INT retval;
1030 WND * wndPtr = WIN_FindWndPtr( hwnd );
1031 if (!wndPtr) return ERROR;
1033 if (wndPtr->hrgnUpdate == 0)
1035 SetRectRgn( hrgn, 0, 0, 0, 0 );
1036 retval = NULLREGION;
1037 goto END;
1039 else
1040 if (wndPtr->hrgnUpdate == 1)
1042 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1043 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1044 retval = SIMPLEREGION;
1046 else
1048 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1049 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1050 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1052 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1053 END:
1054 WIN_ReleaseWndPtr(wndPtr);
1055 return retval;
1059 /***********************************************************************
1060 * ExcludeUpdateRgn16 (USER.238)
1062 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1064 return ExcludeUpdateRgn( hdc, hwnd );
1068 /***********************************************************************
1069 * ExcludeUpdateRgn32 (USER32.195)
1071 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1073 RECT rect;
1074 WND * wndPtr;
1076 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1078 if (wndPtr->hrgnUpdate)
1080 INT ret;
1081 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1082 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1083 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1084 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1085 if( wndPtr->hrgnUpdate > 1 )
1087 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1088 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1089 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1092 /* do ugly coordinate translations in dce.c */
1094 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1095 DeleteObject( hrgn );
1096 WIN_ReleaseWndPtr(wndPtr);
1097 return ret;
1099 WIN_ReleaseWndPtr(wndPtr);
1100 return GetClipBox( hdc, &rect );