Implemented VK_PRIOR and VK_NEXT processing (merged from Corel tree).
[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  * TODO
7  *     - actually add smooth scrolling
8  */
9
10 #include "winbase.h"
11 #include "winreg.h"
12 #include "winerror.h"
13 #include "commctrl.h"
14 #include "debugtools.h"
15
16 DEFAULT_DEBUG_CHANNEL(commctrl);
17
18 static DWORD    smoothscroll = 2;
19
20 typedef BOOL (CALLBACK *SCROLLWINDOWEXPROC)(HWND,INT,INT,LPRECT,LPRECT,HRGN,LPRECT,DWORD);
21 typedef struct tagSMOOTHSCROLLSTRUCT {
22         DWORD                   dwSize;
23         DWORD                   x2;
24         HWND                    hwnd;
25         DWORD                   dx;
26
27         DWORD                   dy;
28         LPRECT                  lpscrollrect;
29         LPRECT                  lpcliprect;
30         HRGN                    hrgnupdate;
31
32         LPRECT                  lpupdaterect;
33         DWORD                   flags;
34         DWORD                   stepinterval;
35         DWORD                   dx_step;
36
37         DWORD                   dy_step;
38         SCROLLWINDOWEXPROC      scrollfun;      /* same parameters as ScrollWindowEx */
39 } SMOOTHSCROLLSTRUCT;
40
41 /**************************************************************************
42  * SmoothScrollWindow [COMCTL32.382]
43  *
44  * Lots of magic for smooth scrolling windows.
45  *
46  * Currently only scrolls ONCE. The comctl32 implementation uses GetTickCount
47  * and what else to do smooth scrolling.
48  */
49
50 BOOL WINAPI SmoothScrollWindow( SMOOTHSCROLLSTRUCT *smooth ) {
51    LPRECT       lpupdaterect = smooth->lpupdaterect;
52    HRGN         hrgnupdate = smooth->hrgnupdate;
53    RECT         tmprect;
54    BOOL         ret = TRUE;
55    DWORD        flags = smooth->flags;
56
57    if (smooth->dwSize!=sizeof(SMOOTHSCROLLSTRUCT))
58        return FALSE;
59
60    if (!lpupdaterect)
61        lpupdaterect = &tmprect;
62    SetRectEmpty(lpupdaterect);
63
64    if (!(flags & 0x40000)) { /* no override, use system wide defaults */
65        if (smoothscroll == 2) {
66            HKEY hkey;
67
68            smoothscroll = 0;
69            if (!RegOpenKeyA(HKEY_CURRENT_USER,"Control Panel\\Desktop",&hkey)) {
70                DWORD    len = 4;
71
72                RegQueryValueExA(hkey,"SmoothScroll",0,0,(LPBYTE)&smoothscroll,&len);
73                RegCloseKey(hkey);
74            }
75        }
76        if (!smoothscroll)
77            flags |= 0x20000;
78    }
79
80    if (flags & 0x20000) { /* are we doing jump scrolling? */
81        if ((smooth->x2 & 1) && smooth->scrollfun)
82            return smooth->scrollfun(
83                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
84                smooth->lpcliprect,hrgnupdate,lpupdaterect,
85                flags & 0xffff
86            );
87        else
88            return ScrollWindowEx(
89                smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
90                smooth->lpcliprect,hrgnupdate,lpupdaterect,
91                flags & 0xffff
92            );
93    }
94
95    FIXME("(hwnd=%x,flags=%lx,x2=%lx): should smooth scroll here.\n",
96            smooth->hwnd,flags,smooth->x2
97    );
98    /* FIXME: do timer based smooth scrolling */
99    if ((smooth->x2 & 1) && smooth->scrollfun)
100        return smooth->scrollfun(
101            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
102            smooth->lpcliprect,hrgnupdate,lpupdaterect,
103            flags & 0xffff
104        );
105    else
106        return ScrollWindowEx(
107            smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect,
108            smooth->lpcliprect,hrgnupdate,lpupdaterect,
109            flags & 0xffff
110        );
111    return ret;
112 }