Spelling fixes (s/occured/occurred/ and variants).
[wine/dcerpc.git] / dlls / x11drv / scroll.c
blob3319567caf05bd13f5d3bed133a018a480451b01
1 /*
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
23 #include "config.h"
25 #include "ts_xlib.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
31 #include "x11drv.h"
32 #include "win.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
38 /*************************************************************************
39 * ScrollDC (X11DRV.@)
41 * Only the hrgnUpdate is returned in device coordinates.
42 * rcUpdate must be returned in logical coordinates to comply with win API.
43 * FIXME: the doc explicitly states the opposite, to be checked
45 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
46 const RECT *clipRect, HRGN hrgnUpdate, LPRECT rcUpdate )
48 RECT rect, rClip, rDst;
50 TRACE( "%p %d,%d hrgnUpdate=%p rcUpdate = %p\n", hdc, dx, dy, hrgnUpdate, rcUpdate );
51 if (clipRect) TRACE( "cliprc = (%ld,%ld,%ld,%ld)\n",
52 clipRect->left, clipRect->top, clipRect->right, clipRect->bottom );
53 if (rc) TRACE( "rc = (%ld,%ld,%ld,%ld)\n", rc->left, rc->top, rc->right, rc->bottom );
55 /* compute device clipping region (in device coordinates) */
57 if (rc) rect = *rc;
58 else GetClipBox( hdc, &rect );
60 if (clipRect)
62 rClip = *clipRect;
63 IntersectRect( &rClip, &rect, &rClip );
65 else rClip = rect;
67 rDst = rClip;
68 OffsetRect( &rDst, dx, dy );
69 IntersectRect( &rDst, &rDst, &rClip );
71 if (!IsRectEmpty(&rDst))
73 /* copy bits */
74 if (!BitBlt( hdc, rDst.left, rDst.top,
75 rDst.right - rDst.left, rDst.bottom - rDst.top,
76 hdc, rDst.left - dx, rDst.top - dy, SRCCOPY))
77 return FALSE;
80 /* compute update areas */
82 if (hrgnUpdate || rcUpdate)
84 HRGN hrgn = hrgnUpdate, hrgn2;
86 /* map everything to device coordinates */
87 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
88 LPtoDP( hdc, (LPPOINT)&rDst, 2 );
90 hrgn2 = CreateRectRgnIndirect( &rDst );
91 if (hrgn) SetRectRgn( hrgn, rClip.left, rClip.top, rClip.right, rClip.bottom );
92 else hrgn = CreateRectRgn( rClip.left, rClip.top, rClip.right, rClip.bottom );
93 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
95 if( rcUpdate )
97 GetRgnBox( hrgn, rcUpdate );
99 /* Put the rcUpdate in logical coordinate */
100 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
102 if (!hrgnUpdate) DeleteObject( hrgn );
103 DeleteObject( hrgn2 );
105 return TRUE;
109 /*************************************************************************
110 * ScrollWindowEx (X11DRV.@)
112 * Note: contrary to what the doc says, pixels that are scrolled from the
113 * outside of clipRect to the inside are NOT painted.
115 * Parameter are the same as in ScrollWindowEx, with the additional
116 * requirement that rect and clipRect are _valid_ pointers, to
117 * rectangles _within_ the client are. Moreover, there is something
118 * to scroll.
120 INT X11DRV_ScrollWindowEx( HWND hwnd, INT dx, INT dy,
121 const RECT *rect, const RECT *clipRect,
122 HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
124 INT retVal;
125 BOOL bOwnRgn = TRUE;
126 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
127 HRGN hrgnTemp;
128 HDC hDC;
129 RECT rc, cliprc;
131 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
132 hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
133 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
135 GetClientRect(hwnd, &rc);
136 if (rect) IntersectRect(&rc, &rc, rect);
138 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
139 else cliprc = rc;
141 if( hrgnUpdate ) bOwnRgn = FALSE;
142 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
144 hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
145 if (hDC)
147 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
148 X11DRV_StartGraphicsExposures( hDC );
149 X11DRV_ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
150 X11DRV_EndGraphicsExposures( hDC, hrgn );
151 ReleaseDC( hwnd, hDC );
152 if (bUpdate) CombineRgn( hrgnUpdate, hrgnUpdate, hrgn, RGN_OR );
153 else RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
154 DeleteObject( hrgn );
157 /* Take into account the fact that some damage may have occurred during the scroll */
158 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
159 retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
160 if (retVal != NULLREGION)
162 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
163 OffsetRgn( hrgnTemp, dx, dy );
164 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
165 RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
166 DeleteObject( hrgnClip );
168 DeleteObject( hrgnTemp );
170 if( flags & SW_SCROLLCHILDREN )
172 HWND *list = WIN_ListChildren( hwnd );
173 if (list)
175 int i;
176 RECT r, dummy;
177 for (i = 0; list[i]; i++)
179 GetWindowRect( list[i], &r );
180 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
181 if (!rect || IntersectRect(&dummy, &r, &rc))
182 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
183 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
184 SWP_NOREDRAW | SWP_DEFERERASE );
186 HeapFree( GetProcessHeap(), 0, list );
190 if( flags & (SW_INVALIDATE | SW_ERASE) )
191 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
192 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
193 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
195 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
197 return retVal;