cscrollbarvertical.hxx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cscrollbarvertical.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. *
  22. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  23. * portions are original efforts. It is difficult to determine at this
  24. * point what parts are original efforts and which parts derive from Woopsi.
  25. * However, in any event, the work of Antony Dzeryn will be acknowledged
  26. * in most NxWidget files. Thanks Antony!
  27. *
  28. * Copyright (c) 2007-2011, Antony Dzeryn
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions are met:
  33. *
  34. * * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * * Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * * Neither the names "Woopsi", "Simian Zombie" nor the
  40. * names of its contributors may be used to endorse or promote products
  41. * derived from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  44. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  45. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  47. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  49. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  50. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  51. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. *
  54. ****************************************************************************/
  55. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLBARVERTICAL_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLBARVERTICAL_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include <nuttx/config.h>
  61. #include <stdint.h>
  62. #include <stdbool.h>
  63. #include <nuttx/nx/nxglib.h>
  64. #include "graphics/nxwidgets/cnxwidget.hxx"
  65. #include "graphics/nxwidgets/cwidgeteventhandler.hxx"
  66. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  67. #include "graphics/nxwidgets/islider.hxx"
  68. /****************************************************************************
  69. * Pre-Processor Definitions
  70. ****************************************************************************/
  71. /****************************************************************************
  72. * Implementation Classes
  73. ****************************************************************************/
  74. #if defined(__cplusplus)
  75. namespace NXWidgets
  76. {
  77. class CSliderVertical;
  78. class CGlyphButton;
  79. class CNxTimer;
  80. /**
  81. * Container class that holds a slider widget and two arrow buttons.
  82. * The interface is presents is virtually identical to the CSliderVertical
  83. * widget, which means the two are easily interchangeable. All events
  84. * raised by the internal slider widget are re-raised by this widget
  85. * to this widget's event handler, meaning its events are also identical
  86. * to the CSliderVertical's.
  87. */
  88. class CScrollbarVertical : public ISlider, public CNxWidget, public CWidgetEventHandler {
  89. protected:
  90. CSliderVertical *m_slider; /**< Pointer to the slider widget */
  91. CGlyphButton *m_upButton; /**< Pointer to the up button */
  92. CGlyphButton *m_downButton; /**< Pointer to the down button */
  93. nxgl_coord_t m_buttonHeight; /**< Height of the buttons */
  94. uint8_t m_scrollTimeout; /**< Time until a button triggers another grip
  95. movement */
  96. CNxTimer *m_timer; /**< Controls slider button repeats */
  97. /**
  98. * Resize the scrollbar to the new dimensions.
  99. *
  100. * @param width The new width.
  101. * @param height The new height.
  102. */
  103. virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
  104. /**
  105. * Copy constructor is protected to prevent usage.
  106. */
  107. inline CScrollbarVertical(const CScrollbarVertical& scrollbarVertical)
  108. : CNxWidget(scrollbarVertical) { }
  109. public:
  110. /**
  111. * Constructor.
  112. *
  113. * @param pWidgetControl The widget control instance for the window.
  114. * @param x The x coordinate of the slider, relative to its parent.
  115. * @param y The y coordinate of the slider, relative to its parent.
  116. * @param width The width of the slider.
  117. * @param height The height of the slider.
  118. * @param style The style that the widget should use. If this is not
  119. * specified, the widget will use the values stored in the global
  120. * g_defaultWidgetStyle object. The widget will copy the properties of
  121. * the style into its own internal style object.
  122. */
  123. CScrollbarVertical(CWidgetControl *pWidgetControl,
  124. nxgl_coord_t x, nxgl_coord_t y,
  125. nxgl_coord_t width, nxgl_coord_t height,
  126. CWidgetStyle *style = (CWidgetStyle *)NULL);
  127. /**
  128. * Destructor.
  129. */
  130. virtual inline ~CScrollbarVertical(void) { }
  131. /**
  132. * Get the smallest value that the slider can represent.
  133. *
  134. * @return The smallest value.
  135. */
  136. const int getMinimumValue(void) const;
  137. /**
  138. * Get the largest value that the slider can represent.
  139. *
  140. * @return The largest value.
  141. */
  142. const int getMaximumValue(void) const;
  143. /**
  144. * Get the current value of the slider.
  145. *
  146. * @return The current slider value.
  147. */
  148. const int getValue(void) const;
  149. /**
  150. * Get the value represented by the height of the grip.
  151. * For sliders, this would typically be 1 (so each new
  152. * grip position is worth 1). For scrollbars, this
  153. * would be the height of the scrolling widget.
  154. *
  155. * @return The page size.
  156. */
  157. const nxgl_coord_t getPageSize(void) const;
  158. /**
  159. * Set the smallest value that the slider can represent.
  160. *
  161. * @param value The smallest value.
  162. */
  163. void setMinimumValue(const int value);
  164. /**
  165. * Set the largest value that the slider can represent.
  166. *
  167. * @param value The largest value.
  168. */
  169. void setMaximumValue(const int value);
  170. /**
  171. * Set the value that of the slider. This will reposition
  172. * and redraw the grip.
  173. *
  174. * @param value The new value.
  175. */
  176. void setValue(const int value);
  177. /**
  178. * Set the value that of the slider. This will reposition and redraw
  179. * the grip. The supplied value should be bitshifted left 16 places.
  180. * This ensures greater accuracy than the standard setValue() method if
  181. * the slider is being used as a scrollbar.
  182. *
  183. * @param value The new value.
  184. */
  185. void setValueWithBitshift(const int32_t value);
  186. /**
  187. * Set the page size represented by the grip.
  188. *
  189. * @param pageSize The page size.
  190. * @see getPageSize().
  191. */
  192. void setPageSize(const nxgl_coord_t pageSize);
  193. /**
  194. * Process events fired by the grip.
  195. *
  196. * @param e The event details.
  197. */
  198. virtual void handleActionEvent(const CWidgetEventArgs &e);
  199. /**
  200. * Process events fired by the grip.
  201. *
  202. * @param e The event details.
  203. */
  204. virtual void handleClickEvent(const CWidgetEventArgs &e);
  205. /**
  206. * Process events fired by the grip.
  207. *
  208. * @param e The event details.
  209. */
  210. virtual void handleReleaseEvent(const CWidgetEventArgs &e);
  211. /**
  212. * Process events fired by the grip.
  213. *
  214. * @param e The event details.
  215. */
  216. virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e);
  217. /**
  218. * Process events fired by the grip.
  219. *
  220. * @param e The event details.
  221. */
  222. virtual void handleValueChangeEvent(const CWidgetEventArgs &e);
  223. };
  224. }
  225. #endif // __cplusplus
  226. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLBARVERTICAL_HXX