NXWidgets  1.19
cwidgeteventhandlerlist.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx
3  *
4  * Copyright (C) 2012 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 #ifndef __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX
71 #define __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX
72 
73 /****************************************************************************
74  * Included Files
75  ****************************************************************************/
76 
77 #include <nuttx/config.h>
78 
79 #include <stdint.h>
80 #include <stdbool.h>
81 
82 #include <nuttx/nx/nxglib.h>
83 
84 #include "cwidgeteventhandler.hxx"
85 #include "tnxarray.hxx"
86 
87 /****************************************************************************
88  * Pre-Processor Definitions
89  ****************************************************************************/
90 
91 /****************************************************************************
92  * Implementation Classes
93  ****************************************************************************/
94 
95 #if defined(__cplusplus)
96 
97 namespace NXWidgets
98 {
99  class CNxWidget;
100  class CListDataItem;
101 
102  /**
103  * List of widget event handlers.
104  */
106  {
107  protected:
109  CNxWidget *m_widget; /**< Owning widget */
110  bool m_isEnabled; /**< Indicates if events are active */
111 
112  public:
113 
114  /**
115  * Constructor.
116  *
117  * @param widget The owning widget.
118  */
119 
121 
122  /**
123  * Destructor.
124  */
125 
127 
128  /**
129  * Check if the object raises events or not.
130  *
131  * @return True if events are enabled.
132  */
133 
134  bool isEnabled(void) const;
135 
136  /**
137  * Get the event handler at the specified index.
138  *
139  * @param index The index of the event handler.
140  * @return The event handler at the specified index.
141  */
142 
143  inline CWidgetEventHandler *at(int index) const
144  {
145  return m_widgetEventHandlers.at(index);
146  }
147 
148  /**
149  * Get the size of the array.
150  *
151  * @return The size of the array.
152  */
153 
154  inline int size(void) const
155  {
156  return m_widgetEventHandlers.size();
157  }
158 
159  /**
160  * Adds a widget event handler. The event handler will receive
161  * all events raised by this object.
162  * @param eventHandler A pointer to the event handler.
163  */
164 
165  void addWidgetEventHandler(CWidgetEventHandler *eventHandler);
166 
167  /**
168  * Remove a widget event handler.
169  *
170  * @param eventHandler A pointer to the event handler to remove.
171  */
172 
173  void removeWidgetEventHandler(CWidgetEventHandler *eventHandler);
174 
175  /**
176  * Enables event raising.
177  */
178 
179  inline void enable(void)
180  {
181  m_isEnabled = true;
182  }
183 
184  /**
185  * Disables event raising.
186  */
187 
188  inline void disable(void)
189  {
190  m_isEnabled = false;
191  }
192 
193  /**
194  * Raise a click event to the event handler.
195  *
196  * @param x The x coordinate of the click.
197  * @param y The y coordinate of the click.
198  */
199 
200  void raiseClickEvent(nxgl_coord_t x, nxgl_coord_t y);
201 
202  /**
203  * Raise a double-click event to the event handler.
204  *
205  * @param x The x coordinate of the click.
206  * @param y The y coordinate of the click.
207  */
208 
209  void raiseDoubleClickEvent(nxgl_coord_t x, nxgl_coord_t y);
210 
211  /**
212  * Raise a mouse release event to the event handler.
213  *
214  * @param x The x coordinate of the release.
215  * @param y The y coordinate of the release.
216  */
217 
218  void raiseReleaseEvent(nxgl_coord_t x, nxgl_coord_t y);
219 
220  /**
221  * Raise a mouse release-outside event to the event handler.
222  *
223  * @param x The x coordinate of the release.
224  * @param y The y coordinate of the release.
225  */
226 
227  void raiseReleaseOutsideEvent(nxgl_coord_t x, nxgl_coord_t y);
228 
229  /**
230  * Raise a mouse drag event to the event handler.
231  *
232  * @param x The x coordinate of the mouse when the drag started.
233  * @param y The y coordinate of the mouse when the drag started.
234  * @param vX The horizontal distance dragged.
235  * @param vY The vertical distance dragged.
236  */
237 
238  void raiseDragEvent(nxgl_coord_t x, nxgl_coord_t y,
239  nxgl_coord_t vX, nxgl_coord_t vY);
240 
241  /**
242  * Raise a widget drop event to the event handler.
243  *
244  * @param x The x coordinate of the mouse when the drop occurred.
245  * @param y The y coordinate of the mouse when the drop occurred.
246  */
247 
248  void raiseDropEvent(nxgl_coord_t x, nxgl_coord_t y);
249 
250  /**
251  * Raise a key press event to the event handler.
252  *
253  * @param key The character code of the key that caused the event.
254  */
255 
257 
258  /**
259  * Raise a cursor control event to the event handler.
260  *
261  * @param cursorControl The cursor control code that caused the event.
262  */
263 
264  void raiseCursorControlEvent(ECursorControl cursorControl);
265 
266  /**
267  * Raise a focus event to the event handler.
268  */
269 
270  void raiseFocusEvent(void);
271 
272  /**
273  * Raise a blur event to the event handler.
274  */
275 
276  void raiseBlurEvent(void);
277 
278  /**
279  * Raise a close event to the event handler.
280  */
281 
282  void raiseCloseEvent(void);
283 
284  /**
285  * Raise a hide event to the event handler.
286  */
287 
288  void raiseHideEvent(void);
289 
290  /**
291  * Raise a show event to the event handler.
292  */
293 
294  void raiseShowEvent(void);
295 
296  /**
297  * Raise an enable event to the event handler.
298  */
299 
300  void raiseEnableEvent(void);
301 
302  /**
303  * Raise a disable event to the event handler.
304  */
305 
306  void raiseDisableEvent(void);
307 
308  /**
309  * Raise a value change event to the event handler.
310  */
311 
312  void raiseValueChangeEvent(void);
313 
314  /**
315  * Raise a resize event to the event handler.
316  *
317  * @param width The new width of the widget.
318  * @param height The new height of the widget.
319  */
320 
321  void raiseResizeEvent(nxgl_coord_t width, nxgl_coord_t height);
322 
323  /**
324  * Raise a move event to the event handler.
325  *
326  * @param x The new x coordinate of the widget.
327  * @param y The new y coordinate of the widget.
328  * @param vX The horizontal distance moved.
329  * @param vY The vertical distance moved.
330  */
331 
332  void raiseMoveEvent(nxgl_coord_t x, nxgl_coord_t y,
333  nxgl_coord_t vX, nxgl_coord_t vY);
334 
335  /**
336  * Raise an action event to the event handler. This should be called
337  * when a widget's purpose has been fulfilled. For example, in the case
338  * of a button, this event is raised when the button is released within
339  * its boundaries. The button has produced a valid click, and thus
340  * fulfilled its purpose, so it needs to raise an "action" event.
341  */
342 
343  void raiseActionEvent(void);
344 
345  /**
346  * Raises a scroll event. Fired when the panel scrolls.
347  *
348  * @param vX Horizontal distance scrolled.
349  * @param vY Vertical distance scrolled.
350  */
351 
352  void raiseScrollEvent(nxgl_coord_t vX, nxgl_coord_t vY);
353  };
354 }
355 
356 #endif // __cplusplus
357 
358 #endif // __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX
void raiseScrollEvent(nxgl_coord_t vX, nxgl_coord_t vY)
void raiseDragEvent(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t vX, nxgl_coord_t vY)
void raiseResizeEvent(nxgl_coord_t width, nxgl_coord_t height)
void raiseCursorControlEvent(ECursorControl cursorControl)
void raiseDoubleClickEvent(nxgl_coord_t x, nxgl_coord_t y)
void addWidgetEventHandler(CWidgetEventHandler *eventHandler)
void raiseMoveEvent(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t vX, nxgl_coord_t vY)
uint16_t nxwidget_char_t
Definition: nxconfig.hxx:454
TNxArray< CWidgetEventHandler * > m_widgetEventHandlers
CWidgetEventHandler * at(int index) const
void raiseReleaseOutsideEvent(nxgl_coord_t x, nxgl_coord_t y)
void raiseClickEvent(nxgl_coord_t x, nxgl_coord_t y)
void removeWidgetEventHandler(CWidgetEventHandler *eventHandler)
const int size(void) const
Definition: tnxarray.hxx:261
T & at(const int index) const
Definition: tnxarray.hxx:404
void raiseReleaseEvent(nxgl_coord_t x, nxgl_coord_t y)
void raiseDropEvent(nxgl_coord_t x, nxgl_coord_t y)