NXWidgets: cscrollbarhorizontal.hxx Source File

NXWidgets 1.19

cscrollbarhorizontal.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx
3 *
4 * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18 * me be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************
35 *
36 * Portions of this package derive from Woopsi (http://woopsi.org/) and
37 * portions are original efforts. It is difficult to determine at this
38 * point what parts are original efforts and which parts derive from Woopsi.
39 * However, in any event, the work of Antony Dzeryn will be acknowledged
40 * in most NxWidget files. Thanks Antony!
41 *
42 * Copyright (c) 2007-2011, Antony Dzeryn
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * * Neither the names "Woopsi", "Simian Zombie" nor the
54 * names of its contributors may be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 ****************************************************************************/
69
70 #ifndef __INCLUDE_CSCROLLBARHORIZONTAL_HXX
71 #define __INCLUDE_CSCROLLBARHORIZONTAL_HXX
72
73 /****************************************************************************
74 * Included Files
75 ****************************************************************************/
76
77 #include <nuttx/config.h>
78
79 #include <stdint.h>
80 #include <stdbool.h>
81
82 #include <nuttx/nx/nxglib.h>
83
84 #include "cnxwidget.hxx"
85 #include "cwidgeteventhandler.hxx"
86 #include "cwidgetstyle.hxx"
87 #include "islider.hxx"
88
89 /****************************************************************************
90 * Pre-Processor Definitions
91 ****************************************************************************/
92
93 /****************************************************************************
94 * Implementation Classes
95 ****************************************************************************/
96
97 #if defined(__cplusplus)
98
99 namespace NXWidgets
100 {
101 class CSliderHorizontal;
102 class CGlyphButton;
103 class CNxTimer;
104
105 /**
106 * Container class that holds a slider widget and two arrow buttons.
107 * The interface is presents is virtually identical to the CSliderHorizontal
108 * widget, which means the two are easily interchangeable. All events
109 * raised by the internal slider widget are re-raised by this widget
110 * to this widget's event handler, meaning its events are also identical
111 * to the CSliderHorizontal's.
112 */
113
114 class CScrollbarHorizontal : public ISlider, public CNxWidget, public CWidgetEventHandler
115 {
116 protected:
117 CSliderHorizontal *m_slider; /**< Pointer to the slider widget */
118 CGlyphButton *m_leftButton; /**< Pointer to the left button */
119 CGlyphButton *m_rightButton; /**< Pointer to the right button */
120 nxgl_coord_t m_buttonWidth; /**< Width of the buttons */
121 uint8_t m_scrollTimeout; /**< Time until a button triggers
122 another grip movement */
123 CNxTimer *m_timer; /**< Controls slider button repeats */
124
125 /**
126 * Resize the scrollbar to the new dimensions.
127 *
128 * @param width The new width.
129 * @param height The new height.
130 */
131
132 virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
133
134 /**
135 * Copy constructor is protected to prevent usage.
136 */
137
138 inline CScrollbarHorizontal(const CScrollbarHorizontal &scrollbarHorizontal)
139 : CNxWidget(scrollbarHorizontal) { }
140
141 public:
142
143 /**
144 * Constructor.
145 *
146 * @param pWidgetControl The widget control instance for the window.
147 * @param x The x coordinate of the slider, relative to its parent.
148 * @param y The y coordinate of the slider, relative to its parent.
149 * @param width The width of the slider.
150 * @param height The height of the slider.
151 * @param style The style that the widget should use. If this is not
152 * specified, the widget will use the values stored in the global
153 * g_defaultWidgetStyle object. The widget will copy the properties of
154 * the style into its own internal style object.
155 */
156
157 CScrollbarHorizontal(CWidgetControl *pWidgetControl,
158 nxgl_coord_t x, nxgl_coord_t y,
159 nxgl_coord_t width, nxgl_coord_t height,
160 CWidgetStyle *style = (CWidgetStyle *)NULL);
161
162 /**
163 * Destructor.
164 */
165
166 virtual inline ~CScrollbarHorizontal(void) { }
167
168 /**
169 * Get the smallest value that the slider can represent.
170 *
171 * @return The smallest value.
172 */
173
174 const int getMinimumValue(void) const;
175
176 /**
177 * Get the largest value that the slider can represent.
178 *
179 * @return The largest value.
180 */
181
182 const int getMaximumValue(void) const;
183
184 /**
185 * Get the current value of the slider.
186 *
187 * @return The current slider value.
188 */
189
190 const int getValue(void) const;
191
192 /**
193 * Get the value represented by the height of the grip.
194 * For sliders, this would typically be 1 (so each new
195 * grip position is worth 1). For scrollbars, this
196 * would be the height of the scrolling widget.
197 *
198 * @return The page size.
199 */
200
201 const nxgl_coord_t getPageSize(void) const;
202
203 /**
204 * Set the smallest value that the slider can represent.
205 *
206 * @param value The smallest value.
207 */
208
209 void setMinimumValue(const int value);
210
211 /**
212 * Set the largest value that the slider can represent.
213 *
214 * @param value The largest value.
215 */
216
217 void setMaximumValue(const int value);
218
219 /**
220 * Set the value that of the slider. This will reposition
221 * and redraw the grip.
222 *
223 * @param value The new value.
224 */
225
226 void setValue(const int value);
227
228 /**
229 * Set the value that of the slider. This will reposition and redraw
230 * the grip. The supplied value should be bitshifted left 16 places.
231 * This ensures greater accuracy than the standard setValue() method if
232 * the slider is being used as a scrollbar.
233 *
234 * @param value The new value.
235 */
236
237 void setValueWithBitshift(const int32_t value);
238
239 /**
240 * Set the page size represented by the grip.
241 *
242 * @param pageSize The page size.
243 * @see getPageSize().
244 */
245
246 void setPageSize(const nxgl_coord_t pageSize);
247
248 /**
249 * Process events fired by the grip.
250 *
251 * @param e The event details.
252 */
253
254 virtual void handleActionEvent(const CWidgetEventArgs &e);
255
256 /**
257 * Process events fired by the grip.
258 *
259 * @param e The event details.
260 */
261
262 virtual void handleClickEvent(const CWidgetEventArgs &e);
263
264 /**
265 * Process events fired by the grip.
266 *
267 * @param e The event details.
268 */
269
270 virtual void handleReleaseEvent(const CWidgetEventArgs &e);
271
272 /**
273 * Process events fired by the grip.
274 *
275 * @param e The event details.
276 */
277
278 virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e);
279
280 /**
281 * Process events fired by the grip.
282 *
283 * @param e The event details.
284 */
285
286 virtual void handleValueChangeEvent(const CWidgetEventArgs &e);
287 };
288 }
289
290 #endif // __cplusplus
291
292 #endif // __INCLUDE_CSCROLLBARHORIZONTAL_HXX
293
NXWidgets::CGlyphButton
Definition: cglyphbutton.hxx:113
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CScrollbarHorizontal::~CScrollbarHorizontal
virtual ~CScrollbarHorizontal(void)
Definition: cscrollbarhorizontal.hxx:166
NXWidgets::CWidgetStyle
Definition: cwidgetstyle.hxx:125
NXWidgets::CWidgetEventHandler
Definition: cwidgeteventhandler.hxx:103
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CScrollbarHorizontal::getPageSize
const nxgl_coord_t getPageSize(void) const
Definition: cscrollbarhorizontal.cxx:201
NXWidgets::CScrollbarHorizontal::m_buttonWidth
nxgl_coord_t m_buttonWidth
Definition: cscrollbarhorizontal.hxx:120
NXWidgets::CScrollbarHorizontal::handleActionEvent
virtual void handleActionEvent(const CWidgetEventArgs &e)
Definition: cscrollbarhorizontal.cxx:272
NXWidgets::CScrollbarHorizontal::m_slider
CSliderHorizontal * m_slider
Definition: cscrollbarhorizontal.hxx:117
cwidgetstyle.hxx
NXWidgets::CSliderHorizontal
Definition: csliderhorizontal.hxx:109
NXWidgets::CScrollbarHorizontal::m_rightButton
CGlyphButton * m_rightButton
Definition: cscrollbarhorizontal.hxx:119
islider.hxx
NXWidgets::CScrollbarHorizontal::handleReleaseOutsideEvent
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
Definition: cscrollbarhorizontal.cxx:347
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CScrollbarHorizontal::setPageSize
void setPageSize(const nxgl_coord_t pageSize)
Definition: cscrollbarhorizontal.cxx:261
NXWidgets::CScrollbarHorizontal::getMaximumValue
const int getMaximumValue(void) const
Definition: cscrollbarhorizontal.cxx:176
NXWidgets::CScrollbarHorizontal::setValueWithBitshift
void setValueWithBitshift(const int32_t value)
Definition: cscrollbarhorizontal.cxx:249
NXWidgets::CScrollbarHorizontal::handleValueChangeEvent
virtual void handleValueChangeEvent(const CWidgetEventArgs &e)
Definition: cscrollbarhorizontal.cxx:363
NXWidgets::CNxTimer
Definition: cnxtimer.hxx:110
NXWidgets::ISlider
Definition: islider.hxx:99
NXWidgets::CScrollbarHorizontal::m_timer
CNxTimer * m_timer
Definition: cscrollbarhorizontal.hxx:123
NXWidgets::CScrollbarHorizontal::m_leftButton
CGlyphButton * m_leftButton
Definition: cscrollbarhorizontal.hxx:118
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
NXWidgets::CScrollbarHorizontal::handleClickEvent
virtual void handleClickEvent(const CWidgetEventArgs &e)
Definition: cscrollbarhorizontal.cxx:301
NXWidgets::CScrollbarHorizontal::m_scrollTimeout
uint8_t m_scrollTimeout
Definition: cscrollbarhorizontal.hxx:121
NXWidgets::CScrollbarHorizontal::handleReleaseEvent
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
Definition: cscrollbarhorizontal.cxx:331
NXWidgets::CScrollbarHorizontal::setMinimumValue
void setMinimumValue(const int value)
Definition: cscrollbarhorizontal.cxx:212
NXWidgets::CScrollbarHorizontal
Definition: cscrollbarhorizontal.hxx:114
NXWidgets::CScrollbarHorizontal::CScrollbarHorizontal
CScrollbarHorizontal(const CScrollbarHorizontal &scrollbarHorizontal)
Definition: cscrollbarhorizontal.hxx:138
NXWidgets::CScrollbarHorizontal::onResize
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cscrollbarhorizontal.cxx:378
cnxwidget.hxx
NXWidgets::CScrollbarHorizontal::getMinimumValue
const int getMinimumValue(void) const
Definition: cscrollbarhorizontal.cxx:165
NXWidgets::CScrollbarHorizontal::setValue
void setValue(const int value)
Definition: cscrollbarhorizontal.cxx:235
cwidgeteventhandler.hxx
NXWidgets::CScrollbarHorizontal::setMaximumValue
void setMaximumValue(const int value)
Definition: cscrollbarhorizontal.cxx:223
NXWidgets::CScrollbarHorizontal::getValue
const int getValue(void) const
Definition: cscrollbarhorizontal.cxx:187