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 RECT16 clipRect
, clientRect
;
274 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
275 if (!wndPtr
) return 0;
277 bIcon
= (wndPtr
->dwStyle
& WS_MINIMIZE
&& GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
279 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
281 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
282 WIN_UpdateNCRgn( wndPtr
, 0, UNC_UPDATE
| UNC_IN_BEGINPAINT
);
285 * Make sure the window is still a window. All window locks are suspended
286 * when the WM_NCPAINT is sent.
288 if (!IsWindow(wndPtr
->hwndSelf
))
290 WIN_ReleaseWndPtr(wndPtr
);
294 if( ((hrgnUpdate
= wndPtr
->hrgnUpdate
) != 0) || (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
295 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
297 wndPtr
->hrgnUpdate
= 0;
298 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
302 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate
);
304 if (GetClassWord16(wndPtr
->hwndSelf
, GCW_STYLE
) & CS_PARENTDC
)
306 /* Don't clip the output to the update region for CS_PARENTDC window */
308 DeleteObject(hrgnUpdate
);
309 lps
->hdc
= GetDCEx16( hwnd
, 0, DCX_WINDOWPAINT
| DCX_USESTYLE
|
310 (bIcon
? DCX_WINDOW
: 0) );
314 if( hrgnUpdate
) /* convert to client coordinates */
315 OffsetRgn( hrgnUpdate
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
316 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
317 lps
->hdc
= GetDCEx16(hwnd
, hrgnUpdate
, DCX_INTERSECTRGN
|
318 DCX_WINDOWPAINT
| DCX_USESTYLE
| (bIcon
? DCX_WINDOW
: 0) );
319 /* ReleaseDC() in EndPaint() will delete the region */
322 TRACE("hdc = %04x\n", lps
->hdc
);
326 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd
);
327 WIN_ReleaseWndPtr(wndPtr
);
331 /* It is possible that the clip box is bigger than the window itself,
332 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
333 than the window itself, so we need to intersect the cliprect with
336 GetClipBox16( lps
->hdc
, &clipRect
);
337 GetClientRect16( hwnd
, &clientRect
);
339 /* The rect obtained by GetClipBox is in logical, so make the client in logical to*/
340 DPtoLP16(lps
->hdc
, (LPPOINT16
) &clientRect
, 2);
342 IntersectRect16(&lps
->rcPaint
, &clientRect
, &clipRect
);
344 TRACE("box = (%i,%i - %i,%i)\n", lps
->rcPaint
.left
, lps
->rcPaint
.top
,
345 lps
->rcPaint
.right
, lps
->rcPaint
.bottom
);
347 if (wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
349 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
350 lps
->fErase
= !SendMessage16(hwnd
, (bIcon
) ? WM_ICONERASEBKGND
352 (WPARAM16
)lps
->hdc
, 0 );
354 else lps
->fErase
= TRUE
;
356 WIN_ReleaseWndPtr(wndPtr
);
361 /***********************************************************************
362 * BeginPaint32 (USER32.10)
364 HDC WINAPI
BeginPaint( HWND hwnd
, PAINTSTRUCT
*lps
)
368 BeginPaint16( hwnd
, &ps
);
369 lps
->hdc
= (HDC
)ps
.hdc
;
370 lps
->fErase
= ps
.fErase
;
371 lps
->rcPaint
.top
= ps
.rcPaint
.top
;
372 lps
->rcPaint
.left
= ps
.rcPaint
.left
;
373 lps
->rcPaint
.right
= ps
.rcPaint
.right
;
374 lps
->rcPaint
.bottom
= ps
.rcPaint
.bottom
;
375 lps
->fRestore
= ps
.fRestore
;
376 lps
->fIncUpdate
= ps
.fIncUpdate
;
381 /***********************************************************************
382 * EndPaint16 (USER.40)
384 BOOL16 WINAPI
EndPaint16( HWND16 hwnd
, const PAINTSTRUCT16
* lps
)
386 ReleaseDC16( hwnd
, lps
->hdc
);
392 /***********************************************************************
393 * EndPaint32 (USER32.176)
395 BOOL WINAPI
EndPaint( HWND hwnd
, const PAINTSTRUCT
*lps
)
397 ReleaseDC( hwnd
, lps
->hdc
);
403 /***********************************************************************
404 * FillWindow (USER.324)
406 void WINAPI
FillWindow16( HWND16 hwndParent
, HWND16 hwnd
, HDC16 hdc
, HBRUSH16 hbrush
)
409 GetClientRect16( hwnd
, &rect
);
410 DPtoLP16( hdc
, (LPPOINT16
)&rect
, 2 );
411 PaintRect16( hwndParent
, hwnd
, hdc
, hbrush
, &rect
);
415 /***********************************************************************
416 * PAINT_GetControlBrush
418 static HBRUSH16
PAINT_GetControlBrush( HWND hParent
, HWND hWnd
, HDC16 hDC
, UINT16 ctlType
)
420 HBRUSH16 bkgBrush
= (HBRUSH16
)SendMessageA( hParent
, WM_CTLCOLORMSGBOX
+ ctlType
,
421 (WPARAM
)hDC
, (LPARAM
)hWnd
);
422 if( !IsGDIObject16(bkgBrush
) )
423 bkgBrush
= DEFWND_ControlColor( hDC
, ctlType
);
428 /***********************************************************************
429 * PaintRect (USER.325)
431 void WINAPI
PaintRect16( HWND16 hwndParent
, HWND16 hwnd
, HDC16 hdc
,
432 HBRUSH16 hbrush
, const RECT16
*rect
)
434 if( hbrush
<= CTLCOLOR_MAX
)
437 hbrush
= PAINT_GetControlBrush( hwndParent
, hwnd
, hdc
, (UINT16
)hbrush
);
442 FillRect16( hdc
, rect
, hbrush
);
446 /***********************************************************************
447 * GetControlBrush (USER.326)
449 HBRUSH16 WINAPI
GetControlBrush16( HWND16 hwnd
, HDC16 hdc
, UINT16 ctlType
)
451 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
454 if((ctlType
<= CTLCOLOR_MAX
) && wndPtr
)
457 if( wndPtr
->dwStyle
& WS_POPUP
) parent
= WIN_LockWndPtr(wndPtr
->owner
);
458 else parent
= WIN_LockWndPtr(wndPtr
->parent
);
459 if( !parent
) parent
= wndPtr
;
460 retvalue
= (HBRUSH16
)PAINT_GetControlBrush( parent
->hwndSelf
, hwnd
, hdc
, ctlType
);
461 WIN_ReleaseWndPtr(parent
);
464 retvalue
= (HBRUSH16
)0;
466 WIN_ReleaseWndPtr(wndPtr
);
471 /***********************************************************************
472 * RDW_ValidateParent [RDW_UpdateRgns() helper]
474 * Validate the portions of parent that are covered by a validated child
477 void RDW_ValidateParent(WND
*wndChild
)
479 WND
*wndParent
= WIN_LockWndPtr(wndChild
->parent
);
480 WND
*wndDesktop
= WIN_GetDesktop();
482 if ((wndParent
) && (wndParent
!= wndDesktop
) && !(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
485 if (wndChild
->hrgnUpdate
== 1 )
491 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
492 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
494 hrg
= CreateRectRgnIndirect( &r
);
497 hrg
= wndChild
->hrgnUpdate
;
498 if (wndParent
->hrgnUpdate
!= 0)
501 RECT rect
, rectParent
;
502 if( wndParent
->hrgnUpdate
== 1 )
508 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
509 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
511 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
513 /* we must offset the child region by the offset of the child rect in the parent */
514 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
515 GetWindowRect(wndChild
->hwndSelf
, &rect
);
516 ptOffset
.x
= rect
.left
- rectParent
.left
;
517 ptOffset
.y
= rect
.top
- rectParent
.top
;
518 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
519 CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
);
520 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
522 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
524 WIN_ReleaseWndPtr(wndParent
);
525 WIN_ReleaseDesktop();
528 /***********************************************************************
529 * RDW_UpdateRgns [RedrawWindow() helper]
531 * Walks the window tree and adds/removes parts of the hRgn to/from update
532 * regions of windows that overlap it. Also, manages internal paint flags.
534 * NOTE: Walks the window tree so the caller must lock it.
535 * MUST preserve hRgn (can modify but then has to restore).
537 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
540 * Called only when one of the following is set:
541 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
544 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
545 BOOL bChildren
= ( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
546 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
551 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
552 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
554 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
556 if( flags
& RDW_INVALIDATE
)
560 switch( wndPtr
->hrgnUpdate
)
563 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
566 wndPtr
->hrgnUpdate
= REGION_CropRgn( wndPtr
->hrgnUpdate
,
567 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
571 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
572 if( IsRectEmpty( &r
) )
574 DeleteObject( wndPtr
->hrgnUpdate
);
575 wndPtr
->hrgnUpdate
= 0;
580 case 1: /* already an entire window */
586 if( wndPtr
->hrgnUpdate
> 1 )
587 DeleteObject( wndPtr
->hrgnUpdate
);
588 wndPtr
->hrgnUpdate
= 1;
591 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
593 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
594 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
596 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
597 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
600 else if( flags
& RDW_VALIDATE
)
602 if( wndPtr
->hrgnUpdate
)
606 if( wndPtr
->hrgnUpdate
== 1 )
607 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
609 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
613 else /* validate everything */
615 if( wndPtr
->hrgnUpdate
> 1 )
618 DeleteObject( wndPtr
->hrgnUpdate
);
620 wndPtr
->hrgnUpdate
= 0;
623 if( !wndPtr
->hrgnUpdate
)
625 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
626 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
627 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
631 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
632 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
636 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
637 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
639 /* in/validate child windows that intersect with the region if it
640 * is a valid handle. */
642 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
644 if( hRgn
> 1 && bChildren
)
646 WND
* wnd
= wndPtr
->child
;
647 POINT ptTotal
, prevOrigin
= {0,0};
650 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
651 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
653 for( ptTotal
.x
= ptTotal
.y
= 0; wnd
; wnd
= wnd
->next
)
655 if( wnd
->dwStyle
& WS_VISIBLE
)
659 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
660 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
661 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
662 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
664 ptOffset
.x
= r
.left
- prevOrigin
.x
;
665 ptOffset
.y
= r
.top
- prevOrigin
.y
;
666 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
668 if( RectInRegion( hRgn
, &r
) )
670 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
671 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
672 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
673 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
674 ptTotal
.x
+= ptOffset
.x
;
675 ptTotal
.y
+= ptOffset
.y
;
679 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
684 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
689 for( wnd
= wndPtr
->child
; wnd
; wnd
= wnd
->next
)
690 if( wnd
->dwStyle
& WS_VISIBLE
)
691 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
696 /* Set/clear internal paint flag */
698 if (flags
& RDW_INTERNALPAINT
)
700 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
701 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
702 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
704 else if (flags
& RDW_NOINTERNALPAINT
)
706 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
707 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
708 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
712 /***********************************************************************
713 * RDW_Paint [RedrawWindow() helper]
715 * Walks the window tree and paints/erases windows that have
716 * nonzero update regions according to redraw flags. hrgn is a scratch
717 * region passed down during recursion. Must not be 1.
720 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
722 /* NOTE: wndPtr is locked by caller.
724 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
725 * SendMessage() calls. This is a comment inside DefWindowProc() source
728 * This message avoids lots of inter-app message traffic
729 * by switching to the other task and continuing the
733 * LOWORD(lParam) = hrgnClip
734 * HIWORD(lParam) = hwndSkip (not used; always NULL)
738 HWND hWnd
= wndPtr
->hwndSelf
;
739 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
741 /* Erase/update the window itself ... */
743 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
746 * Check if this window should delay it's processing of WM_NCPAINT.
747 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
749 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
, 0) )
750 ex
|= RDW_EX_DELAY_NCPAINT
;
752 if (flags
& RDW_UPDATENOW
)
754 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
755 SendMessage16( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
757 else if ((flags
& RDW_ERASENOW
) || (ex
& RDW_EX_TOPFRAME
))
759 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
762 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
764 UNC_REGION
| UNC_CHECK
|
765 ((ex
& RDW_EX_TOPFRAME
) ? UNC_ENTIRE
: 0) |
766 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
770 if( hrgnRet
> 1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
771 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
773 if( bIcon
) dcx
|= DCX_WINDOW
;
776 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
777 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
779 dcx
&= ~DCX_INTERSECTRGN
;
780 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
782 if (SendMessage16( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
783 : WM_ERASEBKGND
, (WPARAM16
)hDC
, 0 ))
784 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
785 ReleaseDC( hWnd
, hDC
);
791 if( !IsWindow(hWnd
) ) return hrgn
;
792 ex
&= ~RDW_EX_TOPFRAME
;
794 /* ... and its child windows */
796 if( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
797 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
801 if( (list
= WIN_BuildWinArray( wndPtr
, 0, NULL
)) )
804 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
806 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
807 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
808 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
809 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
810 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
812 WIN_ReleaseWndPtr(wndPtr
);
813 WIN_ReleaseWinArray(list
);
820 /***********************************************************************
824 BOOL
PAINT_RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
825 HRGN hrgnUpdate
, UINT flags
, UINT ex
)
832 if (!hwnd
) hwnd
= GetDesktopWindow();
833 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
835 /* check if the window or its parents are visible/not minimized */
837 if (!WIN_IsWindowDrawable( wndPtr
, !(flags
& RDW_FRAME
) ) )
839 WIN_ReleaseWndPtr(wndPtr
);
847 GetRgnBox( hrgnUpdate
, &r
);
848 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
849 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
, ex
);
857 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
858 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
859 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
, ex
);
863 /* prepare an update region in window coordinates */
865 if( flags
& RDW_FRAME
)
866 r
= wndPtr
->rectWindow
;
868 r
= wndPtr
->rectClient
;
870 if( ex
& RDW_EX_XYWINDOW
)
873 OffsetRect( &r
, -wndPtr
->rectWindow
.left
, -wndPtr
->rectWindow
.top
);
877 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
878 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
879 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
882 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
884 /* If the window doesn't have hrgnUpdate we leave hRgn zero
885 * and put a new region straight into wndPtr->hrgnUpdate
886 * so that RDW_UpdateRgns() won't have to do any extra work.
891 if( wndPtr
->hrgnUpdate
)
892 hRgn
= REGION_CropRgn( 0, hrgnUpdate
, NULL
, &pt
);
894 wndPtr
->hrgnUpdate
= REGION_CropRgn( 0, hrgnUpdate
, &r
, &pt
);
896 else if( rectUpdate
)
898 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
899 OffsetRect( &r2
, pt
.x
, pt
.y
);
902 if( wndPtr
->hrgnUpdate
== 0 )
903 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
905 hRgn
= CreateRectRgnIndirect( &r2
);
907 else /* entire window or client depending on RDW_FRAME */
909 if( flags
& RDW_FRAME
)
911 if( wndPtr
->hrgnUpdate
)
912 DeleteObject( wndPtr
->hrgnUpdate
);
913 wndPtr
->hrgnUpdate
= 1;
917 GETCLIENTRECTW( wndPtr
, r2
);
922 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
924 /* In this we cannot leave with zero hRgn */
927 hRgn
= REGION_CropRgn( hRgn
, hrgnUpdate
, &r
, &pt
);
928 GetRgnBox( hRgn
, &r2
);
929 if( IsRectEmpty( &r2
) ) goto END
;
931 else if( rectUpdate
)
933 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
934 OffsetRect( &r2
, pt
.x
, pt
.y
);
936 hRgn
= CreateRectRgnIndirect( &r2
);
938 else /* entire window or client depending on RDW_FRAME */
940 if( flags
& RDW_FRAME
)
944 GETCLIENTRECTW( wndPtr
, r2
);
950 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
952 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
954 /* Erase/update windows, from now on hRgn is a scratch region */
956 hRgn
= RDW_Paint( wndPtr
, (hRgn
== 1) ? 0 : hRgn
, flags
, ex
);
959 if( hRgn
> 1 && (hRgn
!= hrgnUpdate
) )
961 WIN_ReleaseWndPtr(wndPtr
);
966 /***********************************************************************
967 * RedrawWindow32 (USER32.426)
969 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
970 HRGN hrgnUpdate
, UINT flags
)
972 return PAINT_RedrawWindow( hwnd
, rectUpdate
, hrgnUpdate
, flags
, 0 );
976 /***********************************************************************
977 * RedrawWindow16 (USER.290)
979 BOOL16 WINAPI
RedrawWindow16( HWND16 hwnd
, const RECT16
*rectUpdate
,
980 HRGN16 hrgnUpdate
, UINT16 flags
)
985 CONV_RECT16TO32( rectUpdate
, &r
);
986 return (BOOL16
)RedrawWindow( (HWND
)hwnd
, &r
, hrgnUpdate
, flags
);
988 return (BOOL16
)PAINT_RedrawWindow( (HWND
)hwnd
, NULL
,
989 (HRGN
)hrgnUpdate
, flags
, 0 );
993 /***********************************************************************
994 * UpdateWindow16 (USER.124)
996 void WINAPI
UpdateWindow16( HWND16 hwnd
)
998 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_NOCHILDREN
, 0 );
1001 /***********************************************************************
1002 * UpdateWindow32 (USER32.567)
1004 void WINAPI
UpdateWindow( HWND hwnd
)
1006 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_NOCHILDREN
, 0 );
1009 /***********************************************************************
1010 * InvalidateRgn16 (USER.126)
1012 void WINAPI
InvalidateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1014 PAINT_RedrawWindow((HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1015 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1019 /***********************************************************************
1020 * InvalidateRgn32 (USER32.329)
1022 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1024 return PAINT_RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1028 /***********************************************************************
1029 * InvalidateRect16 (USER.125)
1031 void WINAPI
InvalidateRect16( HWND16 hwnd
, const RECT16
*rect
, BOOL16 erase
)
1033 RedrawWindow16( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
1037 /***********************************************************************
1038 * InvalidateRect32 (USER32.328)
1040 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
1042 return PAINT_RedrawWindow( hwnd
, rect
, 0,
1043 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1047 /***********************************************************************
1048 * ValidateRgn16 (USER.128)
1050 void WINAPI
ValidateRgn16( HWND16 hwnd
, HRGN16 hrgn
)
1052 PAINT_RedrawWindow( (HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1053 RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1057 /***********************************************************************
1058 * ValidateRgn32 (USER32.572)
1060 void WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
1062 PAINT_RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1066 /***********************************************************************
1067 * ValidateRect16 (USER.127)
1069 void WINAPI
ValidateRect16( HWND16 hwnd
, const RECT16
*rect
)
1071 RedrawWindow16( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
1075 /***********************************************************************
1076 * ValidateRect32 (USER32.571)
1078 void WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
1080 PAINT_RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1084 /***********************************************************************
1085 * GetUpdateRect16 (USER.190)
1087 BOOL16 WINAPI
GetUpdateRect16( HWND16 hwnd
, LPRECT16 rect
, BOOL16 erase
)
1092 if (!rect
) return GetUpdateRect( hwnd
, NULL
, erase
);
1093 ret
= GetUpdateRect( hwnd
, &r
, erase
);
1094 CONV_RECT32TO16( &r
, rect
);
1099 /***********************************************************************
1100 * GetUpdateRect32 (USER32.297)
1102 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
1105 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1106 if (!wndPtr
) return FALSE
;
1110 if (wndPtr
->hrgnUpdate
> 1)
1112 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
1113 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
1118 GetRgnBox( hrgn
, rect
);
1119 DeleteObject( hrgn
);
1120 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
1122 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
1124 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
1129 if( wndPtr
->hrgnUpdate
== 1 )
1131 GetClientRect( hwnd
, rect
);
1132 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
1135 SetRectEmpty( rect
);
1137 retvalue
= (wndPtr
->hrgnUpdate
>= 1);
1139 WIN_ReleaseWndPtr(wndPtr
);
1144 /***********************************************************************
1145 * GetUpdateRgn16 (USER.237)
1147 INT16 WINAPI
GetUpdateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1149 return GetUpdateRgn( hwnd
, hrgn
, erase
);
1153 /***********************************************************************
1154 * GetUpdateRgn (USER32.298)
1156 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1159 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1160 if (!wndPtr
) return ERROR
;
1162 if (wndPtr
->hrgnUpdate
== 0)
1164 SetRectRgn( hrgn
, 0, 0, 0, 0 );
1165 retval
= NULLREGION
;
1169 if (wndPtr
->hrgnUpdate
== 1)
1171 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
1172 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
1173 retval
= SIMPLEREGION
;
1177 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1178 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1179 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1181 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
1183 WIN_ReleaseWndPtr(wndPtr
);
1188 /***********************************************************************
1189 * ExcludeUpdateRgn16 (USER.238)
1191 INT16 WINAPI
ExcludeUpdateRgn16( HDC16 hdc
, HWND16 hwnd
)
1193 return ExcludeUpdateRgn( hdc
, hwnd
);
1197 /***********************************************************************
1198 * ExcludeUpdateRgn32 (USER32.195)
1200 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1205 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
1207 if (wndPtr
->hrgnUpdate
)
1210 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1211 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
1212 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
1213 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
1214 if( wndPtr
->hrgnUpdate
> 1 )
1216 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1217 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1218 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1221 /* do ugly coordinate translations in dce.c */
1223 ret
= DCE_ExcludeRgn( hdc
, wndPtr
, hrgn
);
1224 DeleteObject( hrgn
);
1225 WIN_ReleaseWndPtr(wndPtr
);
1228 WIN_ReleaseWndPtr(wndPtr
);
1229 return GetClipBox( hdc
, &rect
);
1234 /***********************************************************************
1235 * FillRect16 (USER.81)
1237 * The Win16 variant doesn't support special color brushes like
1238 * the Win32 one, despite the fact that Win16, as well as Win32,
1239 * supports special background brushes for a window class.
1241 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
1245 /* coordinates are logical so we cannot fast-check 'rect',
1246 * it will be done later in the PatBlt().
1249 if (!(prevBrush
= SelectObject16( hdc
, hbrush
))) return 0;
1250 PatBlt( hdc
, rect
->left
, rect
->top
,
1251 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1252 SelectObject16( hdc
, prevBrush
);
1257 /***********************************************************************
1258 * FillRect (USER32.197)
1260 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1264 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1265 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1268 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1269 PatBlt( hdc
, rect
->left
, rect
->top
,
1270 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1271 SelectObject( hdc
, prevBrush
);
1276 /***********************************************************************
1277 * InvertRect16 (USER.82)
1279 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1281 PatBlt( hdc
, rect
->left
, rect
->top
,
1282 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1286 /***********************************************************************
1287 * InvertRect (USER32.330)
1289 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1291 return PatBlt( hdc
, rect
->left
, rect
->top
,
1292 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1297 /***********************************************************************
1298 * FrameRect (USER32.203)
1300 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1305 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1306 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1308 PatBlt( hdc
, r
.left
, r
.top
, 1,
1309 r
.bottom
- r
.top
, PATCOPY
);
1310 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1311 r
.bottom
- r
.top
, PATCOPY
);
1312 PatBlt( hdc
, r
.left
, r
.top
,
1313 r
.right
- r
.left
, 1, PATCOPY
);
1314 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1315 r
.right
- r
.left
, 1, PATCOPY
);
1317 SelectObject( hdc
, prevBrush
);
1322 /***********************************************************************
1323 * FrameRect16 (USER.83)
1325 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1328 CONV_RECT16TO32( rect16
, &rect
);
1329 return FrameRect( hdc
, &rect
, hbrush
);
1333 /***********************************************************************
1334 * DrawFocusRect16 (USER.466)
1336 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1339 CONV_RECT16TO32( rc
, &rect32
);
1340 DrawFocusRect( hdc
, &rect32
);
1344 /***********************************************************************
1345 * DrawFocusRect (USER32.156)
1347 * FIXME: PatBlt(PATINVERT) with background brush.
1349 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1352 HPEN hOldPen
, hNewPen
;
1353 INT oldDrawMode
, oldBkMode
;
1355 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1356 hNewPen
= CreatePen(PS_DOT
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1357 hOldPen
= SelectObject(hdc
, hNewPen
);
1358 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1359 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1361 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1363 SetBkMode(hdc
, oldBkMode
);
1364 SetROP2(hdc
, oldDrawMode
);
1365 SelectObject(hdc
, hOldPen
);
1366 DeleteObject(hNewPen
);
1367 SelectObject(hdc
, hOldBrush
);
1372 /**********************************************************************
1373 * DrawAnimatedRects16 (USER.448)
1375 BOOL16 WINAPI
DrawAnimatedRects16( HWND16 hwnd
, INT16 idAni
,
1376 const RECT16
* lprcFrom
,
1377 const RECT16
* lprcTo
)
1379 RECT rcFrom32
, rcTo32
;
1381 rcFrom32
.left
= (INT
)lprcFrom
->left
;
1382 rcFrom32
.top
= (INT
)lprcFrom
->top
;
1383 rcFrom32
.right
= (INT
)lprcFrom
->right
;
1384 rcFrom32
.bottom
= (INT
)lprcFrom
->bottom
;
1386 rcTo32
.left
= (INT
)lprcTo
->left
;
1387 rcTo32
.top
= (INT
)lprcTo
->top
;
1388 rcTo32
.right
= (INT
)lprcTo
->right
;
1389 rcTo32
.bottom
= (INT
)lprcTo
->bottom
;
1391 return DrawAnimatedRects((HWND
)hwnd
, (INT
)idAni
, &rcFrom32
, &rcTo32
);
1395 /**********************************************************************
1396 * DrawAnimatedRects (USER32.153)
1398 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1399 const RECT
* lprcFrom
,
1400 const RECT
* lprcTo
)
1402 FIXME_(win
)("(0x%x,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1407 /**********************************************************************
1408 * PAINTING_DrawStateJam
1410 * Jams in the requested type in the dc
1412 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1413 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1414 LPRECT rc
, UINT dtflags
,
1415 BOOL unicode
, BOOL _32bit
)
1420 INT cx
= rc
->right
- rc
->left
;
1421 INT cy
= rc
->bottom
- rc
->top
;
1426 case DST_PREFIXTEXT
:
1428 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1430 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1432 return DrawTextA(hdc
, (LPSTR
)PTR_SEG_TO_LIN(lp
), (INT
)wp
, rc
, dtflags
);
1435 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1438 memdc
= CreateCompatibleDC(hdc
);
1439 if(!memdc
) return FALSE
;
1440 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1446 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1447 SelectObject(memdc
, hbmsave
);
1454 return func(hdc
, lp
, wp
, cx
, cy
);
1456 return (BOOL
)((DRAWSTATEPROC16
)func
)((HDC16
)hdc
, (LPARAM
)lp
, (WPARAM16
)wp
, (INT16
)cx
, (INT16
)cy
);
1463 /**********************************************************************
1464 * PAINTING_DrawState()
1466 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
,
1467 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1468 INT x
, INT y
, INT cx
, INT cy
,
1469 UINT flags
, BOOL unicode
, BOOL _32bit
)
1471 HBITMAP hbm
, hbmsave
;
1476 UINT dtflags
= DT_NOCLIP
;
1478 UINT opcode
= flags
& 0xf;
1482 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1485 len
= lstrlenW((LPWSTR
)lp
);
1487 len
= lstrlenA((LPSTR
)lp
);
1489 len
= lstrlenA((LPSTR
)PTR_SEG_TO_LIN(lp
));
1492 /* Find out what size the image has if not given by caller */
1496 CURSORICONINFO
*ici
;
1502 case DST_PREFIXTEXT
:
1504 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1506 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1508 retval
= GetTextExtentPoint32A(hdc
, PTR_SEG_TO_LIN(lp
), len
, &s
);
1509 if(!retval
) return FALSE
;
1513 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1514 if(!ici
) return FALSE
;
1516 s
.cy
= ici
->nHeight
;
1517 GlobalUnlock16((HGLOBAL16
)lp
);
1521 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1527 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1540 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1541 dtflags
|= DT_RIGHT
;
1542 if(opcode
== DST_TEXT
)
1543 dtflags
|= DT_NOPREFIX
;
1545 /* For DSS_NORMAL we just jam in the image and return */
1546 if((flags
& 0x7ff0) == DSS_NORMAL
)
1548 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1551 /* For all other states we need to convert the image to B/W in a local bitmap */
1552 /* before it is displayed */
1553 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1554 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1555 hbm
= (HBITMAP
)NULL
; hbmsave
= (HBITMAP
)NULL
;
1556 memdc
= (HDC
)NULL
; hbsave
= (HBRUSH
)NULL
;
1557 retval
= FALSE
; /* assume failure */
1559 /* From here on we must use "goto cleanup" when something goes wrong */
1560 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1561 if(!hbm
) goto cleanup
;
1562 memdc
= CreateCompatibleDC(hdc
);
1563 if(!memdc
) goto cleanup
;
1564 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1565 if(!hbmsave
) goto cleanup
;
1566 rc
.left
= rc
.top
= 0;
1569 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1570 SetBkColor(memdc
, RGB(255, 255, 255));
1571 SetTextColor(memdc
, RGB(0, 0, 0));
1572 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1573 if(!hfsave
&& (opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
)) goto cleanup
;
1574 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1575 if(hfsave
) SelectObject(memdc
, hfsave
);
1576 if(!tmp
) goto cleanup
;
1578 /* These states cause the image to be dithered */
1579 if(flags
& (DSS_UNION
|DSS_DISABLED
))
1581 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1582 if(!hbsave
) goto cleanup
;
1583 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1584 if(hbsave
) SelectObject(memdc
, hbsave
);
1585 if(!tmp
) goto cleanup
;
1588 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
? hbr
: GetStockObject(WHITE_BRUSH
));
1589 if(!hbsave
) goto cleanup
;
1591 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1593 /* DSS_DEFAULT makes the image boldface */
1594 if(flags
& DSS_DEFAULT
)
1596 if(!BitBlt(hdc
, x
+1, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1599 retval
= TRUE
; /* We succeeded */
1602 SetTextColor(hdc
, fg
);
1603 SetBkColor(hdc
, bg
);
1605 if(hbsave
) SelectObject(hdc
, hbsave
);
1606 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1607 if(hbm
) DeleteObject(hbm
);
1608 if(memdc
) DeleteDC(memdc
);
1613 /**********************************************************************
1614 * DrawStateA() (USER32.162)
1616 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1617 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1618 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1620 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, TRUE
);
1623 /**********************************************************************
1624 * DrawStateW() (USER32.163)
1626 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1627 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1628 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1630 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
, TRUE
);
1633 /**********************************************************************
1634 * DrawState16() (USER.449)
1636 BOOL16 WINAPI
DrawState16(HDC16 hdc
, HBRUSH16 hbr
,
1637 DRAWSTATEPROC16 func
, LPARAM ldata
, WPARAM16 wdata
,
1638 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, UINT16 flags
)
1640 return PAINTING_DrawState(hdc
, hbr
, (DRAWSTATEPROC
)func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, FALSE
);