2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
18 #include "sysmetrics.h"
21 /*************************************************************************
22 * ScrollWindow16 (USER.61)
24 void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
25 const RECT16 *clipRect )
27 RECT rect32, clipRect32;
29 if (rect) CONV_RECT16TO32( rect, &rect32 );
30 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
31 ScrollWindow( hwnd, dx, dy, rect ? &rect32 : NULL,
32 clipRect ? &clipRect32 : NULL );
35 /*************************************************************************
36 * ScrollWindow32 (USER32.450)
39 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
40 const RECT *rect, const RECT *clipRect )
43 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
44 (rect ? 0 : SW_SCROLLCHILDREN) |
48 /*************************************************************************
49 * ScrollDC16 (USER.221)
51 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
52 const RECT16 *cliprc, HRGN16 hrgnUpdate,
55 RECT rect32, clipRect32, rcUpdate32;
58 if (rect) CONV_RECT16TO32( rect, &rect32 );
59 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
60 ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL,
61 cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 );
62 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
67 /*************************************************************************
68 * ScrollDC32 (USER32.449)
70 * Only the hrgnUpdate is return in device coordinate.
71 * rcUpdate must be returned in logical coordinate to comply with win API.
74 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
75 const RECT *prLClip, HRGN hrgnUpdate,
78 RECT rect, rClip, rSrc;
80 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
82 TRACE(scroll,"%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
83 (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate,
84 prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
85 rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
87 if ( !dc || !hdc ) return FALSE;
90 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
91 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
92 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
93 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
96 /* compute device clipping region */
100 else /* maybe we should just return FALSE? */
101 GetClipBox( hdc, &rect );
104 IntersectRect( &rClip,&rect,prLClip );
109 OffsetRect( &rSrc, -dx, -dy );
110 IntersectRect( &rSrc, &rSrc, &rect );
114 if (!IsRectEmpty(&rSrc))
116 dest.x = (src.x = rSrc.left) + dx;
117 dest.y = (src.y = rSrc.top) + dy;
121 if (!BitBlt( hdc, dest.x, dest.y,
122 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
123 hdc, src.x, src.y, SRCCOPY))
125 GDI_HEAP_UNLOCK( hdc );
130 /* compute update areas */
132 if (hrgnUpdate || rcUpdate)
135 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
138 dx = XLPTODP ( dc, rect.left + dx) - XLPTODP ( dc, rect.left);
139 dy = YLPTODP ( dc, rect.top + dy) - YLPTODP ( dc, rect.top);
140 LPtoDP( hdc, (LPPOINT)&rect, 2 );
141 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
142 hrgn2 = CreateRectRgnIndirect( &rect );
143 OffsetRgn( hrgn2, dc->w.DCOrgX, dc->w.DCOrgY );
144 CombineRgn( hrgn2, hrgn2, dc->w.hVisRgn, RGN_AND );
145 OffsetRgn( hrgn2, -dc->w.DCOrgX, -dc->w.DCOrgY );
146 SetRectRgn( hrgn, rClip.left, rClip.top,
147 rClip.right, rClip.bottom );
148 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
149 OffsetRgn( hrgn2, dx, dy );
150 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
154 GetRgnBox( hrgn, rcUpdate );
156 //Put the rcUpdate in logical coordinate
157 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
159 if (!hrgnUpdate) DeleteObject( hrgn );
160 DeleteObject( hrgn2 );
166 if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
167 if (rcUpdate) SetRectEmpty(rcUpdate);
170 GDI_HEAP_UNLOCK( hdc );
175 /*************************************************************************
176 * ScrollWindowEx16 (USER.319)
178 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
179 const RECT16 *rect, const RECT16 *clipRect,
180 HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
183 RECT rect32, clipRect32, rcUpdate32;
186 if (rect) CONV_RECT16TO32( rect, &rect32 );
187 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
188 ret = ScrollWindowEx( hwnd, dx, dy, rect ? &rect32 : NULL,
189 clipRect ? &clipRect32 : NULL, hrgnUpdate,
190 (rcUpdate) ? &rcUpdate32 : NULL, flags );
191 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
195 /*************************************************************************
198 static BOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags)
200 HWND hCaret = CARET_GetHwnd();
205 CARET_GetRect( &rc );
206 if( hCaret == hWnd ||
207 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
211 pt.x = rc.left; pt.y = rc.top;
212 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
213 if( IntersectRect(lprc, lprc, &rc) )
216 lprc->left = pt.x; lprc->top = pt.y;
224 /*************************************************************************
225 * ScrollWindowEx32 (USER32.451)
227 * NOTE: Use this function instead of ScrollWindow32
229 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
230 const RECT *rect, const RECT *clipRect,
231 HRGN hrgnUpdate, LPRECT rcUpdate,
234 INT retVal = NULLREGION;
235 BOOL bCaret = FALSE, bOwnRgn = TRUE;
237 WND* wnd = WIN_FindWndPtr( hwnd );
239 if( !wnd || !WIN_IsWindowDrawable( wnd, TRUE ))
245 GetClientRect(hwnd, &rc);
246 if (rect) IntersectRect(&rc, &rc, rect);
248 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
251 if (!IsRectEmpty(&cliprc) && (dx || dy))
255 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
256 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
257 HRGN hrgnTemp = CreateRectRgnIndirect(&rc);
260 TRACE(scroll,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
261 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
262 (HWND16)hwnd, dx, dy, hrgnUpdate, rcUpdate,
263 clipRect?clipRect->left:0, clipRect?clipRect->top:0, clipRect?clipRect->right:0, clipRect?clipRect->bottom:0,
264 rc.left, rc.top, rc.right, rc.bottom, (UINT16)flags );
267 bCaret = SCROLL_FixCaret(hwnd, &caretrc, flags);
269 if( hrgnUpdate ) bOwnRgn = FALSE;
270 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
272 hDC = GetDCEx( hwnd, hrgnClip, DCX_CACHE | DCX_USESTYLE |
273 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
274 ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
275 if( (dc = (DC *)GDI_GetObjPtr(hDC, DC_MAGIC)) )
278 wnd->pDriver->pScrollWindow(wnd,dc,dx,dy,&rc,bUpdate);
282 OffsetRgn( hrgnTemp, dc->w.DCOrgX, dc->w.DCOrgY );
283 CombineRgn( hrgnTemp, hrgnTemp, dc->w.hVisRgn,
285 OffsetRgn( hrgnTemp, -dc->w.DCOrgX, -dc->w.DCOrgY );
286 CombineRgn( hrgnUpdate, hrgnTemp, hrgnClip,
288 OffsetRgn( hrgnTemp, dx, dy );
290 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp,
293 if( rcUpdate ) GetRgnBox( hrgnUpdate, rcUpdate );
296 ReleaseDC(hwnd, hDC);
297 GDI_HEAP_UNLOCK( hDC );
300 if( wnd->hrgnUpdate > 1 )
302 /* Takes into account the fact that some damages may have
303 occured during the scroll. */
304 CombineRgn( hrgnTemp, wnd->hrgnUpdate, 0, RGN_COPY );
305 OffsetRgn( hrgnTemp, dx, dy );
306 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
307 CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate, hrgnTemp, RGN_OR );
310 if( flags & SW_SCROLLCHILDREN )
314 for( w =WIN_LockWndPtr(wnd->child); w; WIN_UpdateWndPtr(&w, w->next))
316 CONV_RECT16TO32( &w->rectWindow, &r );
317 if( IntersectRect(&r, &r, &rc) )
318 SetWindowPos(w->hwndSelf, 0, w->rectWindow.left + dx,
319 w->rectWindow.top + dy, 0,0, SWP_NOZORDER |
320 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
325 if( flags & (SW_INVALIDATE | SW_ERASE) )
326 PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
327 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
331 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
335 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
336 DeleteObject( hrgnClip );
337 DeleteObject( hrgnTemp );
340 WIN_ReleaseWndPtr(wnd);