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
28 #include "wine/winuser16.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
36 /*************************************************************************
39 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
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)))
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) )
57 return info.hwndCaret;
63 /*************************************************************************
66 * Note: contrary to what the doc says, pixels that are scrolled from the
67 * outside of clipRect to the inside are NOT painted.
69 * Parameter are the same as in ScrollWindowEx, with the additional
70 * requirement that rect and clipRect are _valid_ pointers, to
71 * rectangles _within_ the client are. Moreover, there is something
74 static INT scroll_window( HWND hwnd, INT dx, INT dy, const RECT *rect,
75 const RECT *clipRect, HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
79 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
84 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
85 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
86 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
88 GetClientRect(hwnd, &rc);
89 if (rect) IntersectRect(&rc, &rc, rect);
91 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
94 if( hrgnUpdate ) bOwnRgn = FALSE;
95 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
97 hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
100 ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
102 ReleaseDC( hwnd, hDC );
105 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE );
108 /* Take into account the fact that some damage may have occurred during the scroll */
109 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
110 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
111 if (retVal != NULLREGION)
113 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
114 OffsetRgn( hrgnTemp, dx, dy );
115 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
116 RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
117 DeleteObject( hrgnClip );
119 DeleteObject( hrgnTemp );
121 if( flags & SW_SCROLLCHILDREN )
123 HWND *list = WIN_ListChildren( hwnd );
128 for (i = 0; list[i]; i++)
130 GetWindowRect( list[i], &r );
131 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
132 if (!rect || IntersectRect(&dummy, &r, &rc))
133 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
134 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
135 SWP_NOREDRAW | SWP_DEFERERASE );
137 HeapFree( GetProcessHeap(), 0, list );
141 if( flags & (SW_INVALIDATE | SW_ERASE) )
142 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
143 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
144 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
146 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
151 /*************************************************************************
152 * ScrollWindow (USER32.@)
155 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
156 const RECT *rect, const RECT *clipRect )
159 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
160 (rect ? 0 : SW_SCROLLCHILDREN) |
164 /*************************************************************************
165 * ScrollDC (USER32.@)
167 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is wrong)
168 * hrgnUpdate is returned in device coordinates with rcUpdate in logical coordinates.
170 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
171 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
174 RECT rSrc, rClipped_src, rClip, rDst, offset;
176 TRACE( "%p %d,%d hrgnUpdate=%p lprcUpdate = %p\n", hdc, dx, dy, hrgnUpdate, lprcUpdate );
177 if (lprcClip) TRACE( "lprcClip = %s\n", wine_dbgstr_rect(lprcClip));
178 if (lprcScroll) TRACE( "lprcScroll = %s\n", wine_dbgstr_rect(lprcScroll));
180 if (USER_Driver.pScrollDC)
181 return USER_Driver.pScrollDC( hdc, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate );
183 /* compute device clipping region (in device coordinates) */
184 if (lprcScroll) rSrc = *lprcScroll;
185 else GetClipBox( hdc, &rSrc );
186 LPtoDP(hdc, (LPPOINT)&rSrc, 2);
188 if (lprcClip) rClip = *lprcClip;
189 else GetClipBox( hdc, &rClip );
190 LPtoDP(hdc, (LPPOINT)&rClip, 2);
192 IntersectRect( &rClipped_src, &rSrc, &rClip );
193 TRACE("rSrc %s rClip %s clipped rSrc %s\n", wine_dbgstr_rect(&rSrc),
194 wine_dbgstr_rect(&rClip), wine_dbgstr_rect(&rClipped_src));
197 SetRect(&offset, 0, 0, dx, dy);
198 LPtoDP(hdc, (LPPOINT)&offset, 2);
199 OffsetRect( &rDst, offset.right - offset.left, offset.bottom - offset.top );
200 TRACE("rDst before clipping %s\n", wine_dbgstr_rect(&rDst));
201 IntersectRect( &rDst, &rDst, &rClip );
202 TRACE("rDst after clipping %s\n", wine_dbgstr_rect(&rDst));
204 if (!IsRectEmpty(&rDst))
207 RECT rDst_lp = rDst, rSrc_lp = rDst;
209 OffsetRect( &rSrc_lp, offset.left - offset.right, offset.top - offset.bottom );
210 DPtoLP(hdc, (LPPOINT)&rDst_lp, 2);
211 DPtoLP(hdc, (LPPOINT)&rSrc_lp, 2);
213 if (!BitBlt( hdc, rDst_lp.left, rDst_lp.top,
214 rDst_lp.right - rDst_lp.left, rDst_lp.bottom - rDst_lp.top,
215 hdc, rSrc_lp.left, rSrc_lp.top, SRCCOPY))
219 /* compute update areas. This is the clipped source or'ed with the unclipped source translated minus the
220 clipped src translated (rDst) all clipped to rClip */
222 if (hrgnUpdate || lprcUpdate)
224 HRGN hrgn = hrgnUpdate, hrgn2;
226 if (hrgn) SetRectRgn( hrgn, rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
227 else hrgn = CreateRectRgn( rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
229 hrgn2 = CreateRectRgnIndirect( &rSrc );
230 OffsetRgn(hrgn2, offset.right - offset.left, offset.bottom - offset.top );
231 CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
233 SetRectRgn( hrgn2, rDst.left, rDst.top, rDst.right, rDst.bottom );
234 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
236 SetRectRgn( hrgn2, rClip.left, rClip.top, rClip.right, rClip.bottom );
237 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
241 GetRgnBox( hrgn, lprcUpdate );
243 /* Put the lprcUpdate in logical coordinate */
244 DPtoLP( hdc, (LPPOINT)lprcUpdate, 2 );
245 TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate));
247 if (!hrgnUpdate) DeleteObject( hrgn );
248 DeleteObject( hrgn2 );
254 /*************************************************************************
255 * ScrollWindowEx (USER32.@)
257 * NOTE: Use this function instead of ScrollWindow32
259 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
260 const RECT *rect, const RECT *clipRect,
261 HRGN hrgnUpdate, LPRECT rcUpdate,
267 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
268 hwnd = WIN_GetFullHandle( hwnd );
270 GetClientRect(hwnd, &rc);
271 if (rect) IntersectRect(&rc, &rc, rect);
273 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
276 if (!IsRectEmpty(&cliprc) && (dx || dy))
279 HWND hwndCaret = fix_caret(hwnd, &caretrc, flags);
281 result = scroll_window( hwnd, dx, dy, rect, clipRect,
282 hrgnUpdate, rcUpdate, flags );
286 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
287 ShowCaret(hwndCaret);