Fixed RtlSetEnvironmentVariable to deal properly with Unicode strings
[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 #include <X11/Xlib.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32
33 #include "x11drv.h"
34 #include "win.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
38
39
40 /*************************************************************************
41  *              ScrollWindowEx   (X11DRV.@)
42  *
43  * Note: contrary to what the doc says, pixels that are scrolled from the
44  *      outside of clipRect to the inside are NOT painted.
45  *
46  * Parameter are the same as in ScrollWindowEx, with the additional
47  * requirement that rect and clipRect are _valid_ pointers, to
48  * rectangles _within_ the client are. Moreover, there is something
49  * to scroll.
50  */
51 INT X11DRV_ScrollWindowEx( HWND hwnd, INT dx, INT dy,
52                            const RECT *rect, const RECT *clipRect,
53                            HRGN hrgnUpdate, LPRECT rcUpdate, UINT flags )
54 {
55     INT   retVal;
56     BOOL  bOwnRgn = TRUE;
57     BOOL  bUpdate = (rcUpdate || hrgnUpdate || flags & (SW_INVALIDATE | SW_ERASE));
58     HRGN  hrgnTemp;
59     HDC   hDC;
60     RECT  rc, cliprc;
61
62     TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
63            hwnd, dx, dy, hrgnUpdate, rcUpdate, wine_dbgstr_rect(rect), flags );
64     TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect));
65
66     GetClientRect(hwnd, &rc);
67     if (rect) IntersectRect(&rc, &rc, rect);
68
69     if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
70     else cliprc = rc;
71
72     if( hrgnUpdate ) bOwnRgn = FALSE;
73     else if( bUpdate ) hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 );
74
75     hDC = GetDCEx( hwnd, 0, DCX_CACHE | DCX_USESTYLE );
76     if (hDC)
77     {
78         enum x11drv_escape_codes code = X11DRV_START_EXPOSURES;
79         HRGN hrgn = 0;
80
81         ExtEscape( hDC, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
82         ScrollDC( hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate );
83         code = X11DRV_END_EXPOSURES;
84         ExtEscape( hDC, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(hrgn), (LPSTR)&hrgn );
85         ReleaseDC( hwnd, hDC );
86         if (hrgn)
87         {
88             if (bUpdate) CombineRgn( hrgnUpdate, hrgnUpdate, hrgn, RGN_OR );
89             else RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
90             DeleteObject( hrgn );
91         }
92     }
93
94     /* Take into account the fact that some damage may have occurred during the scroll */
95     hrgnTemp = CreateRectRgn( 0, 0, 0, 0 );
96     retVal = GetUpdateRgn( hwnd, hrgnTemp, FALSE );
97     if (retVal != NULLREGION)
98     {
99         HRGN hrgnClip = CreateRectRgnIndirect(&cliprc);
100         OffsetRgn( hrgnTemp, dx, dy );
101         CombineRgn( hrgnTemp, hrgnTemp, hrgnClip, RGN_AND );
102         RedrawWindow( hwnd, NULL, hrgnTemp, RDW_INVALIDATE | RDW_ERASE );
103         DeleteObject( hrgnClip );
104     }
105     DeleteObject( hrgnTemp );
106
107     if( flags & SW_SCROLLCHILDREN )
108     {
109         HWND *list = WIN_ListChildren( hwnd );
110         if (list)
111         {
112             int i;
113             RECT r, dummy;
114             for (i = 0; list[i]; i++)
115             {
116                 GetWindowRect( list[i], &r );
117                 MapWindowPoints( 0, hwnd, (POINT *)&r, 2 );
118                 if (!rect || IntersectRect(&dummy, &r, &rc))
119                     SetWindowPos( list[i], 0, r.left + dx, r.top  + dy, 0, 0,
120                                   SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
121                                   SWP_NOREDRAW | SWP_DEFERERASE );
122             }
123             HeapFree( GetProcessHeap(), 0, list );
124         }
125     }
126
127     if( flags & (SW_INVALIDATE | SW_ERASE) )
128         RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
129                       ((flags & SW_ERASE) ? RDW_ERASENOW : 0) |
130                       ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
131
132     if( bOwnRgn && hrgnUpdate ) DeleteObject( hrgnUpdate );
133     
134     return retVal;
135 }