2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
18 #include "sysmetrics.h"
21 extern HWND32
CARET_GetHwnd(); /* windows/caret.c */
22 extern void CARET_GetRect(LPRECT32
);
23 extern void CLIPPING_UpdateGCRegion(DC
* ); /* objects/clipping.c */
25 /*************************************************************************
26 * ScrollWindow16 (USER.61)
28 void WINAPI
ScrollWindow16(HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
29 const RECT16
*clipRect
)
31 RECT32 rect32
, clipRect32
;
33 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
34 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
35 ScrollWindow32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
36 clipRect
? &clipRect32
: NULL
);
39 /*************************************************************************
40 * ScrollWindow32 (USER32.449)
42 * FIXME: verify clipping region calculations
44 BOOL32 WINAPI
ScrollWindow32( HWND32 hwnd
, INT32 dx
, INT32 dy
,
45 const RECT32
*rect
, const RECT32
*clipRect
)
48 HRGN32 hrgnUpdate
,hrgnClip
;
50 HWND32 hCaretWnd
= CARET_GetHwnd();
51 WND
* wndScroll
= WIN_FindWndPtr( hwnd
);
53 TRACE(scroll
,"hwnd=%04x, dx=%d, dy=%d, lpRect =%p clipRect=%i,%i,%i,%i\n",
55 clipRect
? clipRect
->left
: 0,
56 clipRect
? clipRect
->top
: 0,
57 clipRect
? clipRect
->right
: 0,
58 clipRect
? clipRect
->bottom
: 0 );
60 if ( !wndScroll
|| !WIN_IsWindowDrawable( wndScroll
, TRUE
) ) return TRUE
;
62 if ( !rect
) /* do not clip children */
64 GetClientRect32(hwnd
, &rc
);
65 hrgnClip
= CreateRectRgnIndirect32( &rc
);
67 if ((hCaretWnd
== hwnd
) || IsChild32(hwnd
,hCaretWnd
))
68 HideCaret32(hCaretWnd
);
71 hdc
= GetDCEx32(hwnd
, hrgnClip
, DCX_CACHE
| DCX_CLIPSIBLINGS
);
72 DeleteObject32( hrgnClip
);
74 else /* clip children */
76 CopyRect32(&rc
, rect
);
78 if (hCaretWnd
== hwnd
) HideCaret32(hCaretWnd
);
81 hdc
= GetDCEx32( hwnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
85 GetClientRect32(hwnd
, &cliprc
);
87 CopyRect32(&cliprc
, clipRect
);
89 hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
90 ScrollDC32( hdc
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, NULL
);
91 ReleaseDC32(hwnd
, hdc
);
93 if( !rect
) /* move child windows and update region */
97 if( wndScroll
->hrgnUpdate
> 1 )
98 OffsetRgn32( wndScroll
->hrgnUpdate
, dx
, dy
);
100 for (wndPtr
= wndScroll
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
101 SetWindowPos32(wndPtr
->hwndSelf
, 0, wndPtr
->rectWindow
.left
+ dx
,
102 wndPtr
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
103 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
107 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_ALLCHILDREN
|
108 RDW_INVALIDATE
| RDW_ERASE
| RDW_ERASENOW
, RDW_C_USEHRGN
);
110 DeleteObject32( hrgnUpdate
);
115 pt
.x
+= dx
; pt
.y
+= dy
;
116 SetCaretPos32(pt
.x
, pt
.y
);
117 ShowCaret32(hCaretWnd
);
123 /*************************************************************************
124 * ScrollDC16 (USER.221)
126 BOOL16 WINAPI
ScrollDC16( HDC16 hdc
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
127 const RECT16
*cliprc
, HRGN16 hrgnUpdate
,
130 RECT32 rect32
, clipRect32
, rcUpdate32
;
133 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
134 if (cliprc
) CONV_RECT16TO32( cliprc
, &clipRect32
);
135 ret
= ScrollDC32( hdc
, dx
, dy
, rect
? &rect32
: NULL
,
136 cliprc
? &clipRect32
: NULL
, hrgnUpdate
, &rcUpdate32
);
137 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
142 /*************************************************************************
143 * ScrollDC32 (USER32.448)
145 * Both 'rc' and 'prLClip' are in logical units but update info is
146 * returned in device coordinates.
148 BOOL32 WINAPI
ScrollDC32( HDC32 hdc
, INT32 dx
, INT32 dy
, const RECT32
*rc
,
149 const RECT32
*prLClip
, HRGN32 hrgnUpdate
,
152 RECT32 rDClip
, rLClip
;
154 HRGN32 hrgnScrollClip
= 0;
157 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
159 TRACE(scroll
,"%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
160 (HDC16
)hdc
, dx
, dy
, hrgnUpdate
, rcUpdate
,
161 prLClip
? prLClip
->left
: 0, prLClip
? prLClip
->top
: 0, prLClip
? prLClip
->right
: 0, prLClip
? prLClip
->bottom
: 0,
162 rc
? rc
->left
: 0, rc
? rc
->top
: 0, rc
? rc
->right
: 0, rc
? rc
->bottom
: 0 );
164 if ( !dc
|| !hdc
) return FALSE
;
167 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
168 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
169 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
170 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
173 /* compute device clipping region */
178 rDClip
.left
= XLPTODP(dc
, rc
->left
); rDClip
.right
= XLPTODP(dc
, rc
->right
);
179 rDClip
.top
= YLPTODP(dc
, rc
->top
); rDClip
.bottom
= YLPTODP(dc
, rc
->bottom
);
181 else /* maybe we should just return FALSE? */
183 GetClipBox32( hdc
, &rDClip
);
184 rLClip
.left
= XDPTOLP(dc
, rDClip
.left
); rLClip
.right
= XDPTOLP(dc
, rDClip
.right
);
185 rLClip
.top
= YDPTOLP(dc
, rDClip
.top
); rLClip
.bottom
= YDPTOLP(dc
, rDClip
.bottom
);
192 r
.left
= XLPTODP(dc
, prLClip
->left
); r
.right
= XLPTODP(dc
, prLClip
->right
);
193 r
.top
= YLPTODP(dc
, prLClip
->top
); r
.bottom
= YLPTODP(dc
, prLClip
->bottom
);
194 IntersectRect32(&rLClip
,&rLClip
,prLClip
);
195 IntersectRect32(&rDClip
,&rDClip
,&r
);
198 if( rDClip
.left
>= rDClip
.right
|| rDClip
.top
>= rDClip
.bottom
)
201 hrgnClip
= GetClipRgn16(hdc
);
202 hrgnScrollClip
= CreateRectRgnIndirect32(&rDClip
);
206 /* change device clipping region directly */
208 CombineRgn32( hrgnScrollClip
, hrgnClip
, 0, RGN_COPY
);
209 SetRectRgn32( hrgnClip
, rDClip
.left
, rDClip
.top
,
210 rDClip
.right
, rDClip
.bottom
);
212 CLIPPING_UpdateGCRegion( dc
);
215 SelectClipRgn32( hdc
, hrgnScrollClip
);
217 /* translate coordinates */
219 ldx
= dx
* dc
->wndExtX
/ dc
->vportExtX
;
220 ldy
= dy
* dc
->wndExtY
/ dc
->vportExtY
;
223 dest
.x
= (src
.x
= rLClip
.left
) + ldx
;
225 src
.x
= (dest
.x
= rLClip
.left
) - ldx
;
228 dest
.y
= (src
.y
= rLClip
.top
) + ldy
;
230 src
.y
= (dest
.y
= rLClip
.top
) - ldy
;
234 if( rDClip
.right
- rDClip
.left
> dx
&&
235 rDClip
.bottom
- rDClip
.top
> dy
)
237 ldx
= rLClip
.right
- rLClip
.left
- ldx
;
238 ldy
= rLClip
.bottom
- rLClip
.top
- ldy
;
240 if (!BitBlt32( hdc
, dest
.x
, dest
.y
, ldx
, ldy
,
241 hdc
, src
.x
, src
.y
, SRCCOPY
))
245 /* restore clipping region */
249 CombineRgn32( hrgnClip
, hrgnScrollClip
, 0, RGN_COPY
);
250 CLIPPING_UpdateGCRegion( dc
);
251 SetRectRgn32( hrgnScrollClip
, rDClip
.left
, rDClip
.top
,
252 rDClip
.right
, rDClip
.bottom
);
255 SelectClipRgn32( hdc
, 0 );
257 /* compute update areas */
259 if (hrgnUpdate
|| rcUpdate
)
261 HRGN32 hrgn
= (hrgnUpdate
) ? hrgnUpdate
: CreateRectRgn32( 0,0,0,0 );
265 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgnScrollClip
, RGN_AND
);
266 OffsetRgn32( hrgn
, dx
, dy
);
267 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgn
, RGN_DIFF
);
268 CombineRgn32( hrgn
, hrgn
, hrgnScrollClip
, RGN_AND
);
274 rect
= rDClip
; /* vertical band */
275 if (dx
> 0) rect
.right
= rect
.left
+ dx
;
276 else if (dx
< 0) rect
.left
= rect
.right
+ dx
;
277 else SetRectEmpty32( &rect
);
278 SetRectRgn32( hrgn
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
280 rect
= rDClip
; /* horizontal band */
281 if (dy
> 0) rect
.bottom
= rect
.top
+ dy
;
282 else if (dy
< 0) rect
.top
= rect
.bottom
+ dy
;
283 else SetRectEmpty32( &rect
);
285 REGION_UnionRectWithRgn( hrgn
, &rect
);
288 if (rcUpdate
) GetRgnBox32( hrgn
, rcUpdate
);
289 if (!hrgnUpdate
) DeleteObject32( hrgn
);
292 DeleteObject32( hrgnScrollClip
);
297 /*************************************************************************
298 * ScrollWindowEx16 (USER.319)
300 INT16 WINAPI
ScrollWindowEx16( HWND16 hwnd
, INT16 dx
, INT16 dy
,
301 const RECT16
*rect
, const RECT16
*clipRect
,
302 HRGN16 hrgnUpdate
, LPRECT16 rcUpdate
,
305 RECT32 rect32
, clipRect32
, rcUpdate32
;
308 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
309 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
310 ret
= ScrollWindowEx32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
311 clipRect
? &clipRect32
: NULL
, hrgnUpdate
,
312 (rcUpdate
) ? &rcUpdate32
: NULL
, flags
);
313 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
317 /*************************************************************************
320 static BOOL32
SCROLL_FixCaret(HWND32 hWnd
, LPRECT32 lprc
, UINT32 flags
)
322 HWND32 hCaret
= CARET_GetHwnd();
327 CARET_GetRect( &rc
);
328 if( hCaret
== hWnd
||
329 (flags
& SW_SCROLLCHILDREN
&& IsChild32(hWnd
, hCaret
)) )
333 pt
.x
= rc
.left
; pt
.y
= rc
.top
;
334 MapWindowPoints32( hCaret
, hWnd
, (LPPOINT32
)&rc
, 2 );
335 if( IntersectRect32(lprc
, lprc
, &rc
) )
338 lprc
->left
= pt
.x
; lprc
->top
= pt
.y
;
346 /*************************************************************************
347 * ScrollWindowEx32 (USER32.450)
349 * NOTE: Use this function instead of ScrollWindow32
351 INT32 WINAPI
ScrollWindowEx32( HWND32 hwnd
, INT32 dx
, INT32 dy
,
352 const RECT32
*rect
, const RECT32
*clipRect
,
353 HRGN32 hrgnUpdate
, LPRECT32 rcUpdate
,
356 INT32 retVal
= NULLREGION
;
357 BOOL32 bCaret
= FALSE
, bOwnRgn
= TRUE
;
359 WND
* wnd
= WIN_FindWndPtr( hwnd
);
361 if( !wnd
|| !WIN_IsWindowDrawable( wnd
, TRUE
)) return ERROR
;
363 if (rect
== NULL
) GetClientRect32(hwnd
, &rc
);
366 if (clipRect
) IntersectRect32(&cliprc
,&rc
,clipRect
);
369 if (!IsRectEmpty32(&cliprc
) && (dx
|| dy
))
373 BOOL32 bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
374 HRGN32 hrgnClip
= CreateRectRgnIndirect32(&cliprc
);
376 TRACE(scroll
,"%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
377 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
378 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
379 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
380 rect
?rect
->left
:0, rect
?rect
->top
:0, rect
?rect
->right
:0, rect
?rect
->bottom
:0, (UINT16
)flags
);
383 bCaret
= SCROLL_FixCaret(hwnd
, &rc
, flags
);
385 if( hrgnUpdate
) bOwnRgn
= FALSE
;
386 else if( bUpdate
) hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
388 hDC
= GetDCEx32( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
389 ((flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0) );
390 if( (dc
= (DC
*)GDI_GetObjPtr(hDC
, DC_MAGIC
)) )
394 if( dx
> 0 ) dst
.x
= (src
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) + dx
;
395 else src
.x
= (dst
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) - dx
;
397 if( dy
> 0 ) dst
.y
= (src
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) + dy
;
398 else src
.y
= (dst
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) - dy
;
400 if( bUpdate
) /* handles non-Wine windows hanging over the scrolled area */
401 TSXSetGraphicsExposures( display
, dc
->u
.x
.gc
, True
);
403 TSXSetFunction( display
, dc
->u
.x
.gc
, GXcopy
);
404 TSXCopyArea( display
, dc
->u
.x
.drawable
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
405 src
.x
, src
.y
, cliprc
.right
- cliprc
.left
- abs(dx
),
406 cliprc
.bottom
- cliprc
.top
- abs(dy
), dst
.x
, dst
.y
);
409 TSXSetGraphicsExposures( display
, dc
->u
.x
.gc
, False
);
411 if( dc
->w
.hVisRgn
&& bUpdate
)
413 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnClip
, RGN_AND
);
414 OffsetRgn32( hrgnUpdate
, dx
, dy
);
415 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnUpdate
, RGN_DIFF
);
416 CombineRgn32( hrgnUpdate
, hrgnUpdate
, hrgnClip
, RGN_AND
);
418 if( rcUpdate
) GetRgnBox32( hrgnUpdate
, rcUpdate
);
420 ReleaseDC32(hwnd
, hDC
);
423 if( wnd
->hrgnUpdate
> 1 )
425 if( rect
|| clipRect
)
427 if( (CombineRgn32( hrgnClip
, hrgnClip
,
428 wnd
->hrgnUpdate
, RGN_AND
) != NULLREGION
) )
430 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_DIFF
);
431 OffsetRgn32( hrgnClip
, dx
, dy
);
432 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_OR
);
436 OffsetRgn32( wnd
->hrgnUpdate
, dx
, dy
);
439 if( flags
& SW_SCROLLCHILDREN
)
443 for( w
= wnd
->child
; w
; w
= w
->next
)
445 CONV_RECT16TO32( &w
->rectWindow
, &r
);
446 if( !clipRect
|| IntersectRect32(&r
, &r
, &cliprc
) )
447 SetWindowPos32(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
448 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
449 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
454 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
455 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
456 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) | ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ), 0 );
460 SetCaretPos32( rc
.left
+ dx
, rc
.top
+ dy
);
464 if( bOwnRgn
&& hrgnUpdate
) DeleteObject32( hrgnUpdate
);
465 DeleteObject32( hrgnClip
);