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
)) return ERROR
;
241 GetClientRect(hwnd
, &rc
);
242 if (rect
) IntersectRect(&rc
, &rc
, rect
);
244 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
247 if (!IsRectEmpty(&cliprc
) && (dx
|| dy
))
251 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
252 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
253 HRGN hrgnTemp
= CreateRectRgnIndirect(&rc
);
256 TRACE(scroll
,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
257 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
258 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
259 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
260 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, (UINT16
)flags
);
263 bCaret
= SCROLL_FixCaret(hwnd
, &caretrc
, flags
);
265 if( hrgnUpdate
) bOwnRgn
= FALSE
;
266 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
268 hDC
= GetDCEx( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
269 DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
|
270 ((flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0) );
271 if( (dc
= (DC
*)GDI_GetObjPtr(hDC
, DC_MAGIC
)) )
274 wnd
->pDriver
->pScrollWindow(wnd
,dc
,dx
,dy
,&rc
,bUpdate
);
278 OffsetRgn( hrgnTemp
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
279 CombineRgn( hrgnTemp
, hrgnTemp
, dc
->w
.hVisRgn
,
281 OffsetRgn( hrgnTemp
, -dc
->w
.DCOrgX
, -dc
->w
.DCOrgY
);
282 CombineRgn( hrgnUpdate
, hrgnTemp
, hrgnClip
,
284 OffsetRgn( hrgnTemp
, dx
, dy
);
286 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnTemp
,
289 if( rcUpdate
) GetRgnBox( hrgnUpdate
, rcUpdate
);
292 ReleaseDC(hwnd
, hDC
);
293 GDI_HEAP_UNLOCK( hDC
);
296 if( wnd
->hrgnUpdate
> 1 )
298 /* Takes into account the fact that some damages may have
299 occured during the scroll. */
300 CombineRgn( hrgnTemp
, wnd
->hrgnUpdate
, 0, RGN_COPY
);
301 OffsetRgn( hrgnTemp
, dx
, dy
);
302 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
303 CombineRgn( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnTemp
, RGN_OR
);
306 if( flags
& SW_SCROLLCHILDREN
)
310 for( w
= wnd
->child
; w
; w
= w
->next
)
312 CONV_RECT16TO32( &w
->rectWindow
, &r
);
313 if( IntersectRect(&r
, &r
, &rc
) )
314 SetWindowPos(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
315 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
316 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
321 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
322 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
323 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) | ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ), 0 );
327 SetCaretPos( caretrc
.left
+ dx
, caretrc
.top
+ dy
);
331 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
332 DeleteObject( hrgnClip
);
333 DeleteObject( hrgnTemp
);