2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/unicode.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(win
);
22 DECLARE_DEBUG_CHANNEL(nonclient
);
24 /* client rect in window coordinates */
26 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
27 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
28 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
29 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
32 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
34 /* Last CTLCOLOR id */
35 #define CTLCOLOR_MAX CTLCOLOR_STATIC
38 /***********************************************************************
39 * WIN_HaveToDelayNCPAINT
41 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
42 * is generated as soon as a region intersecting the non-client area
43 * of a window is invalidated.
45 * This technique will work fine for all windows whose parents
46 * have the WS_CLIPCHILDREN style. When the parents have that style,
47 * they are not going to override the contents of their children.
48 * However, when the parent doesn't have that style, Windows relies
49 * on a "painter's algorithm" to display the contents of the windows.
50 * That is, windows are painted from back to front. This includes the
53 * This method looks at the current state of a window to determine
54 * if the sending of the WM_NCPAINT message should be delayed until
55 * the BeginPaint call.
58 * wndPtr - A Locked window pointer to the window we're
60 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
61 * function. This is a shortcut for the cases when
62 * we already know when to avoid scanning all the
63 * parents of a window. If you already know that this
64 * window's NCPAINT should be delayed, set the
65 * UNC_DELAY_NCPAINT flag for this parameter.
67 * This shortcut behavior is implemented in the
71 static BOOL
WIN_HaveToDelayNCPAINT(
75 WND
* parentWnd
= NULL
;
78 * Test the shortcut first. (duh)
80 if (uncFlags
& UNC_DELAY_NCPAINT
)
84 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
85 * method only. This is another shortcut to avoid going
86 * up the parent's chain of the window to finally
87 * figure-out that none of them has an invalid region.
89 if (uncFlags
& UNC_IN_BEGINPAINT
)
93 * Scan all the parents of this window to find a window
94 * that doesn't have the WS_CLIPCHILDREN style and that
95 * has an invalid region.
97 parentWnd
= WIN_LockWndPtr(wndPtr
->parent
);
99 while (parentWnd
!=NULL
)
101 if ( ((parentWnd
->dwStyle
& WS_CLIPCHILDREN
) == 0) &&
102 (parentWnd
->hrgnUpdate
!= 0) )
104 WIN_ReleaseWndPtr(parentWnd
);
108 WIN_UpdateWndPtr(&parentWnd
, parentWnd
->parent
);
111 WIN_ReleaseWndPtr(parentWnd
);
116 /***********************************************************************
120 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
121 * Crop hrgnUpdate to a client rect, especially if it 1.
122 * If UNC_REGION is set return update region for the client rect.
124 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
125 * The trick is that when the returned region handle may be different from hRgn.
126 * In this case the old hRgn must be considered gone. BUT, if the returned value
127 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
128 * a DC without extra clipping region.
130 HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
136 TRACE_(nonclient
)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
137 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
139 /* desktop window doesn't have a nonclient area */
140 if(wnd
== WIN_GetDesktop())
142 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
143 if( wnd
->hrgnUpdate
> 1 )
144 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
147 hrgnRet
= wnd
->hrgnUpdate
;
149 WIN_ReleaseDesktop();
152 WIN_ReleaseDesktop();
154 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
155 !(wnd
->flags
& WIN_NCACTIVATED
) )
157 wnd
->flags
|= WIN_NCACTIVATED
;
158 uncFlags
|= UNC_ENTIRE
;
162 * If the window's non-client area needs to be painted,
164 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
165 !WIN_HaveToDelayNCPAINT(wnd
, uncFlags
) )
169 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
170 GETCLIENTRECTW( wnd
, r
);
172 TRACE_(nonclient
)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
173 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
174 if( wnd
->hrgnUpdate
> 1 )
176 /* Check if update rgn overlaps with nonclient area */
178 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
179 UnionRect( &r3
, &r2
, &r
);
180 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
181 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
183 /* crop hrgnUpdate, save old one in hClip - the only
184 * case that places a valid region handle in hClip */
186 hClip
= wnd
->hrgnUpdate
;
187 wnd
->hrgnUpdate
= REGION_CropRgn( hRgn
, hClip
, &r
, NULL
);
188 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
191 if( uncFlags
& UNC_CHECK
)
193 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
194 if( IsRectEmpty( &r3
) )
196 /* delete the update region since all invalid
197 * parts were in the nonclient area */
199 DeleteObject( wnd
->hrgnUpdate
);
201 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
202 QUEUE_DecPaintCount( wnd
->hmemTaskQ
);
204 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
208 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
211 if( wnd
->hrgnUpdate
== 1 )/* entire window */
213 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
214 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
215 uncFlags
|= UNC_ENTIRE
;
218 else /* no WM_NCPAINT unless forced */
220 if( wnd
->hrgnUpdate
> 1 )
223 if( uncFlags
& UNC_REGION
)
224 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
227 if( wnd
->hrgnUpdate
== 1 && (uncFlags
& UNC_UPDATE
) )
229 GETCLIENTRECTW( wnd
, r
);
230 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
231 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
235 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
237 /* still don't do anything if there is no nonclient area */
238 hClip
= (memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
241 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
243 if ( hClip
== hrgnRet
&& hrgnRet
> 1 ) {
244 hClip
= CreateRectRgn( 0, 0, 0, 0 );
245 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
248 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, hClip
, 0L );
249 if( (hClip
> 1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
250 DeleteObject( hClip
);
252 * Since all Window locks are suspended while processing the WM_NCPAINT
253 * we want to make sure the window still exists before continuing.
255 if (!IsWindow(wnd
->hwndSelf
))
257 DeleteObject(hrgnRet
);
262 TRACE_(nonclient
)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
268 /***********************************************************************
269 * BeginPaint (USER.39)
271 HDC16 WINAPI
BeginPaint16( HWND16 hwnd
, LPPAINTSTRUCT16 lps
)
275 BeginPaint( hwnd
, &ps
);
277 lps
->fErase
= ps
.fErase
;
278 lps
->rcPaint
.top
= ps
.rcPaint
.top
;
279 lps
->rcPaint
.left
= ps
.rcPaint
.left
;
280 lps
->rcPaint
.right
= ps
.rcPaint
.right
;
281 lps
->rcPaint
.bottom
= ps
.rcPaint
.bottom
;
282 lps
->fRestore
= ps
.fRestore
;
283 lps
->fIncUpdate
= ps
.fIncUpdate
;
288 /***********************************************************************
289 * BeginPaint (USER32.@)
291 HDC WINAPI
BeginPaint( HWND hwnd
, PAINTSTRUCT
*lps
)
295 RECT clipRect
, clientRect
;
296 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
297 if (!wndPtr
) return 0;
299 bIcon
= (wndPtr
->dwStyle
& WS_MINIMIZE
&& GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
301 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
303 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
304 WIN_UpdateNCRgn( wndPtr
, 0, UNC_UPDATE
| UNC_IN_BEGINPAINT
);
307 * Make sure the window is still a window. All window locks are suspended
308 * when the WM_NCPAINT is sent.
310 if (!IsWindow(wndPtr
->hwndSelf
))
312 WIN_ReleaseWndPtr(wndPtr
);
316 if( ((hrgnUpdate
= wndPtr
->hrgnUpdate
) != 0) || (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
317 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
319 wndPtr
->hrgnUpdate
= 0;
320 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
324 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate
);
326 if (GetClassWord16(wndPtr
->hwndSelf
, GCW_STYLE
) & CS_PARENTDC
)
328 /* Don't clip the output to the update region for CS_PARENTDC window */
330 DeleteObject(hrgnUpdate
);
331 lps
->hdc
= GetDCEx( hwnd
, 0, DCX_WINDOWPAINT
| DCX_USESTYLE
|
332 (bIcon
? DCX_WINDOW
: 0) );
336 if( hrgnUpdate
) /* convert to client coordinates */
337 OffsetRgn( hrgnUpdate
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
338 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
339 lps
->hdc
= GetDCEx(hwnd
, hrgnUpdate
, DCX_INTERSECTRGN
|
340 DCX_WINDOWPAINT
| DCX_USESTYLE
| (bIcon
? DCX_WINDOW
: 0) );
341 /* ReleaseDC() in EndPaint() will delete the region */
344 TRACE("hdc = %04x\n", lps
->hdc
);
348 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd
);
349 WIN_ReleaseWndPtr(wndPtr
);
353 /* It is possible that the clip box is bigger than the window itself,
354 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
355 than the window itself, so we need to intersect the cliprect with
358 GetClientRect( hwnd
, &clientRect
);
360 GetClipBox( lps
->hdc
, &clipRect
);
361 LPtoDP(lps
->hdc
, (LPPOINT
)&clipRect
, 2); /* GetClipBox returns LP */
363 IntersectRect(&lps
->rcPaint
, &clientRect
, &clipRect
);
364 DPtoLP(lps
->hdc
, (LPPOINT
)&lps
->rcPaint
, 2); /* we must return LP */
366 TRACE("box = (%i,%i - %i,%i)\n", lps
->rcPaint
.left
, lps
->rcPaint
.top
,
367 lps
->rcPaint
.right
, lps
->rcPaint
.bottom
);
369 if (wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
371 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
372 lps
->fErase
= !SendMessageA(hwnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
373 (WPARAM16
)lps
->hdc
, 0 );
375 else lps
->fErase
= TRUE
;
377 WIN_ReleaseWndPtr(wndPtr
);
382 /***********************************************************************
385 BOOL16 WINAPI
EndPaint16( HWND16 hwnd
, const PAINTSTRUCT16
* lps
)
387 ReleaseDC16( hwnd
, lps
->hdc
);
393 /***********************************************************************
394 * EndPaint (USER32.@)
396 BOOL WINAPI
EndPaint( HWND hwnd
, const PAINTSTRUCT
*lps
)
398 ReleaseDC( hwnd
, lps
->hdc
);
404 /***********************************************************************
405 * FillWindow (USER.324)
407 void WINAPI
FillWindow16( HWND16 hwndParent
, HWND16 hwnd
, HDC16 hdc
, HBRUSH16 hbrush
)
411 GetClientRect( hwnd
, &rect
);
412 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
413 CONV_RECT32TO16( &rect
, &rc16
);
414 PaintRect16( hwndParent
, hwnd
, hdc
, hbrush
, &rc16
);
418 /***********************************************************************
419 * PAINT_GetControlBrush
421 static HBRUSH16
PAINT_GetControlBrush( HWND hParent
, HWND hWnd
, HDC16 hDC
, UINT16 ctlType
)
423 HBRUSH16 bkgBrush
= (HBRUSH16
)SendMessageA( hParent
, WM_CTLCOLORMSGBOX
+ ctlType
,
424 (WPARAM
)hDC
, (LPARAM
)hWnd
);
425 if( !IsGDIObject16(bkgBrush
) )
426 bkgBrush
= DEFWND_ControlColor( hDC
, ctlType
);
431 /***********************************************************************
432 * PaintRect (USER.325)
434 void WINAPI
PaintRect16( HWND16 hwndParent
, HWND16 hwnd
, HDC16 hdc
,
435 HBRUSH16 hbrush
, const RECT16
*rect
)
437 if( hbrush
<= CTLCOLOR_MAX
)
440 hbrush
= PAINT_GetControlBrush( hwndParent
, hwnd
, hdc
, (UINT16
)hbrush
);
445 FillRect16( hdc
, rect
, hbrush
);
449 /***********************************************************************
450 * GetControlBrush (USER.326)
452 HBRUSH16 WINAPI
GetControlBrush16( HWND16 hwnd
, HDC16 hdc
, UINT16 ctlType
)
454 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
457 if((ctlType
<= CTLCOLOR_MAX
) && wndPtr
)
460 if( wndPtr
->dwStyle
& WS_POPUP
) parent
= WIN_LockWndPtr(wndPtr
->owner
);
461 else parent
= WIN_LockWndPtr(wndPtr
->parent
);
462 if( !parent
) parent
= wndPtr
;
463 retvalue
= (HBRUSH16
)PAINT_GetControlBrush( parent
->hwndSelf
, hwnd
, hdc
, ctlType
);
464 WIN_ReleaseWndPtr(parent
);
467 retvalue
= (HBRUSH16
)0;
469 WIN_ReleaseWndPtr(wndPtr
);
474 /***********************************************************************
475 * RDW_ValidateParent [RDW_UpdateRgns() helper]
477 * Validate the portions of parents that are covered by a validated child
480 void RDW_ValidateParent(WND
*wndChild
)
482 WND
*wndParent
= WIN_LockWndPtr(wndChild
->parent
);
483 WND
*wndDesktop
= WIN_GetDesktop();
486 if (wndChild
->hrgnUpdate
== 1 ) {
490 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
491 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
492 hrg
= CreateRectRgnIndirect( &r
);
494 hrg
= wndChild
->hrgnUpdate
;
496 while ((wndParent
) && (wndParent
!= wndDesktop
) ) {
497 if (!(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
499 if (wndParent
->hrgnUpdate
!= 0)
502 RECT rect
, rectParent
;
503 if( wndParent
->hrgnUpdate
== 1 )
509 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
510 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
512 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
514 /* we must offset the child region by the offset of the child rect in the parent */
515 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
516 GetWindowRect(wndChild
->hwndSelf
, &rect
);
517 ptOffset
.x
= rect
.left
- rectParent
.left
;
518 ptOffset
.y
= rect
.top
- rectParent
.top
;
519 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
520 CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
);
521 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
524 WIN_UpdateWndPtr(&wndParent
, wndParent
->parent
);
526 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
527 WIN_ReleaseWndPtr(wndParent
);
528 WIN_ReleaseDesktop();
531 /***********************************************************************
532 * RDW_UpdateRgns [RedrawWindow() helper]
534 * Walks the window tree and adds/removes parts of the hRgn to/from update
535 * regions of windows that overlap it. Also, manages internal paint flags.
537 * NOTE: Walks the window tree so the caller must lock it.
538 * MUST preserve hRgn (can modify but then has to restore).
540 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
543 * Called only when one of the following is set:
544 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
547 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
548 BOOL bChildren
= ( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
549 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
554 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
555 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
557 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
559 if( flags
& RDW_INVALIDATE
)
563 switch( wndPtr
->hrgnUpdate
)
566 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
569 wndPtr
->hrgnUpdate
= REGION_CropRgn( wndPtr
->hrgnUpdate
,
570 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
574 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
575 if( IsRectEmpty( &r
) )
577 DeleteObject( wndPtr
->hrgnUpdate
);
578 wndPtr
->hrgnUpdate
= 0;
583 case 1: /* already an entire window */
589 if( wndPtr
->hrgnUpdate
> 1 )
590 DeleteObject( wndPtr
->hrgnUpdate
);
591 wndPtr
->hrgnUpdate
= 1;
594 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
596 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
597 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
599 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
600 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
603 else if( flags
& RDW_VALIDATE
)
605 if( wndPtr
->hrgnUpdate
)
609 if( wndPtr
->hrgnUpdate
== 1 )
610 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
612 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
616 else /* validate everything */
618 if( wndPtr
->hrgnUpdate
> 1 )
621 DeleteObject( wndPtr
->hrgnUpdate
);
623 wndPtr
->hrgnUpdate
= 0;
626 if( !wndPtr
->hrgnUpdate
)
628 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
629 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
630 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
634 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
635 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
639 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
640 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
642 /* in/validate child windows that intersect with the region if it
643 * is a valid handle. */
645 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
647 if( hRgn
> 1 && bChildren
)
649 WND
* wnd
= wndPtr
->child
;
650 POINT ptTotal
, prevOrigin
= {0,0};
653 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
654 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
656 for( ptTotal
.x
= ptTotal
.y
= 0; wnd
; wnd
= wnd
->next
)
658 if( wnd
->dwStyle
& WS_VISIBLE
)
662 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
663 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
664 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
665 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
667 ptOffset
.x
= r
.left
- prevOrigin
.x
;
668 ptOffset
.y
= r
.top
- prevOrigin
.y
;
669 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
671 if( RectInRegion( hRgn
, &r
) )
673 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
674 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
675 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
676 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
677 ptTotal
.x
+= ptOffset
.x
;
678 ptTotal
.y
+= ptOffset
.y
;
682 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
687 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
692 for( wnd
= wndPtr
->child
; wnd
; wnd
= wnd
->next
)
693 if( wnd
->dwStyle
& WS_VISIBLE
)
694 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
699 /* Set/clear internal paint flag */
701 if (flags
& RDW_INTERNALPAINT
)
703 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
704 QUEUE_IncPaintCount( wndPtr
->hmemTaskQ
);
705 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
707 else if (flags
& RDW_NOINTERNALPAINT
)
709 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
710 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
711 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
715 /***********************************************************************
716 * RDW_Paint [RedrawWindow() helper]
718 * Walks the window tree and paints/erases windows that have
719 * nonzero update regions according to redraw flags. hrgn is a scratch
720 * region passed down during recursion. Must not be 1.
723 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
725 /* NOTE: wndPtr is locked by caller.
727 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
728 * SendMessage() calls. This is a comment inside DefWindowProc() source
731 * This message avoids lots of inter-app message traffic
732 * by switching to the other task and continuing the
736 * LOWORD(lParam) = hrgnClip
737 * HIWORD(lParam) = hwndSkip (not used; always NULL)
741 HWND hWnd
= wndPtr
->hwndSelf
;
742 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassWord(wndPtr
->hwndSelf
, GCW_HICON
));
744 /* Erase/update the window itself ... */
746 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
749 * Check if this window should delay it's processing of WM_NCPAINT.
750 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
752 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
, 0) )
753 ex
|= RDW_EX_DELAY_NCPAINT
;
755 if (flags
& RDW_UPDATENOW
)
757 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
758 SendMessage16( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
760 else if ((flags
& RDW_ERASENOW
) || (ex
& RDW_EX_TOPFRAME
))
762 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
765 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
767 UNC_REGION
| UNC_CHECK
|
768 ((ex
& RDW_EX_TOPFRAME
) ? UNC_ENTIRE
: 0) |
769 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
773 if( hrgnRet
> 1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
774 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
776 if( bIcon
) dcx
|= DCX_WINDOW
;
779 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
780 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
782 dcx
&= ~DCX_INTERSECTRGN
;
783 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
785 if (SendMessage16( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
786 : WM_ERASEBKGND
, (WPARAM16
)hDC
, 0 ))
787 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
788 ReleaseDC( hWnd
, hDC
);
794 if( !IsWindow(hWnd
) ) return hrgn
;
795 ex
&= ~RDW_EX_TOPFRAME
;
797 /* ... and its child windows */
799 if( wndPtr
->child
&& !(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
)
800 && ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
804 if( (list
= WIN_BuildWinArray( wndPtr
, 0, NULL
)) )
807 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
809 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
810 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
811 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
812 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
813 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
815 WIN_ReleaseWndPtr(wndPtr
);
816 WIN_ReleaseWinArray(list
);
823 /***********************************************************************
827 BOOL
PAINT_RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
828 HRGN hrgnUpdate
, UINT flags
, UINT ex
)
835 if (!hwnd
) hwnd
= GetDesktopWindow();
836 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
838 /* check if the window or its parents are visible/not minimized */
840 if (!WIN_IsWindowDrawable( wndPtr
, !(flags
& RDW_FRAME
) ) )
842 WIN_ReleaseWndPtr(wndPtr
);
850 GetRgnBox( hrgnUpdate
, &r
);
851 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
852 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
, ex
);
860 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
861 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
862 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
, ex
);
866 /* prepare an update region in window coordinates */
868 if( flags
& RDW_FRAME
)
869 r
= wndPtr
->rectWindow
;
871 r
= wndPtr
->rectClient
;
873 if( ex
& RDW_EX_XYWINDOW
)
876 OffsetRect( &r
, -wndPtr
->rectWindow
.left
, -wndPtr
->rectWindow
.top
);
880 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
881 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
882 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
885 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
887 /* If the window doesn't have hrgnUpdate we leave hRgn zero
888 * and put a new region straight into wndPtr->hrgnUpdate
889 * so that RDW_UpdateRgns() won't have to do any extra work.
894 if( wndPtr
->hrgnUpdate
)
895 hRgn
= REGION_CropRgn( 0, hrgnUpdate
, NULL
, &pt
);
897 wndPtr
->hrgnUpdate
= REGION_CropRgn( 0, hrgnUpdate
, &r
, &pt
);
899 else if( rectUpdate
)
901 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
902 OffsetRect( &r2
, pt
.x
, pt
.y
);
905 if( wndPtr
->hrgnUpdate
== 0 )
906 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
908 hRgn
= CreateRectRgnIndirect( &r2
);
910 else /* entire window or client depending on RDW_FRAME */
912 if( flags
& RDW_FRAME
)
914 if( wndPtr
->hrgnUpdate
)
915 DeleteObject( wndPtr
->hrgnUpdate
);
916 wndPtr
->hrgnUpdate
= 1;
920 GETCLIENTRECTW( wndPtr
, r2
);
925 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
927 /* In this we cannot leave with zero hRgn */
930 hRgn
= REGION_CropRgn( hRgn
, hrgnUpdate
, &r
, &pt
);
931 GetRgnBox( hRgn
, &r2
);
932 if( IsRectEmpty( &r2
) ) goto END
;
934 else if( rectUpdate
)
936 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
937 OffsetRect( &r2
, pt
.x
, pt
.y
);
939 hRgn
= CreateRectRgnIndirect( &r2
);
941 else /* entire window or client depending on RDW_FRAME */
943 if( flags
& RDW_FRAME
)
947 GETCLIENTRECTW( wndPtr
, r2
);
953 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
955 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
957 /* Erase/update windows, from now on hRgn is a scratch region */
959 hRgn
= RDW_Paint( wndPtr
, (hRgn
== 1) ? 0 : hRgn
, flags
, ex
);
962 if( hRgn
> 1 && (hRgn
!= hrgnUpdate
) )
964 WIN_ReleaseWndPtr(wndPtr
);
969 /***********************************************************************
970 * RedrawWindow (USER32.@)
972 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
973 HRGN hrgnUpdate
, UINT flags
)
975 return PAINT_RedrawWindow( hwnd
, rectUpdate
, hrgnUpdate
, flags
, 0 );
979 /***********************************************************************
980 * RedrawWindow (USER.290)
982 BOOL16 WINAPI
RedrawWindow16( HWND16 hwnd
, const RECT16
*rectUpdate
,
983 HRGN16 hrgnUpdate
, UINT16 flags
)
988 CONV_RECT16TO32( rectUpdate
, &r
);
989 return (BOOL16
)RedrawWindow( (HWND
)hwnd
, &r
, hrgnUpdate
, flags
);
991 return (BOOL16
)PAINT_RedrawWindow( (HWND
)hwnd
, NULL
,
992 (HRGN
)hrgnUpdate
, flags
, 0 );
996 /***********************************************************************
997 * UpdateWindow (USER.124)
999 void WINAPI
UpdateWindow16( HWND16 hwnd
)
1001 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
, 0 );
1004 /***********************************************************************
1005 * UpdateWindow (USER32.@)
1007 void WINAPI
UpdateWindow( HWND hwnd
)
1009 PAINT_RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
, 0 );
1012 /***********************************************************************
1013 * InvalidateRgn (USER.126)
1015 void WINAPI
InvalidateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1017 PAINT_RedrawWindow((HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1018 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1022 /***********************************************************************
1023 * InvalidateRgn (USER32.@)
1025 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1027 return PAINT_RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1031 /***********************************************************************
1032 * InvalidateRect (USER.125)
1034 void WINAPI
InvalidateRect16( HWND16 hwnd
, const RECT16
*rect
, BOOL16 erase
)
1036 RedrawWindow16( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
1040 /***********************************************************************
1041 * InvalidateRect (USER32.@)
1043 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
1045 return PAINT_RedrawWindow( hwnd
, rect
, 0,
1046 RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0), 0 );
1050 /***********************************************************************
1051 * ValidateRgn (USER.128)
1053 void WINAPI
ValidateRgn16( HWND16 hwnd
, HRGN16 hrgn
)
1055 PAINT_RedrawWindow( (HWND
)hwnd
, NULL
, (HRGN
)hrgn
,
1056 RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1060 /***********************************************************************
1061 * ValidateRgn (USER32.@)
1063 void WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
1065 PAINT_RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1069 /***********************************************************************
1070 * ValidateRect (USER.127)
1072 void WINAPI
ValidateRect16( HWND16 hwnd
, const RECT16
*rect
)
1074 RedrawWindow16( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
1078 /***********************************************************************
1079 * ValidateRect (USER32.@)
1081 void WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
1083 PAINT_RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
, 0 );
1087 /***********************************************************************
1088 * GetUpdateRect (USER.190)
1090 BOOL16 WINAPI
GetUpdateRect16( HWND16 hwnd
, LPRECT16 rect
, BOOL16 erase
)
1095 if (!rect
) return GetUpdateRect( hwnd
, NULL
, erase
);
1096 ret
= GetUpdateRect( hwnd
, &r
, erase
);
1097 CONV_RECT32TO16( &r
, rect
);
1102 /***********************************************************************
1103 * GetUpdateRect (USER32.@)
1105 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
1108 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1109 if (!wndPtr
) return FALSE
;
1113 if (wndPtr
->hrgnUpdate
> 1)
1115 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
1116 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
1121 GetRgnBox( hrgn
, rect
);
1122 DeleteObject( hrgn
);
1123 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
1125 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
1127 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
1132 if( wndPtr
->hrgnUpdate
== 1 )
1134 GetClientRect( hwnd
, rect
);
1135 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
1138 SetRectEmpty( rect
);
1140 retvalue
= (wndPtr
->hrgnUpdate
>= 1);
1142 WIN_ReleaseWndPtr(wndPtr
);
1147 /***********************************************************************
1148 * GetUpdateRgn (USER.237)
1150 INT16 WINAPI
GetUpdateRgn16( HWND16 hwnd
, HRGN16 hrgn
, BOOL16 erase
)
1152 return GetUpdateRgn( hwnd
, hrgn
, erase
);
1156 /***********************************************************************
1157 * GetUpdateRgn (USER32.@)
1159 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1162 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1163 if (!wndPtr
) return ERROR
;
1165 if (wndPtr
->hrgnUpdate
== 0)
1167 SetRectRgn( hrgn
, 0, 0, 0, 0 );
1168 retval
= NULLREGION
;
1172 if (wndPtr
->hrgnUpdate
== 1)
1174 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
1175 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
1176 retval
= SIMPLEREGION
;
1180 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1181 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1182 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1184 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
1186 WIN_ReleaseWndPtr(wndPtr
);
1191 /***********************************************************************
1192 * ExcludeUpdateRgn (USER.238)
1194 INT16 WINAPI
ExcludeUpdateRgn16( HDC16 hdc
, HWND16 hwnd
)
1196 return ExcludeUpdateRgn( hdc
, hwnd
);
1200 /***********************************************************************
1201 * ExcludeUpdateRgn (USER32.@)
1203 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1208 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
1210 if (wndPtr
->hrgnUpdate
)
1213 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1214 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
1215 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
1216 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
1217 if( wndPtr
->hrgnUpdate
> 1 )
1219 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1220 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1221 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1224 /* do ugly coordinate translations in dce.c */
1226 ret
= DCE_ExcludeRgn( hdc
, wndPtr
, hrgn
);
1227 DeleteObject( hrgn
);
1228 WIN_ReleaseWndPtr(wndPtr
);
1231 WIN_ReleaseWndPtr(wndPtr
);
1232 return GetClipBox( hdc
, &rect
);
1237 /***********************************************************************
1238 * FillRect (USER.81)
1240 * The Win16 variant doesn't support special color brushes like
1241 * the Win32 one, despite the fact that Win16, as well as Win32,
1242 * supports special background brushes for a window class.
1244 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
1248 /* coordinates are logical so we cannot fast-check 'rect',
1249 * it will be done later in the PatBlt().
1252 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1253 PatBlt( hdc
, rect
->left
, rect
->top
,
1254 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1255 SelectObject( hdc
, prevBrush
);
1260 /***********************************************************************
1261 * FillRect (USER32.@)
1263 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1267 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1268 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1271 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1272 PatBlt( hdc
, rect
->left
, rect
->top
,
1273 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1274 SelectObject( hdc
, prevBrush
);
1279 /***********************************************************************
1280 * InvertRect (USER.82)
1282 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1284 PatBlt( hdc
, rect
->left
, rect
->top
,
1285 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1289 /***********************************************************************
1290 * InvertRect (USER32.@)
1292 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1294 return PatBlt( hdc
, rect
->left
, rect
->top
,
1295 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1300 /***********************************************************************
1301 * FrameRect (USER32.@)
1303 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1308 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1309 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1311 PatBlt( hdc
, r
.left
, r
.top
, 1,
1312 r
.bottom
- r
.top
, PATCOPY
);
1313 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1314 r
.bottom
- r
.top
, PATCOPY
);
1315 PatBlt( hdc
, r
.left
, r
.top
,
1316 r
.right
- r
.left
, 1, PATCOPY
);
1317 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1318 r
.right
- r
.left
, 1, PATCOPY
);
1320 SelectObject( hdc
, prevBrush
);
1325 /***********************************************************************
1326 * FrameRect (USER.83)
1328 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1331 CONV_RECT16TO32( rect16
, &rect
);
1332 return FrameRect( hdc
, &rect
, hbrush
);
1336 /***********************************************************************
1337 * DrawFocusRect (USER.466)
1339 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1342 CONV_RECT16TO32( rc
, &rect32
);
1343 DrawFocusRect( hdc
, &rect32
);
1347 /***********************************************************************
1348 * DrawFocusRect (USER32.@)
1350 * FIXME: PatBlt(PATINVERT) with background brush.
1352 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1355 HPEN hOldPen
, hNewPen
;
1356 INT oldDrawMode
, oldBkMode
;
1358 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1359 hNewPen
= CreatePen(PS_ALTERNATE
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1360 hOldPen
= SelectObject(hdc
, hNewPen
);
1361 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1362 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1364 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1366 SetBkMode(hdc
, oldBkMode
);
1367 SetROP2(hdc
, oldDrawMode
);
1368 SelectObject(hdc
, hOldPen
);
1369 DeleteObject(hNewPen
);
1370 SelectObject(hdc
, hOldBrush
);
1375 /**********************************************************************
1376 * DrawAnimatedRects (USER.448)
1378 BOOL16 WINAPI
DrawAnimatedRects16( HWND16 hwnd
, INT16 idAni
,
1379 const RECT16
* lprcFrom
,
1380 const RECT16
* lprcTo
)
1382 RECT rcFrom32
, rcTo32
;
1384 rcFrom32
.left
= (INT
)lprcFrom
->left
;
1385 rcFrom32
.top
= (INT
)lprcFrom
->top
;
1386 rcFrom32
.right
= (INT
)lprcFrom
->right
;
1387 rcFrom32
.bottom
= (INT
)lprcFrom
->bottom
;
1389 rcTo32
.left
= (INT
)lprcTo
->left
;
1390 rcTo32
.top
= (INT
)lprcTo
->top
;
1391 rcTo32
.right
= (INT
)lprcTo
->right
;
1392 rcTo32
.bottom
= (INT
)lprcTo
->bottom
;
1394 return DrawAnimatedRects((HWND
)hwnd
, (INT
)idAni
, &rcFrom32
, &rcTo32
);
1398 /**********************************************************************
1399 * DrawAnimatedRects (USER32.@)
1401 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1402 const RECT
* lprcFrom
,
1403 const RECT
* lprcTo
)
1405 FIXME_(win
)("(0x%x,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1410 /**********************************************************************
1411 * PAINTING_DrawStateJam
1413 * Jams in the requested type in the dc
1415 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1416 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1417 LPRECT rc
, UINT dtflags
,
1418 BOOL unicode
, BOOL _32bit
)
1423 INT cx
= rc
->right
- rc
->left
;
1424 INT cy
= rc
->bottom
- rc
->top
;
1429 case DST_PREFIXTEXT
:
1431 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1433 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1435 return DrawTextA(hdc
, MapSL(lp
), (INT
)wp
, rc
, dtflags
);
1438 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1441 memdc
= CreateCompatibleDC(hdc
);
1442 if(!memdc
) return FALSE
;
1443 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1449 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1450 SelectObject(memdc
, hbmsave
);
1457 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1459 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1461 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1463 bRet
= (BOOL
)((DRAWSTATEPROC16
)func
)((HDC16
)hdc
, (LPARAM
)lp
, (WPARAM16
)wp
, (INT16
)cx
, (INT16
)cy
);
1464 /* Restore origin */
1465 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1473 /**********************************************************************
1474 * PAINTING_DrawState()
1476 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
,
1477 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1478 INT x
, INT y
, INT cx
, INT cy
,
1479 UINT flags
, BOOL unicode
, BOOL _32bit
)
1481 HBITMAP hbm
, hbmsave
;
1483 HBRUSH hbsave
, hbrtmp
= 0;
1486 UINT dtflags
= DT_NOCLIP
;
1488 UINT opcode
= flags
& 0xf;
1492 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1495 len
= strlenW((LPWSTR
)lp
);
1497 len
= strlen((LPSTR
)lp
);
1499 len
= strlen(MapSL(lp
));
1502 /* Find out what size the image has if not given by caller */
1506 CURSORICONINFO
*ici
;
1512 case DST_PREFIXTEXT
:
1514 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1516 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1518 retval
= GetTextExtentPoint32A(hdc
, MapSL(lp
), len
, &s
);
1519 if(!retval
) return FALSE
;
1523 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1524 if(!ici
) return FALSE
;
1526 s
.cy
= ici
->nHeight
;
1527 GlobalUnlock16((HGLOBAL16
)lp
);
1531 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1537 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1550 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1551 dtflags
|= DT_RIGHT
;
1552 if(opcode
== DST_TEXT
)
1553 dtflags
|= DT_NOPREFIX
;
1555 /* For DSS_NORMAL we just jam in the image and return */
1556 if((flags
& 0x7ff0) == DSS_NORMAL
)
1558 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1561 /* For all other states we need to convert the image to B/W in a local bitmap */
1562 /* before it is displayed */
1563 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1564 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1565 hbm
= (HBITMAP
)NULL
; hbmsave
= (HBITMAP
)NULL
;
1566 memdc
= (HDC
)NULL
; hbsave
= (HBRUSH
)NULL
;
1567 retval
= FALSE
; /* assume failure */
1569 /* From here on we must use "goto cleanup" when something goes wrong */
1570 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1571 if(!hbm
) goto cleanup
;
1572 memdc
= CreateCompatibleDC(hdc
);
1573 if(!memdc
) goto cleanup
;
1574 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1575 if(!hbmsave
) goto cleanup
;
1576 rc
.left
= rc
.top
= 0;
1579 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1580 SetBkColor(memdc
, RGB(255, 255, 255));
1581 SetTextColor(memdc
, RGB(0, 0, 0));
1582 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1584 /* DST_COMPLEX may draw text as well,
1585 * so we must be sure that correct font is selected
1587 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1588 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
, _32bit
);
1589 if(hfsave
) SelectObject(memdc
, hfsave
);
1590 if(!tmp
) goto cleanup
;
1592 /* This state cause the image to be dithered */
1593 if(flags
& DSS_UNION
)
1595 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1596 if(!hbsave
) goto cleanup
;
1597 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1598 SelectObject(memdc
, hbsave
);
1599 if(!tmp
) goto cleanup
;
1602 if (flags
& DSS_DISABLED
)
1603 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT
));
1604 else if (flags
& DSS_DEFAULT
)
1605 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1607 /* Draw light or dark shadow */
1608 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1610 if(!hbrtmp
) goto cleanup
;
1611 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1612 if(!hbsave
) goto cleanup
;
1613 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1614 SelectObject(hdc
, hbsave
);
1615 DeleteObject(hbrtmp
);
1619 if (flags
& DSS_DISABLED
)
1621 hbr
= hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1622 if(!hbrtmp
) goto cleanup
;
1626 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1629 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1631 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1633 retval
= TRUE
; /* We succeeded */
1636 SetTextColor(hdc
, fg
);
1637 SetBkColor(hdc
, bg
);
1639 if(hbsave
) SelectObject(hdc
, hbsave
);
1640 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1641 if(hbrtmp
) DeleteObject(hbrtmp
);
1642 if(hbm
) DeleteObject(hbm
);
1643 if(memdc
) DeleteDC(memdc
);
1648 /**********************************************************************
1649 * DrawStateA (USER32.@)
1651 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1652 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1653 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1655 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, TRUE
);
1658 /**********************************************************************
1659 * DrawStateW (USER32.@)
1661 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1662 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1663 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1665 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
, TRUE
);
1668 /**********************************************************************
1669 * DrawState (USER.449)
1671 BOOL16 WINAPI
DrawState16(HDC16 hdc
, HBRUSH16 hbr
,
1672 DRAWSTATEPROC16 func
, LPARAM ldata
, WPARAM16 wdata
,
1673 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, UINT16 flags
)
1675 return PAINTING_DrawState(hdc
, hbr
, (DRAWSTATEPROC
)func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
, FALSE
);
1679 /***********************************************************************
1680 * SelectPalette (USER.282)
1682 HPALETTE16 WINAPI
SelectPalette16( HDC16 hDC
, HPALETTE16 hPal
,
1683 BOOL16 bForceBackground
)
1685 WORD wBkgPalette
= 1;
1687 if (!bForceBackground
&& (hPal
!= GetStockObject(DEFAULT_PALETTE
)))
1689 HWND hwnd
= WindowFromDC( hDC
);
1692 HWND hForeground
= GetForegroundWindow();
1693 /* set primary palette if it's related to current active */
1694 if (hForeground
== hwnd
|| IsChild(hForeground
,hwnd
)) wBkgPalette
= 0;
1697 return GDISelectPalette16( hDC
, hPal
, wBkgPalette
);
1701 /***********************************************************************
1702 * RealizePalette (USER.283)
1704 UINT16 WINAPI
RealizePalette16( HDC16 hDC
)
1706 UINT16 realized
= GDIRealizePalette16( hDC
);
1708 /* do not send anything if no colors were changed */
1709 if (realized
&& IsDCCurrentPalette16( hDC
))
1711 /* send palette change notification */
1712 HWND hWnd
= WindowFromDC( hDC
);
1713 if (hWnd
) SendMessageA( HWND_BROADCAST
, WM_PALETTECHANGED
, hWnd
, 0L);
1719 /***********************************************************************
1720 * UserRealizePalette (USER32.@)
1722 UINT WINAPI
UserRealizePalette( HDC hDC
)
1724 return RealizePalette16( hDC
);