2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
10 #include "wine/winuser16.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(win);
20 DECLARE_DEBUG_CHANNEL(nonclient);
22 /* client rect in window coordinates */
24 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
25 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
26 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
27 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
30 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
32 /* Last CTLCOLOR id */
33 #define CTLCOLOR_MAX CTLCOLOR_STATIC
36 /***********************************************************************
37 * WIN_HaveToDelayNCPAINT
39 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
40 * is generated as soon as a region intersecting the non-client area
41 * of a window is invalidated.
43 * This technique will work fine for all windows whose parents
44 * have the WS_CLIPCHILDREN style. When the parents have that style,
45 * they are not going to override the contents of their children.
46 * However, when the parent doesn't have that style, Windows relies
47 * on a "painter's algorithm" to display the contents of the windows.
48 * That is, windows are painted from back to front. This includes the
51 * This method looks at the current state of a window to determine
52 * if the sending of the WM_NCPAINT message should be delayed until
53 * the BeginPaint call.
56 * wndPtr - A Locked window pointer to the window we're
58 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
59 * function. This is a shortcut for the cases when
60 * we already know when to avoid scanning all the
61 * parents of a window. If you already know that this
62 * window's NCPAINT should be delayed, set the
63 * UNC_DELAY_NCPAINT flag for this parameter.
65 * This shortcut behavior is implemented in the
69 static BOOL WIN_HaveToDelayNCPAINT(
73 WND* parentWnd = NULL;
76 * Test the shortcut first. (duh)
78 if (uncFlags & UNC_DELAY_NCPAINT)
82 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
83 * method only. This is another shortcut to avoid going
84 * up the parent's chain of the window to finally
85 * figure-out that none of them has an invalid region.
87 if (uncFlags & UNC_IN_BEGINPAINT)
91 * Scan all the parents of this window to find a window
92 * that doesn't have the WS_CLIPCHILDREN style and that
93 * has an invalid region.
95 parentWnd = WIN_LockWndPtr(wndPtr->parent);
97 while (parentWnd!=NULL)
99 if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
100 (parentWnd->hrgnUpdate != 0) )
102 WIN_ReleaseWndPtr(parentWnd);
106 WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);
109 WIN_ReleaseWndPtr(parentWnd);
114 /***********************************************************************
118 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
119 * Crop hrgnUpdate to a client rect, especially if it 1.
120 * If UNC_REGION is set return update region for the client rect.
122 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
123 * The trick is that when the returned region handle may be different from hRgn.
124 * In this case the old hRgn must be considered gone. BUT, if the returned value
125 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
126 * a DC without extra clipping region.
128 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
134 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
135 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
137 /* desktop window doesn't have a nonclient area */
138 if(wnd == WIN_GetDesktop())
140 wnd->flags &= ~WIN_NEEDS_NCPAINT;
141 if( wnd->hrgnUpdate > 1 )
142 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
145 hrgnRet = wnd->hrgnUpdate;
147 WIN_ReleaseDesktop();
150 WIN_ReleaseDesktop();
152 if ((wnd->hwndSelf == GetForegroundWindow()) &&
153 !(wnd->flags & WIN_NCACTIVATED) )
155 wnd->flags |= WIN_NCACTIVATED;
156 uncFlags |= UNC_ENTIRE;
160 * If the window's non-client area needs to be painted,
162 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
163 !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
167 wnd->flags &= ~WIN_NEEDS_NCPAINT;
168 GETCLIENTRECTW( wnd, r );
170 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
171 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
172 if( wnd->hrgnUpdate > 1 )
174 /* Check if update rgn overlaps with nonclient area */
176 GetRgnBox( wnd->hrgnUpdate, &r2 );
177 UnionRect( &r3, &r2, &r );
178 if( r3.left != r.left || r3.top != r.top ||
179 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
181 /* crop hrgnUpdate, save old one in hClip - the only
182 * case that places a valid region handle in hClip */
184 hClip = wnd->hrgnUpdate;
185 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
186 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
189 if( uncFlags & UNC_CHECK )
191 GetRgnBox( wnd->hrgnUpdate, &r3 );
192 if( IsRectEmpty( &r3 ) )
194 /* delete the update region since all invalid
195 * parts were in the nonclient area */
197 DeleteObject( wnd->hrgnUpdate );
199 if(!(wnd->flags & WIN_INTERNAL_PAINT))
200 QUEUE_DecPaintCount( wnd->hmemTaskQ );
202 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
206 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
209 if( wnd->hrgnUpdate == 1 )/* entire window */
211 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
212 if( uncFlags & UNC_REGION ) hrgnRet = 1;
213 uncFlags |= UNC_ENTIRE;
216 else /* no WM_NCPAINT unless forced */
218 if( wnd->hrgnUpdate > 1 )
221 if( uncFlags & UNC_REGION )
222 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
225 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
227 GETCLIENTRECTW( wnd, r );
228 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
229 if( uncFlags & UNC_REGION ) hrgnRet = 1;
233 if(!hClip && (uncFlags & UNC_ENTIRE) )
235 /* still don't do anything if there is no nonclient area */
236 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
239 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
241 if ( hClip == hrgnRet && hrgnRet > 1 ) {
242 hClip = CreateRectRgn( 0, 0, 0, 0 );
243 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
246 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
247 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
248 DeleteObject( hClip );
250 * Since all Window locks are suspended while processing the WM_NCPAINT
251 * we want to make sure the window still exists before continuing.
253 if (!IsWindow(wnd->hwndSelf))
255 DeleteObject(hrgnRet);
260 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
266 /***********************************************************************
267 * BeginPaint16 (USER.39)
269 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
273 BeginPaint( hwnd, &ps );
275 lps->fErase = ps.fErase;
276 lps->rcPaint.top = ps.rcPaint.top;
277 lps->rcPaint.left = ps.rcPaint.left;
278 lps->rcPaint.right = ps.rcPaint.right;
279 lps->rcPaint.bottom = ps.rcPaint.bottom;
280 lps->fRestore = ps.fRestore;
281 lps->fIncUpdate = ps.fIncUpdate;
286 /***********************************************************************
287 * BeginPaint (USER32.10)
289 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
293 RECT clipRect, clientRect;
294 WND *wndPtr = WIN_FindWndPtr( hwnd );
295 if (!wndPtr) return 0;
297 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
299 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
301 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
302 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
305 * Make sure the window is still a window. All window locks are suspended
306 * when the WM_NCPAINT is sent.
308 if (!IsWindow(wndPtr->hwndSelf))
310 WIN_ReleaseWndPtr(wndPtr);
314 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
315 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
317 wndPtr->hrgnUpdate = 0;
318 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
322 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate);
324 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
326 /* Don't clip the output to the update region for CS_PARENTDC window */
328 DeleteObject(hrgnUpdate);
329 lps->hdc = GetDCEx( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
330 (bIcon ? DCX_WINDOW : 0) );
334 if( hrgnUpdate ) /* convert to client coordinates */
335 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
336 wndPtr->rectWindow.top - wndPtr->rectClient.top );
337 lps->hdc = GetDCEx(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
338 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
339 /* ReleaseDC() in EndPaint() will delete the region */
342 TRACE("hdc = %04x\n", lps->hdc);
346 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
347 WIN_ReleaseWndPtr(wndPtr);
351 /* It is possible that the clip box is bigger than the window itself,
352 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
353 than the window itself, so we need to intersect the cliprect with
356 GetClipBox( lps->hdc, &clipRect );
357 GetClientRect( hwnd, &clientRect );
359 /* The rect obtained by GetClipBox is in logical, so make the client in logical to*/
360 DPtoLP(lps->hdc, (LPPOINT)&clientRect, 2);
362 IntersectRect(&lps->rcPaint, &clientRect, &clipRect);
364 TRACE("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
365 lps->rcPaint.right, lps->rcPaint.bottom );
367 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
369 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
370 lps->fErase = !SendMessageA(hwnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
371 (WPARAM16)lps->hdc, 0 );
373 else lps->fErase = TRUE;
375 WIN_ReleaseWndPtr(wndPtr);
380 /***********************************************************************
381 * EndPaint16 (USER.40)
383 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
385 ReleaseDC16( hwnd, lps->hdc );
391 /***********************************************************************
392 * EndPaint (USER32.176)
394 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
396 ReleaseDC( hwnd, lps->hdc );
402 /***********************************************************************
403 * FillWindow (USER.324)
405 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
409 GetClientRect( hwnd, &rect );
410 DPtoLP( hdc, (LPPOINT)&rect, 2 );
411 CONV_RECT32TO16( &rect, &rc16 );
412 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rc16 );
416 /***********************************************************************
417 * PAINT_GetControlBrush
419 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
421 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
422 (WPARAM)hDC, (LPARAM)hWnd );
423 if( !IsGDIObject16(bkgBrush) )
424 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
429 /***********************************************************************
430 * PaintRect (USER.325)
432 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
433 HBRUSH16 hbrush, const RECT16 *rect)
435 if( hbrush <= CTLCOLOR_MAX )
438 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
443 FillRect16( hdc, rect, hbrush );
447 /***********************************************************************
448 * GetControlBrush (USER.326)
450 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
452 WND* wndPtr = WIN_FindWndPtr( hwnd );
455 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
458 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
459 else parent = WIN_LockWndPtr(wndPtr->parent);
460 if( !parent ) parent = wndPtr;
461 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
462 WIN_ReleaseWndPtr(parent);
465 retvalue = (HBRUSH16)0;
467 WIN_ReleaseWndPtr(wndPtr);
472 /***********************************************************************
473 * RDW_ValidateParent [RDW_UpdateRgns() helper]
475 * Validate the portions of parents that are covered by a validated child
478 void RDW_ValidateParent(WND *wndChild)
480 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
481 WND *wndDesktop = WIN_GetDesktop();
484 if (wndChild->hrgnUpdate == 1 ) {
488 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
489 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
490 hrg = CreateRectRgnIndirect( &r );
492 hrg = wndChild->hrgnUpdate;
494 while ((wndParent) && (wndParent != wndDesktop) ) {
495 if (!(wndParent->dwStyle & WS_CLIPCHILDREN))
497 if (wndParent->hrgnUpdate != 0)
500 RECT rect, rectParent;
501 if( wndParent->hrgnUpdate == 1 )
507 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
508 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
510 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
512 /* we must offset the child region by the offset of the child rect in the parent */
513 GetWindowRect(wndParent->hwndSelf, &rectParent);
514 GetWindowRect(wndChild->hwndSelf, &rect);
515 ptOffset.x = rect.left - rectParent.left;
516 ptOffset.y = rect.top - rectParent.top;
517 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
518 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
519 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
522 WIN_UpdateWndPtr(&wndParent, wndParent->parent);
524 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
525 WIN_ReleaseWndPtr(wndParent);
526 WIN_ReleaseDesktop();
529 /***********************************************************************
530 * RDW_UpdateRgns [RedrawWindow() helper]
532 * Walks the window tree and adds/removes parts of the hRgn to/from update
533 * regions of windows that overlap it. Also, manages internal paint flags.
535 * NOTE: Walks the window tree so the caller must lock it.
536 * MUST preserve hRgn (can modify but then has to restore).
538 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
541 * Called only when one of the following is set:
542 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
545 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
546 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
547 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
552 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
553 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
555 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
557 if( flags & RDW_INVALIDATE )
561 switch( wndPtr->hrgnUpdate )
564 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
567 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
568 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
572 GetRgnBox( wndPtr->hrgnUpdate, &r );
573 if( IsRectEmpty( &r ) )
575 DeleteObject( wndPtr->hrgnUpdate );
576 wndPtr->hrgnUpdate = 0;
581 case 1: /* already an entire window */
587 if( wndPtr->hrgnUpdate > 1 )
588 DeleteObject( wndPtr->hrgnUpdate );
589 wndPtr->hrgnUpdate = 1;
592 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
594 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
595 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
597 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
598 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
601 else if( flags & RDW_VALIDATE )
603 if( wndPtr->hrgnUpdate )
607 if( wndPtr->hrgnUpdate == 1 )
608 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
610 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
614 else /* validate everything */
616 if( wndPtr->hrgnUpdate > 1 )
619 DeleteObject( wndPtr->hrgnUpdate );
621 wndPtr->hrgnUpdate = 0;
624 if( !wndPtr->hrgnUpdate )
626 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
627 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
628 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
632 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
633 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
637 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
638 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
640 /* in/validate child windows that intersect with the region if it
641 * is a valid handle. */
643 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
645 if( hRgn > 1 && bChildren )
647 WND* wnd = wndPtr->child;
648 POINT ptTotal, prevOrigin = {0,0};
651 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
652 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
654 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
656 if( wnd->dwStyle & WS_VISIBLE )
660 r.left = wnd->rectWindow.left + ptClient.x;
661 r.right = wnd->rectWindow.right + ptClient.x;
662 r.top = wnd->rectWindow.top + ptClient.y;
663 r.bottom = wnd->rectWindow.bottom + ptClient.y;
665 ptOffset.x = r.left - prevOrigin.x;
666 ptOffset.y = r.top - prevOrigin.y;
667 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
669 if( RectInRegion( hRgn, &r ) )
671 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
672 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
673 prevOrigin.x = r.left + ptTotal.x;
674 prevOrigin.y = r.top + ptTotal.y;
675 ptTotal.x += ptOffset.x;
676 ptTotal.y += ptOffset.y;
680 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
685 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
690 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
691 if( wnd->dwStyle & WS_VISIBLE )
692 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
697 /* Set/clear internal paint flag */
699 if (flags & RDW_INTERNALPAINT)
701 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
702 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
703 wndPtr->flags |= WIN_INTERNAL_PAINT;
705 else if (flags & RDW_NOINTERNALPAINT)
707 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
708 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
709 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
713 /***********************************************************************
714 * RDW_Paint [RedrawWindow() helper]
716 * Walks the window tree and paints/erases windows that have
717 * nonzero update regions according to redraw flags. hrgn is a scratch
718 * region passed down during recursion. Must not be 1.
721 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
723 /* NOTE: wndPtr is locked by caller.
725 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
726 * SendMessage() calls. This is a comment inside DefWindowProc() source
729 * This message avoids lots of inter-app message traffic
730 * by switching to the other task and continuing the
734 * LOWORD(lParam) = hrgnClip
735 * HIWORD(lParam) = hwndSkip (not used; always NULL)
739 HWND hWnd = wndPtr->hwndSelf;
740 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
742 /* Erase/update the window itself ... */
744 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
747 * Check if this window should delay it's processing of WM_NCPAINT.
748 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
750 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
751 ex |= RDW_EX_DELAY_NCPAINT;
753 if (flags & RDW_UPDATENOW)
755 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
756 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
758 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
760 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
763 hrgnRet = WIN_UpdateNCRgn(wndPtr,
765 UNC_REGION | UNC_CHECK |
766 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) |
767 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
771 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
772 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
774 if( bIcon ) dcx |= DCX_WINDOW;
777 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
778 wndPtr->rectWindow.top - wndPtr->rectClient.top);
780 dcx &= ~DCX_INTERSECTRGN;
781 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
783 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
784 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
785 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
786 ReleaseDC( hWnd, hDC );
792 if( !IsWindow(hWnd) ) return hrgn;
793 ex &= ~RDW_EX_TOPFRAME;
795 /* ... and its child windows */
797 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
798 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
802 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
805 for (ppWnd = list; *ppWnd; ppWnd++)
807 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
808 if (!IsWindow(wndPtr->hwndSelf)) continue;
809 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
810 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
811 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
813 WIN_ReleaseWndPtr(wndPtr);
814 WIN_ReleaseWinArray(list);
821 /***********************************************************************
825 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
826 HRGN hrgnUpdate, UINT flags, UINT ex )
833 if (!hwnd) hwnd = GetDesktopWindow();
834 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
836 /* check if the window or its parents are visible/not minimized */
838 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
840 WIN_ReleaseWndPtr(wndPtr);
848 GetRgnBox( hrgnUpdate, &r );
849 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
850 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
858 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
859 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
860 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
864 /* prepare an update region in window coordinates */
866 if( flags & RDW_FRAME )
867 r = wndPtr->rectWindow;
869 r = wndPtr->rectClient;
871 if( ex & RDW_EX_XYWINDOW )
874 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
878 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
879 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
880 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
883 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
885 /* If the window doesn't have hrgnUpdate we leave hRgn zero
886 * and put a new region straight into wndPtr->hrgnUpdate
887 * so that RDW_UpdateRgns() won't have to do any extra work.
892 if( wndPtr->hrgnUpdate )
893 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
895 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
897 else if( rectUpdate )
899 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
900 OffsetRect( &r2, pt.x, pt.y );
903 if( wndPtr->hrgnUpdate == 0 )
904 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
906 hRgn = CreateRectRgnIndirect( &r2 );
908 else /* entire window or client depending on RDW_FRAME */
910 if( flags & RDW_FRAME )
912 if( wndPtr->hrgnUpdate )
913 DeleteObject( wndPtr->hrgnUpdate );
914 wndPtr->hrgnUpdate = 1;
918 GETCLIENTRECTW( wndPtr, r2 );
923 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
925 /* In this we cannot leave with zero hRgn */
928 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
929 GetRgnBox( hRgn, &r2 );
930 if( IsRectEmpty( &r2 ) ) goto END;
932 else if( rectUpdate )
934 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
935 OffsetRect( &r2, pt.x, pt.y );
937 hRgn = CreateRectRgnIndirect( &r2 );
939 else /* entire window or client depending on RDW_FRAME */
941 if( flags & RDW_FRAME )
945 GETCLIENTRECTW( wndPtr, r2 );
951 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
953 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
955 /* Erase/update windows, from now on hRgn is a scratch region */
957 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
960 if( hRgn > 1 && (hRgn != hrgnUpdate) )
962 WIN_ReleaseWndPtr(wndPtr);
967 /***********************************************************************
968 * RedrawWindow (USER32.426)
970 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
971 HRGN hrgnUpdate, UINT flags )
973 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
977 /***********************************************************************
978 * RedrawWindow16 (USER.290)
980 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
981 HRGN16 hrgnUpdate, UINT16 flags )
986 CONV_RECT16TO32( rectUpdate, &r );
987 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
989 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
990 (HRGN)hrgnUpdate, flags, 0 );
994 /***********************************************************************
995 * UpdateWindow16 (USER.124)
997 void WINAPI UpdateWindow16( HWND16 hwnd )
999 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN, 0 );
1002 /***********************************************************************
1003 * UpdateWindow (USER32.567)
1005 void WINAPI UpdateWindow( HWND hwnd )
1007 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN, 0 );
1010 /***********************************************************************
1011 * InvalidateRgn16 (USER.126)
1013 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1015 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
1016 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1020 /***********************************************************************
1021 * InvalidateRgn (USER32.329)
1023 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1025 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1029 /***********************************************************************
1030 * InvalidateRect16 (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.328)
1041 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1043 return PAINT_RedrawWindow( hwnd, rect, 0,
1044 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1048 /***********************************************************************
1049 * ValidateRgn16 (USER.128)
1051 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1053 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
1054 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1058 /***********************************************************************
1059 * ValidateRgn (USER32.572)
1061 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1063 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1067 /***********************************************************************
1068 * ValidateRect16 (USER.127)
1070 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1072 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1076 /***********************************************************************
1077 * ValidateRect (USER32.571)
1079 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1081 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1085 /***********************************************************************
1086 * GetUpdateRect16 (USER.190)
1088 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1093 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1094 ret = GetUpdateRect( hwnd, &r, erase );
1095 CONV_RECT32TO16( &r, rect );
1100 /***********************************************************************
1101 * GetUpdateRect (USER32.297)
1103 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1106 WND * wndPtr = WIN_FindWndPtr( hwnd );
1107 if (!wndPtr) return FALSE;
1111 if (wndPtr->hrgnUpdate > 1)
1113 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1114 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1119 GetRgnBox( hrgn, rect );
1120 DeleteObject( hrgn );
1121 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1123 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1125 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1130 if( wndPtr->hrgnUpdate == 1 )
1132 GetClientRect( hwnd, rect );
1133 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1136 SetRectEmpty( rect );
1138 retvalue = (wndPtr->hrgnUpdate >= 1);
1140 WIN_ReleaseWndPtr(wndPtr);
1145 /***********************************************************************
1146 * GetUpdateRgn16 (USER.237)
1148 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1150 return GetUpdateRgn( hwnd, hrgn, erase );
1154 /***********************************************************************
1155 * GetUpdateRgn (USER32.298)
1157 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1160 WND * wndPtr = WIN_FindWndPtr( hwnd );
1161 if (!wndPtr) return ERROR;
1163 if (wndPtr->hrgnUpdate == 0)
1165 SetRectRgn( hrgn, 0, 0, 0, 0 );
1166 retval = NULLREGION;
1170 if (wndPtr->hrgnUpdate == 1)
1172 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1173 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1174 retval = SIMPLEREGION;
1178 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1179 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1180 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1182 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1184 WIN_ReleaseWndPtr(wndPtr);
1189 /***********************************************************************
1190 * ExcludeUpdateRgn16 (USER.238)
1192 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1194 return ExcludeUpdateRgn( hdc, hwnd );
1198 /***********************************************************************
1199 * ExcludeUpdateRgn (USER32.195)
1201 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1206 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1208 if (wndPtr->hrgnUpdate)
1211 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1212 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1213 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1214 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1215 if( wndPtr->hrgnUpdate > 1 )
1217 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1218 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1219 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1222 /* do ugly coordinate translations in dce.c */
1224 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1225 DeleteObject( hrgn );
1226 WIN_ReleaseWndPtr(wndPtr);
1229 WIN_ReleaseWndPtr(wndPtr);
1230 return GetClipBox( hdc, &rect );
1235 /***********************************************************************
1236 * FillRect16 (USER.81)
1238 * The Win16 variant doesn't support special color brushes like
1239 * the Win32 one, despite the fact that Win16, as well as Win32,
1240 * supports special background brushes for a window class.
1242 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1246 /* coordinates are logical so we cannot fast-check 'rect',
1247 * it will be done later in the PatBlt().
1250 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1251 PatBlt( hdc, rect->left, rect->top,
1252 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1253 SelectObject( hdc, prevBrush );
1258 /***********************************************************************
1259 * FillRect (USER32.197)
1261 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1265 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1266 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1269 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1270 PatBlt( hdc, rect->left, rect->top,
1271 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1272 SelectObject( hdc, prevBrush );
1277 /***********************************************************************
1278 * InvertRect16 (USER.82)
1280 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1282 PatBlt( hdc, rect->left, rect->top,
1283 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1287 /***********************************************************************
1288 * InvertRect (USER32.330)
1290 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1292 return PatBlt( hdc, rect->left, rect->top,
1293 rect->right - rect->left, rect->bottom - rect->top,
1298 /***********************************************************************
1299 * FrameRect (USER32.203)
1301 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1306 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1307 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1309 PatBlt( hdc, r.left, r.top, 1,
1310 r.bottom - r.top, PATCOPY );
1311 PatBlt( hdc, r.right - 1, r.top, 1,
1312 r.bottom - r.top, PATCOPY );
1313 PatBlt( hdc, r.left, r.top,
1314 r.right - r.left, 1, PATCOPY );
1315 PatBlt( hdc, r.left, r.bottom - 1,
1316 r.right - r.left, 1, PATCOPY );
1318 SelectObject( hdc, prevBrush );
1323 /***********************************************************************
1324 * FrameRect16 (USER.83)
1326 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1329 CONV_RECT16TO32( rect16, &rect );
1330 return FrameRect( hdc, &rect, hbrush );
1334 /***********************************************************************
1335 * DrawFocusRect16 (USER.466)
1337 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1340 CONV_RECT16TO32( rc, &rect32 );
1341 DrawFocusRect( hdc, &rect32 );
1345 /***********************************************************************
1346 * DrawFocusRect (USER32.156)
1348 * FIXME: PatBlt(PATINVERT) with background brush.
1350 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1353 HPEN hOldPen, hNewPen;
1354 INT oldDrawMode, oldBkMode;
1356 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1357 hNewPen = CreatePen(PS_DOT, 1, GetSysColor(COLOR_WINDOWTEXT));
1358 hOldPen = SelectObject(hdc, hNewPen);
1359 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1360 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1362 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1364 SetBkMode(hdc, oldBkMode);
1365 SetROP2(hdc, oldDrawMode);
1366 SelectObject(hdc, hOldPen);
1367 DeleteObject(hNewPen);
1368 SelectObject(hdc, hOldBrush);
1373 /**********************************************************************
1374 * DrawAnimatedRects16 (USER.448)
1376 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
1377 const RECT16* lprcFrom,
1378 const RECT16* lprcTo )
1380 RECT rcFrom32, rcTo32;
1382 rcFrom32.left = (INT)lprcFrom->left;
1383 rcFrom32.top = (INT)lprcFrom->top;
1384 rcFrom32.right = (INT)lprcFrom->right;
1385 rcFrom32.bottom = (INT)lprcFrom->bottom;
1387 rcTo32.left = (INT)lprcTo->left;
1388 rcTo32.top = (INT)lprcTo->top;
1389 rcTo32.right = (INT)lprcTo->right;
1390 rcTo32.bottom = (INT)lprcTo->bottom;
1392 return DrawAnimatedRects((HWND)hwnd, (INT)idAni, &rcFrom32, &rcTo32);
1396 /**********************************************************************
1397 * DrawAnimatedRects (USER32.153)
1399 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1400 const RECT* lprcFrom,
1401 const RECT* lprcTo )
1403 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1408 /**********************************************************************
1409 * PAINTING_DrawStateJam
1411 * Jams in the requested type in the dc
1413 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1414 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1415 LPRECT rc, UINT dtflags,
1416 BOOL unicode, BOOL _32bit)
1421 INT cx = rc->right - rc->left;
1422 INT cy = rc->bottom - rc->top;
1427 case DST_PREFIXTEXT:
1429 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1431 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1433 return DrawTextA(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT)wp, rc, dtflags);
1436 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1439 memdc = CreateCompatibleDC(hdc);
1440 if(!memdc) return FALSE;
1441 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1447 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1448 SelectObject(memdc, hbmsave);
1455 return func(hdc, lp, wp, cx, cy);
1457 return (BOOL)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
1464 /**********************************************************************
1465 * PAINTING_DrawState()
1467 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr,
1468 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1469 INT x, INT y, INT cx, INT cy,
1470 UINT flags, BOOL unicode, BOOL _32bit)
1472 HBITMAP hbm, hbmsave;
1477 UINT dtflags = DT_NOCLIP;
1479 UINT opcode = flags & 0xf;
1483 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1486 len = lstrlenW((LPWSTR)lp);
1488 len = strlen((LPSTR)lp);
1490 len = strlen((LPSTR)PTR_SEG_TO_LIN(lp));
1493 /* Find out what size the image has if not given by caller */
1497 CURSORICONINFO *ici;
1503 case DST_PREFIXTEXT:
1505 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1507 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1509 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
1510 if(!retval) return FALSE;
1514 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1515 if(!ici) return FALSE;
1517 s.cy = ici->nHeight;
1518 GlobalUnlock16((HGLOBAL16)lp);
1522 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1528 case DST_COMPLEX: /* cx and cy must be set in this mode */
1541 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1542 dtflags |= DT_RIGHT;
1543 if(opcode == DST_TEXT)
1544 dtflags |= DT_NOPREFIX;
1546 /* For DSS_NORMAL we just jam in the image and return */
1547 if((flags & 0x7ff0) == DSS_NORMAL)
1549 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1552 /* For all other states we need to convert the image to B/W in a local bitmap */
1553 /* before it is displayed */
1554 fg = SetTextColor(hdc, RGB(0, 0, 0));
1555 bg = SetBkColor(hdc, RGB(255, 255, 255));
1556 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1557 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1558 retval = FALSE; /* assume failure */
1560 /* From here on we must use "goto cleanup" when something goes wrong */
1561 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1562 if(!hbm) goto cleanup;
1563 memdc = CreateCompatibleDC(hdc);
1564 if(!memdc) goto cleanup;
1565 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1566 if(!hbmsave) goto cleanup;
1567 rc.left = rc.top = 0;
1570 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1571 SetBkColor(memdc, RGB(255, 255, 255));
1572 SetTextColor(memdc, RGB(0, 0, 0));
1573 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1574 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
1575 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1576 if(hfsave) SelectObject(memdc, hfsave);
1577 if(!tmp) goto cleanup;
1579 /* These states cause the image to be dithered */
1580 if(flags & (DSS_UNION|DSS_DISABLED))
1582 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1583 if(!hbsave) goto cleanup;
1584 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1585 if(hbsave) SelectObject(memdc, hbsave);
1586 if(!tmp) goto cleanup;
1589 hbsave = (HBRUSH)SelectObject(hdc, hbr ? hbr : GetStockObject(WHITE_BRUSH));
1590 if(!hbsave) goto cleanup;
1592 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1594 /* DSS_DEFAULT makes the image boldface */
1595 if(flags & DSS_DEFAULT)
1597 if(!BitBlt(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1600 retval = TRUE; /* We succeeded */
1603 SetTextColor(hdc, fg);
1604 SetBkColor(hdc, bg);
1606 if(hbsave) SelectObject(hdc, hbsave);
1607 if(hbmsave) SelectObject(memdc, hbmsave);
1608 if(hbm) DeleteObject(hbm);
1609 if(memdc) DeleteDC(memdc);
1614 /**********************************************************************
1615 * DrawStateA() (USER32.162)
1617 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1618 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1619 INT x, INT y, INT cx, INT cy, UINT flags)
1621 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1624 /**********************************************************************
1625 * DrawStateW() (USER32.163)
1627 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1628 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1629 INT x, INT y, INT cx, INT cy, UINT flags)
1631 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1634 /**********************************************************************
1635 * DrawState16() (USER.449)
1637 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1638 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1639 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1641 return PAINTING_DrawState(hdc, hbr, (DRAWSTATEPROC)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1645 /***********************************************************************
1646 * SelectPalette16 (USER.282)
1648 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1649 BOOL16 bForceBackground )
1651 return SelectPalette( hDC, hPal, bForceBackground );
1655 /***********************************************************************
1656 * RealizePalette16 (USER.283)
1658 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1660 return RealizePalette( hDC );