2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
12 #include "wine/winuser16.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(scroll
)
23 /*************************************************************************
24 * ScrollWindow16 (USER.61)
26 void WINAPI
ScrollWindow16(HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
27 const RECT16
*clipRect
)
29 RECT rect32
, clipRect32
;
31 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
32 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
33 ScrollWindow( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
34 clipRect
? &clipRect32
: NULL
);
37 /*************************************************************************
38 * ScrollWindow32 (USER32.450)
41 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
42 const RECT
*rect
, const RECT
*clipRect
)
45 (ERROR
!= ScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
46 (rect
? 0 : SW_SCROLLCHILDREN
) |
50 /*************************************************************************
51 * ScrollDC16 (USER.221)
53 BOOL16 WINAPI
ScrollDC16( HDC16 hdc
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
54 const RECT16
*cliprc
, HRGN16 hrgnUpdate
,
57 RECT rect32
, clipRect32
, rcUpdate32
;
60 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
61 if (cliprc
) CONV_RECT16TO32( cliprc
, &clipRect32
);
62 ret
= ScrollDC( hdc
, dx
, dy
, rect
? &rect32
: NULL
,
63 cliprc
? &clipRect32
: NULL
, hrgnUpdate
, &rcUpdate32
);
64 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
69 /*************************************************************************
70 * ScrollDC32 (USER32.449)
72 * Only the hrgnUpdate is return in device coordinate.
73 * rcUpdate must be returned in logical coordinate to comply with win API.
76 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*rc
,
77 const RECT
*prLClip
, HRGN hrgnUpdate
,
80 RECT rect
, rClip
, rSrc
;
82 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
84 TRACE("%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
85 (HDC16
)hdc
, dx
, dy
, hrgnUpdate
, rcUpdate
,
86 prLClip
? prLClip
->left
: 0, prLClip
? prLClip
->top
: 0, prLClip
? prLClip
->right
: 0, prLClip
? prLClip
->bottom
: 0,
87 rc
? rc
->left
: 0, rc
? rc
->top
: 0, rc
? rc
->right
: 0, rc
? rc
->bottom
: 0 );
89 if ( !dc
|| !hdc
) return FALSE
;
92 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
93 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
94 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
95 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
98 /* compute device clipping region */
102 else /* maybe we should just return FALSE? */
103 GetClipBox( hdc
, &rect
);
106 IntersectRect( &rClip
,&rect
,prLClip
);
111 OffsetRect( &rSrc
, -dx
, -dy
);
112 IntersectRect( &rSrc
, &rSrc
, &rect
);
116 if (!IsRectEmpty(&rSrc
))
118 dest
.x
= (src
.x
= rSrc
.left
) + dx
;
119 dest
.y
= (src
.y
= rSrc
.top
) + dy
;
123 if (!BitBlt( hdc
, dest
.x
, dest
.y
,
124 rSrc
.right
- rSrc
.left
, rSrc
.bottom
- rSrc
.top
,
125 hdc
, src
.x
, src
.y
, SRCCOPY
))
127 GDI_HEAP_UNLOCK( hdc
);
132 /* compute update areas */
134 if (hrgnUpdate
|| rcUpdate
)
137 (hrgnUpdate
) ? hrgnUpdate
: CreateRectRgn( 0,0,0,0 );
140 dx
= XLPTODP ( dc
, rect
.left
+ dx
) - XLPTODP ( dc
, rect
.left
);
141 dy
= YLPTODP ( dc
, rect
.top
+ dy
) - YLPTODP ( dc
, rect
.top
);
142 LPtoDP( hdc
, (LPPOINT
)&rect
, 2 );
143 LPtoDP( hdc
, (LPPOINT
)&rClip
, 2 );
144 hrgn2
= CreateRectRgnIndirect( &rect
);
145 OffsetRgn( hrgn2
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
146 CombineRgn( hrgn2
, hrgn2
, dc
->w
.hVisRgn
, RGN_AND
);
147 OffsetRgn( hrgn2
, -dc
->w
.DCOrgX
, -dc
->w
.DCOrgY
);
148 SetRectRgn( hrgn
, rClip
.left
, rClip
.top
,
149 rClip
.right
, rClip
.bottom
);
150 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_AND
);
151 OffsetRgn( hrgn2
, dx
, dy
);
152 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_DIFF
);
156 GetRgnBox( hrgn
, rcUpdate
);
158 /* Put the rcUpdate in logical coordinate */
159 DPtoLP( hdc
, (LPPOINT
)rcUpdate
, 2 );
161 if (!hrgnUpdate
) DeleteObject( hrgn
);
162 DeleteObject( hrgn2
);
168 if (hrgnUpdate
) SetRectRgn(hrgnUpdate
, 0, 0, 0, 0);
169 if (rcUpdate
) SetRectEmpty(rcUpdate
);
172 GDI_HEAP_UNLOCK( hdc
);
177 /*************************************************************************
178 * ScrollWindowEx16 (USER.319)
180 INT16 WINAPI
ScrollWindowEx16( HWND16 hwnd
, INT16 dx
, INT16 dy
,
181 const RECT16
*rect
, const RECT16
*clipRect
,
182 HRGN16 hrgnUpdate
, LPRECT16 rcUpdate
,
185 RECT rect32
, clipRect32
, rcUpdate32
;
188 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
189 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
190 ret
= ScrollWindowEx( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
191 clipRect
? &clipRect32
: NULL
, hrgnUpdate
,
192 (rcUpdate
) ? &rcUpdate32
: NULL
, flags
);
193 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
197 /*************************************************************************
200 static BOOL
SCROLL_FixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
202 HWND hCaret
= CARET_GetHwnd();
207 CARET_GetRect( &rc
);
208 if( hCaret
== hWnd
||
209 (flags
& SW_SCROLLCHILDREN
&& IsChild(hWnd
, hCaret
)) )
213 pt
.x
= rc
.left
; pt
.y
= rc
.top
;
214 MapWindowPoints( hCaret
, hWnd
, (LPPOINT
)&rc
, 2 );
215 if( IntersectRect(lprc
, lprc
, &rc
) )
218 lprc
->left
= pt
.x
; lprc
->top
= pt
.y
;
226 /*************************************************************************
227 * ScrollWindowEx32 (USER32.451)
229 * NOTE: Use this function instead of ScrollWindow32
231 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
232 const RECT
*rect
, const RECT
*clipRect
,
233 HRGN hrgnUpdate
, LPRECT rcUpdate
,
236 INT retVal
= NULLREGION
;
237 BOOL bCaret
= FALSE
, bOwnRgn
= TRUE
;
239 WND
* wnd
= WIN_FindWndPtr( hwnd
);
241 if( !wnd
|| !WIN_IsWindowDrawable( wnd
, TRUE
))
247 GetClientRect(hwnd
, &rc
);
248 if (rect
) IntersectRect(&rc
, &rc
, rect
);
250 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
253 if (!IsRectEmpty(&cliprc
) && (dx
|| dy
))
257 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
258 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
259 HRGN hrgnTemp
= CreateRectRgnIndirect(&rc
);
262 TRACE("%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
263 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
264 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
265 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
266 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, (UINT16
)flags
);
269 bCaret
= SCROLL_FixCaret(hwnd
, &caretrc
, flags
);
271 if( hrgnUpdate
) bOwnRgn
= FALSE
;
272 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
274 hDC
= GetDCEx( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
275 DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
|
276 ((flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0) );
277 if( (dc
= (DC
*)GDI_GetObjPtr(hDC
, DC_MAGIC
)) )
280 wnd
->pDriver
->pSurfaceCopy(wnd
,dc
,dx
,dy
,&rc
,bUpdate
);
284 OffsetRgn( hrgnTemp
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
285 CombineRgn( hrgnTemp
, hrgnTemp
, dc
->w
.hVisRgn
,
287 OffsetRgn( hrgnTemp
, -dc
->w
.DCOrgX
, -dc
->w
.DCOrgY
);
288 CombineRgn( hrgnUpdate
, hrgnTemp
, hrgnClip
,
290 OffsetRgn( hrgnTemp
, dx
, dy
);
292 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnTemp
,
295 if( rcUpdate
) GetRgnBox( hrgnUpdate
, rcUpdate
);
298 ReleaseDC(hwnd
, hDC
);
299 GDI_HEAP_UNLOCK( hDC
);
302 if( wnd
->hrgnUpdate
> 1 )
304 /* Takes into account the fact that some damages may have
305 occured during the scroll. */
306 CombineRgn( hrgnTemp
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
307 OffsetRgn( hrgnTemp
, dx
, dy
);
308 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
309 CombineRgn( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnTemp
, RGN_OR
);
312 if( flags
& SW_SCROLLCHILDREN
)
316 for( w
=WIN_LockWndPtr(wnd
->child
); w
; WIN_UpdateWndPtr(&w
, w
->next
))
318 CONV_RECT16TO32( &w
->rectWindow
, &r
);
319 if( IntersectRect(&r
, &r
, &rc
) )
320 SetWindowPos(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
321 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
322 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
327 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
328 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
329 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) | ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ), 0 );
333 SetCaretPos( caretrc
.left
+ dx
, caretrc
.top
+ dy
);
337 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
338 DeleteObject( hrgnClip
);
339 DeleteObject( hrgnTemp
);
342 WIN_ReleaseWndPtr(wnd
);