NXWidgets: cwidgeteventargs.hxx Source File

NXWidgets 1.19

cwidgeteventargs.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cwidgeteventargs.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_CWIDGETEVENTARGS_HXX
71 #define __INCLUDE_CWIDGETEVENTARGS_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 "nxconfig.hxx"
85 #include "teventargs.hxx"
86
87 /****************************************************************************
88 * Pre-Processor Definitions
89 ****************************************************************************/
90 /* Interesting Key events ***************************************************/
91
92 #define KEY_CODE_NONE ((nxwidget_char_t)0x00) /**< No key (NUL) */
93 #define KEY_CODE_BACKSPACE ((nxwidget_char_t)0x08) /**< Backspace key */
94 #define KEY_CODE_DELETE ((nxwidget_char_t)0x7f) /**< Delete key */
95 #define KEY_CODE_ENTER ((nxwidget_char_t)0x0d) /**< Enter key (carriage return) */
96
97 /****************************************************************************
98 * Implementation Classes
99 ****************************************************************************/
100
101 #if defined(__cplusplus)
102
103 namespace NXWidgets
104 {
105 class CNxWidget;
106
107 /**
108 * Cursor control events
109 */
110
111 typedef enum
112 {
113 CURSOR_HOME = 1, // Set the cursor to the beginning
114 CURSOR_END, // Set the cursor to the end
115 CURSOR_UP, // Set the cursor up one row
116 CURSOR_DOWN, // Set the cursor down one row
117 CURSOR_LEFT, // Move the cursor left one column
118 CURSOR_RIGHT, // Move the cursor right one column
119 CURSOR_PAGEUP, // Move the cursor up one page
120 CURSOR_PAGEDOWN, // Move the cursor down one page
121 } ECursorControl;
122
123 /**
124 * Event arguments passed to listeners when a CNxWidget object raises an event.
125 */
126
127 class CWidgetEventArgs : public TEventArgs<CNxWidget*>
128 {
129 private:
130 nxgl_coord_t m_x; /**< X coordinateinate of the event. */
131 nxgl_coord_t m_y; /**< Y coordinateinate of the event. */
132 nxgl_coord_t m_vX; /**< X distance moved during event, for dragging. */
133 nxgl_coord_t m_vY; /**< Y distance moved during event, for dragging. */
134 nxwidget_char_t m_key; /**< The key code / cursor code that raised the event. */
135
136 public:
137
138 /**
139 * Constructor.
140 *
141 * @param source Pointer to the CNxWidget object that raised the event.
142 * @param x The x coordinate of the event.
143 * @param y The y coordinate of the event.
144 * @param vX The x distance of the event.
145 * @param vY The y distance of the event.
146 * @param keyCode The keycode of the event.
147 */
148
149 CWidgetEventArgs(CNxWidget *source, const nxgl_coord_t x, const nxgl_coord_t y,
150 const nxgl_coord_t vX, const nxgl_coord_t vY,
151 const nxwidget_char_t key)
152 : TEventArgs<CNxWidget*>(source)
153 {
154 m_x = x;
155 m_y = y;
156 m_vX = vX;
157 m_vY = vY;
158 m_key = key;
159 }
160
161 /**
162 * Get the x coordinate of the mouse event. Applies only to the following
163 * events: mouse click, mouse double click, mouse drag, mouse release
164 *
165 * @return The x coordinate of the event.
166 */
167
168 inline const nxgl_coord_t getX(void) const
169 {
170 return m_x;
171 }
172
173 /**
174 * Get the y coordinate of the mouse event. Applies only to the following
175 * events: mouse click, mouse double click, mouse drag, mouse release
176 *
177 * @return The y coordinate of the event.
178 */
179
180 inline const nxgl_coord_t getY(void) const
181 {
182 return m_y;
183 }
184
185 /**
186 * Get the x-axis mouse move distance of the mouse event. Applies
187 * only to the mouse drag event.
188 *
189 * @return The x-axis mouse move distance of the event.
190 */
191
192 inline const nxgl_coord_t getVX(void) const
193 {
194 return m_vX;
195 }
196
197 /**
198 * Get the y-axis mouse move distance of the event. Applies
199 * only to the mouse drag event.
200 *
201 * @return The y-axis mouse move distance of the event.
202 */
203
204 inline const nxgl_coord_t getVY(void) const
205 {
206 return m_vY;
207 }
208
209 /**
210 * Get the key press that generated the event. Applies only to
211 * the key press event.
212 *
213 * @return The key that generated the event.
214 */
215
216 inline const nxwidget_char_t getKey(void) const
217 {
218 return m_key;
219 }
220
221 /**
222 * Get the cursor control that generated the event. Applies only
223 * to the cursor control event.
224 *
225 * @return The cursor control that generated the event.
226 */
227
228 inline const ECursorControl getCursorControl(void) const
229 {
230 return (ECursorControl)m_key;
231 }
232 };
233 }
234
235 #endif // __cplusplus
236
237 #endif // __INCLUDE_CWIDGETEVENTARGS_HXX
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CWidgetEventArgs::m_vY
nxgl_coord_t m_vY
Definition: cwidgeteventargs.hxx:133
NXWidgets::CURSOR_PAGEUP
Definition: cwidgeteventargs.hxx:119
NXWidgets::CURSOR_LEFT
Definition: cwidgeteventargs.hxx:117
NXWidgets::CWidgetEventArgs::m_key
nxwidget_char_t m_key
Definition: cwidgeteventargs.hxx:134
NXWidgets::CWidgetEventArgs::m_vX
nxgl_coord_t m_vX
Definition: cwidgeteventargs.hxx:132
NXWidgets::CWidgetEventArgs::m_x
nxgl_coord_t m_x
Definition: cwidgeteventargs.hxx:130
teventargs.hxx
NXWidgets::CURSOR_RIGHT
Definition: cwidgeteventargs.hxx:118
NXWidgets::CWidgetEventArgs::m_y
nxgl_coord_t m_y
Definition: cwidgeteventargs.hxx:131
NXWidgets::CURSOR_END
Definition: cwidgeteventargs.hxx:114
NXWidgets::CWidgetEventArgs::getX
const nxgl_coord_t getX(void) const
Definition: cwidgeteventargs.hxx:168
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CWidgetEventArgs::getVY
const nxgl_coord_t getVY(void) const
Definition: cwidgeteventargs.hxx:204
NXWidgets::CWidgetEventArgs::getVX
const nxgl_coord_t getVX(void) const
Definition: cwidgeteventargs.hxx:192
NXWidgets::nxwidget_char_t
uint16_t nxwidget_char_t
Definition: nxconfig.hxx:454
nxconfig.hxx
NXWidgets::CWidgetEventArgs::getKey
const nxwidget_char_t getKey(void) const
Definition: cwidgeteventargs.hxx:216
NXWidgets::CWidgetEventArgs::getY
const nxgl_coord_t getY(void) const
Definition: cwidgeteventargs.hxx:180
NXWidgets::CURSOR_UP
Definition: cwidgeteventargs.hxx:115
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
NXWidgets::ECursorControl
ECursorControl
Definition: cwidgeteventargs.hxx:111
NXWidgets::CURSOR_HOME
Definition: cwidgeteventargs.hxx:113
NXWidgets::TEventArgs
Definition: teventargs.hxx:100
NXWidgets::CURSOR_PAGEDOWN
Definition: cwidgeteventargs.hxx:120
NXWidgets::CURSOR_DOWN
Definition: cwidgeteventargs.hxx:116
NXWidgets::CWidgetEventArgs::CWidgetEventArgs
CWidgetEventArgs(CNxWidget *source, const nxgl_coord_t x, const nxgl_coord_t y, const nxgl_coord_t vX, const nxgl_coord_t vY, const nxwidget_char_t key)
Definition: cwidgeteventargs.hxx:149
NXWidgets::CWidgetEventArgs::getCursorControl
const ECursorControl getCursorControl(void) const
Definition: cwidgeteventargs.hxx:228