2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
20 DEFAULT_DEBUG_CHANNEL(scroll)
22 /*************************************************************************
23 * ScrollWindow16 (USER.61)
25 void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
26 const RECT16 *clipRect )
28 RECT rect32, clipRect32;
30 if (rect) CONV_RECT16TO32( rect, &rect32 );
31 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
32 ScrollWindow( hwnd, dx, dy, rect ? &rect32 : NULL,
33 clipRect ? &clipRect32 : NULL );
36 /*************************************************************************
37 * ScrollWindow32 (USER32.450)
40 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
41 const RECT *rect, const RECT *clipRect )
44 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
45 (rect ? 0 : SW_SCROLLCHILDREN) |
49 /*************************************************************************
50 * ScrollDC16 (USER.221)
52 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
53 const RECT16 *cliprc, HRGN16 hrgnUpdate,
56 RECT rect32, clipRect32, rcUpdate32;
59 if (rect) CONV_RECT16TO32( rect, &rect32 );
60 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
61 ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL,
62 cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 );
63 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
68 /*************************************************************************
69 * ScrollDC32 (USER32.449)
71 * Only the hrgnUpdate is return in device coordinate.
72 * rcUpdate must be returned in logical coordinate to comply with win API.
75 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
76 const RECT *prLClip, HRGN hrgnUpdate,
79 RECT rect, rClip, rSrc;
81 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
83 TRACE(scroll,"%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
84 (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate,
85 prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
86 rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
88 if ( !dc || !hdc ) return FALSE;
91 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
92 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
93 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
94 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
97 /* compute device clipping region */
101 else /* maybe we should just return FALSE? */
102 GetClipBox( hdc, &rect );
105 IntersectRect( &rClip,&rect,prLClip );
110 OffsetRect( &rSrc, -dx, -dy );
111 IntersectRect( &rSrc, &rSrc, &rect );
115 if (!IsRectEmpty(&rSrc))
117 dest.x = (src.x = rSrc.left) + dx;
118 dest.y = (src.y = rSrc.top) + dy;
122 if (!BitBlt( hdc, dest.x, dest.y,
123 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
124 hdc, src.x, src.y, SRCCOPY))
126 GDI_HEAP_UNLOCK( hdc );
131 /* compute update areas */
133 if (hrgnUpdate || rcUpdate)
136 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
139 dx = XLPTODP ( dc, rect.left + dx) - XLPTODP ( dc, rect.left);
140 dy = YLPTODP ( dc, rect.top + dy) - YLPTODP ( dc, rect.top);
141 LPtoDP( hdc, (LPPOINT)&rect, 2 );
142 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
143 hrgn2 = CreateRectRgnIndirect( &rect );
144 OffsetRgn( hrgn2, dc->w.DCOrgX, dc->w.DCOrgY );
145 CombineRgn( hrgn2, hrgn2, dc->w.hVisRgn, RGN_AND );
146 OffsetRgn( hrgn2, -dc->w.DCOrgX, -dc->w.DCOrgY );
147 SetRectRgn( hrgn, rClip.left, rClip.top,
148 rClip.right, rClip.bottom );
149 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
150 OffsetRgn( hrgn2, dx, dy );
151 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
155 GetRgnBox( hrgn, rcUpdate );
157 /* Put the rcUpdate in logical coordinate */
158 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
160 if (!hrgnUpdate) DeleteObject( hrgn );
161 DeleteObject( hrgn2 );
167 if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
168 if (rcUpdate) SetRectEmpty(rcUpdate);
171 GDI_HEAP_UNLOCK( hdc );
176 /*************************************************************************
177 * ScrollWindowEx16 (USER.319)
179 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
180 const RECT16 *rect, const RECT16 *clipRect,
181 HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
184 RECT rect32, clipRect32, rcUpdate32;
187 if (rect) CONV_RECT16TO32( rect, &rect32 );
188 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
189 ret = ScrollWindowEx( hwnd, dx, dy, rect ? &rect32 : NULL,
190 clipRect ? &clipRect32 : NULL, hrgnUpdate,
191 (rcUpdate) ? &rcUpdate32 : NULL, flags );
192 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
196 /*************************************************************************
199 static BOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags)
201 HWND hCaret = CARET_GetHwnd();
206 CARET_GetRect( &rc );
207 if( hCaret == hWnd ||
208 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
212 pt.x = rc.left; pt.y = rc.top;
213 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
214 if( IntersectRect(lprc, lprc, &rc) )
217 lprc->left = pt.x; lprc->top = pt.y;
225 /*************************************************************************
226 * ScrollWindowEx32 (USER32.451)
228 * NOTE: Use this function instead of ScrollWindow32
230 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
231 const RECT *rect, const RECT *clipRect,
232 HRGN hrgnUpdate, LPRECT rcUpdate,
235 INT retVal = NULLREGION;
236 BOOL bCaret = FALSE, bOwnRgn = TRUE;
238 WND* wnd = WIN_FindWndPtr( hwnd );
240 if( !wnd || !WIN_IsWindowDrawable( wnd, TRUE ))
246 GetClientRect(hwnd, &rc);
247 if (rect) IntersectRect(&rc, &rc, rect);
249 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
252 if (!IsRectEmpty(&cliprc) && (dx || dy))
256 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
257 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
258 HRGN hrgnTemp = CreateRectRgnIndirect(&rc);
261 TRACE(scroll,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
262 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
263 (HWND16)hwnd, dx, dy, hrgnUpdate, rcUpdate,
264 clipRect?clipRect->left:0, clipRect?clipRect->top:0, clipRect?clipRect->right:0, clipRect?clipRect->bottom:0,
265 rc.left, rc.top, rc.right, rc.bottom, (UINT16)flags );
268 bCaret = SCROLL_FixCaret(hwnd, &caretrc, flags);
270 if( hrgnUpdate ) bOwnRgn = FALSE;
271 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
273 hDC = GetDCEx( hwnd, hrgnClip, DCX_CACHE | DCX_USESTYLE |
274 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
275 ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
276 if( (dc = (DC *)GDI_GetObjPtr(hDC, DC_MAGIC)) )
279 wnd->pDriver->pSurfaceCopy(wnd,dc,dx,dy,&rc,bUpdate);
283 OffsetRgn( hrgnTemp, dc->w.DCOrgX, dc->w.DCOrgY );
284 CombineRgn( hrgnTemp, hrgnTemp, dc->w.hVisRgn,
286 OffsetRgn( hrgnTemp, -dc->w.DCOrgX, -dc->w.DCOrgY );
287 CombineRgn( hrgnUpdate, hrgnTemp, hrgnClip,
289 OffsetRgn( hrgnTemp, dx, dy );
291 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp,
294 if( rcUpdate ) GetRgnBox( hrgnUpdate, rcUpdate );
297 ReleaseDC(hwnd, hDC);
298 GDI_HEAP_UNLOCK( hDC );
301 if( wnd->hrgnUpdate > 1 )
303 /* Takes into account the fact that some damages may have
304 occured during the scroll. */
305 CombineRgn( hrgnTemp, wnd->hrgnUpdate, 0, RGN_COPY );
306 OffsetRgn( hrgnTemp, dx, dy );
307 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
308 CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate, hrgnTemp, RGN_OR );
311 if( flags & SW_SCROLLCHILDREN )
315 for( w =WIN_LockWndPtr(wnd->child); w; WIN_UpdateWndPtr(&w, w->next))
317 CONV_RECT16TO32( &w->rectWindow, &r );
318 if( IntersectRect(&r, &r, &rc) )
319 SetWindowPos(w->hwndSelf, 0, w->rectWindow.left + dx,
320 w->rectWindow.top + dy, 0,0, SWP_NOZORDER |
321 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
326 if( flags & (SW_INVALIDATE | SW_ERASE) )
327 PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
328 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
332 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
336 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
337 DeleteObject( hrgnClip );
338 DeleteObject( hrgnTemp );
341 WIN_ReleaseWndPtr(wnd);