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
25 #include "wine/winuser16.h"
27 #include "wine/unicode.h"
28 #include "wine/server.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(win
);
37 WINE_DECLARE_DEBUG_CHANNEL(nonclient
);
39 /* client rect in window coordinates */
41 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
42 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
43 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
44 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
46 /* PAINT_RedrawWindow() control flags */
47 #define RDW_EX_DELAY_NCPAINT 0x0020
49 /* WIN_UpdateNCRgn() flags */
50 #define UNC_CHECK 0x0001
51 #define UNC_ENTIRE 0x0002
52 #define UNC_REGION 0x0004
53 #define UNC_UPDATE 0x0008
54 #define UNC_DELAY_NCPAINT 0x0010
55 #define UNC_IN_BEGINPAINT 0x0020
58 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
60 HPALETTE (WINAPI
*pfnGDISelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = NULL
;
61 UINT (WINAPI
*pfnGDIRealizePalette
)(HDC hdc
) = NULL
;
64 /***********************************************************************
67 * Add an increment (normally 1 or -1) to the current paint count of a window.
69 static void add_paint_count( HWND hwnd
, int incr
)
71 SERVER_START_REQ( inc_window_paint_count
)
75 wine_server_call( req
);
81 /***********************************************************************
84 * hSrc: Region to crop.
85 * lpRect: Clipping rectangle.
87 * hDst: Region to hold the result (a new region is created if it's 0).
88 * Allowed to be the same region as hSrc in which case everything
89 * will be done in place, with no memory reallocations.
91 * Returns: hDst if success, 0 otherwise.
93 static HRGN
crop_rgn( HRGN hDst
, HRGN hSrc
, const RECT
*rect
)
95 HRGN h
= CreateRectRgnIndirect( rect
);
96 if (hDst
== 0) hDst
= h
;
97 CombineRgn( hDst
, hSrc
, h
, RGN_AND
);
98 if (hDst
!= h
) DeleteObject( h
);
103 /***********************************************************************
104 * WIN_HaveToDelayNCPAINT
106 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
107 * is generated as soon as a region intersecting the non-client area
108 * of a window is invalidated.
110 * This technique will work fine for all windows whose parents
111 * have the WS_CLIPCHILDREN style. When the parents have that style,
112 * they are not going to override the contents of their children.
113 * However, when the parent doesn't have that style, Windows relies
114 * on a "painter's algorithm" to display the contents of the windows.
115 * That is, windows are painted from back to front. This includes the
118 * This method looks at the current state of a window to determine
119 * if the sending of the WM_NCPAINT message should be delayed until
120 * the BeginPaint call.
123 * wndPtr - A Locked window pointer to the window we're
125 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
126 * function. This is a shortcut for the cases when
127 * we already know when to avoid scanning all the
128 * parents of a window. If you already know that this
129 * window's NCPAINT should be delayed, set the
130 * UNC_DELAY_NCPAINT flag for this parameter.
132 * This shortcut behavior is implemented in the
133 * RDW_Paint() method.
136 static BOOL
WIN_HaveToDelayNCPAINT( HWND hwnd
, UINT uncFlags
)
139 * Test the shortcut first. (duh)
141 if (uncFlags
& UNC_DELAY_NCPAINT
)
145 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
146 * method only. This is another shortcut to avoid going
147 * up the parent's chain of the window to finally
148 * figure-out that none of them has an invalid region.
150 if (uncFlags
& UNC_IN_BEGINPAINT
)
154 * Scan all the parents of this window to find a window
155 * that doesn't have the WS_CLIPCHILDREN style and that
156 * has an invalid region.
158 while ((hwnd
= GetAncestor( hwnd
, GA_PARENT
)))
160 WND
* parentWnd
= WIN_FindWndPtr( hwnd
);
161 if (parentWnd
&& !(parentWnd
->dwStyle
& WS_CLIPCHILDREN
) && parentWnd
->hrgnUpdate
)
163 WIN_ReleaseWndPtr( parentWnd
);
166 WIN_ReleaseWndPtr( parentWnd
);
171 /***********************************************************************
175 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
176 * Crop hrgnUpdate to a client rect, especially if it 1.
177 * If UNC_REGION is set return update region for the client rect.
179 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
180 * The trick is that when the returned region handle may be different from hRgn.
181 * In this case the old hRgn must be considered gone. BUT, if the returned value
182 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
183 * a DC without extra clipping region.
185 static HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
191 TRACE_(nonclient
)("hwnd %p [%p] hrgn %p, unc %04x, ncf %i\n",
192 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
194 /* desktop window doesn't have a nonclient area */
195 if(wnd
->hwndSelf
== GetDesktopWindow())
197 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
198 if( wnd
->hrgnUpdate
> (HRGN
)1 )
200 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
201 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
206 hrgnRet
= wnd
->hrgnUpdate
;
211 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
212 !(wnd
->flags
& WIN_NCACTIVATED
) )
214 wnd
->flags
|= WIN_NCACTIVATED
;
215 uncFlags
|= UNC_ENTIRE
;
219 * If the window's non-client area needs to be painted,
221 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
222 !WIN_HaveToDelayNCPAINT(wnd
->hwndSelf
, uncFlags
) )
226 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
227 GETCLIENTRECTW( wnd
, r
);
229 TRACE_(nonclient
)( "\tclient box (%ld,%ld-%ld,%ld), hrgnUpdate %p\n",
230 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
231 if( wnd
->hrgnUpdate
> (HRGN
)1 )
233 /* Check if update rgn overlaps with nonclient area */
235 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
236 UnionRect( &r3
, &r2
, &r
);
237 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
238 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
240 /* crop hrgnUpdate, save old one in hClip - the only
241 * case that places a valid region handle in hClip */
243 hClip
= wnd
->hrgnUpdate
;
244 wnd
->hrgnUpdate
= crop_rgn( hRgn
, hClip
, &r
);
245 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
248 if( uncFlags
& UNC_CHECK
)
250 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
251 if( IsRectEmpty( &r3
) )
253 /* delete the update region since all invalid
254 * parts were in the nonclient area */
256 DeleteObject( wnd
->hrgnUpdate
);
258 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
259 add_paint_count( wnd
->hwndSelf
, -1 );
261 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
265 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
268 if( wnd
->hrgnUpdate
== (HRGN
)1 )/* entire window */
270 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
271 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
272 uncFlags
|= UNC_ENTIRE
;
275 else /* no WM_NCPAINT unless forced */
277 if( wnd
->hrgnUpdate
> (HRGN
)1 )
280 if( uncFlags
& UNC_REGION
)
282 if (!hRgn
) hRgn
= CreateRectRgn( 0, 0, 0, 0 );
283 CombineRgn( hRgn
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
288 if( wnd
->hrgnUpdate
== (HRGN
)1 && (uncFlags
& UNC_UPDATE
) )
290 GETCLIENTRECTW( wnd
, r
);
291 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
292 if( uncFlags
& UNC_REGION
) hrgnRet
= (HRGN
)1;
296 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
298 /* still don't do anything if there is no nonclient area */
299 hClip
= (HRGN
)(memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
302 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
304 if ( hClip
== hrgnRet
&& hrgnRet
> (HRGN
)1 ) {
305 hClip
= CreateRectRgn( 0, 0, 0, 0 );
306 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
309 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, (WPARAM
)hClip
, 0L );
310 if( (hClip
> (HRGN
)1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
311 DeleteObject( hClip
);
313 * Since all Window locks are suspended while processing the WM_NCPAINT
314 * we want to make sure the window still exists before continuing.
316 if (!IsWindow(wnd
->hwndSelf
))
318 DeleteObject(hrgnRet
);
323 TRACE_(nonclient
)("returning %p (hClip = %p, hrgnUpdate = %p)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
329 /***********************************************************************
330 * RDW_ValidateParent [RDW_UpdateRgns() helper]
332 * Validate the portions of parents that are covered by a validated child
335 static void RDW_ValidateParent(WND
*wndChild
)
340 if (wndChild
->hrgnUpdate
== (HRGN
)1 ) {
344 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
345 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
346 hrg
= CreateRectRgnIndirect( &r
);
348 hrg
= wndChild
->hrgnUpdate
;
350 parent
= GetAncestor( wndChild
->hwndSelf
, GA_PARENT
);
351 while (parent
&& parent
!= GetDesktopWindow())
353 WND
*wndParent
= WIN_FindWndPtr( parent
);
354 if (wndParent
&& !(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
356 if (wndParent
->hrgnUpdate
!= 0)
359 RECT rect
, rectParent
;
360 if( wndParent
->hrgnUpdate
== (HRGN
)1 )
366 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
367 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
369 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
371 /* we must offset the child region by the offset of the child rect in the parent */
372 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
373 GetWindowRect(wndChild
->hwndSelf
, &rect
);
374 ptOffset
.x
= rect
.left
- rectParent
.left
;
375 ptOffset
.y
= rect
.top
- rectParent
.top
;
376 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
377 CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
);
378 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
381 WIN_ReleaseWndPtr( wndParent
);
382 parent
= GetAncestor( parent
, GA_PARENT
);
384 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
387 /***********************************************************************
388 * RDW_UpdateRgns [RedrawWindow() helper]
390 * Walks the window tree and adds/removes parts of the hRgn to/from update
391 * regions of windows that overlap it. Also, manages internal paint flags.
393 * NOTE: Walks the window tree so the caller must lock it.
394 * MUST preserve hRgn (can modify but then has to restore).
396 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
399 * Called only when one of the following is set:
400 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
403 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
404 BOOL bChildren
= (!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
405 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
410 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
411 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
413 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
415 if( flags
& RDW_INVALIDATE
)
419 switch ((UINT
)wndPtr
->hrgnUpdate
)
422 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
425 wndPtr
->hrgnUpdate
= crop_rgn( wndPtr
->hrgnUpdate
,
426 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
430 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
431 if( IsRectEmpty( &r
) )
433 DeleteObject( wndPtr
->hrgnUpdate
);
434 wndPtr
->hrgnUpdate
= 0;
439 case 1: /* already an entire window */
443 else if( hRgn
== (HRGN
)1 )
445 if( wndPtr
->hrgnUpdate
> (HRGN
)1 )
446 DeleteObject( wndPtr
->hrgnUpdate
);
447 wndPtr
->hrgnUpdate
= (HRGN
)1;
450 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
452 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
453 add_paint_count( wndPtr
->hwndSelf
, 1 );
455 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
456 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
459 else if( flags
& RDW_VALIDATE
)
461 if( wndPtr
->hrgnUpdate
)
465 if( wndPtr
->hrgnUpdate
== (HRGN
)1 )
466 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
468 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
471 DeleteObject( wndPtr
->hrgnUpdate
);
472 wndPtr
->hrgnUpdate
= 0;
475 else /* validate everything */
477 if( wndPtr
->hrgnUpdate
> (HRGN
)1 ) DeleteObject( wndPtr
->hrgnUpdate
);
478 wndPtr
->hrgnUpdate
= 0;
481 if( !wndPtr
->hrgnUpdate
)
483 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
484 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
485 add_paint_count( wndPtr
->hwndSelf
, -1 );
489 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
490 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
494 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
495 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
497 /* in/validate child windows that intersect with the region if it
498 * is a valid handle. */
500 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
503 if( hRgn
> (HRGN
)1 && bChildren
&& (list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
505 POINT ptTotal
, prevOrigin
= {0,0};
509 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
510 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
512 for(i
= ptTotal
.x
= ptTotal
.y
= 0; list
[i
]; i
++)
514 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
516 if( wnd
->dwStyle
& WS_VISIBLE
)
520 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
521 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
522 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
523 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
525 ptOffset
.x
= r
.left
- prevOrigin
.x
;
526 ptOffset
.y
= r
.top
- prevOrigin
.y
;
527 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
529 if( RectInRegion( hRgn
, &r
) )
531 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
532 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
533 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
534 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
535 ptTotal
.x
+= ptOffset
.x
;
536 ptTotal
.y
+= ptOffset
.y
;
539 WIN_ReleaseWndPtr( wnd
);
541 HeapFree( GetProcessHeap(), 0, list
);
542 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
547 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
552 if ((list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
555 for (i
= 0; list
[i
]; i
++)
557 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
559 if( wnd
->dwStyle
& WS_VISIBLE
)
560 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
561 WIN_ReleaseWndPtr( wnd
);
563 HeapFree( GetProcessHeap(), 0, list
);
569 /* Set/clear internal paint flag */
571 if (flags
& RDW_INTERNALPAINT
)
573 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
574 add_paint_count( wndPtr
->hwndSelf
, 1 );
575 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
577 else if (flags
& RDW_NOINTERNALPAINT
)
579 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
580 add_paint_count( wndPtr
->hwndSelf
, -1 );
581 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
585 /***********************************************************************
586 * RDW_Paint [RedrawWindow() helper]
588 * Walks the window tree and paints/erases windows that have
589 * nonzero update regions according to redraw flags. hrgn is a scratch
590 * region passed down during recursion. Must not be 1.
593 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
595 /* NOTE: wndPtr is locked by caller.
597 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
598 * SendMessage() calls. This is a comment inside DefWindowProc() source
601 * This message avoids lots of inter-app message traffic
602 * by switching to the other task and continuing the
606 * LOWORD(lParam) = hrgnClip
607 * HIWORD(lParam) = hwndSkip (not used; always NULL)
611 HWND hWnd
= wndPtr
->hwndSelf
;
612 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassLongA(hWnd
, GCL_HICON
));
614 /* Erase/update the window itself ... */
616 TRACE("\thwnd %p [%p] -> hrgn [%p], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
619 * Check if this window should delay it's processing of WM_NCPAINT.
620 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
622 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
->hwndSelf
, 0) )
623 ex
|= RDW_EX_DELAY_NCPAINT
;
625 if (flags
& RDW_UPDATENOW
)
627 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
628 SendMessageW( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
630 else if (flags
& RDW_ERASENOW
)
632 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
635 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
637 UNC_REGION
| UNC_CHECK
|
638 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
642 if( hrgnRet
> (HRGN
)1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
643 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
645 if( bIcon
) dcx
|= DCX_WINDOW
;
648 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
649 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
651 dcx
&= ~DCX_INTERSECTRGN
;
652 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
654 if (SendMessageW( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
656 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
657 ReleaseDC( hWnd
, hDC
);
663 if( !IsWindow(hWnd
) ) return hrgn
;
665 /* ... and its child windows */
667 if(!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
668 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
672 if( (list
= WIN_ListChildren( wndPtr
->hwndSelf
)) )
674 for (phwnd
= list
; *phwnd
; phwnd
++)
676 if (!(wndPtr
= WIN_FindWndPtr( *phwnd
))) continue;
677 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
678 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
679 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
680 WIN_ReleaseWndPtr(wndPtr
);
682 HeapFree( GetProcessHeap(), 0, list
);
690 /***********************************************************************
693 static void dump_rdw_flags(UINT flags
)
696 if (flags
& RDW_INVALIDATE
) TRACE(" RDW_INVALIDATE");
697 if (flags
& RDW_INTERNALPAINT
) TRACE(" RDW_INTERNALPAINT");
698 if (flags
& RDW_ERASE
) TRACE(" RDW_ERASE");
699 if (flags
& RDW_VALIDATE
) TRACE(" RDW_VALIDATE");
700 if (flags
& RDW_NOINTERNALPAINT
) TRACE(" RDW_NOINTERNALPAINT");
701 if (flags
& RDW_NOERASE
) TRACE(" RDW_NOERASE");
702 if (flags
& RDW_NOCHILDREN
) TRACE(" RDW_NOCHILDREN");
703 if (flags
& RDW_ALLCHILDREN
) TRACE(" RDW_ALLCHILDREN");
704 if (flags
& RDW_UPDATENOW
) TRACE(" RDW_UPDATENOW");
705 if (flags
& RDW_ERASENOW
) TRACE(" RDW_ERASENOW");
706 if (flags
& RDW_FRAME
) TRACE(" RDW_FRAME");
707 if (flags
& RDW_NOFRAME
) TRACE(" RDW_NOFRAME");
711 RDW_INTERNALPAINT | \
714 RDW_NOINTERNALPAINT | \
723 if (flags
& ~RDW_FLAGS
) TRACE(" %04x", flags
& ~RDW_FLAGS
);
729 /***********************************************************************
730 * RedrawWindow (USER32.@)
732 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
733 HRGN hrgnUpdate
, UINT flags
)
740 if (!hwnd
) hwnd
= GetDesktopWindow();
742 /* check if the window or its parents are visible/not minimized */
744 if (!WIN_IsWindowDrawable( hwnd
, !(flags
& RDW_FRAME
) )) return TRUE
;
746 /* process pending events and messages before painting */
747 if (flags
& RDW_UPDATENOW
)
748 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 0, QS_ALLINPUT
);
750 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
755 GetRgnBox( hrgnUpdate
, &r
);
756 TRACE( "%p (%p) NULL %p box (%ld,%ld-%ld,%ld) flags=%04x\n",
757 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
);
765 TRACE( "%p (%p) %s %ld,%ld-%ld,%ld %p flags=%04x\n",
766 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
767 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
);
769 dump_rdw_flags(flags
);
772 /* prepare an update region in window coordinates */
774 if (((flags
& (RDW_INVALIDATE
|RDW_FRAME
)) == (RDW_INVALIDATE
|RDW_FRAME
)) ||
775 ((flags
& (RDW_VALIDATE
|RDW_NOFRAME
)) == (RDW_VALIDATE
|RDW_NOFRAME
)))
776 r
= wndPtr
->rectWindow
;
778 r
= wndPtr
->rectClient
;
780 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
781 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
782 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
784 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
786 /* If the window doesn't have hrgnUpdate we leave hRgn zero
787 * and put a new region straight into wndPtr->hrgnUpdate
788 * so that RDW_UpdateRgns() won't have to do any extra work.
793 if( wndPtr
->hrgnUpdate
)
795 hRgn
= CreateRectRgn( 0, 0, 0, 0 );
796 CombineRgn( hRgn
, hrgnUpdate
, 0, RGN_COPY
);
797 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
801 wndPtr
->hrgnUpdate
= crop_rgn( 0, hrgnUpdate
, &r
);
802 OffsetRgn( wndPtr
->hrgnUpdate
, pt
.x
, pt
.y
);
805 else if( rectUpdate
)
807 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
808 OffsetRect( &r2
, pt
.x
, pt
.y
);
809 if( wndPtr
->hrgnUpdate
== 0 )
810 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
812 hRgn
= CreateRectRgnIndirect( &r2
);
814 else /* entire window or client depending on RDW_FRAME */
816 if( flags
& RDW_FRAME
)
818 if (wndPtr
->hrgnUpdate
) hRgn
= (HRGN
)1;
819 else wndPtr
->hrgnUpdate
= (HRGN
)1;
823 GETCLIENTRECTW( wndPtr
, r2
);
824 if( wndPtr
->hrgnUpdate
== 0 )
825 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
827 hRgn
= CreateRectRgnIndirect( &r2
);
831 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
833 /* In this we cannot leave with zero hRgn */
836 hRgn
= crop_rgn( hRgn
, hrgnUpdate
, &r
);
837 OffsetRgn( hRgn
, pt
.x
, pt
.y
);
838 GetRgnBox( hRgn
, &r2
);
839 if( IsRectEmpty( &r2
) ) goto END
;
841 else if( rectUpdate
)
843 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
844 OffsetRect( &r2
, pt
.x
, pt
.y
);
845 hRgn
= CreateRectRgnIndirect( &r2
);
847 else /* entire window or client depending on RDW_NOFRAME */
849 if( flags
& RDW_NOFRAME
)
853 GETCLIENTRECTW( wndPtr
, r2
);
854 hRgn
= CreateRectRgnIndirect( &r2
);
859 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
861 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
863 /* Erase/update windows, from now on hRgn is a scratch region */
865 hRgn
= RDW_Paint( wndPtr
, (hRgn
== (HRGN
)1) ? 0 : hRgn
, flags
, 0 );
868 if( hRgn
> (HRGN
)1 && (hRgn
!= hrgnUpdate
) )
870 WIN_ReleaseWndPtr(wndPtr
);
875 /***********************************************************************
876 * UpdateWindow (USER32.@)
878 BOOL WINAPI
UpdateWindow( HWND hwnd
)
880 return RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
884 /***********************************************************************
885 * InvalidateRgn (USER32.@)
887 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
889 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
893 /***********************************************************************
894 * InvalidateRect (USER32.@)
896 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
898 return RedrawWindow( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
902 /***********************************************************************
903 * ValidateRgn (USER32.@)
905 BOOL WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
907 return RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
911 /***********************************************************************
912 * ValidateRect (USER32.@)
914 BOOL WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
916 return RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
920 /***********************************************************************
921 * GetUpdateRect (USER32.@)
923 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
926 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
927 if (!wndPtr
) return FALSE
;
931 if (wndPtr
->hrgnUpdate
> (HRGN
)1)
933 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
934 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
939 GetRgnBox( hrgn
, rect
);
940 DeleteObject( hrgn
);
941 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
943 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
945 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
950 if( wndPtr
->hrgnUpdate
== (HRGN
)1 )
952 GetClientRect( hwnd
, rect
);
953 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
956 SetRectEmpty( rect
);
958 retvalue
= (wndPtr
->hrgnUpdate
>= (HRGN
)1);
960 WIN_ReleaseWndPtr(wndPtr
);
965 /***********************************************************************
966 * GetUpdateRgn (USER32.@)
968 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
971 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
972 if (!wndPtr
) return ERROR
;
974 if (wndPtr
->hrgnUpdate
== 0)
976 SetRectRgn( hrgn
, 0, 0, 0, 0 );
981 if (wndPtr
->hrgnUpdate
== (HRGN
)1)
983 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
984 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
985 retval
= SIMPLEREGION
;
989 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
990 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
991 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
993 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
995 WIN_ReleaseWndPtr(wndPtr
);
1000 /***********************************************************************
1001 * ExcludeUpdateRgn (USER32.@)
1003 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1008 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
1010 if (wndPtr
->hrgnUpdate
)
1013 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1014 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
1015 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
1016 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
1017 if( wndPtr
->hrgnUpdate
> (HRGN
)1 )
1019 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
1020 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
1021 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
1024 /* do ugly coordinate translations in dce.c */
1026 ret
= DCE_ExcludeRgn( hdc
, hwnd
, hrgn
);
1027 DeleteObject( hrgn
);
1028 WIN_ReleaseWndPtr(wndPtr
);
1031 WIN_ReleaseWndPtr(wndPtr
);
1032 return GetClipBox( hdc
, &rect
);
1037 /***********************************************************************
1038 * FillRect (USER.81)
1040 * The Win16 variant doesn't support special color brushes like
1041 * the Win32 one, despite the fact that Win16, as well as Win32,
1042 * supports special background brushes for a window class.
1044 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
1048 /* coordinates are logical so we cannot fast-check 'rect',
1049 * it will be done later in the PatBlt().
1052 if (!(prevBrush
= SelectObject( HDC_32(hdc
), HBRUSH_32(hbrush
) ))) return 0;
1053 PatBlt( HDC_32(hdc
), rect
->left
, rect
->top
,
1054 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1055 SelectObject( HDC_32(hdc
), prevBrush
);
1060 /***********************************************************************
1061 * FillRect (USER32.@)
1063 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1067 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1068 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1071 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1072 PatBlt( hdc
, rect
->left
, rect
->top
,
1073 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1074 SelectObject( hdc
, prevBrush
);
1079 /***********************************************************************
1080 * InvertRect (USER.82)
1082 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1084 PatBlt( HDC_32(hdc
), rect
->left
, rect
->top
,
1085 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1089 /***********************************************************************
1090 * InvertRect (USER32.@)
1092 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1094 return PatBlt( hdc
, rect
->left
, rect
->top
,
1095 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1100 /***********************************************************************
1101 * FrameRect (USER32.@)
1103 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1108 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1109 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1111 PatBlt( hdc
, r
.left
, r
.top
, 1,
1112 r
.bottom
- r
.top
, PATCOPY
);
1113 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1114 r
.bottom
- r
.top
, PATCOPY
);
1115 PatBlt( hdc
, r
.left
, r
.top
,
1116 r
.right
- r
.left
, 1, PATCOPY
);
1117 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1118 r
.right
- r
.left
, 1, PATCOPY
);
1120 SelectObject( hdc
, prevBrush
);
1125 /***********************************************************************
1126 * FrameRect (USER.83)
1128 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1131 CONV_RECT16TO32( rect16
, &rect
);
1132 return FrameRect( HDC_32(hdc
), &rect
, HBRUSH_32(hbrush
) );
1136 /***********************************************************************
1137 * DrawFocusRect (USER.466)
1139 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1142 CONV_RECT16TO32( rc
, &rect32
);
1143 DrawFocusRect( HDC_32(hdc
), &rect32
);
1147 /***********************************************************************
1148 * DrawFocusRect (USER32.@)
1150 * FIXME: PatBlt(PATINVERT) with background brush.
1152 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1155 HPEN hOldPen
, hNewPen
;
1156 INT oldDrawMode
, oldBkMode
;
1158 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1159 hNewPen
= CreatePen(PS_ALTERNATE
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1160 hOldPen
= SelectObject(hdc
, hNewPen
);
1161 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1162 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1164 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1166 SetBkMode(hdc
, oldBkMode
);
1167 SetROP2(hdc
, oldDrawMode
);
1168 SelectObject(hdc
, hOldPen
);
1169 DeleteObject(hNewPen
);
1170 SelectObject(hdc
, hOldBrush
);
1176 /**********************************************************************
1177 * DrawAnimatedRects (USER32.@)
1179 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1180 const RECT
* lprcFrom
,
1181 const RECT
* lprcTo
)
1183 FIXME_(win
)("(%p,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1188 /**********************************************************************
1189 * PAINTING_DrawStateJam
1191 * Jams in the requested type in the dc
1193 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1194 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1195 LPRECT rc
, UINT dtflags
, BOOL unicode
)
1200 INT cx
= rc
->right
- rc
->left
;
1201 INT cy
= rc
->bottom
- rc
->top
;
1206 case DST_PREFIXTEXT
:
1208 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1210 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1213 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1216 memdc
= CreateCompatibleDC(hdc
);
1217 if(!memdc
) return FALSE
;
1218 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1224 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1225 SelectObject(memdc
, hbmsave
);
1232 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1234 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1235 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1236 /* Restore origin */
1237 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1245 /**********************************************************************
1246 * PAINTING_DrawState()
1248 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
, DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1249 INT x
, INT y
, INT cx
, INT cy
, UINT flags
, BOOL unicode
)
1251 HBITMAP hbm
, hbmsave
;
1253 HBRUSH hbsave
, hbrtmp
= 0;
1256 UINT dtflags
= DT_NOCLIP
;
1258 UINT opcode
= flags
& 0xf;
1262 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1265 len
= strlenW((LPWSTR
)lp
);
1267 len
= strlen((LPSTR
)lp
);
1270 /* Find out what size the image has if not given by caller */
1274 CURSORICONINFO
*ici
;
1280 case DST_PREFIXTEXT
:
1282 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1284 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1285 if(!retval
) return FALSE
;
1289 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1290 if(!ici
) return FALSE
;
1292 s
.cy
= ici
->nHeight
;
1293 GlobalUnlock16((HGLOBAL16
)lp
);
1297 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1303 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1316 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1317 dtflags
|= DT_RIGHT
;
1318 if(opcode
== DST_TEXT
)
1319 dtflags
|= DT_NOPREFIX
;
1321 /* For DSS_NORMAL we just jam in the image and return */
1322 if((flags
& 0x7ff0) == DSS_NORMAL
)
1324 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1327 /* For all other states we need to convert the image to B/W in a local bitmap */
1328 /* before it is displayed */
1329 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1330 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1331 hbm
= NULL
; hbmsave
= NULL
;
1332 memdc
= NULL
; hbsave
= NULL
;
1333 retval
= FALSE
; /* assume failure */
1335 /* From here on we must use "goto cleanup" when something goes wrong */
1336 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1337 if(!hbm
) goto cleanup
;
1338 memdc
= CreateCompatibleDC(hdc
);
1339 if(!memdc
) goto cleanup
;
1340 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1341 if(!hbmsave
) goto cleanup
;
1342 rc
.left
= rc
.top
= 0;
1345 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1346 SetBkColor(memdc
, RGB(255, 255, 255));
1347 SetTextColor(memdc
, RGB(0, 0, 0));
1348 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1350 /* DST_COMPLEX may draw text as well,
1351 * so we must be sure that correct font is selected
1353 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1354 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1355 if(hfsave
) SelectObject(memdc
, hfsave
);
1356 if(!tmp
) goto cleanup
;
1358 /* This state cause the image to be dithered */
1359 if(flags
& DSS_UNION
)
1361 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1362 if(!hbsave
) goto cleanup
;
1363 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1364 SelectObject(memdc
, hbsave
);
1365 if(!tmp
) goto cleanup
;
1368 if (flags
& DSS_DISABLED
)
1369 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT
));
1370 else if (flags
& DSS_DEFAULT
)
1371 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1373 /* Draw light or dark shadow */
1374 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1376 if(!hbrtmp
) goto cleanup
;
1377 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1378 if(!hbsave
) goto cleanup
;
1379 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1380 SelectObject(hdc
, hbsave
);
1381 DeleteObject(hbrtmp
);
1385 if (flags
& DSS_DISABLED
)
1387 hbr
= hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1388 if(!hbrtmp
) goto cleanup
;
1392 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1395 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1397 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1399 retval
= TRUE
; /* We succeeded */
1402 SetTextColor(hdc
, fg
);
1403 SetBkColor(hdc
, bg
);
1405 if(hbsave
) SelectObject(hdc
, hbsave
);
1406 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1407 if(hbrtmp
) DeleteObject(hbrtmp
);
1408 if(hbm
) DeleteObject(hbm
);
1409 if(memdc
) DeleteDC(memdc
);
1414 /**********************************************************************
1415 * DrawStateA (USER32.@)
1417 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1418 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1419 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1421 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
);
1424 /**********************************************************************
1425 * DrawStateW (USER32.@)
1427 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1428 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1429 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1431 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
);
1435 /***********************************************************************
1436 * SelectPalette (Not a Windows API)
1438 HPALETTE WINAPI
SelectPalette( HDC hDC
, HPALETTE hPal
, BOOL bForceBackground
)
1440 WORD wBkgPalette
= 1;
1442 if (!bForceBackground
&& (hPal
!= GetStockObject(DEFAULT_PALETTE
)))
1444 HWND hwnd
= WindowFromDC( hDC
);
1447 HWND hForeground
= GetForegroundWindow();
1448 /* set primary palette if it's related to current active */
1449 if (hForeground
== hwnd
|| IsChild(hForeground
,hwnd
)) wBkgPalette
= 0;
1452 return pfnGDISelectPalette( hDC
, hPal
, wBkgPalette
);
1456 /***********************************************************************
1457 * UserRealizePalette (USER32.@)
1459 UINT WINAPI
UserRealizePalette( HDC hDC
)
1461 UINT realized
= pfnGDIRealizePalette( hDC
);
1463 /* do not send anything if no colors were changed */
1464 if (realized
&& IsDCCurrentPalette16( HDC_16(hDC
) ))
1466 /* send palette change notification */
1467 HWND hWnd
= WindowFromDC( hDC
);
1468 if (hWnd
) SendMessageA( HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0L);