2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
18 #include "sysmetrics.h"
22 extern HWND32
CARET_GetHwnd(); /* windows/caret.c */
23 extern void CARET_GetRect(LPRECT32
);
24 extern void CLIPPING_UpdateGCRegion(DC
* ); /* objects/clipping.c */
26 /*************************************************************************
27 * ScrollWindow16 (USER.61)
29 void ScrollWindow16( HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
30 const RECT16
*clipRect
)
32 RECT32 rect32
, clipRect32
;
34 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
35 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
36 ScrollWindow32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
37 clipRect
? &clipRect32
: NULL
);
40 /*************************************************************************
41 * ScrollWindow32 (USER32.449)
43 BOOL32
ScrollWindow32( HWND32 hwnd
, INT32 dx
, INT32 dy
, const RECT32
*rect
,
44 const RECT32
*clipRect
)
47 HRGN32 hrgnUpdate
,hrgnClip
;
49 HWND32 hCaretWnd
= CARET_GetHwnd();
50 WND
* wndScroll
= WIN_FindWndPtr( hwnd
);
52 dprintf_scroll(stddeb
,"ScrollWindow: hwnd=%04x, dx=%d, dy=%d, lpRect =%p clipRect=%i,%i,%i,%i\n",
54 clipRect
? clipRect
->left
: 0,
55 clipRect
? clipRect
->top
: 0,
56 clipRect
? clipRect
->right
: 0,
57 clipRect
? clipRect
->bottom
: 0 );
59 if ( !wndScroll
|| !WIN_IsWindowDrawable( wndScroll
, TRUE
) ) return TRUE
;
61 if ( !rect
) /* do not clip children */
63 GetClientRect32(hwnd
, &rc
);
64 hrgnClip
= CreateRectRgnIndirect32( &rc
);
66 if ((hCaretWnd
== hwnd
) || IsChild32(hwnd
,hCaretWnd
))
67 HideCaret32(hCaretWnd
);
70 hdc
= GetDCEx32(hwnd
, hrgnClip
, DCX_CACHE
| DCX_CLIPSIBLINGS
);
71 DeleteObject32( hrgnClip
);
73 else /* clip children */
75 CopyRect32(&rc
, rect
);
77 if (hCaretWnd
== hwnd
) HideCaret32(hCaretWnd
);
80 hdc
= GetDCEx32( hwnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
84 GetClientRect32(hwnd
, &cliprc
);
86 CopyRect32(&cliprc
, clipRect
);
88 hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
89 ScrollDC32( hdc
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, NULL
);
90 ReleaseDC32(hwnd
, hdc
);
92 if( !rect
) /* move child windows and update region */
96 if( wndScroll
->hrgnUpdate
> 1 )
97 OffsetRgn32( wndScroll
->hrgnUpdate
, dx
, dy
);
99 for (wndPtr
= wndScroll
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
100 SetWindowPos32(wndPtr
->hwndSelf
, 0, wndPtr
->rectWindow
.left
+ dx
,
101 wndPtr
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
102 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
106 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_ALLCHILDREN
|
107 RDW_INVALIDATE
| RDW_ERASE
| RDW_ERASENOW
, RDW_C_USEHRGN
);
109 DeleteObject32( hrgnUpdate
);
114 pt
.x
+= dx
; pt
.y
+= dy
;
115 SetCaretPos32(pt
.x
, pt
.y
);
116 ShowCaret32(hCaretWnd
);
122 /*************************************************************************
123 * ScrollDC16 (USER.221)
125 BOOL16
ScrollDC16( HDC16 hdc
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
126 const RECT16
*cliprc
, HRGN16 hrgnUpdate
, LPRECT16 rcUpdate
)
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.448)
143 * Both 'rc' and 'rLClip' are in logical units but update info is
144 * returned in device coordinates.
146 BOOL32
ScrollDC32( HDC32 hdc
, INT32 dx
, INT32 dy
, const RECT32
*rc
,
147 const RECT32
*prLClip
, HRGN32 hrgnUpdate
, LPRECT32 rcUpdate
)
149 RECT32 rDClip
, rLClip
;
151 HRGN32 hrgnScrollClip
= 0;
154 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
156 dprintf_scroll(stddeb
,"ScrollDC: %04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
157 (HDC16
)hdc
, dx
, dy
, hrgnUpdate
, rcUpdate
,
158 prLClip
? prLClip
->left
: 0, prLClip
? prLClip
->top
: 0, prLClip
? prLClip
->right
: 0, prLClip
? prLClip
->bottom
: 0,
159 rc
? rc
->left
: 0, rc
? rc
->top
: 0, rc
? rc
->right
: 0, rc
? rc
->bottom
: 0 );
161 if ( !dc
|| !hdc
) return FALSE
;
164 printf(stddeb,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
165 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
166 printf(stddeb,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
167 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
170 /* compute device clipping region */
175 rDClip
.left
= XLPTODP(dc
, rc
->left
); rDClip
.right
= XLPTODP(dc
, rc
->right
);
176 rDClip
.top
= YLPTODP(dc
, rc
->top
); rDClip
.bottom
= YLPTODP(dc
, rc
->bottom
);
178 else /* maybe we should just return FALSE? */
180 GetClipBox32( hdc
, &rDClip
);
181 rLClip
.left
= XDPTOLP(dc
, rDClip
.left
); rLClip
.right
= XDPTOLP(dc
, rDClip
.right
);
182 rLClip
.top
= YDPTOLP(dc
, rDClip
.top
); rLClip
.bottom
= YDPTOLP(dc
, rDClip
.bottom
);
189 r
.left
= XLPTODP(dc
, prLClip
->left
); r
.right
= XLPTODP(dc
, prLClip
->right
);
190 r
.top
= YLPTODP(dc
, prLClip
->top
); r
.bottom
= YLPTODP(dc
, prLClip
->bottom
);
191 IntersectRect32(&rLClip
,&rLClip
,prLClip
);
192 IntersectRect32(&rDClip
,&rDClip
,&r
);
195 if( rDClip
.left
>= rDClip
.right
|| rDClip
.top
>= rDClip
.bottom
)
198 hrgnClip
= GetClipRgn16(hdc
);
199 hrgnScrollClip
= CreateRectRgnIndirect32(&rDClip
);
203 /* change device clipping region directly */
205 CombineRgn32( hrgnScrollClip
, hrgnClip
, 0, RGN_COPY
);
206 SetRectRgn32( hrgnClip
, rDClip
.left
, rDClip
.top
,
207 rDClip
.right
, rDClip
.bottom
);
209 CLIPPING_UpdateGCRegion( dc
);
212 SelectClipRgn32( hdc
, hrgnScrollClip
);
214 /* translate coordinates */
216 ldx
= dx
* dc
->wndExtX
/ dc
->vportExtX
;
217 ldy
= dy
* dc
->wndExtY
/ dc
->vportExtY
;
220 dest
.x
= (src
.x
= rLClip
.left
) + ldx
;
222 src
.x
= (dest
.x
= rLClip
.left
) - ldx
;
225 dest
.y
= (src
.y
= rLClip
.top
) + ldy
;
227 src
.y
= (dest
.y
= rLClip
.top
) - ldy
;
231 if( rDClip
.right
- rDClip
.left
> dx
&&
232 rDClip
.bottom
- rDClip
.top
> dy
)
234 ldx
= rLClip
.right
- rLClip
.left
- ldx
;
235 ldy
= rLClip
.bottom
- rLClip
.top
- ldy
;
237 if (!BitBlt32( hdc
, dest
.x
, dest
.y
, ldx
, ldy
,
238 hdc
, src
.x
, src
.y
, SRCCOPY
))
242 /* restore clipping region */
246 CombineRgn32( hrgnClip
, hrgnScrollClip
, 0, RGN_COPY
);
247 CLIPPING_UpdateGCRegion( dc
);
248 SetRectRgn32( hrgnScrollClip
, rDClip
.left
, rDClip
.top
,
249 rDClip
.right
, rDClip
.bottom
);
252 SelectClipRgn32( hdc
, 0 );
254 /* compute update areas */
256 if (hrgnUpdate
|| rcUpdate
)
258 HRGN32 hrgn
= (hrgnUpdate
) ? hrgnUpdate
: CreateRectRgn32( 0,0,0,0 );
262 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgnScrollClip
, RGN_AND
);
263 OffsetRgn32( hrgn
, dx
, dy
);
264 CombineRgn32( hrgn
, dc
->w
.hVisRgn
, hrgn
, RGN_DIFF
);
265 CombineRgn32( hrgn
, hrgn
, hrgnScrollClip
, RGN_AND
);
271 rect
= rDClip
; /* vertical band */
272 if (dx
> 0) rect
.right
= rect
.left
+ dx
;
273 else if (dx
< 0) rect
.left
= rect
.right
+ dx
;
274 else SetRectEmpty32( &rect
);
275 SetRectRgn32( hrgn
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
277 rect
= rDClip
; /* horizontal band */
278 if (dy
> 0) rect
.bottom
= rect
.top
+ dy
;
279 else if (dy
< 0) rect
.top
= rect
.bottom
+ dy
;
280 else SetRectEmpty32( &rect
);
282 REGION_UnionRectWithRgn( hrgn
, &rect
);
285 if (rcUpdate
) GetRgnBox32( hrgn
, rcUpdate
);
286 if (!hrgnUpdate
) DeleteObject32( hrgn
);
289 DeleteObject32( hrgnScrollClip
);
294 /*************************************************************************
295 * ScrollWindowEx16 (USER.319)
297 INT16
ScrollWindowEx16( HWND16 hwnd
, INT16 dx
, INT16 dy
, const RECT16
*rect
,
298 const RECT16
*clipRect
, HRGN16 hrgnUpdate
,
299 LPRECT16 rcUpdate
, UINT16 flags
)
301 RECT32 rect32
, clipRect32
, rcUpdate32
;
304 if (rect
) CONV_RECT16TO32( rect
, &rect32
);
305 if (clipRect
) CONV_RECT16TO32( clipRect
, &clipRect32
);
306 ret
= ScrollWindowEx32( hwnd
, dx
, dy
, rect
? &rect32
: NULL
,
307 clipRect
? &clipRect32
: NULL
, hrgnUpdate
,
308 (rcUpdate
) ? &rcUpdate32
: NULL
, flags
);
309 if (rcUpdate
) CONV_RECT32TO16( &rcUpdate32
, rcUpdate
);
313 /*************************************************************************
316 BOOL32
SCROLL_FixCaret(HWND32 hWnd
, LPRECT32 lprc
, UINT32 flags
)
318 HWND32 hCaret
= CARET_GetHwnd();
323 CARET_GetRect( &rc
);
324 if( hCaret
== hWnd
||
325 (flags
& SW_SCROLLCHILDREN
&& IsChild32(hWnd
, hCaret
)) )
329 pt
.x
= rc
.left
; pt
.y
= rc
.top
;
330 MapWindowPoints32( hCaret
, hWnd
, (LPPOINT32
)&rc
, 2 );
331 if( IntersectRect32(lprc
, lprc
, &rc
) )
334 lprc
->left
= pt
.x
; lprc
->top
= pt
.y
;
342 /*************************************************************************
343 * ScrollWindowEx32 (USER32.450)
345 INT32
ScrollWindowEx32( HWND32 hwnd
, INT32 dx
, INT32 dy
, const RECT32
*rect
,
346 const RECT32
*clipRect
, HRGN32 hrgnUpdate
,
347 LPRECT32 rcUpdate
, UINT32 flags
)
349 INT32 retVal
= NULLREGION
;
350 BOOL32 bCaret
= FALSE
, bOwnRgn
= TRUE
;
352 WND
* wnd
= WIN_FindWndPtr( hwnd
);
354 if( !wnd
|| !WIN_IsWindowDrawable( wnd
, TRUE
)) return ERROR
;
356 if (rect
== NULL
) GetClientRect32(hwnd
, &rc
);
359 if (clipRect
) IntersectRect32(&cliprc
,&rc
,clipRect
);
362 if (!IsRectEmpty32(&cliprc
) && (dx
|| dy
))
366 BOOL32 bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
367 HRGN32 hrgnClip
= CreateRectRgnIndirect32(&cliprc
);
369 dprintf_scroll(stddeb
,"ScrollWindowEx: %04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
370 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
371 (HWND16
)hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
,
372 clipRect
?clipRect
->left
:0, clipRect
?clipRect
->top
:0, clipRect
?clipRect
->right
:0, clipRect
?clipRect
->bottom
:0,
373 rect
?rect
->left
:0, rect
?rect
->top
:0, rect
?rect
->right
:0, rect
?rect
->bottom
:0, (UINT16
)flags
);
376 bCaret
= SCROLL_FixCaret(hwnd
, &rc
, flags
);
378 if( hrgnUpdate
) bOwnRgn
= FALSE
;
379 else if( bUpdate
) hrgnUpdate
= CreateRectRgn32( 0, 0, 0, 0 );
381 hDC
= GetDCEx32( hwnd
, hrgnClip
, DCX_CACHE
| DCX_USESTYLE
|
382 (flags
& SW_SCROLLCHILDREN
) ? DCX_NOCLIPCHILDREN
: 0 );
383 if( (dc
= (DC
*)GDI_GetObjPtr(hDC
, DC_MAGIC
)) )
387 if( dx
> 0 ) dst
.x
= (src
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) + dx
;
388 else src
.x
= (dst
.x
= dc
->w
.DCOrgX
+ cliprc
.left
) - dx
;
390 if( dy
> 0 ) dst
.y
= (src
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) + dy
;
391 else src
.y
= (dst
.y
= dc
->w
.DCOrgY
+ cliprc
.top
) - dy
;
394 XSetGraphicsExposures( display
, dc
->u
.x
.gc
, True
);
395 XSetFunction( display
, dc
->u
.x
.gc
, GXcopy
);
396 XCopyArea( display
, dc
->u
.x
.drawable
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
397 src
.x
, src
.y
, cliprc
.right
- cliprc
.left
- abs(dx
),
398 cliprc
.bottom
- cliprc
.top
- abs(dy
), dst
.x
, dst
.y
);
400 XSetGraphicsExposures( display
, dc
->u
.x
.gc
, False
);
402 if( dc
->w
.hVisRgn
&& bUpdate
)
404 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnClip
, RGN_AND
);
405 OffsetRgn32( hrgnUpdate
, dx
, dy
);
406 CombineRgn32( hrgnUpdate
, dc
->w
.hVisRgn
, hrgnUpdate
, RGN_DIFF
);
407 CombineRgn32( hrgnUpdate
, hrgnUpdate
, hrgnClip
, RGN_AND
);
409 if( rcUpdate
) GetRgnBox32( hrgnUpdate
, rcUpdate
);
411 ReleaseDC32(hwnd
, hDC
);
414 if( wnd
->hrgnUpdate
> 1 )
416 if( rect
|| clipRect
)
418 if( (CombineRgn32( hrgnClip
, hrgnClip
,
419 wnd
->hrgnUpdate
, RGN_AND
) != NULLREGION
) )
421 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_DIFF
);
422 OffsetRgn32( hrgnClip
, dx
, dy
);
423 CombineRgn32( wnd
->hrgnUpdate
, wnd
->hrgnUpdate
, hrgnClip
, RGN_OR
);
427 OffsetRgn32( wnd
->hrgnUpdate
, dx
, dy
);
430 if( flags
& SW_SCROLLCHILDREN
)
434 for( w
= wnd
->child
; w
; w
= w
->next
)
436 CONV_RECT16TO32( &w
->rectWindow
, &r
);
437 if( IntersectRect32(&r
, &r
, &cliprc
) )
438 SetWindowPos32(w
->hwndSelf
, 0, w
->rectWindow
.left
+ dx
,
439 w
->rectWindow
.top
+ dy
, 0,0, SWP_NOZORDER
|
440 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOREDRAW
|
445 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
446 PAINT_RedrawWindow( hwnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
447 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0), 0 );
451 SetCaretPos32( rc
.left
+ dx
, rc
.top
+ dy
);
455 if( bOwnRgn
&& hrgnUpdate
) DeleteObject32( hrgnUpdate
);
456 DeleteObject32( hrgnClip
);