user32: Set the DC layout to mirrored when the window has the WS_EX_LAYOUTRTL style.
[wine.git] / dlls / user32 / painting.c
blob1b0cc3df08ae4db7c497e26b3bc2813d1534f201
1 /*
2 * Window painting functions
4 * Copyright 1993, 1994, 1995, 2001, 2004, 2005, 2008 Alexandre Julliard
5 * Copyright 1996, 1997, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "wine/server.h"
36 #include "win.h"
37 #include "user_private.h"
38 #include "controls.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
45 struct dce
47 struct list entry; /* entry in global DCE list */
48 HDC hdc;
49 HWND hwnd;
50 HRGN clip_rgn;
51 DWORD flags;
52 LONG count; /* usage count; 0 or 1 for cache DCEs, always 1 for window DCEs,
53 always >= 1 for class DCEs */
56 static struct list dce_list = LIST_INIT(dce_list);
58 static BOOL CALLBACK dc_hook( HDC hDC, WORD code, DWORD_PTR data, LPARAM lParam );
60 static const WCHAR displayW[] = { 'D','I','S','P','L','A','Y',0 };
63 /***********************************************************************
64 * dump_rdw_flags
66 static void dump_rdw_flags(UINT flags)
68 TRACE("flags:");
69 if (flags & RDW_INVALIDATE) TRACE(" RDW_INVALIDATE");
70 if (flags & RDW_INTERNALPAINT) TRACE(" RDW_INTERNALPAINT");
71 if (flags & RDW_ERASE) TRACE(" RDW_ERASE");
72 if (flags & RDW_VALIDATE) TRACE(" RDW_VALIDATE");
73 if (flags & RDW_NOINTERNALPAINT) TRACE(" RDW_NOINTERNALPAINT");
74 if (flags & RDW_NOERASE) TRACE(" RDW_NOERASE");
75 if (flags & RDW_NOCHILDREN) TRACE(" RDW_NOCHILDREN");
76 if (flags & RDW_ALLCHILDREN) TRACE(" RDW_ALLCHILDREN");
77 if (flags & RDW_UPDATENOW) TRACE(" RDW_UPDATENOW");
78 if (flags & RDW_ERASENOW) TRACE(" RDW_ERASENOW");
79 if (flags & RDW_FRAME) TRACE(" RDW_FRAME");
80 if (flags & RDW_NOFRAME) TRACE(" RDW_NOFRAME");
82 #define RDW_FLAGS \
83 (RDW_INVALIDATE | \
84 RDW_INTERNALPAINT | \
85 RDW_ERASE | \
86 RDW_VALIDATE | \
87 RDW_NOINTERNALPAINT | \
88 RDW_NOERASE | \
89 RDW_NOCHILDREN | \
90 RDW_ALLCHILDREN | \
91 RDW_UPDATENOW | \
92 RDW_ERASENOW | \
93 RDW_FRAME | \
94 RDW_NOFRAME)
96 if (flags & ~RDW_FLAGS) TRACE(" %04x", flags & ~RDW_FLAGS);
97 TRACE("\n");
98 #undef RDW_FLAGS
102 /***********************************************************************
103 * update_visible_region
105 * Set the visible region and X11 drawable for the DC associated to
106 * a given window.
108 static void update_visible_region( struct dce *dce )
110 NTSTATUS status;
111 HRGN vis_rgn = 0;
112 HWND top_win = 0;
113 DWORD flags = dce->flags;
114 size_t size = 256;
115 RECT win_rect, top_rect;
117 /* don't clip siblings if using parent clip region */
118 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
120 /* fetch the visible region from the server */
123 RGNDATA *data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 );
124 if (!data) return;
126 SERVER_START_REQ( get_visible_region )
128 req->window = wine_server_user_handle( dce->hwnd );
129 req->flags = flags;
130 wine_server_set_reply( req, data->Buffer, size );
131 if (!(status = wine_server_call( req )))
133 size_t reply_size = wine_server_reply_size( reply );
134 data->rdh.dwSize = sizeof(data->rdh);
135 data->rdh.iType = RDH_RECTANGLES;
136 data->rdh.nCount = reply_size / sizeof(RECT);
137 data->rdh.nRgnSize = reply_size;
138 vis_rgn = ExtCreateRegion( NULL, size, data );
140 top_win = wine_server_ptr_handle( reply->top_win );
141 win_rect.left = reply->win_rect.left;
142 win_rect.top = reply->win_rect.top;
143 win_rect.right = reply->win_rect.right;
144 win_rect.bottom = reply->win_rect.bottom;
145 top_rect.left = reply->top_rect.left;
146 top_rect.top = reply->top_rect.top;
147 top_rect.right = reply->top_rect.right;
148 top_rect.bottom = reply->top_rect.bottom;
150 else size = reply->total_size;
152 SERVER_END_REQ;
153 HeapFree( GetProcessHeap(), 0, data );
154 } while (status == STATUS_BUFFER_OVERFLOW);
156 if (status || !vis_rgn) return;
158 USER_Driver->pGetDC( dce->hdc, dce->hwnd, top_win, &win_rect, &top_rect, flags );
160 if (dce->clip_rgn) CombineRgn( vis_rgn, vis_rgn, dce->clip_rgn,
161 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
163 __wine_set_visible_region( dce->hdc, vis_rgn, &win_rect );
167 /***********************************************************************
168 * reset_dce_attrs
170 static void reset_dce_attrs( struct dce *dce )
172 RestoreDC( dce->hdc, 1 ); /* initial save level is always 1 */
173 SaveDC( dce->hdc ); /* save the state again for next time */
177 /***********************************************************************
178 * release_dce
180 static void release_dce( struct dce *dce )
182 if (!dce->hwnd) return; /* already released */
184 USER_Driver->pReleaseDC( dce->hwnd, dce->hdc );
186 if (dce->clip_rgn) DeleteObject( dce->clip_rgn );
187 dce->clip_rgn = 0;
188 dce->hwnd = 0;
189 dce->flags &= DCX_CACHE;
193 /***********************************************************************
194 * delete_clip_rgn
196 static void delete_clip_rgn( struct dce *dce )
198 if (!dce->clip_rgn) return; /* nothing to do */
200 dce->flags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN);
201 DeleteObject( dce->clip_rgn );
202 dce->clip_rgn = 0;
204 /* make it dirty so that the vis rgn gets recomputed next time */
205 SetHookFlags( dce->hdc, DCHF_INVALIDATEVISRGN );
209 /***********************************************************************
210 * alloc_dce
212 * Allocate a new DCE.
214 static struct dce *alloc_dce(void)
216 struct dce *dce;
218 if (!(dce = HeapAlloc( GetProcessHeap(), 0, sizeof(*dce) ))) return NULL;
219 if (!(dce->hdc = CreateDCW( displayW, NULL, NULL, NULL )))
221 HeapFree( GetProcessHeap(), 0, dce );
222 return 0;
224 SaveDC( dce->hdc );
226 dce->hwnd = 0;
227 dce->clip_rgn = 0;
228 dce->flags = 0;
229 dce->count = 1;
231 /* store DCE handle in DC hook data field */
232 SetDCHook( dce->hdc, dc_hook, (DWORD_PTR)dce );
233 SetHookFlags( dce->hdc, DCHF_INVALIDATEVISRGN );
234 return dce;
238 /***********************************************************************
239 * get_window_dce
241 static struct dce *get_window_dce( HWND hwnd )
243 struct dce *dce;
244 WND *win = WIN_GetPtr( hwnd );
246 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return NULL;
248 dce = win->dce;
249 if (!dce && (dce = get_class_dce( win->class )))
251 win->dce = dce;
252 dce->count++;
254 WIN_ReleasePtr( win );
256 if (!dce) /* try to allocate one */
258 struct dce *dce_to_free = NULL;
259 LONG class_style = GetClassLongW( hwnd, GCL_STYLE );
261 if (class_style & CS_CLASSDC)
263 if (!(dce = alloc_dce())) return NULL;
265 win = WIN_GetPtr( hwnd );
266 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
268 if (win->dce) /* another thread beat us to it */
270 dce_to_free = dce;
271 dce = win->dce;
273 else if ((win->dce = set_class_dce( win->class, dce )) != dce)
275 dce_to_free = dce;
276 dce = win->dce;
277 dce->count++;
279 else
281 dce->count++;
282 list_add_tail( &dce_list, &dce->entry );
284 WIN_ReleasePtr( win );
286 else dce_to_free = dce;
288 else if (class_style & CS_OWNDC)
290 if (!(dce = alloc_dce())) return NULL;
292 win = WIN_GetPtr( hwnd );
293 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
295 if (win->dwStyle & WS_CLIPCHILDREN) dce->flags |= DCX_CLIPCHILDREN;
296 if (win->dwStyle & WS_CLIPSIBLINGS) dce->flags |= DCX_CLIPSIBLINGS;
297 if (win->dce) /* another thread beat us to it */
299 dce_to_free = dce;
300 dce = win->dce;
302 else
304 win->dce = dce;
305 dce->hwnd = hwnd;
306 dce->count++;
307 list_add_tail( &dce_list, &dce->entry );
309 WIN_ReleasePtr( win );
311 else dce_to_free = dce;
314 if (dce_to_free)
316 SetDCHook( dce->hdc, NULL, 0 );
317 DeleteDC( dce->hdc );
318 HeapFree( GetProcessHeap(), 0, dce );
321 return dce;
325 /***********************************************************************
326 * free_dce
328 * Free a class or window DCE.
330 void free_dce( struct dce *dce, HWND hwnd )
332 USER_Lock();
334 if (dce)
336 if (!--dce->count)
338 /* turn it into a cache entry */
339 reset_dce_attrs( dce );
340 release_dce( dce );
341 dce->flags |= DCX_CACHE;
343 else if (dce->hwnd == hwnd)
345 release_dce( dce );
349 /* now check for cache DCEs */
351 if (hwnd)
353 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
355 if (dce->hwnd != hwnd) continue;
356 if (!(dce->flags & DCX_CACHE)) continue;
358 if (dce->count) WARN( "GetDC() without ReleaseDC() for window %p\n", hwnd );
359 dce->count = 0;
360 release_dce( dce );
364 USER_Unlock();
368 /***********************************************************************
369 * make_dc_dirty
371 * Mark the associated DC as dirty to force a refresh of the visible region
373 static void make_dc_dirty( struct dce *dce )
375 if (!dce->count)
377 /* Don't bother with visible regions of unused DCEs */
378 TRACE("\tpurged %p dce [%p]\n", dce, dce->hwnd);
379 release_dce( dce );
381 else
383 /* Set dirty bits in the hDC and DCE structs */
384 TRACE("\tfixed up %p dce [%p]\n", dce, dce->hwnd);
385 SetHookFlags( dce->hdc, DCHF_INVALIDATEVISRGN );
390 /***********************************************************************
391 * invalidate_dce
393 * It is called from SetWindowPos() - we have to
394 * mark as dirty all busy DCEs for windows that have pWnd->parent as
395 * an ancestor and whose client rect intersects with specified update
396 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
397 * DCX_CLIPCHILDREN flag is set.
399 void invalidate_dce( HWND hwnd, const RECT *rect )
401 RECT window_rect, extra_rect;
402 struct dce *dce;
403 HWND hwndScope = GetAncestor( hwnd, GA_PARENT );
405 if (!hwndScope) return;
407 GetWindowRect( hwnd, &window_rect );
408 if (rect)
410 extra_rect = *rect;
411 MapWindowPoints( hwndScope, 0, (POINT *)&extra_rect, 2 );
414 TRACE("%p scope hwnd = %p %s (%s)\n",
415 hwnd, hwndScope, wine_dbgstr_rect(&window_rect), wine_dbgstr_rect(rect) );
417 /* walk all DCEs and fixup non-empty entries */
419 USER_Lock();
420 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
422 TRACE( "%p: hwnd %p dcx %08x %s %s\n", dce, dce->hwnd, dce->flags,
423 (dce->flags & DCX_CACHE) ? "Cache" : "Owned", dce->count ? "InUse" : "" );
425 if (!dce->hwnd) continue;
426 if ((dce->hwnd == hwndScope) && !(dce->flags & DCX_CLIPCHILDREN))
427 continue; /* child window positions don't bother us */
429 /* if DCE window is a child of hwnd, it has to be invalidated */
430 if (dce->hwnd == hwnd || IsChild( hwnd, dce->hwnd ))
432 make_dc_dirty( dce );
434 else /* otherwise check if the window rectangle intersects this DCE window */
436 if (hwndScope == GetDesktopWindow() ||
437 hwndScope == dce->hwnd || IsChild( hwndScope, dce->hwnd ))
439 RECT dce_rect, tmp;
440 GetWindowRect( dce->hwnd, &dce_rect );
441 if (IntersectRect( &tmp, &dce_rect, &window_rect ) ||
442 (rect && IntersectRect( &tmp, &dce_rect, &extra_rect )))
443 make_dc_dirty( dce );
447 USER_Unlock();
450 /***********************************************************************
451 * release_dc
453 * Implementation of ReleaseDC.
455 static INT release_dc( HWND hwnd, HDC hdc, BOOL end_paint )
457 struct dce *dce;
458 BOOL ret = FALSE;
460 TRACE("%p %p\n", hwnd, hdc );
462 USER_Lock();
463 dce = (struct dce *)GetDCHook( hdc, NULL );
464 if (dce && dce->count)
466 if (!(dce->flags & DCX_NORESETATTRS)) reset_dce_attrs( dce );
467 if (end_paint || (dce->flags & DCX_CACHE)) delete_clip_rgn( dce );
468 if (dce->flags & DCX_CACHE) dce->count = 0;
469 ret = TRUE;
471 USER_Unlock();
472 return ret;
476 /***********************************************************************
477 * dc_hook
479 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
481 static BOOL CALLBACK dc_hook( HDC hDC, WORD code, DWORD_PTR data, LPARAM lParam )
483 BOOL retv = TRUE;
484 struct dce *dce = (struct dce *)data;
486 TRACE("hDC = %p, %u\n", hDC, code);
488 if (!dce) return 0;
489 assert( dce->hdc == hDC );
491 switch( code )
493 case DCHC_INVALIDVISRGN:
494 /* GDI code calls this when it detects that the
495 * DC is dirty (usually after SetHookFlags()). This
496 * means that we have to recompute the visible region.
498 if (dce->count) update_visible_region( dce );
499 else /* non-fatal but shouldn't happen */
500 WARN("DC is not in use!\n");
501 break;
502 case DCHC_DELETEDC:
504 * Windows will not let you delete a DC that is busy
505 * (between GetDC and ReleaseDC)
507 USER_Lock();
508 if (dce->count > 1)
510 WARN("Application trying to delete a busy DC %p\n", dce->hdc);
511 retv = FALSE;
513 else
515 list_remove( &dce->entry );
516 if (dce->clip_rgn) DeleteObject( dce->clip_rgn );
517 HeapFree( GetProcessHeap(), 0, dce );
519 USER_Unlock();
520 break;
522 return retv;
526 /***********************************************************************
527 * get_update_region
529 * Return update region (in screen coordinates) for a window.
531 static HRGN get_update_region( HWND hwnd, UINT *flags, HWND *child )
533 HRGN hrgn = 0;
534 NTSTATUS status;
535 RGNDATA *data;
536 size_t size = 256;
540 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
542 SetLastError( ERROR_OUTOFMEMORY );
543 return 0;
546 SERVER_START_REQ( get_update_region )
548 req->window = wine_server_user_handle( hwnd );
549 req->from_child = wine_server_user_handle( child ? *child : 0 );
550 req->flags = *flags;
551 wine_server_set_reply( req, data->Buffer, size );
552 if (!(status = wine_server_call( req )))
554 size_t reply_size = wine_server_reply_size( reply );
555 data->rdh.dwSize = sizeof(data->rdh);
556 data->rdh.iType = RDH_RECTANGLES;
557 data->rdh.nCount = reply_size / sizeof(RECT);
558 data->rdh.nRgnSize = reply_size;
559 hrgn = ExtCreateRegion( NULL, size, data );
560 if (child) *child = wine_server_ptr_handle( reply->child );
561 *flags = reply->flags;
563 else size = reply->total_size;
565 SERVER_END_REQ;
566 HeapFree( GetProcessHeap(), 0, data );
567 } while (status == STATUS_BUFFER_OVERFLOW);
569 if (status) SetLastError( RtlNtStatusToDosError(status) );
570 return hrgn;
574 /***********************************************************************
575 * get_update_flags
577 * Get only the update flags, not the update region.
579 static BOOL get_update_flags( HWND hwnd, HWND *child, UINT *flags )
581 BOOL ret;
583 SERVER_START_REQ( get_update_region )
585 req->window = wine_server_user_handle( hwnd );
586 req->from_child = wine_server_user_handle( child ? *child : 0 );
587 req->flags = *flags | UPDATE_NOREGION;
588 if ((ret = !wine_server_call_err( req )))
590 if (child) *child = wine_server_ptr_handle( reply->child );
591 *flags = reply->flags;
594 SERVER_END_REQ;
595 return ret;
599 /***********************************************************************
600 * redraw_window_rects
602 * Redraw part of a window.
604 static BOOL redraw_window_rects( HWND hwnd, UINT flags, const RECT *rects, UINT count )
606 BOOL ret;
608 if (!(flags & (RDW_INVALIDATE|RDW_VALIDATE|RDW_INTERNALPAINT|RDW_NOINTERNALPAINT)))
609 return TRUE; /* nothing to do */
611 SERVER_START_REQ( redraw_window )
613 req->window = wine_server_user_handle( hwnd );
614 req->flags = flags;
615 wine_server_add_data( req, rects, count * sizeof(RECT) );
616 ret = !wine_server_call_err( req );
618 SERVER_END_REQ;
619 return ret;
623 /***********************************************************************
624 * send_ncpaint
626 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
627 * Helper for erase_now and BeginPaint.
629 static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags )
631 HRGN whole_rgn = get_update_region( hwnd, flags, child );
632 HRGN client_rgn = 0;
634 if (child) hwnd = *child;
636 if (hwnd == GetDesktopWindow()) return whole_rgn;
638 if (whole_rgn)
640 RECT client, update;
641 INT type;
643 /* check if update rgn overlaps with nonclient area */
644 type = GetRgnBox( whole_rgn, &update );
645 GetClientRect( hwnd, &client );
646 MapWindowPoints( hwnd, 0, (POINT *)&client, 2 );
648 if ((*flags & UPDATE_NONCLIENT) ||
649 update.left < client.left || update.top < client.top ||
650 update.right > client.right || update.bottom > client.bottom)
652 client_rgn = CreateRectRgnIndirect( &client );
653 CombineRgn( client_rgn, client_rgn, whole_rgn, RGN_AND );
655 /* check if update rgn contains complete nonclient area */
656 if (type == SIMPLEREGION)
658 RECT window;
659 GetWindowRect( hwnd, &window );
660 if (EqualRect( &window, &update ))
662 DeleteObject( whole_rgn );
663 whole_rgn = (HRGN)1;
667 else
669 client_rgn = whole_rgn;
670 whole_rgn = 0;
673 if (whole_rgn) /* NOTE: WM_NCPAINT allows wParam to be 1 */
675 if (*flags & UPDATE_NONCLIENT) SendMessageW( hwnd, WM_NCPAINT, (WPARAM)whole_rgn, 0 );
676 if (whole_rgn > (HRGN)1) DeleteObject( whole_rgn );
679 return client_rgn;
683 /***********************************************************************
684 * send_erase
686 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
687 * If a DC is requested, the region is selected into it. In all cases the region is deleted.
688 * Helper for erase_now and BeginPaint.
690 static BOOL send_erase( HWND hwnd, UINT flags, HRGN client_rgn,
691 RECT *clip_rect, HDC *hdc_ret )
693 BOOL need_erase = (flags & UPDATE_DELAYED_ERASE) != 0;
694 HDC hdc = 0;
695 RECT dummy;
697 if (!clip_rect) clip_rect = &dummy;
698 if (hdc_ret || (flags & UPDATE_ERASE))
700 UINT dcx_flags = DCX_INTERSECTRGN | DCX_USESTYLE;
701 if (IsIconic(hwnd)) dcx_flags |= DCX_WINDOW;
703 if ((hdc = GetDCEx( hwnd, client_rgn, dcx_flags )))
705 INT type = GetClipBox( hdc, clip_rect );
707 if (flags & UPDATE_ERASE)
709 /* don't erase if the clip box is empty */
710 if (type != NULLREGION)
711 need_erase = !SendMessageW( hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0 );
713 if (!hdc_ret) release_dc( hwnd, hdc, TRUE );
716 if (hdc_ret) *hdc_ret = hdc;
718 if (!hdc) DeleteObject( client_rgn );
719 return need_erase;
723 /***********************************************************************
724 * erase_now
726 * Implementation of RDW_ERASENOW behavior.
728 void erase_now( HWND hwnd, UINT rdw_flags )
730 HWND child = 0;
731 HRGN hrgn;
732 BOOL need_erase = FALSE;
734 /* loop while we find a child to repaint */
735 for (;;)
737 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE;
739 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
740 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
741 if (need_erase) flags |= UPDATE_DELAYED_ERASE;
743 if (!(hrgn = send_ncpaint( hwnd, &child, &flags ))) break;
744 need_erase = send_erase( child, flags, hrgn, NULL, NULL );
746 if (!flags) break; /* nothing more to do */
747 if ((rdw_flags & RDW_NOCHILDREN) && !need_erase) break;
752 /***********************************************************************
753 * update_now
755 * Implementation of RDW_UPDATENOW behavior.
757 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
758 * SendMessage() calls. This is a comment inside DefWindowProc() source
759 * from 16-bit SDK:
761 * This message avoids lots of inter-app message traffic
762 * by switching to the other task and continuing the
763 * recursion there.
765 * wParam = flags
766 * LOWORD(lParam) = hrgnClip
767 * HIWORD(lParam) = hwndSkip (not used; always NULL)
770 static void update_now( HWND hwnd, UINT rdw_flags )
772 HWND child = 0;
774 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
775 if (hwnd == GetDesktopWindow()) erase_now( hwnd, rdw_flags | RDW_NOCHILDREN );
777 /* loop while we find a child to repaint */
778 for (;;)
780 UINT flags = UPDATE_PAINT | UPDATE_INTERNALPAINT;
782 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
783 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
785 if (!get_update_flags( hwnd, &child, &flags )) break;
786 if (!flags) break; /* nothing more to do */
788 SendMessageW( child, WM_PAINT, 0, 0 );
789 if (rdw_flags & RDW_NOCHILDREN) break;
794 /*************************************************************************
795 * fix_caret
797 * Helper for ScrollWindowEx:
798 * If the return value is 0, no special caret handling is necessary.
799 * Otherwise the return value is the handle of the window that owns the
800 * caret. Its caret needs to be hidden during the scroll operation and
801 * moved to new_caret_pos if move_caret is TRUE.
803 static HWND fix_caret(HWND hWnd, const RECT *scroll_rect, INT dx, INT dy,
804 UINT flags, LPBOOL move_caret, LPPOINT new_caret_pos)
806 GUITHREADINFO info;
807 RECT rect, mapped_rcCaret;
808 BOOL hide_caret = FALSE;
810 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
811 if (!info.hwndCaret) return 0;
813 if (info.hwndCaret == hWnd)
815 /* Move the caret if it's (partially) in the source rectangle */
816 if (IntersectRect(&rect, scroll_rect, &info.rcCaret))
818 *move_caret = TRUE;
819 hide_caret = TRUE;
820 new_caret_pos->x = info.rcCaret.left + dx;
821 new_caret_pos->y = info.rcCaret.top + dy;
823 else
825 *move_caret = FALSE;
827 /* Hide the caret if it's in the destination rectangle */
828 rect = *scroll_rect;
829 OffsetRect(&rect, dx, dy);
830 hide_caret = IntersectRect(&rect, &rect, &info.rcCaret);
833 else
835 if ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret))
837 *move_caret = FALSE;
839 /* Hide the caret if it's in the source or in the destination
840 rectangle */
841 mapped_rcCaret = info.rcCaret;
842 MapWindowPoints(info.hwndCaret, hWnd, (LPPOINT)&mapped_rcCaret, 2);
844 if (IntersectRect(&rect, scroll_rect, &mapped_rcCaret))
846 hide_caret = TRUE;
848 else
850 rect = *scroll_rect;
851 OffsetRect(&rect, dx, dy);
852 hide_caret = IntersectRect(&rect, &rect, &mapped_rcCaret);
855 else
856 return 0;
859 if (hide_caret)
861 HideCaret(info.hwndCaret);
862 return info.hwndCaret;
864 else
865 return 0;
869 /***********************************************************************
870 * BeginPaint (USER32.@)
872 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
874 HRGN hrgn;
875 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
877 if (!lps) return 0;
879 HideCaret( hwnd );
881 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
883 lps->fErase = send_erase( hwnd, flags, hrgn, &lps->rcPaint, &lps->hdc );
885 TRACE("hdc = %p box = (%s), fErase = %d\n",
886 lps->hdc, wine_dbgstr_rect(&lps->rcPaint), lps->fErase);
888 return lps->hdc;
892 /***********************************************************************
893 * EndPaint (USER32.@)
895 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
897 if (!lps) return FALSE;
898 release_dc( hwnd, lps->hdc, TRUE );
899 ShowCaret( hwnd );
900 return TRUE;
904 /***********************************************************************
905 * GetDCEx (USER32.@)
907 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
909 const DWORD clip_flags = DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW;
910 const DWORD user_flags = clip_flags | DCX_NORESETATTRS; /* flags that can be set by user */
911 struct dce *dce;
912 BOOL bUpdateVisRgn = TRUE;
913 HWND parent;
914 LONG window_style = GetWindowLongW( hwnd, GWL_STYLE );
916 if (!hwnd) hwnd = GetDesktopWindow();
917 else hwnd = WIN_GetFullHandle( hwnd );
919 TRACE("hwnd %p, hrgnClip %p, flags %08x\n", hwnd, hrgnClip, flags);
921 if (!IsWindow(hwnd)) return 0;
923 /* fixup flags */
925 if (flags & (DCX_WINDOW | DCX_PARENTCLIP)) flags |= DCX_CACHE;
927 if (flags & DCX_USESTYLE)
929 flags &= ~(DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
931 if (window_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
933 if (!(flags & DCX_WINDOW))
935 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC) flags |= DCX_PARENTCLIP;
937 if (window_style & WS_CLIPCHILDREN && !(window_style & WS_MINIMIZE))
938 flags |= DCX_CLIPCHILDREN;
942 if (flags & DCX_WINDOW) flags &= ~DCX_CLIPCHILDREN;
944 parent = GetAncestor( hwnd, GA_PARENT );
945 if (!parent || (parent == GetDesktopWindow()))
946 flags = (flags & ~DCX_PARENTCLIP) | DCX_CLIPSIBLINGS;
948 /* it seems parent clip is ignored when clipping siblings or children */
949 if (flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) flags &= ~DCX_PARENTCLIP;
951 if( flags & DCX_PARENTCLIP )
953 LONG parent_style = GetWindowLongW( parent, GWL_STYLE );
954 if( (window_style & WS_VISIBLE) && (parent_style & WS_VISIBLE) )
956 flags &= ~DCX_CLIPCHILDREN;
957 if (parent_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
961 /* find a suitable DCE */
963 if ((flags & DCX_CACHE) || !(dce = get_window_dce( hwnd )))
965 struct dce *dceEmpty = NULL, *dceUnused = NULL;
967 /* Strategy: First, we attempt to find a non-empty but unused DCE with
968 * compatible flags. Next, we look for an empty entry. If the cache is
969 * full we have to purge one of the unused entries.
971 USER_Lock();
972 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
974 if ((dce->flags & DCX_CACHE) && !dce->count)
976 dceUnused = dce;
978 if (!dce->hwnd) dceEmpty = dce;
979 else if ((dce->hwnd == hwnd) && !((dce->flags ^ flags) & clip_flags))
981 TRACE("\tfound valid %p dce [%p], flags %08x\n",
982 dce, hwnd, dce->flags );
983 bUpdateVisRgn = FALSE;
984 break;
989 if (&dce->entry == &dce_list) /* nothing found */
990 dce = dceEmpty ? dceEmpty : dceUnused;
992 if (dce) dce->count = 1;
994 USER_Unlock();
996 /* if there's no dce empty or unused, allocate a new one */
997 if (!dce)
999 if (!(dce = alloc_dce())) return 0;
1000 dce->flags = DCX_CACHE;
1001 USER_Lock();
1002 list_add_head( &dce_list, &dce->entry );
1003 USER_Unlock();
1006 else
1008 flags |= DCX_NORESETATTRS;
1009 if (dce->hwnd == hwnd)
1011 TRACE("\tskipping hVisRgn update\n");
1012 bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
1014 else
1016 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
1017 dce->flags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN);
1018 dce->clip_rgn = 0;
1022 if (flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN))
1024 /* if the extra clip region has changed, get rid of the old one */
1025 if (dce->clip_rgn != hrgnClip || ((flags ^ dce->flags) & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)))
1026 delete_clip_rgn( dce );
1027 dce->clip_rgn = hrgnClip;
1028 if (!dce->clip_rgn) dce->clip_rgn = CreateRectRgn( 0, 0, 0, 0 );
1029 dce->flags |= flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN);
1030 bUpdateVisRgn = TRUE;
1033 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) SetLayout( dce->hdc, LAYOUT_RTL );
1035 dce->hwnd = hwnd;
1036 dce->flags = (dce->flags & ~user_flags) | (flags & user_flags);
1038 if (SetHookFlags( dce->hdc, DCHF_VALIDATEVISRGN )) bUpdateVisRgn = TRUE; /* DC was dirty */
1040 if (bUpdateVisRgn) update_visible_region( dce );
1042 TRACE("(%p,%p,0x%x): returning %p\n", hwnd, hrgnClip, flags, dce->hdc);
1043 return dce->hdc;
1047 /***********************************************************************
1048 * GetDC (USER32.@)
1050 * Get a device context.
1052 * RETURNS
1053 * Success: Handle to the device context
1054 * Failure: NULL.
1056 HDC WINAPI GetDC( HWND hwnd )
1058 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
1059 return GetDCEx( hwnd, 0, DCX_USESTYLE );
1063 /***********************************************************************
1064 * GetWindowDC (USER32.@)
1066 HDC WINAPI GetWindowDC( HWND hwnd )
1068 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
1072 /***********************************************************************
1073 * ReleaseDC (USER32.@)
1075 * Release a device context.
1077 * RETURNS
1078 * Success: Non-zero. Resources used by hdc are released.
1079 * Failure: 0.
1081 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
1083 return release_dc( hwnd, hdc, FALSE );
1087 /**********************************************************************
1088 * WindowFromDC (USER32.@)
1090 HWND WINAPI WindowFromDC( HDC hdc )
1092 struct dce *dce;
1093 HWND hwnd = 0;
1095 USER_Lock();
1096 dce = (struct dce *)GetDCHook( hdc, NULL );
1097 if (dce) hwnd = dce->hwnd;
1098 USER_Unlock();
1099 return hwnd;
1103 /***********************************************************************
1104 * LockWindowUpdate (USER32.@)
1106 * Enables or disables painting in the chosen window.
1108 * PARAMS
1109 * hwnd [I] handle to a window.
1111 * RETURNS
1112 * If successful, returns nonzero value. Otherwise,
1113 * returns 0.
1115 * NOTES
1116 * You can lock only one window at a time.
1118 BOOL WINAPI LockWindowUpdate( HWND hwnd )
1120 static HWND lockedWnd;
1122 FIXME("(%p), partial stub!\n",hwnd);
1124 USER_Lock();
1125 if (lockedWnd)
1127 if (!hwnd)
1129 /* Unlock lockedWnd */
1130 /* FIXME: Do something */
1132 else
1134 /* Attempted to lock a second window */
1135 /* Return FALSE and do nothing */
1136 USER_Unlock();
1137 return FALSE;
1140 lockedWnd = hwnd;
1141 USER_Unlock();
1142 return TRUE;
1146 /***********************************************************************
1147 * RedrawWindow (USER32.@)
1149 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
1151 static const RECT empty;
1152 BOOL ret;
1154 if (!hwnd) hwnd = GetDesktopWindow();
1156 if (TRACE_ON(win))
1158 if (hrgn)
1160 RECT r;
1161 GetRgnBox( hrgn, &r );
1162 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
1164 else if (rect)
1165 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
1166 else
1167 TRACE( "%p whole window ", hwnd );
1169 dump_rdw_flags(flags);
1172 /* process pending expose events before painting */
1173 if (flags & RDW_UPDATENOW) USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_PAINT, 0 );
1175 if (rect && !hrgn)
1177 if (IsRectEmpty( rect )) rect = &empty;
1178 ret = redraw_window_rects( hwnd, flags, rect, 1 );
1180 else if (!hrgn)
1182 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
1184 else /* need to build a list of the region rectangles */
1186 DWORD size;
1187 RGNDATA *data = NULL;
1189 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
1190 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
1191 GetRegionData( hrgn, size, data );
1192 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
1193 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
1194 else
1195 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
1196 HeapFree( GetProcessHeap(), 0, data );
1199 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
1200 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
1202 return ret;
1206 /***********************************************************************
1207 * UpdateWindow (USER32.@)
1209 BOOL WINAPI UpdateWindow( HWND hwnd )
1211 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1215 /***********************************************************************
1216 * InvalidateRgn (USER32.@)
1218 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1220 if (!hwnd)
1222 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1223 return FALSE;
1226 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1230 /***********************************************************************
1231 * InvalidateRect (USER32.@)
1233 * MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
1234 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
1236 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1238 UINT flags = RDW_INVALIDATE | (erase ? RDW_ERASE : 0);
1240 if (!hwnd)
1242 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
1243 rect = NULL;
1246 return RedrawWindow( hwnd, rect, 0, flags );
1250 /***********************************************************************
1251 * ValidateRgn (USER32.@)
1253 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1255 if (!hwnd)
1257 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1258 return FALSE;
1261 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
1265 /***********************************************************************
1266 * ValidateRect (USER32.@)
1268 * MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
1269 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
1271 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1273 UINT flags = RDW_VALIDATE;
1275 if (!hwnd)
1277 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
1278 rect = NULL;
1281 return RedrawWindow( hwnd, rect, 0, flags );
1285 /***********************************************************************
1286 * GetUpdateRgn (USER32.@)
1288 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1290 INT retval = ERROR;
1291 UINT flags = UPDATE_NOCHILDREN;
1292 HRGN update_rgn;
1294 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
1296 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
1298 POINT offset;
1300 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
1301 if (send_erase( hwnd, flags, update_rgn, NULL, NULL ))
1303 flags = UPDATE_DELAYED_ERASE;
1304 get_update_flags( hwnd, NULL, &flags );
1306 /* map region to client coordinates */
1307 offset.x = offset.y = 0;
1308 ScreenToClient( hwnd, &offset );
1309 OffsetRgn( hrgn, offset.x, offset.y );
1311 return retval;
1315 /***********************************************************************
1316 * GetUpdateRect (USER32.@)
1318 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1320 UINT flags = UPDATE_NOCHILDREN;
1321 HRGN update_rgn;
1322 BOOL need_erase;
1324 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
1326 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
1328 if (rect)
1330 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
1332 HDC hdc = GetDCEx( hwnd, 0, DCX_USESTYLE );
1333 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
1334 DPtoLP( hdc, (LPPOINT)rect, 2 );
1335 ReleaseDC( hwnd, hdc );
1338 need_erase = send_erase( hwnd, flags, update_rgn, NULL, NULL );
1340 /* check if we still have an update region */
1341 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
1342 if (need_erase) flags |= UPDATE_DELAYED_ERASE;
1343 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
1347 /***********************************************************************
1348 * ExcludeUpdateRgn (USER32.@)
1350 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1352 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
1353 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
1355 if (ret != ERROR)
1357 POINT pt;
1359 GetDCOrgEx( hdc, &pt );
1360 MapWindowPoints( 0, hwnd, &pt, 1 );
1361 OffsetRgn( update_rgn, -pt.x, -pt.y );
1362 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
1363 DeleteObject( update_rgn );
1365 return ret;
1369 /*************************************************************************
1370 * ScrollWindowEx (USER32.@)
1372 * Note: contrary to what the doc says, pixels that are scrolled from the
1373 * outside of clipRect to the inside are NOT painted.
1376 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
1377 const RECT *rect, const RECT *clipRect,
1378 HRGN hrgnUpdate, LPRECT rcUpdate,
1379 UINT flags )
1381 INT retVal = NULLREGION;
1382 BOOL bOwnRgn = TRUE;
1383 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
1384 int rdw_flags;
1385 HRGN hrgnTemp;
1386 HRGN hrgnWinupd = 0;
1387 HDC hDC;
1388 RECT rc, cliprc;
1389 HWND hwndCaret = NULL;
1390 BOOL moveCaret = FALSE;
1391 POINT newCaretPos;
1393 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
1394 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
1395 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
1396 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
1397 FIXME("some flags (%04x) are unhandled\n", flags);
1399 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
1400 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
1402 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
1403 hwnd = WIN_GetFullHandle( hwnd );
1405 GetClientRect(hwnd, &rc);
1407 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
1408 else cliprc = rc;
1410 if (rect) IntersectRect(&rc, &rc, rect);
1412 if( hrgnUpdate ) bOwnRgn = FALSE;
1413 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
1415 newCaretPos.x = newCaretPos.y = 0;
1417 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
1418 DWORD dcxflags = DCX_CACHE;
1419 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
1421 hwndCaret = fix_caret(hwnd, &rc, dx, dy, flags, &moveCaret, &newCaretPos);
1423 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
1424 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
1425 dcxflags |= DCX_PARENTCLIP;
1426 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
1427 dcxflags |= DCX_CLIPCHILDREN;
1428 hDC = GetDCEx( hwnd, 0, dcxflags);
1429 if (hDC)
1431 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
1433 ReleaseDC( hwnd, hDC );
1435 if (!bUpdate)
1436 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
1439 /* If the windows has an update region, this must be
1440 * scrolled as well. Keep a copy in hrgnWinupd
1441 * to be added to hrngUpdate at the end. */
1442 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
1443 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
1444 if (retVal != NULLREGION)
1446 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
1447 if( !bOwnRgn) {
1448 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
1449 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
1451 OffsetRgn( hrgnTemp, dx, dy );
1452 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
1453 if( !bOwnRgn)
1454 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
1455 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
1457 /* Catch the case where the scrolling amount exceeds the size of the
1458 * original window. This generated a second update area that is the
1459 * location where the original scrolled content would end up.
1460 * This second region is not returned by the ScrollDC and sets
1461 * ScrollWindowEx apart from just a ScrollDC.
1463 * This has been verified with testing on windows.
1465 if (abs(dx) > abs(rc.right - rc.left) ||
1466 abs(dy) > abs(rc.bottom - rc.top))
1468 SetRectRgn( hrgnTemp, rc.left + dx, rc.top + dy, rc.right+dx, rc.bottom + dy);
1469 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
1470 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp, RGN_OR );
1472 if( !bOwnRgn)
1473 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
1475 DeleteObject( hrgnClip );
1477 DeleteObject( hrgnTemp );
1478 } else {
1479 /* nothing was scrolled */
1480 if( !bOwnRgn)
1481 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
1482 SetRectEmpty( rcUpdate);
1485 if( flags & SW_SCROLLCHILDREN )
1487 HWND *list = WIN_ListChildren( hwnd );
1488 if (list)
1490 int i;
1491 RECT r, dummy;
1492 for (i = 0; list[i]; i++)
1494 GetWindowRect( list[i], &r );
1495 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
1496 if (!rect || IntersectRect(&dummy, &r, rect))
1497 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
1498 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
1499 SWP_NOREDRAW | SWP_DEFERERASE );
1501 HeapFree( GetProcessHeap(), 0, list );
1505 if( flags & (SW_INVALIDATE | SW_ERASE) )
1506 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
1507 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
1509 if( hrgnWinupd) {
1510 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
1511 DeleteObject( hrgnWinupd);
1514 if( hwndCaret ) {
1515 if ( moveCaret ) SetCaretPos( newCaretPos.x, newCaretPos.y );
1516 ShowCaret(hwndCaret);
1519 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
1521 return retVal;
1525 /*************************************************************************
1526 * ScrollWindow (USER32.@)
1529 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
1530 const RECT *rect, const RECT *clipRect )
1532 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
1533 (rect ? 0 : SW_SCROLLCHILDREN) |
1534 SW_INVALIDATE | SW_ERASE ));
1538 /*************************************************************************
1539 * ScrollDC (USER32.@)
1541 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
1542 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
1543 * logical coordinates.
1545 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
1546 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
1549 return USER_Driver->pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
1552 /************************************************************************
1553 * PrintWindow (USER32.@)
1556 BOOL WINAPI PrintWindow(HWND hwnd, HDC hdcBlt, UINT nFlags)
1558 UINT flags = PRF_CHILDREN | PRF_ERASEBKGND | PRF_OWNED | PRF_CLIENT;
1559 if(!(nFlags & PW_CLIENTONLY))
1561 flags |= PRF_NONCLIENT;
1563 SendMessageW(hwnd, WM_PRINT, (WPARAM)hdcBlt, flags);
1564 return TRUE;