Moved the ScrollWindow and ScrollDC functions to dlls/user/painting.c,
[wine.git] / dlls / user / painting.c
blobf817c452c5d2dbf63ad5d6ad2d61742661fc7518
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "ntstatus.h"
32 #include "winuser.h"
33 #include "wine/server.h"
34 #include "win.h"
35 #include "user_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 /***********************************************************************
42 * dump_rdw_flags
44 static void dump_rdw_flags(UINT flags)
46 TRACE("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");
60 #define RDW_FLAGS \
61 (RDW_INVALIDATE | \
62 RDW_INTERNALPAINT | \
63 RDW_ERASE | \
64 RDW_VALIDATE | \
65 RDW_NOINTERNALPAINT | \
66 RDW_NOERASE | \
67 RDW_NOCHILDREN | \
68 RDW_ALLCHILDREN | \
69 RDW_UPDATENOW | \
70 RDW_ERASENOW | \
71 RDW_FRAME | \
72 RDW_NOFRAME)
74 if (flags & ~RDW_FLAGS) TRACE(" %04x", flags & ~RDW_FLAGS);
75 TRACE("\n");
76 #undef RDW_FLAGS
80 /***********************************************************************
81 * get_update_region
83 * Return update region (in screen coordinates) for a window.
85 static HRGN get_update_region( HWND hwnd, UINT *flags, HWND *child )
87 HRGN hrgn = 0;
88 NTSTATUS status;
89 RGNDATA *data;
90 size_t size = 256;
94 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
96 SetLastError( ERROR_OUTOFMEMORY );
97 return 0;
100 SERVER_START_REQ( get_update_region )
102 req->window = hwnd;
103 req->flags = *flags;
104 wine_server_set_reply( req, data->Buffer, size );
105 if (!(status = wine_server_call( req )))
107 size_t reply_size = wine_server_reply_size( reply );
108 data->rdh.dwSize = sizeof(data->rdh);
109 data->rdh.iType = RDH_RECTANGLES;
110 data->rdh.nCount = reply_size / sizeof(RECT);
111 data->rdh.nRgnSize = reply_size;
112 hrgn = ExtCreateRegion( NULL, size, data );
113 if (child) *child = reply->child;
114 *flags = reply->flags;
116 else size = reply->total_size;
118 SERVER_END_REQ;
119 HeapFree( GetProcessHeap(), 0, data );
120 } while (status == STATUS_BUFFER_OVERFLOW);
122 if (status) SetLastError( RtlNtStatusToDosError(status) );
123 return hrgn;
127 /***********************************************************************
128 * get_update_flags
130 * Get only the update flags, not the update region.
132 static BOOL get_update_flags( HWND hwnd, HWND *child, UINT *flags )
134 BOOL ret;
136 SERVER_START_REQ( get_update_region )
138 req->window = hwnd;
139 req->flags = *flags | UPDATE_NOREGION;
140 if ((ret = !wine_server_call_err( req )))
142 if (child) *child = reply->child;
143 *flags = reply->flags;
146 SERVER_END_REQ;
147 return ret;
151 /***********************************************************************
152 * redraw_window_rects
154 * Redraw part of a window.
156 static BOOL redraw_window_rects( HWND hwnd, UINT flags, const RECT *rects, UINT count )
158 BOOL ret;
160 SERVER_START_REQ( redraw_window )
162 req->window = hwnd;
163 req->flags = flags;
164 wine_server_add_data( req, rects, count * sizeof(RECT) );
165 ret = !wine_server_call_err( req );
167 SERVER_END_REQ;
168 return ret;
172 /***********************************************************************
173 * send_ncpaint
175 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
176 * Helper for erase_now and BeginPaint.
178 static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags )
180 HRGN whole_rgn = get_update_region( hwnd, flags, child );
181 HRGN client_rgn = 0;
183 if (child) hwnd = *child;
185 if (whole_rgn)
187 RECT client, update;
188 INT type;
190 /* check if update rgn overlaps with nonclient area */
191 type = GetRgnBox( whole_rgn, &update );
192 GetClientRect( hwnd, &client );
193 MapWindowPoints( hwnd, 0, (POINT *)&client, 2 );
195 if ((*flags & UPDATE_NONCLIENT) ||
196 update.left < client.left || update.top < client.top ||
197 update.right > client.right || update.bottom > client.bottom)
199 client_rgn = CreateRectRgnIndirect( &client );
200 CombineRgn( client_rgn, client_rgn, whole_rgn, RGN_AND );
202 /* check if update rgn contains complete nonclient area */
203 if (type == SIMPLEREGION)
205 RECT window;
206 GetWindowRect( hwnd, &window );
207 if (EqualRect( &window, &update ))
209 DeleteObject( whole_rgn );
210 whole_rgn = (HRGN)1;
214 else
216 client_rgn = whole_rgn;
217 whole_rgn = 0;
220 if (whole_rgn) /* NOTE: WM_NCPAINT allows wParam to be 1 */
222 if (*flags & UPDATE_NONCLIENT) SendMessageW( hwnd, WM_NCPAINT, (WPARAM)whole_rgn, 0 );
223 if (whole_rgn > (HRGN)1) DeleteObject( whole_rgn );
226 return client_rgn;
230 /***********************************************************************
231 * send_erase
233 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
234 * If a DC is requested, the region is selected into it.
235 * Helper for erase_now and BeginPaint.
237 static BOOL send_erase( HWND hwnd, UINT flags, HRGN client_rgn,
238 RECT *clip_rect, HDC *hdc_ret )
240 BOOL need_erase = FALSE;
241 HDC hdc;
242 RECT dummy;
244 if (!clip_rect) clip_rect = &dummy;
245 if (hdc_ret || (flags & UPDATE_ERASE))
247 UINT dcx_flags = DCX_INTERSECTRGN | DCX_USESTYLE;
248 if (IsIconic(hwnd)) dcx_flags |= DCX_WINDOW;
250 if ((hdc = GetDCEx( hwnd, client_rgn, dcx_flags )))
252 INT type = GetClipBox( hdc, clip_rect );
254 if (flags & UPDATE_ERASE)
256 /* don't erase if the clip box is empty */
257 if (type != NULLREGION)
258 need_erase = !SendMessageW( hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0 );
260 if (!hdc_ret)
262 if (need_erase && hwnd != GetDesktopWindow()) /* FIXME: mark it as needing erase again */
263 RedrawWindow( hwnd, clip_rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
264 ReleaseDC( hwnd, hdc );
268 if (hdc_ret) *hdc_ret = hdc;
270 return need_erase;
274 /***********************************************************************
275 * erase_now
277 * Implementation of RDW_ERASENOW behavior.
279 static void erase_now( HWND hwnd, UINT rdw_flags )
281 HWND child;
282 HRGN hrgn;
284 /* loop while we find a child to repaint */
285 for (;;)
287 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE;
289 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
290 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
292 if (!(hrgn = send_ncpaint( hwnd, &child, &flags ))) break;
293 send_erase( child, flags, hrgn, NULL, NULL );
294 DeleteObject( hrgn );
296 if (!flags) break; /* nothing more to do */
297 if (rdw_flags & RDW_NOCHILDREN) break;
302 /***********************************************************************
303 * update_now
305 * Implementation of RDW_UPDATENOW behavior.
307 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
308 * SendMessage() calls. This is a comment inside DefWindowProc() source
309 * from 16-bit SDK:
311 * This message avoids lots of inter-app message traffic
312 * by switching to the other task and continuing the
313 * recursion there.
315 * wParam = flags
316 * LOWORD(lParam) = hrgnClip
317 * HIWORD(lParam) = hwndSkip (not used; always NULL)
320 static void update_now( HWND hwnd, UINT rdw_flags )
322 HWND prev = 0, child;
324 /* process pending expose events before painting */
325 MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_PAINT );
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 */
331 for (;;)
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 if (child == prev) /* same window again, didn't get repainted properly */
343 UINT erase_flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_NOCHILDREN;
344 HRGN hrgn;
346 TRACE( "%p not repainted properly, erasing\n", child );
347 if ((hrgn = send_ncpaint( child, NULL, &erase_flags )))
349 send_erase( child, erase_flags, hrgn, NULL, NULL );
350 DeleteObject( hrgn );
352 prev = 0;
354 else
356 prev = child;
357 SendMessageW( child, WM_PAINT, 0, 0 );
359 if (rdw_flags & RDW_NOCHILDREN) break;
364 /*************************************************************************
365 * fix_caret
367 * Helper for ScrollWindowEx.
369 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
371 GUITHREADINFO info;
373 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
374 if (!info.hwndCaret) return 0;
375 if (info.hwndCaret == hWnd ||
376 ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret)))
378 POINT pt;
379 pt.x = info.rcCaret.left;
380 pt.y = info.rcCaret.top;
381 MapWindowPoints( info.hwndCaret, hWnd, (LPPOINT)&info.rcCaret, 2 );
382 if( IntersectRect(lprc, lprc, &info.rcCaret) )
384 HideCaret(0);
385 lprc->left = pt.x;
386 lprc->top = pt.y;
387 return info.hwndCaret;
390 return 0;
394 /***********************************************************************
395 * BeginPaint (USER32.@)
397 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
399 HWND full_handle;
400 HRGN hrgn;
401 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
403 if (!lps) return 0;
405 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
407 if (IsWindow(hwnd))
408 FIXME( "window %p belongs to other thread\n", hwnd );
409 return 0;
411 hwnd = full_handle;
413 HideCaret( hwnd );
415 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
417 lps->fErase = send_erase( hwnd, flags, hrgn, &lps->rcPaint, &lps->hdc );
418 if (!lps->hdc) DeleteObject( hrgn );
420 TRACE("hdc = %p box = (%ld,%ld - %ld,%ld), fErase = %d\n",
421 lps->hdc, lps->rcPaint.left, lps->rcPaint.top, lps->rcPaint.right, lps->rcPaint.bottom,
422 lps->fErase);
424 return lps->hdc;
428 /***********************************************************************
429 * EndPaint (USER32.@)
431 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
433 if (!lps) return FALSE;
434 if (USER_Driver.pReleaseDC) USER_Driver.pReleaseDC( hwnd, lps->hdc, TRUE );
435 ShowCaret( hwnd );
436 return TRUE;
440 /***********************************************************************
441 * GetDCEx (USER32.@)
443 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
445 if (!hwnd) hwnd = GetDesktopWindow();
446 else hwnd = WIN_GetFullHandle( hwnd );
448 if (USER_Driver.pGetDCEx) return USER_Driver.pGetDCEx( hwnd, hrgnClip, flags );
449 return 0;
453 /***********************************************************************
454 * GetDC (USER32.@)
456 * Get a device context.
458 * RETURNS
459 * Success: Handle to the device context
460 * Failure: NULL.
462 HDC WINAPI GetDC( HWND hwnd )
464 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
465 return GetDCEx( hwnd, 0, DCX_USESTYLE );
469 /***********************************************************************
470 * GetWindowDC (USER32.@)
472 HDC WINAPI GetWindowDC( HWND hwnd )
474 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
478 /***********************************************************************
479 * ReleaseDC (USER32.@)
481 * Release a device context.
483 * RETURNS
484 * Success: Non-zero. Resources used by hdc are released.
485 * Failure: 0.
487 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
489 if (USER_Driver.pReleaseDC) return USER_Driver.pReleaseDC( hwnd, hdc, FALSE );
490 return 0;
494 /**********************************************************************
495 * WindowFromDC (USER32.@)
497 HWND WINAPI WindowFromDC( HDC hDC )
499 if (USER_Driver.pWindowFromDC) return USER_Driver.pWindowFromDC( hDC );
500 return 0;
504 /***********************************************************************
505 * LockWindowUpdate (USER32.@)
507 BOOL WINAPI LockWindowUpdate( HWND hwnd )
509 static HWND lockedWnd;
511 /* This function is fully implemented by the following patch:
513 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
515 * but in order to work properly, it needs the ability to invalidate
516 * DCEs in other processes when the lock window is changed, which
517 * isn't possible yet.
518 * -mike
521 FIXME("(%p), partial stub!\n",hwnd);
523 USER_Lock();
524 if (lockedWnd)
526 if (!hwnd)
528 /* Unlock lockedWnd */
529 /* FIXME: Do something */
531 else
533 /* Attempted to lock a second window */
534 /* Return FALSE and do nothing */
535 USER_Unlock();
536 return FALSE;
539 lockedWnd = hwnd;
540 USER_Unlock();
541 return TRUE;
545 /***********************************************************************
546 * RedrawWindow (USER32.@)
548 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
550 BOOL ret;
552 if (!hwnd) hwnd = GetDesktopWindow();
554 if (TRACE_ON(win))
556 if (hrgn)
558 RECT r;
559 GetRgnBox( hrgn, &r );
560 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
562 else if (rect)
563 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
564 else
565 TRACE( "%p whole window ", hwnd );
567 dump_rdw_flags(flags);
570 if (rect && !hrgn)
572 ret = redraw_window_rects( hwnd, flags, rect, 1 );
574 else if (!hrgn)
576 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
578 else /* need to build a list of the region rectangles */
580 DWORD size;
581 RGNDATA *data = NULL;
582 static const RECT empty;
584 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
585 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
586 GetRegionData( hrgn, size, data );
587 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
588 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
589 else
590 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
591 HeapFree( GetProcessHeap(), 0, data );
594 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
595 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
597 return ret;
601 /***********************************************************************
602 * UpdateWindow (USER32.@)
604 BOOL WINAPI UpdateWindow( HWND hwnd )
606 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
610 /***********************************************************************
611 * InvalidateRgn (USER32.@)
613 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
615 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
619 /***********************************************************************
620 * InvalidateRect (USER32.@)
622 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
624 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
628 /***********************************************************************
629 * ValidateRgn (USER32.@)
631 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
633 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
637 /***********************************************************************
638 * ValidateRect (USER32.@)
640 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
642 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE );
646 /***********************************************************************
647 * GetUpdateRgn (USER32.@)
649 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
651 INT retval = ERROR;
652 UINT flags = UPDATE_NOCHILDREN;
653 HRGN update_rgn;
655 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
657 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
659 POINT offset;
660 send_erase( hwnd, flags, update_rgn, NULL, NULL );
661 /* map region to client coordinates */
662 offset.x = offset.y = 0;
663 ScreenToClient( hwnd, &offset );
664 OffsetRgn( update_rgn, offset.x, offset.y );
665 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
666 DeleteObject( update_rgn );
668 return retval;
672 /***********************************************************************
673 * GetUpdateRect (USER32.@)
675 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
677 HDC hdc;
678 UINT flags = UPDATE_NOCHILDREN;
679 HRGN update_rgn;
681 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
683 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
685 if (rect)
687 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
688 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
691 send_erase( hwnd, flags, update_rgn, NULL, &hdc );
692 if (hdc)
694 if (rect) DPtoLP( hdc, (LPPOINT)rect, 2 );
695 ReleaseDC( hwnd, hdc );
697 else DeleteObject( update_rgn );
699 /* check if we still have an update region */
700 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
701 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
705 /***********************************************************************
706 * ExcludeUpdateRgn (USER32.@)
708 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
710 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
711 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
713 if (ret != ERROR)
715 POINT pt;
717 GetDCOrgEx( hdc, &pt );
718 MapWindowPoints( 0, hwnd, &pt, 1 );
719 OffsetRgn( update_rgn, -pt.x, -pt.y );
720 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
721 DeleteObject( update_rgn );
723 return ret;
727 /*************************************************************************
728 * ScrollWindowEx (USER32.@)
730 * Note: contrary to what the doc says, pixels that are scrolled from the
731 * outside of clipRect to the inside are NOT painted.
734 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
735 const RECT *rect, const RECT *clipRect,
736 HRGN hrgnUpdate, LPRECT rcUpdate,
737 UINT flags )
739 INT retVal = NULLREGION;
740 BOOL bOwnRgn = TRUE;
741 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
742 int rdw_flags;
743 HRGN hrgnTemp;
744 HRGN hrgnWinupd = 0;
745 HDC hDC;
746 RECT rc, cliprc;
747 RECT caretrc;
748 HWND hwndCaret = NULL;
750 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
751 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
752 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
753 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
754 FIXME("some flags (%04x) are unhandled\n", flags);
756 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
757 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
759 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
760 hwnd = WIN_GetFullHandle( hwnd );
762 GetClientRect(hwnd, &rc);
763 if (rect) IntersectRect(&rc, &rc, rect);
765 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
766 else cliprc = rc;
768 if( hrgnUpdate ) bOwnRgn = FALSE;
769 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
771 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
772 DWORD dcxflags = DCX_CACHE;
773 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
774 caretrc = rc;
775 hwndCaret = fix_caret(hwnd, &caretrc, flags);
777 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
778 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
779 dcxflags |= DCX_PARENTCLIP;
780 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
781 dcxflags |= DCX_CLIPCHILDREN;
782 hDC = GetDCEx( hwnd, 0, dcxflags);
783 if (hDC)
785 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
787 ReleaseDC( hwnd, hDC );
789 if (!bUpdate)
790 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
793 /* If the windows has an update region, this must be
794 * scrolled as well. Keep a copy in hrgnWinupd
795 * to be added to hrngUpdate at the end. */
796 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
797 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
798 if (retVal != NULLREGION)
800 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
801 if( !bOwnRgn) {
802 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
803 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
805 OffsetRgn( hrgnTemp, dx, dy );
806 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
807 if( !bOwnRgn)
808 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
809 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
810 DeleteObject( hrgnClip );
812 DeleteObject( hrgnTemp );
813 } else {
814 /* nothing was scrolled */
815 if( !bOwnRgn)
816 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
817 SetRectEmpty( rcUpdate);
820 if( flags & SW_SCROLLCHILDREN )
822 HWND *list = WIN_ListChildren( hwnd );
823 if (list)
825 int i;
826 RECT r, dummy;
827 for (i = 0; list[i]; i++)
829 GetWindowRect( list[i], &r );
830 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
831 if (!rect || IntersectRect(&dummy, &r, rect))
832 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
833 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
834 SWP_NOREDRAW | SWP_DEFERERASE );
836 HeapFree( GetProcessHeap(), 0, list );
840 if( flags & (SW_INVALIDATE | SW_ERASE) )
841 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
842 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
844 if( hrgnWinupd) {
845 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
846 DeleteObject( hrgnWinupd);
849 if( hwndCaret ) {
850 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
851 ShowCaret(hwndCaret);
854 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
856 return retVal;
860 /*************************************************************************
861 * ScrollWindow (USER32.@)
864 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
865 const RECT *rect, const RECT *clipRect )
867 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
868 (rect ? 0 : SW_SCROLLCHILDREN) |
869 SW_INVALIDATE | SW_ERASE ));
873 /*************************************************************************
874 * ScrollDC (USER32.@)
876 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
877 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
878 * logical coordinates.
880 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
881 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
884 if (USER_Driver.pScrollDC)
885 return USER_Driver.pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
886 return FALSE;