NXWidgets: cnxtkwindow.hxx Source File

NXWidgets 1.19

cnxtkwindow.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cnxtkwindow.hxx
3 *
4 * Copyright (C) 2012, 2015 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_CNXTKWINDOW_HXX
37 #define __INCLUDE_CNXTKWINDOW_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/config.h>
44
45 #include <stdint.h>
46 #include <stdbool.h>
47
48 #include <nuttx/nx/nxglib.h>
49 #include <nuttx/nx/nx.h>
50 #include <nuttx/nx/nxtk.h>
51
52 #include "ccallback.hxx"
53 #include "inxwindow.hxx"
54
55 /****************************************************************************
56 * Pre-Processor Definitions
57 ****************************************************************************/
58
59 /****************************************************************************
60 * Implementation Classes
61 ****************************************************************************/
62
63 #if defined(__cplusplus)
64
65 namespace NXWidgets
66 {
67 class CNxToolbar;
68 struct SBitmap;
69
70 /**
71 * This class defines operations on a framed NX window.
72 * There are three instances that represent an NX window from the
73 * perspective of NXWidgets.
74 *
75 * - There is one widget control instance per NX window,
76 * - One CCallback instance per window,
77 * - One window instance.
78 *
79 * There a various kinds of of window instances, but each inherits
80 * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
81 * that describes the common window behavior.
82 */
83
84 class CNxTkWindow : protected CCallback, public INxWindow
85 {
86 protected:
87 NXHANDLE m_hNxServer; /**< Handle to the NX server. */
88 NXTKWINDOW m_hNxTkWindow; /**< Handle to the NX raw window */
89 CWidgetControl *m_widgetControl; /**< Controlling widget for the window */
90 CNxToolbar *m_toolbar; /**< Child toolbar */
91 nxgl_coord_t m_toolbarHeight; /**< The height of the toolbar */
92
93 public:
94
95 /**
96 * Constructor. Creates an uninitialized instance of the CNxTkWindow
97 * object. The open() method must be called to initialize the instance.
98 *
99 * The general steps to create any window include:
100 * 1) Create a dumb CWigetControl instance
101 * 2) Pass the dumb CWidgetControl instance to the window constructor
102 * that inherits from INxWindow.
103 * 3) The window constructor call CWidgetControl methods to "smarten"
104 * the CWidgetControl instance with window-specific knowledge.
105 * 4) Call the open() method on the window to display the window.
106 * 5) After that, the fully smartened CWidgetControl instance can
107 * be used to generate additional widgets.
108 * 6) After that, the fully smartened CWidgetControl instance can
109 * be used to generate additional widgets by passing it to the
110 * widget constructor
111 *
112 * @param hNxServer Handle to the NX server.
113 * @param widgetControl Controlling widget for this window.
114 */
115
116 CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
117
118 /**
119 * Destructor.
120 */
121
122 ~CNxTkWindow(void);
123
124 /**
125 * Creates a new window. Window creation is separate from
126 * object instantiation so that failures can be reported.
127 *
128 * @return True if the window was successfully opened.
129 */
130
131 bool open(void);
132
133 /**
134 * Each implementation of INxWindow must provide a method to recover
135 * the contained CWidgetControl instance.
136 *
137 * @return The contained CWidgetControl instance
138 */
139
140 CWidgetControl *getWidgetControl(void) const;
141
142 /**
143 * Open a toolbar on the framed window. This method both instantiates
144 * the toolbar object AND calls the INxWindow::open() method to
145 * create the toolbar. The toolbar is ready for use upon return.
146 *
147 * @param height. The height in rows of the tool bar
148 * @param widgetControl. The controlling widget for this window. If
149 * none is provided, then a new, vanilla CWidgetControl will be created
150 * for the tool bar.
151 * @return True if the toolbar was successfully created.
152 */
153
154 CNxToolbar *openToolbar(nxgl_coord_t height,
155 CWidgetControl *widgetControl = (CWidgetControl *)0);
156
157 /**
158 * Detach the toolbar. This should *ONLY* be called by the toolbar
159 * instance itself. If this is called by end-user logic, it will
160 * screw things up miserably.
161 */
162
163 inline void detachToolbar(void)
164 {
165 m_toolbar = (CNxToolbar *)NULL;
166 m_toolbarHeight = 0;
167 }
168
169 /**
170 * Request the position and size information of the window. The values
171 * will be returned asynchronously through the client callback method.
172 * The GetPosition() method may than be called to obtain the positional
173 * data as provided by the callback.
174 *
175 * @return True on success, false on any failure.
176 */
177
178 bool requestPosition(void);
179
180 /**
181 * Get the position of the window (as reported by the NX callback).
182 *
183 * @return True on success, false on any failure.
184 */
185
186 bool getPosition(FAR struct nxgl_point_s *pos);
187
188 /**
189 * Get the size of the window (as reported by the NX callback).
190 *
191 * @return The size.
192 */
193
194 bool getSize(FAR struct nxgl_size_s *size);
195
196 /**
197 * Set the position and size of the window.
198 *
199 * @param pos The new position of the window.
200 * @return True on success, false on any failure.
201 */
202
203 bool setPosition(FAR const struct nxgl_point_s *pos);
204
205 /**
206 * Set the size of the selected window.
207 *
208 * @param size The new size of the window.
209 * @return True on success, false on any failure.
210 */
211
212 bool setSize(FAR const struct nxgl_size_s *size);
213
214 /**
215 * Bring the window to the top of the display.
216 *
217 * @return True on success, false on any failure.
218 */
219
220 bool raise(void);
221
222 /**
223 * Lower the window to the bottom of the display.
224 *
225 * @return True on success, false on any failure.
226 */
227
228 bool lower(void);
229
230 /**
231 * Each window implementation also inherits from CCallback. CCallback,
232 * by default, forwards NX keyboard input to the various widgets residing
233 * in the window. But NxTerm is a different usage model; In this case,
234 * keyboard input needs to be directed to the NxTerm character driver.
235 * This method can be used to enable (or disable) redirection of NX
236 * keyboard input from the window widgets to the NxTerm
237 *
238 * @param handle. The NXTERM handle. If non-NULL, NX keyboard
239 * input will be directed to the NxTerm driver using this
240 * handle; If NULL (the default), NX keyboard input will be
241 * directed to the widgets within the window.
242 */
243
244 #ifdef CONFIG_NXTERM_NXKBDIN
245 inline void redirectNxTerm(NXTERM handle)
246 {
247 setNxTerm(handle);
248 }
249 #endif
250
251 /**
252 * Set an individual pixel in the window with the specified color.
253 *
254 * @param pos The location of the pixel to be filled.
255 * @param color The color to use in the fill.
256 *
257 * @return True on success; false on failure.
258 */
259
260 bool setPixel(FAR const struct nxgl_point_s *pos,
261 nxgl_mxpixel_t color);
262
263 /**
264 * Fill the specified rectangle in the window with the specified color.
265 *
266 * @param pRect The location to be filled.
267 * @param color The color to use in the fill.
268 *
269 * @return True on success; false on failure.
270 */
271
272 bool fill(FAR const struct nxgl_rect_s *pRect,
273 nxgl_mxpixel_t color);
274
275 /**
276 * Get the raw contents of graphic memory within a rectangular region. NOTE:
277 * Since raw graphic memory is returned, the returned memory content may be
278 * the memory of windows above this one and may not necessarily belong to
279 * this window unless you assure that this is the top window.
280 *
281 * @param rect The location to be copied
282 * @param dest - The describes the destination bitmap to receive the
283 * graphics data.
284 */
285
286 void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
287
288 /**
289 * Fill the specified trapezoidal region in the window with the specified
290 * color.
291 *
292 * @param pClip Clipping rectangle relative to window (may be null).
293 * @param pTrap The trapezoidal region to be filled.
294 * @param color The color to use in the fill.
295 *
296 * @return True on success; false on failure.
297 */
298
299 bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
300 FAR const struct nxgl_trapezoid_s *pTrap,
301 nxgl_mxpixel_t color);
302
303 /**
304 * Fill the specified line in the window with the specified color.
305 *
306 * @param vector - Describes the line to be drawn
307 * @param width - The width of the line
308 * @param color - The color to use to fill the line
309 * @param caps - Draw a circular cap on the ends of the line to support
310 * better line joins
311 *
312 * @return True on success; false on failure.
313 */
314
315 bool drawLine(FAR struct nxgl_vector_s *vector,
316 nxgl_coord_t width, nxgl_mxpixel_t color,
317 enum ELineCaps caps);
318
319 /**
320 * Draw a filled circle at the specified position, size, and color.
321 *
322 * @param center The window-relative coordinates of the circle center.
323 * @param radius The radius of the rectangle in pixels.
324 * @param color The color of the rectangle.
325 */
326
327 bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
328 nxgl_mxpixel_t color);
329
330 /**
331 * Move a rectangular region within the window.
332 *
333 * @param pRect Describes the rectangular region to move.
334 * @param pOffset The offset to move the region.
335 *
336 * @return True on success; false on failure.
337 */
338
339 bool move(FAR const struct nxgl_rect_s *pRect,
340 FAR const struct nxgl_point_s *pOffset);
341
342 /**
343 * Copy a rectangular region of a larger image into the rectangle in the
344 * specified window.
345 *
346 * @param pDest Describes the rectangular on the display that will receive
347 * the bitmap.
348 * @param pSrc The start of the source image.
349 * @param pOrigin the pOrigin of the upper, left-most corner of the full
350 * bitmap. Both pDest and pOrigin are in window coordinates, however,
351 * pOrigin may lie outside of the display.
352 * @param stride The width of the full source image in bytes.
353 *
354 * @return True on success; false on failure.
355 */
356
357 bool bitmap(FAR const struct nxgl_rect_s *pDest,
358 FAR const void *pSrc,
359 FAR const struct nxgl_point_s *pOrigin,
360 unsigned int stride);
361 };
362 }
363
364 #endif // __cplusplus
365
366 #endif // __INCLUDE_CNXTKWINDOW_HXX
367
NXWidgets::CNxTkWindow::getRectangle
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cnxtkwindow.cxx:412
NXWidgets::CCallback
Definition: ccallback.hxx:91
NXWidgets::CNxTkWindow::~CNxTkWindow
~CNxTkWindow(void)
Definition: cnxtkwindow.cxx:92
NXWidgets::CNxTkWindow::setPixel
bool setPixel(FAR const struct nxgl_point_s *pos, nxgl_mxpixel_t color)
Definition: cnxtkwindow.cxx:371
NXWidgets::CNxTkWindow::CNxTkWindow
CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl)
Definition: cnxtkwindow.cxx:69
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CNxTkWindow::m_toolbarHeight
nxgl_coord_t m_toolbarHeight
Definition: cnxtkwindow.hxx:91
NXWidgets::CNxTkWindow::m_hNxServer
NXHANDLE m_hNxServer
Definition: cnxtkwindow.hxx:87
NXWidgets::CNxTkWindow::openToolbar
CNxToolbar * openToolbar(nxgl_coord_t height, CWidgetControl *widgetControl=(CWidgetControl *) 0)
Definition: cnxtkwindow.cxx:152
NXWidgets::CNxTkWindow::redirectNxTerm
void redirectNxTerm(NXTERM handle)
Definition: cnxtkwindow.hxx:245
NXWidgets::CNxTkWindow::fill
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cnxtkwindow.cxx:393
NXWidgets::CNxTkWindow::getPosition
bool getPosition(FAR struct nxgl_point_s *pos)
Definition: cnxtkwindow.cxx:289
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNxTkWindow::lower
bool lower(void)
Definition: cnxtkwindow.cxx:355
NXWidgets::CNxTkWindow::move
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cnxtkwindow.cxx:483
NXWidgets::CNxTkWindow::setPosition
bool setPosition(FAR const struct nxgl_point_s *pos)
Definition: cnxtkwindow.cxx:315
NXWidgets::INxWindow::ELineCaps
ELineCaps
Definition: inxwindow.hxx:86
NXWidgets::CCallback::setNxTerm
void setNxTerm(NXTERM handle)
Definition: ccallback.hxx:259
NXWidgets::CNxTkWindow::detachToolbar
void detachToolbar(void)
Definition: cnxtkwindow.hxx:163
inxwindow.hxx
ccallback.hxx
NXWidgets::CNxTkWindow::open
bool open(void)
Definition: cnxtkwindow.cxx:115
NXWidgets::CNxTkWindow::drawLine
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cnxtkwindow.cxx:451
NXWidgets::CNxTkWindow::fillTrapezoid
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cnxtkwindow.cxx:430
NXWidgets::CNxToolbar
Definition: cnxtoolbar.hxx:85
NXWidgets::CNxTkWindow::drawFilledCircle
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cnxtkwindow.cxx:468
NXWidgets::CNxTkWindow::m_widgetControl
CWidgetControl * m_widgetControl
Definition: cnxtkwindow.hxx:89
NXWidgets::CNxTkWindow::requestPosition
bool requestPosition(void)
Definition: cnxtkwindow.cxx:275
NXWidgets::CNxTkWindow::m_toolbar
CNxToolbar * m_toolbar
Definition: cnxtkwindow.hxx:90
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::CNxTkWindow::bitmap
bool bitmap(FAR const struct nxgl_rect_s *pDest, FAR const void *pSrc, FAR const struct nxgl_point_s *pOrigin, unsigned int stride)
Definition: cnxtkwindow.cxx:506
NXWidgets::INxWindow
Definition: inxwindow.hxx:83
NXWidgets::CNxTkWindow::getWidgetControl
CWidgetControl * getWidgetControl(void) const
Definition: cnxtkwindow.cxx:135
NXWidgets::CNxTkWindow::getSize
bool getSize(FAR struct nxgl_size_s *size)
Definition: cnxtkwindow.cxx:300
NXWidgets::CNxTkWindow::setSize
bool setSize(FAR const struct nxgl_size_s *size)
Definition: cnxtkwindow.cxx:329
NXWidgets::CNxTkWindow
Definition: cnxtkwindow.hxx:84
NXWidgets::CNxTkWindow::m_hNxTkWindow
NXTKWINDOW m_hNxTkWindow
Definition: cnxtkwindow.hxx:88