2 * Scroll windows and DCs
4 * Copyright 1993 David W. Metcalfe
5 * Copyright 1995, 1996 Alex Korobka
6 * Copyright 2001 Alexandre Julliard
20 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(x11drv);
25 /*************************************************************************
28 static BOOL fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
30 HWND hCaret = CARET_GetHwnd();
37 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
42 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
43 if( IntersectRect(lprc, lprc, &rc) )
56 /*************************************************************************
59 * Only the hrgnUpdate is returned in device coordinates.
60 * rcUpdate must be returned in logical coordinates to comply with win API.
61 * FIXME: the doc explicitly states the opposite, to be checked
63 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
64 const RECT *clipRect, HRGN hrgnUpdate, LPRECT rcUpdate )
66 RECT rect, rClip, rSrc;
68 TRACE( "%04x %d,%d hrgnUpdate=%04x rcUpdate = %p\n", hdc, dx, dy, hrgnUpdate, rcUpdate );
69 if (clipRect) TRACE( "cliprc = (%d,%d,%d,%d)\n",
70 clipRect->left, clipRect->top, clipRect->right, clipRect->bottom );
71 if (rc) TRACE( "rc = (%d,%d,%d,%d)\n", rc->left, rc->top, rc->right, rc->bottom );
73 /* compute device clipping region (in device coordinates) */
76 else GetClipBox( hdc, &rect );
81 IntersectRect( &rClip, &rect, &rClip );
86 OffsetRect( &rSrc, -dx, -dy );
87 IntersectRect( &rSrc, &rSrc, &rect );
89 if (!IsRectEmpty(&rSrc))
92 if (!BitBlt( hdc, rSrc.left + dx, rSrc.top + dy,
93 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
94 hdc, rSrc.left, rSrc.top, SRCCOPY))
98 /* compute update areas */
100 if (hrgnUpdate || rcUpdate)
102 HRGN hrgn = hrgnUpdate, hrgn2;
105 /* map everything to device coordinates */
106 pt.x = rect.left + dx;
107 pt.y = rect.top + dy;
108 LPtoDP( hdc, &pt, 1 );
109 LPtoDP( hdc, (LPPOINT)&rect, 2 );
110 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
111 dx = pt.x - rect.left;
112 dy = pt.y - rect.top;
114 hrgn2 = CreateRectRgnIndirect( &rect );
115 if (hrgn) SetRectRgn( hrgn, rClip.left, rClip.top, rClip.right, rClip.bottom );
116 else hrgn = CreateRectRgn( rClip.left, rClip.top, rClip.right, rClip.bottom );
117 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
118 OffsetRgn( hrgn2, dx, dy );
119 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
123 GetRgnBox( hrgn, rcUpdate );
125 /* Put the rcUpdate in logical coordinate */
126 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
128 if (!hrgnUpdate) DeleteObject( hrgn );
129 DeleteObject( hrgn2 );
135 /*************************************************************************
136 * ScrollWindowEx (X11DRV.@)
138 INT X11DRV_ScrollWindowEx( HWND hwnd, INT dx, INT dy,
139 const RECT *rect, const RECT *clipRect,
140 HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
142 INT retVal = NULLREGION;
143 BOOL bCaret = FALSE, bOwnRgn = TRUE;
146 if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
147 hwnd = WIN_GetFullHandle( hwnd );
149 GetClientRect(hwnd, &rc);
150 if (rect) IntersectRect(&rc, &rc, rect);
152 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
155 if (!IsRectEmpty(&cliprc) && (dx || dy))
158 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
159 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
163 TRACE( "%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p rc=(%d,%d-%d,%d) %04x\n",
164 hwnd, dx, dy, hrgnUpdate, rcUpdate,
165 rc.left, rc.top, rc.right, rc.bottom, flags );
166 if (clipRect) TRACE( "cliprc = (%d,%d,%d,%d)\n",
167 clipRect->left, clipRect->top,
168 clipRect->right, clipRect->bottom );
171 bCaret = fix_caret(hwnd, &caretrc, flags);
173 if( hrgnUpdate ) bOwnRgn = FALSE;
174 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
176 hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
179 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
180 X11DRV_StartGraphicsExposures( hDC );
181 X11DRV_ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
182 X11DRV_EndGraphicsExposures( hDC, hrgn );
183 ReleaseDC( hwnd, hDC );
184 if (bUpdate) CombineRgn( hrgnUpdate, hrgnUpdate, hrgn, RGN_OR );
185 else RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
186 DeleteObject( hrgn );
189 /* Take into account the fact that some damages may have occured during the scroll */
190 hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
191 if (GetUpdateRgn( hwnd, hrgnTemp, FALSE ) != NULLREGION)
193 OffsetRgn( hrgnTemp, dx, dy );
194 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
195 RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
197 DeleteObject( hrgnTemp );
199 if( flags & SW_SCROLLCHILDREN )
201 HWND *list = WIN_ListChildren( hwnd );
207 for (i = 0; list[i]; i++)
209 GetWindowRect( list[i], &r );
210 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
211 if (!rect || IntersectRect(&dummy, &r, &rc))
212 SetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
213 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
214 SWP_NOREDRAW | SWP_DEFERERASE );
216 HeapFree( GetProcessHeap(), 0, list );
220 if( flags & (SW_INVALIDATE | SW_ERASE) )
221 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
222 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
223 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
227 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
231 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
232 DeleteObject( hrgnClip );