2 * Scroll windows and DCs
4 * Copyright 1993 David W. Metcalfe
5 * Copyright 1995, 1996 Alex Korobka
6 * Copyright 2001 Alexandre Julliard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
41 /*************************************************************************
44 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is wrong)
45 * hrgnUpdate is returned in device coordinates with rcUpdate in logical coordinates.
48 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
49 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
51 RECT rSrc, rClipped_src, rClip, rDst, offset;
53 TRACE( "%p %d,%d hrgnUpdate=%p lprcUpdate = %p\n", hdc, dx, dy, hrgnUpdate, lprcUpdate );
54 if (lprcClip) TRACE( "lprcClip = %s\n", wine_dbgstr_rect(lprcClip));
55 if (lprcScroll) TRACE( "lprcScroll = %s\n", wine_dbgstr_rect(lprcScroll));
57 /* compute device clipping region (in device coordinates) */
59 if (lprcScroll) rSrc = *lprcScroll;
60 else GetClipBox( hdc, &rSrc );
61 LPtoDP(hdc, (LPPOINT)&rSrc, 2);
63 if (lprcClip) rClip = *lprcClip;
64 else GetClipBox( hdc, &rClip );
65 LPtoDP(hdc, (LPPOINT)&rClip, 2);
67 IntersectRect( &rClipped_src, &rSrc, &rClip );
68 TRACE("rSrc %s rClip %s clipped rSrc %s\n", wine_dbgstr_rect(&rSrc),
69 wine_dbgstr_rect(&rClip), wine_dbgstr_rect(&rClipped_src));
72 SetRect(&offset, 0, 0, dx, dy);
73 LPtoDP(hdc, (LPPOINT)&offset, 2);
74 OffsetRect( &rDst, offset.right - offset.left, offset.bottom - offset.top );
75 TRACE("rDst before clipping %s\n", wine_dbgstr_rect(&rDst));
76 IntersectRect( &rDst, &rDst, &rClip );
77 TRACE("rDst after clipping %s\n", wine_dbgstr_rect(&rDst));
79 if (!IsRectEmpty(&rDst))
82 RECT rDst_lp = rDst, rSrc_lp = rDst;
84 OffsetRect( &rSrc_lp, offset.left - offset.right, offset.top - offset.bottom );
85 DPtoLP(hdc, (LPPOINT)&rDst_lp, 2);
86 DPtoLP(hdc, (LPPOINT)&rSrc_lp, 2);
88 if (!BitBlt( hdc, rDst_lp.left, rDst_lp.top,
89 rDst_lp.right - rDst_lp.left, rDst_lp.bottom - rDst_lp.top,
90 hdc, rSrc_lp.left, rSrc_lp.top, SRCCOPY))
94 /* compute update areas. This is the clipped source or'ed with the unclipped source translated minus the
95 clipped src translated (rDst) all clipped to rClip */
97 if (hrgnUpdate || lprcUpdate)
99 HRGN hrgn = hrgnUpdate, hrgn2;
101 if (hrgn) SetRectRgn( hrgn, rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
102 else hrgn = CreateRectRgn( rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
104 hrgn2 = CreateRectRgnIndirect( &rSrc );
105 OffsetRgn(hrgn2, offset.right - offset.left, offset.bottom - offset.top );
106 CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
108 SetRectRgn( hrgn2, rDst.left, rDst.top, rDst.right, rDst.bottom );
109 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
111 SetRectRgn( hrgn2, rClip.left, rClip.top, rClip.right, rClip.bottom );
112 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
116 GetRgnBox( hrgn, lprcUpdate );
118 /* Put the lprcUpdate in logical coordinate */
119 DPtoLP( hdc, (LPPOINT)lprcUpdate, 2 );
120 TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate));
122 if (!hrgnUpdate) DeleteObject( hrgn );
123 DeleteObject( hrgn2 );
129 /*************************************************************************
130 * ScrollWindowEx (X11DRV.@)
132 * Note: contrary to what the doc says, pixels that are scrolled from the
133 * outside of clipRect to the inside are NOT painted.
135 * Parameter are the same as in ScrollWindowEx, with the additional
136 * requirement that rect and clipRect are _valid_ pointers, to
137 * rectangles _within_ the client are. Moreover, there is something
140 INT X11DRV_ScrollWindowEx( HWND hwnd, INT dx, INT dy,
141 const RECT *rect, const RECT *clipRect,
142 HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
146 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
151 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
152 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
153 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
155 GetClientRect(hwnd, &rc);
156 if (rect) IntersectRect(&rc, &rc, rect);
158 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
161 if( hrgnUpdate ) bOwnRgn = FALSE;
162 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
164 hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
167 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
168 X11DRV_StartGraphicsExposures( hDC );
169 X11DRV_ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
170 X11DRV_EndGraphicsExposures( hDC, hrgn );
171 ReleaseDC( hwnd, hDC );
172 if (bUpdate) CombineRgn( hrgnUpdate, hrgnUpdate, hrgn, RGN_OR );
173 else RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
174 DeleteObject( hrgn );
177 /* Take into account the fact that some damage may have occurred during the scroll */
178 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
179 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
180 if (retVal != NULLREGION)
182 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
183 OffsetRgn( hrgnTemp, dx, dy );
184 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
185 RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
186 DeleteObject( hrgnClip );
188 DeleteObject( hrgnTemp );
190 if( flags & SW_SCROLLCHILDREN )
192 HWND *list = WIN_ListChildren( hwnd );
197 for (i = 0; list[i]; i++)
199 GetWindowRect( list[i], &r );
200 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
201 if (!rect || IntersectRect(&dummy, &r, &rc))
202 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
203 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
204 SWP_NOREDRAW | SWP_DEFERERASE );
206 HeapFree( GetProcessHeap(), 0, list );
210 if( flags & (SW_INVALIDATE | SW_ERASE) )
211 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
212 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
213 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
215 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );