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"
33 #include "wine/server.h"
35 #include "user_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 /***********************************************************************
44 static void dump_rdw_flags(UINT flags
)
47 if (flags
& RDW_INVALIDATE
) TRACE(" RDW_INVALIDATE");
48 if (flags
& RDW_INTERNALPAINT
) TRACE(" RDW_INTERNALPAINT");
49 if (flags
& RDW_ERASE
) TRACE(" RDW_ERASE");
50 if (flags
& RDW_VALIDATE
) TRACE(" RDW_VALIDATE");
51 if (flags
& RDW_NOINTERNALPAINT
) TRACE(" RDW_NOINTERNALPAINT");
52 if (flags
& RDW_NOERASE
) TRACE(" RDW_NOERASE");
53 if (flags
& RDW_NOCHILDREN
) TRACE(" RDW_NOCHILDREN");
54 if (flags
& RDW_ALLCHILDREN
) TRACE(" RDW_ALLCHILDREN");
55 if (flags
& RDW_UPDATENOW
) TRACE(" RDW_UPDATENOW");
56 if (flags
& RDW_ERASENOW
) TRACE(" RDW_ERASENOW");
57 if (flags
& RDW_FRAME
) TRACE(" RDW_FRAME");
58 if (flags
& RDW_NOFRAME
) TRACE(" RDW_NOFRAME");
65 RDW_NOINTERNALPAINT | \
74 if (flags
& ~RDW_FLAGS
) TRACE(" %04x", flags
& ~RDW_FLAGS
);
80 /***********************************************************************
83 * Return update region (in screen coordinates) for a window.
85 static HRGN
get_update_region( HWND hwnd
, UINT
*flags
, HWND
*child
)
94 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
96 SetLastError( ERROR_OUTOFMEMORY
);
100 SERVER_START_REQ( get_update_region
)
103 req
->from_child
= child
? *child
: 0;
105 wine_server_set_reply( req
, data
->Buffer
, size
);
106 if (!(status
= wine_server_call( req
)))
108 size_t reply_size
= wine_server_reply_size( reply
);
109 data
->rdh
.dwSize
= sizeof(data
->rdh
);
110 data
->rdh
.iType
= RDH_RECTANGLES
;
111 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
112 data
->rdh
.nRgnSize
= reply_size
;
113 hrgn
= ExtCreateRegion( NULL
, size
, data
);
114 if (child
) *child
= reply
->child
;
115 *flags
= reply
->flags
;
117 else size
= reply
->total_size
;
120 HeapFree( GetProcessHeap(), 0, data
);
121 } while (status
== STATUS_BUFFER_OVERFLOW
);
123 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
128 /***********************************************************************
131 * Get only the update flags, not the update region.
133 static BOOL
get_update_flags( HWND hwnd
, HWND
*child
, UINT
*flags
)
137 SERVER_START_REQ( get_update_region
)
140 req
->from_child
= child
? *child
: 0;
141 req
->flags
= *flags
| UPDATE_NOREGION
;
142 if ((ret
= !wine_server_call_err( req
)))
144 if (child
) *child
= reply
->child
;
145 *flags
= reply
->flags
;
153 /***********************************************************************
154 * redraw_window_rects
156 * Redraw part of a window.
158 static BOOL
redraw_window_rects( HWND hwnd
, UINT flags
, const RECT
*rects
, UINT count
)
162 SERVER_START_REQ( redraw_window
)
166 wine_server_add_data( req
, rects
, count
* sizeof(RECT
) );
167 ret
= !wine_server_call_err( req
);
174 /***********************************************************************
177 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
178 * Helper for erase_now and BeginPaint.
180 static HRGN
send_ncpaint( HWND hwnd
, HWND
*child
, UINT
*flags
)
182 HRGN whole_rgn
= get_update_region( hwnd
, flags
, child
);
185 if (child
) hwnd
= *child
;
192 /* check if update rgn overlaps with nonclient area */
193 type
= GetRgnBox( whole_rgn
, &update
);
194 GetClientRect( hwnd
, &client
);
195 MapWindowPoints( hwnd
, 0, (POINT
*)&client
, 2 );
197 if ((*flags
& UPDATE_NONCLIENT
) ||
198 update
.left
< client
.left
|| update
.top
< client
.top
||
199 update
.right
> client
.right
|| update
.bottom
> client
.bottom
)
201 client_rgn
= CreateRectRgnIndirect( &client
);
202 CombineRgn( client_rgn
, client_rgn
, whole_rgn
, RGN_AND
);
204 /* check if update rgn contains complete nonclient area */
205 if (type
== SIMPLEREGION
)
208 GetWindowRect( hwnd
, &window
);
209 if (EqualRect( &window
, &update
))
211 DeleteObject( whole_rgn
);
218 client_rgn
= whole_rgn
;
222 if (whole_rgn
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
224 if (*flags
& UPDATE_NONCLIENT
) SendMessageW( hwnd
, WM_NCPAINT
, (WPARAM
)whole_rgn
, 0 );
225 if (whole_rgn
> (HRGN
)1) DeleteObject( whole_rgn
);
232 /***********************************************************************
235 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
236 * If a DC is requested, the region is selected into it. In all cases the region is deleted.
237 * Helper for erase_now and BeginPaint.
239 static BOOL
send_erase( HWND hwnd
, UINT flags
, HRGN client_rgn
,
240 RECT
*clip_rect
, HDC
*hdc_ret
)
242 BOOL need_erase
= FALSE
;
246 if (!clip_rect
) clip_rect
= &dummy
;
247 if (hdc_ret
|| (flags
& UPDATE_ERASE
))
249 UINT dcx_flags
= DCX_INTERSECTRGN
| DCX_USESTYLE
;
250 if (IsIconic(hwnd
)) dcx_flags
|= DCX_WINDOW
;
252 if ((hdc
= GetDCEx( hwnd
, client_rgn
, dcx_flags
)))
254 INT type
= GetClipBox( hdc
, clip_rect
);
256 if (flags
& UPDATE_ERASE
)
258 /* don't erase if the clip box is empty */
259 if (type
!= NULLREGION
)
260 need_erase
= !SendMessageW( hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0 );
264 if (need_erase
&& hwnd
!= GetDesktopWindow()) /* FIXME: mark it as needing erase again */
265 RedrawWindow( hwnd
, clip_rect
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_NOCHILDREN
);
266 USER_Driver
->pReleaseDC( hwnd
, hdc
, TRUE
);
270 if (hdc_ret
) *hdc_ret
= hdc
;
272 if (!hdc
) DeleteObject( client_rgn
);
277 /***********************************************************************
280 * Implementation of RDW_ERASENOW behavior.
282 static void erase_now( HWND hwnd
, UINT rdw_flags
)
287 /* loop while we find a child to repaint */
290 UINT flags
= UPDATE_NONCLIENT
| UPDATE_ERASE
;
292 if (rdw_flags
& RDW_NOCHILDREN
) flags
|= UPDATE_NOCHILDREN
;
293 else if (rdw_flags
& RDW_ALLCHILDREN
) flags
|= UPDATE_ALLCHILDREN
;
295 if (!(hrgn
= send_ncpaint( hwnd
, &child
, &flags
))) break;
296 send_erase( child
, flags
, hrgn
, NULL
, NULL
);
298 if (!flags
) break; /* nothing more to do */
299 if (rdw_flags
& RDW_NOCHILDREN
) break;
304 /***********************************************************************
307 * Implementation of RDW_UPDATENOW behavior.
309 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
310 * SendMessage() calls. This is a comment inside DefWindowProc() source
313 * This message avoids lots of inter-app message traffic
314 * by switching to the other task and continuing the
318 * LOWORD(lParam) = hrgnClip
319 * HIWORD(lParam) = hwndSkip (not used; always NULL)
322 static void update_now( HWND hwnd
, UINT rdw_flags
)
326 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
327 if (hwnd
== GetDesktopWindow()) erase_now( hwnd
, rdw_flags
| RDW_NOCHILDREN
);
329 /* loop while we find a child to repaint */
332 UINT flags
= UPDATE_PAINT
| UPDATE_INTERNALPAINT
;
334 if (rdw_flags
& RDW_NOCHILDREN
) flags
|= UPDATE_NOCHILDREN
;
335 else if (rdw_flags
& RDW_ALLCHILDREN
) flags
|= UPDATE_ALLCHILDREN
;
337 if (!get_update_flags( hwnd
, &child
, &flags
)) break;
338 if (!flags
) break; /* nothing more to do */
340 SendMessageW( child
, WM_PAINT
, 0, 0 );
341 if (rdw_flags
& RDW_NOCHILDREN
) break;
346 /*************************************************************************
349 * Helper for ScrollWindowEx:
350 * If the return value is 0, no special caret handling is necessary.
351 * Otherwise the return value is the handle of the window that owns the
352 * caret. Its caret needs to be hidden during the scroll operation and
353 * moved to new_caret_pos if move_caret is TRUE.
355 static HWND
fix_caret(HWND hWnd
, const LPRECT scroll_rect
, INT dx
, INT dy
,
356 UINT flags
, LPBOOL move_caret
, LPPOINT new_caret_pos
)
359 RECT rect
, mapped_rcCaret
;
360 BOOL hide_caret
= FALSE
;
362 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info
)) return 0;
363 if (!info
.hwndCaret
) return 0;
365 if (info
.hwndCaret
== hWnd
)
367 /* Move the caret if it's (partially) in the source rectangle */
368 if (IntersectRect(&rect
, scroll_rect
, &info
.rcCaret
))
372 new_caret_pos
->x
= info
.rcCaret
.left
+ dx
;
373 new_caret_pos
->y
= info
.rcCaret
.top
+ dy
;
379 /* Hide the caret if it's in the destination rectangle */
381 OffsetRect(&rect
, dx
, dy
);
382 hide_caret
= IntersectRect(&rect
, &rect
, &info
.rcCaret
);
387 if ((flags
& SW_SCROLLCHILDREN
) && IsChild(hWnd
, info
.hwndCaret
))
391 /* Hide the caret if it's in the source or in the destination
393 mapped_rcCaret
= info
.rcCaret
;
394 MapWindowPoints(info
.hwndCaret
, hWnd
, (LPPOINT
)&mapped_rcCaret
, 2);
396 if (IntersectRect(&rect
, scroll_rect
, &mapped_rcCaret
))
403 OffsetRect(&rect
, dx
, dy
);
404 hide_caret
= IntersectRect(&rect
, &rect
, &mapped_rcCaret
);
413 HideCaret(info
.hwndCaret
);
414 return info
.hwndCaret
;
421 /***********************************************************************
422 * BeginPaint (USER32.@)
424 HDC WINAPI
BeginPaint( HWND hwnd
, PAINTSTRUCT
*lps
)
428 UINT flags
= UPDATE_NONCLIENT
| UPDATE_ERASE
| UPDATE_PAINT
| UPDATE_INTERNALPAINT
| UPDATE_NOCHILDREN
;
432 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
435 FIXME( "window %p belongs to other thread\n", hwnd
);
442 if (!(hrgn
= send_ncpaint( hwnd
, NULL
, &flags
))) return 0;
444 lps
->fErase
= send_erase( hwnd
, flags
, hrgn
, &lps
->rcPaint
, &lps
->hdc
);
446 TRACE("hdc = %p box = (%ld,%ld - %ld,%ld), fErase = %d\n",
447 lps
->hdc
, lps
->rcPaint
.left
, lps
->rcPaint
.top
, lps
->rcPaint
.right
, lps
->rcPaint
.bottom
,
454 /***********************************************************************
455 * EndPaint (USER32.@)
457 BOOL WINAPI
EndPaint( HWND hwnd
, const PAINTSTRUCT
*lps
)
459 if (!lps
) return FALSE
;
460 USER_Driver
->pReleaseDC( hwnd
, lps
->hdc
, TRUE
);
466 /***********************************************************************
469 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
471 if (!hwnd
) hwnd
= GetDesktopWindow();
472 else hwnd
= WIN_GetFullHandle( hwnd
);
474 return USER_Driver
->pGetDCEx( hwnd
, hrgnClip
, flags
);
478 /***********************************************************************
481 * Get a device context.
484 * Success: Handle to the device context
487 HDC WINAPI
GetDC( HWND hwnd
)
489 if (!hwnd
) return GetDCEx( 0, 0, DCX_CACHE
| DCX_WINDOW
);
490 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
494 /***********************************************************************
495 * GetWindowDC (USER32.@)
497 HDC WINAPI
GetWindowDC( HWND hwnd
)
499 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
503 /***********************************************************************
504 * ReleaseDC (USER32.@)
506 * Release a device context.
509 * Success: Non-zero. Resources used by hdc are released.
512 INT WINAPI
ReleaseDC( HWND hwnd
, HDC hdc
)
514 return USER_Driver
->pReleaseDC( hwnd
, hdc
, FALSE
);
518 /**********************************************************************
519 * WindowFromDC (USER32.@)
521 HWND WINAPI
WindowFromDC( HDC hDC
)
523 return USER_Driver
->pWindowFromDC( hDC
);
527 /***********************************************************************
528 * LockWindowUpdate (USER32.@)
530 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
532 static HWND lockedWnd
;
534 /* This function is fully implemented by the following patch:
536 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
538 * but in order to work properly, it needs the ability to invalidate
539 * DCEs in other processes when the lock window is changed, which
540 * isn't possible yet.
544 FIXME("(%p), partial stub!\n",hwnd
);
551 /* Unlock lockedWnd */
552 /* FIXME: Do something */
556 /* Attempted to lock a second window */
557 /* Return FALSE and do nothing */
568 /***********************************************************************
569 * RedrawWindow (USER32.@)
571 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rect
, HRGN hrgn
, UINT flags
)
575 if (!hwnd
) hwnd
= GetDesktopWindow();
582 GetRgnBox( hrgn
, &r
);
583 TRACE( "%p region %p box %s ", hwnd
, hrgn
, wine_dbgstr_rect(&r
) );
586 TRACE( "%p rect %s ", hwnd
, wine_dbgstr_rect(rect
) );
588 TRACE( "%p whole window ", hwnd
);
590 dump_rdw_flags(flags
);
593 /* process pending expose events before painting */
594 if (flags
& RDW_UPDATENOW
) USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_PAINT
, 0 );
598 ret
= redraw_window_rects( hwnd
, flags
, rect
, 1 );
602 ret
= redraw_window_rects( hwnd
, flags
, NULL
, 0 );
604 else /* need to build a list of the region rectangles */
607 RGNDATA
*data
= NULL
;
608 static const RECT empty
;
610 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
611 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
612 GetRegionData( hrgn
, size
, data
);
613 if (!data
->rdh
.nCount
) /* empty region -> use a single all-zero rectangle */
614 ret
= redraw_window_rects( hwnd
, flags
, &empty
, 1 );
616 ret
= redraw_window_rects( hwnd
, flags
, (const RECT
*)data
->Buffer
, data
->rdh
.nCount
);
617 HeapFree( GetProcessHeap(), 0, data
);
620 if (flags
& RDW_UPDATENOW
) update_now( hwnd
, flags
);
621 else if (flags
& RDW_ERASENOW
) erase_now( hwnd
, flags
);
627 /***********************************************************************
628 * UpdateWindow (USER32.@)
630 BOOL WINAPI
UpdateWindow( HWND hwnd
)
632 return RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
636 /***********************************************************************
637 * InvalidateRgn (USER32.@)
639 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
643 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
647 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
651 /***********************************************************************
652 * InvalidateRect (USER32.@)
654 * MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
655 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
657 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
659 UINT flags
= RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0);
663 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
667 return RedrawWindow( hwnd
, rect
, 0, flags
);
671 /***********************************************************************
672 * ValidateRgn (USER32.@)
674 BOOL WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
678 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
682 return RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
);
686 /***********************************************************************
687 * ValidateRect (USER32.@)
689 * MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
690 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
692 BOOL WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
694 UINT flags
= RDW_VALIDATE
;
698 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
702 return RedrawWindow( hwnd
, rect
, 0, flags
);
706 /***********************************************************************
707 * GetUpdateRgn (USER32.@)
709 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
712 UINT flags
= UPDATE_NOCHILDREN
;
715 if (erase
) flags
|= UPDATE_NONCLIENT
| UPDATE_ERASE
;
717 if ((update_rgn
= send_ncpaint( hwnd
, NULL
, &flags
)))
721 retval
= CombineRgn( hrgn
, update_rgn
, 0, RGN_COPY
);
722 send_erase( hwnd
, flags
, update_rgn
, NULL
, NULL
);
723 /* map region to client coordinates */
724 offset
.x
= offset
.y
= 0;
725 ScreenToClient( hwnd
, &offset
);
726 OffsetRgn( hrgn
, offset
.x
, offset
.y
);
732 /***********************************************************************
733 * GetUpdateRect (USER32.@)
735 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
737 UINT flags
= UPDATE_NOCHILDREN
;
740 if (erase
) flags
|= UPDATE_NONCLIENT
| UPDATE_ERASE
;
742 if (!(update_rgn
= send_ncpaint( hwnd
, NULL
, &flags
))) return FALSE
;
746 if (GetRgnBox( update_rgn
, rect
) != NULLREGION
)
748 HDC hdc
= GetDCEx( hwnd
, 0, DCX_USESTYLE
);
749 MapWindowPoints( 0, hwnd
, (LPPOINT
)rect
, 2 );
750 DPtoLP( hdc
, (LPPOINT
)rect
, 2 );
751 ReleaseDC( hwnd
, hdc
);
754 send_erase( hwnd
, flags
, update_rgn
, NULL
, NULL
);
756 /* check if we still have an update region */
757 flags
= UPDATE_PAINT
| UPDATE_NOCHILDREN
;
758 return (get_update_flags( hwnd
, NULL
, &flags
) && (flags
& UPDATE_PAINT
));
762 /***********************************************************************
763 * ExcludeUpdateRgn (USER32.@)
765 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
767 HRGN update_rgn
= CreateRectRgn( 0, 0, 0, 0 );
768 INT ret
= GetUpdateRgn( hwnd
, update_rgn
, FALSE
);
774 GetDCOrgEx( hdc
, &pt
);
775 MapWindowPoints( 0, hwnd
, &pt
, 1 );
776 OffsetRgn( update_rgn
, -pt
.x
, -pt
.y
);
777 ret
= ExtSelectClipRgn( hdc
, update_rgn
, RGN_DIFF
);
778 DeleteObject( update_rgn
);
784 /*************************************************************************
785 * ScrollWindowEx (USER32.@)
787 * Note: contrary to what the doc says, pixels that are scrolled from the
788 * outside of clipRect to the inside are NOT painted.
791 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
792 const RECT
*rect
, const RECT
*clipRect
,
793 HRGN hrgnUpdate
, LPRECT rcUpdate
,
796 INT retVal
= NULLREGION
;
798 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
804 HWND hwndCaret
= NULL
;
805 BOOL moveCaret
= FALSE
;
808 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
809 hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
, wine_dbgstr_rect(rect
), flags
);
810 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect
));
811 if( flags
& ~( SW_SCROLLCHILDREN
| SW_INVALIDATE
| SW_ERASE
))
812 FIXME("some flags (%04x) are unhandled\n", flags
);
814 rdw_flags
= (flags
& SW_ERASE
) && (flags
& SW_INVALIDATE
) ?
815 RDW_INVALIDATE
| RDW_ERASE
: RDW_INVALIDATE
;
817 if (!WIN_IsWindowDrawable( hwnd
, TRUE
)) return ERROR
;
818 hwnd
= WIN_GetFullHandle( hwnd
);
820 GetClientRect(hwnd
, &rc
);
821 if (rect
) IntersectRect(&rc
, &rc
, rect
);
823 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
826 if( hrgnUpdate
) bOwnRgn
= FALSE
;
827 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
829 newCaretPos
.x
= newCaretPos
.y
= 0;
831 if( !IsRectEmpty(&cliprc
) && (dx
|| dy
)) {
832 DWORD dcxflags
= DCX_CACHE
;
833 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
835 hwndCaret
= fix_caret(hwnd
, &rc
, dx
, dy
, flags
, &moveCaret
, &newCaretPos
);
837 if( style
& WS_CLIPSIBLINGS
) dcxflags
|= DCX_CLIPSIBLINGS
;
838 if( GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
839 dcxflags
|= DCX_PARENTCLIP
;
840 if( !(flags
& SW_SCROLLCHILDREN
) && (style
& WS_CLIPCHILDREN
))
841 dcxflags
|= DCX_CLIPCHILDREN
;
842 hDC
= GetDCEx( hwnd
, 0, dcxflags
);
845 ScrollDC( hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
847 ReleaseDC( hwnd
, hDC
);
850 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
);
853 /* If the windows has an update region, this must be
854 * scrolled as well. Keep a copy in hrgnWinupd
855 * to be added to hrngUpdate at the end. */
856 hrgnTemp
= CreateRectRgn( 0, 0, 0, 0 );
857 retVal
= GetUpdateRgn( hwnd
, hrgnTemp
, FALSE
);
858 if (retVal
!= NULLREGION
)
860 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
862 hrgnWinupd
= CreateRectRgn( 0, 0, 0, 0);
863 CombineRgn( hrgnWinupd
, hrgnTemp
, 0, RGN_COPY
);
865 OffsetRgn( hrgnTemp
, dx
, dy
);
866 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
868 CombineRgn( hrgnWinupd
, hrgnWinupd
, hrgnTemp
, RGN_OR
);
869 RedrawWindow( hwnd
, NULL
, hrgnTemp
, rdw_flags
);
870 DeleteObject( hrgnClip
);
872 DeleteObject( hrgnTemp
);
874 /* nothing was scrolled */
876 SetRectRgn( hrgnUpdate
, 0, 0, 0, 0 );
877 SetRectEmpty( rcUpdate
);
880 if( flags
& SW_SCROLLCHILDREN
)
882 HWND
*list
= WIN_ListChildren( hwnd
);
887 for (i
= 0; list
[i
]; i
++)
889 GetWindowRect( list
[i
], &r
);
890 MapWindowPoints( 0, hwnd
, (POINT
*)&r
, 2 );
891 if (!rect
|| IntersectRect(&dummy
, &r
, rect
))
892 SetWindowPos( list
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
893 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
894 SWP_NOREDRAW
| SWP_DEFERERASE
);
896 HeapFree( GetProcessHeap(), 0, list
);
900 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
901 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
|
902 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ) );
905 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnWinupd
, RGN_OR
);
906 DeleteObject( hrgnWinupd
);
910 if ( moveCaret
) SetCaretPos( newCaretPos
.x
, newCaretPos
.y
);
911 ShowCaret(hwndCaret
);
914 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
920 /*************************************************************************
921 * ScrollWindow (USER32.@)
924 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
925 const RECT
*rect
, const RECT
*clipRect
)
927 return (ERROR
!= ScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
928 (rect
? 0 : SW_SCROLLCHILDREN
) |
929 SW_INVALIDATE
| SW_ERASE
));
933 /*************************************************************************
934 * ScrollDC (USER32.@)
936 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
937 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
938 * logical coordinates.
940 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*lprcScroll
,
941 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
944 return USER_Driver
->pScrollDC( hdc
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
);