cwidgeteventhandlerlist.hxx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cwidgeteventhandlerlist.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_CWIDGETEVENTHANDLERLIST_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETEVENTHANDLERLIST_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/cwidgeteventhandler.hxx"
  65. #include "graphics/nxwidgets/tnxarray.hxx"
  66. /****************************************************************************
  67. * Pre-Processor Definitions
  68. ****************************************************************************/
  69. /****************************************************************************
  70. * Implementation Classes
  71. ****************************************************************************/
  72. #if defined(__cplusplus)
  73. namespace NXWidgets
  74. {
  75. class CNxWidget;
  76. class CListDataItem;
  77. /**
  78. * List of widget event handlers.
  79. */
  80. class CWidgetEventHandlerList
  81. {
  82. protected:
  83. TNxArray<CWidgetEventHandler*> m_widgetEventHandlers; /**< List of event handlers */
  84. CNxWidget *m_widget; /**< Owning widget */
  85. bool m_isEnabled; /**< Indicates if events are active */
  86. public:
  87. /**
  88. * Constructor.
  89. *
  90. * @param widget The owning widget.
  91. */
  92. CWidgetEventHandlerList(CNxWidget *widget);
  93. /**
  94. * Destructor.
  95. */
  96. ~CWidgetEventHandlerList(void) { }
  97. /**
  98. * Check if the object raises events or not.
  99. *
  100. * @return True if events are enabled.
  101. */
  102. bool isEnabled(void) const;
  103. /**
  104. * Get the event handler at the specified index.
  105. *
  106. * @param index The index of the event handler.
  107. * @return The event handler at the specified index.
  108. */
  109. inline CWidgetEventHandler *at(int index) const
  110. {
  111. return m_widgetEventHandlers.at(index);
  112. }
  113. /**
  114. * Get the size of the array.
  115. *
  116. * @return The size of the array.
  117. */
  118. inline int size(void) const
  119. {
  120. return m_widgetEventHandlers.size();
  121. }
  122. /**
  123. * Adds a widget event handler. The event handler will receive
  124. * all events raised by this object.
  125. * @param eventHandler A pointer to the event handler.
  126. */
  127. void addWidgetEventHandler(CWidgetEventHandler *eventHandler);
  128. /**
  129. * Remove a widget event handler.
  130. *
  131. * @param eventHandler A pointer to the event handler to remove.
  132. */
  133. void removeWidgetEventHandler(CWidgetEventHandler *eventHandler);
  134. /**
  135. * Enables event raising.
  136. */
  137. inline void enable(void)
  138. {
  139. m_isEnabled = true;
  140. }
  141. /**
  142. * Disables event raising.
  143. */
  144. inline void disable(void)
  145. {
  146. m_isEnabled = false;
  147. }
  148. /**
  149. * Raise a click event to the event handler.
  150. *
  151. * @param x The x coordinate of the click.
  152. * @param y The y coordinate of the click.
  153. */
  154. void raiseClickEvent(nxgl_coord_t x, nxgl_coord_t y);
  155. /**
  156. * Raise a double-click event to the event handler.
  157. *
  158. * @param x The x coordinate of the click.
  159. * @param y The y coordinate of the click.
  160. */
  161. void raiseDoubleClickEvent(nxgl_coord_t x, nxgl_coord_t y);
  162. /**
  163. * Raise a mouse release event to the event handler.
  164. *
  165. * @param x The x coordinate of the release.
  166. * @param y The y coordinate of the release.
  167. */
  168. void raiseReleaseEvent(nxgl_coord_t x, nxgl_coord_t y);
  169. /**
  170. * Raise a mouse release-outside event to the event handler.
  171. *
  172. * @param x The x coordinate of the release.
  173. * @param y The y coordinate of the release.
  174. */
  175. void raiseReleaseOutsideEvent(nxgl_coord_t x, nxgl_coord_t y);
  176. /**
  177. * Raise a mouse drag event to the event handler.
  178. *
  179. * @param x The x coordinate of the mouse when the drag started.
  180. * @param y The y coordinate of the mouse when the drag started.
  181. * @param vX The horizontal distance dragged.
  182. * @param vY The vertical distance dragged.
  183. */
  184. void raiseDragEvent(nxgl_coord_t x, nxgl_coord_t y,
  185. nxgl_coord_t vX, nxgl_coord_t vY);
  186. /**
  187. * Raise a widget drop event to the event handler.
  188. *
  189. * @param x The x coordinate of the mouse when the drop occurred.
  190. * @param y The y coordinate of the mouse when the drop occurred.
  191. */
  192. void raiseDropEvent(nxgl_coord_t x, nxgl_coord_t y);
  193. /**
  194. * Raise a key press event to the event handler.
  195. *
  196. * @param key The character code of the key that caused the event.
  197. */
  198. void raiseKeyPressEvent(nxwidget_char_t key);
  199. /**
  200. * Raise a cursor control event to the event handler.
  201. *
  202. * @param cursorControl The cursor control code that caused the event.
  203. */
  204. void raiseCursorControlEvent(ECursorControl cursorControl);
  205. /**
  206. * Raise a focus event to the event handler.
  207. */
  208. void raiseFocusEvent(void);
  209. /**
  210. * Raise a blur event to the event handler.
  211. */
  212. void raiseBlurEvent(void);
  213. /**
  214. * Raise a close event to the event handler.
  215. */
  216. void raiseCloseEvent(void);
  217. /**
  218. * Raise a hide event to the event handler.
  219. */
  220. void raiseHideEvent(void);
  221. /**
  222. * Raise a show event to the event handler.
  223. */
  224. void raiseShowEvent(void);
  225. /**
  226. * Raise an enable event to the event handler.
  227. */
  228. void raiseEnableEvent(void);
  229. /**
  230. * Raise a disable event to the event handler.
  231. */
  232. void raiseDisableEvent(void);
  233. /**
  234. * Raise a value change event to the event handler.
  235. */
  236. void raiseValueChangeEvent(void);
  237. /**
  238. * Raise a resize event to the event handler.
  239. *
  240. * @param width The new width of the widget.
  241. * @param height The new height of the widget.
  242. */
  243. void raiseResizeEvent(nxgl_coord_t width, nxgl_coord_t height);
  244. /**
  245. * Raise a move event to the event handler.
  246. *
  247. * @param x The new x coordinate of the widget.
  248. * @param y The new y coordinate of the widget.
  249. * @param vX The horizontal distance moved.
  250. * @param vY The vertical distance moved.
  251. */
  252. void raiseMoveEvent(nxgl_coord_t x, nxgl_coord_t y,
  253. nxgl_coord_t vX, nxgl_coord_t vY);
  254. /**
  255. * Raise an action event to the event handler. This should be called
  256. * when a widget's purpose has been fulfilled. For example, in the case
  257. * of a button, this event is raised when the button is released within
  258. * its boundaries. The button has produced a valid click, and thus
  259. * fulfilled its purpose, so it needs to raise an "action" event.
  260. */
  261. void raiseActionEvent(void);
  262. /**
  263. * Raises a scroll event. Fired when the panel scrolls.
  264. *
  265. * @param vX Horizontal distance scrolled.
  266. * @param vY Vertical distance scrolled.
  267. */
  268. void raiseScrollEvent(nxgl_coord_t vX, nxgl_coord_t vY);
  269. };
  270. }
  271. #endif // __cplusplus
  272. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETEVENTHANDLERLIST_HXX