If using the default values, also set dwType to REG_SZ as our default
[wine] / dlls / x11drv / scroll.c
1 /*
2  * Scroll windows and DCs
3  *
4  * Copyright 1993  David W. Metcalfe
5  * Copyright 1995, 1996 Alex Korobka
6  * Copyright 2001 Alexandre Julliard
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26
27 #include "ts_xlib.h"
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33
34 #include "x11drv.h"
35 #include "win.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
39
40
41 /*************************************************************************
42  *              ScrollDC   (X11DRV.@)
43  *
44  * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is wrong)
45  * hrgnUpdate is returned in device coordinates with rcUpdate in logical coordinates.
46  *
47  */
48 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll,
49                       const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate )
50 {
51     RECT rSrc, rClipped_src, rClip, rDst, offset;
52
53     TRACE( "%p %d,%d hrgnUpdate=%p lprcUpdate = %p\n", hdc, dx, dy, hrgnUpdate, lprcUpdate );
54     if (lprcClip) TRACE( "lprcClip = %s\n", wine_dbgstr_rect(lprcClip));
55     if (lprcScroll) TRACE( "lprcScroll = %s\n", wine_dbgstr_rect(lprcScroll));
56
57     /* compute device clipping region (in device coordinates) */
58
59     if (lprcScroll) rSrc = *lprcScroll;
60     else GetClipBox( hdc, &rSrc );
61     LPtoDP(hdc, (LPPOINT)&rSrc, 2);
62
63     if (lprcClip) rClip = *lprcClip;
64     else GetClipBox( hdc, &rClip );
65     LPtoDP(hdc, (LPPOINT)&rClip, 2);
66
67     IntersectRect( &rClipped_src, &rSrc, &rClip );
68     TRACE("rSrc %s rClip %s clipped rSrc %s\n", wine_dbgstr_rect(&rSrc),
69           wine_dbgstr_rect(&rClip), wine_dbgstr_rect(&rClipped_src));
70
71     rDst = rClipped_src;
72     SetRect(&offset, 0, 0, dx, dy);
73     LPtoDP(hdc, (LPPOINT)&offset, 2);
74     OffsetRect( &rDst, offset.right - offset.left,  offset.bottom - offset.top );
75     TRACE("rDst before clipping %s\n", wine_dbgstr_rect(&rDst));
76     IntersectRect( &rDst, &rDst, &rClip );
77     TRACE("rDst after clipping %s\n", wine_dbgstr_rect(&rDst));
78
79     if (!IsRectEmpty(&rDst))
80     {
81         /* copy bits */
82         RECT rDst_lp = rDst, rSrc_lp = rDst;
83
84         OffsetRect( &rSrc_lp, offset.left - offset.right, offset.top - offset.bottom );
85         DPtoLP(hdc, (LPPOINT)&rDst_lp, 2);
86         DPtoLP(hdc, (LPPOINT)&rSrc_lp, 2);
87
88         if (!BitBlt( hdc, rDst_lp.left, rDst_lp.top,
89                      rDst_lp.right - rDst_lp.left, rDst_lp.bottom - rDst_lp.top,
90                      hdc, rSrc_lp.left, rSrc_lp.top, SRCCOPY))
91             return FALSE;
92     }
93
94     /* compute update areas.  This is the clipped source or'ed with the unclipped source translated minus the
95      clipped src translated (rDst) all clipped to rClip */
96
97     if (hrgnUpdate || lprcUpdate)
98     {
99         HRGN hrgn = hrgnUpdate, hrgn2;
100
101         if (hrgn) SetRectRgn( hrgn, rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
102         else hrgn = CreateRectRgn( rClipped_src.left, rClipped_src.top, rClipped_src.right, rClipped_src.bottom );
103
104         hrgn2 = CreateRectRgnIndirect( &rSrc );
105         OffsetRgn(hrgn2, offset.right - offset.left,  offset.bottom - offset.top );
106         CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
107
108         SetRectRgn( hrgn2, rDst.left, rDst.top, rDst.right, rDst.bottom );
109         CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
110         
111         SetRectRgn( hrgn2, rClip.left, rClip.top, rClip.right, rClip.bottom );
112         CombineRgn( hrgn, hrgn, hrgn2, RGN_AND );
113
114         if( lprcUpdate )
115         {
116             GetRgnBox( hrgn, lprcUpdate );
117
118             /* Put the lprcUpdate in logical coordinate */
119             DPtoLP( hdc, (LPPOINT)lprcUpdate, 2 );
120             TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate));
121         }
122         if (!hrgnUpdate) DeleteObject( hrgn );
123         DeleteObject( hrgn2 );
124     }
125     return TRUE;
126 }
127
128
129 /*************************************************************************
130  *              ScrollWindowEx   (X11DRV.@)
131  *
132  * Note: contrary to what the doc says, pixels that are scrolled from the
133  *      outside of clipRect to the inside are NOT painted.
134  *
135  * Parameter are the same as in ScrollWindowEx, with the additional
136  * requirement that rect and clipRect are _valid_ pointers, to
137  * rectangles _within_ the client are. Moreover, there is something
138  * to scroll.
139  */
140 INT X11DRV_ScrollWindowEx( HWND hwnd, INT dx, INT dy,
141                            const RECT *rect, const RECT *clipRect,
142                            HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
143 {
144     INT   retVal;
145     BOOL  bOwnRgn = TRUE;
146     BOOL  bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
147     HRGN  hrgnTemp;
148     HDC   hDC;
149     RECT  rc, cliprc;
150
151     TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
152            hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
153     TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
154
155     GetClientRect(hwnd, &rc);
156     if (rect) IntersectRect(&rc, &rc, rect);
157
158     if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
159     else cliprc = rc;
160
161     if( hrgnUpdate ) bOwnRgn = FALSE;
162     else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
163
164     hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
165     if (hDC)
166     {
167         HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
168         X11DRV_StartGraphicsExposures( hDC );
169         X11DRV_ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
170         X11DRV_EndGraphicsExposures( hDC, hrgn );
171         ReleaseDC( hwnd, hDC );
172         if (bUpdate) CombineRgn( hrgnUpdate, hrgnUpdate, hrgn, RGN_OR );
173         else RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
174         DeleteObject( hrgn );
175     }
176
177     /* Take into account the fact that some damage may have occurred during the scroll */
178     hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
179     retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
180     if (retVal != NULLREGION)
181     {
182         HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
183         OffsetRgn( hrgnTemp, dx, dy );
184         CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
185         RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
186         DeleteObject( hrgnClip );
187     }
188     DeleteObject( hrgnTemp );
189
190     if( flags & SW_SCROLLCHILDREN )
191     {
192         HWND *list = WIN_ListChildren( hwnd );
193         if (list)
194         {
195             int i;
196             RECT r, dummy;
197             for (i = 0; list[i]; i++)
198             {
199                 GetWindowRect( list[i], &r );
200                 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
201                 if (!rect || IntersectRect(&dummy, &r, &rc))
202                     SetWindowPos( list[i], 0, r.left + dx, r.top  + dy, 0, 0,
203                                   SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
204                                   SWP_NOREDRAW | SWP_DEFERERASE );
205             }
206             HeapFree( GetProcessHeap(), 0, list );
207         }
208     }
209
210     if( flags & (SW_INVALIDATE | SW_ERASE) )
211         RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
212                       ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
213                       ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
214
215     if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
216     
217     return retVal;
218 }