NXWidgets: cnxtoolbar.hxx Source File

NXWidgets 1.19

cnxtoolbar.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cnxtoolbar.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_CNXTOOLBAR_HXX
37 #define __INCLUDE_CNXTOOLBAR_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 #include "cnxtkwindow.hxx"
55
56 /****************************************************************************
57 * Pre-Processor Definitions
58 ****************************************************************************/
59
60 /****************************************************************************
61 * Implementation Classes
62 ****************************************************************************/
63
64 #if defined(__cplusplus)
65
66 namespace NXWidgets
67 {
68 class CWidgetControl;
69 struct SBitmap;
70
71 /**
72 * This class defines operations on a the toolbar in a framed NX window.
73 * There are three instances that represent an NX window from the
74 * perspective of NXWidgets.
75 *
76 * - There is one widget control instance per NX window,
77 * - One CCallback instance per window,
78 * - One window instance.
79 *
80 * There a various kinds of of window instances, but each inherits
81 * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
82 * that describes the common window behavior.
83 */
84
85 class CNxToolbar : protected CCallback, public INxWindow
86 {
87 private:
88 CNxTkWindow *m_nxTkWindow; /**< Parent framed window instance. */
89 NXTKWINDOW m_hNxTkWindow; /**< Parent framed window handle. */
90 CWidgetControl *m_widgetControl; /**< Controlling widget for the toolbar */
91 nxgl_coord_t m_height; /**< The toolbar height */
92
93 public:
94
95 /**
96 * Constructor. Creates an uninitialized instance of the CNxToolbar
97 * object. The open() method must be called to initialize the instance.
98 *
99 * @param pNxTkWindow Parent framed window instance
100 * @param hNxTkWindow Parent framed window NX handler
101 * @param widgetControl Controlling widget for this toolbar.
102 * @param height The height of the toolbar.
103 */
104
105 CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow,
106 CWidgetControl *pWidgetControl, nxgl_coord_t height);
107
108 /**
109 * Destructor.
110 */
111
112 ~CNxToolbar(void);
113
114 /**
115 * Creates a new toolbar. Toolbar creation is separate from
116 * object instantiation so that failures can be reported.
117 *
118 * @return True if the toolbar was successfully created.
119 */
120
121 bool open(void);
122
123 /**
124 * Each implementation of INxWindow must provide a method to recover
125 * the contained CWidgetControl instance.
126 *
127 * @return The contained CWidgetControl instance
128 */
129
130 CWidgetControl *getWidgetControl(void) const;
131
132 /**
133 * Request the position and size information of the toolbar. The values
134 * will be returned asynchronously through the client callback method.
135 * The GetPosition() method may than be called to obtain the positional
136 * data as provided by the callback.
137 *
138 * @return True on success, false on any failure.
139 */
140
141 bool requestPosition(void);
142
143 /**
144 * Get the position of the toolbar (as reported by the NX callback).
145 *
146 * @return The position.
147 */
148
149 bool getPosition(FAR struct nxgl_point_s *pPos);
150
151 /**
152 * Get the size of the toolbar (as reported by the NX callback).
153 *
154 * @return The size.
155 */
156
157 bool getSize(FAR struct nxgl_size_s *pSize);
158
159 /**
160 * Set the position and size of the toolbar. The position of
161 * the toolbar is fixed at the top of the parent framed window.
162 *
163 * @param pPos The new position of the toolbar.
164 * @return Always returns false.
165 */
166
167 bool setPosition(FAR const struct nxgl_point_s *pPos);
168
169 /**
170 * Set the position and size of the toolbar. The position of
171 * the toolbar is fixed at the top of the parent framed window.
172 *
173 * @param pPos The new position of the toolbar.
174 * @return Always returns false.
175 */
176
177 bool setSize(FAR const struct nxgl_size_s *pSize);
178
179 /**
180 * Bring the toolbar to the top of the display. The toolbar is
181 * a component of the containing, parent, framed window. It
182 * cannot be raised separately.
183 *
184 * @return Always returns false.
185 */
186
187 bool raise(void);
188
189 /**
190 * Lower the toolbar to the bottom of the display. The toolbar is
191 * a component of the containing, parent, framed window. It
192 * cannot be lowered separately.
193 *
194 * @return Always returns false.
195 */
196
197 bool lower(void);
198
199 /**
200 * Each window implementation also inherits from CCallback. CCallback,
201 * by default, forwards NX keyboard input to the various widgets residing
202 * in the window. But NxTerm is a different usage model; In this case,
203 * keyboard input needs to be directed to the NxTerm character driver.
204 * This method can be used to enable (or disable) redirection of NX
205 * keyboard input from the window widgets to the NxTerm
206 *
207 * @param handle. The NXTERM handle. If non-NULL, NX keyboard
208 * input will be directed to the NxTerm driver using this
209 * handle; If NULL (the default), NX keyboard input will be
210 * directed to the widgets within the window.
211 */
212
213 #ifdef CONFIG_NXTERM_NXKBDIN
214 inline void redirectNxTerm(NXTERM handle)
215 {
216 setNxTerm(handle);
217 }
218 #endif
219
220 /**
221 * Set an individual pixel in the toolbar with the specified color.
222 *
223 * @param pPos The location of the pixel to be filled.
224 * @param color The color to use in the fill.
225 *
226 * @return True on success; false on failure.
227 */
228
229 bool setPixel(FAR const struct nxgl_point_s *pPos,
230 nxgl_mxpixel_t color);
231
232 /**
233 * Fill the specified rectangle in the toolbar with the specified color.
234 *
235 * @param pRect The location to be filled.
236 * @param color The color to use in the fill.
237 *
238 * @return True on success; false on failure.
239 */
240
241 bool fill(FAR const struct nxgl_rect_s *pRect,
242 nxgl_mxpixel_t color);
243
244 /**
245 * Get the raw contents of graphic memory within a rectangular region. NOTE:
246 * Since raw graphic memory is returned, the returned memory content may be
247 * the memory of windows above this one and may not necessarily belong to
248 * this window unless you assure that this is the top window.
249 *
250 * @param rect The location to be copied
251 * @param dest - The describes the destination bitmap to receive the
252 * graphics data.
253 */
254
255 void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
256
257 /**
258 * Fill the specified trapezoidal region in the toolbar with the specified
259 * color.
260 *
261 * @param pClip Clipping rectangle relative to toolbar (may be null).
262 * @param pTrap The trapezoidal region to be filled.
263 * @param color The color to use in the fill.
264 *
265 * @return True on success; false on failure.
266 */
267
268 bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
269 FAR const struct nxgl_trapezoid_s *pTrap,
270 nxgl_mxpixel_t color);
271
272 /**
273 * Fill the specified line in the toolbar with the specified color.
274 *
275 * @param vector - Describes the line to be drawn
276 * @param width - The width of the line
277 * @param color - The color to use to fill the line
278 * @param caps - Draw a circular cap on the ends of the line to suppor
279 * better line joins
280 *
281 * @return True on success; false on failure.
282 */
283
284 bool drawLine(FAR struct nxgl_vector_s *vector,
285 nxgl_coord_t width, nxgl_mxpixel_t color,
286 enum ELineCaps caps);
287
288 /**
289 * Draw a filled circle at the specified position, size, and color.
290 *
291 * @param center The window-relative coordinates of the circle center.
292 * @param radius The radius of the rectangle in pixels.
293 * @param color The color of the rectangle.
294 */
295
296 bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
297 nxgl_mxpixel_t color);
298
299 /**
300 * Move a rectangular region within the toolbar.
301 *
302 * @param pRect Describes the rectangular region to move.
303 * @param pOffset The offset to move the region.
304 *
305 * @return True on success; false on failure.
306 */
307
308 bool move(FAR const struct nxgl_rect_s *pRect,
309 FAR const struct nxgl_point_s *pOffset);
310
311 /**
312 * Copy a rectangular region of a larger image into the rectangle in the
313 * specified toolbar.
314 *
315 * @param pDest Describes the rectangular on the display that will receive
316 * the bitmap.
317 * @param pSrc The start of the source image.
318 * @param pOrigin the pOrigin of the upper, left-most corner of the full
319 * bitmap. Both pDest and pOrigin are in toolbar coordinates, however,
320 * pOrigin may lie outside of the display.
321 * @param stride The width of the full source image in bytes.
322 *
323 * @return True on success; false on failure.
324 */
325
326 bool bitmap(FAR const struct nxgl_rect_s *pDest,
327 FAR const void *pSrc,
328 FAR const struct nxgl_point_s *pOrigin,
329 unsigned int stride);
330 };
331 }
332
333 #endif // __cplusplus
334
335 #endif // __INCLUDE_CNXTOOLBAR_HXX
336
NXWidgets::CNxToolbar::open
bool open(void)
Definition: cnxtoolbar.cxx:113
NXWidgets::CCallback
Definition: ccallback.hxx:91
NXWidgets::CNxToolbar::setPixel
bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:242
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CNxToolbar::setSize
bool setSize(FAR const struct nxgl_size_s *pSize)
Definition: cnxtoolbar.cxx:202
NXWidgets::CNxToolbar::lower
bool lower(void)
Definition: cnxtoolbar.cxx:228
NXWidgets::CNxToolbar::getWidgetControl
CWidgetControl * getWidgetControl(void) const
Definition: cnxtoolbar.cxx:133
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNxToolbar::~CNxToolbar
~CNxToolbar(void)
Definition: cnxtoolbar.cxx:88
NXWidgets::CNxToolbar::fill
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:264
NXWidgets::INxWindow::ELineCaps
ELineCaps
Definition: inxwindow.hxx:86
NXWidgets::CCallback::setNxTerm
void setNxTerm(NXTERM handle)
Definition: ccallback.hxx:259
inxwindow.hxx
NXWidgets::CNxToolbar::setPosition
bool setPosition(FAR const struct nxgl_point_s *pPos)
Definition: cnxtoolbar.cxx:188
ccallback.hxx
NXWidgets::CNxToolbar::getSize
bool getSize(FAR struct nxgl_size_s *pSize)
Definition: cnxtoolbar.cxx:175
NXWidgets::CNxToolbar::fillTrapezoid
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:301
NXWidgets::CNxToolbar
Definition: cnxtoolbar.hxx:85
NXWidgets::CNxToolbar::requestPosition
bool requestPosition(void)
Definition: cnxtoolbar.cxx:147
NXWidgets::CNxToolbar::CNxToolbar
CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow, CWidgetControl *pWidgetControl, nxgl_coord_t height)
Definition: cnxtoolbar.cxx:68
NXWidgets::CNxToolbar::getRectangle
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cnxtoolbar.cxx:283
NXWidgets::CNxToolbar::m_widgetControl
CWidgetControl * m_widgetControl
Definition: cnxtoolbar.hxx:90
NXWidgets::CNxToolbar::drawFilledCircle
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:339
cnxtkwindow.hxx
NXWidgets::CNxToolbar::move
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cnxtoolbar.cxx:354
NXWidgets::CNxToolbar::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: cnxtoolbar.cxx:377
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::CNxToolbar::getPosition
bool getPosition(FAR struct nxgl_point_s *pPos)
Definition: cnxtoolbar.cxx:164
NXWidgets::INxWindow
Definition: inxwindow.hxx:83
NXWidgets::CNxTkWindow
Definition: cnxtkwindow.hxx:84
NXWidgets::CNxToolbar::drawLine
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cnxtoolbar.cxx:322
NXWidgets::CNxToolbar::m_nxTkWindow
CNxTkWindow * m_nxTkWindow
Definition: cnxtoolbar.hxx:88
NXWidgets::CNxToolbar::redirectNxTerm
void redirectNxTerm(NXTERM handle)
Definition: cnxtoolbar.hxx:214
NXWidgets::CNxToolbar::m_height
nxgl_coord_t m_height
Definition: cnxtoolbar.hxx:91
NXWidgets::CNxToolbar::m_hNxTkWindow
NXTKWINDOW m_hNxTkWindow
Definition: cnxtoolbar.hxx:89