There is no point making '--register' functions stdcall so just
[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 <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winerror.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "commctrl.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
37
38 static DWORD    smoothscroll = 2;
39
40 typedef BOOL (CALLBACK *SCROLLWINDOWEXPROC)(HWND,INT,INT,LPRECT,LPRECT,HRGN,LPRECT,DWORD);
41 typedef struct tagSMOOTHSCROLLSTRUCT {
42         DWORD                   dwSize;
43         DWORD                   x2;
44         HWND                    hwnd;
45         DWORD                   dx;
46
47         DWORD                   dy;
48         LPRECT                  lpscrollrect;
49         LPRECT                  lpcliprect;
50         HRGN                    hrgnupdate;
51
52         LPRECT                  lpupdaterect;
53         DWORD                   flags;
54         DWORD                   stepinterval;
55         DWORD                   dx_step;
56
57         DWORD                   dy_step;
58         SCROLLWINDOWEXPROC      scrollfun;      /* same parameters as ScrollWindowEx */
59 } SMOOTHSCROLLSTRUCT;
60
61 /**************************************************************************
62  * SmoothScrollWindow [COMCTL32.382]
63  *
64  * Lots of magic for smooth scrolling windows.
65  *
66  * RETURNS
67  *     Success: TRUE
68  *     Failure: FALSE
69  *
70  * BUGS
71  *     Currently only scrolls ONCE. The comctl32 implementation uses GetTickCount
72  *     and what else to do smooth scrolling.
73  */
74 BOOL WINAPI SmoothScrollWindow( SMOOTHSCROLLSTRUCT *smooth ) {
75    LPRECT       lpupdaterect = smooth->lpupdaterect;
76    HRGN         hrgnupdate = smooth->hrgnupdate;
77    RECT         tmprect;
78    BOOL         ret = TRUE;
79    DWORD        flags = smooth->flags;
80
81    if (smooth->dwSize!=sizeof(SMOOTHSCROLLSTRUCT))
82        return FALSE;
83
84    if (!lpupdaterect)
85        lpupdaterect = &tmprect;
86    SetRectEmpty(lpupdaterect);
87
88    if (!(flags & 0x40000)) { /* no override, use system wide defaults */
89        if (smoothscroll == 2) {
90            HKEY hkey;
91
92            smoothscroll = 0;
93            if (!RegOpenKeyA(HKEY_CURRENT_USER,"Control Panel\\Desktop",&hkey)) {
94                DWORD    len = 4;
95
96                RegQueryValueExA(hkey,"SmoothScroll",0,0,(LPBYTE)&smoothscroll,&len);
97                RegCloseKey(hkey);
98            }
99        }
100        if (!smoothscroll)
101            flags |= 0x20000;
102    }
103
104    if (flags & 0x20000) { /* are we doing jump scrolling? */
105        if ((smooth->x2 & 1) && smooth->scrollfun)
106            return smooth->scrollfun(
107                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
108                smooth->lpcliprect,hrgnupdate,lpupdaterect,
109                flags & 0xffff
110            );
111        else
112            return ScrollWindowEx(
113                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
114                smooth->lpcliprect,hrgnupdate,lpupdaterect,
115                flags & 0xffff
116            );
117    }
118
119    FIXME("(hwnd=%p,flags=%lx,x2=%lx): should smooth scroll here.\n",
120            smooth->hwnd,flags,smooth->x2
121    );
122    /* FIXME: do timer based smooth scrolling */
123    if ((smooth->x2 & 1) && smooth->scrollfun)
124        return smooth->scrollfun(
125            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
126            smooth->lpcliprect,hrgnupdate,lpupdaterect,
127            flags & 0xffff
128        );
129    else
130        return ScrollWindowEx(
131            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
132            smooth->lpcliprect,hrgnupdate,lpupdaterect,
133            flags & 0xffff
134        );
135    return ret;
136 }