- Factor out common text shifting logic.
[wine] / dlls / comctl32 / flatsb.c
1 /*
2  * Flat Scrollbar control
3  *
4  * Copyright 1998, 1999 Eric Kohl
5  * Copyright 1998 Alex Priem
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * NOTES
22  *   This is just a dummy control. An author is needed! Any volunteers?
23  *   I will only improve this control once in a while.
24  *     Eric <ekohl@abo.rhein-zeitung.de>
25  *
26  * TODO:
27  *   - All messages.
28  *   - All notifications.
29  *
30  */
31
32 #include <stdarg.h>
33 #include <string.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winuser.h"
38 #include "commctrl.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
42
43 typedef struct
44 {
45     DWORD dwDummy;  /* just to keep the compiler happy ;-) */
46 } FLATSB_INFO, *LPFLATSB_INFO;
47
48 #define FlatSB_GetInfoPtr(hwnd) ((FLATSB_INFO*)GetWindowLongPtrW (hwnd, 0))
49
50
51 /***********************************************************************
52  *              InitializeFlatSB (COMCTL32.@)
53  *
54  * Initializes flat scroll bars for the specified window.
55  *
56  * RETURNS
57  *     Success: Non-zero
58  *     Failure: Zero
59  *
60  * NOTES
61  *     Subclasses specified window so that flat scroll bars may be drawn
62  *     and used.
63  */
64 BOOL WINAPI InitializeFlatSB(HWND hwnd)
65 {
66     TRACE("[%p]\n", hwnd);
67     return FALSE;
68 }
69
70 /***********************************************************************
71  *              UninitializeFlatSB (COMCTL32.@)
72  *
73  * Uninitializes flat scroll bars for the specified window.
74  *
75  * RETURNS
76  *      E_FAIL          if one of the scroll bars is currently in use
77  *      S_FALSE         if InitializeFlatSB() was never called on this hwnd
78  *      S_OK            otherwise
79  *
80  * NOTES
81  *     Removes any subclassing on the specified window so that regular
82  *     scroll bars are drawn and used.
83  */
84 HRESULT WINAPI UninitializeFlatSB(HWND hwnd)
85 {
86     TRACE("[%p]\n", hwnd);
87     return S_FALSE;
88 }
89
90 /***********************************************************************
91  *              FlatSB_GetScrollProp (COMCTL32.@)
92  *
93  * Retrieves flat-scroll-bar-specific properties for the specified window.
94  *
95  * RETURNS
96  *     nonzero if successful, or zero otherwise. If index is WSB_PROP_HSTYLE,
97  *     the return is nonzero if InitializeFlatSB has been called for this window, or
98  *     zero otherwise.
99  */
100 BOOL WINAPI
101 FlatSB_GetScrollProp(HWND hwnd, INT propIndex, LPINT prop)
102 {
103     TRACE("[%p] propIndex=%d\n", hwnd, propIndex);
104     return FALSE;
105 }
106
107 /***********************************************************************
108  *              FlatSB_SetScrollProp (COMCTL32.@)
109  *
110  * Sets flat-scroll-bar-specific properties for the specified window.
111  *
112  * RETURNS
113  *     Success: Non-zero
114  *     Failure: Zero
115  */
116 BOOL WINAPI
117 FlatSB_SetScrollProp(HWND hwnd, UINT index, INT newValue, BOOL flag)
118 {
119     TRACE("[%p] index=%u newValue=%d flag=%d\n", hwnd, index, newValue, flag);
120     return FALSE;
121 }
122
123 /***********************************************************************
124  *      From the Microsoft docs:
125  *      "If flat scroll bars haven't been initialized for the
126  *      window, the flat scroll bar APIs will defer to the corresponding
127  *      standard APIs.  This allows the developer to turn flat scroll
128  *      bars on and off without having to write conditional code."
129  *
130  *      So, if we just call the standard functions until we implement
131  *      the flat scroll bar functions, flat scroll bars will show up and
132  *      behave properly, as though they had simply not been setup to
133  *      have flat properties.
134  *
135  *      Susan <sfarley@codeweavers.com>
136  *
137  */
138
139 /***********************************************************************
140  *              FlatSB_EnableScrollBar (COMCTL32.@)
141  *
142  * See EnableScrollBar.
143  */
144 BOOL WINAPI
145 FlatSB_EnableScrollBar(HWND hwnd, int nBar, UINT flags)
146 {
147     return EnableScrollBar(hwnd, nBar, flags);
148 }
149
150 /***********************************************************************
151  *              FlatSB_ShowScrollBar (COMCTL32.@)
152  *
153  * See ShowScrollBar.
154  */
155 BOOL WINAPI
156 FlatSB_ShowScrollBar(HWND hwnd, int nBar, BOOL fShow)
157 {
158     return ShowScrollBar(hwnd, nBar, fShow);
159 }
160
161 /***********************************************************************
162  *              FlatSB_GetScrollRange (COMCTL32.@)
163  *
164  * See GetScrollRange.
165  */
166 BOOL WINAPI
167 FlatSB_GetScrollRange(HWND hwnd, int nBar, LPINT min, LPINT max)
168 {
169     return GetScrollRange(hwnd, nBar, min, max);
170 }
171
172 /***********************************************************************
173  *              FlatSB_GetScrollInfo (COMCTL32.@)
174  *
175  * See GetScrollInfo.
176  */
177 BOOL WINAPI
178 FlatSB_GetScrollInfo(HWND hwnd, int nBar, LPSCROLLINFO info)
179 {
180     return GetScrollInfo(hwnd, nBar, info);
181 }
182
183 /***********************************************************************
184  *              FlatSB_GetScrollPos (COMCTL32.@)
185  *
186  * See GetScrollPos.
187  */
188 INT WINAPI
189 FlatSB_GetScrollPos(HWND hwnd, int nBar)
190 {
191     return GetScrollPos(hwnd, nBar);
192 }
193
194 /***********************************************************************
195  *              FlatSB_SetScrollPos (COMCTL32.@)
196  *
197  * See SetScrollPos.
198  */
199 INT WINAPI
200 FlatSB_SetScrollPos(HWND hwnd, int nBar, INT pos, BOOL bRedraw)
201 {
202     return SetScrollPos(hwnd, nBar, pos, bRedraw);
203 }
204
205 /***********************************************************************
206  *              FlatSB_SetScrollInfo (COMCTL32.@)
207  *
208  * See SetScrollInfo.
209  */
210 INT WINAPI
211 FlatSB_SetScrollInfo(HWND hwnd, int nBar, LPSCROLLINFO info, BOOL bRedraw)
212 {
213     return SetScrollInfo(hwnd, nBar, info, bRedraw);
214 }
215
216 /***********************************************************************
217  *              FlatSB_SetScrollRange (COMCTL32.@)
218  *
219  * See SetScrollRange.
220  */
221 INT WINAPI
222 FlatSB_SetScrollRange(HWND hwnd, int nBar, INT min, INT max, BOOL bRedraw)
223 {
224     return SetScrollRange(hwnd, nBar, min, max, bRedraw);
225 }
226
227
228 static LRESULT
229 FlatSB_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
230 {
231     TRACE("[%p] wParam=%04x lParam=%08lx\n", hwnd, wParam, lParam);
232     return 0;
233 }
234
235
236 static LRESULT
237 FlatSB_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
238 {
239     TRACE("[%p] wParam=%04x lParam=%08lx\n", hwnd, wParam, lParam);
240     return 0;
241 }
242
243
244 static LRESULT WINAPI
245 FlatSB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
246 {
247     if (!FlatSB_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
248         return DefWindowProcW( hwnd, uMsg, wParam, lParam );
249
250     switch (uMsg)
251     {
252         case WM_CREATE:
253             return FlatSB_Create (hwnd, wParam, lParam);
254
255         case WM_DESTROY:
256             return FlatSB_Destroy (hwnd, wParam, lParam);
257
258         default:
259             if ((uMsg >= WM_USER) && (uMsg < WM_APP))
260                 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
261                     uMsg, wParam, lParam);
262             return DefWindowProcW (hwnd, uMsg, wParam, lParam);
263     }
264 }
265
266
267 VOID
268 FLATSB_Register (void)
269 {
270     WNDCLASSW wndClass;
271
272     ZeroMemory (&wndClass, sizeof(WNDCLASSW));
273     wndClass.style         = CS_GLOBALCLASS;
274     wndClass.lpfnWndProc   = FlatSB_WindowProc;
275     wndClass.cbClsExtra    = 0;
276     wndClass.cbWndExtra    = sizeof(FLATSB_INFO *);
277     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
278     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
279     wndClass.lpszClassName = FLATSB_CLASSW;
280
281     RegisterClassW (&wndClass);
282 }
283
284
285 VOID
286 FLATSB_Unregister (void)
287 {
288     UnregisterClassW (FLATSB_CLASSW, NULL);
289 }