- support DirectInput 8 interfaces.
[wine] / dlls / comctl32 / smoothscroll.c
1 /*
2  * Undocumented SmoothScrollWindow function from COMCTL32.DLL
3  *
4  * Copyright 2000 Marcus Meissner <marcus@jet.franken.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * TODO
21  *     - actually add smooth scrolling
22  */
23
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "winerror.h"
27 #include "commctrl.h"
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
31
32 static DWORD    smoothscroll = 2;
33
34 typedef BOOL (CALLBACK *SCROLLWINDOWEXPROC)(HWND,INT,INT,LPRECT,LPRECT,HRGN,LPRECT,DWORD);
35 typedef struct tagSMOOTHSCROLLSTRUCT {
36         DWORD                   dwSize;
37         DWORD                   x2;
38         HWND                    hwnd;
39         DWORD                   dx;
40
41         DWORD                   dy;
42         LPRECT                  lpscrollrect;
43         LPRECT                  lpcliprect;
44         HRGN                    hrgnupdate;
45
46         LPRECT                  lpupdaterect;
47         DWORD                   flags;
48         DWORD                   stepinterval;
49         DWORD                   dx_step;
50
51         DWORD                   dy_step;
52         SCROLLWINDOWEXPROC      scrollfun;      /* same parameters as ScrollWindowEx */
53 } SMOOTHSCROLLSTRUCT;
54
55 /**************************************************************************
56  * SmoothScrollWindow [COMCTL32.382]
57  *
58  * Lots of magic for smooth scrolling windows.
59  *
60  * Currently only scrolls ONCE. The comctl32 implementation uses GetTickCount
61  * and what else to do smooth scrolling.
62  */
63
64 BOOL WINAPI SmoothScrollWindow( SMOOTHSCROLLSTRUCT *smooth ) {
65    LPRECT       lpupdaterect = smooth->lpupdaterect;
66    HRGN         hrgnupdate = smooth->hrgnupdate;
67    RECT         tmprect;
68    BOOL         ret = TRUE;
69    DWORD        flags = smooth->flags;
70
71    if (smooth->dwSize!=sizeof(SMOOTHSCROLLSTRUCT))
72        return FALSE;
73
74    if (!lpupdaterect)
75        lpupdaterect = &tmprect;
76    SetRectEmpty(lpupdaterect);
77
78    if (!(flags & 0x40000)) { /* no override, use system wide defaults */
79        if (smoothscroll == 2) {
80            HKEY hkey;
81
82            smoothscroll = 0;
83            if (!RegOpenKeyA(HKEY_CURRENT_USER,"Control Panel\\Desktop",&hkey)) {
84                DWORD    len = 4;
85
86                RegQueryValueExA(hkey,"SmoothScroll",0,0,(LPBYTE)&smoothscroll,&len);
87                RegCloseKey(hkey);
88            }
89        }
90        if (!smoothscroll)
91            flags |= 0x20000;
92    }
93
94    if (flags & 0x20000) { /* are we doing jump scrolling? */
95        if ((smooth->x2 & 1) && smooth->scrollfun)
96            return smooth->scrollfun(
97                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
98                smooth->lpcliprect,hrgnupdate,lpupdaterect,
99                flags & 0xffff
100            );
101        else
102            return ScrollWindowEx(
103                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
104                smooth->lpcliprect,hrgnupdate,lpupdaterect,
105                flags & 0xffff
106            );
107    }
108
109    FIXME("(hwnd=%x,flags=%lx,x2=%lx): should smooth scroll here.\n",
110            smooth->hwnd,flags,smooth->x2
111    );
112    /* FIXME: do timer based smooth scrolling */
113    if ((smooth->x2 & 1) && smooth->scrollfun)
114        return smooth->scrollfun(
115            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
116            smooth->lpcliprect,hrgnupdate,lpupdaterect,
117            flags & 0xffff
118        );
119    else
120        return ScrollWindowEx(
121            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
122            smooth->lpcliprect,hrgnupdate,lpupdaterect,
123            flags & 0xffff
124        );
125    return ret;
126 }