Moved ScrollWindowEx implementation to the graphics driver.
[wine] / windows / scroll.c
1 /*
2  * Scroll windows and DCs
3  *
4  * Copyright  David W. Metcalfe, 1993
5  *            Alex Korobka       1995,1996
6  *
7  *
8  */
9
10 #include <stdlib.h>
11
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 "user.h"
21 #include "debugtools.h"
22
23 DEFAULT_DEBUG_CHANNEL(scroll);
24
25 /*************************************************************************
26  *              ScrollWindow (USER.61)
27  */
28 void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
29                            const RECT16 *clipRect )
30 {
31     RECT rect32, clipRect32;
32
33     if (rect) CONV_RECT16TO32( rect, &rect32 );
34     if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
35     ScrollWindow( hwnd, dx, dy, rect ? &rect32 : NULL,
36                     clipRect ? &clipRect32 : NULL );
37 }
38
39 /*************************************************************************
40  *              ScrollWindow (USER32.@)
41  *
42  */
43 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
44                               const RECT *rect, const RECT *clipRect )
45 {
46     return
47         (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
48                                     (rect ? 0 : SW_SCROLLCHILDREN) |
49                                     SW_INVALIDATE ));
50 }
51
52 /*************************************************************************
53  *              ScrollDC (USER.221)
54  */
55 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
56                           const RECT16 *cliprc, HRGN16 hrgnUpdate,
57                           LPRECT16 rcUpdate )
58 {
59     RECT rect32, clipRect32, rcUpdate32;
60     BOOL16 ret;
61
62     if (rect) CONV_RECT16TO32( rect, &rect32 );
63     if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
64     ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL,
65                       cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 );
66     if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
67     return ret;
68 }
69
70
71 /*************************************************************************
72  *              ScrollDC (USER32.@)
73  * 
74  *   Only the hrgnUpdate is return in device coordinate.
75  *   rcUpdate must be returned in logical coordinate to comply with win API.
76  *
77  */
78 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
79                           const RECT *prLClip, HRGN hrgnUpdate,
80                           LPRECT rcUpdate )
81 {
82     RECT rect, rClip, rSrc;
83     POINT src, dest;
84     DC *dc = DC_GetDCUpdate( hdc );
85
86     TRACE("%04x %d,%d hrgnUpdate=%04x rcUpdate = %p cliprc = (%d,%d-%d,%d), rc=(%d,%d-%d,%d)\n",
87                    (HDC16)hdc, dx, dy, hrgnUpdate, rcUpdate, 
88                    prLClip ? prLClip->left : 0, prLClip ? prLClip->top : 0, prLClip ? prLClip->right : 0, prLClip ? prLClip->bottom : 0,
89                    rc ? rc->left : 0, rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
90
91     if ( !dc || !hdc ) return FALSE;
92
93 /*
94     TRACE(scroll,"\t[wndOrgX=%i, wndExtX=%i, vportOrgX=%i, vportExtX=%i]\n",
95           dc->wndOrgX, dc->wndExtX, dc->vportOrgX, dc->vportExtX );
96     TRACE(scroll,"\t[wndOrgY=%i, wndExtY=%i, vportOrgY=%i, vportExtY=%i]\n",
97           dc->wndOrgY, dc->wndExtY, dc->vportOrgY, dc->vportExtY );
98 */
99
100     /* compute device clipping region (in device coordinates) */
101
102     if ( rc )
103         rect = *rc;
104     else /* maybe we should just return FALSE? */
105         GetClipBox( hdc, &rect );
106
107     LPtoDP( hdc, (LPPOINT)&rect, 2 );
108
109     if (prLClip)
110     {
111         rClip = *prLClip;
112         LPtoDP( hdc, (LPPOINT)&rClip, 2 );
113         IntersectRect( &rClip, &rect, &rClip );
114     }
115     else
116         rClip = rect;
117
118     dx = XLPTODP ( dc, rect.left + dx ) - XLPTODP ( dc, rect.left );
119     dy = YLPTODP ( dc, rect.top + dy ) - YLPTODP ( dc, rect.top );
120
121     rSrc = rClip;
122     OffsetRect( &rSrc, -dx, -dy );
123     IntersectRect( &rSrc, &rSrc, &rect );
124
125     if(dc->hVisRgn)
126     {
127         if (!IsRectEmpty(&rSrc))
128         {
129             dest.x = (src.x = rSrc.left) + dx;
130             dest.y = (src.y = rSrc.top) + dy;
131
132             /* copy bits */
133     
134             DPtoLP( hdc, (LPPOINT)&rSrc, 2 );
135             DPtoLP( hdc, &src, 1 );
136             DPtoLP( hdc, &dest, 1 );
137
138             if (!BitBlt( hdc, dest.x, dest.y,
139                            rSrc.right - rSrc.left, rSrc.bottom - rSrc.top,
140                            hdc, src.x, src.y, SRCCOPY))
141             {
142                 GDI_ReleaseObj( hdc );
143                 return FALSE;
144             }
145         }
146
147         /* compute update areas */
148
149         if (hrgnUpdate || rcUpdate)
150         {
151             HRGN hrgn =
152               (hrgnUpdate) ? hrgnUpdate : CreateRectRgn( 0,0,0,0 );
153             HRGN hrgn2;
154
155             hrgn2 = CreateRectRgnIndirect( &rect );
156             OffsetRgn( hrgn2, dc->DCOrgX, dc->DCOrgY );
157             CombineRgn( hrgn2, hrgn2, dc->hVisRgn, RGN_AND );
158             OffsetRgn( hrgn2, -dc->DCOrgX, -dc->DCOrgY );
159             SetRectRgn( hrgn, rClip.left, rClip.top,
160                           rClip.right, rClip.bottom );
161             CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
162             OffsetRgn( hrgn2, dx, dy );
163             CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
164
165             if( rcUpdate )
166             {
167                 GetRgnBox( hrgn, rcUpdate );
168
169                 /* Put the rcUpdate in logical coordinate */
170                 DPtoLP( hdc, (LPPOINT)rcUpdate, 2 );
171             }
172             if (!hrgnUpdate) DeleteObject( hrgn );
173             DeleteObject( hrgn2 );
174
175         }
176     }
177     else
178     {
179        if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
180        if (rcUpdate) SetRectEmpty(rcUpdate);
181     }
182
183     GDI_ReleaseObj( hdc );
184     return TRUE;
185 }
186
187
188 /*************************************************************************
189  *              ScrollWindowEx (USER.319)
190  */
191 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
192                                const RECT16 *rect, const RECT16 *clipRect,
193                                HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
194                                UINT16 flags )
195 {
196     RECT rect32, clipRect32, rcUpdate32;
197     BOOL16 ret;
198
199     if (rect) CONV_RECT16TO32( rect, &rect32 );
200     if (clipRect) CONV_RECT16TO32( clipRect, &clipRect32 );
201     ret = ScrollWindowEx( hwnd, dx, dy, rect ? &rect32 : NULL,
202                             clipRect ? &clipRect32 : NULL, hrgnUpdate,
203                             (rcUpdate) ? &rcUpdate32 : NULL, flags );
204     if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
205     return ret;
206 }
207
208
209 /*************************************************************************
210  *              ScrollWindowEx (USER32.@)
211  *
212  * NOTE: Use this function instead of ScrollWindow32
213  */
214 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
215                                const RECT *rect, const RECT *clipRect,
216                                HRGN hrgnUpdate, LPRECT rcUpdate,
217                                UINT flags )
218 {
219     if (USER_Driver.pScrollWindowEx)
220         return USER_Driver.pScrollWindowEx( hwnd, dx, dy, rect, clipRect,
221                                             hrgnUpdate, rcUpdate, flags );
222     return ERROR;
223 }