Don't prefix the functions DllInstall and DllGetVersion with the dll
[wine/multimedia.git] / dlls / user / painting.c
blob5e20162396e919b4a503fca2685fb1c1e313dab9
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->from_child = child ? *child : 0;
104 req->flags = *flags;
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;
119 SERVER_END_REQ;
120 HeapFree( GetProcessHeap(), 0, data );
121 } while (status == STATUS_BUFFER_OVERFLOW);
123 if (status) SetLastError( RtlNtStatusToDosError(status) );
124 return hrgn;
128 /***********************************************************************
129 * get_update_flags
131 * Get only the update flags, not the update region.
133 static BOOL get_update_flags( HWND hwnd, HWND *child, UINT *flags )
135 BOOL ret;
137 SERVER_START_REQ( get_update_region )
139 req->window = hwnd;
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;
148 SERVER_END_REQ;
149 return ret;
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 )
160 BOOL ret;
162 SERVER_START_REQ( redraw_window )
164 req->window = hwnd;
165 req->flags = flags;
166 wine_server_add_data( req, rects, count * sizeof(RECT) );
167 ret = !wine_server_call_err( req );
169 SERVER_END_REQ;
170 return ret;
174 /***********************************************************************
175 * send_ncpaint
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 );
183 HRGN client_rgn = 0;
185 if (child) hwnd = *child;
187 if (whole_rgn)
189 RECT client, update;
190 INT type;
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)
207 RECT window;
208 GetWindowRect( hwnd, &window );
209 if (EqualRect( &window, &update ))
211 DeleteObject( whole_rgn );
212 whole_rgn = (HRGN)1;
216 else
218 client_rgn = whole_rgn;
219 whole_rgn = 0;
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 );
228 return client_rgn;
232 /***********************************************************************
233 * send_erase
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;
243 HDC hdc = 0;
244 RECT dummy;
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 );
262 if (!hdc_ret)
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 );
273 return need_erase;
277 /***********************************************************************
278 * erase_now
280 * Implementation of RDW_ERASENOW behavior.
282 static void erase_now( HWND hwnd, UINT rdw_flags )
284 HWND child = 0;
285 HRGN hrgn;
287 /* loop while we find a child to repaint */
288 for (;;)
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 /***********************************************************************
305 * update_now
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
311 * from 16-bit SDK:
313 * This message avoids lots of inter-app message traffic
314 * by switching to the other task and continuing the
315 * recursion there.
317 * wParam = flags
318 * LOWORD(lParam) = hrgnClip
319 * HIWORD(lParam) = hwndSkip (not used; always NULL)
322 static void update_now( HWND hwnd, UINT rdw_flags )
324 HWND child = 0;
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 */
330 for (;;)
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 /*************************************************************************
347 * fix_caret
349 * Helper for ScrollWindowEx.
351 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
353 GUITHREADINFO info;
355 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
356 if (!info.hwndCaret) return 0;
357 if (info.hwndCaret == hWnd ||
358 ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret)))
360 POINT pt;
361 pt.x = info.rcCaret.left;
362 pt.y = info.rcCaret.top;
363 MapWindowPoints( info.hwndCaret, hWnd, (LPPOINT)&info.rcCaret, 2 );
364 if( IntersectRect(lprc, lprc, &info.rcCaret) )
366 HideCaret(0);
367 lprc->left = pt.x;
368 lprc->top = pt.y;
369 return info.hwndCaret;
372 return 0;
376 /***********************************************************************
377 * BeginPaint (USER32.@)
379 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
381 HWND full_handle;
382 HRGN hrgn;
383 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
385 if (!lps) return 0;
387 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
389 if (IsWindow(hwnd))
390 FIXME( "window %p belongs to other thread\n", hwnd );
391 return 0;
393 hwnd = full_handle;
395 HideCaret( hwnd );
397 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
399 lps->fErase = send_erase( hwnd, flags, hrgn, &lps->rcPaint, &lps->hdc );
401 TRACE("hdc = %p box = (%ld,%ld - %ld,%ld), fErase = %d\n",
402 lps->hdc, lps->rcPaint.left, lps->rcPaint.top, lps->rcPaint.right, lps->rcPaint.bottom,
403 lps->fErase);
405 return lps->hdc;
409 /***********************************************************************
410 * EndPaint (USER32.@)
412 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
414 if (!lps) return FALSE;
415 USER_Driver->pReleaseDC( hwnd, lps->hdc, TRUE );
416 ShowCaret( hwnd );
417 return TRUE;
421 /***********************************************************************
422 * GetDCEx (USER32.@)
424 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
426 if (!hwnd) hwnd = GetDesktopWindow();
427 else hwnd = WIN_GetFullHandle( hwnd );
429 return USER_Driver->pGetDCEx( hwnd, hrgnClip, flags );
433 /***********************************************************************
434 * GetDC (USER32.@)
436 * Get a device context.
438 * RETURNS
439 * Success: Handle to the device context
440 * Failure: NULL.
442 HDC WINAPI GetDC( HWND hwnd )
444 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
445 return GetDCEx( hwnd, 0, DCX_USESTYLE );
449 /***********************************************************************
450 * GetWindowDC (USER32.@)
452 HDC WINAPI GetWindowDC( HWND hwnd )
454 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
458 /***********************************************************************
459 * ReleaseDC (USER32.@)
461 * Release a device context.
463 * RETURNS
464 * Success: Non-zero. Resources used by hdc are released.
465 * Failure: 0.
467 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
469 return USER_Driver->pReleaseDC( hwnd, hdc, FALSE );
473 /**********************************************************************
474 * WindowFromDC (USER32.@)
476 HWND WINAPI WindowFromDC( HDC hDC )
478 return USER_Driver->pWindowFromDC( hDC );
482 /***********************************************************************
483 * LockWindowUpdate (USER32.@)
485 BOOL WINAPI LockWindowUpdate( HWND hwnd )
487 static HWND lockedWnd;
489 /* This function is fully implemented by the following patch:
491 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
493 * but in order to work properly, it needs the ability to invalidate
494 * DCEs in other processes when the lock window is changed, which
495 * isn't possible yet.
496 * -mike
499 FIXME("(%p), partial stub!\n",hwnd);
501 USER_Lock();
502 if (lockedWnd)
504 if (!hwnd)
506 /* Unlock lockedWnd */
507 /* FIXME: Do something */
509 else
511 /* Attempted to lock a second window */
512 /* Return FALSE and do nothing */
513 USER_Unlock();
514 return FALSE;
517 lockedWnd = hwnd;
518 USER_Unlock();
519 return TRUE;
523 /***********************************************************************
524 * RedrawWindow (USER32.@)
526 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
528 BOOL ret;
530 if (!hwnd) hwnd = GetDesktopWindow();
532 if (TRACE_ON(win))
534 if (hrgn)
536 RECT r;
537 GetRgnBox( hrgn, &r );
538 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
540 else if (rect)
541 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
542 else
543 TRACE( "%p whole window ", hwnd );
545 dump_rdw_flags(flags);
548 /* process pending expose events before painting */
549 if (flags & RDW_UPDATENOW) USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_PAINT, 0 );
551 if (rect && !hrgn)
553 ret = redraw_window_rects( hwnd, flags, rect, 1 );
555 else if (!hrgn)
557 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
559 else /* need to build a list of the region rectangles */
561 DWORD size;
562 RGNDATA *data = NULL;
563 static const RECT empty;
565 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
566 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
567 GetRegionData( hrgn, size, data );
568 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
569 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
570 else
571 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
572 HeapFree( GetProcessHeap(), 0, data );
575 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
576 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
578 return ret;
582 /***********************************************************************
583 * UpdateWindow (USER32.@)
585 BOOL WINAPI UpdateWindow( HWND hwnd )
587 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
591 /***********************************************************************
592 * InvalidateRgn (USER32.@)
594 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
596 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
600 /***********************************************************************
601 * InvalidateRect (USER32.@)
603 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
605 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
609 /***********************************************************************
610 * ValidateRgn (USER32.@)
612 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
614 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
618 /***********************************************************************
619 * ValidateRect (USER32.@)
621 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
623 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE );
627 /***********************************************************************
628 * GetUpdateRgn (USER32.@)
630 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
632 INT retval = ERROR;
633 UINT flags = UPDATE_NOCHILDREN;
634 HRGN update_rgn;
636 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
638 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
640 POINT offset;
642 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
643 send_erase( hwnd, flags, update_rgn, NULL, NULL );
644 /* map region to client coordinates */
645 offset.x = offset.y = 0;
646 ScreenToClient( hwnd, &offset );
647 OffsetRgn( hrgn, offset.x, offset.y );
649 return retval;
653 /***********************************************************************
654 * GetUpdateRect (USER32.@)
656 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
658 UINT flags = UPDATE_NOCHILDREN;
659 HRGN update_rgn;
661 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
663 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
665 if (rect)
667 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
669 HDC hdc = GetDCEx( hwnd, 0, DCX_USESTYLE );
670 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
671 DPtoLP( hdc, (LPPOINT)rect, 2 );
672 ReleaseDC( hwnd, hdc );
675 send_erase( hwnd, flags, update_rgn, NULL, NULL );
677 /* check if we still have an update region */
678 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
679 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
683 /***********************************************************************
684 * ExcludeUpdateRgn (USER32.@)
686 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
688 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
689 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
691 if (ret != ERROR)
693 POINT pt;
695 GetDCOrgEx( hdc, &pt );
696 MapWindowPoints( 0, hwnd, &pt, 1 );
697 OffsetRgn( update_rgn, -pt.x, -pt.y );
698 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
699 DeleteObject( update_rgn );
701 return ret;
705 /*************************************************************************
706 * ScrollWindowEx (USER32.@)
708 * Note: contrary to what the doc says, pixels that are scrolled from the
709 * outside of clipRect to the inside are NOT painted.
712 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
713 const RECT *rect, const RECT *clipRect,
714 HRGN hrgnUpdate, LPRECT rcUpdate,
715 UINT flags )
717 INT retVal = NULLREGION;
718 BOOL bOwnRgn = TRUE;
719 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
720 int rdw_flags;
721 HRGN hrgnTemp;
722 HRGN hrgnWinupd = 0;
723 HDC hDC;
724 RECT rc, cliprc;
725 RECT caretrc;
726 HWND hwndCaret = NULL;
728 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
729 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
730 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
731 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
732 FIXME("some flags (%04x) are unhandled\n", flags);
734 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
735 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
737 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
738 hwnd = WIN_GetFullHandle( hwnd );
740 GetClientRect(hwnd, &rc);
741 if (rect) IntersectRect(&rc, &rc, rect);
743 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
744 else cliprc = rc;
746 if( hrgnUpdate ) bOwnRgn = FALSE;
747 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
749 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
750 DWORD dcxflags = DCX_CACHE;
751 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
752 caretrc = rc;
753 hwndCaret = fix_caret(hwnd, &caretrc, flags);
755 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
756 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
757 dcxflags |= DCX_PARENTCLIP;
758 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
759 dcxflags |= DCX_CLIPCHILDREN;
760 hDC = GetDCEx( hwnd, 0, dcxflags);
761 if (hDC)
763 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
765 ReleaseDC( hwnd, hDC );
767 if (!bUpdate)
768 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
771 /* If the windows has an update region, this must be
772 * scrolled as well. Keep a copy in hrgnWinupd
773 * to be added to hrngUpdate at the end. */
774 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
775 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
776 if (retVal != NULLREGION)
778 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
779 if( !bOwnRgn) {
780 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
781 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
783 OffsetRgn( hrgnTemp, dx, dy );
784 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
785 if( !bOwnRgn)
786 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
787 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
788 DeleteObject( hrgnClip );
790 DeleteObject( hrgnTemp );
791 } else {
792 /* nothing was scrolled */
793 if( !bOwnRgn)
794 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
795 SetRectEmpty( rcUpdate);
798 if( flags & SW_SCROLLCHILDREN )
800 HWND *list = WIN_ListChildren( hwnd );
801 if (list)
803 int i;
804 RECT r, dummy;
805 for (i = 0; list[i]; i++)
807 GetWindowRect( list[i], &r );
808 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
809 if (!rect || IntersectRect(&dummy, &r, rect))
810 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
811 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
812 SWP_NOREDRAW | SWP_DEFERERASE );
814 HeapFree( GetProcessHeap(), 0, list );
818 if( flags & (SW_INVALIDATE | SW_ERASE) )
819 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
820 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
822 if( hrgnWinupd) {
823 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
824 DeleteObject( hrgnWinupd);
827 if( hwndCaret ) {
828 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
829 ShowCaret(hwndCaret);
832 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
834 return retVal;
838 /*************************************************************************
839 * ScrollWindow (USER32.@)
842 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
843 const RECT *rect, const RECT *clipRect )
845 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
846 (rect ? 0 : SW_SCROLLCHILDREN) |
847 SW_INVALIDATE | SW_ERASE ));
851 /*************************************************************************
852 * ScrollDC (USER32.@)
854 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
855 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
856 * logical coordinates.
858 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
859 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
862 return USER_Driver->pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );