2 * Window painting functions
4 * Copyright 1993, 1994, 1995, 2001, 2004 Alexandre Julliard
5 * Copyright 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
23 #include "wine/port.h"
29 #define WIN32_NO_STATUS
34 #include "wine/server.h"
36 #include "user_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
42 /***********************************************************************
45 static void dump_rdw_flags(UINT flags)
48 if (flags & RDW_INVALIDATE) TRACE(" RDW_INVALIDATE");
49 if (flags & RDW_INTERNALPAINT) TRACE(" RDW_INTERNALPAINT");
50 if (flags & RDW_ERASE) TRACE(" RDW_ERASE");
51 if (flags & RDW_VALIDATE) TRACE(" RDW_VALIDATE");
52 if (flags & RDW_NOINTERNALPAINT) TRACE(" RDW_NOINTERNALPAINT");
53 if (flags & RDW_NOERASE) TRACE(" RDW_NOERASE");
54 if (flags & RDW_NOCHILDREN) TRACE(" RDW_NOCHILDREN");
55 if (flags & RDW_ALLCHILDREN) TRACE(" RDW_ALLCHILDREN");
56 if (flags & RDW_UPDATENOW) TRACE(" RDW_UPDATENOW");
57 if (flags & RDW_ERASENOW) TRACE(" RDW_ERASENOW");
58 if (flags & RDW_FRAME) TRACE(" RDW_FRAME");
59 if (flags & RDW_NOFRAME) TRACE(" RDW_NOFRAME");
66 RDW_NOINTERNALPAINT | \
75 if (flags & ~RDW_FLAGS) TRACE(" %04x", flags & ~RDW_FLAGS);
81 /***********************************************************************
84 * Return update region (in screen coordinates) for a window.
86 static HRGN get_update_region( HWND hwnd, UINT *flags, HWND *child )
95 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
97 SetLastError( ERROR_OUTOFMEMORY );
101 SERVER_START_REQ( get_update_region )
104 req->from_child = child ? *child : 0;
106 wine_server_set_reply( req, data->Buffer, size );
107 if (!(status = wine_server_call( req )))
109 size_t reply_size = wine_server_reply_size( reply );
110 data->rdh.dwSize = sizeof(data->rdh);
111 data->rdh.iType = RDH_RECTANGLES;
112 data->rdh.nCount = reply_size / sizeof(RECT);
113 data->rdh.nRgnSize = reply_size;
114 hrgn = ExtCreateRegion( NULL, size, data );
115 if (child) *child = reply->child;
116 *flags = reply->flags;
118 else size = reply->total_size;
121 HeapFree( GetProcessHeap(), 0, data );
122 } while (status == STATUS_BUFFER_OVERFLOW);
124 if (status) SetLastError( RtlNtStatusToDosError(status) );
129 /***********************************************************************
132 * Get only the update flags, not the update region.
134 static BOOL get_update_flags( HWND hwnd, HWND *child, UINT *flags )
138 SERVER_START_REQ( get_update_region )
141 req->from_child = child ? *child : 0;
142 req->flags = *flags | UPDATE_NOREGION;
143 if ((ret = !wine_server_call_err( req )))
145 if (child) *child = reply->child;
146 *flags = reply->flags;
154 /***********************************************************************
155 * redraw_window_rects
157 * Redraw part of a window.
159 static BOOL redraw_window_rects( HWND hwnd, UINT flags, const RECT *rects, UINT count )
163 SERVER_START_REQ( redraw_window )
167 wine_server_add_data( req, rects, count * sizeof(RECT) );
168 ret = !wine_server_call_err( req );
175 /***********************************************************************
178 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
179 * Helper for erase_now and BeginPaint.
181 static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags )
183 HRGN whole_rgn = get_update_region( hwnd, flags, child );
186 if (child) hwnd = *child;
193 /* check if update rgn overlaps with nonclient area */
194 type = GetRgnBox( whole_rgn, &update );
195 GetClientRect( hwnd, &client );
196 MapWindowPoints( hwnd, 0, (POINT *)&client, 2 );
198 if ((*flags & UPDATE_NONCLIENT) ||
199 update.left < client.left || update.top < client.top ||
200 update.right > client.right || update.bottom > client.bottom)
202 client_rgn = CreateRectRgnIndirect( &client );
203 CombineRgn( client_rgn, client_rgn, whole_rgn, RGN_AND );
205 /* check if update rgn contains complete nonclient area */
206 if (type == SIMPLEREGION)
209 GetWindowRect( hwnd, &window );
210 if (EqualRect( &window, &update ))
212 DeleteObject( whole_rgn );
219 client_rgn = whole_rgn;
223 if (whole_rgn) /* NOTE: WM_NCPAINT allows wParam to be 1 */
225 if (*flags & UPDATE_NONCLIENT) SendMessageW( hwnd, WM_NCPAINT, (WPARAM)whole_rgn, 0 );
226 if (whole_rgn > (HRGN)1) DeleteObject( whole_rgn );
233 /***********************************************************************
236 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
237 * If a DC is requested, the region is selected into it. In all cases the region is deleted.
238 * Helper for erase_now and BeginPaint.
240 static BOOL send_erase( HWND hwnd, UINT flags, HRGN client_rgn,
241 RECT *clip_rect, HDC *hdc_ret )
243 BOOL need_erase = FALSE;
247 if (!clip_rect) clip_rect = &dummy;
248 if (hdc_ret || (flags & UPDATE_ERASE))
250 UINT dcx_flags = DCX_INTERSECTRGN | DCX_USESTYLE;
251 if (IsIconic(hwnd)) dcx_flags |= DCX_WINDOW;
253 if ((hdc = GetDCEx( hwnd, client_rgn, dcx_flags )))
255 INT type = GetClipBox( hdc, clip_rect );
257 if (flags & UPDATE_ERASE)
259 /* don't erase if the clip box is empty */
260 if (type != NULLREGION)
261 need_erase = !SendMessageW( hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0 );
265 if (need_erase && hwnd != GetDesktopWindow()) /* FIXME: mark it as needing erase again */
266 RedrawWindow( hwnd, clip_rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
267 USER_Driver->pReleaseDC( hwnd, hdc, TRUE );
271 if (hdc_ret) *hdc_ret = hdc;
273 if (!hdc) DeleteObject( client_rgn );
278 /***********************************************************************
281 * Implementation of RDW_ERASENOW behavior.
283 static void erase_now( HWND hwnd, UINT rdw_flags )
288 /* loop while we find a child to repaint */
291 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE;
293 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
294 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
296 if (!(hrgn = send_ncpaint( hwnd, &child, &flags ))) break;
297 send_erase( child, flags, hrgn, NULL, NULL );
299 if (!flags) break; /* nothing more to do */
300 if (rdw_flags & RDW_NOCHILDREN) break;
305 /***********************************************************************
308 * Implementation of RDW_UPDATENOW behavior.
310 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
311 * SendMessage() calls. This is a comment inside DefWindowProc() source
314 * This message avoids lots of inter-app message traffic
315 * by switching to the other task and continuing the
319 * LOWORD(lParam) = hrgnClip
320 * HIWORD(lParam) = hwndSkip (not used; always NULL)
323 static void update_now( HWND hwnd, UINT rdw_flags )
327 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
328 if (hwnd == GetDesktopWindow()) erase_now( hwnd, rdw_flags | RDW_NOCHILDREN );
330 /* loop while we find a child to repaint */
333 UINT flags = UPDATE_PAINT | UPDATE_INTERNALPAINT;
335 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
336 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
338 if (!get_update_flags( hwnd, &child, &flags )) break;
339 if (!flags) break; /* nothing more to do */
341 SendMessageW( child, WM_PAINT, 0, 0 );
342 if (rdw_flags & RDW_NOCHILDREN) break;
347 /*************************************************************************
350 * Helper for ScrollWindowEx:
351 * If the return value is 0, no special caret handling is necessary.
352 * Otherwise the return value is the handle of the window that owns the
353 * caret. Its caret needs to be hidden during the scroll operation and
354 * moved to new_caret_pos if move_caret is TRUE.
356 static HWND fix_caret(HWND hWnd, const LPRECT scroll_rect, INT dx, INT dy,
357 UINT flags, LPBOOL move_caret, LPPOINT new_caret_pos)
360 RECT rect, mapped_rcCaret;
361 BOOL hide_caret = FALSE;
363 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
364 if (!info.hwndCaret) return 0;
366 if (info.hwndCaret == hWnd)
368 /* Move the caret if it's (partially) in the source rectangle */
369 if (IntersectRect(&rect, scroll_rect, &info.rcCaret))
373 new_caret_pos->x = info.rcCaret.left + dx;
374 new_caret_pos->y = info.rcCaret.top + dy;
380 /* Hide the caret if it's in the destination rectangle */
382 OffsetRect(&rect, dx, dy);
383 hide_caret = IntersectRect(&rect, &rect, &info.rcCaret);
388 if ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret))
392 /* Hide the caret if it's in the source or in the destination
394 mapped_rcCaret = info.rcCaret;
395 MapWindowPoints(info.hwndCaret, hWnd, (LPPOINT)&mapped_rcCaret, 2);
397 if (IntersectRect(&rect, scroll_rect, &mapped_rcCaret))
404 OffsetRect(&rect, dx, dy);
405 hide_caret = IntersectRect(&rect, &rect, &mapped_rcCaret);
414 HideCaret(info.hwndCaret);
415 return info.hwndCaret;
422 /***********************************************************************
423 * BeginPaint (USER32.@)
425 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
429 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
433 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
436 FIXME( "window %p belongs to other thread\n", hwnd );
443 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
445 lps->fErase = send_erase( hwnd, flags, hrgn, &lps->rcPaint, &lps->hdc );
447 TRACE("hdc = %p box = (%ld,%ld - %ld,%ld), fErase = %d\n",
448 lps->hdc, lps->rcPaint.left, lps->rcPaint.top, lps->rcPaint.right, lps->rcPaint.bottom,
455 /***********************************************************************
456 * EndPaint (USER32.@)
458 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
460 if (!lps) return FALSE;
461 USER_Driver->pReleaseDC( hwnd, lps->hdc, TRUE );
467 /***********************************************************************
470 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
472 if (!hwnd) hwnd = GetDesktopWindow();
473 else hwnd = WIN_GetFullHandle( hwnd );
475 return USER_Driver->pGetDCEx( hwnd, hrgnClip, flags );
479 /***********************************************************************
482 * Get a device context.
485 * Success: Handle to the device context
488 HDC WINAPI GetDC( HWND hwnd )
490 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
491 return GetDCEx( hwnd, 0, DCX_USESTYLE );
495 /***********************************************************************
496 * GetWindowDC (USER32.@)
498 HDC WINAPI GetWindowDC( HWND hwnd )
500 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
504 /***********************************************************************
505 * ReleaseDC (USER32.@)
507 * Release a device context.
510 * Success: Non-zero. Resources used by hdc are released.
513 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
515 return USER_Driver->pReleaseDC( hwnd, hdc, FALSE );
519 /**********************************************************************
520 * WindowFromDC (USER32.@)
522 HWND WINAPI WindowFromDC( HDC hDC )
524 return USER_Driver->pWindowFromDC( hDC );
528 /***********************************************************************
529 * LockWindowUpdate (USER32.@)
531 BOOL WINAPI LockWindowUpdate( HWND hwnd )
533 static HWND lockedWnd;
535 /* This function is fully implemented by the following patch:
537 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
539 * but in order to work properly, it needs the ability to invalidate
540 * DCEs in other processes when the lock window is changed, which
541 * isn't possible yet.
545 FIXME("(%p), partial stub!\n",hwnd);
552 /* Unlock lockedWnd */
553 /* FIXME: Do something */
557 /* Attempted to lock a second window */
558 /* Return FALSE and do nothing */
569 /***********************************************************************
570 * RedrawWindow (USER32.@)
572 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
576 if (!hwnd) hwnd = GetDesktopWindow();
583 GetRgnBox( hrgn, &r );
584 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
587 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
589 TRACE( "%p whole window ", hwnd );
591 dump_rdw_flags(flags);
594 /* process pending expose events before painting */
595 if (flags & RDW_UPDATENOW) USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_PAINT, 0 );
599 ret = redraw_window_rects( hwnd, flags, rect, 1 );
603 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
605 else /* need to build a list of the region rectangles */
608 RGNDATA *data = NULL;
609 static const RECT empty;
611 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
612 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
613 GetRegionData( hrgn, size, data );
614 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
615 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
617 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
618 HeapFree( GetProcessHeap(), 0, data );
621 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
622 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
628 /***********************************************************************
629 * UpdateWindow (USER32.@)
631 BOOL WINAPI UpdateWindow( HWND hwnd )
633 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
637 /***********************************************************************
638 * InvalidateRgn (USER32.@)
640 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
644 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
648 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
652 /***********************************************************************
653 * InvalidateRect (USER32.@)
655 * MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
656 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
658 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
660 UINT flags = RDW_INVALIDATE | (erase ? RDW_ERASE : 0);
664 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
668 return RedrawWindow( hwnd, rect, 0, flags );
672 /***********************************************************************
673 * ValidateRgn (USER32.@)
675 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
679 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
683 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
687 /***********************************************************************
688 * ValidateRect (USER32.@)
690 * MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
691 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
693 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
695 UINT flags = RDW_VALIDATE;
699 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
703 return RedrawWindow( hwnd, rect, 0, flags );
707 /***********************************************************************
708 * GetUpdateRgn (USER32.@)
710 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
713 UINT flags = UPDATE_NOCHILDREN;
716 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
718 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
722 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
723 send_erase( hwnd, flags, update_rgn, NULL, NULL );
724 /* map region to client coordinates */
725 offset.x = offset.y = 0;
726 ScreenToClient( hwnd, &offset );
727 OffsetRgn( hrgn, offset.x, offset.y );
733 /***********************************************************************
734 * GetUpdateRect (USER32.@)
736 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
738 UINT flags = UPDATE_NOCHILDREN;
741 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
743 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
747 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
749 HDC hdc = GetDCEx( hwnd, 0, DCX_USESTYLE );
750 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
751 DPtoLP( hdc, (LPPOINT)rect, 2 );
752 ReleaseDC( hwnd, hdc );
755 send_erase( hwnd, flags, update_rgn, NULL, NULL );
757 /* check if we still have an update region */
758 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
759 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
763 /***********************************************************************
764 * ExcludeUpdateRgn (USER32.@)
766 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
768 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
769 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
775 GetDCOrgEx( hdc, &pt );
776 MapWindowPoints( 0, hwnd, &pt, 1 );
777 OffsetRgn( update_rgn, -pt.x, -pt.y );
778 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
779 DeleteObject( update_rgn );
785 /*************************************************************************
786 * ScrollWindowEx (USER32.@)
788 * Note: contrary to what the doc says, pixels that are scrolled from the
789 * outside of clipRect to the inside are NOT painted.
792 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
793 const RECT *rect, const RECT *clipRect,
794 HRGN hrgnUpdate, LPRECT rcUpdate,
797 INT retVal = NULLREGION;
799 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
805 HWND hwndCaret = NULL;
806 BOOL moveCaret = FALSE;
809 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
810 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
811 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
812 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
813 FIXME("some flags (%04x) are unhandled\n", flags);
815 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
816 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
818 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
819 hwnd = WIN_GetFullHandle( hwnd );
821 GetClientRect(hwnd, &rc);
822 if (rect) IntersectRect(&rc, &rc, rect);
824 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
827 if( hrgnUpdate ) bOwnRgn = FALSE;
828 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
830 newCaretPos.x = newCaretPos.y = 0;
832 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
833 DWORD dcxflags = DCX_CACHE;
834 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
836 hwndCaret = fix_caret(hwnd, &rc, dx, dy, flags, &moveCaret, &newCaretPos);
838 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
839 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
840 dcxflags |= DCX_PARENTCLIP;
841 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
842 dcxflags |= DCX_CLIPCHILDREN;
843 hDC = GetDCEx( hwnd, 0, dcxflags);
846 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
848 ReleaseDC( hwnd, hDC );
851 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
854 /* If the windows has an update region, this must be
855 * scrolled as well. Keep a copy in hrgnWinupd
856 * to be added to hrngUpdate at the end. */
857 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
858 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
859 if (retVal != NULLREGION)
861 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
863 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
864 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
866 OffsetRgn( hrgnTemp, dx, dy );
867 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
869 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
870 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
871 DeleteObject( hrgnClip );
873 DeleteObject( hrgnTemp );
875 /* nothing was scrolled */
877 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
878 SetRectEmpty( rcUpdate);
881 if( flags & SW_SCROLLCHILDREN )
883 HWND *list = WIN_ListChildren( hwnd );
888 for (i = 0; list[i]; i++)
890 GetWindowRect( list[i], &r );
891 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
892 if (!rect || IntersectRect(&dummy, &r, rect))
893 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
894 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
895 SWP_NOREDRAW | SWP_DEFERERASE );
897 HeapFree( GetProcessHeap(), 0, list );
901 if( flags & (SW_INVALIDATE | SW_ERASE) )
902 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
903 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
906 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
907 DeleteObject( hrgnWinupd);
911 if ( moveCaret ) SetCaretPos( newCaretPos.x, newCaretPos.y );
912 ShowCaret(hwndCaret);
915 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
921 /*************************************************************************
922 * ScrollWindow (USER32.@)
925 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
926 const RECT *rect, const RECT *clipRect )
928 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
929 (rect ? 0 : SW_SCROLLCHILDREN) |
930 SW_INVALIDATE | SW_ERASE ));
934 /*************************************************************************
935 * ScrollDC (USER32.@)
937 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
938 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
939 * logical coordinates.
941 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
942 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
945 return USER_Driver->pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );