2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
30 #include "wine/winuser16.h"
32 #include "wine/unicode.h"
33 #include "wine/server.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 WINE_DECLARE_DEBUG_CHANNEL(nonclient
);
43 /* client rect in window coordinates */
45 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
46 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
47 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
48 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
50 /* PAINT_RedrawWindow() control flags */
51 #define RDW_EX_DELAY_NCPAINT 0x0020
53 /* WIN_UpdateNCRgn() flags */
54 #define UNC_CHECK 0x0001
55 #define UNC_ENTIRE 0x0002
56 #define UNC_REGION 0x0004
57 #define UNC_UPDATE 0x0008
58 #define UNC_DELAY_NCPAINT 0x0010
59 #define UNC_IN_BEGINPAINT 0x0020
61 HPALETTE (WINAPI
*pfnGDISelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = NULL
;
62 UINT (WINAPI
*pfnGDIRealizePalette
)(HDC hdc
) = NULL
;
65 /***********************************************************************
68 * Add an increment (normally 1 or -1) to the current paint count of a window.
70 static void add_paint_count( HWND hwnd
, int incr
)
72 SERVER_START_REQ( inc_window_paint_count
)
76 wine_server_call( req
);
82 /***********************************************************************
85 * hSrc: Region to crop.
86 * lpRect: Clipping rectangle.
88 * hDst: Region to hold the result (a new region is created if it's 0).
89 * Allowed to be the same region as hSrc in which case everything
90 * will be done in place, with no memory reallocations.
92 * Returns: hDst if success, 0 otherwise.
94 static HRGN
crop_rgn( HRGN hDst
, HRGN hSrc
, const RECT
*rect
)
96 HRGN h
= CreateRectRgnIndirect( rect
);
97 if (hDst
== 0) hDst
= h
;
98 CombineRgn( hDst
, hSrc
, h
, RGN_AND
);
99 if (hDst
!= h
) DeleteObject( h
);
104 /***********************************************************************
105 * WIN_HaveToDelayNCPAINT
107 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
108 * is generated as soon as a region intersecting the non-client area
109 * of a window is invalidated.
111 * This technique will work fine for all windows whose parents
112 * have the WS_CLIPCHILDREN style. When the parents have that style,
113 * they are not going to override the contents of their children.
114 * However, when the parent doesn't have that style, Windows relies
115 * on a "painter's algorithm" to display the contents of the windows.
116 * That is, windows are painted from back to front. This includes the
119 * This method looks at the current state of a window to determine
120 * if the sending of the WM_NCPAINT message should be delayed until
121 * the BeginPaint call.
124 * wndPtr - A Locked window pointer to the window we're
126 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
127 * function. This is a shortcut for the cases when
128 * we already know when to avoid scanning all the
129 * parents of a window. If you already know that this
130 * window's NCPAINT should be delayed, set the
131 * UNC_DELAY_NCPAINT flag for this parameter.
133 * This shortcut behavior is implemented in the
134 * RDW_Paint() method.
137 static BOOL
WIN_HaveToDelayNCPAINT( HWND hwnd
, UINT uncFlags
)
140 * Test the shortcut first. (duh)
142 if (uncFlags
& UNC_DELAY_NCPAINT
)
146 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
147 * method only. This is another shortcut to avoid going
148 * up the parent's chain of the window to finally
149 * figure-out that none of them has an invalid region.
151 if (uncFlags
& UNC_IN_BEGINPAINT
)
155 * Scan all the parents of this window to find a window
156 * that doesn't have the WS_CLIPCHILDREN style and that
157 * has an invalid region.
159 while ((hwnd
= GetAncestor( hwnd
, GA_PARENT
)))
161 WND
* parentWnd
= WIN_FindWndPtr( hwnd
);
162 if (parentWnd
&& !(parentWnd
->dwStyle
& WS_CLIPCHILDREN
) && parentWnd
->hrgnUpdate
)
164 WIN_ReleaseWndPtr( parentWnd
);
167 WIN_ReleaseWndPtr( parentWnd
);
172 /***********************************************************************
176 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
177 * Crop hrgnUpdate to a client rect, especially if it 1.
178 * If UNC_REGION is set return update region for the client rect.
180 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
181 * The trick is that when the returned region handle may be different from hRgn.
182 * In this case the old hRgn must be considered gone. BUT, if the returned value
183 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
184 * a DC without extra clipping region.
186 static HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
192 TRACE_(nonclient
)("hwnd %p [%p] hrgn %p, unc %04x, ncf %i\n",
193 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
195 /* desktop window doesn't have a nonclient area */
196 if(wnd
->hwndSelf
== GetDesktopWindow())
198 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
199 if( wnd
->hrgnUpdate
> (HRGN
)1 )
201 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
202 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
207 hrgnRet
= wnd
->hrgnUpdate
;
212 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
213 !(wnd
->flags
& WIN_NCACTIVATED
) )
215 wnd
->flags
|= WIN_NCACTIVATED
;
216 uncFlags
|= UNC_ENTIRE
;
220 * If the window's non-client area needs to be painted,
222 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
223 !WIN_HaveToDelayNCPAINT(wnd
->hwndSelf
, uncFlags
) )
227 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
228 GETCLIENTRECTW( wnd
, r
);
230 TRACE_(nonclient
)( "\tclient box (%ld,%ld-%ld,%ld), hrgnUpdate %p\n",
231 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
232 if( wnd
->hrgnUpdate
> (HRGN
)1 )
234 /* Check if update rgn overlaps with nonclient area */
236 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
237 UnionRect( &r3
, &r2
, &r
);
238 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
239 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
241 /* crop hrgnUpdate, save old one in hClip - the only
242 * case that places a valid region handle in hClip */
244 hClip
= wnd
->hrgnUpdate
;
245 wnd
->hrgnUpdate
= crop_rgn( hRgn
, hClip
, &r
);
246 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
249 if( uncFlags
& UNC_CHECK
)
251 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
252 if( IsRectEmpty( &r3
) )
254 /* delete the update region since all invalid
255 * parts were in the nonclient area */
257 DeleteObject( wnd
->hrgnUpdate
);
259 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
260 add_paint_count( wnd
->hwndSelf
, -1 );
262 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
266 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
269 if( wnd
->hrgnUpdate
== (HRGN
)1 )/* entire window */
271 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
272 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
273 uncFlags
|= UNC_ENTIRE
;
276 else /* no WM_NCPAINT unless forced */
278 if( wnd
->hrgnUpdate
> (HRGN
)1 )
281 if( uncFlags
& UNC_REGION
)
283 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
284 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
289 if( wnd
->hrgnUpdate
== (HRGN
)1 && (uncFlags
& UNC_UPDATE
) )
291 GETCLIENTRECTW( wnd
, r
);
292 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
293 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
297 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
299 /* still don't do anything if there is no nonclient area */
300 hClip
= (HRGN
)(memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
303 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
305 if ( hClip
== hrgnRet
&& hrgnRet
> (HRGN
)1 ) {
306 hClip
= CreateRectRgn( 0, 0, 0, 0 );
307 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
310 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, (WPARAM
)hClip
, 0L );
311 if( (hClip
> (HRGN
)1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
312 DeleteObject( hClip
);
314 * Since all Window locks are suspended while processing the WM_NCPAINT
315 * we want to make sure the window still exists before continuing.
317 if (!IsWindow(wnd
->hwndSelf
))
319 DeleteObject(hrgnRet
);
324 TRACE_(nonclient
)("returning %p (hClip = %p, hrgnUpdate = %p)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
330 /***********************************************************************
331 * RDW_ValidateParent [RDW_UpdateRgns() helper]
333 * Validate the portions of parents that are covered by a validated child
336 static void RDW_ValidateParent(WND
*wndChild
)
341 if (wndChild
->hrgnUpdate
== (HRGN
)1 ) {
345 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
346 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
347 hrg
= CreateRectRgnIndirect( &r
);
349 hrg
= wndChild
->hrgnUpdate
;
351 parent
= GetAncestor( wndChild
->hwndSelf
, GA_PARENT
);
352 while (parent
&& parent
!= GetDesktopWindow())
354 WND
*wndParent
= WIN_FindWndPtr( parent
);
355 if (wndParent
&& !(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
357 if (wndParent
->hrgnUpdate
!= 0)
360 RECT rect
, rectParent
;
361 if( wndParent
->hrgnUpdate
== (HRGN
)1 )
367 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
368 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
370 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
372 /* we must offset the child region by the offset of the child rect in the parent */
373 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
374 GetWindowRect(wndChild
->hwndSelf
, &rect
);
375 ptOffset
.x
= rect
.left
- rectParent
.left
;
376 ptOffset
.y
= rect
.top
- rectParent
.top
;
377 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
378 if (CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
) == NULLREGION
)
380 /* the update region has become empty */
381 DeleteObject( wndParent
->hrgnUpdate
);
382 wndParent
->hrgnUpdate
= 0;
383 wndParent
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
384 if( !(wndParent
->flags
& WIN_INTERNAL_PAINT
) )
385 add_paint_count( wndParent
->hwndSelf
, -1 );
387 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
390 WIN_ReleaseWndPtr( wndParent
);
391 parent
= GetAncestor( parent
, GA_PARENT
);
393 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
396 /***********************************************************************
397 * RDW_UpdateRgns [RedrawWindow() helper]
399 * Walks the window tree and adds/removes parts of the hRgn to/from update
400 * regions of windows that overlap it. Also, manages internal paint flags.
402 * NOTE: Walks the window tree so the caller must lock it.
403 * MUST preserve hRgn (can modify but then has to restore).
405 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
408 * Called only when one of the following is set:
409 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
412 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
413 BOOL bChildren
= (!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
414 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
419 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
420 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
422 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
424 if( flags
& RDW_INVALIDATE
)
428 switch ((UINT
)wndPtr
->hrgnUpdate
)
431 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
434 wndPtr
->hrgnUpdate
= crop_rgn( wndPtr
->hrgnUpdate
,
435 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
439 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
440 if( IsRectEmpty( &r
) )
442 DeleteObject( wndPtr
->hrgnUpdate
);
443 wndPtr
->hrgnUpdate
= 0;
448 case 1: /* already an entire window */
452 else if( hRgn
== (HRGN
)1 )
454 if( wndPtr
->hrgnUpdate
> (HRGN
)1 )
455 DeleteObject( wndPtr
->hrgnUpdate
);
456 wndPtr
->hrgnUpdate
= (HRGN
)1;
461 if( wndPtr
->hrgnUpdate
> (HRGN
)1)
463 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
464 if( IsRectEmpty( &r
) )
466 DeleteObject( wndPtr
->hrgnUpdate
);
467 wndPtr
->hrgnUpdate
= 0;
471 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends
472 * on code in RDW_Paint() */
475 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
476 add_paint_count( wndPtr
->hwndSelf
, 1 );
478 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
479 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
482 else if( flags
& RDW_VALIDATE
)
484 if( wndPtr
->hrgnUpdate
)
488 if( wndPtr
->hrgnUpdate
== (HRGN
)1 )
489 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
491 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
494 DeleteObject( wndPtr
->hrgnUpdate
);
495 wndPtr
->hrgnUpdate
= 0;
498 else /* validate everything */
500 if( wndPtr
->hrgnUpdate
> (HRGN
)1 ) DeleteObject( wndPtr
->hrgnUpdate
);
501 wndPtr
->hrgnUpdate
= 0;
504 if( !wndPtr
->hrgnUpdate
)
506 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
507 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
508 add_paint_count( wndPtr
->hwndSelf
, -1 );
512 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
513 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
517 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
518 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
520 /* in/validate child windows that intersect with the region if it
521 * is a valid handle. */
523 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
526 if( hRgn
> (HRGN
)1 && bChildren
&& (list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
528 POINT ptTotal
, prevOrigin
= {0,0};
532 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
533 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
535 for(i
= ptTotal
.x
= ptTotal
.y
= 0; list
[i
]; i
++)
537 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
539 if( wnd
->dwStyle
& WS_VISIBLE
)
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
;
562 WIN_ReleaseWndPtr( wnd
);
564 HeapFree( GetProcessHeap(), 0, list
);
565 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
570 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
575 if ((list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
578 for (i
= 0; list
[i
]; i
++)
580 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
582 if( wnd
->dwStyle
& WS_VISIBLE
)
583 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
584 WIN_ReleaseWndPtr( wnd
);
586 HeapFree( GetProcessHeap(), 0, list
);
592 /* Set/clear internal paint flag */
594 if (flags
& RDW_INTERNALPAINT
)
596 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
597 add_paint_count( wndPtr
->hwndSelf
, 1 );
598 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
600 else if (flags
& RDW_NOINTERNALPAINT
)
602 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
603 add_paint_count( wndPtr
->hwndSelf
, -1 );
604 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
608 /***********************************************************************
609 * RDW_Paint [RedrawWindow() helper]
611 * Walks the window tree and paints/erases windows that have
612 * nonzero update regions according to redraw flags. hrgn is a scratch
613 * region passed down during recursion. Must not be 1.
616 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
618 /* NOTE: wndPtr is locked by caller.
620 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
621 * SendMessage() calls. This is a comment inside DefWindowProc() source
624 * This message avoids lots of inter-app message traffic
625 * by switching to the other task and continuing the
629 * LOWORD(lParam) = hrgnClip
630 * HIWORD(lParam) = hwndSkip (not used; always NULL)
634 HWND hWnd
= wndPtr
->hwndSelf
;
635 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassLongA(hWnd
, GCL_HICON
));
637 /* Erase/update the window itself ... */
639 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
642 * Check if this window should delay it's processing of WM_NCPAINT.
643 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
645 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
->hwndSelf
, 0) )
646 ex
|= RDW_EX_DELAY_NCPAINT
;
648 if (flags
& RDW_UPDATENOW
)
650 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
651 SendMessageW( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
653 else if (flags
& RDW_ERASENOW
)
655 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
658 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
660 UNC_REGION
| UNC_CHECK
|
661 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
665 if( hrgnRet
> (HRGN
)1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
666 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
668 if( bIcon
) dcx
|= DCX_WINDOW
;
671 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
672 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
674 dcx
&= ~DCX_INTERSECTRGN
;
675 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
677 if (SendMessageW( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
679 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
680 ReleaseDC( hWnd
, hDC
);
686 if( !IsWindow(hWnd
) ) return hrgn
;
688 /* ... and its child windows */
690 if(!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
691 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
695 if( (list
= WIN_ListChildren( wndPtr
->hwndSelf
)) )
697 for (phwnd
= list
; *phwnd
; phwnd
++)
699 if (!(wndPtr
= WIN_FindWndPtr( *phwnd
))) continue;
700 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
701 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
702 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
703 WIN_ReleaseWndPtr(wndPtr
);
705 HeapFree( GetProcessHeap(), 0, list
);
713 /***********************************************************************
716 static void dump_rdw_flags(UINT flags
)
719 if (flags
& RDW_INVALIDATE
) TRACE(" RDW_INVALIDATE");
720 if (flags
& RDW_INTERNALPAINT
) TRACE(" RDW_INTERNALPAINT");
721 if (flags
& RDW_ERASE
) TRACE(" RDW_ERASE");
722 if (flags
& RDW_VALIDATE
) TRACE(" RDW_VALIDATE");
723 if (flags
& RDW_NOINTERNALPAINT
) TRACE(" RDW_NOINTERNALPAINT");
724 if (flags
& RDW_NOERASE
) TRACE(" RDW_NOERASE");
725 if (flags
& RDW_NOCHILDREN
) TRACE(" RDW_NOCHILDREN");
726 if (flags
& RDW_ALLCHILDREN
) TRACE(" RDW_ALLCHILDREN");
727 if (flags
& RDW_UPDATENOW
) TRACE(" RDW_UPDATENOW");
728 if (flags
& RDW_ERASENOW
) TRACE(" RDW_ERASENOW");
729 if (flags
& RDW_FRAME
) TRACE(" RDW_FRAME");
730 if (flags
& RDW_NOFRAME
) TRACE(" RDW_NOFRAME");
734 RDW_INTERNALPAINT | \
737 RDW_NOINTERNALPAINT | \
746 if (flags
& ~RDW_FLAGS
) TRACE(" %04x", flags
& ~RDW_FLAGS
);
752 /***********************************************************************
753 * RedrawWindow (USER32.@)
755 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
756 HRGN hrgnUpdate
, UINT flags
)
763 if (!hwnd
) hwnd
= GetDesktopWindow();
765 /* check if the window or its parents are visible/not minimized */
767 if (!WIN_IsWindowDrawable( hwnd
, !(flags
& RDW_FRAME
) )) return TRUE
;
769 /* process pending events and messages before painting */
770 if (flags
& RDW_UPDATENOW
)
771 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 0, QS_ALLINPUT
);
773 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
778 GetRgnBox( hrgnUpdate
, &r
);
779 TRACE( "%p (%p) NULL %p box (%ld,%ld-%ld,%ld) flags=%04x\n",
780 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
);
788 TRACE( "%p (%p) %s %ld,%ld-%ld,%ld %p flags=%04x\n",
789 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
790 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
);
792 dump_rdw_flags(flags
);
795 /* prepare an update region in window coordinates */
797 if (((flags
& (RDW_INVALIDATE
|RDW_FRAME
)) == (RDW_INVALIDATE
|RDW_FRAME
)) ||
798 ((flags
& (RDW_VALIDATE
|RDW_NOFRAME
)) == (RDW_VALIDATE
|RDW_NOFRAME
)))
799 r
= wndPtr
->rectWindow
;
801 r
= wndPtr
->rectClient
;
803 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
804 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
805 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
807 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
809 /* If the window doesn't have hrgnUpdate we leave hRgn zero
810 * and put a new region straight into wndPtr->hrgnUpdate
811 * so that RDW_UpdateRgns() won't have to do any extra work.
816 if( wndPtr
->hrgnUpdate
)
818 hRgn
= CreateRectRgn( 0, 0, 0, 0 );
819 CombineRgn( hRgn
, hrgnUpdate
, 0, RGN_COPY
);
820 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
824 wndPtr
->hrgnUpdate
= crop_rgn( 0, hrgnUpdate
, &r
);
825 OffsetRgn( wndPtr
->hrgnUpdate
, pt
.x
, pt
.y
);
828 else if( rectUpdate
)
830 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
831 OffsetRect( &r2
, pt
.x
, pt
.y
);
832 if( wndPtr
->hrgnUpdate
== 0 )
833 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
835 hRgn
= CreateRectRgnIndirect( &r2
);
837 else /* entire window or client depending on RDW_FRAME */
839 if( flags
& RDW_FRAME
)
841 if (wndPtr
->hrgnUpdate
) hRgn
= (HRGN
)1;
842 else wndPtr
->hrgnUpdate
= (HRGN
)1;
846 GETCLIENTRECTW( wndPtr
, r2
);
847 if( wndPtr
->hrgnUpdate
== 0 )
848 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
850 hRgn
= CreateRectRgnIndirect( &r2
);
854 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
856 /* In this we cannot leave with zero hRgn */
859 hRgn
= crop_rgn( hRgn
, hrgnUpdate
, &r
);
860 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
861 GetRgnBox( hRgn
, &r2
);
862 if( IsRectEmpty( &r2
) ) goto END
;
864 else if( rectUpdate
)
866 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
867 OffsetRect( &r2
, pt
.x
, pt
.y
);
868 hRgn
= CreateRectRgnIndirect( &r2
);
870 else /* entire window or client depending on RDW_NOFRAME */
872 if( flags
& RDW_NOFRAME
)
876 GETCLIENTRECTW( wndPtr
, r2
);
877 hRgn
= CreateRectRgnIndirect( &r2
);
882 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
884 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
886 /* Erase/update windows, from now on hRgn is a scratch region */
888 hRgn
= RDW_Paint( wndPtr
, (hRgn
== (HRGN
)1) ? 0 : hRgn
, flags
, 0 );
891 if( hRgn
> (HRGN
)1 && (hRgn
!= hrgnUpdate
) )
893 WIN_ReleaseWndPtr(wndPtr
);
898 /***********************************************************************
899 * UpdateWindow (USER32.@)
901 BOOL WINAPI
UpdateWindow( HWND hwnd
)
903 return RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
907 /***********************************************************************
908 * InvalidateRgn (USER32.@)
910 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
912 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
916 /***********************************************************************
917 * InvalidateRect (USER32.@)
919 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
921 return RedrawWindow( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
925 /***********************************************************************
926 * ValidateRgn (USER32.@)
928 BOOL WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
930 return RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
934 /***********************************************************************
935 * ValidateRect (USER32.@)
937 BOOL WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
939 return RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
943 /***********************************************************************
944 * SelectPalette (Not a Windows API)
946 HPALETTE WINAPI
SelectPalette( HDC hDC
, HPALETTE hPal
, BOOL bForceBackground
)
948 WORD wBkgPalette
= 1;
950 if (!bForceBackground
&& (hPal
!= GetStockObject(DEFAULT_PALETTE
)))
952 HWND hwnd
= WindowFromDC( hDC
);
955 HWND hForeground
= GetForegroundWindow();
956 /* set primary palette if it's related to current active */
957 if (hForeground
== hwnd
|| IsChild(hForeground
,hwnd
)) wBkgPalette
= 0;
960 return pfnGDISelectPalette( hDC
, hPal
, wBkgPalette
);
964 /***********************************************************************
965 * UserRealizePalette (USER32.@)
967 UINT WINAPI
UserRealizePalette( HDC hDC
)
969 UINT realized
= pfnGDIRealizePalette( hDC
);
971 /* do not send anything if no colors were changed */
972 if (realized
&& IsDCCurrentPalette16( HDC_16(hDC
) ))
974 /* send palette change notification */
975 HWND hWnd
= WindowFromDC( hDC
);
976 if (hWnd
) SendMessageTimeoutW( HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0,
977 SMTO_ABORTIFHUNG
, 2000, NULL
);