2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/unicode.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
32 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
34 /* Last CTLCOLOR id */
35 #define CTLCOLOR_MAX CTLCOLOR_STATIC
38 /***********************************************************************
39 * WIN_HaveToDelayNCPAINT
41 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
42 * is generated as soon as a region intersecting the non-client area
43 * of a window is invalidated.
45 * This technique will work fine for all windows whose parents
46 * have the WS_CLIPCHILDREN style. When the parents have that style,
47 * they are not going to override the contents of their children.
48 * However, when the parent doesn't have that style, Windows relies
49 * on a "painter's algorithm" to display the contents of the windows.
50 * That is, windows are painted from back to front. This includes the
53 * This method looks at the current state of a window to determine
54 * if the sending of the WM_NCPAINT message should be delayed until
55 * the BeginPaint call.
58 * wndPtr - A Locked window pointer to the window we're
60 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
61 * function. This is a shortcut for the cases when
62 * we already know when to avoid scanning all the
63 * parents of a window. If you already know that this
64 * window's NCPAINT should be delayed, set the
65 * UNC_DELAY_NCPAINT flag for this parameter.
67 * This shortcut behavior is implemented in the
71 static BOOL WIN_HaveToDelayNCPAINT(
75 WND* parentWnd = NULL;
78 * Test the shortcut first. (duh)
80 if (uncFlags & UNC_DELAY_NCPAINT)
84 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
85 * method only. This is another shortcut to avoid going
86 * up the parent's chain of the window to finally
87 * figure-out that none of them has an invalid region.
89 if (uncFlags & UNC_IN_BEGINPAINT)
93 * Scan all the parents of this window to find a window
94 * that doesn't have the WS_CLIPCHILDREN style and that
95 * has an invalid region.
97 parentWnd = WIN_LockWndPtr(wndPtr->parent);
99 while (parentWnd!=NULL)
101 if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
102 (parentWnd->hrgnUpdate != 0) )
104 WIN_ReleaseWndPtr(parentWnd);
108 WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);
111 WIN_ReleaseWndPtr(parentWnd);
116 /***********************************************************************
120 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
121 * Crop hrgnUpdate to a client rect, especially if it 1.
122 * If UNC_REGION is set return update region for the client rect.
124 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
125 * The trick is that when the returned region handle may be different from hRgn.
126 * In this case the old hRgn must be considered gone. BUT, if the returned value
127 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
128 * a DC without extra clipping region.
130 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
136 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
137 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
139 /* desktop window doesn't have a nonclient area */
140 if(wnd == WIN_GetDesktop())
142 wnd->flags &= ~WIN_NEEDS_NCPAINT;
143 if( wnd->hrgnUpdate > 1 )
144 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
147 hrgnRet = wnd->hrgnUpdate;
149 WIN_ReleaseDesktop();
152 WIN_ReleaseDesktop();
154 if ((wnd->hwndSelf == GetForegroundWindow()) &&
155 !(wnd->flags & WIN_NCACTIVATED) )
157 wnd->flags |= WIN_NCACTIVATED;
158 uncFlags |= UNC_ENTIRE;
162 * If the window's non-client area needs to be painted,
164 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
165 !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
169 wnd->flags &= ~WIN_NEEDS_NCPAINT;
170 GETCLIENTRECTW( wnd, r );
172 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
173 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
174 if( wnd->hrgnUpdate > 1 )
176 /* Check if update rgn overlaps with nonclient area */
178 GetRgnBox( wnd->hrgnUpdate, &r2 );
179 UnionRect( &r3, &r2, &r );
180 if( r3.left != r.left || r3.top != r.top ||
181 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
183 /* crop hrgnUpdate, save old one in hClip - the only
184 * case that places a valid region handle in hClip */
186 hClip = wnd->hrgnUpdate;
187 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
188 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
191 if( uncFlags & UNC_CHECK )
193 GetRgnBox( wnd->hrgnUpdate, &r3 );
194 if( IsRectEmpty( &r3 ) )
196 /* delete the update region since all invalid
197 * parts were in the nonclient area */
199 DeleteObject( wnd->hrgnUpdate );
201 if(!(wnd->flags & WIN_INTERNAL_PAINT))
202 QUEUE_DecPaintCount( wnd->hmemTaskQ );
204 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
208 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
211 if( wnd->hrgnUpdate == 1 )/* entire window */
213 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
214 if( uncFlags & UNC_REGION ) hrgnRet = 1;
215 uncFlags |= UNC_ENTIRE;
218 else /* no WM_NCPAINT unless forced */
220 if( wnd->hrgnUpdate > 1 )
223 if( uncFlags & UNC_REGION )
224 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
227 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
229 GETCLIENTRECTW( wnd, r );
230 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
231 if( uncFlags & UNC_REGION ) hrgnRet = 1;
235 if(!hClip && (uncFlags & UNC_ENTIRE) )
237 /* still don't do anything if there is no nonclient area */
238 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
241 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
243 if ( hClip == hrgnRet && hrgnRet > 1 ) {
244 hClip = CreateRectRgn( 0, 0, 0, 0 );
245 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
248 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
249 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
250 DeleteObject( hClip );
252 * Since all Window locks are suspended while processing the WM_NCPAINT
253 * we want to make sure the window still exists before continuing.
255 if (!IsWindow(wnd->hwndSelf))
257 DeleteObject(hrgnRet);
262 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
268 /***********************************************************************
269 * BeginPaint (USER.39)
271 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
275 BeginPaint( hwnd, &ps );
277 lps->fErase = ps.fErase;
278 lps->rcPaint.top = ps.rcPaint.top;
279 lps->rcPaint.left = ps.rcPaint.left;
280 lps->rcPaint.right = ps.rcPaint.right;
281 lps->rcPaint.bottom = ps.rcPaint.bottom;
282 lps->fRestore = ps.fRestore;
283 lps->fIncUpdate = ps.fIncUpdate;
288 /***********************************************************************
289 * BeginPaint (USER32.@)
291 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
295 RECT clipRect, clientRect;
296 WND *wndPtr = WIN_FindWndPtr( hwnd );
297 if (!wndPtr) return 0;
299 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
301 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
303 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
304 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
307 * Make sure the window is still a window. All window locks are suspended
308 * when the WM_NCPAINT is sent.
310 if (!IsWindow(wndPtr->hwndSelf))
312 WIN_ReleaseWndPtr(wndPtr);
316 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
317 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
319 wndPtr->hrgnUpdate = 0;
320 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
324 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate);
326 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
328 /* Don't clip the output to the update region for CS_PARENTDC window */
330 DeleteObject(hrgnUpdate);
331 lps->hdc = GetDCEx( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
332 (bIcon ? DCX_WINDOW : 0) );
336 if( hrgnUpdate ) /* convert to client coordinates */
337 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
338 wndPtr->rectWindow.top - wndPtr->rectClient.top );
339 lps->hdc = GetDCEx(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
340 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
341 /* ReleaseDC() in EndPaint() will delete the region */
344 TRACE("hdc = %04x\n", lps->hdc);
348 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
349 WIN_ReleaseWndPtr(wndPtr);
353 /* It is possible that the clip box is bigger than the window itself,
354 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
355 than the window itself, so we need to intersect the cliprect with
358 GetClientRect( hwnd, &clientRect );
360 GetClipBox( lps->hdc, &clipRect );
361 LPtoDP(lps->hdc, (LPPOINT)&clipRect, 2); /* GetClipBox returns LP */
363 IntersectRect(&lps->rcPaint, &clientRect, &clipRect);
364 DPtoLP(lps->hdc, (LPPOINT)&lps->rcPaint, 2); /* we must return LP */
366 TRACE("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
367 lps->rcPaint.right, lps->rcPaint.bottom );
369 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
371 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
372 lps->fErase = !SendMessageA(hwnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
373 (WPARAM16)lps->hdc, 0 );
375 else lps->fErase = TRUE;
377 WIN_ReleaseWndPtr(wndPtr);
382 /***********************************************************************
385 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
387 ReleaseDC16( hwnd, lps->hdc );
393 /***********************************************************************
394 * EndPaint (USER32.@)
396 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
398 ReleaseDC( hwnd, lps->hdc );
404 /***********************************************************************
405 * FillWindow (USER.324)
407 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
411 GetClientRect( hwnd, &rect );
412 DPtoLP( hdc, (LPPOINT)&rect, 2 );
413 CONV_RECT32TO16( &rect, &rc16 );
414 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rc16 );
418 /***********************************************************************
419 * PAINT_GetControlBrush
421 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
423 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
424 (WPARAM)hDC, (LPARAM)hWnd );
425 if( !IsGDIObject16(bkgBrush) )
426 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
431 /***********************************************************************
432 * PaintRect (USER.325)
434 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
435 HBRUSH16 hbrush, const RECT16 *rect)
437 if( hbrush <= CTLCOLOR_MAX )
440 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
445 FillRect16( hdc, rect, hbrush );
449 /***********************************************************************
450 * GetControlBrush (USER.326)
452 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
454 WND* wndPtr = WIN_FindWndPtr( hwnd );
457 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
460 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
461 else parent = WIN_LockWndPtr(wndPtr->parent);
462 if( !parent ) parent = wndPtr;
463 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
464 WIN_ReleaseWndPtr(parent);
467 retvalue = (HBRUSH16)0;
469 WIN_ReleaseWndPtr(wndPtr);
474 /***********************************************************************
475 * RDW_ValidateParent [RDW_UpdateRgns() helper]
477 * Validate the portions of parents that are covered by a validated child
480 void RDW_ValidateParent(WND *wndChild)
482 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
483 WND *wndDesktop = WIN_GetDesktop();
486 if (wndChild->hrgnUpdate == 1 ) {
490 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
491 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
492 hrg = CreateRectRgnIndirect( &r );
494 hrg = wndChild->hrgnUpdate;
496 while ((wndParent) && (wndParent != wndDesktop) ) {
497 if (!(wndParent->dwStyle & WS_CLIPCHILDREN))
499 if (wndParent->hrgnUpdate != 0)
502 RECT rect, rectParent;
503 if( wndParent->hrgnUpdate == 1 )
509 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
510 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
512 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
514 /* we must offset the child region by the offset of the child rect in the parent */
515 GetWindowRect(wndParent->hwndSelf, &rectParent);
516 GetWindowRect(wndChild->hwndSelf, &rect);
517 ptOffset.x = rect.left - rectParent.left;
518 ptOffset.y = rect.top - rectParent.top;
519 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
520 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
521 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
524 WIN_UpdateWndPtr(&wndParent, wndParent->parent);
526 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
527 WIN_ReleaseWndPtr(wndParent);
528 WIN_ReleaseDesktop();
531 /***********************************************************************
532 * RDW_UpdateRgns [RedrawWindow() helper]
534 * Walks the window tree and adds/removes parts of the hRgn to/from update
535 * regions of windows that overlap it. Also, manages internal paint flags.
537 * NOTE: Walks the window tree so the caller must lock it.
538 * MUST preserve hRgn (can modify but then has to restore).
540 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
543 * Called only when one of the following is set:
544 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
547 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
548 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
549 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
554 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
555 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
557 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
559 if( flags & RDW_INVALIDATE )
563 switch( wndPtr->hrgnUpdate )
566 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
569 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
570 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
574 GetRgnBox( wndPtr->hrgnUpdate, &r );
575 if( IsRectEmpty( &r ) )
577 DeleteObject( wndPtr->hrgnUpdate );
578 wndPtr->hrgnUpdate = 0;
583 case 1: /* already an entire window */
589 if( wndPtr->hrgnUpdate > 1 )
590 DeleteObject( wndPtr->hrgnUpdate );
591 wndPtr->hrgnUpdate = 1;
594 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
596 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
597 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
599 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
600 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
603 else if( flags & RDW_VALIDATE )
605 if( wndPtr->hrgnUpdate )
609 if( wndPtr->hrgnUpdate == 1 )
610 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
612 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
616 else /* validate everything */
618 if( wndPtr->hrgnUpdate > 1 )
621 DeleteObject( wndPtr->hrgnUpdate );
623 wndPtr->hrgnUpdate = 0;
626 if( !wndPtr->hrgnUpdate )
628 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
629 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
630 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
634 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
635 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
639 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
640 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
642 /* in/validate child windows that intersect with the region if it
643 * is a valid handle. */
645 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
647 if( hRgn > 1 && bChildren )
649 WND* wnd = wndPtr->child;
650 POINT ptTotal, prevOrigin = {0,0};
653 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
654 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
656 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
658 if( wnd->dwStyle & WS_VISIBLE )
662 r.left = wnd->rectWindow.left + ptClient.x;
663 r.right = wnd->rectWindow.right + ptClient.x;
664 r.top = wnd->rectWindow.top + ptClient.y;
665 r.bottom = wnd->rectWindow.bottom + ptClient.y;
667 ptOffset.x = r.left - prevOrigin.x;
668 ptOffset.y = r.top - prevOrigin.y;
669 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
671 if( RectInRegion( hRgn, &r ) )
673 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
674 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
675 prevOrigin.x = r.left + ptTotal.x;
676 prevOrigin.y = r.top + ptTotal.y;
677 ptTotal.x += ptOffset.x;
678 ptTotal.y += ptOffset.y;
682 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
687 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
692 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
693 if( wnd->dwStyle & WS_VISIBLE )
694 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
699 /* Set/clear internal paint flag */
701 if (flags & RDW_INTERNALPAINT)
703 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
704 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
705 wndPtr->flags |= WIN_INTERNAL_PAINT;
707 else if (flags & RDW_NOINTERNALPAINT)
709 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
710 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
711 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
715 /***********************************************************************
716 * RDW_Paint [RedrawWindow() helper]
718 * Walks the window tree and paints/erases windows that have
719 * nonzero update regions according to redraw flags. hrgn is a scratch
720 * region passed down during recursion. Must not be 1.
723 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
725 /* NOTE: wndPtr is locked by caller.
727 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
728 * SendMessage() calls. This is a comment inside DefWindowProc() source
731 * This message avoids lots of inter-app message traffic
732 * by switching to the other task and continuing the
736 * LOWORD(lParam) = hrgnClip
737 * HIWORD(lParam) = hwndSkip (not used; always NULL)
741 HWND hWnd = wndPtr->hwndSelf;
742 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
744 /* Erase/update the window itself ... */
746 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
749 * Check if this window should delay it's processing of WM_NCPAINT.
750 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
752 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
753 ex |= RDW_EX_DELAY_NCPAINT;
755 if (flags & RDW_UPDATENOW)
757 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
758 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
760 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
762 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
765 hrgnRet = WIN_UpdateNCRgn(wndPtr,
767 UNC_REGION | UNC_CHECK |
768 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) |
769 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
773 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
774 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
776 if( bIcon ) dcx |= DCX_WINDOW;
779 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
780 wndPtr->rectWindow.top - wndPtr->rectClient.top);
782 dcx &= ~DCX_INTERSECTRGN;
783 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
785 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
786 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
787 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
788 ReleaseDC( hWnd, hDC );
794 if( !IsWindow(hWnd) ) return hrgn;
795 ex &= ~RDW_EX_TOPFRAME;
797 /* ... and its child windows */
799 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
800 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
804 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
807 for (ppWnd = list; *ppWnd; ppWnd++)
809 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
810 if (!IsWindow(wndPtr->hwndSelf)) continue;
811 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
812 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
813 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
815 WIN_ReleaseWndPtr(wndPtr);
816 WIN_ReleaseWinArray(list);
823 /***********************************************************************
827 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
828 HRGN hrgnUpdate, UINT flags, UINT ex )
835 if (!hwnd) hwnd = GetDesktopWindow();
836 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
838 /* check if the window or its parents are visible/not minimized */
840 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
842 WIN_ReleaseWndPtr(wndPtr);
850 GetRgnBox( hrgnUpdate, &r );
851 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
852 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
860 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
861 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
862 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
866 /* prepare an update region in window coordinates */
868 if( flags & RDW_FRAME )
869 r = wndPtr->rectWindow;
871 r = wndPtr->rectClient;
873 if( ex & RDW_EX_XYWINDOW )
876 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
880 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
881 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
882 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
885 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
887 /* If the window doesn't have hrgnUpdate we leave hRgn zero
888 * and put a new region straight into wndPtr->hrgnUpdate
889 * so that RDW_UpdateRgns() won't have to do any extra work.
894 if( wndPtr->hrgnUpdate )
895 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
897 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
899 else if( rectUpdate )
901 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
902 OffsetRect( &r2, pt.x, pt.y );
905 if( wndPtr->hrgnUpdate == 0 )
906 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
908 hRgn = CreateRectRgnIndirect( &r2 );
910 else /* entire window or client depending on RDW_FRAME */
912 if( flags & RDW_FRAME )
914 if( wndPtr->hrgnUpdate )
915 DeleteObject( wndPtr->hrgnUpdate );
916 wndPtr->hrgnUpdate = 1;
920 GETCLIENTRECTW( wndPtr, r2 );
925 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
927 /* In this we cannot leave with zero hRgn */
930 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
931 GetRgnBox( hRgn, &r2 );
932 if( IsRectEmpty( &r2 ) ) goto END;
934 else if( rectUpdate )
936 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
937 OffsetRect( &r2, pt.x, pt.y );
939 hRgn = CreateRectRgnIndirect( &r2 );
941 else /* entire window or client depending on RDW_FRAME */
943 if( flags & RDW_FRAME )
947 GETCLIENTRECTW( wndPtr, r2 );
953 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
955 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
957 /* Erase/update windows, from now on hRgn is a scratch region */
959 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
962 if( hRgn > 1 && (hRgn != hrgnUpdate) )
964 WIN_ReleaseWndPtr(wndPtr);
969 /***********************************************************************
970 * RedrawWindow (USER32.@)
972 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
973 HRGN hrgnUpdate, UINT flags )
975 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
979 /***********************************************************************
980 * RedrawWindow (USER.290)
982 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
983 HRGN16 hrgnUpdate, UINT16 flags )
988 CONV_RECT16TO32( rectUpdate, &r );
989 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
991 return RedrawWindow( hwnd, NULL, hrgnUpdate, flags );
995 /***********************************************************************
996 * UpdateWindow (USER.124)
998 void WINAPI UpdateWindow16( HWND16 hwnd )
1000 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1003 /***********************************************************************
1004 * UpdateWindow (USER32.@)
1006 void WINAPI UpdateWindow( HWND hwnd )
1008 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1011 /***********************************************************************
1012 * InvalidateRgn (USER.126)
1014 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1016 RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1020 /***********************************************************************
1021 * InvalidateRgn (USER32.@)
1023 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1025 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1029 /***********************************************************************
1030 * InvalidateRect (USER.125)
1032 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1034 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1038 /***********************************************************************
1039 * InvalidateRect (USER32.@)
1041 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1043 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1047 /***********************************************************************
1048 * ValidateRgn (USER.128)
1050 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1052 RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1056 /***********************************************************************
1057 * ValidateRgn (USER32.@)
1059 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1061 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1065 /***********************************************************************
1066 * ValidateRect (USER.127)
1068 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1070 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1074 /***********************************************************************
1075 * ValidateRect (USER32.@)
1077 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1079 RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1083 /***********************************************************************
1084 * GetUpdateRect (USER.190)
1086 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1091 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1092 ret = GetUpdateRect( hwnd, &r, erase );
1093 CONV_RECT32TO16( &r, rect );
1098 /***********************************************************************
1099 * GetUpdateRect (USER32.@)
1101 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1104 WND * wndPtr = WIN_FindWndPtr( hwnd );
1105 if (!wndPtr) return FALSE;
1109 if (wndPtr->hrgnUpdate > 1)
1111 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1112 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1117 GetRgnBox( hrgn, rect );
1118 DeleteObject( hrgn );
1119 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1121 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1123 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1128 if( wndPtr->hrgnUpdate == 1 )
1130 GetClientRect( hwnd, rect );
1131 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1134 SetRectEmpty( rect );
1136 retvalue = (wndPtr->hrgnUpdate >= 1);
1138 WIN_ReleaseWndPtr(wndPtr);
1143 /***********************************************************************
1144 * GetUpdateRgn (USER.237)
1146 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1148 return GetUpdateRgn( hwnd, hrgn, erase );
1152 /***********************************************************************
1153 * GetUpdateRgn (USER32.@)
1155 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1158 WND * wndPtr = WIN_FindWndPtr( hwnd );
1159 if (!wndPtr) return ERROR;
1161 if (wndPtr->hrgnUpdate == 0)
1163 SetRectRgn( hrgn, 0, 0, 0, 0 );
1164 retval = NULLREGION;
1168 if (wndPtr->hrgnUpdate == 1)
1170 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1171 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1172 retval = SIMPLEREGION;
1176 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1177 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1178 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1180 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1182 WIN_ReleaseWndPtr(wndPtr);
1187 /***********************************************************************
1188 * ExcludeUpdateRgn (USER.238)
1190 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1192 return ExcludeUpdateRgn( hdc, hwnd );
1196 /***********************************************************************
1197 * ExcludeUpdateRgn (USER32.@)
1199 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1204 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1206 if (wndPtr->hrgnUpdate)
1209 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1210 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1211 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1212 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1213 if( wndPtr->hrgnUpdate > 1 )
1215 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1216 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1217 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1220 /* do ugly coordinate translations in dce.c */
1222 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1223 DeleteObject( hrgn );
1224 WIN_ReleaseWndPtr(wndPtr);
1227 WIN_ReleaseWndPtr(wndPtr);
1228 return GetClipBox( hdc, &rect );
1233 /***********************************************************************
1234 * FillRect (USER.81)
1236 * The Win16 variant doesn't support special color brushes like
1237 * the Win32 one, despite the fact that Win16, as well as Win32,
1238 * supports special background brushes for a window class.
1240 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1244 /* coordinates are logical so we cannot fast-check 'rect',
1245 * it will be done later in the PatBlt().
1248 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1249 PatBlt( hdc, rect->left, rect->top,
1250 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1251 SelectObject( hdc, prevBrush );
1256 /***********************************************************************
1257 * FillRect (USER32.@)
1259 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1263 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1264 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1267 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1268 PatBlt( hdc, rect->left, rect->top,
1269 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1270 SelectObject( hdc, prevBrush );
1275 /***********************************************************************
1276 * InvertRect (USER.82)
1278 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1280 PatBlt( hdc, rect->left, rect->top,
1281 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1285 /***********************************************************************
1286 * InvertRect (USER32.@)
1288 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1290 return PatBlt( hdc, rect->left, rect->top,
1291 rect->right - rect->left, rect->bottom - rect->top,
1296 /***********************************************************************
1297 * FrameRect (USER32.@)
1299 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1304 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1305 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1307 PatBlt( hdc, r.left, r.top, 1,
1308 r.bottom - r.top, PATCOPY );
1309 PatBlt( hdc, r.right - 1, r.top, 1,
1310 r.bottom - r.top, PATCOPY );
1311 PatBlt( hdc, r.left, r.top,
1312 r.right - r.left, 1, PATCOPY );
1313 PatBlt( hdc, r.left, r.bottom - 1,
1314 r.right - r.left, 1, PATCOPY );
1316 SelectObject( hdc, prevBrush );
1321 /***********************************************************************
1322 * FrameRect (USER.83)
1324 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1327 CONV_RECT16TO32( rect16, &rect );
1328 return FrameRect( hdc, &rect, hbrush );
1332 /***********************************************************************
1333 * DrawFocusRect (USER.466)
1335 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1338 CONV_RECT16TO32( rc, &rect32 );
1339 DrawFocusRect( hdc, &rect32 );
1343 /***********************************************************************
1344 * DrawFocusRect (USER32.@)
1346 * FIXME: PatBlt(PATINVERT) with background brush.
1348 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1351 HPEN hOldPen, hNewPen;
1352 INT oldDrawMode, oldBkMode;
1354 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1355 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1356 hOldPen = SelectObject(hdc, hNewPen);
1357 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1358 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1360 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1362 SetBkMode(hdc, oldBkMode);
1363 SetROP2(hdc, oldDrawMode);
1364 SelectObject(hdc, hOldPen);
1365 DeleteObject(hNewPen);
1366 SelectObject(hdc, hOldBrush);
1371 /**********************************************************************
1372 * DrawAnimatedRects (USER.448)
1374 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
1375 const RECT16* lprcFrom,
1376 const RECT16* lprcTo )
1378 RECT rcFrom32, rcTo32;
1380 rcFrom32.left = (INT)lprcFrom->left;
1381 rcFrom32.top = (INT)lprcFrom->top;
1382 rcFrom32.right = (INT)lprcFrom->right;
1383 rcFrom32.bottom = (INT)lprcFrom->bottom;
1385 rcTo32.left = (INT)lprcTo->left;
1386 rcTo32.top = (INT)lprcTo->top;
1387 rcTo32.right = (INT)lprcTo->right;
1388 rcTo32.bottom = (INT)lprcTo->bottom;
1390 return DrawAnimatedRects((HWND)hwnd, (INT)idAni, &rcFrom32, &rcTo32);
1394 /**********************************************************************
1395 * DrawAnimatedRects (USER32.@)
1397 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1398 const RECT* lprcFrom,
1399 const RECT* lprcTo )
1401 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1406 /**********************************************************************
1407 * PAINTING_DrawStateJam
1409 * Jams in the requested type in the dc
1411 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1412 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1413 LPRECT rc, UINT dtflags,
1414 BOOL unicode, BOOL _32bit)
1419 INT cx = rc->right - rc->left;
1420 INT cy = rc->bottom - rc->top;
1425 case DST_PREFIXTEXT:
1427 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1429 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1431 return DrawTextA(hdc, MapSL(lp), (INT)wp, rc, dtflags);
1434 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1437 memdc = CreateCompatibleDC(hdc);
1438 if(!memdc) return FALSE;
1439 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1445 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1446 SelectObject(memdc, hbmsave);
1453 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1455 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1457 bRet = func(hdc, lp, wp, cx, cy);
1459 bRet = (BOOL)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
1460 /* Restore origin */
1461 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1469 /**********************************************************************
1470 * PAINTING_DrawState()
1472 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr,
1473 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1474 INT x, INT y, INT cx, INT cy,
1475 UINT flags, BOOL unicode, BOOL _32bit)
1477 HBITMAP hbm, hbmsave;
1479 HBRUSH hbsave, hbrtmp = 0;
1482 UINT dtflags = DT_NOCLIP;
1484 UINT opcode = flags & 0xf;
1488 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1491 len = strlenW((LPWSTR)lp);
1493 len = strlen((LPSTR)lp);
1495 len = strlen(MapSL(lp));
1498 /* Find out what size the image has if not given by caller */
1502 CURSORICONINFO *ici;
1508 case DST_PREFIXTEXT:
1510 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1512 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1514 retval = GetTextExtentPoint32A(hdc, MapSL(lp), len, &s);
1515 if(!retval) return FALSE;
1519 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1520 if(!ici) return FALSE;
1522 s.cy = ici->nHeight;
1523 GlobalUnlock16((HGLOBAL16)lp);
1527 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1533 case DST_COMPLEX: /* cx and cy must be set in this mode */
1546 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1547 dtflags |= DT_RIGHT;
1548 if(opcode == DST_TEXT)
1549 dtflags |= DT_NOPREFIX;
1551 /* For DSS_NORMAL we just jam in the image and return */
1552 if((flags & 0x7ff0) == DSS_NORMAL)
1554 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1557 /* For all other states we need to convert the image to B/W in a local bitmap */
1558 /* before it is displayed */
1559 fg = SetTextColor(hdc, RGB(0, 0, 0));
1560 bg = SetBkColor(hdc, RGB(255, 255, 255));
1561 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1562 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1563 retval = FALSE; /* assume failure */
1565 /* From here on we must use "goto cleanup" when something goes wrong */
1566 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1567 if(!hbm) goto cleanup;
1568 memdc = CreateCompatibleDC(hdc);
1569 if(!memdc) goto cleanup;
1570 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1571 if(!hbmsave) goto cleanup;
1572 rc.left = rc.top = 0;
1575 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1576 SetBkColor(memdc, RGB(255, 255, 255));
1577 SetTextColor(memdc, RGB(0, 0, 0));
1578 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1580 /* DST_COMPLEX may draw text as well,
1581 * so we must be sure that correct font is selected
1583 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1584 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1585 if(hfsave) SelectObject(memdc, hfsave);
1586 if(!tmp) goto cleanup;
1588 /* This state cause the image to be dithered */
1589 if(flags & DSS_UNION)
1591 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1592 if(!hbsave) goto cleanup;
1593 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1594 SelectObject(memdc, hbsave);
1595 if(!tmp) goto cleanup;
1598 if (flags & DSS_DISABLED)
1599 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1600 else if (flags & DSS_DEFAULT)
1601 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1603 /* Draw light or dark shadow */
1604 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1606 if(!hbrtmp) goto cleanup;
1607 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1608 if(!hbsave) goto cleanup;
1609 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1610 SelectObject(hdc, hbsave);
1611 DeleteObject(hbrtmp);
1615 if (flags & DSS_DISABLED)
1617 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1618 if(!hbrtmp) goto cleanup;
1622 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1625 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1627 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1629 retval = TRUE; /* We succeeded */
1632 SetTextColor(hdc, fg);
1633 SetBkColor(hdc, bg);
1635 if(hbsave) SelectObject(hdc, hbsave);
1636 if(hbmsave) SelectObject(memdc, hbmsave);
1637 if(hbrtmp) DeleteObject(hbrtmp);
1638 if(hbm) DeleteObject(hbm);
1639 if(memdc) DeleteDC(memdc);
1644 /**********************************************************************
1645 * DrawStateA (USER32.@)
1647 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1648 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1649 INT x, INT y, INT cx, INT cy, UINT flags)
1651 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1654 /**********************************************************************
1655 * DrawStateW (USER32.@)
1657 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1658 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1659 INT x, INT y, INT cx, INT cy, UINT flags)
1661 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1664 /**********************************************************************
1665 * DrawState (USER.449)
1667 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1668 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1669 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1671 return PAINTING_DrawState(hdc, hbr, (DRAWSTATEPROC)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1675 /***********************************************************************
1676 * SelectPalette (USER.282)
1678 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1679 BOOL16 bForceBackground )
1681 WORD wBkgPalette = 1;
1683 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1685 HWND hwnd = WindowFromDC( hDC );
1688 HWND hForeground = GetForegroundWindow();
1689 /* set primary palette if it's related to current active */
1690 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1693 return GDISelectPalette16( hDC, hPal, wBkgPalette);
1697 /***********************************************************************
1698 * RealizePalette (USER.283)
1700 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1702 UINT16 realized = GDIRealizePalette16( hDC );
1704 /* do not send anything if no colors were changed */
1705 if (realized && IsDCCurrentPalette16( hDC ))
1707 /* send palette change notification */
1708 HWND hWnd = WindowFromDC( hDC );
1709 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
1715 /***********************************************************************
1716 * UserRealizePalette (USER32.@)
1718 UINT WINAPI UserRealizePalette( HDC hDC )
1720 return RealizePalette16( hDC );