Fix prototypes of MSVCRT___getmainargs and MSVCRT___wgetmainargs.
[wine.git] / windows / scroll.c
blobdc05ffa63312c1a0f3aebdf44cef39a20eec8e9e
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
8 */
10 #include <stdlib.h>
12 #include "windef.h"
13 #include "wingdi.h"
14 #include "wine/winuser16.h"
15 #include "winuser.h"
16 #include "win.h"
17 #include "gdi.h"
18 #include "dce.h"
19 #include "region.h"
20 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(scroll);
24 /*************************************************************************
25 * ScrollWindow (USER.61)
27 void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
28 const RECT16 *clipRect )
30 RECT rect32, clipRect32;
32 if (rect) CONV_RECT16TO32( rect, &rect32 );
33 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
34 ScrollWindow( hwnd, dx, dy, rect ? &rect32 : NULL,
35 clipRect ? &clipRect32 : NULL );
38 /*************************************************************************
39 * ScrollWindow (USER32.@)
42 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
43 const RECT *rect, const RECT *clipRect )
45 return
46 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
47 (rect ? 0 : SW_SCROLLCHILDREN) |
48 SW_INVALIDATE ));
51 /*************************************************************************
52 * ScrollDC (USER.221)
54 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
55 const RECT16 *cliprc, HRGN16 hrgnUpdate,
56 LPRECT16 rcUpdate )
58 RECT rect32, clipRect32, rcUpdate32;
59 BOOL16 ret;
61 if (rect) CONV_RECT16TO32( rect, &rect32 );
62 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
63 ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL,
64 cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 );
65 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
66 return ret;
70 /*************************************************************************
71 * ScrollDC (USER32.@)
73 * Only the hrgnUpdate is return in device coordinate.
74 * rcUpdate must be returned in logical coordinate to comply with win API.
77 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
78 const RECT *prLClip, HRGN hrgnUpdate,
79 LPRECT rcUpdate )
81 RECT rect, rClip, rSrc;
82 POINT src, dest;
83 DC *dc = DC_GetDCUpdate( hdc );
85 TRACE("%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
86 (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate,
87 prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
88 rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
90 if ( !dc || !hdc ) return FALSE;
93 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
94 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
95 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
96 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
99 /* compute device clipping region (in device coordinates) */
101 if ( rc )
102 rect = *rc;
103 else /* maybe we should just return FALSE? */
104 GetClipBox( hdc, &rect );
106 LPtoDP( hdc, (LPPOINT)&rect, 2 );
108 if (prLClip)
110 rClip = *prLClip;
111 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
112 IntersectRect( &rClip, &rect, &rClip );
114 else
115 rClip = rect;
117 dx = XLPTODP ( dc, rect.left + dx ) - XLPTODP ( dc, rect.left );
118 dy = YLPTODP ( dc, rect.top + dy ) - YLPTODP ( dc, rect.top );
120 rSrc = rClip;
121 OffsetRect( &rSrc, -dx, -dy );
122 IntersectRect( &rSrc, &rSrc, &rect );
124 if(dc->hVisRgn)
126 if (!IsRectEmpty(&rSrc))
128 dest.x = (src.x = rSrc.left) + dx;
129 dest.y = (src.y = rSrc.top) + dy;
131 /* copy bits */
133 DPtoLP( hdc, (LPPOINT)&rSrc, 2 );
134 DPtoLP( hdc, &src, 1 );
135 DPtoLP( hdc, &dest, 1 );
137 if (!BitBlt( hdc, dest.x, dest.y,
138 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
139 hdc, src.x, src.y, SRCCOPY))
141 GDI_ReleaseObj( hdc );
142 return FALSE;
146 /* compute update areas */
148 if (hrgnUpdate || rcUpdate)
150 HRGN hrgn =
151 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
152 HRGN hrgn2;
154 hrgn2 = CreateRectRgnIndirect( &rect );
155 OffsetRgn( hrgn2, dc->DCOrgX, dc->DCOrgY );
156 CombineRgn( hrgn2, hrgn2, dc->hVisRgn, RGN_AND );
157 OffsetRgn( hrgn2, -dc->DCOrgX, -dc->DCOrgY );
158 SetRectRgn( hrgn, rClip.left, rClip.top,
159 rClip.right, rClip.bottom );
160 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
161 OffsetRgn( hrgn2, dx, dy );
162 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
164 if( rcUpdate )
166 GetRgnBox( hrgn, rcUpdate );
168 /* Put the rcUpdate in logical coordinate */
169 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
171 if (!hrgnUpdate) DeleteObject( hrgn );
172 DeleteObject( hrgn2 );
176 else
178 if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
179 if (rcUpdate) SetRectEmpty(rcUpdate);
182 GDI_ReleaseObj( hdc );
183 return TRUE;
187 /*************************************************************************
188 * ScrollWindowEx (USER.319)
190 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
191 const RECT16 *rect, const RECT16 *clipRect,
192 HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
193 UINT16 flags )
195 RECT rect32, clipRect32, rcUpdate32;
196 BOOL16 ret;
198 if (rect) CONV_RECT16TO32( rect, &rect32 );
199 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
200 ret = ScrollWindowEx( hwnd, dx, dy, rect ? &rect32 : NULL,
201 clipRect ? &clipRect32 : NULL, hrgnUpdate,
202 (rcUpdate) ? &rcUpdate32 : NULL, flags );
203 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
204 return ret;
207 /*************************************************************************
208 * SCROLL_FixCaret
210 static BOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags)
212 HWND hCaret = CARET_GetHwnd();
214 if( hCaret )
216 RECT rc;
217 CARET_GetRect( &rc );
218 if( hCaret == hWnd ||
219 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
221 POINT pt;
223 pt.x = rc.left; pt.y = rc.top;
224 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
225 if( IntersectRect(lprc, lprc, &rc) )
227 HideCaret(0);
228 lprc->left = pt.x; lprc->top = pt.y;
229 return TRUE;
233 return FALSE;
236 /*************************************************************************
237 * ScrollWindowEx (USER32.@)
239 * NOTE: Use this function instead of ScrollWindow32
241 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
242 const RECT *rect, const RECT *clipRect,
243 HRGN hrgnUpdate, LPRECT rcUpdate,
244 UINT flags )
246 INT retVal = NULLREGION;
247 BOOL bCaret = FALSE, bOwnRgn = TRUE;
248 RECT rc, cliprc;
249 WND* wnd = WIN_FindWndPtr( hwnd );
251 if( !wnd || !WIN_IsWindowDrawable( wnd, TRUE ))
253 retVal = ERROR;
254 goto END;
257 GetClientRect(hwnd, &rc);
258 if (rect) IntersectRect(&rc, &rc, rect);
260 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
261 else cliprc = rc;
263 if (!IsRectEmpty(&cliprc) && (dx || dy))
265 HDC hDC;
266 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
267 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
268 HRGN hrgnTemp = CreateRectRgnIndirect(&rc);
269 RECT caretrc;
271 TRACE("%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
272 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
273 (HWND16)hwnd, dx, dy, hrgnUpdate, rcUpdate,
274 clipRect?clipRect->left:0, clipRect?clipRect->top:0, clipRect?clipRect->right:0, clipRect?clipRect->bottom:0,
275 rc.left, rc.top, rc.right, rc.bottom, (UINT16)flags );
277 caretrc = rc;
278 bCaret = SCROLL_FixCaret(hwnd, &caretrc, flags);
280 if( hrgnUpdate ) bOwnRgn = FALSE;
281 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
283 hDC = GetDCEx( hwnd, hrgnClip, DCX_CACHE | DCX_USESTYLE |
284 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
285 ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
286 if (hDC)
288 wnd->pDriver->pSurfaceCopy(wnd,hDC,dx,dy,&rc,bUpdate);
289 if( bUpdate )
291 DC* dc;
293 if( (dc = DC_GetDCPtr(hDC)) )
295 OffsetRgn( hrgnTemp, dc->DCOrgX, dc->DCOrgY );
296 CombineRgn( hrgnTemp, hrgnTemp, dc->hVisRgn,
297 RGN_AND );
298 OffsetRgn( hrgnTemp, -dc->DCOrgX, -dc->DCOrgY );
299 CombineRgn( hrgnUpdate, hrgnTemp, hrgnClip,
300 RGN_AND );
301 OffsetRgn( hrgnTemp, dx, dy );
302 retVal =
303 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp,
304 RGN_DIFF );
306 if( rcUpdate ) GetRgnBox( hrgnUpdate, rcUpdate );
307 GDI_ReleaseObj( hDC );
310 ReleaseDC(hwnd, hDC);
313 if( wnd->hrgnUpdate > 1 )
315 /* Takes into account the fact that some damages may have
316 occured during the scroll. */
317 CombineRgn( hrgnTemp, wnd->hrgnUpdate, 0, RGN_COPY );
318 OffsetRgn( hrgnTemp, dx, dy );
319 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
320 CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate, hrgnTemp, RGN_OR );
323 if( flags & SW_SCROLLCHILDREN )
325 RECT r;
326 WND* w;
327 for( w =WIN_LockWndPtr(wnd->child); w; WIN_UpdateWndPtr(&w, w->next))
329 r = w->rectWindow;
330 if( !rect || IntersectRect(&r, &r, &rc) )
331 SetWindowPos(w->hwndSelf, 0, w->rectWindow.left + dx,
332 w->rectWindow.top + dy, 0,0, SWP_NOZORDER |
333 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
334 SWP_DEFERERASE );
338 if( flags & (SW_INVALIDATE | SW_ERASE) )
339 PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
340 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
342 if( bCaret )
344 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
345 ShowCaret(0);
348 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
349 DeleteObject( hrgnClip );
350 DeleteObject( hrgnTemp );
352 END:
353 WIN_ReleaseWndPtr(wnd);
354 return retVal;