2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
14 #include "wine/winuser16.h"
20 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(scroll
);
24 /*************************************************************************
25 * ScrollWindow (USER.61)
27 void WINAPI
ScrollWindow16(HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
28 const RECT16
*clipRect
)
30 RECT rect32
, clipRect32
;
32 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
33 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
34 ScrollWindow( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
35 clipRect
? &clipRect32
: NULL
);
38 /*************************************************************************
39 * ScrollWindow (USER32.@)
42 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
43 const RECT
*rect
, const RECT
*clipRect
)
46 (ERROR
!= ScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
47 (rect
? 0 : SW_SCROLLCHILDREN
) |
51 /*************************************************************************
54 BOOL16 WINAPI
ScrollDC16( HDC16 hdc
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
55 const RECT16
*cliprc
, HRGN16 hrgnUpdate
,
58 RECT rect32
, clipRect32
, rcUpdate32
;
61 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
62 if (cliprc
) CONV_RECT16TO32( cliprc
, &clipRect32
);
63 ret
= ScrollDC( hdc
, dx
, dy
, rect
? &rect32
: NULL
,
64 cliprc
? &clipRect32
: NULL
, hrgnUpdate
, &rcUpdate32
);
65 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
70 /*************************************************************************
73 * Only the hrgnUpdate is return in device coordinate.
74 * rcUpdate must be returned in logical coordinate to comply with win API.
77 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*rc
,
78 const RECT
*prLClip
, HRGN hrgnUpdate
,
81 RECT rect
, rClip
, rSrc
;
83 DC
*dc
= DC_GetDCUpdate( hdc
);
85 TRACE("%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
86 (HDC16
)hdc
, dx
, dy
, hrgnUpdate
, rcUpdate
,
87 prLClip
? prLClip
->left
: 0, prLClip
? prLClip
->top
: 0, prLClip
? prLClip
->right
: 0, prLClip
? prLClip
->bottom
: 0,
88 rc
? rc
->left
: 0, rc
? rc
->top
: 0, rc
? rc
->right
: 0, rc
? rc
->bottom
: 0 );
90 if ( !dc
|| !hdc
) return FALSE
;
93 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
94 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
95 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
96 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
99 /* compute device clipping region (in device coordinates) */
103 else /* maybe we should just return FALSE? */
104 GetClipBox( hdc
, &rect
);
106 LPtoDP( hdc
, (LPPOINT
)&rect
, 2 );
111 LPtoDP( hdc
, (LPPOINT
)&rClip
, 2 );
112 IntersectRect( &rClip
, &rect
, &rClip
);
117 dx
= XLPTODP ( dc
, rect
.left
+ dx
) - XLPTODP ( dc
, rect
.left
);
118 dy
= YLPTODP ( dc
, rect
.top
+ dy
) - YLPTODP ( dc
, rect
.top
);
121 OffsetRect( &rSrc
, -dx
, -dy
);
122 IntersectRect( &rSrc
, &rSrc
, &rect
);
126 if (!IsRectEmpty(&rSrc
))
128 dest
.x
= (src
.x
= rSrc
.left
) + dx
;
129 dest
.y
= (src
.y
= rSrc
.top
) + dy
;
133 DPtoLP( hdc
, (LPPOINT
)&rSrc
, 2 );
134 DPtoLP( hdc
, &src
, 1 );
135 DPtoLP( hdc
, &dest
, 1 );
137 if (!BitBlt( hdc
, dest
.x
, dest
.y
,
138 rSrc
.right
- rSrc
.left
, rSrc
.bottom
- rSrc
.top
,
139 hdc
, src
.x
, src
.y
, SRCCOPY
))
141 GDI_ReleaseObj( hdc
);
146 /* compute update areas */
148 if (hrgnUpdate
|| rcUpdate
)
151 (hrgnUpdate
) ? hrgnUpdate
: CreateRectRgn( 0,0,0,0 );
154 hrgn2
= CreateRectRgnIndirect( &rect
);
155 OffsetRgn( hrgn2
, dc
->DCOrgX
, dc
->DCOrgY
);
156 CombineRgn( hrgn2
, hrgn2
, dc
->hVisRgn
, RGN_AND
);
157 OffsetRgn( hrgn2
, -dc
->DCOrgX
, -dc
->DCOrgY
);
158 SetRectRgn( hrgn
, rClip
.left
, rClip
.top
,
159 rClip
.right
, rClip
.bottom
);
160 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_AND
);
161 OffsetRgn( hrgn2
, dx
, dy
);
162 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_DIFF
);
166 GetRgnBox( hrgn
, rcUpdate
);
168 /* Put the rcUpdate in logical coordinate */
169 DPtoLP( hdc
, (LPPOINT
)rcUpdate
, 2 );
171 if (!hrgnUpdate
) DeleteObject( hrgn
);
172 DeleteObject( hrgn2
);
178 if (hrgnUpdate
) SetRectRgn(hrgnUpdate
, 0, 0, 0, 0);
179 if (rcUpdate
) SetRectEmpty(rcUpdate
);
182 GDI_ReleaseObj( hdc
);
187 /*************************************************************************
188 * ScrollWindowEx (USER.319)
190 INT16 WINAPI
ScrollWindowEx16( HWND16 hwnd
, INT16 dx
, INT16 dy
,
191 const RECT16
*rect
, const RECT16
*clipRect
,
192 HRGN16 hrgnUpdate
, LPRECT16 rcUpdate
,
195 RECT rect32
, clipRect32
, rcUpdate32
;
198 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
199 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
200 ret
= ScrollWindowEx( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
201 clipRect
? &clipRect32
: NULL
, hrgnUpdate
,
202 (rcUpdate
) ? &rcUpdate32
: NULL
, flags
);
203 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
207 /*************************************************************************
210 static BOOL
SCROLL_FixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
212 HWND hCaret
= CARET_GetHwnd();
217 CARET_GetRect( &rc
);
218 if( hCaret
== hWnd
||
219 (flags
& SW_SCROLLCHILDREN
&& IsChild(hWnd
, hCaret
)) )
223 pt
.x
= rc
.left
; pt
.y
= rc
.top
;
224 MapWindowPoints( hCaret
, hWnd
, (LPPOINT
)&rc
, 2 );
225 if( IntersectRect(lprc
, lprc
, &rc
) )
228 lprc
->left
= pt
.x
; lprc
->top
= pt
.y
;
236 /*************************************************************************
237 * ScrollWindowEx (USER32.@)
239 * NOTE: Use this function instead of ScrollWindow32
241 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
242 const RECT
*rect
, const RECT
*clipRect
,
243 HRGN hrgnUpdate
, LPRECT rcUpdate
,
246 INT retVal
= NULLREGION
;
247 BOOL bCaret
= FALSE
, bOwnRgn
= TRUE
;
249 WND
* wnd
= WIN_FindWndPtr( hwnd
);
251 if( !wnd
|| !WIN_IsWindowDrawable( wnd
, TRUE
))
257 GetClientRect(hwnd
, &rc
);
258 if (rect
) IntersectRect(&rc
, &rc
, rect
);
260 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
263 if (!IsRectEmpty(&cliprc
) && (dx
|| dy
))
266 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
267 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
268 HRGN hrgnTemp
= CreateRectRgnIndirect(&rc
);
271 TRACE("%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
272 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
273 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
274 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
275 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, (UINT16
)flags
);
278 bCaret
= SCROLL_FixCaret(hwnd
, &caretrc
, flags
);
280 if( hrgnUpdate
) bOwnRgn
= FALSE
;
281 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
283 hDC
= GetDCEx( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
284 DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
|
285 ((flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0) );
288 wnd
->pDriver
->pSurfaceCopy(wnd
,hDC
,dx
,dy
,&rc
,bUpdate
);
293 if( (dc
= DC_GetDCPtr(hDC
)) )
295 OffsetRgn( hrgnTemp
, dc
->DCOrgX
, dc
->DCOrgY
);
296 CombineRgn( hrgnTemp
, hrgnTemp
, dc
->hVisRgn
,
298 OffsetRgn( hrgnTemp
, -dc
->DCOrgX
, -dc
->DCOrgY
);
299 CombineRgn( hrgnUpdate
, hrgnTemp
, hrgnClip
,
301 OffsetRgn( hrgnTemp
, dx
, dy
);
303 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnTemp
,
306 if( rcUpdate
) GetRgnBox( hrgnUpdate
, rcUpdate
);
307 GDI_ReleaseObj( hDC
);
310 ReleaseDC(hwnd
, hDC
);
313 if( wnd
->hrgnUpdate
> 1 )
315 /* Takes into account the fact that some damages may have
316 occured during the scroll. */
317 CombineRgn( hrgnTemp
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
318 OffsetRgn( hrgnTemp
, dx
, dy
);
319 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
320 CombineRgn( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnTemp
, RGN_OR
);
323 if( flags
& SW_SCROLLCHILDREN
)
327 for( w
=WIN_LockWndPtr(wnd
->child
); w
; WIN_UpdateWndPtr(&w
, w
->next
))
330 if( !rect
|| IntersectRect(&r
, &r
, &rc
) )
331 SetWindowPos(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
332 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
333 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
338 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
339 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
340 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) | ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ), 0 );
344 SetCaretPos( caretrc
.left
+ dx
, caretrc
.top
+ dy
);
348 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
349 DeleteObject( hrgnClip
);
350 DeleteObject( hrgnTemp
);
353 WIN_ReleaseWndPtr(wnd
);