NXWidgets: ccallback.hxx Source File

NXWidgets 1.19

ccallback.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/ccallback.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 #ifndef __INCLUDE_CCALLBACK_HXX
37 #define __INCLUDE_CCALLBACK_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/config.h>
44
45 #include <sys/types.h>
46 #include <stdint.h>
47 #include <stdbool.h>
48
49 #include <nuttx/nx/nxglib.h>
50 #include <nuttx/nx/nx.h>
51
52 #ifdef CONFIG_NXTERM_NXKBDIN
53 # include <nuttx/nx/nxterm.h>
54 #endif
55
56 #include "crect.hxx"
57
58 /****************************************************************************
59 * Pre-Processor Definitions
60 ****************************************************************************/
61
62 /****************************************************************************
63 * Implementation Classes
64 ****************************************************************************/
65
66 #if defined(__cplusplus)
67
68 namespace NXWidgets
69 {
70 class CWidgetControl;
71
72 /**
73 * Callback function proxies. This class receives and dispatches callbacks
74 * from the NX server. This calls also manages a few lower-level details
75 * such as keeping track of the reported window handles and window positions
76 * and sizes.
77 *
78 * There are three instances that represent an NX window from the
79 * perspective of NXWidgets.
80 *
81 * - There is one widget control instance per NX window,
82 * - One CCallback instance per window,
83 * - One window instance.
84 *
85 * There a various kinds of of window instances, but each inherits
86 * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
87 * that describes the common window behavior.
88
89 */
90
91 class CCallback
92 {
93 private:
94 CWidgetControl *m_widgetControl; /**< The widget control instance for this window */
95 struct nx_callback_s m_callbacks; /**< C-callable vtable of callback function pointers */
96 #ifdef CONFIG_NXTERM_NXKBDIN
97 NXTERM m_nxterm; /**< The NxTerm handle for redirection of keyboard input */
98 #endif
99
100 // Methods in the callback vtable
101
102 /**
103 * Re-Draw Callback. The redraw event is handled by CWidgetControl::redrawEvent.
104 *
105 * NOTE: This method runs in the context of the NX callback which may
106 * either be the context of the owning thread or, in the case of multi-
107 * user NX, the context of the NX event listener thread.
108 *
109 * @param hwnd Handle to a specific NX window.
110 * @param rect The rectangle that needs to be re-drawn (in window
111 * relative coordinates).
112 * @param bMore true: More re-draw requests will follow.
113 * @param arg User provided argument (see nx_openwindow, nx_requestbg,
114 * nxtk_openwindow, or nxtk_opentoolbar).
115 */
116
117 static void redraw(NXHANDLE hwnd, FAR const struct nxgl_rect_s *rect,
118 bool bMore, FAR void *arg);
119
120 /**
121 * Position Callback. The new positional data is handled by
122 * CWidgetControl::geometryEvent.
123 *
124 * NOTE: This method runs in the context of the NX callback which may
125 * either be the context of the owning thread or, in the case of multi-
126 * user NX, the context of the NX event listener thread.
127 *
128 * @param hwnd Handle to a specific NX window.
129 * @param size The size of the window.
130 * @param pos The position of the upper left hand corner of the window on
131 * the overall display.
132 * @param bounds The bounding rectangle that describes the entire display.
133 * @param arg User provided argument (see nx_openwindow, nx_requestbg,
134 * nxtk_openwindow, or nxtk_opentoolbar).
135 */
136
137 static void position(NXHANDLE hwnd, FAR const struct nxgl_size_s *size,
138 FAR const struct nxgl_point_s *pos,
139 FAR const struct nxgl_rect_s *bounds,
140 FAR void *arg);
141
142 /**
143 * New mouse data is available for the window. The new mouse
144 * data is handled by CWidgetControl::newMouseEvent.
145 *
146 * NOTE: This method runs in the context of the NX callback which may
147 * either be the context of the NX event listener thread (if multi-
148 * user NX), or possibly in the connects of device driver or even a
149 * device driver interrupt.
150 *
151 * The GUI thread is probably sleeping a semaphore, waiting to be
152 * awakened by a mouse or keyboard event.
153 *
154 * @param hwnd Handle to a specific NX window.
155 * @param pos The (x,y) position of the mouse.
156 * @param buttons See NX_MOUSE_* definitions.
157 * @param arg User provided argument (see nx_openwindow, nx_requestbg,
158 * nxtk_openwindow, or nxtk_opentoolbar).
159 */
160
161 #ifdef CONFIG_NX_XYINPUT
162 static void newMouseEvent(NXHANDLE hwnd,
163 FAR const struct nxgl_point_s *pos,
164 uint8_t buttons, FAR void *arg);
165 #endif /* CONFIG_NX_XYINPUT */
166
167 /**
168 * New keyboard/keypad data is available for the window. The new
169 * keyboard data is handled by CWidgetControl::newKeyboardEvent.
170 *
171 * NOTE: This method runs in the context of the NX callback which may
172 * either be the context of the NX event listener thread (if multi-
173 * user NX), or possibly in the connects of device driver or even a
174 * device driver interrupt.
175 *
176 * The GUI thread is probably sleeping a semaphore, waiting to be
177 * awakened by a mouse or keyboard event.
178 *
179 * @param hwnd Handle to a specific NX window.
180 * @param nCh The number of characters that are available in str[].
181 * @param str The array of characters.
182 * @param arg User provided argument (see nx_openwindow, nx_requestbg,
183 * nxtk_openwindow, or nxtk_opentoolbar).
184 */
185
186 #ifdef CONFIG_NX_KBD
187 static void newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh,
188 FAR const uint8_t *str, FAR void *arg);
189 #endif // CONFIG_NX_KBD
190
191 /**
192 * This callback is the response from nx_block (or nxtk_block). Those
193 * blocking interfaces are used to assure that no further messages are
194 * directed to the window. Receipt of the blocked callback signifies
195 * that (1) there are no further pending callbacks and (2) that the
196 * window is now 'defunct' and will receive no further callbacks.
197 *
198 * This callback supports coordinated destruction of a window in multi-
199 * user mode. In multi-use mode, the client window logic must stay
200 * intact until all of the queued callbacks are processed. Then the
201 * window may be safely closed. Closing the window prior with pending
202 * callbacks can lead to bad behavior when the callback is executed.
203 *
204 * @param hwnd. Window handle of the blocked window
205 * @param arg1. User provided argument (see nx_openwindow, nx_requestbkgd,
206 * nxtk_openwindow, or nxtk_opentoolbar)
207 * @param arg2 - User provided argument (see nx_block or nxtk_block)
208 */
209
210 static void windowBlocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2);
211
212 public:
213
214 /**
215 * Constructor.
216 *
217 * @param widgetControl Control object associated with this window
218 */
219
220 CCallback(CWidgetControl *widgetControl);
221
222 /**
223 * Destructor.
224 */
225
226 inline ~CCallback(void) {}
227
228 /**
229 * Get the callback vtable. This is neeed only by the window
230 * instance that inherits this class. The window instance needs the
231 * C-callable vtable in order to create the NX window. Once the
232 * window is created, this class will begin to receive callbacks via
233 * the C-callable vtable methods.
234 *
235 * @return This method returns the C-callable vtable needed for
236 * NX window creation.
237 */
238
239 inline FAR struct nx_callback_s *getCallbackVTable(void)
240 {
241 return &m_callbacks;
242 }
243
244 /**
245 * By default, NX keyboard input is given to the various widgets
246 * residing in the window. But NxTerm is a different usage model;
247 * In this case, keyboard input needs to be directed to the NxTerm
248 * character driver. This method can be used to enable (or disable)
249 * redirection of NX keyboard input from the window widgets to the
250 * NxTerm
251 *
252 * @param handle. The NXTERM handle. If non-NULL, NX keyboard
253 * input will be directed to the NxTerm driver using this
254 * handle; If NULL (the default), NX keyboard input will be
255 * directed to the widgets within the window.
256 */
257
258 #ifdef CONFIG_NXTERM_NXKBDIN
259 inline void setNxTerm(NXTERM handle)
260 {
261 m_nxterm = handle;
262 }
263 #endif
264 };
265 }
266
267 #endif // __cplusplus
268
269 #endif // __INCLUDE_CCALLBACK_HXX
270
NXWidgets::CCallback::windowBlocked
static void windowBlocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2)
Definition: ccallback.cxx:249
NXWidgets::CCallback
Definition: ccallback.hxx:91
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CCallback::newKeyboardEvent
static void newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh, FAR const uint8_t *str, FAR void *arg)
Definition: ccallback.cxx:198
NXWidgets::CCallback::m_callbacks
struct nx_callback_s m_callbacks
Definition: ccallback.hxx:95
NXWidgets::CCallback::m_widgetControl
CWidgetControl * m_widgetControl
Definition: ccallback.hxx:94
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CCallback::CCallback
CCallback(CWidgetControl *widgetControl)
Definition: ccallback.cxx:70
NXWidgets::CCallback::setNxTerm
void setNxTerm(NXTERM handle)
Definition: ccallback.hxx:259
NXWidgets::CCallback::newMouseEvent
static void newMouseEvent(NXHANDLE hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg)
Definition: ccallback.cxx:169
NXWidgets::CCallback::~CCallback
~CCallback(void)
Definition: ccallback.hxx:226
NXWidgets::CCallback::m_nxterm
NXTERM m_nxterm
Definition: ccallback.hxx:97
NXWidgets::CCallback::position
static void position(NXHANDLE hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg)
Definition: ccallback.cxx:137
NXWidgets::CCallback::redraw
static void redraw(NXHANDLE hwnd, FAR const struct nxgl_rect_s *rect, bool bMore, FAR void *arg)
Definition: ccallback.cxx:106
NXWidgets::CCallback::getCallbackVTable
FAR struct nx_callback_s * getCallbackVTable(void)
Definition: ccallback.hxx:239
crect.hxx