2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
10 #include "wine/winuser16.h"
11 #include "wine/unicode.h"
17 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(win
);
21 DECLARE_DEBUG_CHANNEL(nonclient
);
23 /* client rect in window coordinates */
25 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
26 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
27 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
28 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
31 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
33 /* Last CTLCOLOR id */
34 #define CTLCOLOR_MAX CTLCOLOR_STATIC
37 /***********************************************************************
38 * WIN_HaveToDelayNCPAINT
40 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
41 * is generated as soon as a region intersecting the non-client area
42 * of a window is invalidated.
44 * This technique will work fine for all windows whose parents
45 * have the WS_CLIPCHILDREN style. When the parents have that style,
46 * they are not going to override the contents of their children.
47 * However, when the parent doesn't have that style, Windows relies
48 * on a "painter's algorithm" to display the contents of the windows.
49 * That is, windows are painted from back to front. This includes the
52 * This method looks at the current state of a window to determine
53 * if the sending of the WM_NCPAINT message should be delayed until
54 * the BeginPaint call.
57 * wndPtr - A Locked window pointer to the window we're
59 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
60 * function. This is a shortcut for the cases when
61 * we already know when to avoid scanning all the
62 * parents of a window. If you already know that this
63 * window's NCPAINT should be delayed, set the
64 * UNC_DELAY_NCPAINT flag for this parameter.
66 * This shortcut behavior is implemented in the
70 static BOOL
WIN_HaveToDelayNCPAINT(
74 WND
* parentWnd
= NULL
;
77 * Test the shortcut first. (duh)
79 if (uncFlags
& UNC_DELAY_NCPAINT
)
83 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
84 * method only. This is another shortcut to avoid going
85 * up the parent's chain of the window to finally
86 * figure-out that none of them has an invalid region.
88 if (uncFlags
& UNC_IN_BEGINPAINT
)
92 * Scan all the parents of this window to find a window
93 * that doesn't have the WS_CLIPCHILDREN style and that
94 * has an invalid region.
96 parentWnd
= WIN_LockWndPtr(wndPtr
->parent
);
98 while (parentWnd
!=NULL
)
100 if ( ((parentWnd
->dwStyle
& WS_CLIPCHILDREN
) == 0) &&
101 (parentWnd
->hrgnUpdate
!= 0) )
103 WIN_ReleaseWndPtr(parentWnd
);
107 WIN_UpdateWndPtr(&parentWnd
, parentWnd
->parent
);
110 WIN_ReleaseWndPtr(parentWnd
);
115 /***********************************************************************
119 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
120 * Crop hrgnUpdate to a client rect, especially if it 1.
121 * If UNC_REGION is set return update region for the client rect.
123 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
124 * The trick is that when the returned region handle may be different from hRgn.
125 * In this case the old hRgn must be considered gone. BUT, if the returned value
126 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
127 * a DC without extra clipping region.
129 HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
135 TRACE_(nonclient
)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
136 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
138 /* desktop window doesn't have a nonclient area */
139 if(wnd
== WIN_GetDesktop())
141 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
142 if( wnd
->hrgnUpdate
> 1 )
143 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
146 hrgnRet
= wnd
->hrgnUpdate
;
148 WIN_ReleaseDesktop();
151 WIN_ReleaseDesktop();
153 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
154 !(wnd
->flags
& WIN_NCACTIVATED
) )
156 wnd
->flags
|= WIN_NCACTIVATED
;
157 uncFlags
|= UNC_ENTIRE
;
161 * If the window's non-client area needs to be painted,
163 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
164 !WIN_HaveToDelayNCPAINT(wnd
, uncFlags
) )
168 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
169 GETCLIENTRECTW( wnd
, r
);
171 TRACE_(nonclient
)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
172 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
173 if( wnd
->hrgnUpdate
> 1 )
175 /* Check if update rgn overlaps with nonclient area */
177 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
178 UnionRect( &r3
, &r2
, &r
);
179 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
180 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
182 /* crop hrgnUpdate, save old one in hClip - the only
183 * case that places a valid region handle in hClip */
185 hClip
= wnd
->hrgnUpdate
;
186 wnd
->hrgnUpdate
= REGION_CropRgn( hRgn
, hClip
, &r
, NULL
);
187 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
190 if( uncFlags
& UNC_CHECK
)
192 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
193 if( IsRectEmpty( &r3
) )
195 /* delete the update region since all invalid
196 * parts were in the nonclient area */
198 DeleteObject( wnd
->hrgnUpdate
);
200 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
201 QUEUE_DecPaintCount( wnd
->hmemTaskQ
);
203 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
207 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
210 if( wnd
->hrgnUpdate
== 1 )/* entire window */
212 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
213 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
214 uncFlags
|= UNC_ENTIRE
;
217 else /* no WM_NCPAINT unless forced */
219 if( wnd
->hrgnUpdate
> 1 )
222 if( uncFlags
& UNC_REGION
)
223 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
226 if( wnd
->hrgnUpdate
== 1 && (uncFlags
& UNC_UPDATE
) )
228 GETCLIENTRECTW( wnd
, r
);
229 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
230 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
234 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
236 /* still don't do anything if there is no nonclient area */
237 hClip
= (memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
240 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
242 if ( hClip
== hrgnRet
&& hrgnRet
> 1 ) {
243 hClip
= CreateRectRgn( 0, 0, 0, 0 );
244 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
247 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, hClip
, 0L );
248 if( (hClip
> 1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
249 DeleteObject( hClip
);
251 * Since all Window locks are suspended while processing the WM_NCPAINT
252 * we want to make sure the window still exists before continuing.
254 if (!IsWindow(wnd
->hwndSelf
))
256 DeleteObject(hrgnRet
);
261 TRACE_(nonclient
)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
267 /***********************************************************************
268 * BeginPaint16 (USER.39)
270 HDC16 WINAPI
BeginPaint16( HWND16 hwnd
, LPPAINTSTRUCT16 lps
)
274 BeginPaint( hwnd
, &ps
);
276 lps
->fErase
= ps
.fErase
;
277 lps
->rcPaint
.top
= ps
.rcPaint
.top
;
278 lps
->rcPaint
.left
= ps
.rcPaint
.left
;
279 lps
->rcPaint
.right
= ps
.rcPaint
.right
;
280 lps
->rcPaint
.bottom
= ps
.rcPaint
.bottom
;
281 lps
->fRestore
= ps
.fRestore
;
282 lps
->fIncUpdate
= ps
.fIncUpdate
;
287 /***********************************************************************
288 * BeginPaint (USER32.10)
290 HDC WINAPI
BeginPaint( HWND hwnd
, PAINTSTRUCT
*lps
)
294 RECT clipRect
, clientRect
;
295 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
296 if (!wndPtr
) return 0;
298 bIcon
= (wndPtr
->dwStyle
& WS_MINIMIZE
&& GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
300 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
302 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
303 WIN_UpdateNCRgn( wndPtr
, 0, UNC_UPDATE
| UNC_IN_BEGINPAINT
);
306 * Make sure the window is still a window. All window locks are suspended
307 * when the WM_NCPAINT is sent.
309 if (!IsWindow(wndPtr
->hwndSelf
))
311 WIN_ReleaseWndPtr(wndPtr
);
315 if( ((hrgnUpdate
= wndPtr
->hrgnUpdate
) != 0) || (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
316 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
318 wndPtr
->hrgnUpdate
= 0;
319 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
323 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate
);
325 if (GetClassWord16(wndPtr
->hwndSelf
, GCW_STYLE
) & CS_PARENTDC
)
327 /* Don't clip the output to the update region for CS_PARENTDC window */
329 DeleteObject(hrgnUpdate
);
330 lps
->hdc
= GetDCEx( hwnd
, 0, DCX_WINDOWPAINT
| DCX_USESTYLE
|
331 (bIcon
? DCX_WINDOW
: 0) );
335 if( hrgnUpdate
) /* convert to client coordinates */
336 OffsetRgn( hrgnUpdate
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
337 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
338 lps
->hdc
= GetDCEx(hwnd
, hrgnUpdate
, DCX_INTERSECTRGN
|
339 DCX_WINDOWPAINT
| DCX_USESTYLE
| (bIcon
? DCX_WINDOW
: 0) );
340 /* ReleaseDC() in EndPaint() will delete the region */
343 TRACE("hdc = %04x\n", lps
->hdc
);
347 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd
);
348 WIN_ReleaseWndPtr(wndPtr
);
352 /* It is possible that the clip box is bigger than the window itself,
353 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
354 than the window itself, so we need to intersect the cliprect with
357 GetClipBox( lps
->hdc
, &clipRect
);
358 GetClientRect( hwnd
, &clientRect
);
360 /* The rect obtained by GetClipBox is in logical, so make the client in logical to*/
361 DPtoLP(lps
->hdc
, (LPPOINT
)&clientRect
, 2);
363 IntersectRect(&lps
->rcPaint
, &clientRect
, &clipRect
);
365 TRACE("box = (%i,%i - %i,%i)\n", lps
->rcPaint
.left
, lps
->rcPaint
.top
,
366 lps
->rcPaint
.right
, lps
->rcPaint
.bottom
);
368 if (wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
370 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
371 lps
->fErase
= !SendMessageA(hwnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
372 (WPARAM16
)lps
->hdc
, 0 );
374 else lps
->fErase
= TRUE
;
376 WIN_ReleaseWndPtr(wndPtr
);
381 /***********************************************************************
382 * EndPaint16 (USER.40)
384 BOOL16 WINAPI
EndPaint16( HWND16 hwnd
, const PAINTSTRUCT16
* lps
)
386 ReleaseDC16( hwnd
, lps
->hdc
);
392 /***********************************************************************
393 * EndPaint (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
)
410 GetClientRect( hwnd
, &rect
);
411 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
412 CONV_RECT32TO16( &rect
, &rc16
);
413 PaintRect16( hwndParent
, hwnd
, hdc
, hbrush
, &rc16
);
417 /***********************************************************************
418 * PAINT_GetControlBrush
420 static HBRUSH16
PAINT_GetControlBrush( HWND hParent
, HWND hWnd
, HDC16 hDC
, UINT16 ctlType
)
422 HBRUSH16 bkgBrush
= (HBRUSH16
)SendMessageA( hParent
, WM_CTLCOLORMSGBOX
+ ctlType
,
423 (WPARAM
)hDC
, (LPARAM
)hWnd
);
424 if( !IsGDIObject16(bkgBrush
) )
425 bkgBrush
= DEFWND_ControlColor( hDC
, ctlType
);
430 /***********************************************************************
431 * PaintRect (USER.325)
433 void WINAPI
PaintRect16( HWND16 hwndParent
, HWND16 hwnd
, HDC16 hdc
,
434 HBRUSH16 hbrush
, const RECT16
*rect
)
436 if( hbrush
<= CTLCOLOR_MAX
)
439 hbrush
= PAINT_GetControlBrush( hwndParent
, hwnd
, hdc
, (UINT16
)hbrush
);
444 FillRect16( hdc
, rect
, hbrush
);
448 /***********************************************************************
449 * GetControlBrush (USER.326)
451 HBRUSH16 WINAPI
GetControlBrush16( HWND16 hwnd
, HDC16 hdc
, UINT16 ctlType
)
453 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
456 if((ctlType
<= CTLCOLOR_MAX
) && wndPtr
)
459 if( wndPtr
->dwStyle
& WS_POPUP
) parent
= WIN_LockWndPtr(wndPtr
->owner
);
460 else parent
= WIN_LockWndPtr(wndPtr
->parent
);
461 if( !parent
) parent
= wndPtr
;
462 retvalue
= (HBRUSH16
)PAINT_GetControlBrush( parent
->hwndSelf
, hwnd
, hdc
, ctlType
);
463 WIN_ReleaseWndPtr(parent
);
466 retvalue
= (HBRUSH16
)0;
468 WIN_ReleaseWndPtr(wndPtr
);
473 /***********************************************************************
474 * RDW_ValidateParent [RDW_UpdateRgns() helper]
476 * Validate the portions of parents that are covered by a validated child
479 void RDW_ValidateParent(WND
*wndChild
)
481 WND
*wndParent
= WIN_LockWndPtr(wndChild
->parent
);
482 WND
*wndDesktop
= WIN_GetDesktop();
485 if (wndChild
->hrgnUpdate
== 1 ) {
489 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
490 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
491 hrg
= CreateRectRgnIndirect( &r
);
493 hrg
= wndChild
->hrgnUpdate
;
495 while ((wndParent
) && (wndParent
!= wndDesktop
) ) {
496 if (!(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
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
);
523 WIN_UpdateWndPtr(&wndParent
, wndParent
->parent
);
525 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
526 WIN_ReleaseWndPtr(wndParent
);
527 WIN_ReleaseDesktop();
530 /***********************************************************************
531 * RDW_UpdateRgns [RedrawWindow() helper]
533 * Walks the window tree and adds/removes parts of the hRgn to/from update
534 * regions of windows that overlap it. Also, manages internal paint flags.
536 * NOTE: Walks the window tree so the caller must lock it.
537 * MUST preserve hRgn (can modify but then has to restore).
539 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
542 * Called only when one of the following is set:
543 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
546 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
547 BOOL bChildren
= ( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
548 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
553 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
554 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
556 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
558 if( flags
& RDW_INVALIDATE
)
562 switch( wndPtr
->hrgnUpdate
)
565 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
568 wndPtr
->hrgnUpdate
= REGION_CropRgn( wndPtr
->hrgnUpdate
,
569 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
573 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
574 if( IsRectEmpty( &r
) )
576 DeleteObject( wndPtr
->hrgnUpdate
);
577 wndPtr
->hrgnUpdate
= 0;
582 case 1: /* already an entire window */
588 if( wndPtr
->hrgnUpdate
> 1 )
589 DeleteObject( wndPtr
->hrgnUpdate
);
590 wndPtr
->hrgnUpdate
= 1;
593 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
595 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
596 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
598 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
599 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
602 else if( flags
& RDW_VALIDATE
)
604 if( wndPtr
->hrgnUpdate
)
608 if( wndPtr
->hrgnUpdate
== 1 )
609 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
611 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
615 else /* validate everything */
617 if( wndPtr
->hrgnUpdate
> 1 )
620 DeleteObject( wndPtr
->hrgnUpdate
);
622 wndPtr
->hrgnUpdate
= 0;
625 if( !wndPtr
->hrgnUpdate
)
627 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
628 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
629 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
633 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
634 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
638 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
639 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
641 /* in/validate child windows that intersect with the region if it
642 * is a valid handle. */
644 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
646 if( hRgn
> 1 && bChildren
)
648 WND
* wnd
= wndPtr
->child
;
649 POINT ptTotal
, prevOrigin
= {0,0};
652 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
653 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
655 for( ptTotal
.x
= ptTotal
.y
= 0; wnd
; wnd
= wnd
->next
)
657 if( wnd
->dwStyle
& WS_VISIBLE
)
661 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
662 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
663 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
664 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
666 ptOffset
.x
= r
.left
- prevOrigin
.x
;
667 ptOffset
.y
= r
.top
- prevOrigin
.y
;
668 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
670 if( RectInRegion( hRgn
, &r
) )
672 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
673 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
674 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
675 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
676 ptTotal
.x
+= ptOffset
.x
;
677 ptTotal
.y
+= ptOffset
.y
;
681 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
686 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
691 for( wnd
= wndPtr
->child
; wnd
; wnd
= wnd
->next
)
692 if( wnd
->dwStyle
& WS_VISIBLE
)
693 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
698 /* Set/clear internal paint flag */
700 if (flags
& RDW_INTERNALPAINT
)
702 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
703 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
704 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
706 else if (flags
& RDW_NOINTERNALPAINT
)
708 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
709 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
710 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
714 /***********************************************************************
715 * RDW_Paint [RedrawWindow() helper]
717 * Walks the window tree and paints/erases windows that have
718 * nonzero update regions according to redraw flags. hrgn is a scratch
719 * region passed down during recursion. Must not be 1.
722 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
724 /* NOTE: wndPtr is locked by caller.
726 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
727 * SendMessage() calls. This is a comment inside DefWindowProc() source
730 * This message avoids lots of inter-app message traffic
731 * by switching to the other task and continuing the
735 * LOWORD(lParam) = hrgnClip
736 * HIWORD(lParam) = hwndSkip (not used; always NULL)
740 HWND hWnd
= wndPtr
->hwndSelf
;
741 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
743 /* Erase/update the window itself ... */
745 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
748 * Check if this window should delay it's processing of WM_NCPAINT.
749 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
751 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
, 0) )
752 ex
|= RDW_EX_DELAY_NCPAINT
;
754 if (flags
& RDW_UPDATENOW
)
756 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
757 SendMessage16( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
759 else if ((flags
& RDW_ERASENOW
) || (ex
& RDW_EX_TOPFRAME
))
761 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
764 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
766 UNC_REGION
| UNC_CHECK
|
767 ((ex
& RDW_EX_TOPFRAME
) ? UNC_ENTIRE
: 0) |
768 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
772 if( hrgnRet
> 1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
773 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
775 if( bIcon
) dcx
|= DCX_WINDOW
;
778 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
779 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
781 dcx
&= ~DCX_INTERSECTRGN
;
782 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
784 if (SendMessage16( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
785 : WM_ERASEBKGND
, (WPARAM16
)hDC
, 0 ))
786 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
787 ReleaseDC( hWnd
, hDC
);
793 if( !IsWindow(hWnd
) ) return hrgn
;
794 ex
&= ~RDW_EX_TOPFRAME
;
796 /* ... and its child windows */
798 if( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
799 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
803 if( (list
= WIN_BuildWinArray( wndPtr
, 0, NULL
)) )
806 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
808 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
809 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
810 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
811 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
812 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
814 WIN_ReleaseWndPtr(wndPtr
);
815 WIN_ReleaseWinArray(list
);
822 /***********************************************************************
826 BOOL
PAINT_RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
827 HRGN hrgnUpdate
, UINT flags
, UINT ex
)
834 if (!hwnd
) hwnd
= GetDesktopWindow();
835 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
837 /* check if the window or its parents are visible/not minimized */
839 if (!WIN_IsWindowDrawable( wndPtr
, !(flags
& RDW_FRAME
) ) )
841 WIN_ReleaseWndPtr(wndPtr
);
849 GetRgnBox( hrgnUpdate
, &r
);
850 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
851 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
, ex
);
859 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
860 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
861 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
, ex
);
865 /* prepare an update region in window coordinates */
867 if( flags
& RDW_FRAME
)
868 r
= wndPtr
->rectWindow
;
870 r
= wndPtr
->rectClient
;
872 if( ex
& RDW_EX_XYWINDOW
)
875 OffsetRect( &r
, -wndPtr
->rectWindow
.left
, -wndPtr
->rectWindow
.top
);
879 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
880 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
881 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
884 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
886 /* If the window doesn't have hrgnUpdate we leave hRgn zero
887 * and put a new region straight into wndPtr->hrgnUpdate
888 * so that RDW_UpdateRgns() won't have to do any extra work.
893 if( wndPtr
->hrgnUpdate
)
894 hRgn
= REGION_CropRgn( 0, hrgnUpdate
, NULL
, &pt
);
896 wndPtr
->hrgnUpdate
= REGION_CropRgn( 0, hrgnUpdate
, &r
, &pt
);
898 else if( rectUpdate
)
900 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
901 OffsetRect( &r2
, pt
.x
, pt
.y
);
904 if( wndPtr
->hrgnUpdate
== 0 )
905 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
907 hRgn
= CreateRectRgnIndirect( &r2
);
909 else /* entire window or client depending on RDW_FRAME */
911 if( flags
& RDW_FRAME
)
913 if( wndPtr
->hrgnUpdate
)
914 DeleteObject( wndPtr
->hrgnUpdate
);
915 wndPtr
->hrgnUpdate
= 1;
919 GETCLIENTRECTW( wndPtr
, r2
);
924 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
926 /* In this we cannot leave with zero hRgn */
929 hRgn
= REGION_CropRgn( hRgn
, hrgnUpdate
, &r
, &pt
);
930 GetRgnBox( hRgn
, &r2
);
931 if( IsRectEmpty( &r2
) ) goto END
;
933 else if( rectUpdate
)
935 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
936 OffsetRect( &r2
, pt
.x
, pt
.y
);
938 hRgn
= CreateRectRgnIndirect( &r2
);
940 else /* entire window or client depending on RDW_FRAME */
942 if( flags
& RDW_FRAME
)
946 GETCLIENTRECTW( wndPtr
, r2
);
952 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
954 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
956 /* Erase/update windows, from now on hRgn is a scratch region */
958 hRgn
= RDW_Paint( wndPtr
, (hRgn
== 1) ? 0 : hRgn
, flags
, ex
);
961 if( hRgn
> 1 && (hRgn
!= hrgnUpdate
) )
963 WIN_ReleaseWndPtr(wndPtr
);
968 /***********************************************************************
969 * RedrawWindow (USER32.426)
971 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
972 HRGN hrgnUpdate
, UINT flags
)
974 return PAINT_RedrawWindow( hwnd
, rectUpdate
, hrgnUpdate
, flags
, 0 );
978 /***********************************************************************
979 * RedrawWindow16 (USER.290)
981 BOOL16 WINAPI
RedrawWindow16( HWND16 hwnd
, const RECT16
*rectUpdate
,
982 HRGN16 hrgnUpdate
, UINT16 flags
)
987 CONV_RECT16TO32( rectUpdate
, &r
);
988 return (BOOL16
)RedrawWindow( (HWND
)hwnd
, &r
, hrgnUpdate
, flags
);
990 return (BOOL16
)PAINT_RedrawWindow( (HWND
)hwnd
, NULL
,
991 (HRGN
)hrgnUpdate
, flags
, 0 );
995 /***********************************************************************
996 * UpdateWindow16 (USER.124)
998 void WINAPI
UpdateWindow16( HWND16 hwnd
)
1000 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
, 0 );
1003 /***********************************************************************
1004 * UpdateWindow (USER32.567)
1006 void WINAPI
UpdateWindow( HWND hwnd
)
1008 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
, 0 );
1011 /***********************************************************************
1012 * InvalidateRgn16 (USER.126)
1014 void WINAPI
InvalidateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1016 PAINT_RedrawWindow((HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1017 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1021 /***********************************************************************
1022 * InvalidateRgn (USER32.329)
1024 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1026 return PAINT_RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1030 /***********************************************************************
1031 * InvalidateRect16 (USER.125)
1033 void WINAPI
InvalidateRect16( HWND16 hwnd
, const RECT16
*rect
, BOOL16 erase
)
1035 RedrawWindow16( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
1039 /***********************************************************************
1040 * InvalidateRect (USER32.328)
1042 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
1044 return PAINT_RedrawWindow( hwnd
, rect
, 0,
1045 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1049 /***********************************************************************
1050 * ValidateRgn16 (USER.128)
1052 void WINAPI
ValidateRgn16( HWND16 hwnd
, HRGN16 hrgn
)
1054 PAINT_RedrawWindow( (HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1055 RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1059 /***********************************************************************
1060 * ValidateRgn (USER32.572)
1062 void WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
1064 PAINT_RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1068 /***********************************************************************
1069 * ValidateRect16 (USER.127)
1071 void WINAPI
ValidateRect16( HWND16 hwnd
, const RECT16
*rect
)
1073 RedrawWindow16( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
1077 /***********************************************************************
1078 * ValidateRect (USER32.571)
1080 void WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
1082 PAINT_RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1086 /***********************************************************************
1087 * GetUpdateRect16 (USER.190)
1089 BOOL16 WINAPI
GetUpdateRect16( HWND16 hwnd
, LPRECT16 rect
, BOOL16 erase
)
1094 if (!rect
) return GetUpdateRect( hwnd
, NULL
, erase
);
1095 ret
= GetUpdateRect( hwnd
, &r
, erase
);
1096 CONV_RECT32TO16( &r
, rect
);
1101 /***********************************************************************
1102 * GetUpdateRect (USER32.297)
1104 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
1107 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1108 if (!wndPtr
) return FALSE
;
1112 if (wndPtr
->hrgnUpdate
> 1)
1114 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
1115 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
1120 GetRgnBox( hrgn
, rect
);
1121 DeleteObject( hrgn
);
1122 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
1124 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
1126 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
1131 if( wndPtr
->hrgnUpdate
== 1 )
1133 GetClientRect( hwnd
, rect
);
1134 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
1137 SetRectEmpty( rect
);
1139 retvalue
= (wndPtr
->hrgnUpdate
>= 1);
1141 WIN_ReleaseWndPtr(wndPtr
);
1146 /***********************************************************************
1147 * GetUpdateRgn16 (USER.237)
1149 INT16 WINAPI
GetUpdateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1151 return GetUpdateRgn( hwnd
, hrgn
, erase
);
1155 /***********************************************************************
1156 * GetUpdateRgn (USER32.298)
1158 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1161 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1162 if (!wndPtr
) return ERROR
;
1164 if (wndPtr
->hrgnUpdate
== 0)
1166 SetRectRgn( hrgn
, 0, 0, 0, 0 );
1167 retval
= NULLREGION
;
1171 if (wndPtr
->hrgnUpdate
== 1)
1173 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
1174 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
1175 retval
= SIMPLEREGION
;
1179 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1180 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1181 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1183 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
1185 WIN_ReleaseWndPtr(wndPtr
);
1190 /***********************************************************************
1191 * ExcludeUpdateRgn16 (USER.238)
1193 INT16 WINAPI
ExcludeUpdateRgn16( HDC16 hdc
, HWND16 hwnd
)
1195 return ExcludeUpdateRgn( hdc
, hwnd
);
1199 /***********************************************************************
1200 * ExcludeUpdateRgn (USER32.195)
1202 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1207 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
1209 if (wndPtr
->hrgnUpdate
)
1212 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1213 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
1214 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
1215 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
1216 if( wndPtr
->hrgnUpdate
> 1 )
1218 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1219 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1220 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1223 /* do ugly coordinate translations in dce.c */
1225 ret
= DCE_ExcludeRgn( hdc
, wndPtr
, hrgn
);
1226 DeleteObject( hrgn
);
1227 WIN_ReleaseWndPtr(wndPtr
);
1230 WIN_ReleaseWndPtr(wndPtr
);
1231 return GetClipBox( hdc
, &rect
);
1236 /***********************************************************************
1237 * FillRect16 (USER.81)
1239 * The Win16 variant doesn't support special color brushes like
1240 * the Win32 one, despite the fact that Win16, as well as Win32,
1241 * supports special background brushes for a window class.
1243 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
1247 /* coordinates are logical so we cannot fast-check 'rect',
1248 * it will be done later in the PatBlt().
1251 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1252 PatBlt( hdc
, rect
->left
, rect
->top
,
1253 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1254 SelectObject( hdc
, prevBrush
);
1259 /***********************************************************************
1260 * FillRect (USER32.197)
1262 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1266 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1267 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1270 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1271 PatBlt( hdc
, rect
->left
, rect
->top
,
1272 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1273 SelectObject( hdc
, prevBrush
);
1278 /***********************************************************************
1279 * InvertRect16 (USER.82)
1281 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1283 PatBlt( hdc
, rect
->left
, rect
->top
,
1284 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1288 /***********************************************************************
1289 * InvertRect (USER32.330)
1291 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1293 return PatBlt( hdc
, rect
->left
, rect
->top
,
1294 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1299 /***********************************************************************
1300 * FrameRect (USER32.203)
1302 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1307 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1308 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1310 PatBlt( hdc
, r
.left
, r
.top
, 1,
1311 r
.bottom
- r
.top
, PATCOPY
);
1312 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1313 r
.bottom
- r
.top
, PATCOPY
);
1314 PatBlt( hdc
, r
.left
, r
.top
,
1315 r
.right
- r
.left
, 1, PATCOPY
);
1316 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1317 r
.right
- r
.left
, 1, PATCOPY
);
1319 SelectObject( hdc
, prevBrush
);
1324 /***********************************************************************
1325 * FrameRect16 (USER.83)
1327 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1330 CONV_RECT16TO32( rect16
, &rect
);
1331 return FrameRect( hdc
, &rect
, hbrush
);
1335 /***********************************************************************
1336 * DrawFocusRect16 (USER.466)
1338 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1341 CONV_RECT16TO32( rc
, &rect32
);
1342 DrawFocusRect( hdc
, &rect32
);
1346 /***********************************************************************
1347 * DrawFocusRect (USER32.156)
1349 * FIXME: PatBlt(PATINVERT) with background brush.
1351 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1354 HPEN hOldPen
, hNewPen
;
1355 INT oldDrawMode
, oldBkMode
;
1357 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1358 hNewPen
= CreatePen(PS_DOT
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1359 hOldPen
= SelectObject(hdc
, hNewPen
);
1360 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1361 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1363 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1365 SetBkMode(hdc
, oldBkMode
);
1366 SetROP2(hdc
, oldDrawMode
);
1367 SelectObject(hdc
, hOldPen
);
1368 DeleteObject(hNewPen
);
1369 SelectObject(hdc
, hOldBrush
);
1374 /**********************************************************************
1375 * DrawAnimatedRects16 (USER.448)
1377 BOOL16 WINAPI
DrawAnimatedRects16( HWND16 hwnd
, INT16 idAni
,
1378 const RECT16
* lprcFrom
,
1379 const RECT16
* lprcTo
)
1381 RECT rcFrom32
, rcTo32
;
1383 rcFrom32
.left
= (INT
)lprcFrom
->left
;
1384 rcFrom32
.top
= (INT
)lprcFrom
->top
;
1385 rcFrom32
.right
= (INT
)lprcFrom
->right
;
1386 rcFrom32
.bottom
= (INT
)lprcFrom
->bottom
;
1388 rcTo32
.left
= (INT
)lprcTo
->left
;
1389 rcTo32
.top
= (INT
)lprcTo
->top
;
1390 rcTo32
.right
= (INT
)lprcTo
->right
;
1391 rcTo32
.bottom
= (INT
)lprcTo
->bottom
;
1393 return DrawAnimatedRects((HWND
)hwnd
, (INT
)idAni
, &rcFrom32
, &rcTo32
);
1397 /**********************************************************************
1398 * DrawAnimatedRects (USER32.153)
1400 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1401 const RECT
* lprcFrom
,
1402 const RECT
* lprcTo
)
1404 FIXME_(win
)("(0x%x,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1409 /**********************************************************************
1410 * PAINTING_DrawStateJam
1412 * Jams in the requested type in the dc
1414 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1415 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1416 LPRECT rc
, UINT dtflags
,
1417 BOOL unicode
, BOOL _32bit
)
1422 INT cx
= rc
->right
- rc
->left
;
1423 INT cy
= rc
->bottom
- rc
->top
;
1428 case DST_PREFIXTEXT
:
1430 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1432 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1434 return DrawTextA(hdc
, (LPSTR
)PTR_SEG_TO_LIN(lp
), (INT
)wp
, rc
, dtflags
);
1437 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1440 memdc
= CreateCompatibleDC(hdc
);
1441 if(!memdc
) return FALSE
;
1442 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1448 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1449 SelectObject(memdc
, hbmsave
);
1456 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1458 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1460 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1462 bRet
= (BOOL
)((DRAWSTATEPROC16
)func
)((HDC16
)hdc
, (LPARAM
)lp
, (WPARAM16
)wp
, (INT16
)cx
, (INT16
)cy
);
1463 /* Restore origin */
1464 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1472 /**********************************************************************
1473 * PAINTING_DrawState()
1475 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
,
1476 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1477 INT x
, INT y
, INT cx
, INT cy
,
1478 UINT flags
, BOOL unicode
, BOOL _32bit
)
1480 HBITMAP hbm
, hbmsave
;
1482 HBRUSH hbsave
, hbrtmp
= 0;
1485 UINT dtflags
= DT_NOCLIP
;
1487 UINT opcode
= flags
& 0xf;
1491 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1494 len
= strlenW((LPWSTR
)lp
);
1496 len
= strlen((LPSTR
)lp
);
1498 len
= strlen((LPSTR
)PTR_SEG_TO_LIN(lp
));
1501 /* Find out what size the image has if not given by caller */
1505 CURSORICONINFO
*ici
;
1511 case DST_PREFIXTEXT
:
1513 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1515 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1517 retval
= GetTextExtentPoint32A(hdc
, PTR_SEG_TO_LIN(lp
), len
, &s
);
1518 if(!retval
) return FALSE
;
1522 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1523 if(!ici
) return FALSE
;
1525 s
.cy
= ici
->nHeight
;
1526 GlobalUnlock16((HGLOBAL16
)lp
);
1530 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1536 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1549 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1550 dtflags
|= DT_RIGHT
;
1551 if(opcode
== DST_TEXT
)
1552 dtflags
|= DT_NOPREFIX
;
1554 /* For DSS_NORMAL we just jam in the image and return */
1555 if((flags
& 0x7ff0) == DSS_NORMAL
)
1557 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1560 /* For all other states we need to convert the image to B/W in a local bitmap */
1561 /* before it is displayed */
1562 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1563 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1564 hbm
= (HBITMAP
)NULL
; hbmsave
= (HBITMAP
)NULL
;
1565 memdc
= (HDC
)NULL
; hbsave
= (HBRUSH
)NULL
;
1566 retval
= FALSE
; /* assume failure */
1568 /* From here on we must use "goto cleanup" when something goes wrong */
1569 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1570 if(!hbm
) goto cleanup
;
1571 memdc
= CreateCompatibleDC(hdc
);
1572 if(!memdc
) goto cleanup
;
1573 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1574 if(!hbmsave
) goto cleanup
;
1575 rc
.left
= rc
.top
= 0;
1578 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1579 SetBkColor(memdc
, RGB(255, 255, 255));
1580 SetTextColor(memdc
, RGB(0, 0, 0));
1581 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1583 /* DST_COMPLEX may draw text as well,
1584 * so we must be sure that correct font is selected
1586 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1587 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1588 if(hfsave
) SelectObject(memdc
, hfsave
);
1589 if(!tmp
) goto cleanup
;
1591 /* This state cause the image to be dithered */
1592 if(flags
& DSS_UNION
)
1594 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1595 if(!hbsave
) goto cleanup
;
1596 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1597 SelectObject(memdc
, hbsave
);
1598 if(!tmp
) goto cleanup
;
1601 if (flags
& DSS_DISABLED
)
1602 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT
));
1603 else if (flags
& DSS_DEFAULT
)
1604 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1606 /* Draw light or dark shadow */
1607 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1609 if(!hbrtmp
) goto cleanup
;
1610 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1611 if(!hbsave
) goto cleanup
;
1612 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1613 SelectObject(hdc
, hbsave
);
1614 DeleteObject(hbrtmp
);
1618 if (flags
& DSS_DISABLED
)
1620 hbr
= hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1621 if(!hbrtmp
) goto cleanup
;
1625 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1628 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1630 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1632 retval
= TRUE
; /* We succeeded */
1635 SetTextColor(hdc
, fg
);
1636 SetBkColor(hdc
, bg
);
1638 if(hbsave
) SelectObject(hdc
, hbsave
);
1639 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1640 if(hbrtmp
) DeleteObject(hbrtmp
);
1641 if(hbm
) DeleteObject(hbm
);
1642 if(memdc
) DeleteDC(memdc
);
1647 /**********************************************************************
1648 * DrawStateA() (USER32.162)
1650 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1651 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1652 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1654 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, TRUE
);
1657 /**********************************************************************
1658 * DrawStateW() (USER32.163)
1660 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1661 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1662 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1664 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
, TRUE
);
1667 /**********************************************************************
1668 * DrawState16() (USER.449)
1670 BOOL16 WINAPI
DrawState16(HDC16 hdc
, HBRUSH16 hbr
,
1671 DRAWSTATEPROC16 func
, LPARAM ldata
, WPARAM16 wdata
,
1672 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, UINT16 flags
)
1674 return PAINTING_DrawState(hdc
, hbr
, (DRAWSTATEPROC
)func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, FALSE
);
1678 /***********************************************************************
1679 * SelectPalette16 (USER.282)
1681 HPALETTE16 WINAPI
SelectPalette16( HDC16 hDC
, HPALETTE16 hPal
,
1682 BOOL16 bForceBackground
)
1684 return SelectPalette( hDC
, hPal
, bForceBackground
);
1688 /***********************************************************************
1689 * RealizePalette16 (USER.283)
1691 UINT16 WINAPI
RealizePalette16( HDC16 hDC
)
1693 return RealizePalette( hDC
);