Fixed Makefile up-to-date check to avoid relinking all the object
[wine/wine-kai.git] / windows / scroll.c
blobc54b49de37e26fde4a8703b20fcfb11d703a36c8
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
8 */
10 #include <stdlib.h>
11 #include "winuser.h"
12 #include "class.h"
13 #include "dc.h"
14 #include "win.h"
15 #include "gdi.h"
16 #include "dce.h"
17 #include "region.h"
18 #include "sysmetrics.h"
19 #include "debug.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 )
42 return
43 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
44 (rect ? 0 : SW_SCROLLCHILDREN) |
45 SW_INVALIDATE ));
48 /*************************************************************************
49 * ScrollDC16 (USER.221)
51 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
52 const RECT16 *cliprc, HRGN16 hrgnUpdate,
53 LPRECT16 rcUpdate )
55 RECT rect32, clipRect32, rcUpdate32;
56 BOOL16 ret;
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 );
63 return ret;
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,
76 LPRECT rcUpdate )
78 RECT rect, rClip, rSrc;
79 POINT src, dest;
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 */
98 if ( rc )
99 rect = *rc;
100 else /* maybe we should just return FALSE? */
101 GetClipBox( hdc, &rect );
103 if (prLClip)
104 IntersectRect( &rClip,&rect,prLClip );
105 else
106 rClip = rect;
108 rSrc = rClip;
109 OffsetRect( &rSrc, -dx, -dy );
110 IntersectRect( &rSrc, &rSrc, &rect );
112 if(dc->w.hVisRgn)
114 if (!IsRectEmpty(&rSrc))
116 dest.x = (src.x = rSrc.left) + dx;
117 dest.y = (src.y = rSrc.top) + dy;
119 /* copy bits */
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 );
126 return FALSE;
130 /* compute update areas */
132 if (hrgnUpdate || rcUpdate)
134 HRGN hrgn =
135 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
136 HRGN hrgn2;
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 );
152 if( rcUpdate )
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 );
164 else
166 if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
167 if (rcUpdate) SetRectEmpty(rcUpdate);
170 GDI_HEAP_UNLOCK( hdc );
171 return TRUE;
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,
181 UINT16 flags )
183 RECT rect32, clipRect32, rcUpdate32;
184 BOOL16 ret;
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 );
192 return ret;
195 /*************************************************************************
196 * SCROLL_FixCaret
198 static BOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags)
200 HWND hCaret = CARET_GetHwnd();
202 if( hCaret )
204 RECT rc;
205 CARET_GetRect( &rc );
206 if( hCaret == hWnd ||
207 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
209 POINT pt;
211 pt.x = rc.left; pt.y = rc.top;
212 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
213 if( IntersectRect(lprc, lprc, &rc) )
215 HideCaret(0);
216 lprc->left = pt.x; lprc->top = pt.y;
217 return TRUE;
221 return FALSE;
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,
232 UINT flags )
234 INT retVal = NULLREGION;
235 BOOL bCaret = FALSE, bOwnRgn = TRUE;
236 RECT rc, cliprc;
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);
245 else cliprc = rc;
247 if (!IsRectEmpty(&cliprc) && (dx || dy))
249 DC* dc;
250 HDC hDC;
251 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
252 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
253 HRGN hrgnTemp = CreateRectRgnIndirect(&rc);
254 RECT caretrc;
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 );
262 caretrc = rc;
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)) )
273 if (dc->w.hVisRgn) {
274 wnd->pDriver->pScrollWindow(wnd,dc,dx,dy,&rc,bUpdate);
276 if( bUpdate )
278 OffsetRgn( hrgnTemp, dc->w.DCOrgX, dc->w.DCOrgY );
279 CombineRgn( hrgnTemp, hrgnTemp, dc->w.hVisRgn,
280 RGN_AND );
281 OffsetRgn( hrgnTemp, -dc->w.DCOrgX, -dc->w.DCOrgY );
282 CombineRgn( hrgnUpdate, hrgnTemp, hrgnClip,
283 RGN_AND );
284 OffsetRgn( hrgnTemp, dx, dy );
285 retVal =
286 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp,
287 RGN_DIFF );
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 )
308 RECT r;
309 WND* w;
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 |
317 SWP_DEFERERASE );
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 );
325 if( bCaret )
327 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
328 ShowCaret(0);
331 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
332 DeleteObject( hrgnClip );
333 DeleteObject( hrgnTemp );
335 return retVal;