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
45 /* Last CTLCOLOR id */
46 #define CTLCOLOR_MAX CTLCOLOR_STATIC
49 /***********************************************************************
52 * Add an increment (normally 1 or -1) to the current paint count of a window.
54 static void add_paint_count( HWND hwnd, int incr )
56 SERVER_START_REQ( inc_queue_paint_count )
58 req->id = (void *)GetWindowThreadProcessId( hwnd, NULL );
66 /***********************************************************************
67 * WIN_HaveToDelayNCPAINT
69 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
70 * is generated as soon as a region intersecting the non-client area
71 * of a window is invalidated.
73 * This technique will work fine for all windows whose parents
74 * have the WS_CLIPCHILDREN style. When the parents have that style,
75 * they are not going to override the contents of their children.
76 * However, when the parent doesn't have that style, Windows relies
77 * on a "painter's algorithm" to display the contents of the windows.
78 * That is, windows are painted from back to front. This includes the
81 * This method looks at the current state of a window to determine
82 * if the sending of the WM_NCPAINT message should be delayed until
83 * the BeginPaint call.
86 * wndPtr - A Locked window pointer to the window we're
88 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
89 * function. This is a shortcut for the cases when
90 * we already know when to avoid scanning all the
91 * parents of a window. If you already know that this
92 * window's NCPAINT should be delayed, set the
93 * UNC_DELAY_NCPAINT flag for this parameter.
95 * This shortcut behavior is implemented in the
99 static BOOL WIN_HaveToDelayNCPAINT(
103 WND* parentWnd = NULL;
106 * Test the shortcut first. (duh)
108 if (uncFlags & UNC_DELAY_NCPAINT)
112 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
113 * method only. This is another shortcut to avoid going
114 * up the parent's chain of the window to finally
115 * figure-out that none of them has an invalid region.
117 if (uncFlags & UNC_IN_BEGINPAINT)
121 * Scan all the parents of this window to find a window
122 * that doesn't have the WS_CLIPCHILDREN style and that
123 * has an invalid region.
125 parentWnd = WIN_LockWndPtr(wndPtr->parent);
127 while (parentWnd!=NULL)
129 if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
130 (parentWnd->hrgnUpdate != 0) )
132 WIN_ReleaseWndPtr(parentWnd);
136 WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);
139 WIN_ReleaseWndPtr(parentWnd);
144 /***********************************************************************
148 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
149 * Crop hrgnUpdate to a client rect, especially if it 1.
150 * If UNC_REGION is set return update region for the client rect.
152 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
153 * The trick is that when the returned region handle may be different from hRgn.
154 * In this case the old hRgn must be considered gone. BUT, if the returned value
155 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
156 * a DC without extra clipping region.
158 static HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
164 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
165 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
167 /* desktop window doesn't have a nonclient area */
168 if(wnd == WIN_GetDesktop())
170 wnd->flags &= ~WIN_NEEDS_NCPAINT;
171 if( wnd->hrgnUpdate > 1 )
172 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
175 hrgnRet = wnd->hrgnUpdate;
177 WIN_ReleaseDesktop();
180 WIN_ReleaseDesktop();
182 if ((wnd->hwndSelf == GetForegroundWindow()) &&
183 !(wnd->flags & WIN_NCACTIVATED) )
185 wnd->flags |= WIN_NCACTIVATED;
186 uncFlags |= UNC_ENTIRE;
190 * If the window's non-client area needs to be painted,
192 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
193 !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
197 wnd->flags &= ~WIN_NEEDS_NCPAINT;
198 GETCLIENTRECTW( wnd, r );
200 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
201 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
202 if( wnd->hrgnUpdate > 1 )
204 /* Check if update rgn overlaps with nonclient area */
206 GetRgnBox( wnd->hrgnUpdate, &r2 );
207 UnionRect( &r3, &r2, &r );
208 if( r3.left != r.left || r3.top != r.top ||
209 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
211 /* crop hrgnUpdate, save old one in hClip - the only
212 * case that places a valid region handle in hClip */
214 hClip = wnd->hrgnUpdate;
215 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
216 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
219 if( uncFlags & UNC_CHECK )
221 GetRgnBox( wnd->hrgnUpdate, &r3 );
222 if( IsRectEmpty( &r3 ) )
224 /* delete the update region since all invalid
225 * parts were in the nonclient area */
227 DeleteObject( wnd->hrgnUpdate );
229 if(!(wnd->flags & WIN_INTERNAL_PAINT))
230 add_paint_count( wnd->hwndSelf, -1 );
232 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
236 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
239 if( wnd->hrgnUpdate == 1 )/* entire window */
241 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
242 if( uncFlags & UNC_REGION ) hrgnRet = 1;
243 uncFlags |= UNC_ENTIRE;
246 else /* no WM_NCPAINT unless forced */
248 if( wnd->hrgnUpdate > 1 )
251 if( uncFlags & UNC_REGION )
252 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
255 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
257 GETCLIENTRECTW( wnd, r );
258 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
259 if( uncFlags & UNC_REGION ) hrgnRet = 1;
263 if(!hClip && (uncFlags & UNC_ENTIRE) )
265 /* still don't do anything if there is no nonclient area */
266 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
269 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
271 if ( hClip == hrgnRet && hrgnRet > 1 ) {
272 hClip = CreateRectRgn( 0, 0, 0, 0 );
273 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
276 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
277 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
278 DeleteObject( hClip );
280 * Since all Window locks are suspended while processing the WM_NCPAINT
281 * we want to make sure the window still exists before continuing.
283 if (!IsWindow(wnd->hwndSelf))
285 DeleteObject(hrgnRet);
290 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
296 /***********************************************************************
297 * BeginPaint (USER.39)
299 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
303 BeginPaint( hwnd, &ps );
305 lps->fErase = ps.fErase;
306 lps->rcPaint.top = ps.rcPaint.top;
307 lps->rcPaint.left = ps.rcPaint.left;
308 lps->rcPaint.right = ps.rcPaint.right;
309 lps->rcPaint.bottom = ps.rcPaint.bottom;
310 lps->fRestore = ps.fRestore;
311 lps->fIncUpdate = ps.fIncUpdate;
316 /***********************************************************************
317 * BeginPaint (USER32.@)
319 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
323 RECT clipRect, clientRect;
324 WND *wndPtr = WIN_FindWndPtr( hwnd );
325 if (!wndPtr) return 0;
327 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassLongA(hwnd, GCL_HICON));
329 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
331 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
332 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
335 * Make sure the window is still a window. All window locks are suspended
336 * when the WM_NCPAINT is sent.
338 if (!IsWindow(wndPtr->hwndSelf))
340 WIN_ReleaseWndPtr(wndPtr);
344 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
345 add_paint_count( hwnd, -1 );
347 wndPtr->hrgnUpdate = 0;
348 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
352 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate);
354 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_PARENTDC)
356 /* Don't clip the output to the update region for CS_PARENTDC window */
358 DeleteObject(hrgnUpdate);
359 lps->hdc = GetDCEx( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
360 (bIcon ? DCX_WINDOW : 0) );
364 if( hrgnUpdate ) /* convert to client coordinates */
365 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
366 wndPtr->rectWindow.top - wndPtr->rectClient.top );
367 lps->hdc = GetDCEx(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
368 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
369 /* ReleaseDC() in EndPaint() will delete the region */
372 TRACE("hdc = %04x\n", lps->hdc);
376 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
377 WIN_ReleaseWndPtr(wndPtr);
381 /* It is possible that the clip box is bigger than the window itself,
382 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
383 than the window itself, so we need to intersect the cliprect with
386 GetClientRect( hwnd, &clientRect );
388 GetClipBox( lps->hdc, &clipRect );
389 LPtoDP(lps->hdc, (LPPOINT)&clipRect, 2); /* GetClipBox returns LP */
391 IntersectRect(&lps->rcPaint, &clientRect, &clipRect);
392 DPtoLP(lps->hdc, (LPPOINT)&lps->rcPaint, 2); /* we must return LP */
394 TRACE("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
395 lps->rcPaint.right, lps->rcPaint.bottom );
397 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
399 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
400 lps->fErase = !SendMessageA(hwnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
401 (WPARAM16)lps->hdc, 0 );
403 else lps->fErase = TRUE;
405 WIN_ReleaseWndPtr(wndPtr);
410 /***********************************************************************
413 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
415 ReleaseDC16( hwnd, lps->hdc );
421 /***********************************************************************
422 * EndPaint (USER32.@)
424 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
426 ReleaseDC( hwnd, lps->hdc );
432 /***********************************************************************
433 * FillWindow (USER.324)
435 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
439 GetClientRect( hwnd, &rect );
440 DPtoLP( hdc, (LPPOINT)&rect, 2 );
441 CONV_RECT32TO16( &rect, &rc16 );
442 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rc16 );
446 /***********************************************************************
447 * PAINT_GetControlBrush
449 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
451 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
452 (WPARAM)hDC, (LPARAM)hWnd );
453 if( !IsGDIObject16(bkgBrush) )
454 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
459 /***********************************************************************
460 * PaintRect (USER.325)
462 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
463 HBRUSH16 hbrush, const RECT16 *rect)
465 if( hbrush <= CTLCOLOR_MAX )
468 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
473 FillRect16( hdc, rect, hbrush );
477 /***********************************************************************
478 * GetControlBrush (USER.326)
480 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
482 if (ctlType <= CTLCOLOR_MAX)
484 HWND16 parent = GetParent16( hwnd );
485 if (!parent) parent = hwnd;
486 return PAINT_GetControlBrush( parent, hwnd, hdc, ctlType );
492 /***********************************************************************
493 * RDW_ValidateParent [RDW_UpdateRgns() helper]
495 * Validate the portions of parents that are covered by a validated child
498 static void RDW_ValidateParent(WND *wndChild)
500 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
501 WND *wndDesktop = WIN_GetDesktop();
504 if (wndChild->hrgnUpdate == 1 ) {
508 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
509 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
510 hrg = CreateRectRgnIndirect( &r );
512 hrg = wndChild->hrgnUpdate;
514 while ((wndParent) && (wndParent != wndDesktop) ) {
515 if (!(wndParent->dwStyle & WS_CLIPCHILDREN))
517 if (wndParent->hrgnUpdate != 0)
520 RECT rect, rectParent;
521 if( wndParent->hrgnUpdate == 1 )
527 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
528 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
530 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
532 /* we must offset the child region by the offset of the child rect in the parent */
533 GetWindowRect(wndParent->hwndSelf, &rectParent);
534 GetWindowRect(wndChild->hwndSelf, &rect);
535 ptOffset.x = rect.left - rectParent.left;
536 ptOffset.y = rect.top - rectParent.top;
537 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
538 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
539 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
542 WIN_UpdateWndPtr(&wndParent, wndParent->parent);
544 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
545 WIN_ReleaseWndPtr(wndParent);
546 WIN_ReleaseDesktop();
549 /***********************************************************************
550 * RDW_UpdateRgns [RedrawWindow() helper]
552 * Walks the window tree and adds/removes parts of the hRgn to/from update
553 * regions of windows that overlap it. Also, manages internal paint flags.
555 * NOTE: Walks the window tree so the caller must lock it.
556 * MUST preserve hRgn (can modify but then has to restore).
558 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
561 * Called only when one of the following is set:
562 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
565 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
566 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
567 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
572 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
573 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
575 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
577 if( flags & RDW_INVALIDATE )
581 switch( wndPtr->hrgnUpdate )
584 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
587 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
588 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
592 GetRgnBox( wndPtr->hrgnUpdate, &r );
593 if( IsRectEmpty( &r ) )
595 DeleteObject( wndPtr->hrgnUpdate );
596 wndPtr->hrgnUpdate = 0;
601 case 1: /* already an entire window */
607 if( wndPtr->hrgnUpdate > 1 )
608 DeleteObject( wndPtr->hrgnUpdate );
609 wndPtr->hrgnUpdate = 1;
612 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
614 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
615 add_paint_count( wndPtr->hwndSelf, 1 );
617 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
618 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
621 else if( flags & RDW_VALIDATE )
623 if( wndPtr->hrgnUpdate )
627 if( wndPtr->hrgnUpdate == 1 )
628 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
630 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
633 DeleteObject( wndPtr->hrgnUpdate );
634 wndPtr->hrgnUpdate = 0;
637 else /* validate everything */
639 if( wndPtr->hrgnUpdate > 1 ) DeleteObject( wndPtr->hrgnUpdate );
640 wndPtr->hrgnUpdate = 0;
643 if( !wndPtr->hrgnUpdate )
645 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
646 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
647 add_paint_count( wndPtr->hwndSelf, -1 );
651 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
652 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
656 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
657 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
659 /* in/validate child windows that intersect with the region if it
660 * is a valid handle. */
662 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
664 if( hRgn > 1 && bChildren )
666 WND* wnd = wndPtr->child;
667 POINT ptTotal, prevOrigin = {0,0};
670 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
671 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
673 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
675 if( wnd->dwStyle & WS_VISIBLE )
679 r.left = wnd->rectWindow.left + ptClient.x;
680 r.right = wnd->rectWindow.right + ptClient.x;
681 r.top = wnd->rectWindow.top + ptClient.y;
682 r.bottom = wnd->rectWindow.bottom + ptClient.y;
684 ptOffset.x = r.left - prevOrigin.x;
685 ptOffset.y = r.top - prevOrigin.y;
686 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
688 if( RectInRegion( hRgn, &r ) )
690 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
691 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
692 prevOrigin.x = r.left + ptTotal.x;
693 prevOrigin.y = r.top + ptTotal.y;
694 ptTotal.x += ptOffset.x;
695 ptTotal.y += ptOffset.y;
699 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
704 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
709 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
710 if( wnd->dwStyle & WS_VISIBLE )
711 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
716 /* Set/clear internal paint flag */
718 if (flags & RDW_INTERNALPAINT)
720 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
721 add_paint_count( wndPtr->hwndSelf, 1 );
722 wndPtr->flags |= WIN_INTERNAL_PAINT;
724 else if (flags & RDW_NOINTERNALPAINT)
726 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
727 add_paint_count( wndPtr->hwndSelf, -1 );
728 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
732 /***********************************************************************
733 * RDW_Paint [RedrawWindow() helper]
735 * Walks the window tree and paints/erases windows that have
736 * nonzero update regions according to redraw flags. hrgn is a scratch
737 * region passed down during recursion. Must not be 1.
740 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
742 /* NOTE: wndPtr is locked by caller.
744 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
745 * SendMessage() calls. This is a comment inside DefWindowProc() source
748 * This message avoids lots of inter-app message traffic
749 * by switching to the other task and continuing the
753 * LOWORD(lParam) = hrgnClip
754 * HIWORD(lParam) = hwndSkip (not used; always NULL)
758 HWND hWnd = wndPtr->hwndSelf;
759 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassLongA(hWnd, GCL_HICON));
761 /* Erase/update the window itself ... */
763 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
766 * Check if this window should delay it's processing of WM_NCPAINT.
767 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
769 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
770 ex |= RDW_EX_DELAY_NCPAINT;
772 if (flags & RDW_UPDATENOW)
774 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
775 SendMessageW( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
777 else if (flags & RDW_ERASENOW)
779 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
782 hrgnRet = WIN_UpdateNCRgn(wndPtr,
784 UNC_REGION | UNC_CHECK |
785 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
789 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
790 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
792 if( bIcon ) dcx |= DCX_WINDOW;
795 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
796 wndPtr->rectWindow.top - wndPtr->rectClient.top);
798 dcx &= ~DCX_INTERSECTRGN;
799 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
801 if (SendMessageW( hWnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
803 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
804 ReleaseDC( hWnd, hDC );
810 if( !IsWindow(hWnd) ) return hrgn;
812 /* ... and its child windows */
814 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
815 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
819 if( (list = WIN_BuildWinArray( wndPtr->hwndSelf )) )
821 for (phwnd = list; *phwnd; phwnd++)
823 if (!(wndPtr = WIN_FindWndPtr( *phwnd ))) continue;
824 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
825 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
826 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
827 WIN_ReleaseWndPtr(wndPtr);
829 WIN_ReleaseWinArray(list);
837 /***********************************************************************
838 * RedrawWindow (USER32.@)
840 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
841 HRGN hrgnUpdate, UINT flags )
848 if (!hwnd) hwnd = GetDesktopWindow();
849 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
851 /* check if the window or its parents are visible/not minimized */
853 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
855 WIN_ReleaseWndPtr(wndPtr);
863 GetRgnBox( hrgnUpdate, &r );
864 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
865 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags );
873 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
874 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
875 r.top, r.right, r.bottom, hrgnUpdate, flags );
879 /* prepare an update region in window coordinates */
881 if( flags & RDW_FRAME )
882 r = wndPtr->rectWindow;
884 r = wndPtr->rectClient;
886 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
887 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
888 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
890 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
892 /* If the window doesn't have hrgnUpdate we leave hRgn zero
893 * and put a new region straight into wndPtr->hrgnUpdate
894 * so that RDW_UpdateRgns() won't have to do any extra work.
899 if( wndPtr->hrgnUpdate )
900 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
902 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
904 else if( rectUpdate )
906 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
907 OffsetRect( &r2, pt.x, pt.y );
910 if( wndPtr->hrgnUpdate == 0 )
911 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
913 hRgn = CreateRectRgnIndirect( &r2 );
915 else /* entire window or client depending on RDW_FRAME */
917 if( flags & RDW_FRAME )
919 if( wndPtr->hrgnUpdate )
920 DeleteObject( wndPtr->hrgnUpdate );
921 wndPtr->hrgnUpdate = 1;
925 GETCLIENTRECTW( wndPtr, r2 );
930 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
932 /* In this we cannot leave with zero hRgn */
935 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
936 GetRgnBox( hRgn, &r2 );
937 if( IsRectEmpty( &r2 ) ) goto END;
939 else if( rectUpdate )
941 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
942 OffsetRect( &r2, pt.x, pt.y );
943 hRgn = CreateRectRgnIndirect( &r2 );
945 else /* entire window or client depending on RDW_FRAME */
947 if( flags & RDW_FRAME )
951 GETCLIENTRECTW( wndPtr, r2 );
952 hRgn = CreateRectRgnIndirect( &r2 );
957 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
959 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
961 /* Erase/update windows, from now on hRgn is a scratch region */
963 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, 0 );
966 if( hRgn > 1 && (hRgn != hrgnUpdate) )
968 WIN_ReleaseWndPtr(wndPtr);
973 /***********************************************************************
974 * RedrawWindow (USER.290)
976 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
977 HRGN16 hrgnUpdate, UINT16 flags )
982 CONV_RECT16TO32( rectUpdate, &r );
983 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
985 return RedrawWindow( hwnd, NULL, hrgnUpdate, flags );
989 /***********************************************************************
990 * UpdateWindow (USER.124)
992 void WINAPI UpdateWindow16( HWND16 hwnd )
994 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
997 /***********************************************************************
998 * UpdateWindow (USER32.@)
1000 void WINAPI UpdateWindow( HWND hwnd )
1002 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1005 /***********************************************************************
1006 * InvalidateRgn (USER.126)
1008 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1010 RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1014 /***********************************************************************
1015 * InvalidateRgn (USER32.@)
1017 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1019 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1023 /***********************************************************************
1024 * InvalidateRect (USER.125)
1026 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1028 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1032 /***********************************************************************
1033 * InvalidateRect (USER32.@)
1035 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1037 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1041 /***********************************************************************
1042 * ValidateRgn (USER.128)
1044 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1046 RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1050 /***********************************************************************
1051 * ValidateRgn (USER32.@)
1053 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1055 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1059 /***********************************************************************
1060 * ValidateRect (USER.127)
1062 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1064 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1068 /***********************************************************************
1069 * ValidateRect (USER32.@)
1071 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1073 RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1077 /***********************************************************************
1078 * GetUpdateRect (USER.190)
1080 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1085 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1086 ret = GetUpdateRect( hwnd, &r, erase );
1087 CONV_RECT32TO16( &r, rect );
1092 /***********************************************************************
1093 * GetUpdateRect (USER32.@)
1095 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1098 WND * wndPtr = WIN_FindWndPtr( hwnd );
1099 if (!wndPtr) return FALSE;
1103 if (wndPtr->hrgnUpdate > 1)
1105 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1106 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1111 GetRgnBox( hrgn, rect );
1112 DeleteObject( hrgn );
1113 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1115 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1117 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1122 if( wndPtr->hrgnUpdate == 1 )
1124 GetClientRect( hwnd, rect );
1125 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1128 SetRectEmpty( rect );
1130 retvalue = (wndPtr->hrgnUpdate >= 1);
1132 WIN_ReleaseWndPtr(wndPtr);
1137 /***********************************************************************
1138 * GetUpdateRgn (USER.237)
1140 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1142 return GetUpdateRgn( hwnd, hrgn, erase );
1146 /***********************************************************************
1147 * GetUpdateRgn (USER32.@)
1149 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1152 WND * wndPtr = WIN_FindWndPtr( hwnd );
1153 if (!wndPtr) return ERROR;
1155 if (wndPtr->hrgnUpdate == 0)
1157 SetRectRgn( hrgn, 0, 0, 0, 0 );
1158 retval = NULLREGION;
1162 if (wndPtr->hrgnUpdate == 1)
1164 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1165 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1166 retval = SIMPLEREGION;
1170 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1171 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1172 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1174 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1176 WIN_ReleaseWndPtr(wndPtr);
1181 /***********************************************************************
1182 * ExcludeUpdateRgn (USER.238)
1184 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1186 return ExcludeUpdateRgn( hdc, hwnd );
1190 /***********************************************************************
1191 * ExcludeUpdateRgn (USER32.@)
1193 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1198 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1200 if (wndPtr->hrgnUpdate)
1203 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1204 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1205 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1206 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1207 if( wndPtr->hrgnUpdate > 1 )
1209 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1210 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1211 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1214 /* do ugly coordinate translations in dce.c */
1216 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1217 DeleteObject( hrgn );
1218 WIN_ReleaseWndPtr(wndPtr);
1221 WIN_ReleaseWndPtr(wndPtr);
1222 return GetClipBox( hdc, &rect );
1227 /***********************************************************************
1228 * FillRect (USER.81)
1230 * The Win16 variant doesn't support special color brushes like
1231 * the Win32 one, despite the fact that Win16, as well as Win32,
1232 * supports special background brushes for a window class.
1234 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1238 /* coordinates are logical so we cannot fast-check 'rect',
1239 * it will be done later in the PatBlt().
1242 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1243 PatBlt( hdc, rect->left, rect->top,
1244 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1245 SelectObject( hdc, prevBrush );
1250 /***********************************************************************
1251 * FillRect (USER32.@)
1253 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1257 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1258 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1261 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1262 PatBlt( hdc, rect->left, rect->top,
1263 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1264 SelectObject( hdc, prevBrush );
1269 /***********************************************************************
1270 * InvertRect (USER.82)
1272 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1274 PatBlt( hdc, rect->left, rect->top,
1275 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1279 /***********************************************************************
1280 * InvertRect (USER32.@)
1282 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1284 return PatBlt( hdc, rect->left, rect->top,
1285 rect->right - rect->left, rect->bottom - rect->top,
1290 /***********************************************************************
1291 * FrameRect (USER32.@)
1293 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1298 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1299 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1301 PatBlt( hdc, r.left, r.top, 1,
1302 r.bottom - r.top, PATCOPY );
1303 PatBlt( hdc, r.right - 1, r.top, 1,
1304 r.bottom - r.top, PATCOPY );
1305 PatBlt( hdc, r.left, r.top,
1306 r.right - r.left, 1, PATCOPY );
1307 PatBlt( hdc, r.left, r.bottom - 1,
1308 r.right - r.left, 1, PATCOPY );
1310 SelectObject( hdc, prevBrush );
1315 /***********************************************************************
1316 * FrameRect (USER.83)
1318 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1321 CONV_RECT16TO32( rect16, &rect );
1322 return FrameRect( hdc, &rect, hbrush );
1326 /***********************************************************************
1327 * DrawFocusRect (USER.466)
1329 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1332 CONV_RECT16TO32( rc, &rect32 );
1333 DrawFocusRect( hdc, &rect32 );
1337 /***********************************************************************
1338 * DrawFocusRect (USER32.@)
1340 * FIXME: PatBlt(PATINVERT) with background brush.
1342 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1345 HPEN hOldPen, hNewPen;
1346 INT oldDrawMode, oldBkMode;
1348 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1349 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1350 hOldPen = SelectObject(hdc, hNewPen);
1351 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1352 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1354 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1356 SetBkMode(hdc, oldBkMode);
1357 SetROP2(hdc, oldDrawMode);
1358 SelectObject(hdc, hOldPen);
1359 DeleteObject(hNewPen);
1360 SelectObject(hdc, hOldBrush);
1365 /**********************************************************************
1366 * DrawAnimatedRects (USER.448)
1368 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
1369 const RECT16* lprcFrom,
1370 const RECT16* lprcTo )
1372 RECT rcFrom32, rcTo32;
1374 rcFrom32.left = (INT)lprcFrom->left;
1375 rcFrom32.top = (INT)lprcFrom->top;
1376 rcFrom32.right = (INT)lprcFrom->right;
1377 rcFrom32.bottom = (INT)lprcFrom->bottom;
1379 rcTo32.left = (INT)lprcTo->left;
1380 rcTo32.top = (INT)lprcTo->top;
1381 rcTo32.right = (INT)lprcTo->right;
1382 rcTo32.bottom = (INT)lprcTo->bottom;
1384 return DrawAnimatedRects((HWND)hwnd, (INT)idAni, &rcFrom32, &rcTo32);
1388 /**********************************************************************
1389 * DrawAnimatedRects (USER32.@)
1391 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1392 const RECT* lprcFrom,
1393 const RECT* lprcTo )
1395 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1400 /**********************************************************************
1401 * PAINTING_DrawStateJam
1403 * Jams in the requested type in the dc
1405 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1406 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1407 LPRECT rc, UINT dtflags, BOOL unicode )
1412 INT cx = rc->right - rc->left;
1413 INT cy = rc->bottom - rc->top;
1418 case DST_PREFIXTEXT:
1420 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1422 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1425 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1428 memdc = CreateCompatibleDC(hdc);
1429 if(!memdc) return FALSE;
1430 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1436 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1437 SelectObject(memdc, hbmsave);
1444 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1446 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1447 bRet = func(hdc, lp, wp, cx, cy);
1448 /* Restore origin */
1449 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1457 /**********************************************************************
1458 * PAINTING_DrawState()
1460 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1461 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1463 HBITMAP hbm, hbmsave;
1465 HBRUSH hbsave, hbrtmp = 0;
1468 UINT dtflags = DT_NOCLIP;
1470 UINT opcode = flags & 0xf;
1474 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1477 len = strlenW((LPWSTR)lp);
1479 len = strlen((LPSTR)lp);
1482 /* Find out what size the image has if not given by caller */
1486 CURSORICONINFO *ici;
1492 case DST_PREFIXTEXT:
1494 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1496 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1497 if(!retval) return FALSE;
1501 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1502 if(!ici) return FALSE;
1504 s.cy = ici->nHeight;
1505 GlobalUnlock16((HGLOBAL16)lp);
1509 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1515 case DST_COMPLEX: /* cx and cy must be set in this mode */
1528 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1529 dtflags |= DT_RIGHT;
1530 if(opcode == DST_TEXT)
1531 dtflags |= DT_NOPREFIX;
1533 /* For DSS_NORMAL we just jam in the image and return */
1534 if((flags & 0x7ff0) == DSS_NORMAL)
1536 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1539 /* For all other states we need to convert the image to B/W in a local bitmap */
1540 /* before it is displayed */
1541 fg = SetTextColor(hdc, RGB(0, 0, 0));
1542 bg = SetBkColor(hdc, RGB(255, 255, 255));
1543 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1544 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1545 retval = FALSE; /* assume failure */
1547 /* From here on we must use "goto cleanup" when something goes wrong */
1548 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1549 if(!hbm) goto cleanup;
1550 memdc = CreateCompatibleDC(hdc);
1551 if(!memdc) goto cleanup;
1552 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1553 if(!hbmsave) goto cleanup;
1554 rc.left = rc.top = 0;
1557 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1558 SetBkColor(memdc, RGB(255, 255, 255));
1559 SetTextColor(memdc, RGB(0, 0, 0));
1560 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1562 /* DST_COMPLEX may draw text as well,
1563 * so we must be sure that correct font is selected
1565 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1566 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1567 if(hfsave) SelectObject(memdc, hfsave);
1568 if(!tmp) goto cleanup;
1570 /* This state cause the image to be dithered */
1571 if(flags & DSS_UNION)
1573 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1574 if(!hbsave) goto cleanup;
1575 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1576 SelectObject(memdc, hbsave);
1577 if(!tmp) goto cleanup;
1580 if (flags & DSS_DISABLED)
1581 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1582 else if (flags & DSS_DEFAULT)
1583 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1585 /* Draw light or dark shadow */
1586 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1588 if(!hbrtmp) goto cleanup;
1589 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1590 if(!hbsave) goto cleanup;
1591 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1592 SelectObject(hdc, hbsave);
1593 DeleteObject(hbrtmp);
1597 if (flags & DSS_DISABLED)
1599 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1600 if(!hbrtmp) goto cleanup;
1604 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1607 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1609 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1611 retval = TRUE; /* We succeeded */
1614 SetTextColor(hdc, fg);
1615 SetBkColor(hdc, bg);
1617 if(hbsave) SelectObject(hdc, hbsave);
1618 if(hbmsave) SelectObject(memdc, hbmsave);
1619 if(hbrtmp) DeleteObject(hbrtmp);
1620 if(hbm) DeleteObject(hbm);
1621 if(memdc) DeleteDC(memdc);
1626 /**********************************************************************
1627 * DrawStateA (USER32.@)
1629 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1630 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1631 INT x, INT y, INT cx, INT cy, UINT flags)
1633 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1636 /**********************************************************************
1637 * DrawStateW (USER32.@)
1639 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1640 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1641 INT x, INT y, INT cx, INT cy, UINT flags)
1643 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);
1646 /***********************************************************************
1647 * SelectPalette (USER.282)
1649 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1650 BOOL16 bForceBackground )
1652 WORD wBkgPalette = 1;
1654 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1656 HWND hwnd = WindowFromDC( hDC );
1659 HWND hForeground = GetForegroundWindow();
1660 /* set primary palette if it's related to current active */
1661 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1664 return GDISelectPalette16( hDC, hPal, wBkgPalette);
1668 /***********************************************************************
1669 * RealizePalette (USER.283)
1671 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1673 UINT16 realized = GDIRealizePalette16( hDC );
1675 /* do not send anything if no colors were changed */
1676 if (realized && IsDCCurrentPalette16( hDC ))
1678 /* send palette change notification */
1679 HWND hWnd = WindowFromDC( hDC );
1680 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
1686 /***********************************************************************
1687 * UserRealizePalette (USER32.@)
1689 UINT WINAPI UserRealizePalette( HDC hDC )
1691 return RealizePalette16( hDC );