2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/unicode.h"
13 #include "wine/server.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(win);
22 DECLARE_DEBUG_CHANNEL(nonclient);
24 /* client rect in window coordinates */
26 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
27 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
28 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
29 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
31 /* PAINT_RedrawWindow() control flags */
32 #define RDW_EX_DELAY_NCPAINT 0x0020
34 /* WIN_UpdateNCRgn() flags */
35 #define UNC_CHECK 0x0001
36 #define UNC_ENTIRE 0x0002
37 #define UNC_REGION 0x0004
38 #define UNC_UPDATE 0x0008
39 #define UNC_DELAY_NCPAINT 0x0010
40 #define UNC_IN_BEGINPAINT 0x0020
43 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
46 /***********************************************************************
49 * Add an increment (normally 1 or -1) to the current paint count of a window.
51 static void add_paint_count( HWND hwnd, int incr )
53 SERVER_START_REQ( inc_window_paint_count )
57 wine_server_call( req );
63 /***********************************************************************
64 * WIN_HaveToDelayNCPAINT
66 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
67 * is generated as soon as a region intersecting the non-client area
68 * of a window is invalidated.
70 * This technique will work fine for all windows whose parents
71 * have the WS_CLIPCHILDREN style. When the parents have that style,
72 * they are not going to override the contents of their children.
73 * However, when the parent doesn't have that style, Windows relies
74 * on a "painter's algorithm" to display the contents of the windows.
75 * That is, windows are painted from back to front. This includes the
78 * This method looks at the current state of a window to determine
79 * if the sending of the WM_NCPAINT message should be delayed until
80 * the BeginPaint call.
83 * wndPtr - A Locked window pointer to the window we're
85 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
86 * function. This is a shortcut for the cases when
87 * we already know when to avoid scanning all the
88 * parents of a window. If you already know that this
89 * window's NCPAINT should be delayed, set the
90 * UNC_DELAY_NCPAINT flag for this parameter.
92 * This shortcut behavior is implemented in the
96 static BOOL WIN_HaveToDelayNCPAINT( HWND hwnd, UINT uncFlags)
99 * Test the shortcut first. (duh)
101 if (uncFlags & UNC_DELAY_NCPAINT)
105 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
106 * method only. This is another shortcut to avoid going
107 * up the parent's chain of the window to finally
108 * figure-out that none of them has an invalid region.
110 if (uncFlags & UNC_IN_BEGINPAINT)
114 * Scan all the parents of this window to find a window
115 * that doesn't have the WS_CLIPCHILDREN style and that
116 * has an invalid region.
118 while ((hwnd = GetAncestor( hwnd, GA_PARENT )))
120 WND* parentWnd = WIN_FindWndPtr( hwnd );
121 if (!(parentWnd->dwStyle & WS_CLIPCHILDREN) && parentWnd->hrgnUpdate)
123 WIN_ReleaseWndPtr( parentWnd );
126 WIN_ReleaseWndPtr( parentWnd );
131 /***********************************************************************
135 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
136 * Crop hrgnUpdate to a client rect, especially if it 1.
137 * If UNC_REGION is set return update region for the client rect.
139 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
140 * The trick is that when the returned region handle may be different from hRgn.
141 * In this case the old hRgn must be considered gone. BUT, if the returned value
142 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
143 * a DC without extra clipping region.
145 static HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
151 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
152 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
154 /* desktop window doesn't have a nonclient area */
155 if(wnd->hwndSelf == GetDesktopWindow())
157 wnd->flags &= ~WIN_NEEDS_NCPAINT;
158 if( wnd->hrgnUpdate > 1 )
159 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
162 hrgnRet = wnd->hrgnUpdate;
167 if ((wnd->hwndSelf == GetForegroundWindow()) &&
168 !(wnd->flags & WIN_NCACTIVATED) )
170 wnd->flags |= WIN_NCACTIVATED;
171 uncFlags |= UNC_ENTIRE;
175 * If the window's non-client area needs to be painted,
177 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
178 !WIN_HaveToDelayNCPAINT(wnd->hwndSelf, uncFlags) )
182 wnd->flags &= ~WIN_NEEDS_NCPAINT;
183 GETCLIENTRECTW( wnd, r );
185 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
186 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
187 if( wnd->hrgnUpdate > 1 )
189 /* Check if update rgn overlaps with nonclient area */
191 GetRgnBox( wnd->hrgnUpdate, &r2 );
192 UnionRect( &r3, &r2, &r );
193 if( r3.left != r.left || r3.top != r.top ||
194 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
196 /* crop hrgnUpdate, save old one in hClip - the only
197 * case that places a valid region handle in hClip */
199 hClip = wnd->hrgnUpdate;
200 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
201 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
204 if( uncFlags & UNC_CHECK )
206 GetRgnBox( wnd->hrgnUpdate, &r3 );
207 if( IsRectEmpty( &r3 ) )
209 /* delete the update region since all invalid
210 * parts were in the nonclient area */
212 DeleteObject( wnd->hrgnUpdate );
214 if(!(wnd->flags & WIN_INTERNAL_PAINT))
215 add_paint_count( wnd->hwndSelf, -1 );
217 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
221 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
224 if( wnd->hrgnUpdate == 1 )/* entire window */
226 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
227 if( uncFlags & UNC_REGION ) hrgnRet = 1;
228 uncFlags |= UNC_ENTIRE;
231 else /* no WM_NCPAINT unless forced */
233 if( wnd->hrgnUpdate > 1 )
236 if( uncFlags & UNC_REGION )
237 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
240 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
242 GETCLIENTRECTW( wnd, r );
243 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
244 if( uncFlags & UNC_REGION ) hrgnRet = 1;
248 if(!hClip && (uncFlags & UNC_ENTIRE) )
250 /* still don't do anything if there is no nonclient area */
251 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
254 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
256 if ( hClip == hrgnRet && hrgnRet > 1 ) {
257 hClip = CreateRectRgn( 0, 0, 0, 0 );
258 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
261 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
262 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
263 DeleteObject( hClip );
265 * Since all Window locks are suspended while processing the WM_NCPAINT
266 * we want to make sure the window still exists before continuing.
268 if (!IsWindow(wnd->hwndSelf))
270 DeleteObject(hrgnRet);
275 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
281 /***********************************************************************
282 * BeginPaint (USER.39)
284 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
288 BeginPaint( WIN_Handle32(hwnd), &ps );
290 lps->fErase = ps.fErase;
291 lps->rcPaint.top = ps.rcPaint.top;
292 lps->rcPaint.left = ps.rcPaint.left;
293 lps->rcPaint.right = ps.rcPaint.right;
294 lps->rcPaint.bottom = ps.rcPaint.bottom;
295 lps->fRestore = ps.fRestore;
296 lps->fIncUpdate = ps.fIncUpdate;
301 /***********************************************************************
302 * BeginPaint (USER32.@)
304 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
308 RECT clipRect, clientRect;
312 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
315 FIXME( "window %x belongs to other thread\n", hwnd );
320 bIcon = (IsIconic(hwnd) && GetClassLongA(hwnd, GCL_HICON));
322 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
323 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
325 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
326 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
329 * Make sure the window is still a window. All window locks are suspended
330 * when the WM_NCPAINT is sent.
332 if (!IsWindow( hwnd ))
334 WIN_ReleaseWndPtr(wndPtr);
338 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
339 add_paint_count( hwnd, -1 );
341 wndPtr->hrgnUpdate = 0;
342 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
344 WIN_ReleaseWndPtr(wndPtr);
348 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate);
350 if (GetClassLongA( hwnd, GCL_STYLE ) & CS_PARENTDC)
352 /* Don't clip the output to the update region for CS_PARENTDC window */
354 DeleteObject(hrgnUpdate);
355 lps->hdc = GetDCEx( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
356 (bIcon ? DCX_WINDOW : 0) );
360 if( hrgnUpdate ) /* convert to client coordinates */
361 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
362 wndPtr->rectWindow.top - wndPtr->rectClient.top );
363 lps->hdc = GetDCEx(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
364 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
365 /* ReleaseDC() in EndPaint() will delete the region */
368 TRACE("hdc = %04x\n", lps->hdc);
372 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
376 /* It is possible that the clip box is bigger than the window itself,
377 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
378 than the window itself, so we need to intersect the cliprect with
381 GetClientRect( hwnd, &clientRect );
383 GetClipBox( lps->hdc, &clipRect );
384 LPtoDP(lps->hdc, (LPPOINT)&clipRect, 2); /* GetClipBox returns LP */
386 IntersectRect(&lps->rcPaint, &clientRect, &clipRect);
387 DPtoLP(lps->hdc, (LPPOINT)&lps->rcPaint, 2); /* we must return LP */
389 TRACE("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
390 lps->rcPaint.right, lps->rcPaint.bottom );
392 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
393 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
395 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
396 lps->fErase = !SendMessageA(hwnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
397 (WPARAM16)lps->hdc, 0 );
399 else lps->fErase = TRUE;
401 WIN_ReleaseWndPtr(wndPtr);
406 /***********************************************************************
409 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
411 ReleaseDC16( hwnd, lps->hdc );
417 /***********************************************************************
418 * EndPaint (USER32.@)
420 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
422 ReleaseDC( hwnd, lps->hdc );
428 /***********************************************************************
429 * RDW_ValidateParent [RDW_UpdateRgns() helper]
431 * Validate the portions of parents that are covered by a validated child
434 static void RDW_ValidateParent(WND *wndChild)
439 if (wndChild->hrgnUpdate == 1 ) {
443 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
444 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
445 hrg = CreateRectRgnIndirect( &r );
447 hrg = wndChild->hrgnUpdate;
449 parent = GetAncestor( wndChild->hwndSelf, GA_PARENT );
450 while (parent && parent != GetDesktopWindow())
452 WND *wndParent = WIN_FindWndPtr( parent );
453 if (!(wndParent->dwStyle & WS_CLIPCHILDREN))
455 if (wndParent->hrgnUpdate != 0)
458 RECT rect, rectParent;
459 if( wndParent->hrgnUpdate == 1 )
465 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
466 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
468 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
470 /* we must offset the child region by the offset of the child rect in the parent */
471 GetWindowRect(wndParent->hwndSelf, &rectParent);
472 GetWindowRect(wndChild->hwndSelf, &rect);
473 ptOffset.x = rect.left - rectParent.left;
474 ptOffset.y = rect.top - rectParent.top;
475 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
476 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
477 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
480 WIN_ReleaseWndPtr( wndParent );
481 parent = GetAncestor( parent, GA_PARENT );
483 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
486 /***********************************************************************
487 * RDW_UpdateRgns [RedrawWindow() helper]
489 * Walks the window tree and adds/removes parts of the hRgn to/from update
490 * regions of windows that overlap it. Also, manages internal paint flags.
492 * NOTE: Walks the window tree so the caller must lock it.
493 * MUST preserve hRgn (can modify but then has to restore).
495 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
498 * Called only when one of the following is set:
499 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
502 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
503 BOOL bChildren = (!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
504 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
509 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
510 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
512 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
514 if( flags & RDW_INVALIDATE )
518 switch( wndPtr->hrgnUpdate )
521 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
524 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
525 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
529 GetRgnBox( wndPtr->hrgnUpdate, &r );
530 if( IsRectEmpty( &r ) )
532 DeleteObject( wndPtr->hrgnUpdate );
533 wndPtr->hrgnUpdate = 0;
538 case 1: /* already an entire window */
544 if( wndPtr->hrgnUpdate > 1 )
545 DeleteObject( wndPtr->hrgnUpdate );
546 wndPtr->hrgnUpdate = 1;
549 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
551 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
552 add_paint_count( wndPtr->hwndSelf, 1 );
554 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
555 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
558 else if( flags & RDW_VALIDATE )
560 if( wndPtr->hrgnUpdate )
564 if( wndPtr->hrgnUpdate == 1 )
565 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
567 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
570 DeleteObject( wndPtr->hrgnUpdate );
571 wndPtr->hrgnUpdate = 0;
574 else /* validate everything */
576 if( wndPtr->hrgnUpdate > 1 ) DeleteObject( wndPtr->hrgnUpdate );
577 wndPtr->hrgnUpdate = 0;
580 if( !wndPtr->hrgnUpdate )
582 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
583 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
584 add_paint_count( wndPtr->hwndSelf, -1 );
588 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
589 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
593 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
594 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
596 /* in/validate child windows that intersect with the region if it
597 * is a valid handle. */
599 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
602 if( hRgn > 1 && bChildren && (list = WIN_ListChildren( wndPtr->hwndSelf )))
604 POINT ptTotal, prevOrigin = {0,0};
608 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
609 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
611 for(i = ptTotal.x = ptTotal.y = 0; list[i]; i++)
613 WND *wnd = WIN_FindWndPtr( list[i] );
615 if( wnd->dwStyle & WS_VISIBLE )
619 r.left = wnd->rectWindow.left + ptClient.x;
620 r.right = wnd->rectWindow.right + ptClient.x;
621 r.top = wnd->rectWindow.top + ptClient.y;
622 r.bottom = wnd->rectWindow.bottom + ptClient.y;
624 ptOffset.x = r.left - prevOrigin.x;
625 ptOffset.y = r.top - prevOrigin.y;
626 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
628 if( RectInRegion( hRgn, &r ) )
630 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
631 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
632 prevOrigin.x = r.left + ptTotal.x;
633 prevOrigin.y = r.top + ptTotal.y;
634 ptTotal.x += ptOffset.x;
635 ptTotal.y += ptOffset.y;
638 WIN_ReleaseWndPtr( wnd );
640 HeapFree( GetProcessHeap(), 0, list );
641 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
646 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
651 if ((list = WIN_ListChildren( wndPtr->hwndSelf )))
654 for (i = 0; list[i]; i++)
656 WND *wnd = WIN_FindWndPtr( list[i] );
658 if( wnd->dwStyle & WS_VISIBLE )
659 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
660 WIN_ReleaseWndPtr( wnd );
662 HeapFree( GetProcessHeap(), 0, list );
668 /* Set/clear internal paint flag */
670 if (flags & RDW_INTERNALPAINT)
672 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
673 add_paint_count( wndPtr->hwndSelf, 1 );
674 wndPtr->flags |= WIN_INTERNAL_PAINT;
676 else if (flags & RDW_NOINTERNALPAINT)
678 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
679 add_paint_count( wndPtr->hwndSelf, -1 );
680 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
684 /***********************************************************************
685 * RDW_Paint [RedrawWindow() helper]
687 * Walks the window tree and paints/erases windows that have
688 * nonzero update regions according to redraw flags. hrgn is a scratch
689 * region passed down during recursion. Must not be 1.
692 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
694 /* NOTE: wndPtr is locked by caller.
696 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
697 * SendMessage() calls. This is a comment inside DefWindowProc() source
700 * This message avoids lots of inter-app message traffic
701 * by switching to the other task and continuing the
705 * LOWORD(lParam) = hrgnClip
706 * HIWORD(lParam) = hwndSkip (not used; always NULL)
710 HWND hWnd = wndPtr->hwndSelf;
711 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassLongA(hWnd, GCL_HICON));
713 /* Erase/update the window itself ... */
715 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
718 * Check if this window should delay it's processing of WM_NCPAINT.
719 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
721 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr->hwndSelf, 0) )
722 ex |= RDW_EX_DELAY_NCPAINT;
724 if (flags & RDW_UPDATENOW)
726 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
727 SendMessageW( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
729 else if (flags & RDW_ERASENOW)
731 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
734 hrgnRet = WIN_UpdateNCRgn(wndPtr,
736 UNC_REGION | UNC_CHECK |
737 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
741 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
742 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
744 if( bIcon ) dcx |= DCX_WINDOW;
747 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
748 wndPtr->rectWindow.top - wndPtr->rectClient.top);
750 dcx &= ~DCX_INTERSECTRGN;
751 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
753 if (SendMessageW( hWnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
755 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
756 ReleaseDC( hWnd, hDC );
762 if( !IsWindow(hWnd) ) return hrgn;
764 /* ... and its child windows */
766 if(!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
767 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
771 if( (list = WIN_ListChildren( wndPtr->hwndSelf )) )
773 for (phwnd = list; *phwnd; phwnd++)
775 if (!(wndPtr = WIN_FindWndPtr( *phwnd ))) continue;
776 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
777 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
778 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
779 WIN_ReleaseWndPtr(wndPtr);
781 HeapFree( GetProcessHeap(), 0, list );
789 /***********************************************************************
790 * RedrawWindow (USER32.@)
792 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
793 HRGN hrgnUpdate, UINT flags )
800 if (!hwnd) hwnd = GetDesktopWindow();
802 /* check if the window or its parents are visible/not minimized */
804 if (!WIN_IsWindowDrawable( hwnd, !(flags & RDW_FRAME) )) return TRUE;
806 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
811 GetRgnBox( hrgnUpdate, &r );
812 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
813 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags );
821 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
822 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
823 r.top, r.right, r.bottom, hrgnUpdate, flags );
828 /* process pending events and messages before painting */
829 if (flags & RDW_UPDATENOW)
830 MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_ALLINPUT );
832 /* prepare an update region in window coordinates */
834 if( flags & RDW_FRAME )
835 r = wndPtr->rectWindow;
837 r = wndPtr->rectClient;
839 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
840 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
841 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
843 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
845 /* If the window doesn't have hrgnUpdate we leave hRgn zero
846 * and put a new region straight into wndPtr->hrgnUpdate
847 * so that RDW_UpdateRgns() won't have to do any extra work.
852 if( wndPtr->hrgnUpdate )
853 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
855 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
857 else if( rectUpdate )
859 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
860 OffsetRect( &r2, pt.x, pt.y );
863 if( wndPtr->hrgnUpdate == 0 )
864 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
866 hRgn = CreateRectRgnIndirect( &r2 );
868 else /* entire window or client depending on RDW_FRAME */
870 if( flags & RDW_FRAME )
872 if( wndPtr->hrgnUpdate )
873 DeleteObject( wndPtr->hrgnUpdate );
874 wndPtr->hrgnUpdate = 1;
878 GETCLIENTRECTW( wndPtr, r2 );
883 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
885 /* In this we cannot leave with zero hRgn */
888 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
889 GetRgnBox( hRgn, &r2 );
890 if( IsRectEmpty( &r2 ) ) goto END;
892 else if( rectUpdate )
894 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
895 OffsetRect( &r2, pt.x, pt.y );
896 hRgn = CreateRectRgnIndirect( &r2 );
898 else /* entire window or client depending on RDW_FRAME */
900 if( flags & RDW_FRAME )
904 GETCLIENTRECTW( wndPtr, r2 );
905 hRgn = CreateRectRgnIndirect( &r2 );
910 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
912 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
914 /* Erase/update windows, from now on hRgn is a scratch region */
916 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, 0 );
919 if( hRgn > 1 && (hRgn != hrgnUpdate) )
921 WIN_ReleaseWndPtr(wndPtr);
926 /***********************************************************************
927 * UpdateWindow (USER32.@)
929 void WINAPI UpdateWindow( HWND hwnd )
931 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
935 /***********************************************************************
936 * InvalidateRgn (USER32.@)
938 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
940 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
944 /***********************************************************************
945 * InvalidateRect (USER32.@)
947 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
949 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
953 /***********************************************************************
954 * ValidateRgn (USER32.@)
956 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
958 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
962 /***********************************************************************
963 * ValidateRect (USER32.@)
965 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
967 RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
971 /***********************************************************************
972 * GetUpdateRect (USER32.@)
974 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
977 WND * wndPtr = WIN_FindWndPtr( hwnd );
978 if (!wndPtr) return FALSE;
982 if (wndPtr->hrgnUpdate > 1)
984 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
985 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
990 GetRgnBox( hrgn, rect );
991 DeleteObject( hrgn );
992 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
994 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
996 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1001 if( wndPtr->hrgnUpdate == 1 )
1003 GetClientRect( hwnd, rect );
1004 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1007 SetRectEmpty( rect );
1009 retvalue = (wndPtr->hrgnUpdate >= 1);
1011 WIN_ReleaseWndPtr(wndPtr);
1016 /***********************************************************************
1017 * GetUpdateRgn (USER32.@)
1019 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1022 WND * wndPtr = WIN_FindWndPtr( hwnd );
1023 if (!wndPtr) return ERROR;
1025 if (wndPtr->hrgnUpdate == 0)
1027 SetRectRgn( hrgn, 0, 0, 0, 0 );
1028 retval = NULLREGION;
1032 if (wndPtr->hrgnUpdate == 1)
1034 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1035 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1036 retval = SIMPLEREGION;
1040 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1041 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1042 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1044 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1046 WIN_ReleaseWndPtr(wndPtr);
1051 /***********************************************************************
1052 * ExcludeUpdateRgn (USER32.@)
1054 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1059 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1061 if (wndPtr->hrgnUpdate)
1064 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1065 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1066 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1067 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1068 if( wndPtr->hrgnUpdate > 1 )
1070 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1071 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1072 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1075 /* do ugly coordinate translations in dce.c */
1077 ret = DCE_ExcludeRgn( hdc, hwnd, hrgn );
1078 DeleteObject( hrgn );
1079 WIN_ReleaseWndPtr(wndPtr);
1082 WIN_ReleaseWndPtr(wndPtr);
1083 return GetClipBox( hdc, &rect );
1088 /***********************************************************************
1089 * FillRect (USER.81)
1091 * The Win16 variant doesn't support special color brushes like
1092 * the Win32 one, despite the fact that Win16, as well as Win32,
1093 * supports special background brushes for a window class.
1095 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1099 /* coordinates are logical so we cannot fast-check 'rect',
1100 * it will be done later in the PatBlt().
1103 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1104 PatBlt( hdc, rect->left, rect->top,
1105 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1106 SelectObject( hdc, prevBrush );
1111 /***********************************************************************
1112 * FillRect (USER32.@)
1114 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1118 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1119 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1122 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1123 PatBlt( hdc, rect->left, rect->top,
1124 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1125 SelectObject( hdc, prevBrush );
1130 /***********************************************************************
1131 * InvertRect (USER.82)
1133 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1135 PatBlt( hdc, rect->left, rect->top,
1136 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1140 /***********************************************************************
1141 * InvertRect (USER32.@)
1143 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1145 return PatBlt( hdc, rect->left, rect->top,
1146 rect->right - rect->left, rect->bottom - rect->top,
1151 /***********************************************************************
1152 * FrameRect (USER32.@)
1154 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1159 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1160 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1162 PatBlt( hdc, r.left, r.top, 1,
1163 r.bottom - r.top, PATCOPY );
1164 PatBlt( hdc, r.right - 1, r.top, 1,
1165 r.bottom - r.top, PATCOPY );
1166 PatBlt( hdc, r.left, r.top,
1167 r.right - r.left, 1, PATCOPY );
1168 PatBlt( hdc, r.left, r.bottom - 1,
1169 r.right - r.left, 1, PATCOPY );
1171 SelectObject( hdc, prevBrush );
1176 /***********************************************************************
1177 * FrameRect (USER.83)
1179 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1182 CONV_RECT16TO32( rect16, &rect );
1183 return FrameRect( hdc, &rect, hbrush );
1187 /***********************************************************************
1188 * DrawFocusRect (USER.466)
1190 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1193 CONV_RECT16TO32( rc, &rect32 );
1194 DrawFocusRect( hdc, &rect32 );
1198 /***********************************************************************
1199 * DrawFocusRect (USER32.@)
1201 * FIXME: PatBlt(PATINVERT) with background brush.
1203 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1206 HPEN hOldPen, hNewPen;
1207 INT oldDrawMode, oldBkMode;
1209 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1210 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1211 hOldPen = SelectObject(hdc, hNewPen);
1212 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1213 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1215 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1217 SetBkMode(hdc, oldBkMode);
1218 SetROP2(hdc, oldDrawMode);
1219 SelectObject(hdc, hOldPen);
1220 DeleteObject(hNewPen);
1221 SelectObject(hdc, hOldBrush);
1227 /**********************************************************************
1228 * DrawAnimatedRects (USER32.@)
1230 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1231 const RECT* lprcFrom,
1232 const RECT* lprcTo )
1234 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1239 /**********************************************************************
1240 * PAINTING_DrawStateJam
1242 * Jams in the requested type in the dc
1244 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1245 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1246 LPRECT rc, UINT dtflags, BOOL unicode )
1251 INT cx = rc->right - rc->left;
1252 INT cy = rc->bottom - rc->top;
1257 case DST_PREFIXTEXT:
1259 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1261 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1264 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1267 memdc = CreateCompatibleDC(hdc);
1268 if(!memdc) return FALSE;
1269 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1275 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1276 SelectObject(memdc, hbmsave);
1283 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1285 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1286 bRet = func(hdc, lp, wp, cx, cy);
1287 /* Restore origin */
1288 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1296 /**********************************************************************
1297 * PAINTING_DrawState()
1299 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1300 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1302 HBITMAP hbm, hbmsave;
1304 HBRUSH hbsave, hbrtmp = 0;
1307 UINT dtflags = DT_NOCLIP;
1309 UINT opcode = flags & 0xf;
1313 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1316 len = strlenW((LPWSTR)lp);
1318 len = strlen((LPSTR)lp);
1321 /* Find out what size the image has if not given by caller */
1325 CURSORICONINFO *ici;
1331 case DST_PREFIXTEXT:
1333 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1335 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1336 if(!retval) return FALSE;
1340 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1341 if(!ici) return FALSE;
1343 s.cy = ici->nHeight;
1344 GlobalUnlock16((HGLOBAL16)lp);
1348 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1354 case DST_COMPLEX: /* cx and cy must be set in this mode */
1367 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1368 dtflags |= DT_RIGHT;
1369 if(opcode == DST_TEXT)
1370 dtflags |= DT_NOPREFIX;
1372 /* For DSS_NORMAL we just jam in the image and return */
1373 if((flags & 0x7ff0) == DSS_NORMAL)
1375 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1378 /* For all other states we need to convert the image to B/W in a local bitmap */
1379 /* before it is displayed */
1380 fg = SetTextColor(hdc, RGB(0, 0, 0));
1381 bg = SetBkColor(hdc, RGB(255, 255, 255));
1382 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1383 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1384 retval = FALSE; /* assume failure */
1386 /* From here on we must use "goto cleanup" when something goes wrong */
1387 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1388 if(!hbm) goto cleanup;
1389 memdc = CreateCompatibleDC(hdc);
1390 if(!memdc) goto cleanup;
1391 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1392 if(!hbmsave) goto cleanup;
1393 rc.left = rc.top = 0;
1396 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1397 SetBkColor(memdc, RGB(255, 255, 255));
1398 SetTextColor(memdc, RGB(0, 0, 0));
1399 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1401 /* DST_COMPLEX may draw text as well,
1402 * so we must be sure that correct font is selected
1404 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1405 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1406 if(hfsave) SelectObject(memdc, hfsave);
1407 if(!tmp) goto cleanup;
1409 /* This state cause the image to be dithered */
1410 if(flags & DSS_UNION)
1412 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1413 if(!hbsave) goto cleanup;
1414 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1415 SelectObject(memdc, hbsave);
1416 if(!tmp) goto cleanup;
1419 if (flags & DSS_DISABLED)
1420 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1421 else if (flags & DSS_DEFAULT)
1422 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1424 /* Draw light or dark shadow */
1425 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1427 if(!hbrtmp) goto cleanup;
1428 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1429 if(!hbsave) goto cleanup;
1430 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1431 SelectObject(hdc, hbsave);
1432 DeleteObject(hbrtmp);
1436 if (flags & DSS_DISABLED)
1438 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1439 if(!hbrtmp) goto cleanup;
1443 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1446 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1448 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1450 retval = TRUE; /* We succeeded */
1453 SetTextColor(hdc, fg);
1454 SetBkColor(hdc, bg);
1456 if(hbsave) SelectObject(hdc, hbsave);
1457 if(hbmsave) SelectObject(memdc, hbmsave);
1458 if(hbrtmp) DeleteObject(hbrtmp);
1459 if(hbm) DeleteObject(hbm);
1460 if(memdc) DeleteDC(memdc);
1465 /**********************************************************************
1466 * DrawStateA (USER32.@)
1468 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1469 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1470 INT x, INT y, INT cx, INT cy, UINT flags)
1472 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1475 /**********************************************************************
1476 * DrawStateW (USER32.@)
1478 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1479 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1480 INT x, INT y, INT cx, INT cy, UINT flags)
1482 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);
1485 /***********************************************************************
1486 * SelectPalette (USER.282)
1488 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1489 BOOL16 bForceBackground )
1491 WORD wBkgPalette = 1;
1493 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1495 HWND hwnd = WindowFromDC( hDC );
1498 HWND hForeground = GetForegroundWindow();
1499 /* set primary palette if it's related to current active */
1500 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1503 return GDISelectPalette16( hDC, hPal, wBkgPalette);
1507 /***********************************************************************
1508 * RealizePalette (USER.283)
1510 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1512 UINT16 realized = GDIRealizePalette16( hDC );
1514 /* do not send anything if no colors were changed */
1515 if (realized && IsDCCurrentPalette16( hDC ))
1517 /* send palette change notification */
1518 HWND hWnd = WindowFromDC( hDC );
1519 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0L);
1525 /***********************************************************************
1526 * UserRealizePalette (USER32.@)
1528 UINT WINAPI UserRealizePalette( HDC hDC )
1530 return RealizePalette16( hDC );