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 RECT32 rect32, clipRect32;
29 if (rect) CONV_RECT16TO32( rect, &rect32 );
30 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
31 ScrollWindow32( hwnd, dx, dy, rect ? &rect32 : NULL,
32 clipRect ? &clipRect32 : NULL );
35 /*************************************************************************
36 * ScrollWindow32 (USER32.450)
39 BOOL32 WINAPI ScrollWindow32( HWND32 hwnd, INT32 dx, INT32 dy,
40 const RECT32 *rect, const RECT32 *clipRect )
43 (ERROR != ScrollWindowEx32( 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 RECT32 rect32, clipRect32, rcUpdate32;
58 if (rect) CONV_RECT16TO32( rect, &rect32 );
59 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
60 ret = ScrollDC32( 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 * Both 'rc' and 'prLClip' are in logical units but update info is
71 * returned in device coordinates.
73 BOOL32 WINAPI ScrollDC32( HDC32 hdc, INT32 dx, INT32 dy, const RECT32 *rc,
74 const RECT32 *prLClip, HRGN32 hrgnUpdate,
77 RECT32 rect, rClip, rSrc;
79 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
81 TRACE(scroll,"%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
82 (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate,
83 prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
84 rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
86 if ( !dc || !hdc ) return FALSE;
89 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
90 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
91 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
92 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
95 /* compute device clipping region */
99 else /* maybe we should just return FALSE? */
100 GetClipBox32( hdc, &rect );
103 IntersectRect32( &rClip,&rect,prLClip );
108 OffsetRect32( &rSrc, -dx, -dy );
109 IntersectRect32( &rSrc, &rSrc, &rect );
113 if (!IsRectEmpty32(&rSrc))
115 dest.x = (src.x = rSrc.left) + dx;
116 dest.y = (src.y = rSrc.top) + dy;
120 if (!BitBlt32( hdc, dest.x, dest.y,
121 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
122 hdc, src.x, src.y, SRCCOPY))
124 GDI_HEAP_UNLOCK( hdc );
129 /* compute update areas */
131 if (hrgnUpdate || rcUpdate)
134 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn32( 0,0,0,0 );
137 dx = XLPTODP ( dc, rect.left + dx) - XLPTODP ( dc, rect.left);
138 dy = YLPTODP ( dc, rect.top + dy) - YLPTODP ( dc, rect.top);
139 LPtoDP32( hdc, (LPPOINT32)&rect, 2 );
140 LPtoDP32( hdc, (LPPOINT32)&rClip, 2 );
141 hrgn2 = CreateRectRgnIndirect32( &rect );
142 OffsetRgn32( hrgn2, dc->w.DCOrgX, dc->w.DCOrgY );
143 CombineRgn32( hrgn2, hrgn2, dc->w.hVisRgn, RGN_AND );
144 OffsetRgn32( hrgn2, -dc->w.DCOrgX, -dc->w.DCOrgY );
145 SetRectRgn32( hrgn, rClip.left, rClip.top,
146 rClip.right, rClip.bottom );
147 CombineRgn32( hrgn, hrgn, hrgn2, RGN_AND );
148 OffsetRgn32( hrgn2, dx, dy );
149 CombineRgn32( hrgn, hrgn, hrgn2, RGN_DIFF );
151 if( rcUpdate ) GetRgnBox32( hrgn, rcUpdate );
153 if (!hrgnUpdate) DeleteObject32( hrgn );
154 DeleteObject32( hrgn2 );
159 if (hrgnUpdate) SetRectRgn32(hrgnUpdate, 0, 0, 0, 0);
160 if (rcUpdate) SetRectEmpty32(rcUpdate);
163 GDI_HEAP_UNLOCK( hdc );
168 /*************************************************************************
169 * ScrollWindowEx16 (USER.319)
171 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
172 const RECT16 *rect, const RECT16 *clipRect,
173 HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
176 RECT32 rect32, clipRect32, rcUpdate32;
179 if (rect) CONV_RECT16TO32( rect, &rect32 );
180 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
181 ret = ScrollWindowEx32( hwnd, dx, dy, rect ? &rect32 : NULL,
182 clipRect ? &clipRect32 : NULL, hrgnUpdate,
183 (rcUpdate) ? &rcUpdate32 : NULL, flags );
184 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
188 /*************************************************************************
191 static BOOL32 SCROLL_FixCaret(HWND32 hWnd, LPRECT32 lprc, UINT32 flags)
193 HWND32 hCaret = CARET_GetHwnd();
198 CARET_GetRect( &rc );
199 if( hCaret == hWnd ||
200 (flags & SW_SCROLLCHILDREN && IsChild32(hWnd, hCaret)) )
204 pt.x = rc.left; pt.y = rc.top;
205 MapWindowPoints32( hCaret, hWnd, (LPPOINT32)&rc, 2 );
206 if( IntersectRect32(lprc, lprc, &rc) )
209 lprc->left = pt.x; lprc->top = pt.y;
217 /*************************************************************************
218 * ScrollWindowEx32 (USER32.451)
220 * NOTE: Use this function instead of ScrollWindow32
222 INT32 WINAPI ScrollWindowEx32( HWND32 hwnd, INT32 dx, INT32 dy,
223 const RECT32 *rect, const RECT32 *clipRect,
224 HRGN32 hrgnUpdate, LPRECT32 rcUpdate,
227 INT32 retVal = NULLREGION;
228 BOOL32 bCaret = FALSE, bOwnRgn = TRUE;
230 WND* wnd = WIN_FindWndPtr( hwnd );
232 if( !wnd || !WIN_IsWindowDrawable( wnd, TRUE )) return ERROR;
234 GetClientRect32(hwnd, &rc);
235 if (rect) IntersectRect32(&rc, &rc, rect);
237 if (clipRect) IntersectRect32(&cliprc,&rc,clipRect);
240 if (!IsRectEmpty32(&cliprc) && (dx || dy))
244 BOOL32 bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
245 HRGN32 hrgnClip = CreateRectRgnIndirect32(&cliprc);
246 HRGN32 hrgnTemp = CreateRectRgnIndirect32(&rc);
249 TRACE(scroll,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
250 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
251 (HWND16)hwnd, dx, dy, hrgnUpdate, rcUpdate,
252 clipRect?clipRect->left:0, clipRect?clipRect->top:0, clipRect?clipRect->right:0, clipRect?clipRect->bottom:0,
253 rc.left, rc.top, rc.right, rc.bottom, (UINT16)flags );
256 bCaret = SCROLL_FixCaret(hwnd, &caretrc, flags);
258 if( hrgnUpdate ) bOwnRgn = FALSE;
259 else if( bUpdate ) hrgnUpdate = CreateRectRgn32( 0, 0, 0, 0 );
261 hDC = GetDCEx32( hwnd, hrgnClip, DCX_CACHE | DCX_USESTYLE |
262 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
263 ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
264 if( (dc = (DC *)GDI_GetObjPtr(hDC, DC_MAGIC)) )
267 wnd->pDriver->pScrollWindow(wnd,dc,dx,dy,&rc,bUpdate);
271 OffsetRgn32( hrgnTemp, dc->w.DCOrgX, dc->w.DCOrgY );
272 CombineRgn32( hrgnTemp, hrgnTemp, dc->w.hVisRgn,
274 OffsetRgn32( hrgnTemp, -dc->w.DCOrgX, -dc->w.DCOrgY );
275 CombineRgn32( hrgnUpdate, hrgnTemp, hrgnClip,
277 OffsetRgn32( hrgnTemp, dx, dy );
279 CombineRgn32( hrgnUpdate, hrgnUpdate, hrgnTemp,
282 if( rcUpdate ) GetRgnBox32( hrgnUpdate, rcUpdate );
285 ReleaseDC32(hwnd, hDC);
286 GDI_HEAP_UNLOCK( hDC );
289 if( wnd->hrgnUpdate > 1 )
291 /* Takes into account the fact that some damages may have
292 occured during the scroll. */
293 CombineRgn32( hrgnTemp, wnd->hrgnUpdate, 0, RGN_COPY );
294 OffsetRgn32( hrgnTemp, dx, dy );
295 CombineRgn32( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
296 CombineRgn32( wnd->hrgnUpdate, wnd->hrgnUpdate, hrgnTemp, RGN_OR );
299 if( flags & SW_SCROLLCHILDREN )
303 for( w = wnd->child; w; w = w->next )
305 CONV_RECT16TO32( &w->rectWindow, &r );
306 if( IntersectRect32(&r, &r, &rc) )
307 SetWindowPos32(w->hwndSelf, 0, w->rectWindow.left + dx,
308 w->rectWindow.top + dy, 0,0, SWP_NOZORDER |
309 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
314 if( flags & (SW_INVALIDATE | SW_ERASE) )
315 PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
316 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
320 SetCaretPos32( caretrc.left + dx, caretrc.top + dy );
324 if( bOwnRgn && hrgnUpdate ) DeleteObject32( hrgnUpdate );
325 DeleteObject32( hrgnClip );
326 DeleteObject32( hrgnTemp );