2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
30 #include "wine/winuser16.h"
32 #include "wine/unicode.h"
33 #include "wine/server.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 WINE_DECLARE_DEBUG_CHANNEL(nonclient
);
43 /* client rect in window coordinates */
45 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
46 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
47 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
48 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
50 /* PAINT_RedrawWindow() control flags */
51 #define RDW_EX_DELAY_NCPAINT 0x0020
53 /* WIN_UpdateNCRgn() flags */
54 #define UNC_CHECK 0x0001
55 #define UNC_ENTIRE 0x0002
56 #define UNC_REGION 0x0004
57 #define UNC_UPDATE 0x0008
58 #define UNC_DELAY_NCPAINT 0x0010
59 #define UNC_IN_BEGINPAINT 0x0020
62 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
64 HPALETTE (WINAPI
*pfnGDISelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = NULL
;
65 UINT (WINAPI
*pfnGDIRealizePalette
)(HDC hdc
) = NULL
;
68 /***********************************************************************
71 * Add an increment (normally 1 or -1) to the current paint count of a window.
73 static void add_paint_count( HWND hwnd
, int incr
)
75 SERVER_START_REQ( inc_window_paint_count
)
79 wine_server_call( req
);
85 /***********************************************************************
88 * hSrc: Region to crop.
89 * lpRect: Clipping rectangle.
91 * hDst: Region to hold the result (a new region is created if it's 0).
92 * Allowed to be the same region as hSrc in which case everything
93 * will be done in place, with no memory reallocations.
95 * Returns: hDst if success, 0 otherwise.
97 static HRGN
crop_rgn( HRGN hDst
, HRGN hSrc
, const RECT
*rect
)
99 HRGN h
= CreateRectRgnIndirect( rect
);
100 if (hDst
== 0) hDst
= h
;
101 CombineRgn( hDst
, hSrc
, h
, RGN_AND
);
102 if (hDst
!= h
) DeleteObject( h
);
107 /***********************************************************************
108 * WIN_HaveToDelayNCPAINT
110 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
111 * is generated as soon as a region intersecting the non-client area
112 * of a window is invalidated.
114 * This technique will work fine for all windows whose parents
115 * have the WS_CLIPCHILDREN style. When the parents have that style,
116 * they are not going to override the contents of their children.
117 * However, when the parent doesn't have that style, Windows relies
118 * on a "painter's algorithm" to display the contents of the windows.
119 * That is, windows are painted from back to front. This includes the
122 * This method looks at the current state of a window to determine
123 * if the sending of the WM_NCPAINT message should be delayed until
124 * the BeginPaint call.
127 * wndPtr - A Locked window pointer to the window we're
129 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
130 * function. This is a shortcut for the cases when
131 * we already know when to avoid scanning all the
132 * parents of a window. If you already know that this
133 * window's NCPAINT should be delayed, set the
134 * UNC_DELAY_NCPAINT flag for this parameter.
136 * This shortcut behavior is implemented in the
137 * RDW_Paint() method.
140 static BOOL
WIN_HaveToDelayNCPAINT( HWND hwnd
, UINT uncFlags
)
143 * Test the shortcut first. (duh)
145 if (uncFlags
& UNC_DELAY_NCPAINT
)
149 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
150 * method only. This is another shortcut to avoid going
151 * up the parent's chain of the window to finally
152 * figure-out that none of them has an invalid region.
154 if (uncFlags
& UNC_IN_BEGINPAINT
)
158 * Scan all the parents of this window to find a window
159 * that doesn't have the WS_CLIPCHILDREN style and that
160 * has an invalid region.
162 while ((hwnd
= GetAncestor( hwnd
, GA_PARENT
)))
164 WND
* parentWnd
= WIN_FindWndPtr( hwnd
);
165 if (parentWnd
&& !(parentWnd
->dwStyle
& WS_CLIPCHILDREN
) && parentWnd
->hrgnUpdate
)
167 WIN_ReleaseWndPtr( parentWnd
);
170 WIN_ReleaseWndPtr( parentWnd
);
175 /***********************************************************************
179 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
180 * Crop hrgnUpdate to a client rect, especially if it 1.
181 * If UNC_REGION is set return update region for the client rect.
183 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
184 * The trick is that when the returned region handle may be different from hRgn.
185 * In this case the old hRgn must be considered gone. BUT, if the returned value
186 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
187 * a DC without extra clipping region.
189 static HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
195 TRACE_(nonclient
)("hwnd %p [%p] hrgn %p, unc %04x, ncf %i\n",
196 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
198 /* desktop window doesn't have a nonclient area */
199 if(wnd
->hwndSelf
== GetDesktopWindow())
201 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
202 if( wnd
->hrgnUpdate
> (HRGN
)1 )
204 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
205 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
210 hrgnRet
= wnd
->hrgnUpdate
;
215 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
216 !(wnd
->flags
& WIN_NCACTIVATED
) )
218 wnd
->flags
|= WIN_NCACTIVATED
;
219 uncFlags
|= UNC_ENTIRE
;
223 * If the window's non-client area needs to be painted,
225 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
226 !WIN_HaveToDelayNCPAINT(wnd
->hwndSelf
, uncFlags
) )
230 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
231 GETCLIENTRECTW( wnd
, r
);
233 TRACE_(nonclient
)( "\tclient box (%ld,%ld-%ld,%ld), hrgnUpdate %p\n",
234 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
235 if( wnd
->hrgnUpdate
> (HRGN
)1 )
237 /* Check if update rgn overlaps with nonclient area */
239 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
240 UnionRect( &r3
, &r2
, &r
);
241 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
242 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
244 /* crop hrgnUpdate, save old one in hClip - the only
245 * case that places a valid region handle in hClip */
247 hClip
= wnd
->hrgnUpdate
;
248 wnd
->hrgnUpdate
= crop_rgn( hRgn
, hClip
, &r
);
249 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
252 if( uncFlags
& UNC_CHECK
)
254 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
255 if( IsRectEmpty( &r3
) )
257 /* delete the update region since all invalid
258 * parts were in the nonclient area */
260 DeleteObject( wnd
->hrgnUpdate
);
262 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
263 add_paint_count( wnd
->hwndSelf
, -1 );
265 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
269 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
272 if( wnd
->hrgnUpdate
== (HRGN
)1 )/* entire window */
274 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
275 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
276 uncFlags
|= UNC_ENTIRE
;
279 else /* no WM_NCPAINT unless forced */
281 if( wnd
->hrgnUpdate
> (HRGN
)1 )
284 if( uncFlags
& UNC_REGION
)
286 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
287 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
292 if( wnd
->hrgnUpdate
== (HRGN
)1 && (uncFlags
& UNC_UPDATE
) )
294 GETCLIENTRECTW( wnd
, r
);
295 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
296 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
300 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
302 /* still don't do anything if there is no nonclient area */
303 hClip
= (HRGN
)(memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
306 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
308 if ( hClip
== hrgnRet
&& hrgnRet
> (HRGN
)1 ) {
309 hClip
= CreateRectRgn( 0, 0, 0, 0 );
310 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
313 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, (WPARAM
)hClip
, 0L );
314 if( (hClip
> (HRGN
)1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
315 DeleteObject( hClip
);
317 * Since all Window locks are suspended while processing the WM_NCPAINT
318 * we want to make sure the window still exists before continuing.
320 if (!IsWindow(wnd
->hwndSelf
))
322 DeleteObject(hrgnRet
);
327 TRACE_(nonclient
)("returning %p (hClip = %p, hrgnUpdate = %p)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
333 /***********************************************************************
334 * RDW_ValidateParent [RDW_UpdateRgns() helper]
336 * Validate the portions of parents that are covered by a validated child
339 static void RDW_ValidateParent(WND
*wndChild
)
344 if (wndChild
->hrgnUpdate
== (HRGN
)1 ) {
348 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
349 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
350 hrg
= CreateRectRgnIndirect( &r
);
352 hrg
= wndChild
->hrgnUpdate
;
354 parent
= GetAncestor( wndChild
->hwndSelf
, GA_PARENT
);
355 while (parent
&& parent
!= GetDesktopWindow())
357 WND
*wndParent
= WIN_FindWndPtr( parent
);
358 if (wndParent
&& !(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
360 if (wndParent
->hrgnUpdate
!= 0)
363 RECT rect
, rectParent
;
364 if( wndParent
->hrgnUpdate
== (HRGN
)1 )
370 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
371 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
373 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
375 /* we must offset the child region by the offset of the child rect in the parent */
376 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
377 GetWindowRect(wndChild
->hwndSelf
, &rect
);
378 ptOffset
.x
= rect
.left
- rectParent
.left
;
379 ptOffset
.y
= rect
.top
- rectParent
.top
;
380 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
381 if (CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
) == NULLREGION
)
383 /* the update region has become empty */
384 DeleteObject( wndParent
->hrgnUpdate
);
385 wndParent
->hrgnUpdate
= 0;
386 wndParent
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
387 if( !(wndParent
->flags
& WIN_INTERNAL_PAINT
) )
388 add_paint_count( wndParent
->hwndSelf
, -1 );
390 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
393 WIN_ReleaseWndPtr( wndParent
);
394 parent
= GetAncestor( parent
, GA_PARENT
);
396 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
399 /***********************************************************************
400 * RDW_UpdateRgns [RedrawWindow() helper]
402 * Walks the window tree and adds/removes parts of the hRgn to/from update
403 * regions of windows that overlap it. Also, manages internal paint flags.
405 * NOTE: Walks the window tree so the caller must lock it.
406 * MUST preserve hRgn (can modify but then has to restore).
408 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
411 * Called only when one of the following is set:
412 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
415 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
416 BOOL bChildren
= (!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
417 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
422 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
423 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
425 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
427 if( flags
& RDW_INVALIDATE
)
431 switch ((UINT
)wndPtr
->hrgnUpdate
)
434 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
437 wndPtr
->hrgnUpdate
= crop_rgn( wndPtr
->hrgnUpdate
,
438 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
442 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
443 if( IsRectEmpty( &r
) )
445 DeleteObject( wndPtr
->hrgnUpdate
);
446 wndPtr
->hrgnUpdate
= 0;
451 case 1: /* already an entire window */
455 else if( hRgn
== (HRGN
)1 )
457 if( wndPtr
->hrgnUpdate
> (HRGN
)1 )
458 DeleteObject( wndPtr
->hrgnUpdate
);
459 wndPtr
->hrgnUpdate
= (HRGN
)1;
462 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
464 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
465 add_paint_count( wndPtr
->hwndSelf
, 1 );
467 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
468 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
471 else if( flags
& RDW_VALIDATE
)
473 if( wndPtr
->hrgnUpdate
)
477 if( wndPtr
->hrgnUpdate
== (HRGN
)1 )
478 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
480 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
483 DeleteObject( wndPtr
->hrgnUpdate
);
484 wndPtr
->hrgnUpdate
= 0;
487 else /* validate everything */
489 if( wndPtr
->hrgnUpdate
> (HRGN
)1 ) DeleteObject( wndPtr
->hrgnUpdate
);
490 wndPtr
->hrgnUpdate
= 0;
493 if( !wndPtr
->hrgnUpdate
)
495 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
496 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
497 add_paint_count( wndPtr
->hwndSelf
, -1 );
501 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
502 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
506 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
507 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
509 /* in/validate child windows that intersect with the region if it
510 * is a valid handle. */
512 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
515 if( hRgn
> (HRGN
)1 && bChildren
&& (list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
517 POINT ptTotal
, prevOrigin
= {0,0};
521 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
522 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
524 for(i
= ptTotal
.x
= ptTotal
.y
= 0; list
[i
]; i
++)
526 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
528 if( wnd
->dwStyle
& WS_VISIBLE
)
532 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
533 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
534 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
535 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
537 ptOffset
.x
= r
.left
- prevOrigin
.x
;
538 ptOffset
.y
= r
.top
- prevOrigin
.y
;
539 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
541 if( RectInRegion( hRgn
, &r
) )
543 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
544 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
545 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
546 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
547 ptTotal
.x
+= ptOffset
.x
;
548 ptTotal
.y
+= ptOffset
.y
;
551 WIN_ReleaseWndPtr( wnd
);
553 HeapFree( GetProcessHeap(), 0, list
);
554 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
559 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
564 if ((list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
567 for (i
= 0; list
[i
]; i
++)
569 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
571 if( wnd
->dwStyle
& WS_VISIBLE
)
572 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
573 WIN_ReleaseWndPtr( wnd
);
575 HeapFree( GetProcessHeap(), 0, list
);
581 /* Set/clear internal paint flag */
583 if (flags
& RDW_INTERNALPAINT
)
585 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
586 add_paint_count( wndPtr
->hwndSelf
, 1 );
587 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
589 else if (flags
& RDW_NOINTERNALPAINT
)
591 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
592 add_paint_count( wndPtr
->hwndSelf
, -1 );
593 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
597 /***********************************************************************
598 * RDW_Paint [RedrawWindow() helper]
600 * Walks the window tree and paints/erases windows that have
601 * nonzero update regions according to redraw flags. hrgn is a scratch
602 * region passed down during recursion. Must not be 1.
605 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
607 /* NOTE: wndPtr is locked by caller.
609 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
610 * SendMessage() calls. This is a comment inside DefWindowProc() source
613 * This message avoids lots of inter-app message traffic
614 * by switching to the other task and continuing the
618 * LOWORD(lParam) = hrgnClip
619 * HIWORD(lParam) = hwndSkip (not used; always NULL)
623 HWND hWnd
= wndPtr
->hwndSelf
;
624 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassLongA(hWnd
, GCL_HICON
));
626 /* Erase/update the window itself ... */
628 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
631 * Check if this window should delay it's processing of WM_NCPAINT.
632 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
634 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
->hwndSelf
, 0) )
635 ex
|= RDW_EX_DELAY_NCPAINT
;
637 if (flags
& RDW_UPDATENOW
)
639 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
640 SendMessageW( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
642 else if (flags
& RDW_ERASENOW
)
644 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
647 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
649 UNC_REGION
| UNC_CHECK
|
650 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
654 if( hrgnRet
> (HRGN
)1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
655 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
657 if( bIcon
) dcx
|= DCX_WINDOW
;
660 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
661 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
663 dcx
&= ~DCX_INTERSECTRGN
;
664 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
666 if (SendMessageW( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
668 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
669 ReleaseDC( hWnd
, hDC
);
675 if( !IsWindow(hWnd
) ) return hrgn
;
677 /* ... and its child windows */
679 if(!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
680 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
684 if( (list
= WIN_ListChildren( wndPtr
->hwndSelf
)) )
686 for (phwnd
= list
; *phwnd
; phwnd
++)
688 if (!(wndPtr
= WIN_FindWndPtr( *phwnd
))) continue;
689 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
690 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
691 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
692 WIN_ReleaseWndPtr(wndPtr
);
694 HeapFree( GetProcessHeap(), 0, list
);
702 /***********************************************************************
705 static void dump_rdw_flags(UINT flags
)
708 if (flags
& RDW_INVALIDATE
) TRACE(" RDW_INVALIDATE");
709 if (flags
& RDW_INTERNALPAINT
) TRACE(" RDW_INTERNALPAINT");
710 if (flags
& RDW_ERASE
) TRACE(" RDW_ERASE");
711 if (flags
& RDW_VALIDATE
) TRACE(" RDW_VALIDATE");
712 if (flags
& RDW_NOINTERNALPAINT
) TRACE(" RDW_NOINTERNALPAINT");
713 if (flags
& RDW_NOERASE
) TRACE(" RDW_NOERASE");
714 if (flags
& RDW_NOCHILDREN
) TRACE(" RDW_NOCHILDREN");
715 if (flags
& RDW_ALLCHILDREN
) TRACE(" RDW_ALLCHILDREN");
716 if (flags
& RDW_UPDATENOW
) TRACE(" RDW_UPDATENOW");
717 if (flags
& RDW_ERASENOW
) TRACE(" RDW_ERASENOW");
718 if (flags
& RDW_FRAME
) TRACE(" RDW_FRAME");
719 if (flags
& RDW_NOFRAME
) TRACE(" RDW_NOFRAME");
723 RDW_INTERNALPAINT | \
726 RDW_NOINTERNALPAINT | \
735 if (flags
& ~RDW_FLAGS
) TRACE(" %04x", flags
& ~RDW_FLAGS
);
741 /***********************************************************************
742 * RedrawWindow (USER32.@)
744 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
745 HRGN hrgnUpdate
, UINT flags
)
752 if (!hwnd
) hwnd
= GetDesktopWindow();
754 /* check if the window or its parents are visible/not minimized */
756 if (!WIN_IsWindowDrawable( hwnd
, !(flags
& RDW_FRAME
) )) return TRUE
;
758 /* process pending events and messages before painting */
759 if (flags
& RDW_UPDATENOW
)
760 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 0, QS_ALLINPUT
);
762 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
767 GetRgnBox( hrgnUpdate
, &r
);
768 TRACE( "%p (%p) NULL %p box (%ld,%ld-%ld,%ld) flags=%04x\n",
769 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
);
777 TRACE( "%p (%p) %s %ld,%ld-%ld,%ld %p flags=%04x\n",
778 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
779 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
);
781 dump_rdw_flags(flags
);
784 /* prepare an update region in window coordinates */
786 if (((flags
& (RDW_INVALIDATE
|RDW_FRAME
)) == (RDW_INVALIDATE
|RDW_FRAME
)) ||
787 ((flags
& (RDW_VALIDATE
|RDW_NOFRAME
)) == (RDW_VALIDATE
|RDW_NOFRAME
)))
788 r
= wndPtr
->rectWindow
;
790 r
= wndPtr
->rectClient
;
792 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
793 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
794 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
796 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
798 /* If the window doesn't have hrgnUpdate we leave hRgn zero
799 * and put a new region straight into wndPtr->hrgnUpdate
800 * so that RDW_UpdateRgns() won't have to do any extra work.
805 if( wndPtr
->hrgnUpdate
)
807 hRgn
= CreateRectRgn( 0, 0, 0, 0 );
808 CombineRgn( hRgn
, hrgnUpdate
, 0, RGN_COPY
);
809 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
813 wndPtr
->hrgnUpdate
= crop_rgn( 0, hrgnUpdate
, &r
);
814 OffsetRgn( wndPtr
->hrgnUpdate
, pt
.x
, pt
.y
);
817 else if( rectUpdate
)
819 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
820 OffsetRect( &r2
, pt
.x
, pt
.y
);
821 if( wndPtr
->hrgnUpdate
== 0 )
822 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
824 hRgn
= CreateRectRgnIndirect( &r2
);
826 else /* entire window or client depending on RDW_FRAME */
828 if( flags
& RDW_FRAME
)
830 if (wndPtr
->hrgnUpdate
) hRgn
= (HRGN
)1;
831 else wndPtr
->hrgnUpdate
= (HRGN
)1;
835 GETCLIENTRECTW( wndPtr
, r2
);
836 if( wndPtr
->hrgnUpdate
== 0 )
837 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
839 hRgn
= CreateRectRgnIndirect( &r2
);
843 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
845 /* In this we cannot leave with zero hRgn */
848 hRgn
= crop_rgn( hRgn
, hrgnUpdate
, &r
);
849 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
850 GetRgnBox( hRgn
, &r2
);
851 if( IsRectEmpty( &r2
) ) goto END
;
853 else if( rectUpdate
)
855 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
856 OffsetRect( &r2
, pt
.x
, pt
.y
);
857 hRgn
= CreateRectRgnIndirect( &r2
);
859 else /* entire window or client depending on RDW_NOFRAME */
861 if( flags
& RDW_NOFRAME
)
865 GETCLIENTRECTW( wndPtr
, r2
);
866 hRgn
= CreateRectRgnIndirect( &r2
);
871 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
873 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
875 /* Erase/update windows, from now on hRgn is a scratch region */
877 hRgn
= RDW_Paint( wndPtr
, (hRgn
== (HRGN
)1) ? 0 : hRgn
, flags
, 0 );
880 if( hRgn
> (HRGN
)1 && (hRgn
!= hrgnUpdate
) )
882 WIN_ReleaseWndPtr(wndPtr
);
887 /***********************************************************************
888 * UpdateWindow (USER32.@)
890 BOOL WINAPI
UpdateWindow( HWND hwnd
)
892 return RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
896 /***********************************************************************
897 * InvalidateRgn (USER32.@)
899 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
901 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
905 /***********************************************************************
906 * InvalidateRect (USER32.@)
908 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
910 return RedrawWindow( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
914 /***********************************************************************
915 * ValidateRgn (USER32.@)
917 BOOL WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
919 return RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
923 /***********************************************************************
924 * ValidateRect (USER32.@)
926 BOOL WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
928 return RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
932 /***********************************************************************
933 * GetUpdateRect (USER32.@)
935 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
938 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
939 if (!wndPtr
) return FALSE
;
943 if (wndPtr
->hrgnUpdate
> (HRGN
)1)
945 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
946 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
951 GetRgnBox( hrgn
, rect
);
952 DeleteObject( hrgn
);
953 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
955 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
957 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
962 if( wndPtr
->hrgnUpdate
== (HRGN
)1 )
964 GetClientRect( hwnd
, rect
);
965 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
968 SetRectEmpty( rect
);
970 retvalue
= (wndPtr
->hrgnUpdate
>= (HRGN
)1);
972 WIN_ReleaseWndPtr(wndPtr
);
977 /***********************************************************************
978 * GetUpdateRgn (USER32.@)
980 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
983 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
984 if (!wndPtr
) return ERROR
;
986 if (wndPtr
->hrgnUpdate
== 0)
988 SetRectRgn( hrgn
, 0, 0, 0, 0 );
993 if (wndPtr
->hrgnUpdate
== (HRGN
)1)
995 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
996 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
997 retval
= SIMPLEREGION
;
1001 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1002 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1003 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1005 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
1007 WIN_ReleaseWndPtr(wndPtr
);
1012 /***********************************************************************
1013 * ExcludeUpdateRgn (USER32.@)
1015 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1020 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
1022 if (wndPtr
->hrgnUpdate
)
1025 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1026 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
1027 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
1028 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
1029 if( wndPtr
->hrgnUpdate
> (HRGN
)1 )
1031 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1032 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1033 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1036 /* do ugly coordinate translations in dce.c */
1038 ret
= DCE_ExcludeRgn( hdc
, hwnd
, hrgn
);
1039 DeleteObject( hrgn
);
1040 WIN_ReleaseWndPtr(wndPtr
);
1043 WIN_ReleaseWndPtr(wndPtr
);
1044 return GetClipBox( hdc
, &rect
);
1049 /***********************************************************************
1050 * FillRect (USER.81)
1052 * The Win16 variant doesn't support special color brushes like
1053 * the Win32 one, despite the fact that Win16, as well as Win32,
1054 * supports special background brushes for a window class.
1056 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
1060 /* coordinates are logical so we cannot fast-check 'rect',
1061 * it will be done later in the PatBlt().
1064 if (!(prevBrush
= SelectObject( HDC_32(hdc
), HBRUSH_32(hbrush
) ))) return 0;
1065 PatBlt( HDC_32(hdc
), rect
->left
, rect
->top
,
1066 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1067 SelectObject( HDC_32(hdc
), prevBrush
);
1072 /***********************************************************************
1073 * FillRect (USER32.@)
1075 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1079 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1080 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1083 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1084 PatBlt( hdc
, rect
->left
, rect
->top
,
1085 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1086 SelectObject( hdc
, prevBrush
);
1091 /***********************************************************************
1092 * InvertRect (USER.82)
1094 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1096 PatBlt( HDC_32(hdc
), rect
->left
, rect
->top
,
1097 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1101 /***********************************************************************
1102 * InvertRect (USER32.@)
1104 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1106 return PatBlt( hdc
, rect
->left
, rect
->top
,
1107 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1112 /***********************************************************************
1113 * FrameRect (USER32.@)
1115 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1120 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1121 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1123 PatBlt( hdc
, r
.left
, r
.top
, 1,
1124 r
.bottom
- r
.top
, PATCOPY
);
1125 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1126 r
.bottom
- r
.top
, PATCOPY
);
1127 PatBlt( hdc
, r
.left
, r
.top
,
1128 r
.right
- r
.left
, 1, PATCOPY
);
1129 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1130 r
.right
- r
.left
, 1, PATCOPY
);
1132 SelectObject( hdc
, prevBrush
);
1137 /***********************************************************************
1138 * FrameRect (USER.83)
1140 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1143 CONV_RECT16TO32( rect16
, &rect
);
1144 return FrameRect( HDC_32(hdc
), &rect
, HBRUSH_32(hbrush
) );
1148 /***********************************************************************
1149 * DrawFocusRect (USER.466)
1151 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1154 CONV_RECT16TO32( rc
, &rect32
);
1155 DrawFocusRect( HDC_32(hdc
), &rect32
);
1159 /***********************************************************************
1160 * DrawFocusRect (USER32.@)
1162 * FIXME: PatBlt(PATINVERT) with background brush.
1164 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1167 HPEN hOldPen
, hNewPen
;
1168 INT oldDrawMode
, oldBkMode
;
1170 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1171 hNewPen
= CreatePen(PS_ALTERNATE
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1172 hOldPen
= SelectObject(hdc
, hNewPen
);
1173 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1174 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1176 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1178 SetBkMode(hdc
, oldBkMode
);
1179 SetROP2(hdc
, oldDrawMode
);
1180 SelectObject(hdc
, hOldPen
);
1181 DeleteObject(hNewPen
);
1182 SelectObject(hdc
, hOldBrush
);
1188 /**********************************************************************
1189 * DrawAnimatedRects (USER32.@)
1191 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1192 const RECT
* lprcFrom
,
1193 const RECT
* lprcTo
)
1195 FIXME_(win
)("(%p,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1200 /**********************************************************************
1201 * PAINTING_DrawStateJam
1203 * Jams in the requested type in the dc
1205 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1206 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1207 LPRECT rc
, UINT dtflags
, BOOL unicode
)
1212 INT cx
= rc
->right
- rc
->left
;
1213 INT cy
= rc
->bottom
- rc
->top
;
1218 case DST_PREFIXTEXT
:
1220 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1222 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1225 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1228 memdc
= CreateCompatibleDC(hdc
);
1229 if(!memdc
) return FALSE
;
1230 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1236 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1237 SelectObject(memdc
, hbmsave
);
1244 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1246 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1247 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1248 /* Restore origin */
1249 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1257 /**********************************************************************
1258 * PAINTING_DrawState()
1260 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
, DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1261 INT x
, INT y
, INT cx
, INT cy
, UINT flags
, BOOL unicode
)
1263 HBITMAP hbm
, hbmsave
;
1265 HBRUSH hbsave
, hbrtmp
= 0;
1268 UINT dtflags
= DT_NOCLIP
;
1270 UINT opcode
= flags
& 0xf;
1274 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1277 len
= strlenW((LPWSTR
)lp
);
1279 len
= strlen((LPSTR
)lp
);
1282 /* Find out what size the image has if not given by caller */
1286 CURSORICONINFO
*ici
;
1292 case DST_PREFIXTEXT
:
1294 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1296 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1297 if(!retval
) return FALSE
;
1301 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1302 if(!ici
) return FALSE
;
1304 s
.cy
= ici
->nHeight
;
1305 GlobalUnlock16((HGLOBAL16
)lp
);
1309 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1315 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1328 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1329 dtflags
|= DT_RIGHT
;
1330 if(opcode
== DST_TEXT
)
1331 dtflags
|= DT_NOPREFIX
;
1333 /* For DSS_NORMAL we just jam in the image and return */
1334 if((flags
& 0x7ff0) == DSS_NORMAL
)
1336 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1339 /* For all other states we need to convert the image to B/W in a local bitmap */
1340 /* before it is displayed */
1341 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1342 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1343 hbm
= NULL
; hbmsave
= NULL
;
1344 memdc
= NULL
; hbsave
= NULL
;
1345 retval
= FALSE
; /* assume failure */
1347 /* From here on we must use "goto cleanup" when something goes wrong */
1348 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1349 if(!hbm
) goto cleanup
;
1350 memdc
= CreateCompatibleDC(hdc
);
1351 if(!memdc
) goto cleanup
;
1352 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1353 if(!hbmsave
) goto cleanup
;
1354 rc
.left
= rc
.top
= 0;
1357 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1358 SetBkColor(memdc
, RGB(255, 255, 255));
1359 SetTextColor(memdc
, RGB(0, 0, 0));
1360 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1362 /* DST_COMPLEX may draw text as well,
1363 * so we must be sure that correct font is selected
1365 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1366 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1367 if(hfsave
) SelectObject(memdc
, hfsave
);
1368 if(!tmp
) goto cleanup
;
1370 /* This state cause the image to be dithered */
1371 if(flags
& DSS_UNION
)
1373 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1374 if(!hbsave
) goto cleanup
;
1375 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1376 SelectObject(memdc
, hbsave
);
1377 if(!tmp
) goto cleanup
;
1380 if (flags
& DSS_DISABLED
)
1381 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT
));
1382 else if (flags
& DSS_DEFAULT
)
1383 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1385 /* Draw light or dark shadow */
1386 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1388 if(!hbrtmp
) goto cleanup
;
1389 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1390 if(!hbsave
) goto cleanup
;
1391 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1392 SelectObject(hdc
, hbsave
);
1393 DeleteObject(hbrtmp
);
1397 if (flags
& DSS_DISABLED
)
1399 hbr
= hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1400 if(!hbrtmp
) goto cleanup
;
1404 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1407 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1409 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1411 retval
= TRUE
; /* We succeeded */
1414 SetTextColor(hdc
, fg
);
1415 SetBkColor(hdc
, bg
);
1417 if(hbsave
) SelectObject(hdc
, hbsave
);
1418 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1419 if(hbrtmp
) DeleteObject(hbrtmp
);
1420 if(hbm
) DeleteObject(hbm
);
1421 if(memdc
) DeleteDC(memdc
);
1426 /**********************************************************************
1427 * DrawStateA (USER32.@)
1429 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1430 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1431 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1433 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
);
1436 /**********************************************************************
1437 * DrawStateW (USER32.@)
1439 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1440 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1441 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1443 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
);
1447 /***********************************************************************
1448 * SelectPalette (Not a Windows API)
1450 HPALETTE WINAPI
SelectPalette( HDC hDC
, HPALETTE hPal
, BOOL bForceBackground
)
1452 WORD wBkgPalette
= 1;
1454 if (!bForceBackground
&& (hPal
!= GetStockObject(DEFAULT_PALETTE
)))
1456 HWND hwnd
= WindowFromDC( hDC
);
1459 HWND hForeground
= GetForegroundWindow();
1460 /* set primary palette if it's related to current active */
1461 if (hForeground
== hwnd
|| IsChild(hForeground
,hwnd
)) wBkgPalette
= 0;
1464 return pfnGDISelectPalette( hDC
, hPal
, wBkgPalette
);
1468 /***********************************************************************
1469 * UserRealizePalette (USER32.@)
1471 UINT WINAPI
UserRealizePalette( HDC hDC
)
1473 UINT realized
= pfnGDIRealizePalette( hDC
);
1475 /* do not send anything if no colors were changed */
1476 if (realized
&& IsDCCurrentPalette16( HDC_16(hDC
) ))
1478 /* send palette change notification */
1479 HWND hWnd
= WindowFromDC( hDC
);
1480 if (hWnd
) SendMessageTimeoutW( HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0,
1481 SMTO_ABORTIFHUNG
, 2000, NULL
);