NXWidgets: cscrollbarvertical.cxx Source File

NXWidgets 1.19

cscrollbarvertical.cxx
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 /****************************************************************************
71 * Included Files
72 ****************************************************************************/
73
74 #include <nuttx/config.h>
75
76 #include <stdint.h>
77 #include <stdbool.h>
78
79 #include <nuttx/nx/nxglib.h>
80
81 #include "nxconfig.hxx"
82 #include "cscrollbarvertical.hxx"
83 #include "cglyphbutton.hxx"
84 #include "cslidervertical.hxx"
85 #include "cnxtimer.hxx"
86 #include "glyphs.hxx"
87
88 /****************************************************************************
89 * Pre-Processor Definitions
90 ****************************************************************************/
91
92 /****************************************************************************
93 * Method Implementation
94 ****************************************************************************/
95
96 using namespace NXWidgets;
97
98 /**
99 * Constructor.
100 *
101 * @param pWidgetControl The widget control instance for the window.
102 * @param x The x coordinate of the slider, relative to its parent.
103 * @param y The y coordinate of the slider, relative to its parent.
104 * @param width The width of the slider.
105 * @param height The height of the slider.
106 * @param style The style that the widget should use. If this is not
107 * specified, the widget will use the values stored in the global
108 * g_defaultWidgetStyle object. The widget will copy the properties of
109 * the style into its own internal style object.
110 */
111
112 CScrollbarVertical::CScrollbarVertical(CWidgetControl *pWidgetControl,
113 nxgl_coord_t x, nxgl_coord_t y,
114 nxgl_coord_t width, nxgl_coord_t height,
115 CWidgetStyle *style)
116 : CNxWidget(pWidgetControl, x, y, width, height, WIDGET_BORDERLESS, style)
117 {
118 m_buttonHeight = 10;
119
120 // Create the children
121
122 m_slider = new CSliderVertical(pWidgetControl, 0, m_buttonHeight,
123 width, height - (m_buttonHeight << 1));
124 m_slider->addWidgetEventHandler(this);
125
126 // Setup the up button
127
128 m_upButton = new CGlyphButton(pWidgetControl,
129 0, 0,
130 width, m_buttonHeight,
131 0, 0,
132 &g_arrowUp, &g_arrowUp, &m_style);
133 m_upButton->addWidgetEventHandler(this);
134
135 // Setup the down button
136
137 m_downButton = new CGlyphButton(pWidgetControl,
138 0, height - m_buttonHeight,
139 width, m_buttonHeight,
140 0, 0,
141 &g_arrowDown, &g_arrowDown, &m_style);
142 m_downButton->addWidgetEventHandler(this);
143
144 // Create timer
145
146 m_scrollTimeout = 10;
147
148 m_timer = new CNxTimer(pWidgetControl, m_scrollTimeout, true);
149 m_timer->addWidgetEventHandler(this);
150
151 addWidget(m_slider);
152 addWidget(m_upButton);
153 addWidget(m_downButton);
154 addWidget(m_timer);
155 }
156
157 /**
158 * Get the smallest value that the slider can represent.
159 *
160 * @return The smallest value.
161 */
162
163 const int CScrollbarVertical::getMinimumValue(void) const
164 {
165 return m_slider->getMinimumValue();
166 }
167
168 /**
169 * Get the largest value that the slider can represent.
170 *
171 * @return The largest value.
172 */
173
174 const int CScrollbarVertical::getMaximumValue(void) const
175 {
176 return m_slider->getMaximumValue();
177 }
178
179 /**
180 * Get the current value of the slider.
181 *
182 * @return The current slider value.
183 */
184
185 const int CScrollbarVertical::getValue(void) const
186 {
187 return m_slider->getValue();
188 }
189
190 /**
191 * Get the value represented by the height of the grip.
192 * For sliders, this would typically be 1 (so each new
193 * grip position is worth 1). For scrollbars, this
194 * would be the height of the scrolling widget.
195 *
196 * @return The page size.
197 */
198
199 const nxgl_coord_t CScrollbarVertical::getPageSize(void) const
200 {
201 return m_slider->getPageSize();
202 }
203
204 /**
205 * Set the smallest value that the slider can represent.
206 *
207 * @param value The smallest value.
208 */
209
210 void CScrollbarVertical::setMinimumValue(const int value)
211 {
212 m_slider->setMinimumValue(value);
213 }
214
215 /**
216 * Set the largest value that the slider can represent.
217 *
218 * @param value The largest value.
219 */
220
221 void CScrollbarVertical::setMaximumValue(const int value)
222 {
223 m_slider->setMaximumValue(value);
224 }
225
226 /**
227 * Set the value that of the slider. This will reposition
228 * and redraw the grip.
229 *
230 * @param value The new value.
231 */
232
233 void CScrollbarVertical::setValue(const int value)
234 {
235 m_slider->setValue(value);
236 }
237
238 /**
239 * Set the value that of the slider. This will reposition and redraw
240 * the grip. The supplied value should be bitshifted left 16 places.
241 * This ensures greater accuracy than the standard setValue() method if
242 * the slider is being used as a scrollbar.
243 *
244 * @param value The new value.
245 */
246
247 void CScrollbarVertical::setValueWithBitshift(const int32_t value)
248 {
249 m_slider->setValueWithBitshift(value);
250 }
251
252 /**
253 * Set the page size represented by the grip.
254 *
255 * @param pageSize The page size.
256 * @see getPageSize().
257 */
258
259 void CScrollbarVertical::setPageSize(nxgl_coord_t pageSize)
260 {
261 m_slider->setPageSize(pageSize);
262 }
263
264 /**
265 * Process events fired by the grip.
266 *
267 * @param e The event details.
268 */
269
270 void CScrollbarVertical::handleActionEvent(const CWidgetEventArgs &e)
271 {
272 // Check which widget fired the event
273
274 if (e.getSource() == m_timer)
275 {
276 // Which widget is clicked?
277
278 if (m_upButton->isClicked())
279 {
280 // Move the grip up
281
282 m_slider->setValue(m_slider->getValue() - m_slider->getMinimumStep());
283 }
284 else if (m_downButton->isClicked())
285 {
286 // Move the grip down
287
288 m_slider->setValue(m_slider->getValue() + m_slider->getMinimumStep());
289 }
290
291 m_widgetEventHandlers->raiseValueChangeEvent();
292 }
293 }
294
295 /**
296 * Process events fired by the grip.
297 *
298 * @param e The event details.
299 */
300
301 void CScrollbarVertical::handleClickEvent(const CWidgetEventArgs &e)
302 {
303 if (e.getSource() == m_upButton)
304 {
305 // Start the timer
306
307 m_timer->start();
308
309 // Move the grip up
310
311 m_slider->setValue(m_slider->getValue() - m_slider->getMinimumStep());
312 m_widgetEventHandlers->raiseValueChangeEvent();
313 }
314 else if (e.getSource() == m_downButton)
315 {
316 // Start the timer
317
318 m_timer->start();
319
320 // Move the grip down
321
322 m_slider->setValue(m_slider->getValue() + m_slider->getMinimumStep());
323 m_widgetEventHandlers->raiseValueChangeEvent();
324 }
325 }
326
327 /**
328 * Process events fired by the grip.
329 *
330 * @param e The event details.
331 */
332
333 void CScrollbarVertical::handleReleaseEvent(const CWidgetEventArgs &e)
334 {
335 if ((e.getSource() == m_upButton) || (e.getSource() == m_downButton))
336 {
337 // Stop the timer
338
339 m_timer->stop();
340 }
341 }
342
343 /**
344 * Process events fired by the grip.
345 *
346 * @param e The event details.
347 */
348
349 void CScrollbarVertical::handleReleaseOutsideEvent(const CWidgetEventArgs &e)
350 {
351 if ((e.getSource() == m_upButton) || (e.getSource() == m_downButton))
352 {
353 // Stop the timer
354
355 m_timer->stop();
356 }
357 }
358
359 /**
360 * Process events fired by the grip.
361 *
362 * @param e The event details.
363 */
364
365 void CScrollbarVertical::handleValueChangeEvent(const CWidgetEventArgs &e)
366 {
367 if (e.getSource() == m_slider)
368 {
369 m_widgetEventHandlers->raiseValueChangeEvent();
370 }
371 }
372
373 /**
374 * Resize the scrollbar to the new dimensions.
375 *
376 * @param width The new width.
377 * @param height The new height.
378 */
379
380 void CScrollbarVertical::onResize(nxgl_coord_t width, nxgl_coord_t height)
381 {
382 // Remember current values
383
384 int value = getValue();
385 bool events = raisesEvents();
386
387 // Disable event raising
388
389 setRaisesEvents(false);
390
391 // Resize and move children
392
393 m_slider->resize(width, height - (m_buttonHeight << 1));
394 m_upButton->moveTo(0, m_slider->getHeight());
395 m_downButton->moveTo(0, m_slider->getHeight() + m_buttonHeight);
396
397 // Set back to current value
398
399 setValue(value);
400
401 // Reset event raising
402
403 setRaisesEvents(events);
404 }
NXWidgets::CGlyphButton
Definition: cglyphbutton.hxx:113
NXWidgets::CScrollbarVertical::setMinimumValue
void setMinimumValue(const int value)
Definition: cscrollbarvertical.cxx:210
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CScrollbarVertical::setValueWithBitshift
void setValueWithBitshift(const int32_t value)
Definition: cscrollbarvertical.cxx:247
cscrollbarvertical.hxx
NXWidgets::CNxWidget::isClicked
bool isClicked(void) const
Definition: cnxwidget.hxx:560
NXWidgets::TEventArgs::getSource
const T & getSource(void) const
Definition: teventargs.hxx:127
NXWidgets::CWidgetStyle
Definition: cwidgetstyle.hxx:125
NXWidgets::CScrollbarVertical::m_upButton
CGlyphButton * m_upButton
Definition: cscrollbarvertical.hxx:117
NXWidgets::CNxWidget::moveTo
bool moveTo(nxgl_coord_t x, nxgl_coord_t y)
Definition: cnxwidget.cxx:990
NXWidgets::CScrollbarVertical::handleValueChangeEvent
virtual void handleValueChangeEvent(const CWidgetEventArgs &e)
Definition: cscrollbarvertical.cxx:365
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CScrollbarVertical::onResize
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cscrollbarvertical.cxx:380
NXWidgets::CNxWidget::setRaisesEvents
void setRaisesEvents(bool raises)
Definition: cnxwidget.hxx:887
glyphs.hxx
NXWidgets::CNxWidget::raisesEvents
bool raisesEvents(void) const
Definition: cnxwidget.hxx:898
NXWidgets::g_arrowUp
const struct SBitmap g_arrowUp
Definition: glyphs.hxx:118
NXWidgets::CScrollbarVertical::m_timer
CNxTimer * m_timer
Definition: cscrollbarvertical.hxx:122
NXWidgets::CScrollbarVertical::setValue
void setValue(const int value)
Definition: cscrollbarvertical.cxx:233
NXWidgets::CScrollbarVertical::getValue
const int getValue(void) const
Definition: cscrollbarvertical.cxx:185
NXWidgets::CScrollbarVertical::CScrollbarVertical
CScrollbarVertical(const CScrollbarVertical &scrollbarVertical)
Definition: cscrollbarvertical.hxx:137
NXWidgets::CScrollbarVertical::getMinimumValue
const int getMinimumValue(void) const
Definition: cscrollbarvertical.cxx:163
NXWidgets::CNxWidget::resize
bool resize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cnxwidget.cxx:1079
NXWidgets::CScrollbarVertical::m_scrollTimeout
uint8_t m_scrollTimeout
Definition: cscrollbarvertical.hxx:120
NXWidgets::CSliderVertical::getMinimumStep
nxgl_coord_t getMinimumStep(void) const
Definition: cslidervertical.cxx:231
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNxWidget::getHeight
nxgl_coord_t getHeight(void) const
Definition: cnxwidget.hxx:593
cglyphbutton.hxx
NXWidgets::CNxWidget::addWidgetEventHandler
void addWidgetEventHandler(CWidgetEventHandler *eventHandler)
Definition: cnxwidget.hxx:854
NXWidgets::CSliderVertical::setValue
void setValue(const int value)
Definition: cslidervertical.cxx:141
nxconfig.hxx
NXWidgets::CNxTimer
Definition: cnxtimer.hxx:110
NXWidgets::CSliderVertical::setPageSize
void setPageSize(const nxgl_coord_t pageSize)
Definition: cslidervertical.hxx:315
cnxtimer.hxx
NXWidgets::CScrollbarVertical::m_downButton
CGlyphButton * m_downButton
Definition: cscrollbarvertical.hxx:118
NXWidgets::CScrollbarVertical::m_buttonHeight
nxgl_coord_t m_buttonHeight
Definition: cscrollbarvertical.hxx:119
NXWidgets::CScrollbarVertical::handleActionEvent
virtual void handleActionEvent(const CWidgetEventArgs &e)
Definition: cscrollbarvertical.cxx:270
NXWidgets::CSliderVertical::setMaximumValue
void setMaximumValue(const int value)
Definition: cslidervertical.hxx:281
NXWidgets::CSliderVertical::getMinimumValue
const int getMinimumValue(void) const
Definition: cslidervertical.hxx:222
NXWidgets::CSliderVertical::setValueWithBitshift
void setValueWithBitshift(const int32_t value)
Definition: cslidervertical.cxx:155
NXWidgets::CNxWidget::m_widgetEventHandlers
CWidgetEventHandlerList * m_widgetEventHandlers
Definition: cnxwidget.hxx:191
NXWidgets::CSliderVertical::getValue
const int getValue(void) const
Definition: cslidervertical.hxx:243
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
cslidervertical.hxx
NXWidgets::CNxWidget::addWidget
void addWidget(CNxWidget *widget)
Definition: cnxwidget.cxx:1293
NXWidgets::CScrollbarVertical::handleClickEvent
virtual void handleClickEvent(const CWidgetEventArgs &e)
Definition: cscrollbarvertical.cxx:301
NXWidgets::CScrollbarVertical::handleReleaseOutsideEvent
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
Definition: cscrollbarvertical.cxx:349
NXWidgets::g_arrowDown
const struct SBitmap g_arrowDown
Definition: glyphs.hxx:119
NXWidgets::CSliderVertical::getPageSize
const nxgl_coord_t getPageSize(void) const
Definition: cslidervertical.hxx:257
NXWidgets::CScrollbarVertical::setMaximumValue
void setMaximumValue(const int value)
Definition: cscrollbarvertical.cxx:221
NXWidgets::CNxTimer::stop
void stop(void)
Definition: cnxtimer.cxx:176
NXWidgets::CNxWidget::m_style
CWidgetStyle m_style
Definition: cnxwidget.hxx:183
NXWidgets::CSliderVertical::setMinimumValue
void setMinimumValue(const int value)
Definition: cslidervertical.hxx:268
NXWidgets::CNxTimer::start
void start(void)
Definition: cnxtimer.cxx:154
NXWidgets::CSliderVertical::getMaximumValue
const int getMaximumValue(void) const
Definition: cslidervertical.hxx:233
NXWidgets::CScrollbarVertical::getMaximumValue
const int getMaximumValue(void) const
Definition: cscrollbarvertical.cxx:174
NXWidgets::CScrollbarVertical::handleReleaseEvent
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
Definition: cscrollbarvertical.cxx:333
NXWidgets::CScrollbarVertical::m_slider
CSliderVertical * m_slider
Definition: cscrollbarvertical.hxx:116
NXWidgets::CSliderVertical
Definition: cslidervertical.hxx:109
NXWidgets::CScrollbarVertical::getPageSize
const nxgl_coord_t getPageSize(void) const
Definition: cscrollbarvertical.cxx:199
NXWidgets::CWidgetEventHandlerList::raiseValueChangeEvent
void raiseValueChangeEvent(void)
Definition: cwidgeteventhandlerlist.cxx:443
NXWidgets::CScrollbarVertical::setPageSize
void setPageSize(const nxgl_coord_t pageSize)
Definition: cscrollbarvertical.cxx:259