Now works around wine never exiting the debugger.
[wine/dcerpc.git] / windows / scroll.c
blob86868bb05f7ea0f9e0d1d849064c4f5f2f0e25d9
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
8 */
10 #include <stdlib.h>
12 #include "wine/winuser16.h"
13 #include "winuser.h"
14 #include "dc.h"
15 #include "win.h"
16 #include "gdi.h"
17 #include "dce.h"
18 #include "region.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(scroll)
23 /*************************************************************************
24 * ScrollWindow16 (USER.61)
26 void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
27 const RECT16 *clipRect )
29 RECT rect32, clipRect32;
31 if (rect) CONV_RECT16TO32( rect, &rect32 );
32 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
33 ScrollWindow( hwnd, dx, dy, rect ? &rect32 : NULL,
34 clipRect ? &clipRect32 : NULL );
37 /*************************************************************************
38 * ScrollWindow32 (USER32.450)
41 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
42 const RECT *rect, const RECT *clipRect )
44 return
45 (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
46 (rect ? 0 : SW_SCROLLCHILDREN) |
47 SW_INVALIDATE ));
50 /*************************************************************************
51 * ScrollDC16 (USER.221)
53 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
54 const RECT16 *cliprc, HRGN16 hrgnUpdate,
55 LPRECT16 rcUpdate )
57 RECT rect32, clipRect32, rcUpdate32;
58 BOOL16 ret;
60 if (rect) CONV_RECT16TO32( rect, &rect32 );
61 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
62 ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL,
63 cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 );
64 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
65 return ret;
69 /*************************************************************************
70 * ScrollDC32 (USER32.449)
72 * Only the hrgnUpdate is return in device coordinate.
73 * rcUpdate must be returned in logical coordinate to comply with win API.
76 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
77 const RECT *prLClip, HRGN hrgnUpdate,
78 LPRECT rcUpdate )
80 RECT rect, rClip, rSrc;
81 POINT src, dest;
82 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
84 TRACE("%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
85 (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate,
86 prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
87 rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
89 if ( !dc || !hdc ) return FALSE;
92 TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
93 dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
94 TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
95 dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
98 /* compute device clipping region */
100 if ( rc )
101 rect = *rc;
102 else /* maybe we should just return FALSE? */
103 GetClipBox( hdc, &rect );
105 if (prLClip)
106 IntersectRect( &rClip,&rect,prLClip );
107 else
108 rClip = rect;
110 rSrc = rClip;
111 OffsetRect( &rSrc, -dx, -dy );
112 IntersectRect( &rSrc, &rSrc, &rect );
114 if(dc->w.hVisRgn)
116 if (!IsRectEmpty(&rSrc))
118 dest.x = (src.x = rSrc.left) + dx;
119 dest.y = (src.y = rSrc.top) + dy;
121 /* copy bits */
123 if (!BitBlt( hdc, dest.x, dest.y,
124 rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
125 hdc, src.x, src.y, SRCCOPY))
127 GDI_HEAP_UNLOCK( hdc );
128 return FALSE;
132 /* compute update areas */
134 if (hrgnUpdate || rcUpdate)
136 HRGN hrgn =
137 (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
138 HRGN hrgn2;
140 dx = XLPTODP ( dc, rect.left + dx) - XLPTODP ( dc, rect.left);
141 dy = YLPTODP ( dc, rect.top + dy) - YLPTODP ( dc, rect.top);
142 LPtoDP( hdc, (LPPOINT)&rect, 2 );
143 LPtoDP( hdc, (LPPOINT)&rClip, 2 );
144 hrgn2 = CreateRectRgnIndirect( &rect );
145 OffsetRgn( hrgn2, dc->w.DCOrgX, dc->w.DCOrgY );
146 CombineRgn( hrgn2, hrgn2, dc->w.hVisRgn, RGN_AND );
147 OffsetRgn( hrgn2, -dc->w.DCOrgX, -dc->w.DCOrgY );
148 SetRectRgn( hrgn, rClip.left, rClip.top,
149 rClip.right, rClip.bottom );
150 CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
151 OffsetRgn( hrgn2, dx, dy );
152 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
154 if( rcUpdate )
156 GetRgnBox( hrgn, rcUpdate );
158 /* Put the rcUpdate in logical coordinate */
159 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
161 if (!hrgnUpdate) DeleteObject( hrgn );
162 DeleteObject( hrgn2 );
166 else
168 if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
169 if (rcUpdate) SetRectEmpty(rcUpdate);
172 GDI_HEAP_UNLOCK( hdc );
173 return TRUE;
177 /*************************************************************************
178 * ScrollWindowEx16 (USER.319)
180 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
181 const RECT16 *rect, const RECT16 *clipRect,
182 HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
183 UINT16 flags )
185 RECT rect32, clipRect32, rcUpdate32;
186 BOOL16 ret;
188 if (rect) CONV_RECT16TO32( rect, &rect32 );
189 if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
190 ret = ScrollWindowEx( hwnd, dx, dy, rect ? &rect32 : NULL,
191 clipRect ? &clipRect32 : NULL, hrgnUpdate,
192 (rcUpdate) ? &rcUpdate32 : NULL, flags );
193 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
194 return ret;
197 /*************************************************************************
198 * SCROLL_FixCaret
200 static BOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags)
202 HWND hCaret = CARET_GetHwnd();
204 if( hCaret )
206 RECT rc;
207 CARET_GetRect( &rc );
208 if( hCaret == hWnd ||
209 (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) )
211 POINT pt;
213 pt.x = rc.left; pt.y = rc.top;
214 MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 );
215 if( IntersectRect(lprc, lprc, &rc) )
217 HideCaret(0);
218 lprc->left = pt.x; lprc->top = pt.y;
219 return TRUE;
223 return FALSE;
226 /*************************************************************************
227 * ScrollWindowEx32 (USER32.451)
229 * NOTE: Use this function instead of ScrollWindow32
231 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
232 const RECT *rect, const RECT *clipRect,
233 HRGN hrgnUpdate, LPRECT rcUpdate,
234 UINT flags )
236 INT retVal = NULLREGION;
237 BOOL bCaret = FALSE, bOwnRgn = TRUE;
238 RECT rc, cliprc;
239 WND* wnd = WIN_FindWndPtr( hwnd );
241 if( !wnd || !WIN_IsWindowDrawable( wnd, TRUE ))
243 retVal = ERROR;
244 goto END;
247 GetClientRect(hwnd, &rc);
248 if (rect) IntersectRect(&rc, &rc, rect);
250 if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
251 else cliprc = rc;
253 if (!IsRectEmpty(&cliprc) && (dx || dy))
255 DC* dc;
256 HDC hDC;
257 BOOL bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
258 HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
259 HRGN hrgnTemp = CreateRectRgnIndirect(&rc);
260 RECT caretrc;
262 TRACE("%04x, %d,%d hrgnUpdate=%04x rcUpdate = %p \
263 cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d) %04x\n",
264 (HWND16)hwnd, dx, dy, hrgnUpdate, rcUpdate,
265 clipRect?clipRect->left:0, clipRect?clipRect->top:0, clipRect?clipRect->right:0, clipRect?clipRect->bottom:0,
266 rc.left, rc.top, rc.right, rc.bottom, (UINT16)flags );
268 caretrc = rc;
269 bCaret = SCROLL_FixCaret(hwnd, &caretrc, flags);
271 if( hrgnUpdate ) bOwnRgn = FALSE;
272 else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
274 hDC = GetDCEx( hwnd, hrgnClip, DCX_CACHE | DCX_USESTYLE |
275 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
276 ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
277 if( (dc = (DC *)GDI_GetObjPtr(hDC, DC_MAGIC)) )
279 if (dc->w.hVisRgn) {
280 wnd->pDriver->pSurfaceCopy(wnd,dc,dx,dy,&rc,bUpdate);
282 if( bUpdate )
284 OffsetRgn( hrgnTemp, dc->w.DCOrgX, dc->w.DCOrgY );
285 CombineRgn( hrgnTemp, hrgnTemp, dc->w.hVisRgn,
286 RGN_AND );
287 OffsetRgn( hrgnTemp, -dc->w.DCOrgX, -dc->w.DCOrgY );
288 CombineRgn( hrgnUpdate, hrgnTemp, hrgnClip,
289 RGN_AND );
290 OffsetRgn( hrgnTemp, dx, dy );
291 retVal =
292 CombineRgn( hrgnUpdate, hrgnUpdate, hrgnTemp,
293 RGN_DIFF );
295 if( rcUpdate ) GetRgnBox( hrgnUpdate, rcUpdate );
298 ReleaseDC(hwnd, hDC);
299 GDI_HEAP_UNLOCK( hDC );
302 if( wnd->hrgnUpdate > 1 )
304 /* Takes into account the fact that some damages may have
305 occured during the scroll. */
306 CombineRgn( hrgnTemp, wnd->hrgnUpdate, 0, RGN_COPY );
307 OffsetRgn( hrgnTemp, dx, dy );
308 CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
309 CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate, hrgnTemp, RGN_OR );
312 if( flags & SW_SCROLLCHILDREN )
314 RECT r;
315 WND* w;
316 for( w =WIN_LockWndPtr(wnd->child); w; WIN_UpdateWndPtr(&w, w->next))
318 CONV_RECT16TO32( &w->rectWindow, &r );
319 if( IntersectRect(&r, &r, &rc) )
320 SetWindowPos(w->hwndSelf, 0, w->rectWindow.left + dx,
321 w->rectWindow.top + dy, 0,0, SWP_NOZORDER |
322 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
323 SWP_DEFERERASE );
327 if( flags & (SW_INVALIDATE | SW_ERASE) )
328 PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
329 ((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
331 if( bCaret )
333 SetCaretPos( caretrc.left + dx, caretrc.top + dy );
334 ShowCaret(0);
337 if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
338 DeleteObject( hrgnClip );
339 DeleteObject( hrgnTemp );
341 END:
342 WIN_ReleaseWndPtr(wnd);
343 return retVal;