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
25 #include "wine/winuser16.h"
27 #include "wine/unicode.h"
28 #include "wine/server.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(win);
37 WINE_DECLARE_DEBUG_CHANNEL(nonclient);
39 /* client rect in window coordinates */
41 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
42 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
43 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
44 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
46 /* PAINT_RedrawWindow() control flags */
47 #define RDW_EX_DELAY_NCPAINT 0x0020
49 /* WIN_UpdateNCRgn() flags */
50 #define UNC_CHECK 0x0001
51 #define UNC_ENTIRE 0x0002
52 #define UNC_REGION 0x0004
53 #define UNC_UPDATE 0x0008
54 #define UNC_DELAY_NCPAINT 0x0010
55 #define UNC_IN_BEGINPAINT 0x0020
58 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
60 HPALETTE (WINAPI *pfnGDISelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd ) = NULL;
61 UINT (WINAPI *pfnGDIRealizePalette)(HDC hdc) = NULL;
63 /* ### start build ### */
64 extern WORD CALLBACK PAINTING_CallTo16_word_wlwww(DRAWSTATEPROC16,WORD,LONG,WORD,WORD,WORD);
65 /* ### stop build ### */
67 struct draw_state_info
73 /* callback for 16-bit DrawState functions */
74 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
76 const struct draw_state_info *info = (struct draw_state_info *)lparam;
77 return PAINTING_CallTo16_word_wlwww( info->proc, HDC_16(hdc), info->param, wparam, cx, cy );
81 /***********************************************************************
84 * Add an increment (normally 1 or -1) to the current paint count of a window.
86 static void add_paint_count( HWND hwnd, int incr )
88 SERVER_START_REQ( inc_window_paint_count )
92 wine_server_call( req );
98 /***********************************************************************
101 * hSrc: Region to crop.
102 * lpRect: Clipping rectangle.
104 * hDst: Region to hold the result (a new region is created if it's 0).
105 * Allowed to be the same region as hSrc in which case everything
106 * will be done in place, with no memory reallocations.
108 * Returns: hDst if success, 0 otherwise.
110 static HRGN crop_rgn( HRGN hDst, HRGN hSrc, const RECT *rect )
112 HRGN h = CreateRectRgnIndirect( rect );
113 if (hDst == 0) hDst = h;
114 CombineRgn( hDst, hSrc, h, RGN_AND );
115 if (hDst != h) DeleteObject( h );
120 /***********************************************************************
121 * WIN_HaveToDelayNCPAINT
123 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
124 * is generated as soon as a region intersecting the non-client area
125 * of a window is invalidated.
127 * This technique will work fine for all windows whose parents
128 * have the WS_CLIPCHILDREN style. When the parents have that style,
129 * they are not going to override the contents of their children.
130 * However, when the parent doesn't have that style, Windows relies
131 * on a "painter's algorithm" to display the contents of the windows.
132 * That is, windows are painted from back to front. This includes the
135 * This method looks at the current state of a window to determine
136 * if the sending of the WM_NCPAINT message should be delayed until
137 * the BeginPaint call.
140 * wndPtr - A Locked window pointer to the window we're
142 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
143 * function. This is a shortcut for the cases when
144 * we already know when to avoid scanning all the
145 * parents of a window. If you already know that this
146 * window's NCPAINT should be delayed, set the
147 * UNC_DELAY_NCPAINT flag for this parameter.
149 * This shortcut behavior is implemented in the
150 * RDW_Paint() method.
153 static BOOL WIN_HaveToDelayNCPAINT( HWND hwnd, UINT uncFlags)
156 * Test the shortcut first. (duh)
158 if (uncFlags & UNC_DELAY_NCPAINT)
162 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
163 * method only. This is another shortcut to avoid going
164 * up the parent's chain of the window to finally
165 * figure-out that none of them has an invalid region.
167 if (uncFlags & UNC_IN_BEGINPAINT)
171 * Scan all the parents of this window to find a window
172 * that doesn't have the WS_CLIPCHILDREN style and that
173 * has an invalid region.
175 while ((hwnd = GetAncestor( hwnd, GA_PARENT )))
177 WND* parentWnd = WIN_FindWndPtr( hwnd );
178 if (parentWnd && !(parentWnd->dwStyle & WS_CLIPCHILDREN) && parentWnd->hrgnUpdate)
180 WIN_ReleaseWndPtr( parentWnd );
183 WIN_ReleaseWndPtr( parentWnd );
188 /***********************************************************************
192 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
193 * Crop hrgnUpdate to a client rect, especially if it 1.
194 * If UNC_REGION is set return update region for the client rect.
196 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
197 * The trick is that when the returned region handle may be different from hRgn.
198 * In this case the old hRgn must be considered gone. BUT, if the returned value
199 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
200 * a DC without extra clipping region.
202 static HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
208 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
209 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
211 /* desktop window doesn't have a nonclient area */
212 if(wnd->hwndSelf == GetDesktopWindow())
214 wnd->flags &= ~WIN_NEEDS_NCPAINT;
215 if( wnd->hrgnUpdate > (HRGN)1 )
217 if (!hRgn) hRgn = CreateRectRgn( 0, 0, 0, 0 );
218 CombineRgn( hRgn, wnd->hrgnUpdate, 0, RGN_COPY );
223 hrgnRet = wnd->hrgnUpdate;
228 if ((wnd->hwndSelf == GetForegroundWindow()) &&
229 !(wnd->flags & WIN_NCACTIVATED) )
231 wnd->flags |= WIN_NCACTIVATED;
232 uncFlags |= UNC_ENTIRE;
236 * If the window's non-client area needs to be painted,
238 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
239 !WIN_HaveToDelayNCPAINT(wnd->hwndSelf, uncFlags) )
243 wnd->flags &= ~WIN_NEEDS_NCPAINT;
244 GETCLIENTRECTW( wnd, r );
246 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
247 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
248 if( wnd->hrgnUpdate > (HRGN)1 )
250 /* Check if update rgn overlaps with nonclient area */
252 GetRgnBox( wnd->hrgnUpdate, &r2 );
253 UnionRect( &r3, &r2, &r );
254 if( r3.left != r.left || r3.top != r.top ||
255 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
257 /* crop hrgnUpdate, save old one in hClip - the only
258 * case that places a valid region handle in hClip */
260 hClip = wnd->hrgnUpdate;
261 wnd->hrgnUpdate = crop_rgn( hRgn, hClip, &r );
262 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
265 if( uncFlags & UNC_CHECK )
267 GetRgnBox( wnd->hrgnUpdate, &r3 );
268 if( IsRectEmpty( &r3 ) )
270 /* delete the update region since all invalid
271 * parts were in the nonclient area */
273 DeleteObject( wnd->hrgnUpdate );
275 if(!(wnd->flags & WIN_INTERNAL_PAINT))
276 add_paint_count( wnd->hwndSelf, -1 );
278 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
282 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
285 if( wnd->hrgnUpdate == (HRGN)1 )/* entire window */
287 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
288 if( uncFlags & UNC_REGION ) hrgnRet = (HRGN)1;
289 uncFlags |= UNC_ENTIRE;
292 else /* no WM_NCPAINT unless forced */
294 if( wnd->hrgnUpdate > (HRGN)1 )
297 if( uncFlags & UNC_REGION )
299 if (!hRgn) hRgn = CreateRectRgn( 0, 0, 0, 0 );
300 CombineRgn( hRgn, wnd->hrgnUpdate, 0, RGN_COPY );
305 if( wnd->hrgnUpdate == (HRGN)1 && (uncFlags & UNC_UPDATE) )
307 GETCLIENTRECTW( wnd, r );
308 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
309 if( uncFlags & UNC_REGION ) hrgnRet = (HRGN)1;
313 if(!hClip && (uncFlags & UNC_ENTIRE) )
315 /* still don't do anything if there is no nonclient area */
316 hClip = (HRGN)(memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
319 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
321 if ( hClip == hrgnRet && hrgnRet > (HRGN)1 ) {
322 hClip = CreateRectRgn( 0, 0, 0, 0 );
323 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
326 SendMessageA( wnd->hwndSelf, WM_NCPAINT, (WPARAM)hClip, 0L );
327 if( (hClip > (HRGN)1) && (hClip != hRgn) && (hClip != hrgnRet) )
328 DeleteObject( hClip );
330 * Since all Window locks are suspended while processing the WM_NCPAINT
331 * we want to make sure the window still exists before continuing.
333 if (!IsWindow(wnd->hwndSelf))
335 DeleteObject(hrgnRet);
340 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
346 /***********************************************************************
347 * RDW_ValidateParent [RDW_UpdateRgns() helper]
349 * Validate the portions of parents that are covered by a validated child
352 static void RDW_ValidateParent(WND *wndChild)
357 if (wndChild->hrgnUpdate == (HRGN)1 ) {
361 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
362 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
363 hrg = CreateRectRgnIndirect( &r );
365 hrg = wndChild->hrgnUpdate;
367 parent = GetAncestor( wndChild->hwndSelf, GA_PARENT );
368 while (parent && parent != GetDesktopWindow())
370 WND *wndParent = WIN_FindWndPtr( parent );
371 if (wndParent && !(wndParent->dwStyle & WS_CLIPCHILDREN))
373 if (wndParent->hrgnUpdate != 0)
376 RECT rect, rectParent;
377 if( wndParent->hrgnUpdate == (HRGN)1 )
383 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
384 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
386 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
388 /* we must offset the child region by the offset of the child rect in the parent */
389 GetWindowRect(wndParent->hwndSelf, &rectParent);
390 GetWindowRect(wndChild->hwndSelf, &rect);
391 ptOffset.x = rect.left - rectParent.left;
392 ptOffset.y = rect.top - rectParent.top;
393 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
394 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
395 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
398 WIN_ReleaseWndPtr( wndParent );
399 parent = GetAncestor( parent, GA_PARENT );
401 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
404 /***********************************************************************
405 * RDW_UpdateRgns [RedrawWindow() helper]
407 * Walks the window tree and adds/removes parts of the hRgn to/from update
408 * regions of windows that overlap it. Also, manages internal paint flags.
410 * NOTE: Walks the window tree so the caller must lock it.
411 * MUST preserve hRgn (can modify but then has to restore).
413 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
416 * Called only when one of the following is set:
417 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
420 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
421 BOOL bChildren = (!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
422 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
427 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
428 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
430 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
432 if( flags & RDW_INVALIDATE )
436 switch ((UINT)wndPtr->hrgnUpdate)
439 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
442 wndPtr->hrgnUpdate = crop_rgn( wndPtr->hrgnUpdate,
443 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
447 GetRgnBox( wndPtr->hrgnUpdate, &r );
448 if( IsRectEmpty( &r ) )
450 DeleteObject( wndPtr->hrgnUpdate );
451 wndPtr->hrgnUpdate = 0;
456 case 1: /* already an entire window */
460 else if( hRgn == (HRGN)1 )
462 if( wndPtr->hrgnUpdate > (HRGN)1 )
463 DeleteObject( wndPtr->hrgnUpdate );
464 wndPtr->hrgnUpdate = (HRGN)1;
467 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
469 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
470 add_paint_count( wndPtr->hwndSelf, 1 );
472 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
473 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
476 else if( flags & RDW_VALIDATE )
478 if( wndPtr->hrgnUpdate )
482 if( wndPtr->hrgnUpdate == (HRGN)1 )
483 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
485 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
488 DeleteObject( wndPtr->hrgnUpdate );
489 wndPtr->hrgnUpdate = 0;
492 else /* validate everything */
494 if( wndPtr->hrgnUpdate > (HRGN)1 ) DeleteObject( wndPtr->hrgnUpdate );
495 wndPtr->hrgnUpdate = 0;
498 if( !wndPtr->hrgnUpdate )
500 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
501 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
502 add_paint_count( wndPtr->hwndSelf, -1 );
506 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
507 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
511 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
512 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
514 /* in/validate child windows that intersect with the region if it
515 * is a valid handle. */
517 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
520 if( hRgn > (HRGN)1 && bChildren && (list = WIN_ListChildren( wndPtr->hwndSelf )))
522 POINT ptTotal, prevOrigin = {0,0};
526 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
527 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
529 for(i = ptTotal.x = ptTotal.y = 0; list[i]; i++)
531 WND *wnd = WIN_FindWndPtr( list[i] );
533 if( wnd->dwStyle & WS_VISIBLE )
537 r.left = wnd->rectWindow.left + ptClient.x;
538 r.right = wnd->rectWindow.right + ptClient.x;
539 r.top = wnd->rectWindow.top + ptClient.y;
540 r.bottom = wnd->rectWindow.bottom + ptClient.y;
542 ptOffset.x = r.left - prevOrigin.x;
543 ptOffset.y = r.top - prevOrigin.y;
544 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
546 if( RectInRegion( hRgn, &r ) )
548 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
549 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
550 prevOrigin.x = r.left + ptTotal.x;
551 prevOrigin.y = r.top + ptTotal.y;
552 ptTotal.x += ptOffset.x;
553 ptTotal.y += ptOffset.y;
556 WIN_ReleaseWndPtr( wnd );
558 HeapFree( GetProcessHeap(), 0, list );
559 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
564 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
569 if ((list = WIN_ListChildren( wndPtr->hwndSelf )))
572 for (i = 0; list[i]; i++)
574 WND *wnd = WIN_FindWndPtr( list[i] );
576 if( wnd->dwStyle & WS_VISIBLE )
577 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
578 WIN_ReleaseWndPtr( wnd );
580 HeapFree( GetProcessHeap(), 0, list );
586 /* Set/clear internal paint flag */
588 if (flags & RDW_INTERNALPAINT)
590 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
591 add_paint_count( wndPtr->hwndSelf, 1 );
592 wndPtr->flags |= WIN_INTERNAL_PAINT;
594 else if (flags & RDW_NOINTERNALPAINT)
596 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
597 add_paint_count( wndPtr->hwndSelf, -1 );
598 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
602 /***********************************************************************
603 * RDW_Paint [RedrawWindow() helper]
605 * Walks the window tree and paints/erases windows that have
606 * nonzero update regions according to redraw flags. hrgn is a scratch
607 * region passed down during recursion. Must not be 1.
610 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
612 /* NOTE: wndPtr is locked by caller.
614 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
615 * SendMessage() calls. This is a comment inside DefWindowProc() source
618 * This message avoids lots of inter-app message traffic
619 * by switching to the other task and continuing the
623 * LOWORD(lParam) = hrgnClip
624 * HIWORD(lParam) = hwndSkip (not used; always NULL)
628 HWND hWnd = wndPtr->hwndSelf;
629 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassLongA(hWnd, GCL_HICON));
631 /* Erase/update the window itself ... */
633 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
636 * Check if this window should delay it's processing of WM_NCPAINT.
637 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
639 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr->hwndSelf, 0) )
640 ex |= RDW_EX_DELAY_NCPAINT;
642 if (flags & RDW_UPDATENOW)
644 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
645 SendMessageW( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
647 else if (flags & RDW_ERASENOW)
649 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
652 hrgnRet = WIN_UpdateNCRgn(wndPtr,
654 UNC_REGION | UNC_CHECK |
655 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
659 if( hrgnRet > (HRGN)1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
660 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
662 if( bIcon ) dcx |= DCX_WINDOW;
665 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
666 wndPtr->rectWindow.top - wndPtr->rectClient.top);
668 dcx &= ~DCX_INTERSECTRGN;
669 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
671 if (SendMessageW( hWnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
673 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
674 ReleaseDC( hWnd, hDC );
680 if( !IsWindow(hWnd) ) return hrgn;
682 /* ... and its child windows */
684 if(!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
685 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
689 if( (list = WIN_ListChildren( wndPtr->hwndSelf )) )
691 for (phwnd = list; *phwnd; phwnd++)
693 if (!(wndPtr = WIN_FindWndPtr( *phwnd ))) continue;
694 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
695 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
696 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
697 WIN_ReleaseWndPtr(wndPtr);
699 HeapFree( GetProcessHeap(), 0, list );
707 /***********************************************************************
708 * RedrawWindow (USER32.@)
710 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
711 HRGN hrgnUpdate, UINT flags )
718 if (!hwnd) hwnd = GetDesktopWindow();
720 /* check if the window or its parents are visible/not minimized */
722 if (!WIN_IsWindowDrawable( hwnd, !(flags & RDW_FRAME) )) return TRUE;
724 /* process pending events and messages before painting */
725 if (flags & RDW_UPDATENOW)
726 MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_ALLINPUT );
728 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
733 GetRgnBox( hrgnUpdate, &r );
734 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
735 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags );
743 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
744 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
745 r.top, r.right, r.bottom, hrgnUpdate, flags );
749 /* prepare an update region in window coordinates */
751 if (((flags & (RDW_INVALIDATE|RDW_FRAME)) == (RDW_INVALIDATE|RDW_FRAME)) ||
752 ((flags & (RDW_VALIDATE|RDW_NOFRAME)) == (RDW_VALIDATE|RDW_NOFRAME)))
753 r = wndPtr->rectWindow;
755 r = wndPtr->rectClient;
757 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
758 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
759 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
761 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
763 /* If the window doesn't have hrgnUpdate we leave hRgn zero
764 * and put a new region straight into wndPtr->hrgnUpdate
765 * so that RDW_UpdateRgns() won't have to do any extra work.
770 if( wndPtr->hrgnUpdate )
772 hRgn = CreateRectRgn( 0, 0, 0, 0 );
773 CombineRgn( hRgn, hrgnUpdate, 0, RGN_COPY );
774 OffsetRgn( hRgn, pt.x, pt.y );
778 wndPtr->hrgnUpdate = crop_rgn( 0, hrgnUpdate, &r );
779 OffsetRgn( wndPtr->hrgnUpdate, pt.x, pt.y );
782 else if( rectUpdate )
784 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
785 OffsetRect( &r2, pt.x, pt.y );
786 if( wndPtr->hrgnUpdate == 0 )
787 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
789 hRgn = CreateRectRgnIndirect( &r2 );
791 else /* entire window or client depending on RDW_FRAME */
793 if( flags & RDW_FRAME )
795 if (wndPtr->hrgnUpdate) hRgn = (HRGN)1;
796 else wndPtr->hrgnUpdate = (HRGN)1;
800 GETCLIENTRECTW( wndPtr, r2 );
801 if( wndPtr->hrgnUpdate == 0 )
802 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
804 hRgn = CreateRectRgnIndirect( &r2 );
808 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
810 /* In this we cannot leave with zero hRgn */
813 hRgn = crop_rgn( hRgn, hrgnUpdate, &r );
814 OffsetRgn( hRgn, pt.x, pt.y );
815 GetRgnBox( hRgn, &r2 );
816 if( IsRectEmpty( &r2 ) ) goto END;
818 else if( rectUpdate )
820 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
821 OffsetRect( &r2, pt.x, pt.y );
822 hRgn = CreateRectRgnIndirect( &r2 );
824 else /* entire window or client depending on RDW_NOFRAME */
826 if( flags & RDW_NOFRAME )
830 GETCLIENTRECTW( wndPtr, r2 );
831 hRgn = CreateRectRgnIndirect( &r2 );
836 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
838 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
840 /* Erase/update windows, from now on hRgn is a scratch region */
842 hRgn = RDW_Paint( wndPtr, (hRgn == (HRGN)1) ? 0 : hRgn, flags, 0 );
845 if( hRgn > (HRGN)1 && (hRgn != hrgnUpdate) )
847 WIN_ReleaseWndPtr(wndPtr);
852 /***********************************************************************
853 * UpdateWindow (USER32.@)
855 void WINAPI UpdateWindow( HWND hwnd )
857 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
861 /***********************************************************************
862 * InvalidateRgn (USER32.@)
864 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
866 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
870 /***********************************************************************
871 * InvalidateRect (USER32.@)
873 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
875 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
879 /***********************************************************************
880 * ValidateRgn (USER32.@)
882 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
884 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
888 /***********************************************************************
889 * ValidateRect (USER32.@)
891 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
893 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
897 /***********************************************************************
898 * GetUpdateRect (USER32.@)
900 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
903 WND * wndPtr = WIN_FindWndPtr( hwnd );
904 if (!wndPtr) return FALSE;
908 if (wndPtr->hrgnUpdate > (HRGN)1)
910 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
911 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
916 GetRgnBox( hrgn, rect );
917 DeleteObject( hrgn );
918 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
920 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
922 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
927 if( wndPtr->hrgnUpdate == (HRGN)1 )
929 GetClientRect( hwnd, rect );
930 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
933 SetRectEmpty( rect );
935 retvalue = (wndPtr->hrgnUpdate >= (HRGN)1);
937 WIN_ReleaseWndPtr(wndPtr);
942 /***********************************************************************
943 * GetUpdateRgn (USER32.@)
945 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
948 WND * wndPtr = WIN_FindWndPtr( hwnd );
949 if (!wndPtr) return ERROR;
951 if (wndPtr->hrgnUpdate == 0)
953 SetRectRgn( hrgn, 0, 0, 0, 0 );
958 if (wndPtr->hrgnUpdate == (HRGN)1)
960 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
961 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
962 retval = SIMPLEREGION;
966 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
967 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
968 wndPtr->rectWindow.top - wndPtr->rectClient.top );
970 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
972 WIN_ReleaseWndPtr(wndPtr);
977 /***********************************************************************
978 * ExcludeUpdateRgn (USER32.@)
980 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
985 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
987 if (wndPtr->hrgnUpdate)
990 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
991 wndPtr->rectWindow.top - wndPtr->rectClient.top,
992 wndPtr->rectWindow.right - wndPtr->rectClient.left,
993 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
994 if( wndPtr->hrgnUpdate > (HRGN)1 )
996 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
997 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
998 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1001 /* do ugly coordinate translations in dce.c */
1003 ret = DCE_ExcludeRgn( hdc, hwnd, hrgn );
1004 DeleteObject( hrgn );
1005 WIN_ReleaseWndPtr(wndPtr);
1008 WIN_ReleaseWndPtr(wndPtr);
1009 return GetClipBox( hdc, &rect );
1014 /***********************************************************************
1015 * FillRect (USER.81)
1017 * The Win16 variant doesn't support special color brushes like
1018 * the Win32 one, despite the fact that Win16, as well as Win32,
1019 * supports special background brushes for a window class.
1021 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1025 /* coordinates are logical so we cannot fast-check 'rect',
1026 * it will be done later in the PatBlt().
1029 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
1030 PatBlt( HDC_32(hdc), rect->left, rect->top,
1031 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1032 SelectObject( HDC_32(hdc), prevBrush );
1037 /***********************************************************************
1038 * FillRect (USER32.@)
1040 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1044 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1045 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1048 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1049 PatBlt( hdc, rect->left, rect->top,
1050 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1051 SelectObject( hdc, prevBrush );
1056 /***********************************************************************
1057 * InvertRect (USER.82)
1059 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1061 PatBlt( HDC_32(hdc), rect->left, rect->top,
1062 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1066 /***********************************************************************
1067 * InvertRect (USER32.@)
1069 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1071 return PatBlt( hdc, rect->left, rect->top,
1072 rect->right - rect->left, rect->bottom - rect->top,
1077 /***********************************************************************
1078 * FrameRect (USER32.@)
1080 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1085 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1086 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1088 PatBlt( hdc, r.left, r.top, 1,
1089 r.bottom - r.top, PATCOPY );
1090 PatBlt( hdc, r.right - 1, r.top, 1,
1091 r.bottom - r.top, PATCOPY );
1092 PatBlt( hdc, r.left, r.top,
1093 r.right - r.left, 1, PATCOPY );
1094 PatBlt( hdc, r.left, r.bottom - 1,
1095 r.right - r.left, 1, PATCOPY );
1097 SelectObject( hdc, prevBrush );
1102 /***********************************************************************
1103 * FrameRect (USER.83)
1105 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1108 CONV_RECT16TO32( rect16, &rect );
1109 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
1113 /***********************************************************************
1114 * DrawFocusRect (USER.466)
1116 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1119 CONV_RECT16TO32( rc, &rect32 );
1120 DrawFocusRect( HDC_32(hdc), &rect32 );
1124 /***********************************************************************
1125 * DrawFocusRect (USER32.@)
1127 * FIXME: PatBlt(PATINVERT) with background brush.
1129 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1132 HPEN hOldPen, hNewPen;
1133 INT oldDrawMode, oldBkMode;
1135 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1136 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1137 hOldPen = SelectObject(hdc, hNewPen);
1138 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1139 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1141 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1143 SetBkMode(hdc, oldBkMode);
1144 SetROP2(hdc, oldDrawMode);
1145 SelectObject(hdc, hOldPen);
1146 DeleteObject(hNewPen);
1147 SelectObject(hdc, hOldBrush);
1153 /**********************************************************************
1154 * DrawAnimatedRects (USER32.@)
1156 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1157 const RECT* lprcFrom,
1158 const RECT* lprcTo )
1160 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1165 /**********************************************************************
1166 * PAINTING_DrawStateJam
1168 * Jams in the requested type in the dc
1170 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1171 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1172 LPRECT rc, UINT dtflags, BOOL unicode )
1177 INT cx = rc->right - rc->left;
1178 INT cy = rc->bottom - rc->top;
1183 case DST_PREFIXTEXT:
1185 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1187 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1190 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1193 memdc = CreateCompatibleDC(hdc);
1194 if(!memdc) return FALSE;
1195 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1201 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1202 SelectObject(memdc, hbmsave);
1209 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1211 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1212 bRet = func(hdc, lp, wp, cx, cy);
1213 /* Restore origin */
1214 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1222 /**********************************************************************
1223 * PAINTING_DrawState()
1225 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1226 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1228 HBITMAP hbm, hbmsave;
1230 HBRUSH hbsave, hbrtmp = 0;
1233 UINT dtflags = DT_NOCLIP;
1235 UINT opcode = flags & 0xf;
1239 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1242 len = strlenW((LPWSTR)lp);
1244 len = strlen((LPSTR)lp);
1247 /* Find out what size the image has if not given by caller */
1251 CURSORICONINFO *ici;
1257 case DST_PREFIXTEXT:
1259 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1261 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1262 if(!retval) return FALSE;
1266 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1267 if(!ici) return FALSE;
1269 s.cy = ici->nHeight;
1270 GlobalUnlock16((HGLOBAL16)lp);
1274 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1280 case DST_COMPLEX: /* cx and cy must be set in this mode */
1293 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1294 dtflags |= DT_RIGHT;
1295 if(opcode == DST_TEXT)
1296 dtflags |= DT_NOPREFIX;
1298 /* For DSS_NORMAL we just jam in the image and return */
1299 if((flags & 0x7ff0) == DSS_NORMAL)
1301 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1304 /* For all other states we need to convert the image to B/W in a local bitmap */
1305 /* before it is displayed */
1306 fg = SetTextColor(hdc, RGB(0, 0, 0));
1307 bg = SetBkColor(hdc, RGB(255, 255, 255));
1308 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1309 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1310 retval = FALSE; /* assume failure */
1312 /* From here on we must use "goto cleanup" when something goes wrong */
1313 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1314 if(!hbm) goto cleanup;
1315 memdc = CreateCompatibleDC(hdc);
1316 if(!memdc) goto cleanup;
1317 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1318 if(!hbmsave) goto cleanup;
1319 rc.left = rc.top = 0;
1322 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1323 SetBkColor(memdc, RGB(255, 255, 255));
1324 SetTextColor(memdc, RGB(0, 0, 0));
1325 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1327 /* DST_COMPLEX may draw text as well,
1328 * so we must be sure that correct font is selected
1330 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1331 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1332 if(hfsave) SelectObject(memdc, hfsave);
1333 if(!tmp) goto cleanup;
1335 /* This state cause the image to be dithered */
1336 if(flags & DSS_UNION)
1338 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1339 if(!hbsave) goto cleanup;
1340 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1341 SelectObject(memdc, hbsave);
1342 if(!tmp) goto cleanup;
1345 if (flags & DSS_DISABLED)
1346 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1347 else if (flags & DSS_DEFAULT)
1348 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1350 /* Draw light or dark shadow */
1351 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1353 if(!hbrtmp) goto cleanup;
1354 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1355 if(!hbsave) goto cleanup;
1356 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1357 SelectObject(hdc, hbsave);
1358 DeleteObject(hbrtmp);
1362 if (flags & DSS_DISABLED)
1364 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1365 if(!hbrtmp) goto cleanup;
1369 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1372 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1374 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1376 retval = TRUE; /* We succeeded */
1379 SetTextColor(hdc, fg);
1380 SetBkColor(hdc, bg);
1382 if(hbsave) SelectObject(hdc, hbsave);
1383 if(hbmsave) SelectObject(memdc, hbmsave);
1384 if(hbrtmp) DeleteObject(hbrtmp);
1385 if(hbm) DeleteObject(hbm);
1386 if(memdc) DeleteDC(memdc);
1391 /**********************************************************************
1392 * DrawStateA (USER32.@)
1394 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1395 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1396 INT x, INT y, INT cx, INT cy, UINT flags)
1398 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1401 /**********************************************************************
1402 * DrawStateW (USER32.@)
1404 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1405 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1406 INT x, INT y, INT cx, INT cy, UINT flags)
1408 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);
1412 /**********************************************************************
1413 * DrawState (USER.449)
1415 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1416 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1418 struct draw_state_info info;
1419 UINT opcode = flags & 0xf;
1421 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1423 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1424 if (!wdata) wdata = strlen( MapSL(ldata) );
1428 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1435 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1436 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1440 /***********************************************************************
1441 * SelectPalette (Not a Windows API)
1443 HPALETTE WINAPI SelectPalette( HDC hDC, HPALETTE hPal, BOOL bForceBackground )
1445 WORD wBkgPalette = 1;
1447 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1449 HWND hwnd = WindowFromDC( hDC );
1452 HWND hForeground = GetForegroundWindow();
1453 /* set primary palette if it's related to current active */
1454 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1457 return pfnGDISelectPalette( hDC, hPal, wBkgPalette);
1461 /***********************************************************************
1462 * UserRealizePalette (USER32.@)
1464 UINT WINAPI UserRealizePalette( HDC hDC )
1466 UINT realized = pfnGDIRealizePalette( hDC );
1468 /* do not send anything if no colors were changed */
1469 if (realized && IsDCCurrentPalette16( HDC_16(hDC) ))
1471 /* send palette change notification */
1472 HWND hWnd = WindowFromDC( hDC );
1473 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0L);