Move the custom draw notifications into the Draw.*Item functions.
[wine.git] / windows / painting.c
blobba13de407302f1748b4d7259598d020fea3271d4
1 /*
2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1999 Alex Korobka
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
22 #include <string.h>
23 #include "windef.h"
24 #include "wingdi.h"
25 #include "wine/winuser16.h"
26 #include "wine/unicode.h"
27 #include "wine/server.h"
28 #include "gdi.h"
29 #include "user.h"
30 #include "win.h"
31 #include "queue.h"
32 #include "dce.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
56 /* Last COLOR id */
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
66 DRAWSTATEPROC16 proc;
67 LPARAM param;
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 /***********************************************************************
79 * add_paint_count
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 )
87 req->handle = hwnd;
88 req->incr = incr;
89 wine_server_call( req );
91 SERVER_END_REQ;
95 /***********************************************************************
96 * crop_rgn
98 * hSrc: Region to crop.
99 * lpRect: Clipping rectangle.
101 * hDst: Region to hold the result (a new region is created if it's 0).
102 * Allowed to be the same region as hSrc in which case everything
103 * will be done in place, with no memory reallocations.
105 * Returns: hDst if success, 0 otherwise.
107 static HRGN crop_rgn( HRGN hDst, HRGN hSrc, const RECT *rect )
109 HRGN h = CreateRectRgnIndirect( rect );
110 if (hDst == 0) hDst = h;
111 CombineRgn( hDst, hSrc, h, RGN_AND );
112 if (hDst != h) DeleteObject( h );
113 return hDst;
117 /***********************************************************************
118 * WIN_HaveToDelayNCPAINT
120 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
121 * is generated as soon as a region intersecting the non-client area
122 * of a window is invalidated.
124 * This technique will work fine for all windows whose parents
125 * have the WS_CLIPCHILDREN style. When the parents have that style,
126 * they are not going to override the contents of their children.
127 * However, when the parent doesn't have that style, Windows relies
128 * on a "painter's algorithm" to display the contents of the windows.
129 * That is, windows are painted from back to front. This includes the
130 * non-client area.
132 * This method looks at the current state of a window to determine
133 * if the sending of the WM_NCPAINT message should be delayed until
134 * the BeginPaint call.
136 * PARAMS:
137 * wndPtr - A Locked window pointer to the window we're
138 * examining.
139 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
140 * function. This is a shortcut for the cases when
141 * we already know when to avoid scanning all the
142 * parents of a window. If you already know that this
143 * window's NCPAINT should be delayed, set the
144 * UNC_DELAY_NCPAINT flag for this parameter.
146 * This shortcut behavior is implemented in the
147 * RDW_Paint() method.
150 static BOOL WIN_HaveToDelayNCPAINT( HWND hwnd, UINT uncFlags)
153 * Test the shortcut first. (duh)
155 if (uncFlags & UNC_DELAY_NCPAINT)
156 return TRUE;
159 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
160 * method only. This is another shortcut to avoid going
161 * up the parent's chain of the window to finally
162 * figure-out that none of them has an invalid region.
164 if (uncFlags & UNC_IN_BEGINPAINT)
165 return FALSE;
168 * Scan all the parents of this window to find a window
169 * that doesn't have the WS_CLIPCHILDREN style and that
170 * has an invalid region.
172 while ((hwnd = GetAncestor( hwnd, GA_PARENT )))
174 WND* parentWnd = WIN_FindWndPtr( hwnd );
175 if (parentWnd && !(parentWnd->dwStyle & WS_CLIPCHILDREN) && parentWnd->hrgnUpdate)
177 WIN_ReleaseWndPtr( parentWnd );
178 return TRUE;
180 WIN_ReleaseWndPtr( parentWnd );
182 return FALSE;
185 /***********************************************************************
186 * WIN_UpdateNCRgn
188 * Things to do:
189 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
190 * Crop hrgnUpdate to a client rect, especially if it 1.
191 * If UNC_REGION is set return update region for the client rect.
193 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
194 * The trick is that when the returned region handle may be different from hRgn.
195 * In this case the old hRgn must be considered gone. BUT, if the returned value
196 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
197 * a DC without extra clipping region.
199 static HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
201 RECT r;
202 HRGN hClip = 0;
203 HRGN hrgnRet = 0;
205 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
206 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
208 /* desktop window doesn't have a nonclient area */
209 if(wnd->hwndSelf == GetDesktopWindow())
211 wnd->flags &= ~WIN_NEEDS_NCPAINT;
212 if( wnd->hrgnUpdate > 1 )
214 if (!hRgn) hRgn = CreateRectRgn( 0, 0, 0, 0 );
215 CombineRgn( hRgn, wnd->hrgnUpdate, 0, RGN_COPY );
216 hrgnRet = hRgn;
218 else
220 hrgnRet = wnd->hrgnUpdate;
222 return hrgnRet;
225 if ((wnd->hwndSelf == GetForegroundWindow()) &&
226 !(wnd->flags & WIN_NCACTIVATED) )
228 wnd->flags |= WIN_NCACTIVATED;
229 uncFlags |= UNC_ENTIRE;
233 * If the window's non-client area needs to be painted,
235 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
236 !WIN_HaveToDelayNCPAINT(wnd->hwndSelf, uncFlags) )
238 RECT r2, r3;
240 wnd->flags &= ~WIN_NEEDS_NCPAINT;
241 GETCLIENTRECTW( wnd, r );
243 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
244 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
245 if( wnd->hrgnUpdate > 1 )
247 /* Check if update rgn overlaps with nonclient area */
249 GetRgnBox( wnd->hrgnUpdate, &r2 );
250 UnionRect( &r3, &r2, &r );
251 if( r3.left != r.left || r3.top != r.top ||
252 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
254 /* crop hrgnUpdate, save old one in hClip - the only
255 * case that places a valid region handle in hClip */
257 hClip = wnd->hrgnUpdate;
258 wnd->hrgnUpdate = crop_rgn( hRgn, hClip, &r );
259 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
262 if( uncFlags & UNC_CHECK )
264 GetRgnBox( wnd->hrgnUpdate, &r3 );
265 if( IsRectEmpty( &r3 ) )
267 /* delete the update region since all invalid
268 * parts were in the nonclient area */
270 DeleteObject( wnd->hrgnUpdate );
271 wnd->hrgnUpdate = 0;
272 if(!(wnd->flags & WIN_INTERNAL_PAINT))
273 add_paint_count( wnd->hwndSelf, -1 );
275 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
279 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
281 else
282 if( wnd->hrgnUpdate == 1 )/* entire window */
284 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
285 if( uncFlags & UNC_REGION ) hrgnRet = 1;
286 uncFlags |= UNC_ENTIRE;
289 else /* no WM_NCPAINT unless forced */
291 if( wnd->hrgnUpdate > 1 )
293 copyrgn:
294 if( uncFlags & UNC_REGION )
296 if (!hRgn) hRgn = CreateRectRgn( 0, 0, 0, 0 );
297 CombineRgn( hRgn, wnd->hrgnUpdate, 0, RGN_COPY );
298 hrgnRet = hRgn;
301 else
302 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
304 GETCLIENTRECTW( wnd, r );
305 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
306 if( uncFlags & UNC_REGION ) hrgnRet = 1;
310 if(!hClip && (uncFlags & UNC_ENTIRE) )
312 /* still don't do anything if there is no nonclient area */
313 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
316 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
318 if ( hClip == hrgnRet && hrgnRet > 1 ) {
319 hClip = CreateRectRgn( 0, 0, 0, 0 );
320 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
323 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
324 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
325 DeleteObject( hClip );
327 * Since all Window locks are suspended while processing the WM_NCPAINT
328 * we want to make sure the window still exists before continuing.
330 if (!IsWindow(wnd->hwndSelf))
332 DeleteObject(hrgnRet);
333 hrgnRet=0;
337 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
339 return hrgnRet;
343 /***********************************************************************
344 * RDW_ValidateParent [RDW_UpdateRgns() helper]
346 * Validate the portions of parents that are covered by a validated child
347 * wndPtr = child
349 static void RDW_ValidateParent(WND *wndChild)
351 HWND parent;
352 HRGN hrg;
354 if (wndChild->hrgnUpdate == 1 ) {
355 RECT r;
356 r.left = 0;
357 r.top = 0;
358 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
359 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
360 hrg = CreateRectRgnIndirect( &r );
361 } else
362 hrg = wndChild->hrgnUpdate;
364 parent = GetAncestor( wndChild->hwndSelf, GA_PARENT );
365 while (parent && parent != GetDesktopWindow())
367 WND *wndParent = WIN_FindWndPtr( parent );
368 if (wndParent && !(wndParent->dwStyle & WS_CLIPCHILDREN))
370 if (wndParent->hrgnUpdate != 0)
372 POINT ptOffset;
373 RECT rect, rectParent;
374 if( wndParent->hrgnUpdate == 1 )
376 RECT r;
378 r.left = 0;
379 r.top = 0;
380 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
381 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
383 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
385 /* we must offset the child region by the offset of the child rect in the parent */
386 GetWindowRect(wndParent->hwndSelf, &rectParent);
387 GetWindowRect(wndChild->hwndSelf, &rect);
388 ptOffset.x = rect.left - rectParent.left;
389 ptOffset.y = rect.top - rectParent.top;
390 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
391 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
392 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
395 WIN_ReleaseWndPtr( wndParent );
396 parent = GetAncestor( parent, GA_PARENT );
398 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
401 /***********************************************************************
402 * RDW_UpdateRgns [RedrawWindow() helper]
404 * Walks the window tree and adds/removes parts of the hRgn to/from update
405 * regions of windows that overlap it. Also, manages internal paint flags.
407 * NOTE: Walks the window tree so the caller must lock it.
408 * MUST preserve hRgn (can modify but then has to restore).
410 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
413 * Called only when one of the following is set:
414 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
417 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
418 BOOL bChildren = (!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
419 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
420 RECT r;
422 r.left = 0;
423 r.top = 0;
424 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
425 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
427 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
429 if( flags & RDW_INVALIDATE )
431 if( hRgn > 1 )
433 switch( wndPtr->hrgnUpdate )
435 default:
436 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
437 /* fall through */
438 case 0:
439 wndPtr->hrgnUpdate = crop_rgn( wndPtr->hrgnUpdate,
440 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
441 &r );
442 if( !bHadOne )
444 GetRgnBox( wndPtr->hrgnUpdate, &r );
445 if( IsRectEmpty( &r ) )
447 DeleteObject( wndPtr->hrgnUpdate );
448 wndPtr->hrgnUpdate = 0;
449 goto end;
452 break;
453 case 1: /* already an entire window */
454 break;
457 else if( hRgn == 1 )
459 if( wndPtr->hrgnUpdate > 1 )
460 DeleteObject( wndPtr->hrgnUpdate );
461 wndPtr->hrgnUpdate = 1;
463 else
464 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
466 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
467 add_paint_count( wndPtr->hwndSelf, 1 );
469 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
470 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
471 flags |= RDW_FRAME;
473 else if( flags & RDW_VALIDATE )
475 if( wndPtr->hrgnUpdate )
477 if( hRgn > 1 )
479 if( wndPtr->hrgnUpdate == 1 )
480 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
482 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
483 == NULLREGION )
485 DeleteObject( wndPtr->hrgnUpdate );
486 wndPtr->hrgnUpdate = 0;
489 else /* validate everything */
491 if( wndPtr->hrgnUpdate > 1 ) DeleteObject( wndPtr->hrgnUpdate );
492 wndPtr->hrgnUpdate = 0;
495 if( !wndPtr->hrgnUpdate )
497 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
498 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
499 add_paint_count( wndPtr->hwndSelf, -1 );
503 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
504 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
508 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
509 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
511 /* in/validate child windows that intersect with the region if it
512 * is a valid handle. */
514 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
516 HWND *list;
517 if( hRgn > 1 && bChildren && (list = WIN_ListChildren( wndPtr->hwndSelf )))
519 POINT ptTotal, prevOrigin = {0,0};
520 POINT ptClient;
521 INT i;
523 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
524 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
526 for(i = ptTotal.x = ptTotal.y = 0; list[i]; i++)
528 WND *wnd = WIN_FindWndPtr( list[i] );
529 if (!wnd) continue;
530 if( wnd->dwStyle & WS_VISIBLE )
532 POINT ptOffset;
534 r.left = wnd->rectWindow.left + ptClient.x;
535 r.right = wnd->rectWindow.right + ptClient.x;
536 r.top = wnd->rectWindow.top + ptClient.y;
537 r.bottom = wnd->rectWindow.bottom + ptClient.y;
539 ptOffset.x = r.left - prevOrigin.x;
540 ptOffset.y = r.top - prevOrigin.y;
541 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
543 if( RectInRegion( hRgn, &r ) )
545 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
546 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
547 prevOrigin.x = r.left + ptTotal.x;
548 prevOrigin.y = r.top + ptTotal.y;
549 ptTotal.x += ptOffset.x;
550 ptTotal.y += ptOffset.y;
553 WIN_ReleaseWndPtr( wnd );
555 HeapFree( GetProcessHeap(), 0, list );
556 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
557 bChildren = 0;
561 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
563 if( bChildren )
565 HWND *list;
566 if ((list = WIN_ListChildren( wndPtr->hwndSelf )))
568 INT i;
569 for (i = 0; list[i]; i++)
571 WND *wnd = WIN_FindWndPtr( list[i] );
572 if (!wnd) continue;
573 if( wnd->dwStyle & WS_VISIBLE )
574 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
575 WIN_ReleaseWndPtr( wnd );
577 HeapFree( GetProcessHeap(), 0, list );
581 end:
583 /* Set/clear internal paint flag */
585 if (flags & RDW_INTERNALPAINT)
587 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
588 add_paint_count( wndPtr->hwndSelf, 1 );
589 wndPtr->flags |= WIN_INTERNAL_PAINT;
591 else if (flags & RDW_NOINTERNALPAINT)
593 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
594 add_paint_count( wndPtr->hwndSelf, -1 );
595 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
599 /***********************************************************************
600 * RDW_Paint [RedrawWindow() helper]
602 * Walks the window tree and paints/erases windows that have
603 * nonzero update regions according to redraw flags. hrgn is a scratch
604 * region passed down during recursion. Must not be 1.
607 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
609 /* NOTE: wndPtr is locked by caller.
611 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
612 * SendMessage() calls. This is a comment inside DefWindowProc() source
613 * from 16-bit SDK:
615 * This message avoids lots of inter-app message traffic
616 * by switching to the other task and continuing the
617 * recursion there.
619 * wParam = flags
620 * LOWORD(lParam) = hrgnClip
621 * HIWORD(lParam) = hwndSkip (not used; always NULL)
624 HDC hDC;
625 HWND hWnd = wndPtr->hwndSelf;
626 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassLongA(hWnd, GCL_HICON));
628 /* Erase/update the window itself ... */
630 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
633 * Check if this window should delay it's processing of WM_NCPAINT.
634 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
636 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr->hwndSelf, 0) )
637 ex |= RDW_EX_DELAY_NCPAINT;
639 if (flags & RDW_UPDATENOW)
641 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
642 SendMessageW( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
644 else if (flags & RDW_ERASENOW)
646 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
647 HRGN hrgnRet;
649 hrgnRet = WIN_UpdateNCRgn(wndPtr,
650 hrgn,
651 UNC_REGION | UNC_CHECK |
652 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
654 if( hrgnRet )
656 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
657 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
659 if( bIcon ) dcx |= DCX_WINDOW;
660 else
661 if( hrgnRet )
662 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
663 wndPtr->rectWindow.top - wndPtr->rectClient.top);
664 else
665 dcx &= ~DCX_INTERSECTRGN;
666 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
668 if (SendMessageW( hWnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
669 (WPARAM)hDC, 0 ))
670 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
671 ReleaseDC( hWnd, hDC );
677 if( !IsWindow(hWnd) ) return hrgn;
679 /* ... and its child windows */
681 if(!(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE) &&
682 ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
684 HWND *list, *phwnd;
686 if( (list = WIN_ListChildren( wndPtr->hwndSelf )) )
688 for (phwnd = list; *phwnd; phwnd++)
690 if (!(wndPtr = WIN_FindWndPtr( *phwnd ))) continue;
691 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
692 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
693 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
694 WIN_ReleaseWndPtr(wndPtr);
696 HeapFree( GetProcessHeap(), 0, list );
700 return hrgn;
704 /***********************************************************************
705 * RedrawWindow (USER32.@)
707 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
708 HRGN hrgnUpdate, UINT flags )
710 HRGN hRgn = 0;
711 RECT r, r2;
712 POINT pt;
713 WND* wndPtr;
715 if (!hwnd) hwnd = GetDesktopWindow();
717 /* check if the window or its parents are visible/not minimized */
719 if (!WIN_IsWindowDrawable( hwnd, !(flags & RDW_FRAME) )) return TRUE;
721 /* process pending events and messages before painting */
722 if (flags & RDW_UPDATENOW)
723 MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_ALLINPUT );
725 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
726 if (TRACE_ON(win))
728 if( hrgnUpdate )
730 GetRgnBox( hrgnUpdate, &r );
731 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
732 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags );
734 else
736 if( rectUpdate )
737 r = *rectUpdate;
738 else
739 SetRectEmpty( &r );
740 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
741 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
742 r.top, r.right, r.bottom, hrgnUpdate, flags );
746 /* prepare an update region in window coordinates */
748 if (((flags & (RDW_INVALIDATE|RDW_FRAME)) == (RDW_INVALIDATE|RDW_FRAME)) ||
749 ((flags & (RDW_VALIDATE|RDW_NOFRAME)) == (RDW_VALIDATE|RDW_NOFRAME)))
750 r = wndPtr->rectWindow;
751 else
752 r = wndPtr->rectClient;
754 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
755 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
756 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
758 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
760 /* If the window doesn't have hrgnUpdate we leave hRgn zero
761 * and put a new region straight into wndPtr->hrgnUpdate
762 * so that RDW_UpdateRgns() won't have to do any extra work.
765 if( hrgnUpdate )
767 if( wndPtr->hrgnUpdate )
769 hRgn = CreateRectRgn( 0, 0, 0, 0 );
770 CombineRgn( hRgn, hrgnUpdate, 0, RGN_COPY );
771 OffsetRgn( hRgn, pt.x, pt.y );
773 else
775 wndPtr->hrgnUpdate = crop_rgn( 0, hrgnUpdate, &r );
776 OffsetRgn( wndPtr->hrgnUpdate, pt.x, pt.y );
779 else if( rectUpdate )
781 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
782 OffsetRect( &r2, pt.x, pt.y );
783 if( wndPtr->hrgnUpdate == 0 )
784 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
785 else
786 hRgn = CreateRectRgnIndirect( &r2 );
788 else /* entire window or client depending on RDW_FRAME */
790 if( flags & RDW_FRAME )
792 if (wndPtr->hrgnUpdate) hRgn = 1;
793 else wndPtr->hrgnUpdate = 1;
795 else
797 GETCLIENTRECTW( wndPtr, r2 );
798 if( wndPtr->hrgnUpdate == 0 )
799 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
800 else
801 hRgn = CreateRectRgnIndirect( &r2 );
805 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
807 /* In this we cannot leave with zero hRgn */
808 if( hrgnUpdate )
810 hRgn = crop_rgn( hRgn, hrgnUpdate, &r );
811 OffsetRgn( hRgn, pt.x, pt.y );
812 GetRgnBox( hRgn, &r2 );
813 if( IsRectEmpty( &r2 ) ) goto END;
815 else if( rectUpdate )
817 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
818 OffsetRect( &r2, pt.x, pt.y );
819 hRgn = CreateRectRgnIndirect( &r2 );
821 else /* entire window or client depending on RDW_NOFRAME */
823 if( flags & RDW_NOFRAME )
824 hRgn = 1;
825 else
827 GETCLIENTRECTW( wndPtr, r2 );
828 hRgn = CreateRectRgnIndirect( &r2 );
833 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
835 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
837 /* Erase/update windows, from now on hRgn is a scratch region */
839 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, 0 );
841 END:
842 if( hRgn > 1 && (hRgn != hrgnUpdate) )
843 DeleteObject(hRgn );
844 WIN_ReleaseWndPtr(wndPtr);
845 return TRUE;
849 /***********************************************************************
850 * UpdateWindow (USER32.@)
852 void WINAPI UpdateWindow( HWND hwnd )
854 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
858 /***********************************************************************
859 * InvalidateRgn (USER32.@)
861 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
863 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
867 /***********************************************************************
868 * InvalidateRect (USER32.@)
870 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
872 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
876 /***********************************************************************
877 * ValidateRgn (USER32.@)
879 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
881 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
885 /***********************************************************************
886 * ValidateRect (USER32.@)
888 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
890 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
894 /***********************************************************************
895 * GetUpdateRect (USER32.@)
897 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
899 BOOL retvalue;
900 WND * wndPtr = WIN_FindWndPtr( hwnd );
901 if (!wndPtr) return FALSE;
903 if (rect)
905 if (wndPtr->hrgnUpdate > 1)
907 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
908 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
910 retvalue = FALSE;
911 goto END;
913 GetRgnBox( hrgn, rect );
914 DeleteObject( hrgn );
915 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
917 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
919 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
923 else
924 if( wndPtr->hrgnUpdate == 1 )
926 GetClientRect( hwnd, rect );
927 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
929 else
930 SetRectEmpty( rect );
932 retvalue = (wndPtr->hrgnUpdate >= 1);
933 END:
934 WIN_ReleaseWndPtr(wndPtr);
935 return retvalue;
939 /***********************************************************************
940 * GetUpdateRgn (USER32.@)
942 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
944 INT retval;
945 WND * wndPtr = WIN_FindWndPtr( hwnd );
946 if (!wndPtr) return ERROR;
948 if (wndPtr->hrgnUpdate == 0)
950 SetRectRgn( hrgn, 0, 0, 0, 0 );
951 retval = NULLREGION;
952 goto END;
954 else
955 if (wndPtr->hrgnUpdate == 1)
957 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
958 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
959 retval = SIMPLEREGION;
961 else
963 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
964 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
965 wndPtr->rectWindow.top - wndPtr->rectClient.top );
967 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
968 END:
969 WIN_ReleaseWndPtr(wndPtr);
970 return retval;
974 /***********************************************************************
975 * ExcludeUpdateRgn (USER32.@)
977 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
979 RECT rect;
980 WND * wndPtr;
982 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
984 if (wndPtr->hrgnUpdate)
986 INT ret;
987 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
988 wndPtr->rectWindow.top - wndPtr->rectClient.top,
989 wndPtr->rectWindow.right - wndPtr->rectClient.left,
990 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
991 if( wndPtr->hrgnUpdate > 1 )
993 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
994 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
995 wndPtr->rectWindow.top - wndPtr->rectClient.top );
998 /* do ugly coordinate translations in dce.c */
1000 ret = DCE_ExcludeRgn( hdc, hwnd, hrgn );
1001 DeleteObject( hrgn );
1002 WIN_ReleaseWndPtr(wndPtr);
1003 return ret;
1005 WIN_ReleaseWndPtr(wndPtr);
1006 return GetClipBox( hdc, &rect );
1011 /***********************************************************************
1012 * FillRect (USER.81)
1013 * NOTE
1014 * The Win16 variant doesn't support special color brushes like
1015 * the Win32 one, despite the fact that Win16, as well as Win32,
1016 * supports special background brushes for a window class.
1018 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1020 HBRUSH prevBrush;
1022 /* coordinates are logical so we cannot fast-check 'rect',
1023 * it will be done later in the PatBlt().
1026 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1027 PatBlt( hdc, rect->left, rect->top,
1028 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1029 SelectObject( hdc, prevBrush );
1030 return 1;
1034 /***********************************************************************
1035 * FillRect (USER32.@)
1037 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1039 HBRUSH prevBrush;
1041 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1042 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1045 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1046 PatBlt( hdc, rect->left, rect->top,
1047 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1048 SelectObject( hdc, prevBrush );
1049 return 1;
1053 /***********************************************************************
1054 * InvertRect (USER.82)
1056 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1058 PatBlt( hdc, rect->left, rect->top,
1059 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1063 /***********************************************************************
1064 * InvertRect (USER32.@)
1066 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1068 return PatBlt( hdc, rect->left, rect->top,
1069 rect->right - rect->left, rect->bottom - rect->top,
1070 DSTINVERT );
1074 /***********************************************************************
1075 * FrameRect (USER32.@)
1077 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1079 HBRUSH prevBrush;
1080 RECT r = *rect;
1082 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1083 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1085 PatBlt( hdc, r.left, r.top, 1,
1086 r.bottom - r.top, PATCOPY );
1087 PatBlt( hdc, r.right - 1, r.top, 1,
1088 r.bottom - r.top, PATCOPY );
1089 PatBlt( hdc, r.left, r.top,
1090 r.right - r.left, 1, PATCOPY );
1091 PatBlt( hdc, r.left, r.bottom - 1,
1092 r.right - r.left, 1, PATCOPY );
1094 SelectObject( hdc, prevBrush );
1095 return TRUE;
1099 /***********************************************************************
1100 * FrameRect (USER.83)
1102 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1104 RECT rect;
1105 CONV_RECT16TO32( rect16, &rect );
1106 return FrameRect( hdc, &rect, hbrush );
1110 /***********************************************************************
1111 * DrawFocusRect (USER.466)
1113 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1115 RECT rect32;
1116 CONV_RECT16TO32( rc, &rect32 );
1117 DrawFocusRect( hdc, &rect32 );
1121 /***********************************************************************
1122 * DrawFocusRect (USER32.@)
1124 * FIXME: PatBlt(PATINVERT) with background brush.
1126 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1128 HBRUSH hOldBrush;
1129 HPEN hOldPen, hNewPen;
1130 INT oldDrawMode, oldBkMode;
1132 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1133 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1134 hOldPen = SelectObject(hdc, hNewPen);
1135 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1136 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1138 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1140 SetBkMode(hdc, oldBkMode);
1141 SetROP2(hdc, oldDrawMode);
1142 SelectObject(hdc, hOldPen);
1143 DeleteObject(hNewPen);
1144 SelectObject(hdc, hOldBrush);
1146 return TRUE;
1150 /**********************************************************************
1151 * DrawAnimatedRects (USER32.@)
1153 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1154 const RECT* lprcFrom,
1155 const RECT* lprcTo )
1157 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1158 return TRUE;
1162 /**********************************************************************
1163 * PAINTING_DrawStateJam
1165 * Jams in the requested type in the dc
1167 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1168 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1169 LPRECT rc, UINT dtflags, BOOL unicode )
1171 HDC memdc;
1172 HBITMAP hbmsave;
1173 BOOL retval;
1174 INT cx = rc->right - rc->left;
1175 INT cy = rc->bottom - rc->top;
1177 switch(opcode)
1179 case DST_TEXT:
1180 case DST_PREFIXTEXT:
1181 if(unicode)
1182 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1183 else
1184 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1186 case DST_ICON:
1187 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1189 case DST_BITMAP:
1190 memdc = CreateCompatibleDC(hdc);
1191 if(!memdc) return FALSE;
1192 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1193 if(!hbmsave)
1195 DeleteDC(memdc);
1196 return FALSE;
1198 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1199 SelectObject(memdc, hbmsave);
1200 DeleteDC(memdc);
1201 return retval;
1203 case DST_COMPLEX:
1204 if(func) {
1205 BOOL bRet;
1206 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1208 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1209 bRet = func(hdc, lp, wp, cx, cy);
1210 /* Restore origin */
1211 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1212 return bRet;
1213 } else
1214 return FALSE;
1216 return FALSE;
1219 /**********************************************************************
1220 * PAINTING_DrawState()
1222 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1223 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1225 HBITMAP hbm, hbmsave;
1226 HFONT hfsave;
1227 HBRUSH hbsave, hbrtmp = 0;
1228 HDC memdc;
1229 RECT rc;
1230 UINT dtflags = DT_NOCLIP;
1231 COLORREF fg, bg;
1232 UINT opcode = flags & 0xf;
1233 INT len = wp;
1234 BOOL retval, tmp;
1236 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1238 if(unicode)
1239 len = strlenW((LPWSTR)lp);
1240 else
1241 len = strlen((LPSTR)lp);
1244 /* Find out what size the image has if not given by caller */
1245 if(!cx || !cy)
1247 SIZE s;
1248 CURSORICONINFO *ici;
1249 BITMAP bm;
1251 switch(opcode)
1253 case DST_TEXT:
1254 case DST_PREFIXTEXT:
1255 if(unicode)
1256 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1257 else
1258 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1259 if(!retval) return FALSE;
1260 break;
1262 case DST_ICON:
1263 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1264 if(!ici) return FALSE;
1265 s.cx = ici->nWidth;
1266 s.cy = ici->nHeight;
1267 GlobalUnlock16((HGLOBAL16)lp);
1268 break;
1270 case DST_BITMAP:
1271 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1272 return FALSE;
1273 s.cx = bm.bmWidth;
1274 s.cy = bm.bmHeight;
1275 break;
1277 case DST_COMPLEX: /* cx and cy must be set in this mode */
1278 return FALSE;
1281 if(!cx) cx = s.cx;
1282 if(!cy) cy = s.cy;
1285 rc.left = x;
1286 rc.top = y;
1287 rc.right = x + cx;
1288 rc.bottom = y + cy;
1290 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1291 dtflags |= DT_RIGHT;
1292 if(opcode == DST_TEXT)
1293 dtflags |= DT_NOPREFIX;
1295 /* For DSS_NORMAL we just jam in the image and return */
1296 if((flags & 0x7ff0) == DSS_NORMAL)
1298 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1301 /* For all other states we need to convert the image to B/W in a local bitmap */
1302 /* before it is displayed */
1303 fg = SetTextColor(hdc, RGB(0, 0, 0));
1304 bg = SetBkColor(hdc, RGB(255, 255, 255));
1305 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1306 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1307 retval = FALSE; /* assume failure */
1309 /* From here on we must use "goto cleanup" when something goes wrong */
1310 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1311 if(!hbm) goto cleanup;
1312 memdc = CreateCompatibleDC(hdc);
1313 if(!memdc) goto cleanup;
1314 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1315 if(!hbmsave) goto cleanup;
1316 rc.left = rc.top = 0;
1317 rc.right = cx;
1318 rc.bottom = cy;
1319 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1320 SetBkColor(memdc, RGB(255, 255, 255));
1321 SetTextColor(memdc, RGB(0, 0, 0));
1322 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1324 /* DST_COMPLEX may draw text as well,
1325 * so we must be sure that correct font is selected
1327 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1328 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1329 if(hfsave) SelectObject(memdc, hfsave);
1330 if(!tmp) goto cleanup;
1332 /* This state cause the image to be dithered */
1333 if(flags & DSS_UNION)
1335 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1336 if(!hbsave) goto cleanup;
1337 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1338 SelectObject(memdc, hbsave);
1339 if(!tmp) goto cleanup;
1342 if (flags & DSS_DISABLED)
1343 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1344 else if (flags & DSS_DEFAULT)
1345 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1347 /* Draw light or dark shadow */
1348 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1350 if(!hbrtmp) goto cleanup;
1351 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1352 if(!hbsave) goto cleanup;
1353 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1354 SelectObject(hdc, hbsave);
1355 DeleteObject(hbrtmp);
1356 hbrtmp = 0;
1359 if (flags & DSS_DISABLED)
1361 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1362 if(!hbrtmp) goto cleanup;
1364 else if (!hbr)
1366 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1369 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1371 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1373 retval = TRUE; /* We succeeded */
1375 cleanup:
1376 SetTextColor(hdc, fg);
1377 SetBkColor(hdc, bg);
1379 if(hbsave) SelectObject(hdc, hbsave);
1380 if(hbmsave) SelectObject(memdc, hbmsave);
1381 if(hbrtmp) DeleteObject(hbrtmp);
1382 if(hbm) DeleteObject(hbm);
1383 if(memdc) DeleteDC(memdc);
1385 return retval;
1388 /**********************************************************************
1389 * DrawStateA (USER32.@)
1391 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1392 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1393 INT x, INT y, INT cx, INT cy, UINT flags)
1395 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1398 /**********************************************************************
1399 * DrawStateW (USER32.@)
1401 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1402 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1403 INT x, INT y, INT cx, INT cy, UINT flags)
1405 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);
1409 /**********************************************************************
1410 * DrawState (USER.449)
1412 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1413 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1415 struct draw_state_info info;
1416 UINT opcode = flags & 0xf;
1418 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1420 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1421 if (!wdata) wdata = strlen( MapSL(ldata) );
1422 if (!cx || !cy)
1424 SIZE s;
1425 if (!GetTextExtentPoint32A( hdc, MapSL(ldata), wdata, &s )) return FALSE;
1426 if (!cx) cx = s.cx;
1427 if (!cy) cy = s.cy;
1430 info.proc = func;
1431 info.param = ldata;
1432 return DrawStateA( hdc, hbr, draw_state_callback, (LPARAM)&info, wdata, x, y, cx, cy, flags );
1436 /***********************************************************************
1437 * SelectPalette (USER.282)
1439 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1440 BOOL16 bForceBackground )
1442 WORD wBkgPalette = 1;
1444 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1446 HWND hwnd = WindowFromDC( hDC );
1447 if (hwnd)
1449 HWND hForeground = GetForegroundWindow();
1450 /* set primary palette if it's related to current active */
1451 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1454 return GDISelectPalette16( hDC, hPal, wBkgPalette);
1458 /***********************************************************************
1459 * RealizePalette (USER.283)
1461 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1463 UINT16 realized = GDIRealizePalette16( hDC );
1465 /* do not send anything if no colors were changed */
1466 if (realized && IsDCCurrentPalette16( hDC ))
1468 /* send palette change notification */
1469 HWND hWnd = WindowFromDC( hDC );
1470 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0L);
1472 return realized;
1476 /***********************************************************************
1477 * UserRealizePalette (USER32.@)
1479 UINT WINAPI UserRealizePalette( HDC hDC )
1481 return RealizePalette16( hDC );