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"
26 #include "wine/unicode.h"
27 #include "wine/server.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(win
);
36 WINE_DECLARE_DEBUG_CHANNEL(nonclient
);
38 /* client rect in window coordinates */
40 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
41 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
42 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
43 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
45 /* PAINT_RedrawWindow() control flags */
46 #define RDW_EX_DELAY_NCPAINT 0x0020
48 /* WIN_UpdateNCRgn() flags */
49 #define UNC_CHECK 0x0001
50 #define UNC_ENTIRE 0x0002
51 #define UNC_REGION 0x0004
52 #define UNC_UPDATE 0x0008
53 #define UNC_DELAY_NCPAINT 0x0010
54 #define UNC_IN_BEGINPAINT 0x0020
57 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
60 /* ### start build ### */
61 extern WORD CALLBACK
PAINTING_CallTo16_word_wlwww(DRAWSTATEPROC16
,WORD
,LONG
,WORD
,WORD
,WORD
);
62 /* ### stop build ### */
64 struct draw_state_info
70 /* callback for 16-bit DrawState functions */
71 static BOOL CALLBACK
draw_state_callback( HDC hdc
, LPARAM lparam
, WPARAM wparam
, int cx
, int cy
)
73 const struct draw_state_info
*info
= (struct draw_state_info
*)lparam
;
74 return PAINTING_CallTo16_word_wlwww( info
->proc
, hdc
, info
->param
, wparam
, cx
, cy
);
78 /***********************************************************************
81 * Add an increment (normally 1 or -1) to the current paint count of a window.
83 static void add_paint_count( HWND hwnd
, int incr
)
85 SERVER_START_REQ( inc_window_paint_count
)
89 wine_server_call( req
);
95 /***********************************************************************
96 * WIN_HaveToDelayNCPAINT
98 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
99 * is generated as soon as a region intersecting the non-client area
100 * of a window is invalidated.
102 * This technique will work fine for all windows whose parents
103 * have the WS_CLIPCHILDREN style. When the parents have that style,
104 * they are not going to override the contents of their children.
105 * However, when the parent doesn't have that style, Windows relies
106 * on a "painter's algorithm" to display the contents of the windows.
107 * That is, windows are painted from back to front. This includes the
110 * This method looks at the current state of a window to determine
111 * if the sending of the WM_NCPAINT message should be delayed until
112 * the BeginPaint call.
115 * wndPtr - A Locked window pointer to the window we're
117 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
118 * function. This is a shortcut for the cases when
119 * we already know when to avoid scanning all the
120 * parents of a window. If you already know that this
121 * window's NCPAINT should be delayed, set the
122 * UNC_DELAY_NCPAINT flag for this parameter.
124 * This shortcut behavior is implemented in the
125 * RDW_Paint() method.
128 static BOOL
WIN_HaveToDelayNCPAINT( HWND hwnd
, UINT uncFlags
)
131 * Test the shortcut first. (duh)
133 if (uncFlags
& UNC_DELAY_NCPAINT
)
137 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
138 * method only. This is another shortcut to avoid going
139 * up the parent's chain of the window to finally
140 * figure-out that none of them has an invalid region.
142 if (uncFlags
& UNC_IN_BEGINPAINT
)
146 * Scan all the parents of this window to find a window
147 * that doesn't have the WS_CLIPCHILDREN style and that
148 * has an invalid region.
150 while ((hwnd
= GetAncestor( hwnd
, GA_PARENT
)))
152 WND
* parentWnd
= WIN_FindWndPtr( hwnd
);
153 if (parentWnd
&& !(parentWnd
->dwStyle
& WS_CLIPCHILDREN
) && parentWnd
->hrgnUpdate
)
155 WIN_ReleaseWndPtr( parentWnd
);
158 WIN_ReleaseWndPtr( parentWnd
);
163 /***********************************************************************
167 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
168 * Crop hrgnUpdate to a client rect, especially if it 1.
169 * If UNC_REGION is set return update region for the client rect.
171 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
172 * The trick is that when the returned region handle may be different from hRgn.
173 * In this case the old hRgn must be considered gone. BUT, if the returned value
174 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
175 * a DC without extra clipping region.
177 static HRGN
WIN_UpdateNCRgn(WND
* wnd
, HRGN hRgn
, UINT uncFlags
)
183 TRACE_(nonclient
)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
184 wnd
->hwndSelf
, wnd
->hrgnUpdate
, hRgn
, uncFlags
, wnd
->flags
& WIN_NEEDS_NCPAINT
);
186 /* desktop window doesn't have a nonclient area */
187 if(wnd
->hwndSelf
== GetDesktopWindow())
189 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
190 if( wnd
->hrgnUpdate
> 1 )
191 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
194 hrgnRet
= wnd
->hrgnUpdate
;
199 if ((wnd
->hwndSelf
== GetForegroundWindow()) &&
200 !(wnd
->flags
& WIN_NCACTIVATED
) )
202 wnd
->flags
|= WIN_NCACTIVATED
;
203 uncFlags
|= UNC_ENTIRE
;
207 * If the window's non-client area needs to be painted,
209 if ( ( wnd
->flags
& WIN_NEEDS_NCPAINT
) &&
210 !WIN_HaveToDelayNCPAINT(wnd
->hwndSelf
, uncFlags
) )
214 wnd
->flags
&= ~WIN_NEEDS_NCPAINT
;
215 GETCLIENTRECTW( wnd
, r
);
217 TRACE_(nonclient
)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
218 r
.left
, r
.top
, r
.right
, r
.bottom
, wnd
->hrgnUpdate
);
219 if( wnd
->hrgnUpdate
> 1 )
221 /* Check if update rgn overlaps with nonclient area */
223 GetRgnBox( wnd
->hrgnUpdate
, &r2
);
224 UnionRect( &r3
, &r2
, &r
);
225 if( r3
.left
!= r
.left
|| r3
.top
!= r
.top
||
226 r3
.right
!= r
.right
|| r3
.bottom
!= r
.bottom
) /* it does */
228 /* crop hrgnUpdate, save old one in hClip - the only
229 * case that places a valid region handle in hClip */
231 hClip
= wnd
->hrgnUpdate
;
232 wnd
->hrgnUpdate
= REGION_CropRgn( hRgn
, hClip
, &r
, NULL
);
233 if( uncFlags
& UNC_REGION
) hrgnRet
= hClip
;
236 if( uncFlags
& UNC_CHECK
)
238 GetRgnBox( wnd
->hrgnUpdate
, &r3
);
239 if( IsRectEmpty( &r3
) )
241 /* delete the update region since all invalid
242 * parts were in the nonclient area */
244 DeleteObject( wnd
->hrgnUpdate
);
246 if(!(wnd
->flags
& WIN_INTERNAL_PAINT
))
247 add_paint_count( wnd
->hwndSelf
, -1 );
249 wnd
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
253 if(!hClip
&& wnd
->hrgnUpdate
) goto copyrgn
;
256 if( wnd
->hrgnUpdate
== 1 )/* entire window */
258 if( uncFlags
& UNC_UPDATE
) wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
259 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
260 uncFlags
|= UNC_ENTIRE
;
263 else /* no WM_NCPAINT unless forced */
265 if( wnd
->hrgnUpdate
> 1 )
268 if( uncFlags
& UNC_REGION
)
269 hrgnRet
= REGION_CropRgn( hRgn
, wnd
->hrgnUpdate
, NULL
, NULL
);
272 if( wnd
->hrgnUpdate
== 1 && (uncFlags
& UNC_UPDATE
) )
274 GETCLIENTRECTW( wnd
, r
);
275 wnd
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
276 if( uncFlags
& UNC_REGION
) hrgnRet
= 1;
280 if(!hClip
&& (uncFlags
& UNC_ENTIRE
) )
282 /* still don't do anything if there is no nonclient area */
283 hClip
= (memcmp( &wnd
->rectWindow
, &wnd
->rectClient
, sizeof(RECT
) ) != 0);
286 if( hClip
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
288 if ( hClip
== hrgnRet
&& hrgnRet
> 1 ) {
289 hClip
= CreateRectRgn( 0, 0, 0, 0 );
290 CombineRgn( hClip
, hrgnRet
, 0, RGN_COPY
);
293 SendMessageA( wnd
->hwndSelf
, WM_NCPAINT
, hClip
, 0L );
294 if( (hClip
> 1) && (hClip
!= hRgn
) && (hClip
!= hrgnRet
) )
295 DeleteObject( hClip
);
297 * Since all Window locks are suspended while processing the WM_NCPAINT
298 * we want to make sure the window still exists before continuing.
300 if (!IsWindow(wnd
->hwndSelf
))
302 DeleteObject(hrgnRet
);
307 TRACE_(nonclient
)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet
, hClip
, wnd
->hrgnUpdate
);
313 /***********************************************************************
314 * RDW_ValidateParent [RDW_UpdateRgns() helper]
316 * Validate the portions of parents that are covered by a validated child
319 static void RDW_ValidateParent(WND
*wndChild
)
324 if (wndChild
->hrgnUpdate
== 1 ) {
328 r
.right
= wndChild
->rectWindow
.right
- wndChild
->rectWindow
.left
;
329 r
.bottom
= wndChild
->rectWindow
.bottom
- wndChild
->rectWindow
.top
;
330 hrg
= CreateRectRgnIndirect( &r
);
332 hrg
= wndChild
->hrgnUpdate
;
334 parent
= GetAncestor( wndChild
->hwndSelf
, GA_PARENT
);
335 while (parent
&& parent
!= GetDesktopWindow())
337 WND
*wndParent
= WIN_FindWndPtr( parent
);
338 if (wndParent
&& !(wndParent
->dwStyle
& WS_CLIPCHILDREN
))
340 if (wndParent
->hrgnUpdate
!= 0)
343 RECT rect
, rectParent
;
344 if( wndParent
->hrgnUpdate
== 1 )
350 r
.right
= wndParent
->rectWindow
.right
- wndParent
->rectWindow
.left
;
351 r
.bottom
= wndParent
->rectWindow
.bottom
- wndParent
->rectWindow
.top
;
353 wndParent
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
355 /* we must offset the child region by the offset of the child rect in the parent */
356 GetWindowRect(wndParent
->hwndSelf
, &rectParent
);
357 GetWindowRect(wndChild
->hwndSelf
, &rect
);
358 ptOffset
.x
= rect
.left
- rectParent
.left
;
359 ptOffset
.y
= rect
.top
- rectParent
.top
;
360 OffsetRgn( hrg
, ptOffset
.x
, ptOffset
.y
);
361 CombineRgn( wndParent
->hrgnUpdate
, wndParent
->hrgnUpdate
, hrg
, RGN_DIFF
);
362 OffsetRgn( hrg
, -ptOffset
.x
, -ptOffset
.y
);
365 WIN_ReleaseWndPtr( wndParent
);
366 parent
= GetAncestor( parent
, GA_PARENT
);
368 if (hrg
!= wndChild
->hrgnUpdate
) DeleteObject( hrg
);
371 /***********************************************************************
372 * RDW_UpdateRgns [RedrawWindow() helper]
374 * Walks the window tree and adds/removes parts of the hRgn to/from update
375 * regions of windows that overlap it. Also, manages internal paint flags.
377 * NOTE: Walks the window tree so the caller must lock it.
378 * MUST preserve hRgn (can modify but then has to restore).
380 static void RDW_UpdateRgns( WND
* wndPtr
, HRGN hRgn
, UINT flags
, BOOL firstRecursLevel
)
383 * Called only when one of the following is set:
384 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
387 BOOL bHadOne
= wndPtr
->hrgnUpdate
&& hRgn
;
388 BOOL bChildren
= (!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
389 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) );
394 r
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
395 r
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
397 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr
->hwndSelf
, wndPtr
->hrgnUpdate
, hRgn
, flags
);
399 if( flags
& RDW_INVALIDATE
)
403 switch( wndPtr
->hrgnUpdate
)
406 CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_OR
);
409 wndPtr
->hrgnUpdate
= REGION_CropRgn( wndPtr
->hrgnUpdate
,
410 wndPtr
->hrgnUpdate
? wndPtr
->hrgnUpdate
: hRgn
,
414 GetRgnBox( wndPtr
->hrgnUpdate
, &r
);
415 if( IsRectEmpty( &r
) )
417 DeleteObject( wndPtr
->hrgnUpdate
);
418 wndPtr
->hrgnUpdate
= 0;
423 case 1: /* already an entire window */
429 if( wndPtr
->hrgnUpdate
> 1 )
430 DeleteObject( wndPtr
->hrgnUpdate
);
431 wndPtr
->hrgnUpdate
= 1;
434 hRgn
= wndPtr
->hrgnUpdate
; /* this is a trick that depends on code in PAINT_RedrawWindow() */
436 if( !bHadOne
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
437 add_paint_count( wndPtr
->hwndSelf
, 1 );
439 if (flags
& RDW_FRAME
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
440 if (flags
& RDW_ERASE
) wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
443 else if( flags
& RDW_VALIDATE
)
445 if( wndPtr
->hrgnUpdate
)
449 if( wndPtr
->hrgnUpdate
== 1 )
450 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r
);
452 if( CombineRgn( wndPtr
->hrgnUpdate
, wndPtr
->hrgnUpdate
, hRgn
, RGN_DIFF
)
455 DeleteObject( wndPtr
->hrgnUpdate
);
456 wndPtr
->hrgnUpdate
= 0;
459 else /* validate everything */
461 if( wndPtr
->hrgnUpdate
> 1 ) DeleteObject( wndPtr
->hrgnUpdate
);
462 wndPtr
->hrgnUpdate
= 0;
465 if( !wndPtr
->hrgnUpdate
)
467 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
468 if( !(wndPtr
->flags
& WIN_INTERNAL_PAINT
) )
469 add_paint_count( wndPtr
->hwndSelf
, -1 );
473 if (flags
& RDW_NOFRAME
) wndPtr
->flags
&= ~WIN_NEEDS_NCPAINT
;
474 if (flags
& RDW_NOERASE
) wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
478 if ((firstRecursLevel
) && (wndPtr
->hrgnUpdate
!= 0) && (flags
& RDW_UPDATENOW
))
479 RDW_ValidateParent(wndPtr
); /* validate parent covered by region */
481 /* in/validate child windows that intersect with the region if it
482 * is a valid handle. */
484 if( flags
& (RDW_INVALIDATE
| RDW_VALIDATE
) )
487 if( hRgn
> 1 && bChildren
&& (list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
489 POINT ptTotal
, prevOrigin
= {0,0};
493 ptClient
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
494 ptClient
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
496 for(i
= ptTotal
.x
= ptTotal
.y
= 0; list
[i
]; i
++)
498 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
500 if( wnd
->dwStyle
& WS_VISIBLE
)
504 r
.left
= wnd
->rectWindow
.left
+ ptClient
.x
;
505 r
.right
= wnd
->rectWindow
.right
+ ptClient
.x
;
506 r
.top
= wnd
->rectWindow
.top
+ ptClient
.y
;
507 r
.bottom
= wnd
->rectWindow
.bottom
+ ptClient
.y
;
509 ptOffset
.x
= r
.left
- prevOrigin
.x
;
510 ptOffset
.y
= r
.top
- prevOrigin
.y
;
511 OffsetRect( &r
, -ptTotal
.x
, -ptTotal
.y
);
513 if( RectInRegion( hRgn
, &r
) )
515 OffsetRgn( hRgn
, -ptOffset
.x
, -ptOffset
.y
);
516 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
517 prevOrigin
.x
= r
.left
+ ptTotal
.x
;
518 prevOrigin
.y
= r
.top
+ ptTotal
.y
;
519 ptTotal
.x
+= ptOffset
.x
;
520 ptTotal
.y
+= ptOffset
.y
;
523 WIN_ReleaseWndPtr( wnd
);
525 HeapFree( GetProcessHeap(), 0, list
);
526 OffsetRgn( hRgn
, ptTotal
.x
, ptTotal
.y
);
531 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
536 if ((list
= WIN_ListChildren( wndPtr
->hwndSelf
)))
539 for (i
= 0; list
[i
]; i
++)
541 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
543 if( wnd
->dwStyle
& WS_VISIBLE
)
544 RDW_UpdateRgns( wnd
, hRgn
, flags
, FALSE
);
545 WIN_ReleaseWndPtr( wnd
);
547 HeapFree( GetProcessHeap(), 0, list
);
553 /* Set/clear internal paint flag */
555 if (flags
& RDW_INTERNALPAINT
)
557 if ( !wndPtr
->hrgnUpdate
&& !(wndPtr
->flags
& WIN_INTERNAL_PAINT
))
558 add_paint_count( wndPtr
->hwndSelf
, 1 );
559 wndPtr
->flags
|= WIN_INTERNAL_PAINT
;
561 else if (flags
& RDW_NOINTERNALPAINT
)
563 if ( !wndPtr
->hrgnUpdate
&& (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
564 add_paint_count( wndPtr
->hwndSelf
, -1 );
565 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
569 /***********************************************************************
570 * RDW_Paint [RedrawWindow() helper]
572 * Walks the window tree and paints/erases windows that have
573 * nonzero update regions according to redraw flags. hrgn is a scratch
574 * region passed down during recursion. Must not be 1.
577 static HRGN
RDW_Paint( WND
* wndPtr
, HRGN hrgn
, UINT flags
, UINT ex
)
579 /* NOTE: wndPtr is locked by caller.
581 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
582 * SendMessage() calls. This is a comment inside DefWindowProc() source
585 * This message avoids lots of inter-app message traffic
586 * by switching to the other task and continuing the
590 * LOWORD(lParam) = hrgnClip
591 * HIWORD(lParam) = hwndSkip (not used; always NULL)
595 HWND hWnd
= wndPtr
->hwndSelf
;
596 BOOL bIcon
= ((wndPtr
->dwStyle
& WS_MINIMIZE
) && GetClassLongA(hWnd
, GCL_HICON
));
598 /* Erase/update the window itself ... */
600 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd
, wndPtr
->hrgnUpdate
, hrgn
, flags
);
603 * Check if this window should delay it's processing of WM_NCPAINT.
604 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
606 if ((ex
& RDW_EX_DELAY_NCPAINT
) || WIN_HaveToDelayNCPAINT(wndPtr
->hwndSelf
, 0) )
607 ex
|= RDW_EX_DELAY_NCPAINT
;
609 if (flags
& RDW_UPDATENOW
)
611 if (wndPtr
->hrgnUpdate
) /* wm_painticon wparam is 1 */
612 SendMessageW( hWnd
, (bIcon
) ? WM_PAINTICON
: WM_PAINT
, bIcon
, 0 );
614 else if (flags
& RDW_ERASENOW
)
616 UINT dcx
= DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
| DCX_WINDOWPAINT
| DCX_CACHE
;
619 hrgnRet
= WIN_UpdateNCRgn(wndPtr
,
621 UNC_REGION
| UNC_CHECK
|
622 ((ex
& RDW_EX_DELAY_NCPAINT
) ? UNC_DELAY_NCPAINT
: 0) );
626 if( hrgnRet
> 1 ) hrgn
= hrgnRet
; else hrgnRet
= 0; /* entire client */
627 if( wndPtr
->flags
& WIN_NEEDS_ERASEBKGND
)
629 if( bIcon
) dcx
|= DCX_WINDOW
;
632 OffsetRgn( hrgnRet
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
633 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
635 dcx
&= ~DCX_INTERSECTRGN
;
636 if (( hDC
= GetDCEx( hWnd
, hrgnRet
, dcx
)) )
638 if (SendMessageW( hWnd
, (bIcon
) ? WM_ICONERASEBKGND
: WM_ERASEBKGND
,
640 wndPtr
->flags
&= ~WIN_NEEDS_ERASEBKGND
;
641 ReleaseDC( hWnd
, hDC
);
647 if( !IsWindow(hWnd
) ) return hrgn
;
649 /* ... and its child windows */
651 if(!(flags
& RDW_NOCHILDREN
) && !(wndPtr
->dwStyle
& WS_MINIMIZE
) &&
652 ((flags
& RDW_ALLCHILDREN
) || !(wndPtr
->dwStyle
& WS_CLIPCHILDREN
)) )
656 if( (list
= WIN_ListChildren( wndPtr
->hwndSelf
)) )
658 for (phwnd
= list
; *phwnd
; phwnd
++)
660 if (!(wndPtr
= WIN_FindWndPtr( *phwnd
))) continue;
661 if ( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
662 (wndPtr
->hrgnUpdate
|| (wndPtr
->flags
& WIN_INTERNAL_PAINT
)) )
663 hrgn
= RDW_Paint( wndPtr
, hrgn
, flags
, ex
);
664 WIN_ReleaseWndPtr(wndPtr
);
666 HeapFree( GetProcessHeap(), 0, list
);
674 /***********************************************************************
675 * RedrawWindow (USER32.@)
677 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rectUpdate
,
678 HRGN hrgnUpdate
, UINT flags
)
685 if (!hwnd
) hwnd
= GetDesktopWindow();
687 /* check if the window or its parents are visible/not minimized */
689 if (!WIN_IsWindowDrawable( hwnd
, !(flags
& RDW_FRAME
) )) return TRUE
;
691 /* process pending events and messages before painting */
692 if (flags
& RDW_UPDATENOW
)
693 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 0, QS_ALLINPUT
);
695 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
700 GetRgnBox( hrgnUpdate
, &r
);
701 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
702 hwnd
, wndPtr
->hrgnUpdate
, hrgnUpdate
, r
.left
, r
.top
, r
.right
, r
.bottom
, flags
);
710 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
711 hwnd
, wndPtr
->hrgnUpdate
, rectUpdate
? "rect" : "NULL", r
.left
,
712 r
.top
, r
.right
, r
.bottom
, hrgnUpdate
, flags
);
716 /* prepare an update region in window coordinates */
718 if( flags
& RDW_FRAME
)
719 r
= wndPtr
->rectWindow
;
721 r
= wndPtr
->rectClient
;
723 pt
.x
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
724 pt
.y
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
725 OffsetRect( &r
, -wndPtr
->rectClient
.left
, -wndPtr
->rectClient
.top
);
727 if (flags
& RDW_INVALIDATE
) /* ------------------------- Invalidate */
729 /* If the window doesn't have hrgnUpdate we leave hRgn zero
730 * and put a new region straight into wndPtr->hrgnUpdate
731 * so that RDW_UpdateRgns() won't have to do any extra work.
736 if( wndPtr
->hrgnUpdate
)
737 hRgn
= REGION_CropRgn( 0, hrgnUpdate
, NULL
, &pt
);
739 wndPtr
->hrgnUpdate
= REGION_CropRgn( 0, hrgnUpdate
, &r
, &pt
);
741 else if( rectUpdate
)
743 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
744 OffsetRect( &r2
, pt
.x
, pt
.y
);
745 if( wndPtr
->hrgnUpdate
== 0 )
746 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
748 hRgn
= CreateRectRgnIndirect( &r2
);
750 else /* entire window or client depending on RDW_FRAME */
752 if( flags
& RDW_FRAME
)
754 if (wndPtr
->hrgnUpdate
) hRgn
= 1;
755 else wndPtr
->hrgnUpdate
= 1;
759 GETCLIENTRECTW( wndPtr
, r2
);
760 if( wndPtr
->hrgnUpdate
== 0 )
761 wndPtr
->hrgnUpdate
= CreateRectRgnIndirect( &r2
);
763 hRgn
= CreateRectRgnIndirect( &r2
);
767 else if (flags
& RDW_VALIDATE
) /* ------------------------- Validate */
769 /* In this we cannot leave with zero hRgn */
772 hRgn
= REGION_CropRgn( hRgn
, hrgnUpdate
, &r
, &pt
);
773 GetRgnBox( hRgn
, &r2
);
774 if( IsRectEmpty( &r2
) ) goto END
;
776 else if( rectUpdate
)
778 if( !IntersectRect( &r2
, &r
, rectUpdate
) ) goto END
;
779 OffsetRect( &r2
, pt
.x
, pt
.y
);
780 hRgn
= CreateRectRgnIndirect( &r2
);
782 else /* entire window or client depending on RDW_FRAME */
784 if( flags
& RDW_FRAME
)
788 GETCLIENTRECTW( wndPtr
, r2
);
789 hRgn
= CreateRectRgnIndirect( &r2
);
794 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
796 RDW_UpdateRgns( wndPtr
, hRgn
, flags
, TRUE
);
798 /* Erase/update windows, from now on hRgn is a scratch region */
800 hRgn
= RDW_Paint( wndPtr
, (hRgn
== 1) ? 0 : hRgn
, flags
, 0 );
803 if( hRgn
> 1 && (hRgn
!= hrgnUpdate
) )
805 WIN_ReleaseWndPtr(wndPtr
);
810 /***********************************************************************
811 * UpdateWindow (USER32.@)
813 void WINAPI
UpdateWindow( HWND hwnd
)
815 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
819 /***********************************************************************
820 * InvalidateRgn (USER32.@)
822 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
824 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
828 /***********************************************************************
829 * InvalidateRect (USER32.@)
831 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
833 return RedrawWindow( hwnd
, rect
, 0, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
837 /***********************************************************************
838 * ValidateRgn (USER32.@)
840 void WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
842 RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
846 /***********************************************************************
847 * ValidateRect (USER32.@)
849 void WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
851 RedrawWindow( hwnd
, rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
855 /***********************************************************************
856 * GetUpdateRect (USER32.@)
858 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
861 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
862 if (!wndPtr
) return FALSE
;
866 if (wndPtr
->hrgnUpdate
> 1)
868 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
869 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
)
874 GetRgnBox( hrgn
, rect
);
875 DeleteObject( hrgn
);
876 if (GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
) & CS_OWNDC
)
878 if (GetMapMode(wndPtr
->dce
->hDC
) != MM_TEXT
)
880 DPtoLP (wndPtr
->dce
->hDC
, (LPPOINT
)rect
, 2);
885 if( wndPtr
->hrgnUpdate
== 1 )
887 GetClientRect( hwnd
, rect
);
888 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
| RDW_NOCHILDREN
);
891 SetRectEmpty( rect
);
893 retvalue
= (wndPtr
->hrgnUpdate
>= 1);
895 WIN_ReleaseWndPtr(wndPtr
);
900 /***********************************************************************
901 * GetUpdateRgn (USER32.@)
903 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
906 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
907 if (!wndPtr
) return ERROR
;
909 if (wndPtr
->hrgnUpdate
== 0)
911 SetRectRgn( hrgn
, 0, 0, 0, 0 );
916 if (wndPtr
->hrgnUpdate
== 1)
918 SetRectRgn( hrgn
, 0, 0, wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
919 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
920 retval
= SIMPLEREGION
;
924 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
925 OffsetRgn( hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
926 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
928 if (erase
) RedrawWindow( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_NOCHILDREN
);
930 WIN_ReleaseWndPtr(wndPtr
);
935 /***********************************************************************
936 * ExcludeUpdateRgn (USER32.@)
938 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
943 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return ERROR
;
945 if (wndPtr
->hrgnUpdate
)
948 HRGN hrgn
= CreateRectRgn(wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
949 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
,
950 wndPtr
->rectWindow
.right
- wndPtr
->rectClient
.left
,
951 wndPtr
->rectWindow
.bottom
- wndPtr
->rectClient
.top
);
952 if( wndPtr
->hrgnUpdate
> 1 )
954 CombineRgn(hrgn
, wndPtr
->hrgnUpdate
, 0, RGN_COPY
);
955 OffsetRgn(hrgn
, wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
,
956 wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
);
959 /* do ugly coordinate translations in dce.c */
961 ret
= DCE_ExcludeRgn( hdc
, hwnd
, hrgn
);
962 DeleteObject( hrgn
);
963 WIN_ReleaseWndPtr(wndPtr
);
966 WIN_ReleaseWndPtr(wndPtr
);
967 return GetClipBox( hdc
, &rect
);
972 /***********************************************************************
975 * The Win16 variant doesn't support special color brushes like
976 * the Win32 one, despite the fact that Win16, as well as Win32,
977 * supports special background brushes for a window class.
979 INT16 WINAPI
FillRect16( HDC16 hdc
, const RECT16
*rect
, HBRUSH16 hbrush
)
983 /* coordinates are logical so we cannot fast-check 'rect',
984 * it will be done later in the PatBlt().
987 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
988 PatBlt( hdc
, rect
->left
, rect
->top
,
989 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
990 SelectObject( hdc
, prevBrush
);
995 /***********************************************************************
996 * FillRect (USER32.@)
998 INT WINAPI
FillRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1002 if (hbrush
<= (HBRUSH
) (COLOR_MAX
+ 1)) {
1003 hbrush
= GetSysColorBrush( (INT
) hbrush
- 1 );
1006 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1007 PatBlt( hdc
, rect
->left
, rect
->top
,
1008 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, PATCOPY
);
1009 SelectObject( hdc
, prevBrush
);
1014 /***********************************************************************
1015 * InvertRect (USER.82)
1017 void WINAPI
InvertRect16( HDC16 hdc
, const RECT16
*rect
)
1019 PatBlt( hdc
, rect
->left
, rect
->top
,
1020 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
, DSTINVERT
);
1024 /***********************************************************************
1025 * InvertRect (USER32.@)
1027 BOOL WINAPI
InvertRect( HDC hdc
, const RECT
*rect
)
1029 return PatBlt( hdc
, rect
->left
, rect
->top
,
1030 rect
->right
- rect
->left
, rect
->bottom
- rect
->top
,
1035 /***********************************************************************
1036 * FrameRect (USER32.@)
1038 INT WINAPI
FrameRect( HDC hdc
, const RECT
*rect
, HBRUSH hbrush
)
1043 if ( (r
.right
<= r
.left
) || (r
.bottom
<= r
.top
) ) return 0;
1044 if (!(prevBrush
= SelectObject( hdc
, hbrush
))) return 0;
1046 PatBlt( hdc
, r
.left
, r
.top
, 1,
1047 r
.bottom
- r
.top
, PATCOPY
);
1048 PatBlt( hdc
, r
.right
- 1, r
.top
, 1,
1049 r
.bottom
- r
.top
, PATCOPY
);
1050 PatBlt( hdc
, r
.left
, r
.top
,
1051 r
.right
- r
.left
, 1, PATCOPY
);
1052 PatBlt( hdc
, r
.left
, r
.bottom
- 1,
1053 r
.right
- r
.left
, 1, PATCOPY
);
1055 SelectObject( hdc
, prevBrush
);
1060 /***********************************************************************
1061 * FrameRect (USER.83)
1063 INT16 WINAPI
FrameRect16( HDC16 hdc
, const RECT16
*rect16
, HBRUSH16 hbrush
)
1066 CONV_RECT16TO32( rect16
, &rect
);
1067 return FrameRect( hdc
, &rect
, hbrush
);
1071 /***********************************************************************
1072 * DrawFocusRect (USER.466)
1074 void WINAPI
DrawFocusRect16( HDC16 hdc
, const RECT16
* rc
)
1077 CONV_RECT16TO32( rc
, &rect32
);
1078 DrawFocusRect( hdc
, &rect32
);
1082 /***********************************************************************
1083 * DrawFocusRect (USER32.@)
1085 * FIXME: PatBlt(PATINVERT) with background brush.
1087 BOOL WINAPI
DrawFocusRect( HDC hdc
, const RECT
* rc
)
1090 HPEN hOldPen
, hNewPen
;
1091 INT oldDrawMode
, oldBkMode
;
1093 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
1094 hNewPen
= CreatePen(PS_ALTERNATE
, 1, GetSysColor(COLOR_WINDOWTEXT
));
1095 hOldPen
= SelectObject(hdc
, hNewPen
);
1096 oldDrawMode
= SetROP2(hdc
, R2_XORPEN
);
1097 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1099 Rectangle(hdc
, rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
1101 SetBkMode(hdc
, oldBkMode
);
1102 SetROP2(hdc
, oldDrawMode
);
1103 SelectObject(hdc
, hOldPen
);
1104 DeleteObject(hNewPen
);
1105 SelectObject(hdc
, hOldBrush
);
1111 /**********************************************************************
1112 * DrawAnimatedRects (USER32.@)
1114 BOOL WINAPI
DrawAnimatedRects( HWND hwnd
, INT idAni
,
1115 const RECT
* lprcFrom
,
1116 const RECT
* lprcTo
)
1118 FIXME_(win
)("(0x%x,%d,%p,%p): stub\n",hwnd
,idAni
,lprcFrom
,lprcTo
);
1123 /**********************************************************************
1124 * PAINTING_DrawStateJam
1126 * Jams in the requested type in the dc
1128 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1129 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1130 LPRECT rc
, UINT dtflags
, BOOL unicode
)
1135 INT cx
= rc
->right
- rc
->left
;
1136 INT cy
= rc
->bottom
- rc
->top
;
1141 case DST_PREFIXTEXT
:
1143 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1145 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1148 return DrawIcon(hdc
, rc
->left
, rc
->top
, (HICON
)lp
);
1151 memdc
= CreateCompatibleDC(hdc
);
1152 if(!memdc
) return FALSE
;
1153 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1159 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1160 SelectObject(memdc
, hbmsave
);
1167 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1169 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1170 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1171 /* Restore origin */
1172 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1180 /**********************************************************************
1181 * PAINTING_DrawState()
1183 static BOOL
PAINTING_DrawState(HDC hdc
, HBRUSH hbr
, DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1184 INT x
, INT y
, INT cx
, INT cy
, UINT flags
, BOOL unicode
)
1186 HBITMAP hbm
, hbmsave
;
1188 HBRUSH hbsave
, hbrtmp
= 0;
1191 UINT dtflags
= DT_NOCLIP
;
1193 UINT opcode
= flags
& 0xf;
1197 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1200 len
= strlenW((LPWSTR
)lp
);
1202 len
= strlen((LPSTR
)lp
);
1205 /* Find out what size the image has if not given by caller */
1209 CURSORICONINFO
*ici
;
1215 case DST_PREFIXTEXT
:
1217 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1219 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1220 if(!retval
) return FALSE
;
1224 ici
= (CURSORICONINFO
*)GlobalLock16((HGLOBAL16
)lp
);
1225 if(!ici
) return FALSE
;
1227 s
.cy
= ici
->nHeight
;
1228 GlobalUnlock16((HGLOBAL16
)lp
);
1232 if(!GetObjectA((HBITMAP
)lp
, sizeof(bm
), &bm
))
1238 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1251 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1252 dtflags
|= DT_RIGHT
;
1253 if(opcode
== DST_TEXT
)
1254 dtflags
|= DT_NOPREFIX
;
1256 /* For DSS_NORMAL we just jam in the image and return */
1257 if((flags
& 0x7ff0) == DSS_NORMAL
)
1259 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1262 /* For all other states we need to convert the image to B/W in a local bitmap */
1263 /* before it is displayed */
1264 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1265 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1266 hbm
= (HBITMAP
)NULL
; hbmsave
= (HBITMAP
)NULL
;
1267 memdc
= (HDC
)NULL
; hbsave
= (HBRUSH
)NULL
;
1268 retval
= FALSE
; /* assume failure */
1270 /* From here on we must use "goto cleanup" when something goes wrong */
1271 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1272 if(!hbm
) goto cleanup
;
1273 memdc
= CreateCompatibleDC(hdc
);
1274 if(!memdc
) goto cleanup
;
1275 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1276 if(!hbmsave
) goto cleanup
;
1277 rc
.left
= rc
.top
= 0;
1280 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1281 SetBkColor(memdc
, RGB(255, 255, 255));
1282 SetTextColor(memdc
, RGB(0, 0, 0));
1283 hfsave
= (HFONT
)SelectObject(memdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1285 /* DST_COMPLEX may draw text as well,
1286 * so we must be sure that correct font is selected
1288 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1289 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1290 if(hfsave
) SelectObject(memdc
, hfsave
);
1291 if(!tmp
) goto cleanup
;
1293 /* This state cause the image to be dithered */
1294 if(flags
& DSS_UNION
)
1296 hbsave
= (HBRUSH
)SelectObject(memdc
, CACHE_GetPattern55AABrush());
1297 if(!hbsave
) goto cleanup
;
1298 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1299 SelectObject(memdc
, hbsave
);
1300 if(!tmp
) goto cleanup
;
1303 if (flags
& DSS_DISABLED
)
1304 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT
));
1305 else if (flags
& DSS_DEFAULT
)
1306 hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1308 /* Draw light or dark shadow */
1309 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1311 if(!hbrtmp
) goto cleanup
;
1312 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1313 if(!hbsave
) goto cleanup
;
1314 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1315 SelectObject(hdc
, hbsave
);
1316 DeleteObject(hbrtmp
);
1320 if (flags
& DSS_DISABLED
)
1322 hbr
= hbrtmp
= CreateSolidBrush(GetSysColor(COLOR_3DSHADOW
));
1323 if(!hbrtmp
) goto cleanup
;
1327 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1330 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1332 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1334 retval
= TRUE
; /* We succeeded */
1337 SetTextColor(hdc
, fg
);
1338 SetBkColor(hdc
, bg
);
1340 if(hbsave
) SelectObject(hdc
, hbsave
);
1341 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1342 if(hbrtmp
) DeleteObject(hbrtmp
);
1343 if(hbm
) DeleteObject(hbm
);
1344 if(memdc
) DeleteDC(memdc
);
1349 /**********************************************************************
1350 * DrawStateA (USER32.@)
1352 BOOL WINAPI
DrawStateA(HDC hdc
, HBRUSH hbr
,
1353 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1354 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1356 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, FALSE
);
1359 /**********************************************************************
1360 * DrawStateW (USER32.@)
1362 BOOL WINAPI
DrawStateW(HDC hdc
, HBRUSH hbr
,
1363 DRAWSTATEPROC func
, LPARAM ldata
, WPARAM wdata
,
1364 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1366 return PAINTING_DrawState(hdc
, hbr
, func
, ldata
, wdata
, x
, y
, cx
, cy
, flags
, TRUE
);
1370 /**********************************************************************
1371 * DrawState (USER.449)
1373 BOOL16 WINAPI
DrawState16( HDC16 hdc
, HBRUSH16 hbr
, DRAWSTATEPROC16 func
, LPARAM ldata
,
1374 WPARAM16 wdata
, INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, UINT16 flags
)
1376 struct draw_state_info info
;
1377 UINT opcode
= flags
& 0xf;
1379 if (opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
)
1381 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1382 if (!wdata
) wdata
= strlen( MapSL(ldata
) );
1386 if (!GetTextExtentPoint32A( hdc
, MapSL(ldata
), wdata
, &s
)) return FALSE
;
1393 return DrawStateA( hdc
, hbr
, draw_state_callback
, (LPARAM
)&info
, wdata
, x
, y
, cx
, cy
, flags
);
1397 /***********************************************************************
1398 * SelectPalette (USER.282)
1400 HPALETTE16 WINAPI
SelectPalette16( HDC16 hDC
, HPALETTE16 hPal
,
1401 BOOL16 bForceBackground
)
1403 WORD wBkgPalette
= 1;
1405 if (!bForceBackground
&& (hPal
!= GetStockObject(DEFAULT_PALETTE
)))
1407 HWND hwnd
= WindowFromDC( hDC
);
1410 HWND hForeground
= GetForegroundWindow();
1411 /* set primary palette if it's related to current active */
1412 if (hForeground
== hwnd
|| IsChild(hForeground
,hwnd
)) wBkgPalette
= 0;
1415 return GDISelectPalette16( hDC
, hPal
, wBkgPalette
);
1419 /***********************************************************************
1420 * RealizePalette (USER.283)
1422 UINT16 WINAPI
RealizePalette16( HDC16 hDC
)
1424 UINT16 realized
= GDIRealizePalette16( hDC
);
1426 /* do not send anything if no colors were changed */
1427 if (realized
&& IsDCCurrentPalette16( hDC
))
1429 /* send palette change notification */
1430 HWND hWnd
= WindowFromDC( hDC
);
1431 if (hWnd
) SendMessageA( HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0L);
1437 /***********************************************************************
1438 * UserRealizePalette (USER32.@)
1440 UINT WINAPI
UserRealizePalette( HDC hDC
)
1442 return RealizePalette16( hDC
);