Add support for impersonating a token.
[wine/multimedia.git] / dlls / user / painting.c
blob0169ada50e0cab29d09f0d59f6d06120dcea1dc3
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 ReleaseDC( hwnd, hdc );
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 if (USER_Driver.pReleaseDC) 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 if (USER_Driver.pGetDCEx) return USER_Driver.pGetDCEx( hwnd, hrgnClip, flags );
430 return 0;
434 /***********************************************************************
435 * GetDC (USER32.@)
437 * Get a device context.
439 * RETURNS
440 * Success: Handle to the device context
441 * Failure: NULL.
443 HDC WINAPI GetDC( HWND hwnd )
445 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
446 return GetDCEx( hwnd, 0, DCX_USESTYLE );
450 /***********************************************************************
451 * GetWindowDC (USER32.@)
453 HDC WINAPI GetWindowDC( HWND hwnd )
455 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
459 /***********************************************************************
460 * ReleaseDC (USER32.@)
462 * Release a device context.
464 * RETURNS
465 * Success: Non-zero. Resources used by hdc are released.
466 * Failure: 0.
468 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
470 if (USER_Driver.pReleaseDC) return USER_Driver.pReleaseDC( hwnd, hdc, FALSE );
471 return 0;
475 /**********************************************************************
476 * WindowFromDC (USER32.@)
478 HWND WINAPI WindowFromDC( HDC hDC )
480 if (USER_Driver.pWindowFromDC) return USER_Driver.pWindowFromDC( hDC );
481 return 0;
485 /***********************************************************************
486 * LockWindowUpdate (USER32.@)
488 BOOL WINAPI LockWindowUpdate( HWND hwnd )
490 static HWND lockedWnd;
492 /* This function is fully implemented by the following patch:
494 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
496 * but in order to work properly, it needs the ability to invalidate
497 * DCEs in other processes when the lock window is changed, which
498 * isn't possible yet.
499 * -mike
502 FIXME("(%p), partial stub!\n",hwnd);
504 USER_Lock();
505 if (lockedWnd)
507 if (!hwnd)
509 /* Unlock lockedWnd */
510 /* FIXME: Do something */
512 else
514 /* Attempted to lock a second window */
515 /* Return FALSE and do nothing */
516 USER_Unlock();
517 return FALSE;
520 lockedWnd = hwnd;
521 USER_Unlock();
522 return TRUE;
526 /***********************************************************************
527 * RedrawWindow (USER32.@)
529 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
531 BOOL ret;
533 if (!hwnd) hwnd = GetDesktopWindow();
535 if (TRACE_ON(win))
537 if (hrgn)
539 RECT r;
540 GetRgnBox( hrgn, &r );
541 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
543 else if (rect)
544 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
545 else
546 TRACE( "%p whole window ", hwnd );
548 dump_rdw_flags(flags);
551 /* process pending expose events before painting */
552 if (flags & RDW_UPDATENOW) MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_PAINT );
554 if (rect && !hrgn)
556 ret = redraw_window_rects( hwnd, flags, rect, 1 );
558 else if (!hrgn)
560 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
562 else /* need to build a list of the region rectangles */
564 DWORD size;
565 RGNDATA *data = NULL;
566 static const RECT empty;
568 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
569 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
570 GetRegionData( hrgn, size, data );
571 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
572 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
573 else
574 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
575 HeapFree( GetProcessHeap(), 0, data );
578 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
579 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
581 return ret;
585 /***********************************************************************
586 * UpdateWindow (USER32.@)
588 BOOL WINAPI UpdateWindow( HWND hwnd )
590 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
594 /***********************************************************************
595 * InvalidateRgn (USER32.@)
597 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
599 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
603 /***********************************************************************
604 * InvalidateRect (USER32.@)
606 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
608 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
612 /***********************************************************************
613 * ValidateRgn (USER32.@)
615 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
617 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
621 /***********************************************************************
622 * ValidateRect (USER32.@)
624 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
626 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE );
630 /***********************************************************************
631 * GetUpdateRgn (USER32.@)
633 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
635 INT retval = ERROR;
636 UINT flags = UPDATE_NOCHILDREN;
637 HRGN update_rgn;
639 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
641 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
643 POINT offset;
645 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
646 send_erase( hwnd, flags, update_rgn, NULL, NULL );
647 /* map region to client coordinates */
648 offset.x = offset.y = 0;
649 ScreenToClient( hwnd, &offset );
650 OffsetRgn( hrgn, offset.x, offset.y );
652 return retval;
656 /***********************************************************************
657 * GetUpdateRect (USER32.@)
659 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
661 UINT flags = UPDATE_NOCHILDREN;
662 HRGN update_rgn;
664 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
666 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
668 if (rect)
670 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
672 HDC hdc = GetDCEx( hwnd, 0, DCX_USESTYLE );
673 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
674 DPtoLP( hdc, (LPPOINT)rect, 2 );
675 ReleaseDC( hwnd, hdc );
678 send_erase( hwnd, flags, update_rgn, NULL, NULL );
680 /* check if we still have an update region */
681 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
682 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
686 /***********************************************************************
687 * ExcludeUpdateRgn (USER32.@)
689 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
691 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
692 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
694 if (ret != ERROR)
696 POINT pt;
698 GetDCOrgEx( hdc, &pt );
699 MapWindowPoints( 0, hwnd, &pt, 1 );
700 OffsetRgn( update_rgn, -pt.x, -pt.y );
701 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
702 DeleteObject( update_rgn );
704 return ret;
708 /*************************************************************************
709 * ScrollWindowEx (USER32.@)
711 * Note: contrary to what the doc says, pixels that are scrolled from the
712 * outside of clipRect to the inside are NOT painted.
715 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
716 const RECT *rect, const RECT *clipRect,
717 HRGN hrgnUpdate, LPRECT rcUpdate,
718 UINT flags )
720 INT retVal = NULLREGION;
721 BOOL bOwnRgn = TRUE;
722 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
723 int rdw_flags;
724 HRGN hrgnTemp;
725 HRGN hrgnWinupd = 0;
726 HDC hDC;
727 RECT rc, cliprc;
728 RECT caretrc;
729 HWND hwndCaret = NULL;
731 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
732 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
733 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
734 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
735 FIXME("some flags (%04x) are unhandled\n", flags);
737 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
738 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
740 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
741 hwnd = WIN_GetFullHandle( hwnd );
743 GetClientRect(hwnd, &rc);
744 if (rect) IntersectRect(&rc, &rc, rect);
746 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
747 else cliprc = rc;
749 if( hrgnUpdate ) bOwnRgn = FALSE;
750 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
752 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
753 DWORD dcxflags = DCX_CACHE;
754 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
755 caretrc = rc;
756 hwndCaret = fix_caret(hwnd, &caretrc, flags);
758 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
759 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
760 dcxflags |= DCX_PARENTCLIP;
761 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
762 dcxflags |= DCX_CLIPCHILDREN;
763 hDC = GetDCEx( hwnd, 0, dcxflags);
764 if (hDC)
766 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
768 ReleaseDC( hwnd, hDC );
770 if (!bUpdate)
771 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
774 /* If the windows has an update region, this must be
775 * scrolled as well. Keep a copy in hrgnWinupd
776 * to be added to hrngUpdate at the end. */
777 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
778 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
779 if (retVal != NULLREGION)
781 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
782 if( !bOwnRgn) {
783 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
784 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
786 OffsetRgn( hrgnTemp, dx, dy );
787 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
788 if( !bOwnRgn)
789 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
790 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
791 DeleteObject( hrgnClip );
793 DeleteObject( hrgnTemp );
794 } else {
795 /* nothing was scrolled */
796 if( !bOwnRgn)
797 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
798 SetRectEmpty( rcUpdate);
801 if( flags & SW_SCROLLCHILDREN )
803 HWND *list = WIN_ListChildren( hwnd );
804 if (list)
806 int i;
807 RECT r, dummy;
808 for (i = 0; list[i]; i++)
810 GetWindowRect( list[i], &r );
811 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
812 if (!rect || IntersectRect(&dummy, &r, rect))
813 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
814 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
815 SWP_NOREDRAW | SWP_DEFERERASE );
817 HeapFree( GetProcessHeap(), 0, list );
821 if( flags & (SW_INVALIDATE | SW_ERASE) )
822 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
823 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
825 if( hrgnWinupd) {
826 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
827 DeleteObject( hrgnWinupd);
830 if( hwndCaret ) {
831 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
832 ShowCaret(hwndCaret);
835 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
837 return retVal;
841 /*************************************************************************
842 * ScrollWindow (USER32.@)
845 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
846 const RECT *rect, const RECT *clipRect )
848 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
849 (rect ? 0 : SW_SCROLLCHILDREN) |
850 SW_INVALIDATE | SW_ERASE ));
854 /*************************************************************************
855 * ScrollDC (USER32.@)
857 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
858 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
859 * logical coordinates.
861 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
862 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
865 if (USER_Driver.pScrollDC)
866 return USER_Driver.pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
867 return FALSE;