2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
19 #include "sysmetrics.h"
23 /*************************************************************************
24 * ScrollWindow16 (USER.61)
26 void WINAPI
ScrollWindow16(HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
27 const RECT16
*clipRect
)
29 RECT32 rect32
, clipRect32
;
31 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
32 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
33 ScrollWindow32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
34 clipRect
? &clipRect32
: NULL
);
37 /*************************************************************************
38 * ScrollWindow32 (USER32.450)
40 * FIXME: verify clipping region calculations
42 BOOL32 WINAPI
ScrollWindow32( HWND32 hwnd
, INT32 dx
, INT32 dy
,
43 const RECT32
*rect
, const RECT32
*clipRect
)
46 HRGN32 hrgnUpdate
,hrgnClip
;
48 HWND32 hCaretWnd
= CARET_GetHwnd();
49 WND
* wndScroll
= WIN_FindWndPtr( hwnd
);
51 TRACE(scroll
,"hwnd=%04x, dx=%d, dy=%d, lpRect =%p clipRect=%i,%i,%i,%i\n",
53 clipRect
? clipRect
->left
: 0,
54 clipRect
? clipRect
->top
: 0,
55 clipRect
? clipRect
->right
: 0,
56 clipRect
? clipRect
->bottom
: 0 );
58 if ( !wndScroll
|| !WIN_IsWindowDrawable( wndScroll
, TRUE
) ) return TRUE
;
60 if ( !rect
) /* do not clip children */
62 GetClientRect32(hwnd
, &rc
);
63 hrgnClip
= CreateRectRgnIndirect32( &rc
);
65 if ((hCaretWnd
== hwnd
) || IsChild32(hwnd
,hCaretWnd
))
66 HideCaret32(hCaretWnd
);
69 hdc
= GetDCEx32(hwnd
, hrgnClip
, DCX_CACHE
| DCX_CLIPSIBLINGS
);
70 DeleteObject32( hrgnClip
);
72 else /* clip children */
74 CopyRect32(&rc
, rect
);
76 if (hCaretWnd
== hwnd
) HideCaret32(hCaretWnd
);
79 hdc
= GetDCEx32( hwnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
83 GetClientRect32(hwnd
, &cliprc
);
85 CopyRect32(&cliprc
, clipRect
);
87 hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
88 ScrollDC32( hdc
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, NULL
);
89 ReleaseDC32(hwnd
, hdc
);
91 if( !rect
) /* move child windows and update region */
95 if( wndScroll
->hrgnUpdate
> 1 )
96 OffsetRgn32( wndScroll
->hrgnUpdate
, dx
, dy
);
98 for (wndPtr
= wndScroll
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
99 SetWindowPos32(wndPtr
->hwndSelf
, 0, wndPtr
->rectWindow
.left
+ dx
,
100 wndPtr
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
101 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
105 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_ALLCHILDREN
|
106 RDW_INVALIDATE
| RDW_ERASE
| RDW_ERASENOW
, RDW_C_USEHRGN
);
108 DeleteObject32( hrgnUpdate
);
113 pt
.x
+= dx
; pt
.y
+= dy
;
114 SetCaretPos32(pt
.x
, pt
.y
);
115 ShowCaret32(hCaretWnd
);
121 /*************************************************************************
122 * ScrollDC16 (USER.221)
124 BOOL16 WINAPI
ScrollDC16( HDC16 hdc
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
125 const RECT16
*cliprc
, HRGN16 hrgnUpdate
,
128 RECT32 rect32
, clipRect32
, rcUpdate32
;
131 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
132 if (cliprc
) CONV_RECT16TO32( cliprc
, &clipRect32
);
133 ret
= ScrollDC32( hdc
, dx
, dy
, rect
? &rect32
: NULL
,
134 cliprc
? &clipRect32
: NULL
, hrgnUpdate
, &rcUpdate32
);
135 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
140 /*************************************************************************
141 * ScrollDC32 (USER32.449)
143 * Both 'rc' and 'prLClip' are in logical units but update info is
144 * returned in device coordinates.
146 BOOL32 WINAPI
ScrollDC32( HDC32 hdc
, INT32 dx
, INT32 dy
, const RECT32
*rc
,
147 const RECT32
*prLClip
, HRGN32 hrgnUpdate
,
150 RECT32 rDClip
, rLClip
;
152 HRGN32 hrgnScrollClip
= 0;
155 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
157 TRACE(scroll
,"%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
158 (HDC16
)hdc
, dx
, dy
, hrgnUpdate
, rcUpdate
,
159 prLClip
? prLClip
->left
: 0, prLClip
? prLClip
->top
: 0, prLClip
? prLClip
->right
: 0, prLClip
? prLClip
->bottom
: 0,
160 rc
? rc
->left
: 0, rc
? rc
->top
: 0, rc
? rc
->right
: 0, rc
? rc
->bottom
: 0 );
162 if ( !dc
|| !hdc
) return FALSE
;
165 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
166 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
167 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
168 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
171 /* compute device clipping region */
176 rDClip
.left
= XLPTODP(dc
, rc
->left
); rDClip
.right
= XLPTODP(dc
, rc
->right
);
177 rDClip
.top
= YLPTODP(dc
, rc
->top
); rDClip
.bottom
= YLPTODP(dc
, rc
->bottom
);
179 else /* maybe we should just return FALSE? */
181 GetClipBox32( hdc
, &rDClip
);
182 rLClip
.left
= XDPTOLP(dc
, rDClip
.left
); rLClip
.right
= XDPTOLP(dc
, rDClip
.right
);
183 rLClip
.top
= YDPTOLP(dc
, rDClip
.top
); rLClip
.bottom
= YDPTOLP(dc
, rDClip
.bottom
);
190 r
.left
= XLPTODP(dc
, prLClip
->left
); r
.right
= XLPTODP(dc
, prLClip
->right
);
191 r
.top
= YLPTODP(dc
, prLClip
->top
); r
.bottom
= YLPTODP(dc
, prLClip
->bottom
);
192 IntersectRect32(&rLClip
,&rLClip
,prLClip
);
193 IntersectRect32(&rDClip
,&rDClip
,&r
);
196 if( rDClip
.left
>= rDClip
.right
|| rDClip
.top
>= rDClip
.bottom
)
198 GDI_HEAP_UNLOCK( hdc
);
202 hrgnClip
= GetClipRgn16(hdc
);
203 hrgnScrollClip
= CreateRectRgnIndirect32(&rDClip
);
207 /* change device clipping region directly */
209 CombineRgn32( hrgnScrollClip
, hrgnClip
, 0, RGN_COPY
);
210 SetRectRgn32( hrgnClip
, rDClip
.left
, rDClip
.top
,
211 rDClip
.right
, rDClip
.bottom
);
213 CLIPPING_UpdateGCRegion( dc
);
216 SelectClipRgn32( hdc
, hrgnScrollClip
);
218 /* translate coordinates */
220 ldx
= dx
* dc
->wndExtX
/ dc
->vportExtX
;
221 ldy
= dy
* dc
->wndExtY
/ dc
->vportExtY
;
224 dest
.x
= (src
.x
= rLClip
.left
) + ldx
;
226 src
.x
= (dest
.x
= rLClip
.left
) - ldx
;
229 dest
.y
= (src
.y
= rLClip
.top
) + ldy
;
231 src
.y
= (dest
.y
= rLClip
.top
) - ldy
;
235 if( rDClip
.right
- rDClip
.left
> dx
&&
236 rDClip
.bottom
- rDClip
.top
> dy
)
238 ldx
= rLClip
.right
- rLClip
.left
- ldx
;
239 ldy
= rLClip
.bottom
- rLClip
.top
- ldy
;
241 if (!BitBlt32( hdc
, dest
.x
, dest
.y
, ldx
, ldy
,
242 hdc
, src
.x
, src
.y
, SRCCOPY
))
244 GDI_HEAP_UNLOCK( hdc
);
249 /* restore clipping region */
253 CombineRgn32( hrgnClip
, hrgnScrollClip
, 0, RGN_COPY
);
254 CLIPPING_UpdateGCRegion( dc
);
255 SetRectRgn32( hrgnScrollClip
, rDClip
.left
, rDClip
.top
,
256 rDClip
.right
, rDClip
.bottom
);
259 SelectClipRgn32( hdc
, 0 );
261 /* compute update areas */
263 if (hrgnUpdate
|| rcUpdate
)
265 HRGN32 hrgn
= (hrgnUpdate
) ? hrgnUpdate
: CreateRectRgn32( 0,0,0,0 );
269 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgnScrollClip
, RGN_AND
);
270 OffsetRgn32( hrgn
, dx
, dy
);
271 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgn
, RGN_DIFF
);
272 CombineRgn32( hrgn
, hrgn
, hrgnScrollClip
, RGN_AND
);
278 rect
= rDClip
; /* vertical band */
279 if (dx
> 0) rect
.right
= rect
.left
+ dx
;
280 else if (dx
< 0) rect
.left
= rect
.right
+ dx
;
281 else SetRectEmpty32( &rect
);
282 SetRectRgn32( hrgn
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
284 rect
= rDClip
; /* horizontal band */
285 if (dy
> 0) rect
.bottom
= rect
.top
+ dy
;
286 else if (dy
< 0) rect
.top
= rect
.bottom
+ dy
;
287 else SetRectEmpty32( &rect
);
289 REGION_UnionRectWithRgn( hrgn
, &rect
);
292 if (rcUpdate
) GetRgnBox32( hrgn
, rcUpdate
);
293 if (!hrgnUpdate
) DeleteObject32( hrgn
);
296 DeleteObject32( hrgnScrollClip
);
297 GDI_HEAP_UNLOCK( hdc
);
302 /*************************************************************************
303 * ScrollWindowEx16 (USER.319)
305 INT16 WINAPI
ScrollWindowEx16( HWND16 hwnd
, INT16 dx
, INT16 dy
,
306 const RECT16
*rect
, const RECT16
*clipRect
,
307 HRGN16 hrgnUpdate
, LPRECT16 rcUpdate
,
310 RECT32 rect32
, clipRect32
, rcUpdate32
;
313 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
314 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
315 ret
= ScrollWindowEx32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
316 clipRect
? &clipRect32
: NULL
, hrgnUpdate
,
317 (rcUpdate
) ? &rcUpdate32
: NULL
, flags
);
318 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
322 /*************************************************************************
325 static BOOL32
SCROLL_FixCaret(HWND32 hWnd
, LPRECT32 lprc
, UINT32 flags
)
327 HWND32 hCaret
= CARET_GetHwnd();
332 CARET_GetRect( &rc
);
333 if( hCaret
== hWnd
||
334 (flags
& SW_SCROLLCHILDREN
&& IsChild32(hWnd
, hCaret
)) )
338 pt
.x
= rc
.left
; pt
.y
= rc
.top
;
339 MapWindowPoints32( hCaret
, hWnd
, (LPPOINT32
)&rc
, 2 );
340 if( IntersectRect32(lprc
, lprc
, &rc
) )
343 lprc
->left
= pt
.x
; lprc
->top
= pt
.y
;
351 /*************************************************************************
352 * ScrollWindowEx32 (USER32.451)
354 * NOTE: Use this function instead of ScrollWindow32
356 INT32 WINAPI
ScrollWindowEx32( HWND32 hwnd
, INT32 dx
, INT32 dy
,
357 const RECT32
*rect
, const RECT32
*clipRect
,
358 HRGN32 hrgnUpdate
, LPRECT32 rcUpdate
,
361 INT32 retVal
= NULLREGION
;
362 BOOL32 bCaret
= FALSE
, bOwnRgn
= TRUE
;
364 WND
* wnd
= WIN_FindWndPtr( hwnd
);
366 if( !wnd
|| !WIN_IsWindowDrawable( wnd
, TRUE
)) return ERROR
;
368 if (rect
== NULL
) GetClientRect32(hwnd
, &rc
);
371 if (clipRect
) IntersectRect32(&cliprc
,&rc
,clipRect
);
374 if (!IsRectEmpty32(&cliprc
) && (dx
|| dy
))
378 BOOL32 bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
379 HRGN32 hrgnClip
= CreateRectRgnIndirect32(&cliprc
);
381 TRACE(scroll
,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
382 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
383 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
384 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
385 rect
?rect
->left
:0, rect
?rect
->top
:0, rect
?rect
->right
:0, rect
?rect
->bottom
:0, (UINT16
)flags
);
388 bCaret
= SCROLL_FixCaret(hwnd
, &rc
, flags
);
390 if( hrgnUpdate
) bOwnRgn
= FALSE
;
391 else if( bUpdate
) hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
393 hDC
= GetDCEx32( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
394 ((flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0) );
395 if( (dc
= (DC
*)GDI_GetObjPtr(hDC
, DC_MAGIC
)) )
399 if( dx
> 0 ) dst
.x
= (src
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) + dx
;
400 else src
.x
= (dst
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) - dx
;
402 if( dy
> 0 ) dst
.y
= (src
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) + dy
;
403 else src
.y
= (dst
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) - dy
;
405 if( bUpdate
) /* handles non-Wine windows hanging over the scrolled area */
406 TSXSetGraphicsExposures( display
, dc
->u
.x
.gc
, True
);
408 TSXSetFunction( display
, dc
->u
.x
.gc
, GXcopy
);
409 TSXCopyArea( display
, dc
->u
.x
.drawable
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
410 src
.x
, src
.y
, cliprc
.right
- cliprc
.left
- abs(dx
),
411 cliprc
.bottom
- cliprc
.top
- abs(dy
), dst
.x
, dst
.y
);
414 TSXSetGraphicsExposures( display
, dc
->u
.x
.gc
, False
);
416 if( dc
->w
.hVisRgn
&& bUpdate
)
418 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnClip
, RGN_AND
);
419 OffsetRgn32( hrgnUpdate
, dx
, dy
);
420 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnUpdate
, RGN_DIFF
);
421 CombineRgn32( hrgnUpdate
, hrgnUpdate
, hrgnClip
, RGN_AND
);
423 if( rcUpdate
) GetRgnBox32( hrgnUpdate
, rcUpdate
);
425 ReleaseDC32(hwnd
, hDC
);
426 GDI_HEAP_UNLOCK( hDC
);
429 if( wnd
->hrgnUpdate
> 1 )
431 if( rect
|| clipRect
)
433 if( (CombineRgn32( hrgnClip
, hrgnClip
,
434 wnd
->hrgnUpdate
, RGN_AND
) != NULLREGION
) )
436 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_DIFF
);
437 OffsetRgn32( hrgnClip
, dx
, dy
);
438 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_OR
);
442 OffsetRgn32( wnd
->hrgnUpdate
, dx
, dy
);
445 if( flags
& SW_SCROLLCHILDREN
)
449 for( w
= wnd
->child
; w
; w
= w
->next
)
451 CONV_RECT16TO32( &w
->rectWindow
, &r
);
452 if( !clipRect
|| IntersectRect32(&r
, &r
, &cliprc
) )
453 SetWindowPos32(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
454 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
455 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
460 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
461 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
462 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) | ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ), 0 );
466 SetCaretPos32( rc
.left
+ dx
, rc
.top
+ dy
);
470 if( bOwnRgn
&& hrgnUpdate
) DeleteObject32( hrgnUpdate
);
471 DeleteObject32( hrgnClip
);