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 
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));
125 
126  // Setup the up button
127 
128  m_upButton = new CGlyphButton(pWidgetControl,
129  0, 0,
130  width, m_buttonHeight,
131  0, 0,
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,
143 
144  // Create timer
145 
146  m_scrollTimeout = 10;
147 
148  m_timer = new CNxTimer(pWidgetControl, m_scrollTimeout, true);
150 
155 }
156 
157 /**
158  * Get the smallest value that the slider can represent.
159  *
160  * @return The smallest value.
161  */
162 
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 
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 
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 
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 
248 {
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 
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 
283  }
284  else if (m_downButton->isClicked())
285  {
286  // Move the grip down
287 
289  }
290 
292  }
293 }
294 
295 /**
296  * Process events fired by the grip.
297  *
298  * @param e The event details.
299  */
300 
302 {
303  if (e.getSource() == m_upButton)
304  {
305  // Start the timer
306 
307  m_timer->start();
308 
309  // Move the grip up
310 
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 
324  }
325 }
326 
327 /**
328  * Process events fired by the grip.
329  *
330  * @param e The event details.
331  */
332 
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 
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 
366 {
367  if (e.getSource() == m_slider)
368  {
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));
396 
397  // Set back to current value
398 
399  setValue(value);
400 
401  // Reset event raising
402 
403  setRaisesEvents(events);
404 }
void setMinimumValue(const int value)
void setValueWithBitshift(const int32_t value)
bool isClicked(void) const
Definition: cnxwidget.hxx:560
const T & getSource(void) const
Definition: teventargs.hxx:127
bool moveTo(nxgl_coord_t x, nxgl_coord_t y)
Definition: cnxwidget.cxx:990
virtual void handleValueChangeEvent(const CWidgetEventArgs &e)
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
void setRaisesEvents(bool raises)
Definition: cnxwidget.hxx:887
bool raisesEvents(void) const
Definition: cnxwidget.hxx:898
const struct SBitmap g_arrowUp
Definition: glyphs.hxx:118
CScrollbarVertical(const CScrollbarVertical &scrollbarVertical)
const int getMinimumValue(void) const
bool resize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cnxwidget.cxx:1079
nxgl_coord_t getMinimumStep(void) const
nxgl_coord_t getHeight(void) const
Definition: cnxwidget.hxx:593
void addWidgetEventHandler(CWidgetEventHandler *eventHandler)
Definition: cnxwidget.hxx:854
void setValue(const int value)
void setPageSize(const nxgl_coord_t pageSize)
virtual void handleActionEvent(const CWidgetEventArgs &e)
void setMaximumValue(const int value)
const int getMinimumValue(void) const
void setValueWithBitshift(const int32_t value)
CWidgetEventHandlerList * m_widgetEventHandlers
Definition: cnxwidget.hxx:191
const int getValue(void) const
void addWidget(CNxWidget *widget)
Definition: cnxwidget.cxx:1293
virtual void handleClickEvent(const CWidgetEventArgs &e)
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
const struct SBitmap g_arrowDown
Definition: glyphs.hxx:119
const nxgl_coord_t getPageSize(void) const
void setMaximumValue(const int value)
CWidgetStyle m_style
Definition: cnxwidget.hxx:183
void setMinimumValue(const int value)
void start(void)
Definition: cnxtimer.cxx:154
const int getMaximumValue(void) const
const int getMaximumValue(void) const
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
const nxgl_coord_t getPageSize(void) const
void setPageSize(const nxgl_coord_t pageSize)