Use proper return values in amstream stub functions.
[wine/hacks.git] / dlls / user / painting.c
blob927f886cebda8ec16be8e61a859f2435b664ea42
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. In all cases the region is deleted.
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 = 0;
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 if (!hdc) DeleteObject( client_rgn );
271 return need_erase;
275 /***********************************************************************
276 * erase_now
278 * Implementation of RDW_ERASENOW behavior.
280 static void erase_now( HWND hwnd, UINT rdw_flags )
282 HWND child;
283 HRGN hrgn;
285 /* loop while we find a child to repaint */
286 for (;;)
288 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE;
290 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
291 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
293 if (!(hrgn = send_ncpaint( hwnd, &child, &flags ))) break;
294 send_erase( child, flags, hrgn, NULL, NULL );
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 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
325 if (hwnd == GetDesktopWindow()) erase_now( hwnd, rdw_flags | RDW_NOCHILDREN );
327 /* loop while we find a child to repaint */
328 for (;;)
330 UINT flags = UPDATE_PAINT | UPDATE_INTERNALPAINT;
332 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
333 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
335 if (!get_update_flags( hwnd, &child, &flags )) break;
336 if (!flags) break; /* nothing more to do */
338 if (child == prev) /* same window again, didn't get repainted properly */
340 UINT erase_flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_NOCHILDREN;
341 HRGN hrgn;
343 TRACE( "%p not repainted properly, erasing\n", child );
344 if ((hrgn = send_ncpaint( child, NULL, &erase_flags )))
345 send_erase( child, erase_flags, hrgn, NULL, NULL );
347 prev = 0;
349 else
351 prev = child;
352 SendMessageW( child, WM_PAINT, 0, 0 );
354 if (rdw_flags & RDW_NOCHILDREN) break;
359 /*************************************************************************
360 * fix_caret
362 * Helper for ScrollWindowEx.
364 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
366 GUITHREADINFO info;
368 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
369 if (!info.hwndCaret) return 0;
370 if (info.hwndCaret == hWnd ||
371 ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret)))
373 POINT pt;
374 pt.x = info.rcCaret.left;
375 pt.y = info.rcCaret.top;
376 MapWindowPoints( info.hwndCaret, hWnd, (LPPOINT)&info.rcCaret, 2 );
377 if( IntersectRect(lprc, lprc, &info.rcCaret) )
379 HideCaret(0);
380 lprc->left = pt.x;
381 lprc->top = pt.y;
382 return info.hwndCaret;
385 return 0;
389 /***********************************************************************
390 * BeginPaint (USER32.@)
392 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
394 HWND full_handle;
395 HRGN hrgn;
396 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
398 if (!lps) return 0;
400 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
402 if (IsWindow(hwnd))
403 FIXME( "window %p belongs to other thread\n", hwnd );
404 return 0;
406 hwnd = full_handle;
408 HideCaret( hwnd );
410 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
412 lps->fErase = send_erase( hwnd, flags, hrgn, &lps->rcPaint, &lps->hdc );
414 TRACE("hdc = %p box = (%ld,%ld - %ld,%ld), fErase = %d\n",
415 lps->hdc, lps->rcPaint.left, lps->rcPaint.top, lps->rcPaint.right, lps->rcPaint.bottom,
416 lps->fErase);
418 return lps->hdc;
422 /***********************************************************************
423 * EndPaint (USER32.@)
425 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
427 if (!lps) return FALSE;
428 if (USER_Driver.pReleaseDC) USER_Driver.pReleaseDC( hwnd, lps->hdc, TRUE );
429 ShowCaret( hwnd );
430 return TRUE;
434 /***********************************************************************
435 * GetDCEx (USER32.@)
437 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
439 if (!hwnd) hwnd = GetDesktopWindow();
440 else hwnd = WIN_GetFullHandle( hwnd );
442 if (USER_Driver.pGetDCEx) return USER_Driver.pGetDCEx( hwnd, hrgnClip, flags );
443 return 0;
447 /***********************************************************************
448 * GetDC (USER32.@)
450 * Get a device context.
452 * RETURNS
453 * Success: Handle to the device context
454 * Failure: NULL.
456 HDC WINAPI GetDC( HWND hwnd )
458 if (!hwnd) return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
459 return GetDCEx( hwnd, 0, DCX_USESTYLE );
463 /***********************************************************************
464 * GetWindowDC (USER32.@)
466 HDC WINAPI GetWindowDC( HWND hwnd )
468 return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
472 /***********************************************************************
473 * ReleaseDC (USER32.@)
475 * Release a device context.
477 * RETURNS
478 * Success: Non-zero. Resources used by hdc are released.
479 * Failure: 0.
481 INT WINAPI ReleaseDC( HWND hwnd, HDC hdc )
483 if (USER_Driver.pReleaseDC) return USER_Driver.pReleaseDC( hwnd, hdc, FALSE );
484 return 0;
488 /**********************************************************************
489 * WindowFromDC (USER32.@)
491 HWND WINAPI WindowFromDC( HDC hDC )
493 if (USER_Driver.pWindowFromDC) return USER_Driver.pWindowFromDC( hDC );
494 return 0;
498 /***********************************************************************
499 * LockWindowUpdate (USER32.@)
501 BOOL WINAPI LockWindowUpdate( HWND hwnd )
503 static HWND lockedWnd;
505 /* This function is fully implemented by the following patch:
507 * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
509 * but in order to work properly, it needs the ability to invalidate
510 * DCEs in other processes when the lock window is changed, which
511 * isn't possible yet.
512 * -mike
515 FIXME("(%p), partial stub!\n",hwnd);
517 USER_Lock();
518 if (lockedWnd)
520 if (!hwnd)
522 /* Unlock lockedWnd */
523 /* FIXME: Do something */
525 else
527 /* Attempted to lock a second window */
528 /* Return FALSE and do nothing */
529 USER_Unlock();
530 return FALSE;
533 lockedWnd = hwnd;
534 USER_Unlock();
535 return TRUE;
539 /***********************************************************************
540 * RedrawWindow (USER32.@)
542 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
544 BOOL ret;
546 if (!hwnd) hwnd = GetDesktopWindow();
548 if (TRACE_ON(win))
550 if (hrgn)
552 RECT r;
553 GetRgnBox( hrgn, &r );
554 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
556 else if (rect)
557 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
558 else
559 TRACE( "%p whole window ", hwnd );
561 dump_rdw_flags(flags);
564 /* process pending expose events before painting */
565 if (flags & RDW_UPDATENOW) MsgWaitForMultipleObjects( 0, NULL, FALSE, 0, QS_PAINT );
567 if (rect && !hrgn)
569 ret = redraw_window_rects( hwnd, flags, rect, 1 );
571 else if (!hrgn)
573 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
575 else /* need to build a list of the region rectangles */
577 DWORD size;
578 RGNDATA *data = NULL;
579 static const RECT empty;
581 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
582 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
583 GetRegionData( hrgn, size, data );
584 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
585 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
586 else
587 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
588 HeapFree( GetProcessHeap(), 0, data );
591 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
592 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
594 return ret;
598 /***********************************************************************
599 * UpdateWindow (USER32.@)
601 BOOL WINAPI UpdateWindow( HWND hwnd )
603 return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
607 /***********************************************************************
608 * InvalidateRgn (USER32.@)
610 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
612 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
616 /***********************************************************************
617 * InvalidateRect (USER32.@)
619 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
621 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
625 /***********************************************************************
626 * ValidateRgn (USER32.@)
628 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
630 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
634 /***********************************************************************
635 * ValidateRect (USER32.@)
637 BOOL WINAPI ValidateRect( HWND hwnd, const RECT *rect )
639 return RedrawWindow( hwnd, rect, 0, RDW_VALIDATE );
643 /***********************************************************************
644 * GetUpdateRgn (USER32.@)
646 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
648 INT retval = ERROR;
649 UINT flags = UPDATE_NOCHILDREN;
650 HRGN update_rgn;
652 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
654 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
656 POINT offset;
658 retval = CombineRgn( hrgn, update_rgn, 0, RGN_COPY );
659 send_erase( hwnd, flags, update_rgn, NULL, NULL );
660 /* map region to client coordinates */
661 offset.x = offset.y = 0;
662 ScreenToClient( hwnd, &offset );
663 OffsetRgn( hrgn, offset.x, offset.y );
665 return retval;
669 /***********************************************************************
670 * GetUpdateRect (USER32.@)
672 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
674 UINT flags = UPDATE_NOCHILDREN;
675 HRGN update_rgn;
677 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
679 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
681 if (rect)
683 if (GetRgnBox( update_rgn, rect ) != NULLREGION)
685 HDC hdc = GetDCEx( hwnd, 0, DCX_USESTYLE );
686 MapWindowPoints( 0, hwnd, (LPPOINT)rect, 2 );
687 DPtoLP( hdc, (LPPOINT)rect, 2 );
688 ReleaseDC( hwnd, hdc );
691 send_erase( hwnd, flags, update_rgn, NULL, NULL );
693 /* check if we still have an update region */
694 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
695 return (get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT));
699 /***********************************************************************
700 * ExcludeUpdateRgn (USER32.@)
702 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
704 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
705 INT ret = GetUpdateRgn( hwnd, update_rgn, FALSE );
707 if (ret != ERROR)
709 POINT pt;
711 GetDCOrgEx( hdc, &pt );
712 MapWindowPoints( 0, hwnd, &pt, 1 );
713 OffsetRgn( update_rgn, -pt.x, -pt.y );
714 ret = ExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
715 DeleteObject( update_rgn );
717 return ret;
721 /*************************************************************************
722 * ScrollWindowEx (USER32.@)
724 * Note: contrary to what the doc says, pixels that are scrolled from the
725 * outside of clipRect to the inside are NOT painted.
728 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
729 const RECT *rect, const RECT *clipRect,
730 HRGN hrgnUpdate, LPRECT rcUpdate,
731 UINT flags )
733 INT retVal = NULLREGION;
734 BOOL bOwnRgn = TRUE;
735 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
736 int rdw_flags;
737 HRGN hrgnTemp;
738 HRGN hrgnWinupd = 0;
739 HDC hDC;
740 RECT rc, cliprc;
741 RECT caretrc;
742 HWND hwndCaret = NULL;
744 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
745 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
746 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
747 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
748 FIXME("some flags (%04x) are unhandled\n", flags);
750 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
751 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
753 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
754 hwnd = WIN_GetFullHandle( hwnd );
756 GetClientRect(hwnd, &rc);
757 if (rect) IntersectRect(&rc, &rc, rect);
759 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
760 else cliprc = rc;
762 if( hrgnUpdate ) bOwnRgn = FALSE;
763 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
765 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
766 DWORD dcxflags = DCX_CACHE;
767 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
768 caretrc = rc;
769 hwndCaret = fix_caret(hwnd, &caretrc, flags);
771 if( style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
772 if( GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
773 dcxflags |= DCX_PARENTCLIP;
774 if( !(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
775 dcxflags |= DCX_CLIPCHILDREN;
776 hDC = GetDCEx( hwnd, 0, dcxflags);
777 if (hDC)
779 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
781 ReleaseDC( hwnd, hDC );
783 if (!bUpdate)
784 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
787 /* If the windows has an update region, this must be
788 * scrolled as well. Keep a copy in hrgnWinupd
789 * to be added to hrngUpdate at the end. */
790 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
791 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
792 if (retVal != NULLREGION)
794 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
795 if( !bOwnRgn) {
796 hrgnWinupd = CreateRectRgn( 0, 0, 0, 0);
797 CombineRgn( hrgnWinupd, hrgnTemp, 0, RGN_COPY);
799 OffsetRgn( hrgnTemp, dx, dy );
800 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
801 if( !bOwnRgn)
802 CombineRgn( hrgnWinupd, hrgnWinupd, hrgnTemp, RGN_OR );
803 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
804 DeleteObject( hrgnClip );
806 DeleteObject( hrgnTemp );
807 } else {
808 /* nothing was scrolled */
809 if( !bOwnRgn)
810 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
811 SetRectEmpty( rcUpdate);
814 if( flags & SW_SCROLLCHILDREN )
816 HWND *list = WIN_ListChildren( hwnd );
817 if (list)
819 int i;
820 RECT r, dummy;
821 for (i = 0; list[i]; i++)
823 GetWindowRect( list[i], &r );
824 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
825 if (!rect || IntersectRect(&dummy, &r, rect))
826 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
827 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
828 SWP_NOREDRAW | SWP_DEFERERASE );
830 HeapFree( GetProcessHeap(), 0, list );
834 if( flags & (SW_INVALIDATE | SW_ERASE) )
835 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
836 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
838 if( hrgnWinupd) {
839 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnWinupd, RGN_OR);
840 DeleteObject( hrgnWinupd);
843 if( hwndCaret ) {
844 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
845 ShowCaret(hwndCaret);
848 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
850 return retVal;
854 /*************************************************************************
855 * ScrollWindow (USER32.@)
858 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
859 const RECT *rect, const RECT *clipRect )
861 return (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
862 (rect ? 0 : SW_SCROLLCHILDREN) |
863 SW_INVALIDATE | SW_ERASE ));
867 /*************************************************************************
868 * ScrollDC (USER32.@)
870 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
871 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
872 * logical coordinates.
874 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
875 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
878 if (USER_Driver.pScrollDC)
879 return USER_Driver.pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
880 return FALSE;