cscrollbarpanel.hxx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cscrollbarpanel.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_CSCROLLBARPANEL_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLBARPANEL_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/cscrollingpanel.hxx"
  66. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  67. #include "graphics/nxwidgets/cscrollbarvertical.hxx"
  68. #include "graphics/nxwidgets/cscrollbarhorizontal.hxx"
  69. #include "graphics/nxwidgets/cwidgeteventhandler.hxx"
  70. #include "graphics/nxwidgets/iscrollable.hxx"
  71. #include "graphics/nxwidgets/cgraphicsport.hxx"
  72. /****************************************************************************
  73. * Pre-Processor Definitions
  74. ****************************************************************************/
  75. /****************************************************************************
  76. * Implementation Classes
  77. ****************************************************************************/
  78. #if defined(__cplusplus)
  79. namespace NXWidgets
  80. {
  81. /**
  82. * Class containing a scrolling panel bordered by scrollbars.
  83. */
  84. class CScrollbarPanel : public CNxWidget, public IScrollable,
  85. public CWidgetEventHandler
  86. {
  87. protected:
  88. CWidgetControl *m_widgetControl; /**< Widget control instance */
  89. CScrollingPanel *m_panel; /**< Internal panel that
  90. contains children. */
  91. CScrollbarHorizontal *m_scrollbarHorizontal; /**< Horizontal scrollbar. */
  92. CScrollbarVertical *m_scrollbarVertical; /**< Vertical scrollbar. */
  93. uint8_t m_scrollbarWidth; /**< Width of the vertical
  94. scrollbar. */
  95. uint8_t m_scrollbarHeight; /**< Height of the horizontal
  96. scrollbar. */
  97. bool m_hasVerticalScrollbar; /**< Indicates the presence of
  98. a vertical scrollbar. */
  99. bool m_hasHorizontalScrollbar; /**< Indicates the presence of
  100. a horizontal scrollbar. */
  101. /**
  102. * Creates the child widgets.
  103. */
  104. void buildUI(void);
  105. /**
  106. * Draw the area of this widget that falls within the clipping region.
  107. * Called by the redraw() function to draw all visible regions.
  108. *
  109. * @param port The CGraphicsPort to draw to.
  110. * @see redraw()
  111. */
  112. virtual void drawContents(CGraphicsPort *port);
  113. /**
  114. * Destructor.
  115. */
  116. virtual ~CScrollbarPanel(void) { }
  117. /**
  118. * Copy constructor is protected to prevent usage.
  119. */
  120. inline CScrollbarPanel(const CScrollbarPanel &scrollbarPanel)
  121. : CNxWidget(scrollbarPanel) { }
  122. public:
  123. /**
  124. * Constructor.
  125. *
  126. * @param pWidgetControl The widget control for the display.
  127. * @param x The x coordinate of the widget.
  128. * @param y The y coordinate of the widget.
  129. * @param width The width of the widget.
  130. * @param height The height of the widget.
  131. * @param flags The usual widget flags.
  132. * @param style The style that the widget should use. If this is not
  133. * specified, the widget will use the values stored in the global
  134. * g_defaultWidgetStyle object. The widget will copy the properties of
  135. * the style into its own internal style object.
  136. */
  137. CScrollbarPanel(CWidgetControl *pWidgetControl,
  138. nxgl_coord_t x, nxgl_coord_t y,
  139. nxgl_coord_t width, nxgl_coord_t height,
  140. uint32_t flags,
  141. CWidgetStyle *style = (CWidgetStyle *)NULL);
  142. /**
  143. * Scroll the panel by the specified amounts.
  144. *
  145. * @param dx The horizontal distance to scroll.
  146. * @param dy The vertical distance to scroll.
  147. */
  148. virtual void scroll(int32_t dx, int32_t dy);
  149. /**
  150. * Reposition the panel's scrolling region to the specified coordinates.
  151. *
  152. * @param x The new x coordinate of the scrolling region.
  153. * @param y The new y coordinate of the scrolling region.
  154. */
  155. virtual void jump(int32_t x, int32_t y);
  156. /**
  157. * Set whether or not horizontal scrolling is allowed.
  158. *
  159. * @param allow True to allow horizontal scrolling; false to deny it.
  160. */
  161. virtual void setAllowsVerticalScroll(bool allow);
  162. /**
  163. * Set whether or not horizontal scrolling is allowed.
  164. *
  165. * @param allow True to allow horizontal scrolling; false to deny it.
  166. */
  167. virtual void setAllowsHorizontalScroll(bool allow);
  168. /**
  169. * Sets the width of the virtual canvas.
  170. *
  171. * @param width The width of the virtual canvas.
  172. */
  173. virtual void setCanvasWidth(const int32_t width);
  174. /**
  175. * Sets the height of the virtual canvas.
  176. *
  177. * @param height The height of the virtual canvas.
  178. */
  179. virtual void setCanvasHeight(const int32_t height);
  180. /**
  181. * Returns true if vertical scrolling is allowed.
  182. *
  183. * @return True if vertical scrolling is allowed.
  184. */
  185. virtual bool allowsVerticalScroll(void) const;
  186. /**
  187. * Returns true if horizontal scrolling is allowed.
  188. *
  189. * @return True if horizontal scrolling is allowed.
  190. */
  191. virtual bool allowsHorizontalScroll(void) const;
  192. /**
  193. * Gets the x coordinate of the virtual canvas.
  194. *
  195. * @return The x coordinate of the virtual canvas.
  196. */
  197. virtual const int32_t getCanvasX(void) const;
  198. /**
  199. * Gets the y coordinate of the virtual canvas.
  200. *
  201. * @return The y coordinate of the virtual canvas.
  202. */
  203. virtual const int32_t getCanvasY(void) const;
  204. /**
  205. * Gets the width of the virtual canvas.
  206. *
  207. * @return The width of the virtual canvas.
  208. */
  209. virtual const int32_t getCanvasWidth(void) const;
  210. /**
  211. * Gets the height of the virtual canvas.
  212. *
  213. * @return The height of the virtual canvas.
  214. */
  215. virtual const int32_t getCanvasHeight(void) const;
  216. /**
  217. * Handle a widget scroll event.
  218. *
  219. * @param e The event data.
  220. */
  221. void handleScrollEvent(const CWidgetEventArgs &e);
  222. /**
  223. * Handle a widget value change event.
  224. *
  225. * @param e The event data.
  226. */
  227. void handleValueChangeEvent(const CWidgetEventArgs &e);
  228. /**
  229. * Gets a pointer to the CScrollingPanel widget contained within
  230. * this widget.
  231. *
  232. * @return A pointer to the CScrollingPanel widget.
  233. */
  234. inline CScrollingPanel *getPanel(void)
  235. {
  236. return m_panel;
  237. }
  238. };
  239. }
  240. #endif // __cplusplus
  241. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLBARPANEL_HXX