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
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
39 /*************************************************************************
42 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
43 const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
46 RECT rSrc, rClipped_src, rClip, rDst, offset;
47 INT code = X11DRV_START_EXPOSURES;
49 if (hrgnUpdate || lprcUpdate)
50 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
52 /* compute device clipping region (in device coordinates) */
54 if (lprcScroll) rSrc = *lprcScroll;
55 else GetClipBox( hdc, &rSrc );
56 LPtoDP(hdc, (LPPOINT)&rSrc, 2);
58 if (lprcClip) rClip = *lprcClip;
59 else GetClipBox( hdc, &rClip );
60 LPtoDP(hdc, (LPPOINT)&rClip, 2);
62 IntersectRect( &rClipped_src, &rSrc, &rClip );
63 TRACE("rSrc %s rClip %s clipped rSrc %s\n", wine_dbgstr_rect(&rSrc),
64 wine_dbgstr_rect(&rClip), wine_dbgstr_rect(&rClipped_src));
67 SetRect(&offset, 0, 0, dx, dy);
68 LPtoDP(hdc, (LPPOINT)&offset, 2);
69 OffsetRect( &rDst, offset.right - offset.left, offset.bottom - offset.top );
70 TRACE("rDst before clipping %s\n", wine_dbgstr_rect(&rDst));
71 IntersectRect( &rDst, &rDst, &rClip );
72 TRACE("rDst after clipping %s\n", wine_dbgstr_rect(&rDst));
74 if (!IsRectEmpty(&rDst))
77 RECT rDst_lp = rDst, rSrc_lp = rDst;
79 OffsetRect( &rSrc_lp, offset.left - offset.right, offset.top - offset.bottom );
80 DPtoLP(hdc, (LPPOINT)&rDst_lp, 2);
81 DPtoLP(hdc, (LPPOINT)&rSrc_lp, 2);
83 if (!BitBlt( hdc, rDst_lp.left, rDst_lp.top,
84 rDst_lp.right - rDst_lp.left, rDst_lp.bottom - rDst_lp.top,
85 hdc, rSrc_lp.left, rSrc_lp.top, SRCCOPY))
89 /* compute update areas. This is the clipped source or'ed with the unclipped source translated minus the
90 clipped src translated (rDst) all clipped to rClip */
92 if (hrgnUpdate || lprcUpdate)
94 HRGN hrgn = hrgnUpdate, hrgn2, hrgn3 = 0;
96 code = X11DRV_END_EXPOSURES;
97 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(hrgn3), (LPSTR)&hrgn3 );
99 if (hrgn) SetRectRgn( hrgn, rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
100 else hrgn = CreateRectRgn( rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
102 hrgn2 = CreateRectRgnIndirect( &rSrc );
103 OffsetRgn(hrgn2, offset.right - offset.left, offset.bottom - offset.top );
104 CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
106 SetRectRgn( hrgn2, rDst.left, rDst.top, rDst.right, rDst.bottom );
107 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
109 SetRectRgn( hrgn2, rClip.left, rClip.top, rClip.right, rClip.bottom );
110 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
114 CombineRgn( hrgn, hrgn, hrgn3, RGN_OR );
115 DeleteObject( hrgn3 );
120 GetRgnBox( hrgn, lprcUpdate );
122 /* Put the lprcUpdate in logical coordinate */
123 DPtoLP( hdc, (LPPOINT)lprcUpdate, 2 );
124 TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate));
126 if (!hrgnUpdate) DeleteObject( hrgn );
127 DeleteObject( hrgn2 );