NXWidgets  1.19
ccallback.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/src/ccallback.cxx
3  *
4  * Copyright (C) 2012-2013 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 /****************************************************************************
37  * Included Files
38  ****************************************************************************/
39 
40 #include <nuttx/config.h>
41 
42 #include <sys/types.h>
43 #include <stdint.h>
44 #include <stdbool.h>
45 #include <debug.h>
46 
47 #ifdef CONFIG_NXTERM_NXKBDIN
48 # include <nuttx/nx/nxterm.h>
49 #endif
50 
51 #include "cwidgetcontrol.hxx"
52 #include "ccallback.hxx"
53 
54 /****************************************************************************
55  * Pre-Processor Definitions
56  ****************************************************************************/
57 
58 /****************************************************************************
59  * Method Implementations
60  ****************************************************************************/
61 
62 using namespace NXWidgets;
63 
64  /**
65  * Constructor.
66  *
67  * @param widgetControl Control object associated with this window
68  */
69 
71 {
72  // Save the widgetControl
73 
74  m_widgetControl = widgetControl;
75 
76  // Initialize the callback vtable
77 
78  m_callbacks.redraw = redraw;
79  m_callbacks.position = position;
80 #ifdef CONFIG_NX_XYINPUT
81  m_callbacks.mousein = newMouseEvent;
82 #endif
83 #ifdef CONFIG_NX_KBD
85 #endif
86  m_callbacks.blocked = windowBlocked;
87 
88  // Keyboard input is initially direct to the widgets within the window
89 
90 #ifdef CONFIG_NXTERM_NXKBDIN
91  m_nxterm = (NXTERM)0;
92 #endif
93 }
94 
95  /**
96  * ReDraw Callback. The redraw action is handled by CWidgetControl:redrawEvent.
97  *
98  * @param hwnd Handle to a specific NX window.
99  * @param rect The rectangle that needs to be re-drawn (in window
100  * relative coordinates).
101  * @param bMore true: More re-draw requests will follow.
102  * @param arg User provided argument (see nx_openwindow, nx_requestbg,
103  * nxtk_openwindow, or nxtk_opentoolbar).
104  */
105 
106 void CCallback::redraw(NXHANDLE hwnd,
107  FAR const struct nxgl_rect_s *rect,
108  bool bMore, FAR void *arg)
109 {
110  ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} bMore=%s\n",
111  hwnd,
112  rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
113  bMore ? "true" : "false");
114 
115  // The argument must be the CCallback instance
116 
117  CCallback *This = (CCallback *)arg;
118 
119  // Just forward the callback to the CWidgetControl::redrawEvent method
120 
121  This->m_widgetControl->redrawEvent(rect, bMore);
122 }
123 
124  /**
125  * Position Callback. The new positional data is handled by
126  * CWidgetControl::geometryEvent.
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 void CCallback::position(NXHANDLE hwnd,
138  FAR const struct nxgl_size_s *size,
139  FAR const struct nxgl_point_s *pos,
140  FAR const struct nxgl_rect_s *bounds,
141  FAR void *arg)
142 {
143  ginfo("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)} arg=%p\n",
144  hwnd, size->w, size->h, pos->x, pos->y,
145  bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y,
146  arg);
147 
148  // The argument must be the CCallback instance
149 
150  CCallback *This = (CCallback *)arg;
151 
152  // Just forward the callback to the CWidgetControl::geometry method
153 
154  This->m_widgetControl->geometryEvent(hwnd, size, pos, bounds);
155 }
156 
157  /**
158  * New mouse data is available for the window. The new mouse data is
159  * handled by CWidgetControl::newMouseEvent.
160  *
161  * @param hwnd Handle to a specific NX window.
162  * @param pos The (x,y) position of the mouse.
163  * @param buttons See NX_MOUSE_* definitions.
164  * @param arg User provided argument (see nx_openwindow, nx_requestbg,
165  * nxtk_openwindow, or nxtk_opentoolbar).
166  */
167 
168 #ifdef CONFIG_NX_XYINPUT
169 void CCallback::newMouseEvent(NXHANDLE hwnd,
170  FAR const struct nxgl_point_s *pos,
171  uint8_t buttons, FAR void *arg)
172 {
173  ginfo("hwnd=%p pos=(%d,%d) buttons=%02x arg=%p\n",
174  hwnd, pos->x, pos->y, buttons, arg);
175 
176  // The argument must be the CCallback instance
177 
178  CCallback *This = (CCallback *)arg;
179 
180  // Just forward the callback to the CWidgetControl::newMouseEvent method
181 
182  This->m_widgetControl->newMouseEvent(pos, buttons);
183 }
184 #endif /* CONFIG_NX_XYINPUT */
185 
186 /**
187  * New keyboard/keypad data is available for the window. The new keyboard
188  * data is handled by CWidgetControl::newKeyboardEvent.
189  *
190  * @param hwnd Handle to a specific NX window.
191  * @param nCh The number of characters that are available in str[].
192  * @param str The array of characters.
193  * @param arg User provided argument (see nx_openwindow, nx_requestbg,
194  * nxtk_openwindow, or nxtk_opentoolbar).
195  */
196 
197 #ifdef CONFIG_NX_KBD
198 void CCallback::newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh,
199  FAR const uint8_t *str,
200  FAR void *arg)
201 {
202  ginfo("hwnd=%p nCh=%d arg=%p\n", hwnd, nCh, arg);
203 
204  // The argument must be the CCallback instance
205 
206  CCallback *This = (CCallback *)arg;
207 
208  // Is NX keyboard input being directed to the widgets within the window
209  // (default) OR is NX keyboard input being re-directed to an NxTerm
210  // driver?
211 
212 #ifdef CONFIG_NXTERM_NXKBDIN
213  if (This->m_nxterm)
214  {
215  // Keyboard input is going to an NxTerm
216 
217  nxterm_kbdin(This->m_nxterm, str, nCh);
218  }
219  else
220 #endif
221  {
222  // Just forward the callback to the CWidgetControl::newKeyboardEvent method
223 
224  This->m_widgetControl->newKeyboardEvent(nCh, str);
225  }
226 }
227 
228 #endif // CONFIG_NX_KBD
229 
230 /**
231  * This callback is the response from nx_block (or nxtk_block). Those
232  * blocking interfaces are used to assure that no further messages are
233  * directed to the window. Receipt of the blocked callback signifies
234  * that (1) there are no further pending callbacks and (2) that the
235  * window is now 'defunct' and will receive no further callbacks.
236  *
237  * This callback supports coordinated destruction of a window in multi-
238  * user mode. In multi-use more, the client window logic must stay
239  * intact until all of the queued callbacks are processed. Then the
240  * window may be safely closed. Closing the window prior with pending
241  * callbacks can lead to bad behavior when the callback is executed.
242  *
243  * @param hwnd. Window handle of the blocked window
244  * @param arg1. User provided argument (see nx_openwindow, nx_requestbkgd,
245  * nxtk_openwindow, or nxtk_opentoolbar)
246  * @param arg2 - User provided argument (see nx_block or nxtk_block)
247  */
248 
249 void CCallback::windowBlocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2)
250 {
251  ginfo("hwnd=%p arg1=%p arg2=%p\n", hwnd, arg1, arg2);
252 
253  // The first argument must be the CCallback instance
254 
255  CCallback *This = (CCallback *)arg1;
256 
257  // Just forward the callback to the CWidgetControl::windowBlocked method
258 
259  This->m_widgetControl->windowBlocked(arg2);
260 }
261 
static void windowBlocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2)
Definition: ccallback.cxx:249
void windowBlocked(FAR void *arg)
static void newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh, FAR const uint8_t *str, FAR void *arg)
Definition: ccallback.cxx:198
struct nx_callback_s m_callbacks
Definition: ccallback.hxx:95
void redrawEvent(FAR const struct nxgl_rect_s *nxRect, bool more)
CWidgetControl * m_widgetControl
Definition: ccallback.hxx:94
CCallback(CWidgetControl *widgetControl)
Definition: ccallback.cxx:70
static void newMouseEvent(NXHANDLE hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg)
Definition: ccallback.cxx:169
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
void geometryEvent(NXHANDLE hWindow, const struct nxgl_size_s *size, const struct nxgl_point_s *pos, const struct nxgl_rect_s *bounds)
void newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr)
static void redraw(NXHANDLE hwnd, FAR const struct nxgl_rect_s *rect, bool bMore, FAR void *arg)
Definition: ccallback.cxx:106
void newMouseEvent(FAR const struct nxgl_point_s *pos, uint8_t buttons)