ScrollDC and X11DRV_SCROLLDC should scroll only pixels coming from
[wine/multimedia.git] / windows / scroll.c
blob24fa769fc59d99c3aced1c761b793bdeada76ceb
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
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 <stdarg.h>
23 #include <stdlib.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "wine/winuser16.h"
29 #include "winuser.h"
30 #include "user_private.h"
31 #include "win.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
36 /*************************************************************************
37 * fix_caret
39 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
41 GUITHREADINFO info;
43 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
44 if (!info.hwndCaret) return 0;
45 if (info.hwndCaret == hWnd ||
46 ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret)))
48 POINT pt;
49 pt.x = info.rcCaret.left;
50 pt.y = info.rcCaret.top;
51 MapWindowPoints( info.hwndCaret, hWnd, (LPPOINT)&info.rcCaret, 2 );
52 if( IntersectRect(lprc, lprc, &info.rcCaret) )
54 HideCaret(0);
55 lprc->left = pt.x;
56 lprc->top = pt.y;
57 return info.hwndCaret;
60 return 0;
63 /*************************************************************************
64 * ScrollWindowEx (USER32.@)
66 * Note: contrary to what the doc says, pixels that are scrolled from the
67 * outside of clipRect to the inside are NOT painted.
70 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
71 const RECT *rect, const RECT *clipRect,
72 HRGN hrgnUpdate, LPRECT rcUpdate,
73 UINT flags )
75 INT retVal = NULLREGION;
76 BOOL bOwnRgn = TRUE;
77 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
78 int rdw_flags;
79 HRGN hrgnTemp;
80 HDC hDC;
81 RECT rc, cliprc;
82 RECT caretrc;
83 HWND hwndCaret = NULL;
85 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
86 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
87 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
88 if( flags & ~( SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE))
89 FIXME("some flags (%04x) are unhandled\n", flags);
91 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
92 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE ;
94 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
95 hwnd = WIN_GetFullHandle( hwnd );
97 GetClientRect(hwnd, &rc);
98 if (rect) IntersectRect(&rc, &rc, rect);
100 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
101 else cliprc = rc;
103 if( hrgnUpdate ) bOwnRgn = FALSE;
104 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
106 if( !IsRectEmpty(&cliprc) && (dx || dy)) {
107 caretrc = rc;
108 hwndCaret = fix_caret(hwnd, &caretrc, flags);
110 hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
111 if (hDC)
113 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
115 ReleaseDC( hwnd, hDC );
117 if (!bUpdate)
118 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags);
121 /* Take into account the fact that some damage may have occurred during
122 * the scroll */
123 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
124 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
125 if (retVal != NULLREGION)
127 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
128 OffsetRgn( hrgnTemp, dx, dy );
129 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
130 RedrawWindow( hwnd, NULL, hrgnTemp, rdw_flags);
131 DeleteObject( hrgnClip );
133 DeleteObject( hrgnTemp );
134 } else {
135 /* nothing was scrolled */
136 if( !bOwnRgn)
137 SetRectRgn( hrgnUpdate, 0, 0, 0, 0 );
138 SetRectEmpty( rcUpdate);
141 if( flags & SW_SCROLLCHILDREN )
143 HWND *list = WIN_ListChildren( hwnd );
144 if (list)
146 int i;
147 RECT r, dummy;
148 for (i = 0; list[i]; i++)
150 GetWindowRect( list[i], &r );
151 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
152 if (!rect || IntersectRect(&dummy, &r, rect))
153 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
154 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
155 SWP_NOREDRAW | SWP_DEFERERASE );
157 HeapFree( GetProcessHeap(), 0, list );
161 if( flags & (SW_INVALIDATE | SW_ERASE) )
162 RedrawWindow( hwnd, NULL, hrgnUpdate, rdw_flags |
163 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
165 if( hwndCaret ) {
166 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
167 ShowCaret(hwndCaret);
170 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
172 return retVal;
175 /*************************************************************************
176 * ScrollWindow (USER32.@)
179 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
180 const RECT *rect, const RECT *clipRect )
182 return
183 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
184 (rect ? 0 : SW_SCROLLCHILDREN) |
185 SW_INVALIDATE ));
188 /*************************************************************************
189 * ScrollDC (USER32.@)
191 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
192 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
193 * logical coordinates.
195 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
196 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
199 if (USER_Driver.pScrollDC)
200 return USER_Driver.pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
201 return FALSE;