From 4dedf494c242b2c4b52707441eefe2a36fbacf0f Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 22 Mar 2012 21:22:59 +0000 Subject: First check-in of NxWidgets git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4505 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/libnxwidgets/include/cbgwindow.hxx | 314 ++++ NxWidgets/libnxwidgets/include/cbitmap.hxx | 204 +++ NxWidgets/libnxwidgets/include/cbutton.hxx | 235 +++ NxWidgets/libnxwidgets/include/cbuttonarray.hxx | 317 ++++ NxWidgets/libnxwidgets/include/ccallback.hxx | 220 +++ NxWidgets/libnxwidgets/include/ccheckbox.hxx | 210 +++ NxWidgets/libnxwidgets/include/ccyclebutton.hxx | 356 +++++ NxWidgets/libnxwidgets/include/cglyphbutton.hxx | 229 +++ NxWidgets/libnxwidgets/include/cgraphicsport.hxx | 411 +++++ NxWidgets/libnxwidgets/include/cimage.hxx | 199 +++ NxWidgets/libnxwidgets/include/ckeypad.hxx | 156 ++ NxWidgets/libnxwidgets/include/clabel.hxx | 355 +++++ NxWidgets/libnxwidgets/include/clatchbutton.hxx | 173 +++ .../libnxwidgets/include/clatchbuttonarray.hxx | 170 ++ NxWidgets/libnxwidgets/include/clistbox.hxx | 431 ++++++ .../libnxwidgets/include/clistboxdataitem.hxx | 180 +++ NxWidgets/libnxwidgets/include/clistdata.hxx | 351 +++++ .../libnxwidgets/include/clistdataeventargs.hxx | 121 ++ NxWidgets/libnxwidgets/include/clistdataitem.hxx | 189 +++ .../libnxwidgets/include/cmultilinetextbox.hxx | 621 ++++++++ NxWidgets/libnxwidgets/include/cnxfont.hxx | 238 +++ NxWidgets/libnxwidgets/include/cnxserver.hxx | 199 +++ NxWidgets/libnxwidgets/include/cnxstring.hxx | 484 ++++++ NxWidgets/libnxwidgets/include/cnxtimer.hxx | 220 +++ NxWidgets/libnxwidgets/include/cnxtkwindow.hxx | 327 ++++ NxWidgets/libnxwidgets/include/cnxtoolbar.hxx | 304 ++++ NxWidgets/libnxwidgets/include/cnxwidget.hxx | 1627 ++++++++++++++++++++ NxWidgets/libnxwidgets/include/cnxwindow.hxx | 307 ++++ NxWidgets/libnxwidgets/include/cprogressbar.hxx | 251 +++ NxWidgets/libnxwidgets/include/cradiobutton.hxx | 207 +++ .../libnxwidgets/include/cradiobuttongroup.hxx | 253 +++ NxWidgets/libnxwidgets/include/crect.hxx | 424 +++++ NxWidgets/libnxwidgets/include/crectcache.hxx | 222 +++ .../libnxwidgets/include/crlepalettebitmap.hxx | 259 ++++ .../libnxwidgets/include/cscrollbarhorizontal.hxx | 293 ++++ NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx | 309 ++++ .../libnxwidgets/include/cscrollbarvertical.hxx | 291 ++++ .../libnxwidgets/include/cscrollinglistbox.hxx | 480 ++++++ NxWidgets/libnxwidgets/include/cscrollingpanel.hxx | 372 +++++ .../libnxwidgets/include/cscrollingtextbox.hxx | 467 ++++++ .../libnxwidgets/include/csliderhorizontal.hxx | 344 +++++ .../libnxwidgets/include/csliderhorizontalgrip.hxx | 203 +++ NxWidgets/libnxwidgets/include/cslidervertical.hxx | 344 +++++ .../libnxwidgets/include/csliderverticalgrip.hxx | 202 +++ NxWidgets/libnxwidgets/include/cstickybutton.hxx | 237 +++ .../libnxwidgets/include/cstickybuttonarray.hxx | 174 +++ NxWidgets/libnxwidgets/include/cstringiterator.hxx | 192 +++ NxWidgets/libnxwidgets/include/ctext.hxx | 386 +++++ NxWidgets/libnxwidgets/include/ctextbox.hxx | 375 +++++ NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx | 641 ++++++++ .../libnxwidgets/include/cwidgeteventargs.hxx | 237 +++ .../libnxwidgets/include/cwidgeteventhandler.hxx | 316 ++++ .../include/cwidgeteventhandlerlist.hxx | 382 +++++ NxWidgets/libnxwidgets/include/cwidgetstyle.hxx | 135 ++ NxWidgets/libnxwidgets/include/glyphs.hxx | 131 ++ NxWidgets/libnxwidgets/include/ibitmap.hxx | 165 ++ NxWidgets/libnxwidgets/include/ilistbox.hxx | 273 ++++ .../libnxwidgets/include/ilistdataeventhandler.hxx | 127 ++ NxWidgets/libnxwidgets/include/inxwindow.hxx | 268 ++++ NxWidgets/libnxwidgets/include/iscrollable.hxx | 208 +++ NxWidgets/libnxwidgets/include/islider.hxx | 188 +++ NxWidgets/libnxwidgets/include/itextbox.hxx | 209 +++ NxWidgets/libnxwidgets/include/nxconfig.hxx | 444 ++++++ NxWidgets/libnxwidgets/include/singletons.hxx | 136 ++ NxWidgets/libnxwidgets/include/teventargs.hxx | 136 ++ NxWidgets/libnxwidgets/include/tnxarray.hxx | 437 ++++++ 66 files changed, 19866 insertions(+) create mode 100644 NxWidgets/libnxwidgets/include/cbgwindow.hxx create mode 100644 NxWidgets/libnxwidgets/include/cbitmap.hxx create mode 100644 NxWidgets/libnxwidgets/include/cbutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/cbuttonarray.hxx create mode 100644 NxWidgets/libnxwidgets/include/ccallback.hxx create mode 100644 NxWidgets/libnxwidgets/include/ccheckbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/ccyclebutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/cglyphbutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/cgraphicsport.hxx create mode 100644 NxWidgets/libnxwidgets/include/cimage.hxx create mode 100644 NxWidgets/libnxwidgets/include/ckeypad.hxx create mode 100644 NxWidgets/libnxwidgets/include/clabel.hxx create mode 100644 NxWidgets/libnxwidgets/include/clatchbutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/clatchbuttonarray.hxx create mode 100644 NxWidgets/libnxwidgets/include/clistbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/clistboxdataitem.hxx create mode 100644 NxWidgets/libnxwidgets/include/clistdata.hxx create mode 100644 NxWidgets/libnxwidgets/include/clistdataeventargs.hxx create mode 100644 NxWidgets/libnxwidgets/include/clistdataitem.hxx create mode 100644 NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxfont.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxserver.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxstring.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxtimer.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxtkwindow.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxtoolbar.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxwidget.hxx create mode 100644 NxWidgets/libnxwidgets/include/cnxwindow.hxx create mode 100644 NxWidgets/libnxwidgets/include/cprogressbar.hxx create mode 100644 NxWidgets/libnxwidgets/include/cradiobutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/cradiobuttongroup.hxx create mode 100644 NxWidgets/libnxwidgets/include/crect.hxx create mode 100644 NxWidgets/libnxwidgets/include/crectcache.hxx create mode 100644 NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollbarvertical.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollinglistbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollingpanel.hxx create mode 100644 NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/csliderhorizontal.hxx create mode 100644 NxWidgets/libnxwidgets/include/csliderhorizontalgrip.hxx create mode 100644 NxWidgets/libnxwidgets/include/cslidervertical.hxx create mode 100644 NxWidgets/libnxwidgets/include/csliderverticalgrip.hxx create mode 100644 NxWidgets/libnxwidgets/include/cstickybutton.hxx create mode 100644 NxWidgets/libnxwidgets/include/cstickybuttonarray.hxx create mode 100644 NxWidgets/libnxwidgets/include/cstringiterator.hxx create mode 100644 NxWidgets/libnxwidgets/include/ctext.hxx create mode 100644 NxWidgets/libnxwidgets/include/ctextbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx create mode 100644 NxWidgets/libnxwidgets/include/cwidgeteventargs.hxx create mode 100644 NxWidgets/libnxwidgets/include/cwidgeteventhandler.hxx create mode 100644 NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx create mode 100644 NxWidgets/libnxwidgets/include/cwidgetstyle.hxx create mode 100644 NxWidgets/libnxwidgets/include/glyphs.hxx create mode 100644 NxWidgets/libnxwidgets/include/ibitmap.hxx create mode 100644 NxWidgets/libnxwidgets/include/ilistbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/ilistdataeventhandler.hxx create mode 100644 NxWidgets/libnxwidgets/include/inxwindow.hxx create mode 100644 NxWidgets/libnxwidgets/include/iscrollable.hxx create mode 100644 NxWidgets/libnxwidgets/include/islider.hxx create mode 100644 NxWidgets/libnxwidgets/include/itextbox.hxx create mode 100644 NxWidgets/libnxwidgets/include/nxconfig.hxx create mode 100644 NxWidgets/libnxwidgets/include/singletons.hxx create mode 100644 NxWidgets/libnxwidgets/include/teventargs.hxx create mode 100644 NxWidgets/libnxwidgets/include/tnxarray.hxx (limited to 'NxWidgets/libnxwidgets/include') diff --git a/NxWidgets/libnxwidgets/include/cbgwindow.hxx b/NxWidgets/libnxwidgets/include/cbgwindow.hxx new file mode 100644 index 000000000..1f8e417af --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cbgwindow.hxx @@ -0,0 +1,314 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbgwindow.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CBGWINDOW_HXX +#define __INCLUDE_CBGWINDOW_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "nxconfig.hxx" +#include "ccallback.hxx" +#include "inxwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class INxWindow; + struct SBitmap; + + /** + * This class defines operations on a the NX background window. + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class CBgWindow : protected CCallback, public INxWindow + { + private: + NXHANDLE m_hNxServer; /**< Handle to the NX server. */ + NXWINDOW m_hWindow; /**< Handle to the NX background window */ + CWidgetControl *m_widgetControl; /**< The controlling widget for the window */ + + public: + + /** + * Constructor. Obtains the background window from server and wraps + * the window as CBgWindow. Creates an uninitialized instance of the + * CBgWindow object. The open() method must be called to initialize + * the instance. + * + * The general steps to create any window include: + * 1) Create a dumb CWigetControl instance + * 2) Pass the dumb CWidgetControl instance to the window constructor + * that inherits from INxWindow. + * 3) The window constructor call CWidgetControl methods to "smarten" + * the CWidgetControl instance with window-specific knowledge. + * 4) Call the open() method on the window to display the window. + * 5) After that, the fully smartend CWidgetControl instance can + * be used to generate additional widgets. + * 6) After that, the fully smartened CWidgetControl instance can + * be used to generate additional widgets by passing it to the + * widget constructor + * + * @param hNxServer Handle to the NX server. + * @param widgetControl Controlling widget for this window. + */ + + CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl); + + /** + * Destructor. Returns the background window to the server. + */ + + virtual ~CBgWindow(void); + + /** + * Creates a the new window. Window creation is separate from + * object instantiation so that failures can be reported. + * + * @return True if the window was successfully created. + */ + + bool open(void); + + /** + * Request the position and size information of the window. The values + * will be returned asynchronously through the client callback method. + * The GetPosition() method may than be called to obtain the positional + * data as provided by the callback. + * + * @return True on success, false on any failure. + */ + + bool requestPosition(void); + + /** + * Get the position of the window (as reported by the NX callback). NOTE: + * The background window is always positioned at {0,0} + * + * @return The position. + */ + + bool getPosition(FAR struct nxgl_point_s *pPos); + + /** + * Get the size of the window (as reported by the NX callback). NOTE: + * The size of the background window is always the entire display. + * + * @return The size. + */ + + bool getSize(FAR struct nxgl_size_s *pSize); + + /** + * Set the position and size of the window. + * + * @param pPos The new position of the window. + * @return True on success, false on any failure. + */ + + bool setPosition(FAR const struct nxgl_point_s *pPos); + + /** + * Set the size of the selected window. NOTE: The size of the + * background window is always the entire display and cannot be + * changed. + * + * @param pSize The new size of the window. + * @return True on success, false on any failure. + */ + + bool setSize(FAR const struct nxgl_size_s *pSize); + + /** + * Bring the window to the top of the display. NOTE: The background + * window cannot be raised. + * + * @return True on success, false on any failure. + */ + + bool raise(void); + + /** + * Lower the window to the bottom of the display. NOTE: The background + * window is always at the bottom of the window hierarchy. + * + * @return True on success, false on any failure. + */ + + bool lower(void); + + /** + * Set an individual pixel in the window with the specified color. + * + * @param pPos The location of the pixel to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool setPixel(FAR const struct nxgl_point_s *pPos, + nxgl_mxpixel_t color); + + /** + * Fill the specified rectangle in the window with the specified color. + * + * @param pRect The location to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fill(FAR const struct nxgl_rect_s *pRect, + nxgl_mxpixel_t color); + + /** + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * @param rect The location to be copied + * @param dest - The describes the destination bitmap to receive the + * graphics data. + */ + + void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest); + + /** + * Fill the specified trapezoidal region in the window with the specified + * color. + * + * @param pClip Clipping rectangle relative to window (may be null). + * @param pTrap The trapezoidal region to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, + FAR const struct nxgl_trapezoid_s *pTrap, + nxgl_mxpixel_t color); + + /** + * Fill the specified line in the window with the specified color. + * + * @param vector - Describes the line to be drawn + * @param width - The width of the line + * @param color - The color to use to fill the line + * + * @return True on success; false on failure. + */ + + bool drawLine(FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color); + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color); + + /** + * Move a rectangular region within the window. + * + * @param pRect Describes the rectangular region to move. + * @param pOffset The offset to move the region. + * + * @return True on success; false on failure. + */ + + bool move(FAR const struct nxgl_rect_s *pRect, + FAR const struct nxgl_point_s *pOffset); + + /** + * Copy a rectangular region of a larger image into the rectangle in the + * specified window. + * + * @param pDest Describes the rectangular on the display that will receive + * the bitmap. + * @param pSrc The start of the source image. + * @param pOrigin the pOrigin of the upper, left-most corner of the full + * bitmap. Both pDest and pOrigin are in window coordinates, however, + * pOrigin may lie outside of the display. + * @param stride The width of the full source image in bytes. + * + * @return True on success; false on failure. + */ + + bool bitmap(FAR const struct nxgl_rect_s *pDest, + FAR const void *pSrc, + FAR const struct nxgl_point_s *pOrigin, + unsigned int stride); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CBGWINDOW_HXX + diff --git a/NxWidgets/libnxwidgets/include/cbitmap.hxx b/NxWidgets/libnxwidgets/include/cbitmap.hxx new file mode 100644 index 000000000..473403aa8 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cbitmap.hxx @@ -0,0 +1,204 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbitmap.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CBITMAP_HXX +#define __INCLUDE_CBITMAP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nxconfig.hxx" +#include "ibitmap.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Bitmap Structure + */ + + struct SBitmap + { + uint8_t bpp; /**< Bits per pixel */ + uint8_t fmt; /**< Color format */ + nxgl_coord_t width; /**< Width in pixels */ + nxgl_coord_t height; /**< Height in rows */ + uint16_t stride; /**< Width in bytes */ + FAR const void *data; /**< Pointer to the beginning of pixel data */ + }; + + /** + * Class providing bitmap accessor for a bitmap represented by SBitmap. + */ + + class CBitmap : public IBitmap + { + protected: + const struct SBitmap *m_bitmap; /**< The bitmap that is being managed */ + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CBitmap(const CBitmap &bitmap) { } + + public: + + /** + * Constructor. + * + * @param bitmap The bitmap structure being wrapped. + */ + + CBitmap(const struct SBitmap *bitmap); + + /** + * Destructor. + */ + + inline ~CBitmap(void) {} + + /** + * Get the bitmap's color format. + * + * @return The bitmap's width. + */ + + const uint8_t getColorFormat(void) const; + + /** + * Get the bitmap's color format. + * + * @return The bitmap's color format. + */ + + const uint8_t getBitsPerPixel(void) const; + + /** + * Get the bitmap's width (in pixels/columns). + * + * @return The bitmap's pixel depth. + */ + + const nxgl_coord_t getWidth(void) const; + + /** + * Get the bitmap's height (in rows). + * + * @return The bitmap's height. + */ + + const nxgl_coord_t getHeight(void) const; + + /** + * Get the bitmap's width (in bytes). + * + * @return The bitmap's width. + */ + + const nxgl_coord_t getStride(void) const; + + /** + * Get one row from the bit map image. + * + * @param x The offset into the row to get + * @param y The row number to get + * @param width The number of pixels to get from the row + * @param data The memory location provided by the caller + * in which to return the data. This should be at least + * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length + * and properly aligned for the pixel color format. + * @param True if the run was returned successfully. + */ + + bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + FAR void *data); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CBITMAP_HXX diff --git a/NxWidgets/libnxwidgets/include/cbutton.hxx b/NxWidgets/libnxwidgets/include/cbutton.hxx new file mode 100644 index 000000000..4af39f0ef --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cbutton.hxx @@ -0,0 +1,235 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CBUTTON_HXX +#define __INCLUDE_CBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "clabel.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + + /** + * Clickable button widget. Displays text within the button. + */ + + class CButton : public CLabel + { + protected: + + /** + * Draws the outline of the button. + * + * @param port Graphics port to draw to. + */ + + virtual void drawOutline(CGraphicsPort *port); + + /** + * Draws the outline of the button. + * + * @param port Graphics port to draw to. + * @param useClicked Present outline using the 'clicked' style + */ + + void drawOutline(CGraphicsPort *port, bool useClicked); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @param useClicked Present contents using the 'clicked' style + * @see redraw() + */ + + void drawContents(CGraphicsPort *port, bool useClicked); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @param useClicked Present border using the 'clicked' style + * @see redraw() + */ + + void drawBorder(CGraphicsPort *port, bool useClicked); + + /** + * Redraws the button. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raises an action event and redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CButton(const CButton &button) : CLabel(button) { } + + public: + + /** + * Constructor for buttons that display a string. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button, relative to its parent. + * @param y The y coordinate of the button, relative to its parent. + * @param width The width of the button. + * @param height The height of the button. + * @param text The text for the button to display. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * CButton Destructor. + */ + + virtual inline ~CButton() { } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/cbuttonarray.hxx b/NxWidgets/libnxwidgets/include/cbuttonarray.hxx new file mode 100644 index 000000000..d5f8be449 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cbuttonarray.hxx @@ -0,0 +1,317 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbuttonarray.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CBUTTONARRAY_HXX +#define __INCLUDE_CBUTTONARRAY_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "clabel.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CNxString; + + /** + * Manages a two-dimensional array of buttons as one widget. A two- + * dimensional array of buttons might also be called a "keyboard". + */ + + class CButtonArray : public CNxWidget + { + protected: + uint8_t m_buttonColumns; /**< The number of columns in one row */ + uint8_t m_buttonRows; /**< The number buttons in one column */ + bool m_redrawButton; /**< True: Redraw button; False: redraw all */ + bool m_cursorOn; /**< Cursor on; hightlighted button displayed */ + bool m_cursorChange; /**< True: Redraw cursor button only */ + nxgl_coord_t m_buttonWidth; /**< The width of one button in pixels */ + nxgl_coord_t m_buttonHeight; /**< The height of one button in rows */ + nxgl_coord_t m_clickX; /**< The X position of the last clicked button */ + nxgl_coord_t m_clickY; /**< The Y position of the last clicked button */ + uint8_t m_cursorColumn; /**< The column index of the highlighted button */ + uint8_t m_cursorRow; /**< The row index of the highlighted button */ + CNxString *m_buttonText; /**< Text for each button */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Redraw only one button + * + * @param port The CGraphicsPort to draw to. + * @param column The button column index + * @param row The button row index + * @param useClicked Draw the button using the 'clicked' button style, + * regardless of the actual button state. + * @see onClick() and onRelease() + */ + + virtual void drawButton(CGraphicsPort *port, int column, int row, bool useClicked); + + /** + * Redraws the button. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raises an action event and redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Convert an X/Y position to a button column/row index + * + * @param x The x position + * @param y The y position + * @param column The location to return the column index of the button + * of interest + * @param row The location to return the row index of the button of + * interest + * @return false is the position is invalid + */ + + virtual bool posToButton(nxgl_coord_t x, nxgl_coord_t y, int &column, int &row); + + /** + * Updates the GUI after the text has changed. + */ + + virtual void onTextChange(void); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CButtonArray(const CButtonArray &button) : CNxWidget(button) { } + + public: + + /** + * Constructor for an array of buttons. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button array, relative to its parent. + * @param y The y coordinate of the button array, relative to its parent. + * @param buttonColumns The number of buttons in one row of the button array + * @param buttonRows The number of buttons in one column of the button array + * @param buttonWidth The width of one button + * @param buttonHeight The height of one button + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CButtonArray(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + uint8_t buttonColumns, uint8_t buttonRows, + nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * CButtonArray Destructor. + */ + + ~CButtonArray(void); + + /** + * Returns the string shown in the label. + * + * @param column The column index of the button of interest + * @param row The row index of the button of interest + * @return The label's text. + */ + + virtual const CNxString &getText(int column, int row) const; + + /** + * Set the text displayed in the label. + * + * @param column The column index of the button to set + * @param row The row index of the button to set + * @param text String to display. + */ + + virtual void setText(int column, int row, const CNxString &text); + + /** + * Return the position of the last clicked button (0,0 will be returned + * the no button has every been clicked). The button at this position + * is currently clicked then, in addition, return true. + * + * @param column The location to return the column index of the button + * of interest + * @param row The location to return the row index of the button of + * interest + * @return True if any button in the array is clicked + */ + + virtual bool isButtonClicked(int &column, int &row) const; + + /** + * Check if this specific button in the array is clicked + * + * @param column The column of the button to check. + * @param row The row of the button to check. + * @return True if this button is clicked + */ + + virtual bool isThisButtonClicked(int column, int row) const; + + /** + * Control the cursor state. + * + * @param cursorOn True(1), the current cursor position will be highlighted + */ + + virtual void cursor(bool cursorOn); + + /** + * Return the current cursor position (button indices) and an indication + * if the button at the cursor is currently hightlighted. + * + * @param column The location to return the column index of the button + * of interest + * @param row The location to return the row index of the button of + * interest + * @return True if the cursor is enabled and the button is highlighted + */ + + virtual bool getCursorPosition(int &column, int &row) const; + + /** + * Set the cursor position (button indices). Note that the cursor + * does not have to be enabled to set the position. + * + * @param column The column index of the button of interest + * @param row The row index of the button of interest + * @return True if the cursor position is valid + */ + + virtual bool setCursorPosition(int column, int row); + + /** + * Check if this specific button in the array is at the cursor position + * and highlighted. + * + * @param column The column of the button to check. + * @param row The row of the button to check. + * @return True if this button is at the cursor postion and highlighted. + */ + + virtual bool isCursorPosition(int column, int row) const; + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the + * widget's parent. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + + /** + * Sets the font. + * + * @param font A pointer to the font to use. + */ + + virtual void setFont(CNxFont *font); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CBUTTONARRAY_HXX diff --git a/NxWidgets/libnxwidgets/include/ccallback.hxx b/NxWidgets/libnxwidgets/include/ccallback.hxx new file mode 100644 index 000000000..0e0d5de8b --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ccallback.hxx @@ -0,0 +1,220 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ccallback.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CCALLBACK_HXX +#define __INCLUDE_CCALLBACK_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "crect.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * Callback function proxies. This class receives and dispatches callbacks + * from the NX server. This calls also manages a few lower-level details + * such as keeping track of the reported window handles and window positions + * and sizes. + * + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + + */ + + class CCallback + { + private: + struct nx_callback_s m_callbacks; /**< C-callable vtable of callback function pointers */ + + // Methods in the callback vtable + + /** + * Re-Draw Callback. The redraw event is handled by CWidgetControl::redrawEvent. + * + * NOTE: This method runs in the context of the NX callback which may + * either be the context of the owning thread or, in the case of multi- + * user NX, the context of the NX event listener thread. + * + * @param hWindow Handle to a specific NX window. + * @param pRect The rectangle that needs to be re-drawn (in window + * relative coordinates). + * @param bMore true: More re-draw requests will follow. + * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * nxtk_openwindow, or nxtk_opentoolbar). + */ + + static void redraw(NXHANDLE hWindow, FAR const struct nxgl_rect_s *pRect, + bool bMore, FAR void *pvArg); + + /** + * Position Callback. The new positional data is handled by + * CWidgetControl::geometryEvent. + * + * NOTE: This method runs in the context of the NX callback which may + * either be the context of the owning thread or, in the case of multi- + * user NX, the context of the NX event listener thread. + * + * @param hWindow Handle to a specific NX window. + * @param pSize The size of the window. + * @param pPos The position of the upper left hand corner of the window on + * the overall display. + * @param pBounds The bounding rectangle that describes the entire display. + * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * nxtk_openwindow, or nxtk_opentoolbar). + */ + + static void position(NXHANDLE hWindow, FAR const struct nxgl_size_s *pSize, + FAR const struct nxgl_point_s *pPos, + FAR const struct nxgl_rect_s *pBounds, + FAR void *pvArg); + + /** + * New mouse data is available for the window. The new mouse + * data is handled by CWidgetControl::newMouseEvent. + * + * NOTE: This method runs in the context of the NX callback which may + * either be the context of the NX event listener thread (if multi- + * user NX), or possibly in the connects of device driver or even a + * device driver interrupt. + * + * The GUI thread is probably sleeping a semaphore, waiting to be + * awakened by a mouse or keyboard event. + * + * @param hWindow Handle to a specific NX window. + * @param pPos The (x,y) position of the mouse. + * @param buttons See NX_MOUSE_* definitions. + * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * nxtk_openwindow, or nxtk_opentoolbar). + */ + +#ifdef CONFIG_NX_MOUSE + static void newMouseEvent(NXHANDLE hWindow, FAR const struct nxgl_point_s *pPos, + uint8_t buttons, FAR void *pvArg); +#endif /* CONFIG_NX_MOUSE */ + + /** + * New keyboard/keypad data is available for the window. The new + * keyboard data is handled by CWidgetControl::newKeyboardEvent. + * + * NOTE: This method runs in the context of the NX callback which may + * either be the context of the NX event listener thread (if multi- + * user NX), or possibly in the connects of device driver or even a + * device driver interrupt. + * + * The GUI thread is probably sleeping a semaphore, waiting to be + * awakened by a mouse or keyboard event. + * + * @param hWindow Handle to a specific NX window. + * @param nCh The number of characters that are available in pStr[]. + * @param pStr The array of characters. + * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * nxtk_openwindow, or nxtk_opentoolbar). + */ + +#ifdef CONFIG_NX_KBD + static void newKeyboardEvent(NXHANDLE hWindow, uint8_t nCh, FAR const uint8_t *pStr, + FAR void *pvArg); +#endif // CONFIG_NX_KBD + + public: + + /** + * Constructor. + * + * @param pWidgetControl Control object associated with this window + */ + + CCallback(CWidgetControl *pWidgetControl); + + /** + * Destructor. + */ + + inline ~CCallback(void) {} + + /** + * Get the callback vtable. This is neeed only by the window + * instance that inherits this class. The window instance needs the + * C-callable vtable in order to create the NX window. Once the + * window is created, this class will begin to receive callbacks via + * the C-callable vtable methods. + * + * @return This method returns the C-callable vtable needed for + * NX window creation. + */ + + inline FAR struct nx_callback_s *getCallbackVTable(void) + { + return &m_callbacks; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CCALLBACK_HXX + diff --git a/NxWidgets/libnxwidgets/include/ccheckbox.hxx b/NxWidgets/libnxwidgets/include/ccheckbox.hxx new file mode 100644 index 000000000..109e7839e --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ccheckbox.hxx @@ -0,0 +1,210 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ccheckbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CCHECKBOX_HXX +#define __INCLUDE_CCHECKBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cbutton.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * Class representing a checkbox. Like radio buttons, checkboxes + * are tri-state - off, on and "mu". The mu state cannot be enabled by + * a user - it can only be set by the developer. + */ + + class CCheckBox : public CButton + { + public: + + /** + * Enum listing all possible checkbox states. + */ + + enum CheckBoxState + { + CHECK_BOX_STATE_OFF = 0, /**< Checkbox is unticked */ + CHECK_BOX_STATE_ON = 1, /**< Checkbox is ticked */ + CHECK_BOX_STATE_MU = 2 /**< Checkbox is in the third state */ + }; + + protected: + CheckBoxState m_state; /**< The state of the checkbox */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Toggles the state of the checkbox. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CCheckBox(const CCheckBox &checkBox) : CButton(checkBox) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the checkbox, relative to its parent. + * @param y The y coordinate of the checkbox, relative to its parent. + * @param width The width of the checkbox. + * @param height The height of the checkbox. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CCheckBox(void) { } + + /** + * Get the current state of the checkbox. + * + * @return The state of the checkbox. + */ + + virtual inline const CheckBoxState getState(void) const + { + return m_state; + } + + /** + * Set the state of the checkbox. + * + * @param state The new checkbox state. + */ + + virtual void setState(CheckBoxState state); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CCHECKBOX_HXX + diff --git a/NxWidgets/libnxwidgets/include/ccyclebutton.hxx b/NxWidgets/libnxwidgets/include/ccyclebutton.hxx new file mode 100644 index 000000000..5fd9405d8 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ccyclebutton.hxx @@ -0,0 +1,356 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ccyclebutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CCYLEBUTTON_HXX +#define __INCLUDE_CCYLEBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cbutton.hxx" +#include "ilistdataeventhandler.hxx" +#include "clistdata.hxx" +#include "clistdataitem.hxx" +#include "cwidgetstyle.hxx" +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + + /** + * Cycle button widget. Displays text within the button. Clicking it cycles + * through its available options. + */ + + class CCycleButton : public CButton, public IListDataEventHandler + { + protected: + + CListData m_options; /**< Option storage. */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Draws the outline of the button. + * + * @param port Graphics port to draw to. + */ + + virtual void drawOutline(CGraphicsPort *port); + + /** + * Selects the next option in the list and redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Prevents the CButton onResize() method from recalculating the text + * positions by overriding it. + * + * @param width The new width. + * @param height The new height. + */ + + virtual inline void onResize(nxgl_coord_t width, nxgl_coord_t height) { } + + /** + * Override method in Label class to prevent recalculation of text positions. + */ + + virtual inline void calculateTextPosition(void) { } + + /** + * Destructor. + */ + + virtual ~CCycleButton(void) { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CCycleButton(const CCycleButton &cycleButton) : CButton(cycleButton) { } + + public: + + /** + * Constructor for cycle buttons. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button, relative to its parent. + * @param y The y coordinate of the button, relative to its parent. + * @param width The width of the button. + * @param height The height of the button. + * @param style The style that the button should use. If this is not + * specified, the button will use the values stored in the global + * g_defaultWidgetStyle object. The button will copy the properties of + * the style into its own internal style object. + */ + + CCycleButton(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Add a new option to the widget. + * + * @param text The text of the option. + * @param value The value of the option. + */ + + void addOption(const CNxString &text, const uint32_t value); + + /** + * Remove an option from the widget by its index. + * + * @param index The index of the option to remove. + */ + + virtual void removeOption(const int index); + + /** + * Remove all options from the widget. + */ + + virtual void removeAllOptions(void); + + /** + * Select an option by its index. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual void selectOption(const int index); + + /** + * Get the selected index. Returns -1 if nothing is selected. If more than one + * option is selected, the index of the first selected option is returned. + * + * @return The selected index. + */ + + virtual const int getSelectedIndex(void) const; + + /** + * Sets the selected index. Specify -1 to select nothing. Resets any + * other selected options to deselected. + * Redraws the widget and raises a value changed event. + * + * @param index The selected index. + */ + + virtual void setSelectedIndex(const int index); + + /** + * Get the selected option. Returns NULL if nothing is selected. + * + * @return The selected option. + */ + + virtual const CListDataItem *getSelectedOption(void) const; + + /** + * Get the value of the current option. + * + * @return Value of the current option. + */ + + inline const uint32_t getValue(void) const + { + return getSelectedOption()->getValue(); + } + + /** + * Get the specified option. + * + * @return The specified option. + */ + + virtual inline const CListDataItem *getOption(const int index) + { + return m_options.getItem(index); + } + + /** + * Sort the options alphabetically by the text of the options. + */ + + virtual void sort(void); + + /** + * Get the total number of options. + * + * @return The number of options. + */ + + virtual inline const int getOptionCount(void) const + { + return m_options.getItemCount(); + } + + /** + * Sets whether or not items added to the list are automatically sorted + * on insert or not. + * + * @param sortInsertedItems True to enable sort on insertion. + */ + + virtual inline void setSortInsertedItems(const bool sortInsertedItems) + { + m_options.setSortInsertedItems(sortInsertedItems); + } + + /** + * Handles list data changed events. + * + * @param e Event arguments. + */ + + virtual void handleListDataChangedEvent(const CListDataEventArgs &e); + + /** + * Handles list selection changed events. + * + * @param e Event arguments. + */ + + virtual void handleListDataSelectionChangedEvent(const CListDataEventArgs &e); + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the widget's + * parent. Value is based on the length of the largest string in the + * set of options. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CCYLEBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/cglyphbutton.hxx b/NxWidgets/libnxwidgets/include/cglyphbutton.hxx new file mode 100644 index 000000000..aad348ca9 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cglyphbutton.hxx @@ -0,0 +1,229 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CGLYPHBUTTON_HXX +#define __INCLUDE_CGLYPHBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + struct SBitmap; + + /** + * Class representing a button that will display a glyph. + * Class representing a clickable button that contains a bitmap image + * instead of text. Displays two bitmaps, one when the button is clicked, + * and one when it isn't. The bitmaps should be the same size. + */ + + class CGlyphButton : public CNxWidget + { + protected: + + FAR const struct SBitmap *m_bitmapNormal; /**< Bitmap when button is not clicked */ + FAR const struct SBitmap *m_bitmapClicked; /**< Bitmap when button is clicked */ + nxgl_coord_t m_bitmapX; /**< X coordinate of the bitmaps */ + nxgl_coord_t m_bitmapY; /**< Y coordinate of the bitmaps */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * + * @param port Graphics port to draw to. + */ + + virtual void drawOutline(CGraphicsPort *port); + + /** + * Redraws the button. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raises an action event and redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CGlyphButton(const CGlyphButton &button) : CNxWidget(button) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button. + * @param y The y coordinate of the button. + * @param width The width of the button. + * @param height The height of the button. + * @param normalGlyph Glyph to display when unclicked. + * @param clickedGlyph Glyph to display when clicked. + * @param bitmapX The x coordinate at which the bitmaps will be drawn. + * @param bitmapY The y coordinate at which the bitmaps will be drawn. + * @param style The style that the button should use. If this is not + * specified, the button will use the values stored in the global + * g_defaultWidgetStyle object. The button will copy the properties of + * the style into its own internal style object. + */ + + CGlyphButton(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + nxgl_coord_t bitmapX, nxgl_coord_t bitmapY, + FAR const struct SBitmap *normalGlyph, + FAR const struct SBitmap *clickedGlyph, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CGlyphButton(void) { } + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the widget's + * parent. + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CGLYPHBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/cgraphicsport.hxx b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx new file mode 100644 index 000000000..404fb1d51 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx @@ -0,0 +1,411 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cgraphicsport.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CGRAPHICSPORT_HXX +#define __INCLUDE_CGRAPHICSPORT_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "inxwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxFont; + class CNxString; + class CRect; + struct SBitmap; + + /** + * CGraphicsPort is the interface between a NXwidget and NX layer. + */ + + class CGraphicsPort + { + private: + INxWindow *m_pNxWnd; /**< NX window interface. */ + + public: + /** + * Constructor. + * + * @param pNxWnd An instance of the underlying window type. + */ + + CGraphicsPort(INxWindow *pNxWnd); + + /** + * Destructor. + */ + + virtual ~CGraphicsPort(); + + /** + * Return the absolute x coordinate of the upper left hand corner of the + * underlying window. + * + * @return The x coordinate of the window. + */ + + const nxgl_coord_t getX(void) const; + + /** + * Return the absolute y coordinate of the upper left hand corner of the + * underlying window. + * + * @return The y coordinate of the window. + */ + + const nxgl_coord_t getY(void) const; + + /** + * Draw a pixel into the window. + * + * @param x The window-relative x coordinate of the pixel. + * @param y The window-relative y coordinate of the pixel. + * @param color The color of the pixel. + */ + + void drawPixel(nxgl_coord_t x, nxgl_coord_t y, nxgl_mxpixel_t color); + + /** + * Draw a horizontal line of the specified start position, width, and + * color. + * + * @param x The x coordinate of the line. + * @param y The y coordinate of the top-most end of the line. + * @param width The width of the line in pixels. + * @param color The color of the line. + */ + + void drawHorizLine(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + nxgl_mxpixel_t color); + + /** + * Draw a vertical line of the specified start position, width, and + * color. + * + * @param x The x coordinate of the left-most end of the line. + * @param y The y coordinate of the line. + * @param height The height of the line in rows. + * @param color The color of the line. + */ + + void drawVertLine(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t height, + nxgl_mxpixel_t color); + + /** + * Draw a line of a fixed color in the window. + * + * @param x1 The x coordinate of the start point of the line. + * @param y1 The y coordinate of the start point of the line. + * @param x2 The x coordinate of the end point of the line. + * @param y2 The y coordinate of the end point of the line. + * @param color The color of the line. + */ + + void drawLine(nxgl_coord_t x1, nxgl_coord_t y1, + nxgl_coord_t x2, nxgl_coord_t y2, + nxgl_mxpixel_t color); + + /** + * Draw a filled rectangle of the specified start position, end position, + * width, and color. + * + * @param x The window-relative x coordinate of the rectangle. + * @param y The window-relative y coordinate of the rectangle. + * @param width The width of the rectangle in pixels. + * @param height The height of the rectangle in rows. + * @param color The color of the rectangle. + */ + + void drawFilledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + nxgl_coord_t height, nxgl_mxpixel_t color); + + /** + * Draw an unfilled rectangle to the window + * + * @param x The window-relative x coordinate of the rectangle. + * @param y The window-relative y coordinate of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param color The color of the rectangle . + */ + + void drawRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + nxgl_coord_t height, nxgl_mxpixel_t color); + + /** + * Draw a bevelled rectangle to the window. + * + * @param x The x coordinate of the rectangle. + * @param y The y coordinate of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param shineColor The color of the top/left sides. + * @param shadowColor The color of the bottom/right sides. + */ + + void drawBevelledRect(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + nxgl_mxpixel_t shineColor, + nxgl_mxpixel_t shadowColor); + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + inline void drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color) + { + (void)m_pNxWnd->drawFilledCircle(center, radius, color); + } + + /** + * Draw a string to the window. + * @param pos The window-relative x/y coordinate of the string. + * @param bound The window-relative bounds of the string. + * @param font The font to draw with. + * @param string The string to output. + */ + + void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string); + + /** + * Draw a particular length of a string to the window in a secific color. + * @param pos The window-relative x/y coordinate of the string. + * @param bound The window-relative bounds of the string. + * @param font The font to draw with. + * @param string The string to output. + * @param startIndex The start index within the string from which + * drawing will commence. + * @param length The number of characters to draw. + * @param color The color of the string. + */ + + void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string, int startIndex, int length, + nxgl_mxpixel_t color); + + /** + * Draw a portion of a string to the window. + * @param pos The window-relative x/y coordinate of the string. + * @param bound The window-relative bounds of the string. + * @param font The font to draw with. + * @param string The string to output. + * @param startIndex The start index within the string from which + * drawing will commence. + * @param length The number of characters to draw. + */ + + void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string, int startIndex, int length); + + /** + * Draw an opaque bitmap to the window. + * + * @param x The window-relative x coordinate to draw the bitmap to. + * @param y The window-relative y coordinate to draw the bitmap to. + * @param width The width of the bitmap to draw. + * @param height The height of the bitmap to draw. + * @param bitmap Pointer to the bitmap to draw. + * @param bitmapX The window-relative x coordinate within the supplied + * bitmap to use as the origin. + * @param bitmapY The window-relative y coordinate within the supplied + * bitmap to use as the origin. + */ + + void drawBitmap(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const struct SBitmap *bitmap, int bitmapX, int bitmapY); + + /** + * Draw a bitmap to the window, using the supplied transparent + * color as an invisible color. + * + * @param x The window-relative x coordinate to draw the bitmap to. + * @param y The window-relative y coordinate to draw the bitmap to. + * @param width The width of the bitmap to draw. + * @param height The height of the bitmap to draw. + * @param bitmap Pointer to the bitmap to draw. + * @param bitmapX The window-relative x coordinate within the supplied bitmap to use as + * the origin. + * @param bitmapY The window-relative y coordinate within the supplied bitmap to use as + * the origin. + * @param transparentColor The transparent color used in the bitmap. + */ + + void drawBitmap(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const struct SBitmap *bitmap, int bitmapX, int bitmapY, + nxgl_mxpixel_t transparentColor); + + /** + * Draw a bitmap to the port in greyscale. + * + * @param x The window-relative x coordinate to draw the bitmap to. + * @param y The window-relative y coordinate to draw the bitmap to. + * @param width The width of the bitmap to draw. + * @param height The height of the bitmap to draw. + * @param bitmap Pointer to the bitmap to draw. + * @param bitmapX The window-relative x coordinate within the supplied bitmap to use as + * the origin. + * @param bitmapY The window-relative y coordinate within the supplied bitmap to use as + * the origin. + */ + + void drawBitmapGreyScale(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const struct SBitmap *bitmap, int bitmapX, int bitmapY); + + /** + * Copy a rectangular region from the source coordinateinates to the + * destination coordinateinates. + * + * @param sourceX Source x coordinate. + * @param sourceY Source y coordinate. + * @param destX Destination x coordinate. + * @param destY Destination y coordinate. + * @param width Width of the rectangle to copy. + * @param height Height of the rectangle to copy. + */ + + void copy(nxgl_coord_t sourceX, nxgl_coord_t sourceY, + nxgl_coord_t destX, nxgl_coord_t destY, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Move a region by a specified distance in two dimensions. + * + * @param x X coordinate of the source area to move. + * @param y Y coordinate of the source area to move. + * @param deltaX Horizontal distance to move. + * @param deltaY Vertical distance to move. + * @param width Width of the area to move. + * @param height Height of the area to move. + */ + + void move(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t deltaX, nxgl_coord_t deltaY, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Convert the region to greyscale. + * + * @param x X coordinate of the region to change. + * @param y Y coordinate of the region to change. + * @param width Width of the region to change. + * @param height Height of the region to change. + */ + + void greyScale(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Invert colors in a region. NOTE: This allocates an in-memory + * buffer the size of one row in graphic memory. So it may only be + * useful for inverting small regions and its only current use of for + * the inverted cursor text. + * + * @param x X coordinate of the region to change. + * @param y Y coordinate of the region to change. + * @param width Width of the region to change. + * @param height Height of the region to change. + */ + + void invert(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CGRAPHICSPORT_HXX diff --git a/NxWidgets/libnxwidgets/include/cimage.hxx b/NxWidgets/libnxwidgets/include/cimage.hxx new file mode 100644 index 000000000..fa87b3f9c --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cimage.hxx @@ -0,0 +1,199 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cimage.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CIMAGE_HXX +#define __INCLUDE_CIMAGE_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class IBitmap; + + /** + * Simple image widget for present static images in the widget framework. + */ + + class CImage : public CNxWidget + { + protected: + FAR IBitmap *m_bitmap; /**< Source bitmap image */ + struct nxgl_point_s m_origin; /**< Origin for offset image display position */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CImage(const CImage &label) : CNxWidget(label) { }; + + public: + + /** + * Constructor for a label containing a string. + * + * @param pWidgetControl The controlling widget for the display + * @param x The x coordinate of the image box, relative to its parent. + * @param y The y coordinate of the image box, relative to its parent. + * @param width The width of the textbox. + * @param height The height of the textbox. + * @param bitmap The source bitmap image. + * @param style The style that the widget should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CImage() { } + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the + * widget's parent. + * + * @param rect Reference to a rect to populate with data. + */ + + void getPreferredDimensions(CRect &rect) const; + + /** + * Set the horizontal position of the bitmap. Zero is the left edge + * of the bitmap and values >0 will move the bit map to the right. + * This method is useful for horizontal scrolling a large bitmap + * within a smaller window + */ + + void setImageLeft(nxgl_coord_t column); + + /** + * Set the vertical position of the bitmap. Zero is the top edge + * of the bitmap and values >0 will move the bit map down. + * This method is useful for vertical scrolling a large bitmap + * within a smaller window + */ + + void setImageTop(nxgl_coord_t row); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CIMAGE_HXX diff --git a/NxWidgets/libnxwidgets/include/ckeypad.hxx b/NxWidgets/libnxwidgets/include/ckeypad.hxx new file mode 100644 index 000000000..2f2a754d4 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ckeypad.hxx @@ -0,0 +1,156 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ckeypad.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CKEYPAD_HXX +#define __INCLUDE_CKEYPAD_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cbuttonarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CWidgetStyle; + + /** + * Extends the CButtonArray class to support a alphanumeric keypad. + */ + + class CKeypad : public CButtonArray + { + protected: + NXHANDLE m_hNxServer; /**< NX server handle */ + bool m_numeric; /**< True: Numeric keypad, False: Alpha */ + + /** + * Configure the keypad for the currenly selected display mode. + */ + + void configureKeypadMode(void); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CKeypad(const CKeypad &keypad) : CButtonArray(keypad) { } + + public: + + /** + * Constructor for buttons that display a string. + * + * @param pWidgetControl The widget control for the display. + * @param hNxServer The NX server that will receive the keyboard input + * @param x The x coordinate of the keypad, relative to its parent. + * @param y The y coordinate of the keypad, relative to its parent. + * @param width The width of the keypad + * @param height The height of the keypad + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CKeypad(CWidgetControl *pWidgetControl, NXHANDLE hNxServer, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * CKeypad Destructor. + */ + + inline ~CKeypad(void) {} + + /** + * Returns the current keypad display mode + * + * @return True: keypad is in numeric mode. False: alphanumeric. + */ + + inline const bool isNumericKeypad(void) const + { + return m_numeric; + } + + /** + * Returns the current keypad display mode + * + * @param mode True: put keypad in numeric mode. False: in alphanumeric. + */ + + inline void setKeypadMode(bool numeric) + { + m_numeric = numeric; + configureKeypadMode(); + } + + /** + * Catch button clicks. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CKEYPAD_HXX diff --git a/NxWidgets/libnxwidgets/include/clabel.hxx b/NxWidgets/libnxwidgets/include/clabel.hxx new file mode 100644 index 000000000..62ed1cda7 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clabel.hxx @@ -0,0 +1,355 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clabel.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLABEL_HXX +#define __INCLUDE_CLABEL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgetstyle.hxx" +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CRect; + + /** + * Single-line label widget. Can align text both vertically and + * horizontally in different ways. + */ + + class CLabel : public CNxWidget + { + public: + + /** + * Enum of horizontal alignment options. + */ + + enum TextAlignmentHoriz + { + TEXT_ALIGNMENT_HORIZ_CENTER = 0, /**< Centre the text */ + TEXT_ALIGNMENT_HORIZ_LEFT = 1, /**< Align left */ + TEXT_ALIGNMENT_HORIZ_RIGHT = 2 /**< Align right */ + }; + + /** + * Enum of vertical alignment options. + */ + + enum TextAlignmentVert + { + TEXT_ALIGNMENT_VERT_CENTER = 0, /**< Align to centre of textbox */ + TEXT_ALIGNMENT_VERT_TOP = 1, /**< Align to top of textbox */ + TEXT_ALIGNMENT_VERT_BOTTOM = 2 /**< Align to bottom of textbox */ + }; + + protected: + CNxString m_text; /**< Text that the textbox will display */ + struct nxgl_point_s m_align; /**< X/Y offset for text alignment */ + TextAlignmentHoriz m_hAlignment; /**< Horizontal alignment of the text */ + TextAlignmentVert m_vAlignment; /**< Vertical alignment of the text */ + bool m_textChange; /**< Redraw is due to a text change */ + bool m_highlighted; /**< Label is highlighted */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * @param port The CGraphicsPort to draw to. + * + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Resize the widget to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Calculate the vertical position of the string based on the font + * + * height and the alignment options. + */ + + virtual void calculateTextPositionVertical(void); + + /** + * Calculate the position of the string based on its length and the + * alignment options. + */ + + virtual void calculateTextPositionHorizontal(void); + + /** + * Updates the GUI after the text has changed. + */ + + virtual void onTextChange(void); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CLabel(const CLabel &label) : CNxWidget(label) { }; + + public: + + /** + * Constructor for a label containing a string. + * + * @param pWidgetControl The controlling widget for the display + * @param x The x coordinate of the text box, relative to its parent. + * @param y The y coordinate of the text box, relative to its parent. + * @param width The width of the textbox. + * @param height The height of the textbox. + * @param text Pointer to a string to display in the textbox. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CLabel(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CLabel() { } + + /** + * Set the horizontal alignment of text within the label. + * + * @param alignment The horizontal position of the text. + */ + + virtual void setTextAlignmentHoriz(TextAlignmentHoriz alignment); + + /** + * Set the vertical alignment of text within the label. + * + * @param alignment The vertical position of the text. + */ + + virtual void setTextAlignmentVert(TextAlignmentVert alignment); + + /** + * Set the horizontal alignment of text within the label. + * + * @param alignment The horizontal position of the text. + */ + + inline const TextAlignmentHoriz getTextAlignmentHoriz(void) const + { + return m_hAlignment; + } + + /** + * Set the vertical alignment of text within the label. + * + * @param alignment The vertical position of the text. + */ + + inline const TextAlignmentVert getTextAlignmentVert(void) const + { + return m_vAlignment; + } + + /** + * Returns the string shown in the label. + * + * @return The label's text. + */ + + virtual inline const CNxString &getText(void) const + { + return m_text; + } + + /** + * Set the text displayed in the label. + * + * @param text String to display. + */ + + virtual void setText(const CNxString &text); + + /** + * Append new text to the end of the current text displayed in the + * label. + * + * @param text String to append. + */ + + virtual void appendText(const CNxString &text); + + /** + * Insert text at the specified index. + * + * @param text The text to insert. + * @param index Index at which to insert the text. + */ + + virtual void insertText(const CNxString &text, const int index); + + /** + * Control the highlight state. + * + * @param highlightOn True(1), the label will be highlighted + */ + + virtual void highlight(bool highlightOn); + + /** + * Return the current highlight state. + * + * @return True if the label is highlighted + */ + + virtual inline bool isHighlighted(void) const + { + return m_highlighted; + } + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the + * widget's parent. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + + /** + * Sets the font. + * + * @param font A pointer to the font to use. + */ + + virtual void setFont(CNxFont *font); + + /** + * Is the redraw due to a text-only change? + * + * @return True if the redraw was caused by a text change + */ + + virtual inline bool isTextChange(void) const + { + return m_textChange; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLABEL_HXX diff --git a/NxWidgets/libnxwidgets/include/clatchbutton.hxx b/NxWidgets/libnxwidgets/include/clatchbutton.hxx new file mode 100644 index 000000000..c0b37d64b --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clatchbutton.hxx @@ -0,0 +1,173 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clatchbutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLATCHBUTTON_HXX +#define __INCLUDE_CLATCHBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cstickybutton.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * CButton that latches down when clicked and unlatches when clicked again. + */ + + class CLatchButton : public CStickyButton + { + protected: + /** + * Handles button click events + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CLatchButton(const CLatchButton &button) : CStickyButton(button) { } + + public: + + /** + * Constructor for buttons that display a string. + * + * @param pWidgetControl The controlling widget for the display. + * @param x The x coordinate of the button, relative to its parent. + * @param y The y coordinate of the button, relative to its parent. + * @param width The width of the button. + * @param height The height of the button. + * @param text The text for the button to display. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CLatchButton(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const CNxString &text, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CLatchButton(void) { } + + /** + * Check if the button is latched + * + * @return True if the button is latched + */ + + inline const bool isLatched(void) const + { + return isStuckDown(); + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLATCHBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/clatchbuttonarray.hxx b/NxWidgets/libnxwidgets/include/clatchbuttonarray.hxx new file mode 100644 index 000000000..bffeb58a1 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clatchbuttonarray.hxx @@ -0,0 +1,170 @@ +/**************************************************************************** + * include/clatchbuttonarray.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLATCHBUTTONARRAY_HXX +#define __INCLUDE_CLATCHBUTTONARRAY_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cstickybuttonarray.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CNxString; + + /** + * Manages a two-dimensional array of buttons as one widget. When a button + * is clicked is latches (i.e., it stays pushed after the press is released. + * The behavior is then like radio buttons: Pressing each each button in + * the array unlatches the previous button and latches the new button. + * + * Unlike CLatchButton, pressing the same button more than once has no + * effect. + */ + + class CLatchButtonArray : public CStickyButtonArray + { + protected: + /** + * Handles button click events + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the button. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CLatchButtonArray(const CLatchButtonArray &button) : CStickyButtonArray(button) { } + + public: + + /** + * Constructor for an array of latch buttons. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button array, relative to its parent. + * @param y The y coordinate of the button array, relative to its parent. + * @param buttonColumns The number of buttons in one row of the button array + * @param buttonRows The number of buttons in one column of the button array + * @param buttonWidth The width of one button + * @param buttonHeight The height of one button + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CLatchButtonArray(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + uint8_t buttonColumns, uint8_t buttonRows, + nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * CLatchButtonArray Destructor. + */ + + virtual inline ~CLatchButtonArray(void) { } + + /** + * Return the position of the last latched button (0,0 will be returned + * the no button has every been latched). The button at this position + * is currently latched then, in addition, return true. + * + * @param column The location to return the column index of the button + * of interest + * @param row The location to return the row index of the button of + * interest + * @return True if a button in the array is latched + */ + + inline const bool isAnyButtonLatched(int &column, int &row) const + { + return isAnyButtonStuckDown(column, row); + } + + /** + * Check if this specific button in the array is latched + * + * @param column The column of the button to check. + * @param row The row of the button to check. + * @return True if this button is clicked + */ + + inline const bool isThisButtonLatched(int column, int row) const + { + return isThisButtonStuckDown(column, row); + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLATCHBUTTONARRAY_HXX diff --git a/NxWidgets/libnxwidgets/include/clistbox.hxx b/NxWidgets/libnxwidgets/include/clistbox.hxx new file mode 100644 index 000000000..7afa76920 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clistbox.hxx @@ -0,0 +1,431 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clistbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in all NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLISTBOX_HXX +#define __INCLUDE_CLISTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nxconfig.hxx" +#include "cscrollingpanel.hxx" +#include "ilistdataeventhandler.hxx" +#include "clistdata.hxx" +#include "clistboxdataitem.hxx" +#include "cwidgetstyle.hxx" +#include "ilistbox.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class providing a scrollable list of options. The CListBox can be set + * up to only allow one selection or multiple selections. Processes + * double-clicks and raises double-click events, so that a double-click + * on an option can be made to automatically select and close a window/etc. + * The options themselves have user-definable text and background colors + * for their selected and unselected states. + */ + + class CListBox : public IListBox, public CScrollingPanel, + public IListDataEventHandler + { + protected: + CListData m_options; /**< Option storage. */ + uint8_t m_optionPadding; /**< Padding between options. */ + int m_lastSelectedIndex; /**< Index of the last option selected. */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Determines which item was clicked and selects or deselects it as + * appropriate. Also starts the dragging system. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Selects the clicked item and deselects all others. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Select or deselect an option by its index. Does not deselect any other + * selected options. Set index to -1 to select nothing. Redraws the widget + * and raises a value changed event. + * + * @param index The index of the option to select. + * @param selected True to select the option, false to deselect it. + */ + + virtual void setOptionSelected(const int index, const bool selected); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CListBox(const CListBox &listBox) : CScrollingPanel(listBox) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display. + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CListBox(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual ~CListBox(void); + + /** + * Add a new option to the widget using default colors. + * + * @param text Text to show in the option. + * @param value The value of the option. + */ + + virtual void addOption(const CNxString &text, const uint32_t value); + + /** + * Add an option to the widget. + * + * @param option The option to add. + */ + + virtual void addOption(CListBoxDataItem *option); + + /** + * Remove an option from the widget by its index. + * + * @param index The index of the option to remove. + */ + + virtual void removeOption(const int index); + + /** + * Remove all options from the widget. + */ + + virtual void removeAllOptions(void); + + /** + * Add a new option to the widget. + * + * @param text Text to show in the option. + * @param value The value of the option. + * @param normalTextColor Color to draw the text with when not selected. + * @param normalBackColor Color to draw the background with when not selected. + * @param selectedTextColor Color to draw the text with when selected. + * @param selectedBackColor Color to draw the background with when selected. + */ + + virtual void addOption(const CNxString &text, const uint32_t value, + const nxwidget_pixel_t normalTextColor, + const nxwidget_pixel_t normalBackColor, + const nxwidget_pixel_t selectedTextColor, + const nxwidget_pixel_t selectedBackColor); + + /** + * Select an option by its index. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual void selectOption(const int index); + + /** + * Select an option by its index. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual void deselectOption(const int index); + + /** + * Select all options. Does nothing if the listbox does not allow + * multiple selections. Redraws the widget and raises a value changed + * event. + */ + + virtual void selectAllOptions(void); + + /** + * Deselect all options. + * Redraws the widget and raises a value changed event. + */ + + virtual void deselectAllOptions(void); + + /** + * Get the selected index. Returns -1 if nothing is selected. If + * more than one option is selected, the index of the first selected + * option is returned. + * + * @return The selected index. + */ + + virtual const int getSelectedIndex(void) const; + + /** + * Sets the selected index. Specify -1 to select nothing. Resets any + * other selected options to deselected. Redraws the widget and raises + * a value changed event. + * + * @param index The selected index. + */ + + virtual void setSelectedIndex(const int index); + + /** + * Get the selected option. Returns NULL if nothing is selected. + * + * @return The selected option. + */ + + virtual const CListBoxDataItem *getSelectedOption(void) const; + + /** + * Sets whether multiple selections are possible or not. + * + * @param allowMultipleSelections True to allow multiple selections. + */ + + virtual inline void + setAllowMultipleSelections(const bool allowMultipleSelections) + { + m_options.setAllowMultipleSelections(allowMultipleSelections); + } + + /** + * Sets whether multiple selections are possible or not. + * + * @return True if multiple selections are allowed. + */ + + virtual inline const bool allowsMultipleSelections(void) const + { + return m_options.allowsMultipleSelections(); + } + + /** + * Resize the scrolling canvas to encompass all options. + */ + + virtual void resizeCanvas(void); + + /** + * Get the specified option. + * + * @return The specified option. + */ + + virtual inline const CListBoxDataItem *getOption(const int index) + { + return (const CListBoxDataItem *)m_options.getItem(index); + } + + /** + * Sort the options alphabetically by the text of the options. + */ + + virtual void sort(void); + + /** + * Get the total number of options. + * + * @return The number of options. + */ + + virtual inline const int getOptionCount(void) const + { + return m_options.getItemCount(); + } + + /** + * Get the height of a single option. + * + * @return The height of an option. + */ + + virtual const nxgl_coord_t getOptionHeight(void) const; + + /** + * Sets whether or not items added to the list are automatically sorted on insert or not. + * + * @param sortInsertedItems True to enable sort on insertion. + */ + + virtual inline void setSortInsertedItems(const bool sortInsertedItems) + { + m_options.setSortInsertedItems(sortInsertedItems); + } + + /** + * Handles list data changed events. + * + * @param e Event arguments. + */ + + virtual void handleListDataChangedEvent(const CListDataEventArgs &e); + + /** + * Handles list selection changed events. + * + * @param e Event arguments. + */ + + virtual void handleListDataSelectionChangedEvent(const CListDataEventArgs &e); + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the widget's + * parent. Value is based on the length of the largest string in the + * set of options. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + + /** + * Check if the click is a double-click. + * + * @param x X coordinate of the click. + * @param y Y coordinate of the click. + * @return True if the click is a double-click. + */ + + virtual bool isDoubleClick(nxgl_coord_t x, nxgl_coord_t y); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLISTBOX_HXX + diff --git a/NxWidgets/libnxwidgets/include/clistboxdataitem.hxx b/NxWidgets/libnxwidgets/include/clistboxdataitem.hxx new file mode 100644 index 000000000..9a1358d39 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clistboxdataitem.hxx @@ -0,0 +1,180 @@ +/**************************************************************************** + * include/clistboxdataitem.hxx + * NxWidgets/libnxwidgets/ + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLISTBOXDATAITEM_HXX +#define __INCLUDE_CLISTBOXDATAITEM_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "clistdataitem.hxx" +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class representing a data item within a ListBox. + */ + + class CListBoxDataItem : public CListDataItem + { + private: + nxwidget_pixel_t m_normalTextColor; /**< Color used for text when not selected. */ + nxwidget_pixel_t m_normalBackColor; /**< Color used for background when not selected. */ + nxwidget_pixel_t m_selectedTextColor; /**< Color used for text when selected. */ + nxwidget_pixel_t m_selectedBackColor; /**< Color used for background when selected. */ + + public: + + /** + * Constructor. + * + * @param text The text to display in the item. + * @param value The value of the item. + * @param normalTextColor Color to draw the text with when not selected. + * @param normalBackColor Color to draw the background with when not selected. + * @param selectedTextColor Color to draw the text with when selected. + * @param selectedBackColor Color to draw the background with when selected. + */ + + CListBoxDataItem(const CNxString &text, const uint32_t value, + const nxwidget_pixel_t normalTextColor, + const nxwidget_pixel_t normalBackColor, + const nxwidget_pixel_t selectedTextColor, + const nxwidget_pixel_t selectedBackColor); + + /** + * Get the color used for text when the item is unselected. + * + * @return The text color when the item is unselected. + */ + + inline nxwidget_pixel_t getNormalTextColor(void) const + { + return m_normalTextColor; + } + + /** + * Get the color used for the background when the item is unselected. + * + * @return The background color when the item is unselected. + */ + + inline nxwidget_pixel_t getNormalBackColor(void) const + { + return m_normalBackColor; + } + + /** + * Get the color used for text when the item is selected. + * + * @return The text color when the item is selected. + */ + + inline nxwidget_pixel_t getSelectedTextColor(void) const + { + return m_selectedTextColor; + } + + /** + * Get the color used for the background when the item is selected. + * + * @return The background color when the item is selected. + */ + + inline nxwidget_pixel_t getSelectedBackColor(void) const + { + return m_selectedBackColor; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLISTBOXDATAITEM_HXX + diff --git a/NxWidgets/libnxwidgets/include/clistdata.hxx b/NxWidgets/libnxwidgets/include/clistdata.hxx new file mode 100644 index 000000000..d88abd9fc --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clistdata.hxx @@ -0,0 +1,351 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clistdata.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLISTDATA_HXX +#define __INCLUDE_CLISTDATA_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "tnxarray.hxx" +#include "ilistdataeventhandler.hxx" +#include "clistdataitem.hxx" +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class representing a list of items. Designed to be used by the + * CListBox class, etc, to store its data. Fires events to notify + * listeners when the list changes or a new selection is made. + */ + + class CListData + { + protected: + TNxArray m_items; /**< Collection of list data items. */ + TNxArray m_listDataEventhandlers; /**< Collection of event handlers. */ + bool m_allowMultipleSelections; /**< If true, multiple options can + be selected. */ + bool m_sortInsertedItems; /**< Automatically sorts items on + insertion if true. */ + + /** + * Quick sort the items using their compareTo() methods. + * + * @param start The index to start sorting at. + * @param end The index to stop sorting at. + */ + + virtual void quickSort(const int start, const int end); + + /** + * Swap the locations of two items in the array. + * + * @param index1 The index of the first item to swap. + * @param index2 The index of the second item to swap. + */ + + virtual void swapItems(const int index1, const int index2); + + /** + * Return the index that an item should be inserted at to maintain a sorted list of data. + * + * @param item The item to insert. + * @return The index that the item should be imserted into at. + */ + + const int getSortedInsertionIndex(const CListDataItem *item) const; + + /** + * Raise a data changed event. + */ + + void raiseDataChangedEvent(void); + + /** + * Raise a selection changed event. + */ + + void raiseSelectionChangedEvent(void); + + public: + + /** + * Constructor. + */ + CListData(void); + + /** + * Destructor. + */ + virtual ~CListData(void); + + /** + * Add a new item. + * + * @param text Text to show in the option. + * @param value The value of the option. + */ + + virtual void addItem(const CNxString &text, const uint32_t value); + + /** + * Add an existing item. CListData becomes the owner of the option and will delete it + * when the list is deleted. + * + * @param item The item to add. + */ + + virtual void addItem(CListDataItem *item); + + /** + * Remove an item by its index. + * + * @param index The index of the option to remove. + */ + + virtual void removeItem(const int index); + + /** + * Select an item by its index. + * + * @param index The index of the item to select. + */ + + virtual void selectItem(const int index); + + /** + * Deselect an item by its index. + * + * @param index The index of the item to select. + */ + + virtual void deselectItem(const int index); + + /** + * Remove all items. + */ + + virtual void removeAllItems(void); + + /** + * Get the selected index. Returns -1 if nothing is selected. If more than one + * item is selected, the index of the first selected item is returned. + * + * @return The selected index. + */ + + virtual const int getSelectedIndex(void) const; + + /** + * Sets the selected index. Specify -1 to select nothing. Resets any + * other selected items to deselected. + * + * @param index The selected index. + */ + + virtual void setSelectedIndex(const int index); + + /** + * Get the selected item. Returns NULL if nothing is selected. + * + * @return The selected option. + */ + + virtual const CListDataItem *getSelectedItem(void) const; + + /** + * Sets whether multiple selections are possible or not. + * + * @param allowMultipleSelections True to allow multiple selections. + */ + + virtual inline void + setAllowMultipleSelections(const bool allowMultipleSelections) + { + m_allowMultipleSelections = allowMultipleSelections; + } + + /** + * Get the specified item. + * + * @return The specified item. + */ + + virtual inline const CListDataItem *getItem(const int index) const + { + return m_items[index]; + } + + /** + * Sort the items using their compareTo() methods. + */ + + virtual void sort(void); + + /** + * Get the total number of items. + * + * @return The number of items. + */ + + virtual inline const int getItemCount(void) const + { + return m_items.size(); + } + + /** + * Select all items. Does nothing if the list does not allow + * multiple selections. + */ + + virtual void selectAllItems(void); + + /** + * Deselect all items. + */ + + virtual void deselectAllItems(void); + + /** + * Select or deselect an item by its index. Does not deselect any + * other selected items. Set index to -1 to select nothing. + * + * @param index The index of the item to select. + * @param selected True to select the item, false to deselect it. + */ + + virtual void setItemSelected(const int index, const bool selected); + + /** + * Returns whether multiple selections are possible or not. + * + * @return True if multiple selections are allowed. + */ + + virtual inline const bool allowsMultipleSelections(void) const + { + return m_allowMultipleSelections; + } + + /** + * Sets whether or not items added to the list are automatically + * sorted on insert or not. + * + * @param sortInsertedItems True to enable sort on insertion. + */ + + virtual inline void setSortInsertedItems(const bool sortInsertedItems) + { + m_sortInsertedItems = sortInsertedItems; + } + + /** + * Add an event handler. + * + * @param eventHandler The event handler to add. + */ + + inline void addListDataEventHandler(IListDataEventHandler *eventHandler) + { + m_listDataEventhandlers.push_back(eventHandler); + } + + /** + * Remove an event handler. + * + * @param eventHandler The event handler to remove. + */ + + void removeListDataEventHandler(IListDataEventHandler *eventHandler); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLISTDATA_HXX diff --git a/NxWidgets/libnxwidgets/include/clistdataeventargs.hxx b/NxWidgets/libnxwidgets/include/clistdataeventargs.hxx new file mode 100644 index 000000000..57118e238 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clistdataeventargs.hxx @@ -0,0 +1,121 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clistdataeventargs.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLISTDATAEVENTARGS_HXX +#define __INCLUDE_CLISTDATAEVENTARGS_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "teventargs.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CListData; + + /** + * Event arguments passed to listeners when a CListData object raises an + * event. + */ + + class CListDataEventArgs : public TEventArgs + { + public: + + /** + * Constructor. + * + * @param source Pointer to the CListData object that raised the event. + */ + + inline CListDataEventArgs(CListData *source) : TEventArgs(source) + { + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLISTDATAEVENTARGS_HXX diff --git a/NxWidgets/libnxwidgets/include/clistdataitem.hxx b/NxWidgets/libnxwidgets/include/clistdataitem.hxx new file mode 100644 index 000000000..db3bb20a2 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/clistdataitem.hxx @@ -0,0 +1,189 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/clistdataitem.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CLISTDATAITEM_HXX +#define __INCLUDE_CLISTDATAITEM_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class representing a data item within a list. Intended for use within + * the CListData class. + */ + + class CListDataItem + { + private: + CNxString m_text; /**< Text to display for option. */ + uint32_t m_value; /**< Option value. */ + bool m_isSelected; /**< True if the option is selected. */ + + public: + + /** + * Constructor. + * + * @param text The text to display in the item. + * @param value The value of the item. + */ + + CListDataItem(const CNxString &text, const uint32_t value); + + /** + * Destructor. + */ + + virtual ~CListDataItem(void); + + /** + * Get the item's text. + * + * @return The item's text. + */ + + inline const CNxString &getText(void) const + { + return m_text; + } + + /** + * Get the item's value. + * + * @return The item's value. + */ + + inline const uint32_t getValue(void) const + { + return m_value; + } + + /** + * Get the item's selection state. + * + * @return True if the item is selected; false if not. + */ + + inline const bool isSelected(void) const + { + return m_isSelected; + } + + /** + * Set the item's selection state. + * + * @param selected True to select the item; false to deselect it. + */ + + inline void setSelected(bool selected) + { + m_isSelected = selected; + } + + /** + * Compare the item with another. Comparison is based on the text of + * the item. Returns 0 if the text in the two items is the same, + * a value less than 0 if this item is less than the argument, and + * a value greater than 0 if this item is greater than the argument. + * + * @param item An item to compare this object with. + * @return 0 if the text in the two items is the same, + * a value less than 0 if this item is less than the argument, and + * a value greater than 0 if this item is greater than the argument. + */ + + virtual int compareTo(const CListDataItem *item) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CLISTDATAITEM_HXX diff --git a/NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx b/NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx new file mode 100644 index 000000000..5ed41740b --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx @@ -0,0 +1,621 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CMULTILINETEXTBOX_HXX +#define __INCLUDE_CMULTILINETEXTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "cscrollingpanel.hxx" +#include "cwidgetstyle.hxx" +#include "cnxstring.hxx" +#include "ctext.hxx" +#include "cwidgeteventhandler.hxx" +#include "itextbox.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxTimer; + + /** + * Textbox that offers multiple lines of text. Has scrolling + * capability and can be dragged using the mouse. The text + * it contains can be changed or added to. It can remember more + * rows of text than it can display, and these additional + * rows can be scrolled through. + */ + + class CMultiLineTextBox : public ITextBox, public CScrollingPanel, + public CWidgetEventHandler + { + public: + + /** + * Enum of horizontal alignment options. + */ + + enum TextAlignmentHoriz + { + TEXT_ALIGNMENT_HORIZ_CENTER = 0, /**< Centre the text */ + TEXT_ALIGNMENT_HORIZ_LEFT = 1, /**< Align left */ + TEXT_ALIGNMENT_HORIZ_RIGHT = 2 /**< Align right */ + }; + + /** + * Enum of vertical alignment options. + */ + + enum TextAlignmentVert + { + TEXT_ALIGNMENT_VERT_CENTER = 0, /**< Align to centre of textbox */ + TEXT_ALIGNMENT_VERT_TOP = 1, /**< Align to top of textbox */ + TEXT_ALIGNMENT_VERT_BOTTOM = 2 /**< Align to bottom of textbox */ + }; + + protected: + CText *m_text; /**< CText object that manipulates + and wraps the raw text string. */ + uint8_t m_visibleRows; /**< Total number of rows that the + textbox can display at once. */ + nxgl_coord_t m_maxRows; /**< Maximum number of rows that the + textbox should buffer. */ + int32_t m_topRow; /**< Index of the top row of text + currently displayed. */ + TextAlignmentHoriz m_hAlignment; /**< Horizontal alignment of the text. */ + TextAlignmentVert m_vAlignment; /**< Vertical alignment of the text. */ + int m_cursorPos; /**< Position of the cursor within + the string. */ + uint8_t m_showCursor; /**< Cursor visibility. */ + bool m_wrapCursor; /**< True wrap cursor at the ends of the text */ + + /** + * Get the coordinates of the cursor relative to the text. + * + * @param x Will be populated with the x coordinate of the cursor. + * @param y Will be populated with the y coordinate of the cursor. + */ + + virtual void getCursorCoordinates(nxgl_coord_t& x, nxgl_coord_t& y) const; + + /** + * Gets the index of the character at the specified x coordinate in the + * specified row. + * + * @param x X coordinate of the character. + * @param rowIndex Index of the row containing the character. + * @return The index of the character at the specified coordinate. + */ + + virtual int getCharIndexAtCoordinate(nxgl_coord_t x, int rowIndex) const; + + /** + * Get the index of the character at the specified coordinates. + * + * @param x X coordinate of the character. + * @param y Y coordinate of the character. + * @return The index of the character at the specified coordinates. + */ + + virtual unsigned int getCharIndexAtCoordinates(nxgl_coord_t x, nxgl_coord_t y) const; + + /** + * Get the row containing the specified Y coordinate. + * + * @param y Y coordinate to locate. + * @return The index of the row containing the specified Y coordinate. + */ + + int getRowContainingCoordinate(nxgl_coord_t y) const; + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Move cursor one character to the left. + */ + + virtual void moveCursorLeft(void); + + /** + * Move cursor one character to the right. + */ + + virtual void moveCursorRight(void); + + /** + * Move cursor one row upwards. + */ + + virtual void moveCursorUp(void); + + /** + * Move cursor one row downwards. + */ + + virtual void moveCursorDown(void); + + /** + * Ensures that the textbox only contains the maximum allowed + * number of rows by culling any excess rows from the top of + * the text. + * + * @return True if lines were removed from the text; false if not. + */ + + virtual bool cullTopLines(void); + + /** + * Ensures that the canvas height is the height of the widget, + * if the widget exceeds the size of the text, or the height of + * the text if the text exceeds the size of the widget. + */ + + virtual void limitCanvasHeight(void); + + /** + * Ensures that the canvas cannot scroll beyond its height. + */ + + virtual void limitCanvasY(void); + + /** + * Jumps to the cursor coordinates of the text. + */ + + void jumpToCursor(void); + + /** + * Jumps to the bottom of the text. + */ + + void jumpToTextBottom(void); + + /** + * Resize the textbox to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Starts the dragging system. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Opens the keyboard on the bottom display. + * + * @param x The x coordinates of the click. + * @param y The y coordinates of the click. + */ + + virtual void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Handles physical button presses. Moves the cursor + * in the direction pressed. + * + * @param key The key that was pressed. + */ + + void processPhysicalKey(nxwidget_char_t key); + + /** + * Handle a keyboard press event. + * + * @param e The event data. + */ + + void handleKeyPressEvent(const CWidgetEventArgs &e); + + /** + * Handle a cursor control event. Replaces CWidgetEventHandler method. + * + * @param e The event data. + */ + + void handleCursorControlEvent(const CWidgetEventArgs &e); + + /** + * Gets the x position of a row of text based on the width of the row and the + * type of horizontal alignment currently set. + * + * @param row The index of the row. + * @return The x coordinate of the row. + */ + + nxgl_coord_t getRowX(int row) const; + + /** + * Gets the y position of the specified row of text based on the type of + * vertical alignment currently set. + * + * @param row The row number to find the y coordinate of. + * @return The y coordinate of the specified row of text. + */ + + nxgl_coord_t getRowY(int row) const; + + /** + * Return true if the cursor is visible + */ + + virtual bool isCursorVisible(void) const; + + /** + * Gets the character under the cursor. + * + * @return The character under the cursor. + */ + + nxwidget_char_t getCursorChar(void) const; + + /** + * Works out the number of visible rows within the textbox. + */ + + void calculateVisibleRows(void); + + /** + * Draws text. + * + * @param port The CGraphicsPort to draw to. + */ + + void drawText(CGraphicsPort *port); + + /** + * Draws the cursor. + * + * @param port The CGraphicsPort to draw to. + */ + + void drawCursor(CGraphicsPort *port); + + /** + * Draws a single line of text. + * + * @param port The CGraphicsPort to draw to. + * @param row The index of the row to draw. + */ + + void drawRow(CGraphicsPort *port, int row); + + /** + * Destructor. + */ + + inline virtual ~CMultiLineTextBox(void) + { + delete m_text; + m_text = (CText *)NULL; + } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CMultiLineTextBox(const CMultiLineTextBox &multiLineTextBox) + : CScrollingPanel(multiLineTextBox) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the text box, relative to its parent. + * @param y The y coordinate of the text box, relative to its parent. + * @param width The width of the textbox. + * @param height The height of the textbox. + * @param text Pointer to a string to display in the textbox. + * @param flags Standard widget flag options. + * @param maxRows The maximum number of rows the textbox can track. Adding + * text beyond this number will cause rows at the start of the text to be + * forgotten; text is essentially stored as a queue, and adding to the back + * of a full queue causes the front items to be popped off. Setting this to + * 0 will make the textbox track only the visible rows. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CMultiLineTextBox(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const CNxString &text, uint32_t flags, + nxgl_coord_t maxRows = 0, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Set the horizontal alignment of text within the textbox. + * + * @param alignment The horizontal position of the text. + */ + + virtual void setTextAlignmentHoriz(TextAlignmentHoriz alignment); + + /** + * Set the vertical alignment of text within the textbox. + * + * @param alignment The vertical position of the text. + */ + + virtual void setTextAlignmentVert(TextAlignmentVert alignment); + + /** + * Returns the number of "pages" that the text spans. A page + * is defined as the amount of text that can be displayed within + * the textbox at one time. + * + * @return The page count. + */ + + virtual const int getPageCount(void) const; + + /** + * Returns the current page. + * + * @return The current page. + * @see getPageCount(). + */ + + virtual const int getCurrentPage(void) const; + + /** + * Returns a pointer to the CText object that contains the + * wrapped text used in the textbox. It is used as the + * pre-processed data source for the textbox, and should + * not be altered. + * + * @return Pointer to the CText object. + */ + + virtual inline const CText *getText(void) const + { + return m_text; + } + + /** + * Set the text displayed in the textbox. + * + * @param text String to display. + */ + + virtual void setText(const CNxString &text); + + /** + * Append new text to the end of the current text + * displayed in the textbox. + * + * @param text String to append. + */ + + virtual void appendText(const CNxString &text); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex Index to remove from. + */ + + virtual void removeText(const unsigned int startIndex); + + /** + * Remove specified number of characters from the string from the + * start index onwards. + * + * @param startIndex Index to remove from. + * @param count Number of characters to remove. + */ + + virtual void removeText(const unsigned int startIndex, const unsigned int count); + + /** + * Set the font used in the textbox. + * + * @param font Pointer to the new font. + */ + + virtual void setFont(CNxFont *font); + + /** + * Get the length of the text string. + * + * @return The length of the text string. + */ + + virtual const int getTextLength(void) const; + + /** + * Sets the cursor display mode. + * + * @param cursorMode Determines cursor display mode + */ + + virtual void showCursor(EShowCursor cursorMode); + + /** + * Shows the cursor in default mode (only when the TextBox has focus). + */ + + virtual inline void showCursor(void) + { + showCursor(SHOW_CURSOR_ONFOCUS); + } + + /** + * Hides the cursor. + */ + + virtual inline void hideCursor(void) + { + showCursor(SHOW_CURSOR_NEVER); + } + + /** + * Enables/disables cursor wrapping + * + * @param wrap True enables cursor wrapping + */ + + virtual inline void wrapCursor(bool wrap) + { + m_wrapCursor = wrap; + } + + /** + * Move the cursor to the text position specified. 0 indicates the start + * of the string. If position is greater than the length of the string, + * the cursor is moved to the end of the string. + * + * @param position The new cursor position. + */ + + virtual void moveCursorToPosition(const int position); + + /** + * Get the cursor position. This is the index within the string that + * the cursor is currently positioned over. + * + * @return position The cursor position. + */ + + virtual inline const int getCursorPosition(void) const + { + return m_cursorPos; + } + + /** + * Insert text at the specified index. + * + * @param text The text to insert. + * @param index Index at which to insert the text. + */ + + virtual void insertText(const CNxString &text, + const unsigned int index); + + /** + * Insert text at the current cursor position. + * + * @param text The text to insert. + */ + + virtual void insertTextAtCursor(const CNxString & ext); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CMULTILINETEXTBOX_HXX diff --git a/NxWidgets/libnxwidgets/include/cnxfont.hxx b/NxWidgets/libnxwidgets/include/cnxfont.hxx new file mode 100644 index 000000000..33e712291 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxfont.hxx @@ -0,0 +1,238 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxfont.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXFONT_HXX +#define __INCLUDE_CNXFONT_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxString; + struct SBitmap; + + /** + * Class defining the properties of one font. + */ + + class CNxFont + { + private: + enum nx_fontid_e m_fontId; /**< The font ID. */ + NXHANDLE m_fontHandle; /**< The font handle */ + FAR const struct nx_font_s *m_pFontSet; /** < The font set metrics */ + nxgl_mxpixel_t m_fontColor; /**< Color to draw the font with when rendering. */ + nxgl_mxpixel_t m_transparentColor; /**< Background color that should not be rendered. */ + + public: + + /** + * CNxFont Constructor. + * + * @param fontid The font ID to use. + * @param fontColor The font color to use. + * @param transparentColor The color in the font bitmap used as the + * background color. + */ + + CNxFont(enum nx_fontid_e fontid, nxgl_mxpixel_t fontColor, + nxgl_mxpixel_t transparentColor); + + /** + * CNxFont Destructor. + */ + + ~CNxFont() { } + + /** + * Checks if supplied character is blank in the current font. + * + * @param letter The character to check. + * @return True if the glyph contains any pixels to be drawn. False if + * the glyph is blank. + */ + + const bool isCharBlank(const nxwidget_char_t letter) const; + + /** + * Gets the color currently being used as the drawing color. + * + * @return The current drawing color. + */ + + inline const nxgl_mxpixel_t getColor() const + { + return m_fontColor; + } + + /** + * Sets the color to use as the drawing color. If set, this overrides + * the colors present in a non-monochrome font. + * @param color The new drawing color. + */ + + inline void setColor(const nxgl_mxpixel_t color) + { + m_fontColor = color; + } + + /** + * Get the color currently being used as the transparent background + * color. + * @return The transparent background color. + */ + + inline const nxgl_mxpixel_t getTransparentColor() const + { + return m_transparentColor; + } + + /** + * Sets the transparent background color to a new value. + * @param color The new background color. + */ + + inline void setTransparentColor(const nxgl_mxpixel_t color) + { + m_transparentColor = color; + } + + /** + * Draw an individual character of the font to the specified bitmap. + * + * @param bitmap The bitmap to draw to. + * @param letter The character to output. + */ + + void drawChar(FAR SBitmap *bitmap, nxwidget_char_t letter); + + /** + * Get the width of a string in pixels when drawn with this font. + * + * @param text The string to check. + * @return The width of the string in pixels. + */ + + nxgl_coord_t getStringWidth(const CNxString &text) const; + + /** + * Get the width of a portion of a string in pixels when drawn with this + * font. + * + * @param text The string to check. + * @param startIndex The start point of the substring within the string. + * @param length The length of the substring in chars. + * @return The width of the substring in pixels. + */ + + nxgl_coord_t getStringWidth(const CNxString& text, + int startIndex, int length) const; + + /** + * Gets font metrics for a particular character + * + * + * @param letter The character to get the width of. + * @param metrics The location to return the font metrics + */ + + void getCharMetrics(nxwidget_char_t letter, + FAR struct nx_fontmetric_s *metrics) const; + + /** + * Get the width of an individual character. + * + * @param letter The character to get the width of. + * @return The width of the character in pixels. + */ + + nxgl_coord_t getCharWidth(nxwidget_char_t letter) const; + + /** + * Get the height of an individual character. + * + * @param letter The letter to get the height of. + * @return The height of the character in pixels. + */ + + inline nxgl_coord_t getCharHeight(nxwidget_char_t letter) const; + + /** + * Gets the maximum width of the font. + * + * @return The height of the font. + */ + + inline const uint8_t getMaxWidth(void) const + { + return m_pFontSet->mxwidth; + } + + /** + * Gets the height of the font. + * + * @return The height of the font. + */ + + inline const uint8_t getHeight(void) const + { + return m_pFontSet->mxheight; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXFONT_HXX diff --git a/NxWidgets/libnxwidgets/include/cnxserver.hxx b/NxWidgets/libnxwidgets/include/cnxserver.hxx new file mode 100644 index 000000000..2c79558a0 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxserver.hxx @@ -0,0 +1,199 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxserver.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXSERVER_HXX +#define __INCLUDE_CNXSERVER_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwindow.hxx" +#include "cbgwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CBgWindow; + + /** + * This class represents the NX server. It includes methods to connect to + * and disconnect form the NX server, methods to manage the background, and + * "factory" methods to create window objects on the NX server. NXWidget + * objects them may be created on the window objects. + */ + + class CNxServer + { + private: +#ifndef CONFIG_NX_MULTIUSER + FAR NX_DRIVERTYPE *m_hDevice; /**< LCD/Framebuffer device handle */ +#endif + NXHANDLE m_hNxServer; /**< NX server handle */ +#ifdef CONFIG_NX_MULTIUSER + voilatile bool m_running; /**< True: The listener thread is running */ + voilatile bool m_connected; /**< True: Connected to the server */ + volatile bool m_stop; /**< True: Waiting for the listener thread to stop */ + sem_t m_connsem; /**< Wait for server connection */ +#endif + static uint8_t m_nServers; /**< The number of NX server instances */ + + /** + * This is the entry point of a thread that listeners for and dispatches + * events from the NX server. + */ + +#ifdef CONFIG_NX_MULTIUSER + static FAR void *listener(FAR void *arg); +#endif + + public: + + /** + * CNXServer constructor. The CNxServer is a normally singleton. However, that + * not enforced: This constructor could run more than one in the situation where + * there are multiple physical displays. However, that configuration has never + * been texted. + */ + + CNxServer(void); + + /** + * CNXServer destructor + */ + + ~CNxServer(void); + + /** + * Connect to the NX Server + */ + + virtual bool connect(void); + + /** + * Disconnect from the NX Server + */ + + virtual void disconnect(void); + + /** + * Get the NX server handle + * + * @return The NX server handler (NULL is not connected) + */ + + inline NXHANDLE getServer(void) + { + return m_hNxServer; + } + + /** + * Test if we are connected to the NX server. + * + * @return True is connected; false is not connected. + */ + + inline bool connected(void) + { +#ifdef CONFIG_NX_MULTIUSER + return m_connected; +#else + return true; +#endif + } + + /** + * Set the background color + */ + + inline bool setBackgroundColor(nxgl_mxpixel_t color) + { + return nx_setbgcolor(m_hNxServer, &color) == OK; + } + + /** + * Get an instance of a raw NX window. + */ + + inline CNxWindow *createRawWindow(CWidgetControl *widgetControl) + { + return new CNxWindow(m_hNxServer, widgetControl); + } + + /** + * Get an instance of the framed NX window. + */ + +#if 0 // Not ready for prime time + inline CFramedWindow *createFramedWindow(CWidgetControl *widgetControl) + { + return new CFramedWindow(m_hNxServer, widgetControl); + } +#endif + + /** + * Get an instance of the background window. + */ + + inline CBgWindow *getBgWindow(CWidgetControl *widgetControl) + { + return new CBgWindow(m_hNxServer, widgetControl); + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXSERVER_HXX diff --git a/NxWidgets/libnxwidgets/include/cnxstring.hxx b/NxWidgets/libnxwidgets/include/cnxstring.hxx new file mode 100644 index 000000000..91bd253c7 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxstring.hxx @@ -0,0 +1,484 @@ +/**************************************************************************** + * include/cnxtring.hxx + * NxWidgets/libnxwidgets/ + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXSTRING_HXX +#define __INCLUDE_CNXSTRING_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "nxconfig.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CStringIterator; + + /** + * Unicode string class. Uses 16-bt wide-character encoding. For optimal + * performance, use the CStringIterator class to iterate over a CNxString + * instance. + * + * Where possible, the string avoids allocating memory each time the + * string grows or shrinks. This means that the string may consume more + * memory than the number of chars would seem to dictate if the object + * previously contained a large string that has subsequently been truncated. + * It also means that increasing the length of such a string is a cheaper + * operation as memory does not need to allocated and copied. + * + * Additionally, the string increases its array size by m_growAmount every + * time it needs to allocate extra memory, potentially reducing the number + * of reallocs needed. + * + * The string is not null-terminated. Instead, it uses a m_stringLength + * member that stores the number of characters in the string. This saves a + * byte and makes calls to getLength() run in O(1) time instead of O(n). + */ + + class CNxString + { + private: + friend class CStringIterator; + + int m_stringLength; /**< Number of characters in the string */ + int m_allocatedSize; /**< Number of bytes allocated for this string */ + int m_growAmount; /**< Number of chars that the string grows by + whenever it needs to get larger */ + + + protected: + FAR nxwidget_char_t *m_text; /**< Raw char array data */ + + /** + * Allocate memory for the string. + * + * @param chars Number of chars to allocate. + * @param preserve If true, the data in the existing memory will be + * preserved if new memory must be allocated + */ + + void allocateMemory(int chars, bool preserve); + + /** + * Check if we've got any string data stored or not. + * + * @return True if the string contains any data; false if no data has + * yet been supplied. + */ + + inline bool hasData(void) const + { + return m_stringLength > 0; + } + + /** + * Get the amount of allocated memory. + * + * @return The number of chars allocated in RAM. + */ + + inline int getAllocatedSize(void) const + { + return m_allocatedSize; + } + + /** + * Returns a pointer to the raw char array data. + * + * @return Pointer to the char array. + */ + + inline FAR const nxwidget_char_t *getCharArray(void) const + { + return m_text; + } + + /** + * Return a pointer to the specified character. + * + * @param index Index of the character to retrieve. + */ + + FAR nxwidget_char_t *getCharPointer(const int index) const; + + public: + + /** + * Constructor to create an empty string object. + */ + + CNxString(); + + /** + * Constructor to create a string from a C character array. + * + * @param text Pointer to a char array to use as the basis of the + * string. + */ + + CNxString(FAR const char *text); + + /** + * Constructor to create a string from a single character. + * + * @param letter Single character to use as the basis of the string. + */ + + CNxString(const nxwidget_char_t letter); + + /** + * Copy constructor. + * @param string CNxString object to create a copy of. + */ + + CNxString(const CNxString &string); + + /** + * Destructor. + */ + + inline ~CNxString() + { + delete[] m_text; + m_text = (FAR nxwidget_char_t *)NULL; + }; + + /** + * Creates and returns a new CStringIterator object that will iterate + * over this string. The object must be manually deleted once it is + * no longer needed. + * + * @return A new CStringIterator object. + */ + + CStringIterator *newStringIterator(void) const; + + /** + * Copy the internal array to the supplied buffer. The buffer must be + * large enough to contain the full text in the string. The + * getByteCount() method can be used to obtain the length of the string. + * Unlike the CNxString class, the char array is null-terminated. + * The buffer must be (getByteCount() + 1) bytes long, in order to + * accommodate the terminator. + * + * @param buffer Buffer to copy the internal char array to. + */ + + void copyToCharArray(FAR nxwidget_char_t *buffer) const; + + /** + * Set the text in the string. + * + * @param text CNxString containing the new data for this string. + */ + + void setText(const CNxString &text); + + /** + * Set the text in the string. + * + * @param text Char array to use as the new data for this string. + */ + + void setText(FAR const char *text); + + /** + * Set the nxwidget_char_t text in the string. + * + * @param text Char array to use as the new data for this string. + */ + + void setText(FAR const nxwidget_char_t *text, int nchars); + + /** + * Set the 8-bit C-string text in the string. + * + * @param text Character to to use as the new data for this string. + */ + + void setText(const nxwidget_char_t text); + + /** + * Append text to the end of the string. + * + * @param text String to append. + */ + + void append(const CNxString &text); + + /** + * Insert text at the specified character index. + * + * @param text The text to insert. + * @param index The index at which to insert the text. + */ + + void insert(const CNxString &text, const int index); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex Index to remove from. + */ + + void remove(const int startIndex); + + /** + * Remove specified number of characters from the string from the + * start index onwards. + * + * @param startIndex Index to remove from. + * @param count Number of characters to remove. + */ + + void remove(const int startIndex, const int count); + + /** + * Get the of number of letters (ie. the length) of the string. + * + * @return The length of the string. + */ + + inline const int getLength(void) const + { + return m_stringLength; + }; + + /** + * Get the character at the specified index. This function is useful + * for finding the occasional character at an index, but for iterating + * over strings it is exceptionally slow. The newStringIterator() + * method should be used to retrieve an iterator object that can iterate + * over the string efficiently. + * + * @param index The index of the character to retrieve. + * @return The character at the specified index. + */ + + const nxwidget_char_t getCharAt(int index) const; + + /** + * Returns the first index of the specified letter within the string. + * Will return -1 if the letter is not found. + * + * @param letter Letter to find. + * @return The index of the letter. + */ + + const int indexOf(nxwidget_char_t letter) const; + + /** + * Returns the first index of the specified letter within the string. + * Will return -1 if the letter is not found. Scans through the string + * from "startIndex" until it has examined all subsequent letters. + * @param letter Letter to find. + * + * @param startIndex The index to start searching from. + * @return The index of the letter. + */ + + const int indexOf(nxwidget_char_t letter, int startIndex) const; + + /** + * Returns the first index of the specified letter within the string. + * Will return -1 if the letter is not found. Scans through the string + * from "startIndex" until it has examined all letters within the + * range "count". + * + * @param letter Letter to find. + * @param startIndex The index to start searching from. + * @param count The number of characters to examine. + * @return The index of the letter. + */ + + const int indexOf(nxwidget_char_t letter, int startIndex, int count) const; + + /** + * Returns the last index of the specified letter within the string. + * Will return -1 if the letter is not found. + * + * @param letter Letter to find. + * @return The index of the letter. + */ + + const int lastIndexOf(nxwidget_char_t letter) const; + + /** + * Returns the last index of the specified letter within the string. + * Will return -1 if the letter is not found. Scans through the string + * backwards from "startIndex" until it has examined all preceding + * letters within the string. + * + * @param letter Letter to find. + * @param startIndex The index to start searching from. + * @return The index of the letter. + */ + + const int lastIndexOf(nxwidget_char_t letter, int startIndex) const; + + /** + * Returns the last index of the specified letter within the string. + * Will return -1 if the letter is not found. Scans through the string + * backwards from "startIndex" until it has examined all letters within + * the range "count". + * @param letter Letter to find. + * @param startIndex The index to start searching from. + * @param count The number of characters to examine. + * @return The index of the letter. + */ + + const int lastIndexOf(nxwidget_char_t letter, int startIndex, int count) const; + + /** + * Get a substring from this string. It is the responsibility of the + * caller to delete the substring when it is no longer required. + * + * @param startIndex The starting point of the substring. + * @return A pointer to a new CNxString object containing the + * substring. + */ + + CNxString *subString(int startIndex) const; + + /** + * Get a substring from this string. It is the responsibility of the + * caller to delete the substring when it is no longer required. + * + * @param startIndex The starting point of the substring. + * @param length The length of the substring. + * @return A pointer to a new CNxString object containing the + * substring. + */ + + CNxString *subString(int startIndex, int length) const; + + /** + * Overloaded assignment operator. Copies the data within the argument + * string to this string. + * + * @param string The string to copy. + * @return This string. + */ + + CNxString &operator=(const CNxString &string); + + /** + * Overloaded assignment operator. Copies the data within the argument + * char array to this string. + * + * @param string The string to copy. + * @return This string. + */ + + CNxString &operator=(const char *string); + + /** + * Overloaded assignment operator. Copies the data from the argument + * char to this string. + * + * @param letter The char to copy. + * @return This string. + */ + + CNxString& operator=(nxwidget_char_t letter); + + /** + * Compares this string to the argument. + * + * @param string String to compare to. + * @return Zero if both strings are equal. A value greater than zero + * indicates that this string is greater than the argument string. A + * value less than zero indicates the opposite. Note that the return + * value indicates the *byte* that does not match, not the *character*. + */ + + int compareTo(const CNxString &string) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXSTRING_HXX diff --git a/NxWidgets/libnxwidgets/include/cnxtimer.hxx b/NxWidgets/libnxwidgets/include/cnxtimer.hxx new file mode 100644 index 000000000..be6038dac --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxtimer.hxx @@ -0,0 +1,220 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxtimer.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXTIMER_HXX +#define __INCLUDE_CNXTIMER_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "cnxwidget.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetcontrol; + + /** + * Timer widget. It can drive time-based events, animations, etc. + * + * Using the timer is simple: + * - Create an instance of the CNxTimer and add it as a child to a widget. + * - Call the instance's "start()" method. + * - Catch the timer's action event and call any code that should run. + */ + + class CNxTimer : public CNxWidget + { + protected: + FAR timer_t m_timerid; /**< POSIX timer */ + uint32_t m_timeout; /**< The timeout value in milliseconds */ + bool m_isRunning; /**< Indicates whether or not the timer is running */ + bool m_isRepeater; /**< Indicates whether or not the timer repeats */ + + /** + * The SIGALM signal handler that will be called when the timer goes off + * + * @param signo The signal number call caused the handler to run (SIGALM) + */ + + static void signalHandler(int signo); + + /** + * Handle an expired timer + */ + + void handleTimerExpiration(void); + + /** + * Convert a timespec to milliseconds + * + * @param tp The pointer to the timespec to convert + * @return The corresponding time in milliseconds + */ + + uint32_t timespecToMilliseconds(FAR const struct timespec *tp); + + /** + * Convert milliseconds to a timespec + * + * @param milliseconds The milliseconds to be converted + * @param tp The pointer to the location to store the converted timespec + */ + + void millisecondsToTimespec(uint32_t milliseconds, FAR struct timespec *tp); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CNxTimer(const CNxTimer &timer) : CNxWidget(timer) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display. + * @param timeout Time, in milliseconds, before the timer fires an + * EVENT_ACTION event. + * @param repeat If true, the timer will fire multiple events. If false, + * the timer will fire just once and stop. + */ + + CNxTimer(CWidgetControl *pWidgetControl, uint32_t timeout, bool repeat); + + /** + * Destructor. + */ + + ~CNxTimer(void); + + /** + * Return the time remaining on this timer. + * + * @return The number of milliseconds that this timer runs before + * firing an event. Zero is returned if the timer is not running. + */ + + const uint32_t getTimeout(void); + + /** + * Resets the (running) timer to its initial timeout value. This + * call does nothing if the timer is not running. + */ + + void reset(void); + + /** + * Starts the timer. This call does nothing if the timer is already + * running. + */ + + void start(void); + + /** + * Stops the timer. Does nothing if the timer is not running. + */ + + void stop(void); + + /** + * Set the timeout of this timer. This timeout value will not + * take effect until start() or reset() is called. + * + * @param timeout The number of milliseconds that this timer will run + * before firing an event. + */ + + inline void setTimeout(uint32_t timeout) + { + m_timeout = timeout; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXTIMER_HXX diff --git a/NxWidgets/libnxwidgets/include/cnxtkwindow.hxx b/NxWidgets/libnxwidgets/include/cnxtkwindow.hxx new file mode 100644 index 000000000..ed2ecdbd2 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxtkwindow.hxx @@ -0,0 +1,327 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxtkwindow.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXTKWINDOW_HXX +#define __INCLUDE_CNXTKWINDOW_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#include "ccallback.hxx" +#include "inxwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxToolbar; + struct SBitmap; + + /** + * This class defines operations on a framed NX window. + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class CNxTkWindow : protected CCallback, public INxWindow + { + protected: + NXHANDLE m_hNxServer; /**< Handle to the NX server. */ + NXTKWINDOW m_hNxTkWindow; /**< Handle to the NX raw window */ + CWidgetControl *m_widgetControl; /**< Controlling widget for the window */ + CNxToolbar *m_toolbar; /**< Child toolbar */ + + public: + + /** + * Constructor. Creates an uninitialized instance of the CNxTkWindow + * object. The open() method must be called to initialize the instance. + * + * The general steps to create any window include: + * 1) Create a dumb CWigetControl instance + * 2) Pass the dumb CWidgetControl instance to the window constructor + * that inherits from INxWindow. + * 3) The window constructor call CWidgetControl methods to "smarten" + * the CWidgetControl instance with window-specific knowledge. + * 4) Call the open() method on the window to display the window. + * 5) After that, the fully smartend CWidgetControl instance can + * be used to generate additional widgets. + * 6) After that, the fully smartened CWidgetControl instance can + * be used to generate additional widgets by passing it to the + * widget constructor + * + * @param hNxServer Handle to the NX server. + * @param widgetControl Controlling widget for this window. + */ + + CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl); + + /** + * Destructor. + */ + + ~CNxTkWindow(void); + + /** + * Creates a new window. Window creation is separate from + * object instantiation so that failures can be reported. + * + * @return True if the window was successfully opened. + */ + + bool open(void); + + /** + * Open a toolbar on the framed window. Toolbar creation is separate + * from object instantion so that errors can be reported + * + * @return True if the toolbar was successfully created. + */ + + CNxToolbar *openToolbar(nxgl_coord_t height); + + /** + * Detach the toolbar. This should *ONLY* be called by the toolbar + * instance itself. If this is called by end-user logic, it will + * screw things up miserably. + */ + + inline void detachToolbar(void) + { + m_toolbar = (CNxToolbar *)NULL; + } + + /** + * Request the position and size information of the window. The values + * will be returned asynchronously through the client callback method. + * The GetPosition() method may than be called to obtain the positional + * data as provided by the callback. + * + * @return True on success, false on any failure. + */ + + bool requestPosition(void); + + /** + * Get the position of the window (as reported by the NX callback). + * + * @return True on success, false on any failure. + */ + + bool getPosition(FAR struct nxgl_point_s *pPos); + + /** + * Get the size of the window (as reported by the NX callback). + * + * @return The size. + */ + + bool getSize(FAR struct nxgl_size_s *pSize); + + /** + * Set the position and size of the window. + * + * @param pPos The new position of the window. + * @return True on success, false on any failure. + */ + + bool setPosition(FAR const struct nxgl_point_s *pPos); + + /** + * Set the size of the selected window. + * + * @param pSize The new size of the window. + * @return True on success, false on any failure. + */ + + bool setSize(FAR const struct nxgl_size_s *pSize); + + /** + * Bring the window to the top of the display. + * + * @return True on success, false on any failure. + */ + + bool raise(void); + + /** + * Lower the window to the bottom of the display. + * + * @return True on success, false on any failure. + */ + + bool lower(void); + + /** + * Set an individual pixel in the window with the specified color. + * + * @param pPos The location of the pixel to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool setPixel(FAR const struct nxgl_point_s *pPos, + nxgl_mxpixel_t color); + + /** + * Fill the specified rectangle in the window with the specified color. + * + * @param pRect The location to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fill(FAR const struct nxgl_rect_s *pRect, + nxgl_mxpixel_t color); + + /** + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * @param rect The location to be copied + * @param dest - The describes the destination bitmap to receive the + * graphics data. + */ + + void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest); + + /** + * Fill the specified trapezoidal region in the window with the specified + * color. + * + * @param pClip Clipping rectangle relative to window (may be null). + * @param pTrap The trapezoidal region to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, + FAR const struct nxgl_trapezoid_s *pTrap, + nxgl_mxpixel_t color); + + /** + * Fill the specified line in the window with the specified color. + * + * @param vector - Describes the line to be drawn + * @param width - The width of the line + * @param color - The color to use to fill the line + * + * @return True on success; false on failure. + */ + + bool drawLine(FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color); + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color); + + /** + * Move a rectangular region within the window. + * + * @param pRect Describes the rectangular region to move. + * @param pOffset The offset to move the region. + * + * @return True on success; false on failure. + */ + + bool move(FAR const struct nxgl_rect_s *pRect, + FAR const struct nxgl_point_s *pOffset); + + /** + * Copy a rectangular region of a larger image into the rectangle in the + * specified window. + * + * @param pDest Describes the rectangular on the display that will receive + * the bitmap. + * @param pSrc The start of the source image. + * @param pOrigin the pOrigin of the upper, left-most corner of the full + * bitmap. Both pDest and pOrigin are in window coordinates, however, + * pOrigin may lie outside of the display. + * @param stride The width of the full source image in bytes. + * + * @return True on success; false on failure. + */ + + bool bitmap(FAR const struct nxgl_rect_s *pDest, + FAR const void *pSrc, + FAR const struct nxgl_point_s *pOrigin, + unsigned int stride); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXTKWINDOW_HXX + diff --git a/NxWidgets/libnxwidgets/include/cnxtoolbar.hxx b/NxWidgets/libnxwidgets/include/cnxtoolbar.hxx new file mode 100644 index 000000000..ff65cf1a9 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxtoolbar.hxx @@ -0,0 +1,304 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxtoolbar.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXTOOLBAR_HXX +#define __INCLUDE_CNXTOOLBAR_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#include "ccallback.hxx" +#include "inxwindow.hxx" +#include "cnxtkwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + struct SBitmap; + + /** + * This class defines operations on a the toolbar in a framed NX window. + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class CNxToolbar : protected CCallback, public INxWindow + { + private: + CNxTkWindow *m_nxTkWindow; /**< Parent framed window instance. */ + NXTKWINDOW m_hNxTkWindow; /**< Parent framed window handle. */ + CWidgetControl *m_widgetControl; /**< Controlling widget for the toolbar */ + nxgl_coord_t m_height; /**< The toolbar height */ + + public: + + /** + * Constructor. Creates an uninitialized instance of the CNxToolbar + * object. The open() method must be called to initialize the instance. + * + * @param pNxTkWindow Parent framed window instance + * @param hNxTkWindow Parent framed window NX handler + * @param widgetControl Controlling widget for this toolbar. + * @param height The height of the toolbar. + */ + + CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow, + CWidgetControl *pWidgetControl, nxgl_coord_t height); + + /** + * Destructor. + */ + + ~CNxToolbar(void); + + /** + * Creates a new toolbar. Toolbar creation is separate from + * object instantiation so that failures can be reported. + * + * @return True if the toolbar was successfully created. + */ + + bool open(void); + + /** + * Request the position and size information of the toolbar. The values + * will be returned asynchronously through the client callback method. + * The GetPosition() method may than be called to obtain the positional + * data as provided by the callback. + * + * @return True on success, false on any failure. + */ + + bool requestPosition(void); + + /** + * Get the position of the toolbar (as reported by the NX callback). + * + * @return The position. + */ + + bool getPosition(FAR struct nxgl_point_s *pPos); + + /** + * Get the size of the toolbar (as reported by the NX callback). + * + * @return The size. + */ + + bool getSize(FAR struct nxgl_size_s *pSize); + + /** + * Set the position and size of the toolbar. The position of + * the toolbar is fixed at the top of the parent framed window. + * + * @param pPos The new position of the toolbar. + * @return Always returns false. + */ + + bool setPosition(FAR const struct nxgl_point_s *pPos); + + /** + * Set the position and size of the toolbar. The position of + * the toolbar is fixed at the top of the parent framed window. + * + * @param pPos The new position of the toolbar. + * @return Always returns false. + */ + + bool setSize(FAR const struct nxgl_size_s *pSize); + + /** + * Bring the toolbar to the top of the display. The toolbar is + * a component of the containing, parent, framed window. It + * cannot be raised separately. + * + * @return Always returns false. + */ + + bool raise(void); + + /** + * Lower the toolbar to the bottom of the display. The toolbar is + * a component of the containing, parent, framed window. It + * cannot be lowered separately. + * + * @return Always returns false. + */ + + bool lower(void); + + /** + * Set an individual pixel in the toolbar with the specified color. + * + * @param pPos The location of the pixel to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool setPixel(FAR const struct nxgl_point_s *pPos, + nxgl_mxpixel_t color); + + /** + * Fill the specified rectangle in the toolbar with the specified color. + * + * @param pRect The location to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fill(FAR const struct nxgl_rect_s *pRect, + nxgl_mxpixel_t color); + + /** + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * @param rect The location to be copied + * @param dest - The describes the destination bitmap to receive the + * graphics data. + */ + + void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest); + + /** + * Fill the specified trapezoidal region in the toolbar with the specified + * color. + * + * @param pClip Clipping rectangle relative to toolbar (may be null). + * @param pTrap The trapezoidal region to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, + FAR const struct nxgl_trapezoid_s *pTrap, + nxgl_mxpixel_t color); + + /** + * Fill the specified line in the toolbar with the specified color. + * + * @param vector - Describes the line to be drawn + * @param width - The width of the line + * @param color - The color to use to fill the line + * + * @return True on success; false on failure. + */ + + bool drawLine(FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color); + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color); + + /** + * Move a rectangular region within the toolbar. + * + * @param pRect Describes the rectangular region to move. + * @param pOffset The offset to move the region. + * + * @return True on success; false on failure. + */ + + bool move(FAR const struct nxgl_rect_s *pRect, + FAR const struct nxgl_point_s *pOffset); + + /** + * Copy a rectangular region of a larger image into the rectangle in the + * specified toolbar. + * + * @param pDest Describes the rectangular on the display that will receive + * the bitmap. + * @param pSrc The start of the source image. + * @param pOrigin the pOrigin of the upper, left-most corner of the full + * bitmap. Both pDest and pOrigin are in toolbar coordinates, however, + * pOrigin may lie outside of the display. + * @param stride The width of the full source image in bytes. + * + * @return True on success; false on failure. + */ + + bool bitmap(FAR const struct nxgl_rect_s *pDest, + FAR const void *pSrc, + FAR const struct nxgl_point_s *pOrigin, + unsigned int stride); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXTOOLBAR_HXX + diff --git a/NxWidgets/libnxwidgets/include/cnxwidget.hxx b/NxWidgets/libnxwidgets/include/cnxwidget.hxx new file mode 100644 index 000000000..eb1b18710 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxwidget.hxx @@ -0,0 +1,1627 @@ +/**************************************************************************** + * include/cnxwidget.hxx + * NxWidgets/libnxwidgets/ + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXWIDGET_HXX +#define __INCLUDE_CNXWIDGET_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "cnxstring.hxx" +#include "cnxfont.hxx" +#include "crect.hxx" +#include "cwidgetstyle.hxx" +#include "cwidgeteventargs.hxx" +#include "cwidgeteventhandler.hxx" +#include "cwidgeteventhandlerlist.hxx" +#include "tnxarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CGraphicsPort; + class CNxFont; + class CRectCache; + class CWidgetEventHandlerList; + + /** + * Class providing all the basic functionality of a NxWidget. All other + * widgets must must inherit from this class. + */ + + class CNxWidget + { + public: + + /** + * Enum describing the way other widgets should behave when they try to + * close this widget. + */ + + enum CloseType + { + CLOSE_TYPE_CLOSE = 0, /**< Widgets should call the close() method */ + CLOSE_TYPE_HIDE = 1, /**< Widgets should call the hide() method */ + CLOSE_TYPE_SHELVE = 2 /**< Widgets should call the shelve() method */ + }; + + /** + * Enum listing flags that can be set in the constructor's "flags" parameter. + */ + + enum WidgetFlagType + { + WIDGET_BORDERLESS = 0x0001, /**< Widget has no border */ + WIDGET_DRAGGABLE = 0x0002, /**< Widget can be dragged by the user */ + WIDGET_PERMEABLE = 0x0004, /**< Widget's children can exceed this widget's edges */ + WIDGET_DOUBLE_CLICKABLE = 0x0008, /**< Widget can be double-clicked */ + WIDGET_NO_RAISE_EVENTS = 0x0010, /**< Widget does not raise events */ + }; + + /** + * Struct describing some basic properties of a widget. + */ + + typedef struct + { + uint8_t clicked : 1; /**< True if the widget is currently clicked. */ + uint8_t hasFocus : 1; /**< True if the widget has focus. */ + uint8_t dragging : 1; /**< True if the widget is being dragged. */ + uint8_t deleted : 1; /**< True if the widget has been deleted. */ + uint8_t shelved : 1; /**< True if the widget has been shelved. */ + uint8_t borderless : 1; /**< True if the widget is borderless. */ + uint8_t draggable : 1; /**< True if the widget can be dragged. */ + uint8_t drawingEnabled : 1; /**< True if the widget can be drawn. */ + uint8_t enabled : 1; /**< True if the widget is enabled. */ + uint8_t permeable : 1; /**< True if the widget's children can exceed its dimensions. */ + uint8_t erased : 1; /**< True if the widget is currently erased from the frame buffer. */ + uint8_t visibleRegionCacheInvalid : 1; /**< True if the region cache is invalid. */ + uint8_t hidden : 1; /**< True if the widget is hidden. */ + uint8_t doubleClickable : 1; /**< True if the widget can be double-clicked. */ + uint8_t modal : 1; /**< True if the widget is modal. */ + } Flags; + + /** + * Struct describing the size of all four borders of a widget. + */ + + typedef struct + { + uint8_t top; /**< Height of the top border. */ + uint8_t right; /**< Width of the right border. */ + uint8_t bottom; /**< Height of the bottom border. */ + uint8_t left; /**< Width of the left border. */ + } WidgetBorderSize; + + protected: + CWidgetControl *m_widgetControl; /**< The controlling widget for the display */ + CRect m_rect; /**< Rectange bounding the widget. */ + uint32_t m_refcon; /**< Identifying number of the widget. */ + + // Dragging variables + + nxgl_coord_t m_grabPointX; /**< Physical space x coordinate where dragging began. */ + nxgl_coord_t m_grabPointY; /**< Physical space y coordinate where dragging began. */ + nxgl_coord_t m_newX; /**< Physical x coordinate where widget is being dragged to. */ + nxgl_coord_t m_newY; /**< Physical y coordinate where widget is being dragged to. */ + + // Style + + CWidgetStyle m_style; /**< All style information used by a widget. */ + + // Status + + Flags m_flags; /**< Flags struct. */ + + // Event handling + + CWidgetEventHandlerList *m_widgetEventHandlers; /**< List of event handlers. */ + + // Double-clicking + + struct timespec m_lastClickTime; /**< System timer when last clicked. */ + nxgl_coord_t m_lastClickX; /**< X coordinate of last click. */ + nxgl_coord_t m_lastClickY; /**< Y coordinate of last click. */ + int m_doubleClickBounds; /**< Area in which a click is assumed to be a double-click. */ + + // Hierarchy control + + CNxWidget *m_parent; /**< Pointer to the widget's parent. */ + CNxWidget *m_focusedChild; /**< Pointer to the child widget that has focus. */ + TNxArray m_children; /**< List of child widgets. */ + TNxArray m_shelvedWidgets; /**< List of shelved child widgets. */ + + // Visible regions + + CRectCache *m_rectCache; /**< List of the widget's visible regions. */ + CloseType m_closeType; /**< Type of close method that should be called for the widget. */ + WidgetBorderSize m_borderSize; /**< Size of the widget borders. */ + + /** + * Use the provided widget style + */ + + void useWidgetStyle(const CWidgetStyle *style); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw(). + */ + + virtual inline void drawContents(CGraphicsPort* port) { } + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw(). + */ + + virtual void drawBorder(CGraphicsPort* port) { } + + /** + * Checks if the supplied coordinates collide with a portion of this widget + * that is not obscured by its siblings, but that may be obscured by + * its children. + * + * @param x X coordinate of the click. + * @param y Y coordinate of the click. + * @return True if a collision occurred; false if not. + */ + + bool checkCollisionWithForegroundRects(nxgl_coord_t x, nxgl_coord_t y) const; + + /** + * Draw all visible regions of this widget's children. + */ + + void drawChildren(void); + + /** + * Erase and remove the supplied child widget from this widget and + * send it to the deletion queue. + * + * @param widget The widget to close. + * @see close(). + */ + + void closeChild(CNxWidget *widget); + + /** + * Erase the supplied child widget and move it out of the main child + * list into the shelved list. The widget remains in memory and can + * be restored by calling "unshelve()" on the widget. + * + * @param widget The widget to hide. + */ + + void shelveChild(CNxWidget *widget); + + /** + * Redraws all regions of child widgets that fall within the invalidRects + * regions. + * + * @param invalidRects List of invalid regions that need to be redrawn. + * @param sender Pointer to the widget that initiated the redraw. + */ + + void redrawDirtyChildren(TNxArray* invalidRects, CNxWidget *sender); + + /** + * Get the index of the next visible widget higher up the z-order. + * + * @param startIndex The starting index. + * @return The index of the next highest visible widget. + */ + + const int getHigherVisibleWidget(const int startIndex) const; + + /** + * Get the index of the next visible widget lower down the z-order. + * + * @param startIndex The starting index. + * @return The index of the next lowest visible widget. + */ + + const int getLowerVisibleWidget(const int startIndex) const; + + /** + * Notify this widget that it is being dragged, and set its drag point. + * + * @param x The x coordinate of the drag position relative to this widget. + * @param y The y coordinate of the drag position relative to this widget. + */ + + void startDragging(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Notify this widget that it is no longer being dragged. + */ + + void stopDragging(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CNxWidget(const CNxWidget &widget) { } + + /** + * Called when the widget is clicked. Override this when creating new + * widgets if the widget should exhibit additional behaviour when it is + * clicked. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual inline void onClick(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Called when the widget is double-clicked. Override this when + * creating new widgets if the widget should exhibit additional + * behaviour when it is double-clicked. To change the conditions that + * apply in detecting a double-click, override the isDoubleClicked() + * method. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual inline void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Called when the widget is released. Override this when + * creating new widgets if the widget should exhibit additional + * behaviour when it is released. + * + * @param x The x coordinate of the mouse when released. + * @param y The y coordinate of the mouse when released. + */ + + virtual inline void onRelease(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Called when the widget is released outside of its boundaries. + * Override this when creating new widgets if the widget should exhibit + * additional behaviour when it is released outside of its boundaries. + * + * @param x The x coordinate of the mouse when released. + * @param y The y coordinate of the mouse when released. + */ + + virtual inline void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Called when the widget is dragged. Override this when creating new + * widgets if the widget should exhibit additional behaviour when it is + * dragged. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + * @param vX X distance dragged. + * @param vY Y distance dragged. + */ + + virtual inline void onDrag(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY) { } + + /** + * Called when the widget starts being dragged. Override this when + * creating new widgets if the widget should exhibit additional + * behaviour when dragging starts. + */ + + virtual inline void onDragStart(void) { } + + /** + * Called when the widget stops being dragged. Override this when + * creating new widgets if the widget should exhibit additional + * behaviour when dragging stops. + */ + + virtual inline void onDragStop(void) { } + + /** + * Called when the widget gains focus. Override this when creating new + * widgets if the widget should exhibit additional behaviour when + * gaining focus. + */ + + virtual inline void onFocus(void) { } + + /** + * Called when the widget loses focus. Override this when creating new + * widgets if the widget should exhibit additional behaviour when + * losing focus. + */ + + virtual inline void onBlur(void) { } + + /** + * Called when the widget is enabled. Override this when creating new + * widgets if the widget should exhibit additional behaviour when + * enabled. + */ + + virtual inline void onEnable(void) { } + + /** + * Called when the widget is disabled. Override this when creating new + * widgets if the widget should exhibit additional behaviour when + * disabled. + */ + + virtual inline void onDisable(void) { } + + /** + * Called when the widget is resized. Override this when creating new + * widgets if the widget should exhibit additional behaviour when + * resized. + * + * @param width The new width. + * @param height The new height. + */ + + virtual inline void onResize(nxgl_coord_t width, nxgl_coord_t height) { } + + public: + + /** + * CNxWidget constructor. + * + * @param pWidgetControl The controllwing widget for the display + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + * @param flags Bitmask specifying some set-up values for the widget. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + * @see WidgetFlagType. + */ + + CNxWidget(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + uint32_t flags, + FAR const CWidgetStyle *style = (FAR const CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual ~CNxWidget(void); + + /** + * Get the x coordinate of the widget in "Widget space". + * + * @return Widget space x coordinate. + */ + + const nxgl_coord_t getX(void) const; + + /** + * Get the y coordinate of the widget in "Widget space". + * + * @return Widget space y coordinate. + */ + + const nxgl_coord_t getY(void) const; + + /** + * Get the x coordinate of the widget relative to its parent. + * + * @return Parent-space x coordinate. + */ + + const nxgl_coord_t getRelativeX(void) const; + + /** + * Get the y coordinate of the widget relative to its parent. + * + * @return Parent-space y coordinate. + */ + + const nxgl_coord_t getRelativeY(void) const; + + /** + * Get the reference constant for this widget. + * @return The reference constant. + */ + + inline const uint32_t getRefcon(void) const + { + return m_refcon; + } + + /** + * Get the type of close routine that should be called by other widgets + * interacting with this widget. + * + * @return The close type of this widget. + */ + + inline const CloseType getCloseType(void) + { + return m_closeType; + } + + /** + * Is the widget active? + * A value of true indicates that this widget has focus or is an ancestor + * of the widget with focus. + * + * @return True if active. + */ + + inline const bool hasFocus(void) const + { + return m_flags.hasFocus; + } + + /** + * Has the widget been marked for deletion? This function recurses up the widget + * hierarchy and only returns true if all of the widgets in the ancestor + * chain are not deleted. + * + * Widgets marked for deletion are automatically deleted and should not be + * interacted with. + * + * @return True if marked for deletion. + */ + + const bool isDeleted(void) const; + + /** + * Is the widget allowed to draw? This function recurses up the widget + * hierarchy and only returns true if all of the widgets in the ancestor + * chain are visible. + * + * @return True if drawing is enabled. + */ + + const bool isDrawingEnabled(void) const; + + /** + * Is the widget hidden? This function recurses up the widget + * hierarchy and returns true if any of the widgets in the ancestor + * chain are hidden. + * + * @return True if hidden. + */ + + const bool isHidden(void) const; + + /** + * Is the widget enabled? This function recurses up the widget + * hierarchy and only returns true if all of the widgets in the ancestor + * chain are enabled. + * + * @return True if enabled. + */ + + const bool isEnabled(void) const; + + /** + * Are the widget's edges permeable or solid? + * Permeable widgets do not enforce their dimensions on the + * coordinates and dimensions of child widgets. + * + * @return True if permeable. + */ + + inline const bool isPermeable(void) const + { + return m_flags.permeable; + } + + /** + * IS the widget double-clickable? + * @return True if the widget watches for double-clicks. + */ + + inline const bool isDoubleClickable(void) const + { + return m_flags.doubleClickable; + } + + /** + * Does the widget have a border? + * + * @return True if the widget does not have a border. + */ + + inline const bool isBorderless(void) const + { + return m_flags.borderless; + } + + /** + * Is the widget clicked? + * + * @return True if the widget is currently clicked. + */ + + inline const bool isClicked(void) const + { + return m_flags.clicked; + } + + /** + * Is the widget being dragged? + * + * @return True if the widget is currently being dragged. + */ + + inline const bool isBeingDragged(void) const + { + return m_flags.dragging; + } + + /** + * Is the widget shelved? + * + * @return True if the widget is shelved. + */ + + inline const bool isShelved(void) const + { + return m_flags.shelved; + } + + /** + * Is the widget modal? Only true if the Widget singleton is also modal. + * + * @return True if the widget is modal. + */ + + const bool isModal(void) const; + + /** + * Get the width of the widget. + * + * @return The widget width. + */ + + inline nxgl_coord_t getWidth(void) const + { + return m_rect.getWidth(); + } + + /** + * Get the height of the widget. + * + * @return The widget height. + */ + + inline nxgl_coord_t getHeight(void) const + { + return m_rect.getHeight(); + } + + /** + * Get the dimensions of the border + * + */ + + inline void getBorderSize(WidgetBorderSize &borderSize) + { + borderSize.top = m_borderSize.top; + borderSize.left = m_borderSize.left; + borderSize.bottom = m_borderSize.bottom; + borderSize.right = m_borderSize.right; + } + + /** + * Get a pointer to this widget's parent. + * + * @return This widget's parent. + */ + + inline CNxWidget *getParent(void) const + { + return m_parent; + } + + /** + * Get a pointer to this widget's focused child. + * + * @return This widget's focused child. + */ + + inline CNxWidget *getFocusedWidget(void) + { + return m_focusedChild; + } + + /** + * Check if this widget raises events or not. + * + * @return True if events are enabled. + */ + + inline const bool raisesEvents(void) const + { + return m_widgetEventHandlers->isEnabled(); + } + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the widget's + * parent. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + + /** + * Insert the properties of the space within this widget that is + * available for children into the rect passed in as a parameter. + * All coordinates are relative to this widget. + * + * @param rect Reference to a rect to populate with data. + */ + + void getClientRect(CRect &rect) const; + + /** + * Insert the properties of the space within this widget that is + * available for children into the rect passed in as a parameter. + * Identical to getClientRect() except that all coordinates are + * absolute positions within the window. + * + * @param rect Reference to a rect to populate with data. + */ + + void getRect(CRect &rect) const; + + /** + * Clips the supplied rect to the boundaries defined by this widget and + * this widget's parents. + * + * @param rect Reference to a rect to populate with data. + */ + + void getRectClippedToHierarchy(CRect &rect) const; + + /** + * Gets a pointer to the vector of all of the visible regions of this widget, + * including any covered by children. + * + * @return A pointer to a vector of all visible regions. + */ + + TNxArray *getForegroundRegions(void); + + /** + * Gets a pointer to the widget's font. + * + * @return A pointer to the widget's font. + */ + + inline CNxFont *getFont(void) const + { + return m_style.font; + } + + /** + * Gets the color used for the normal background fill. + * + * @return Background fill color. + */ + + inline const nxgl_mxpixel_t getBackgroundColor(void) const + { + return m_style.colors.background; + } + + /** + * Gets the color used for the background fill when the widget is selected. + * + * @return Dark color. + */ + + inline const nxgl_mxpixel_t getSelectedBackgroundColor(void) const + { + return m_style.colors.selectedBackground; + } + + /** + * Gets the color used as the light edge in bevelled boxes. + * + * @return Shine color. + */ + + inline const nxgl_mxpixel_t getShineEdgeColor(void) const + { + return m_style.colors.shineEdge; + } + + /** + * Gets the color used as the dark edge in bevelled boxes. + * + * @return Shadow color. + */ + + inline const nxgl_mxpixel_t getShadowEdgeColor(void) const + { + return m_style.colors.shadowEdge; + } + + /** + * Gets the color used as the fill in focused window borders. + * + * @return Highlight color. + */ + + inline const nxgl_mxpixel_t getHighlightColor(void) const + { + return m_style.colors.highlight; + } + + /** + * Gets the color used for text in a disabled widget. + * + * @return Disabled text color. + */ + + inline const nxgl_mxpixel_t getDisabledTextColor(void) const + { + return m_style.colors.disabledText; + } + + /** + * Gets the color used for text in a enabled widget. + * + * @return Enabled text color. + */ + + inline const nxgl_mxpixel_t getEnabledTextColor(void) const + { + return m_style.colors.enabledText; + } + + /** + * Gets the color used for text in a clicked widget. + * + * @return Selected text color. + */ + + inline const nxgl_mxpixel_t getSelectedTextColor(void) const + { + return m_style.colors.selectedText; + } + + /** + * Sets this widget's reference constant. This should be unique, + * at least amongst this widget's siblings. + * + * @param refcon The reference constant. + */ + + uint32_t setRefcon(uint32_t refcon); + + /** + * Sets this widget's border state. + * + * @param isBorderless The border state. + */ + + void setBorderless(bool isBorderless); + + /** + * Sets whether or not this widget can be dragged. + * + * @param isDraggable The draggable state. + */ + + inline void setDraggable(const bool isDraggable) + { + m_flags.draggable = isDraggable; + } + + /** + * Sets whether or not child widgets can exceed this widget's dimensions. + * + * @param permeable The permeable state. + */ + + inline void setPermeable(const bool permeable) + { + m_flags.permeable = permeable; + } + + /** + * Sets whether or not the widgets processes double-clicks. + * + * @param doubleClickable The double-clickable state. + */ + + inline void setDoubleClickable(const bool doubleClickable) + { + m_flags.doubleClickable = doubleClickable; + } + + /** + * Adds a widget event handler. The event handler will receive + * all events raised by this widget. + * + * @param eventHandler A pointer to the event handler. + */ + + inline void addWidgetEventHandler(CWidgetEventHandler *eventHandler) + { + m_widgetEventHandlers->addWidgetEventHandler(eventHandler); + } + + /** + * Remove a widget event handler. + * + * @param eventHandler A pointer to the event handler to remove. + */ + + inline void removeWidgetEventHandler(CWidgetEventHandler* eventHandler) + { + m_widgetEventHandlers->removeWidgetEventHandler(eventHandler); + } + + /** + * Enables or disables event firing for this widget. + * + * @param raises True to enable events, false to disable. + */ + + inline void setRaisesEvents(const bool raises) + { + raises ? m_widgetEventHandlers->enable() : m_widgetEventHandlers->disable(); + } + + /** + * Disabled drawing of this widget. Widgets hidden using this method will still + * be processed. + */ + + inline void disableDrawing(void) + { + m_flags.drawingEnabled = false; + } + + /** + * Enables drawing of this widget. + */ + + inline void enableDrawing(void) + { + m_flags.drawingEnabled = true; + } + + /** + * Sets the normal background color. + * + * @param color The new background color. + */ + + inline void setBackgroundColor(const nxgl_mxpixel_t color) + { + m_style.colors.background = color; + } + + /** + * Sets the background color for a selected widget. + * + * @param color The new selected background color. + */ + + inline void setSelectedBackgroundColor(const nxgl_mxpixel_t color) + { + m_style.colors.selectedBackground = color; + } + + /** + * Sets the shiny edge color. + * + * @param color The new shine edge color. + */ + + inline void setShineEdgeColor(const nxgl_mxpixel_t color) + { + m_style.colors.shineEdge = color; + } + + /** + * Sets the shadow edge color. + * + * @param color The new shadow edge color. + */ + + inline void setShadowEdgeColor(const nxgl_mxpixel_t color) + { + m_style.colors.shadowEdge = color; + } + + /** + * Sets the highlight color. + * + * @param color The new highlight color. + */ + + inline void setHighlightColor(const nxgl_mxpixel_t color) + { + m_style.colors.highlight = color; + } + + /** + * Sets the text color to use when the widget is disabled. + * + * @param color The new text color. + */ + + inline void setDisabledTextColor(const nxgl_mxpixel_t color) + { + m_style.colors.disabledText = color; + } + + /** + * Sets the text color to use when the widget is enabled. + * + * @param color The new text color. + */ + + inline void setEnabledTextColor(const nxgl_mxpixel_t color) + { + m_style.colors.enabledText = color; + } + + /** + * Sets the text color to use when the widget is highlighted or clicked. + * + * @param color The new selected text color. + */ + + inline void setSelectedTextColor(const nxgl_mxpixel_t color) + { + m_style.colors.selectedText = color; + } + + /** + * Sets the close type other widgets should use when closing this widget. + * + * @param closeType The close type to use. + */ + + inline void setCloseType(const CloseType closeType) + { + m_closeType = closeType; + } + + /** + * Sets the font. + * + * @param font A pointer to the font to use. + */ + + virtual void setFont(CNxFont *font); + + /** + * Draws the visible regions of the widget and the widget's child widgets. + */ + + void redraw(void); + + /** + * Erases the visible regions of the widget by redrawing the widgets + * behind it. + */ + + void erase(void); + + /** + * Enables the widget. + * + * @return True if the widget was enabled. + */ + + bool enable(void); + + /** + * Disabled the widget. + * + * @return True if the widget was disabled. + */ + + bool disable(void); + + /** + * Erases the widget, marks it as deleted, and moves it to the CNxWidget + * deletion queue. Widgets are automatically deleted by the framework and + * should not be deleted externally. + */ + + void close(void); + + /** + * Erases the widget, removes it from the main hierarchy and sets it to + * invisible. Widgets hidden in this way will be partioned off from + * other widgets and will no longer be processed. + * + * @return True if the widget was shelved. + * @see unshelve() + */ + + bool shelve(void); + + /** + * Moves the widget back into the hierarchy and redraws it. Widgets shown + * in this way will be unpartioned and will be processed again. + * + * @return True if the widget was unshelved. + * @see shelve() + */ + + bool unshelve(void); + + /** + * Draws the widget and makes it visible. + * Does not steal focus from other widgets. + * + * @return True if the widget was shown. + * @see hide() + */ + + bool show(void); + + /** + * Erases the widget and makes it invisible. + * Does not re-assign focus to another widget. + * + * @return True if the widget was hidden. + * @see show() + */ + + bool hide(void); + + /** + * Click this widget at the supplied coordinates. This should only be + * overridden in subclasses if the default click behaviour needs to be changed. + * If the subclassed widget should just respond to a standard click, + * the onClick() method should be overridden instead. + * + * @param x X coordinate of the click. + * @param y Y coordinate of the click. + * @return True if the click was successful. + */ + + bool click(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Check if the click is a double-click. + * + * @param x X coordinate of the click. + * @param y Y coordinate of the click. + * @return True if the click is a double-click. + */ + + virtual bool isDoubleClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Double-click this widget at the supplied coordinates. This + * should only be overridden in subclasses if the default + * double-click behaviour needs to be changed. If the subclassed + * widget should just respond to a standard double-click, the + * onDoubleClick() method should be overridden instead. + * + * @param x X coordinate of the click. + * @param y Y coordinate of the click. + * @return True if the click was successful. + */ + + bool doubleClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Release this widget at the supplied coordinates. This + * should only be overridden in subclasses if the default + * release behaviour needs to be changed. If the subclassed + * widget should just respond to a standard release, the + * onRelease() method should be overridden instead. + * + * @param x X coordinate of the release. + * @param y Y coordinate of the release. + * @return True if the release was successful. + */ + + bool release(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Drag the widget to the supplied coordinates. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + * @param vX The horizontal distance that the mouse was dragged. + * @param vY The vertical distance that the mouse was dragged. + * @return True if the drag was successful. + */ + + bool drag(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Send a keypress to the widget. + * + * @param key The keycode to send to the widget. + * @return True if the keypress was processed. + */ + + bool keyPress(nxwidget_char_t key); + + /** + * Send a cursor control event to the widget. + * + * @param control The cursor control code to send to the widget. + * @return True if the cursor control was processed. + */ + + bool cursorControl(ECursorControl control); + + /** + * Give the widget focus. + * + * @return True if the widget received focus correctly. + */ + + bool focus(void); + + /** + * Remove focus from the widget. + * + * @return True if the widget lost focus correctly. + */ + + bool blur(void); + + /** + * Move the widget to the new coordinates. + * Co-ordinates are relative to the parent widget. + * + * @param x The new x coordinate. + * @param y The new y coordinate. + * @return True if the move was successful. + */ + + bool moveTo(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Resize the widget to the new dimensions. + * + * @param width The new width. + * @param height The new height. + * @return True if the resize was successful. + */ + + bool resize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Resize and move the widget in one operation. + * Only performs one redraw so it is faster than calling the + * two separate functions. + * + * @param x The new x coordinate. + * @param y The new y coordinate. + * @param width The new width. + * @param height The new height. + * @return True if the widget was adjusted successfully. + */ + + bool changeDimensions(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Raises the widget to the top of its parent's widget stack. + * + * @return True if the raise was successful. + */ + + bool raiseToTop(void); + + /** + * Lowers the widget to the bottom of its parent's widget stack. + * + * @return True if the lower was successful. + */ + + bool lowerToBottom(void); + + /** + * Raises the supplied widget to the top of this widget's child stack. + * The supplied widget pointer must be a child of this widget. + * + * @param widget A pointer to the child widget to raise. + * @return True if the raise was successful. + */ + + bool raiseWidgetToTop(CNxWidget *widget); + + /** + * Lowers the supplied widget to the bottom of this widget's child stack. + * The supplied widget pointer must be a child of this widget. + * + * @param widget A pointer to the child widget to lower. + * @return True if the lower was successful. + */ + + bool lowerWidgetToBottom(CNxWidget *widget); + + /** + * Moves the supplied child widget to the deletion queue. + * For framework use only. + * + * @param widget A pointer to the child widget. + */ + + void moveChildToDeleteQueue(CNxWidget *widget); + + /** + * Moves the supplied child widget to the shelved widget list. + * For framework use only. + * + * @param widget A pointer to the child widget. + * @return True if the widget was moved successfully. + * @see moveShelvedToChildList() + * @see hide() + */ + + bool moveChildToShelvedList(CNxWidget *widget); + + /** + * Moves the supplied child widget from the shelved list back + * to the child widget list. + * For framework use only. + * + * @param widget A pointer to the shelved widget. + * @return True if the widget was moved successfully. + * @see moveChildtoShelvedList() + * @see show() + */ + + bool moveShelvedToChildList(CNxWidget *widget); + + /** + * Sets the supplied widget as the focused child. The widget must + * be a child of this widget. + * + * @param widget A pointer to the child widget. + * @see getFocusedWidget() + */ + + void setFocusedWidget(CNxWidget *widget); + + /** + * Checks if the supplied coordinates collide with this widget. + * + * @param x The x coordinate to check. + * @param y The y coordinate to check. + * @return True if a collision occurred. + */ + + bool checkCollision(nxgl_coord_t x, nxgl_coord_t y) const; + + /** + * Checks if the supplied rectangle definition collides with this widget. + * + * @param x The x coordinate of the rectangle to check. + * @param y The y coordinate of the rectangle to check. + * @param width The width of the rectangle to check. + * @param height The height of the rectangle to check. + * @return True if a collision occurred. + */ + + bool checkCollision(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height) const; + + /** + * Checks if the supplied widget collides with this widget. + * + * @param widget A pointer to another widget to check for collisions with. + * @return True if a collision occurred. + */ + + bool checkCollision(CNxWidget *widget) const; + + /** + * Invalidate the visible region cache for all widgets below the supplied + * widget in this widget's child stack. This will cause those widgets to + * + * recalculate their visible regions next time they try to draw themselves. + * @param widget A pointer to a child widget. + */ + + void invalidateLowerWidgetsVisibleRectCache(CNxWidget *widget); + + /** + * Adds a widget to this widget's child stack. The widget is added to the + * top of the stack. Note that the widget can only be added if it is not + * already a child of another widget. + * + * @param widget A pointer to the widget to add to the child list. + * @see insertWidget() + */ + + void addWidget(CNxWidget *widget); + + /** + * Inserts a widget into this widget's child stack at the bottom of the + * stack. Note that the widget can only be added if it is not already + * a child of another widget. + * + * @param widget A pointer to the widget to add to the child list. + * @see addWidget() + */ + + void insertWidget(CNxWidget *widget); + + /** + * Set the widget's parent to the widget passed in as a parameter. + * Called automatically when a widget is added as a child. + * + * @param parent A pointer to the parent widget. + */ + + inline void setParent(CNxWidget *parent) + { + m_parent = parent; + } + + /** + * Rebuild the list of this widget's visible regions + */ + + void cacheVisibleRects(void) const; + + /** + * Mark this widget's visible region cache as invalid, and do the same + * to its child widgets. + */ + + void invalidateVisibleRectCache(void); + + /** + * Erase a child widget by drawing the widgets behind it. + * + * @param widget The child widget to erase. + */ + + void eraseWidget(CNxWidget *widget); + + /** + * Redraw any visible regions of this widget that have become corrupted. + * + * @param invalidRects A list of corrupt regions. + * @param sender A pointer to the widget that corrupted the regions. + */ + + void redrawDirty(TNxArray* invalidRects, CNxWidget *sender); + + /** + * Clips a rectangular region to the dimensions of this widget and its ancestors. + * + * @param rect The region that needs to be clipped. + */ + + void clipRectToHierarchy(CRect &rect) const; + + /** + * Swaps the depth of the supplied child widget. + * + * @param widget A pointer to the child widget that needs to swap depths. + * @return True if the swap was successful. + */ + + virtual bool swapWidgetDepth(CNxWidget *widget); + + /** + * Swap the depth of this widget. + * + * @return True if the swap was successful. + */ + + bool swapDepth(void); + + /** + * Delete this widget. This should never be called in user code; widget + * deletion is handled internally. + */ + + inline void destroy(void) + { + delete this; + } + + /** + * Remove this widget from the widget hierarchy. Returns + * responsibility for deleting the widget back to the developer. + * Does not unregister the widget from the VBL system. + * Does not erase the widget from the display. + * + * @return True if the widget was successfully removed. + */ + + bool remove(void); + + /** + * Remove a child widget from the widget hierarchy. Returns + * responsibility for deleting the widget back to the developer. + * Does not unregister the widget from the VBL system. + * Does not erase the widget from the display. + * + * @param widget Pointer to the widget to remove from the hierarchy. + * @return True if the widget was succesfully removed. + */ + + bool removeChild(CNxWidget *widget); + + /** + * Run the widget modally. + */ + + void goModal(void); + + /** + * Stop the widget running modally. + */ + + inline void stopModal(void) + { + m_flags.modal = false; + } + + /** + * Get the index of the specified child widget. + * + * @param widget The widget to get the index of. + * @return The index of the widget. -1 if the widget is not found. + */ + + const int getWidgetIndex(const CNxWidget *widget) const; + + /** + * Get the child widget at the specified index. + * + * @param index Index of the child to retrieve. + * @return Pointer to the child at the specified index. + */ + + const CNxWidget *getChild(int index) const; + + /** + * Get the number of child widgets. + * + * @return The number of child widgets belonging to this widget. + */ + + const int getChildCount(void) const + { + return m_children.size(); + } + + /** + * Get a pointer to the cache of visible rects. + * + * @return A pointer to the cache of visible rects. + */ + + inline CRectCache *getCRectCache(void) const + { + return m_rectCache; + } + + /** + * Sets the border size. The border cannot be drawn over in the + * drawContents() method. + * + * @param borderSize The new border size. + */ + + void setBorderSize(const WidgetBorderSize &borderSize); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXWIDGET_HXX + diff --git a/NxWidgets/libnxwidgets/include/cnxwindow.hxx b/NxWidgets/libnxwidgets/include/cnxwindow.hxx new file mode 100644 index 000000000..4a371bb27 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cnxwindow.hxx @@ -0,0 +1,307 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cnxwindow.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CNXWINDOW_HXX +#define __INCLUDE_CNXWINDOW_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#include "ccallback.hxx" +#include "inxwindow.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + struct SBitmap; + + /** + * This class defines operations on a basic "raw" NX window. These windows + * are "raw" in the since that they are simply rectangular regions with + * no framing or decoration of any kind + * + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class CNxWindow : protected CCallback, public INxWindow + { + private: + NXHANDLE m_hNxServer; /**< Handle to the NX server. */ + NXWINDOW m_hNxWindow; /**< Handle to the NX raw window */ + CWidgetControl *m_widgetControl; /**< The controlling widget for the window */ + + public: + + /** + * Constructor. Creates an uninitialized instance of the CNxWindow + * object. The open() method must be called to initialize the instance. + * + * The general steps to create any window include: + * 1) Create a dumb CWigetControl instance + * 2) Pass the dumb CWidgetControl instance to the window constructor + * that inherits from INxWindow. + * 3) The window constructor call CWidgetControl methods to "smarten" + * the CWidgetControl instance with window-specific knowledge. + * 4) Call the open() method on the window to display the window. + * 5) After that, the fully smartend CWidgetControl instance can + * be used to generate additional widgets. + * 6) After that, the fully smartened CWidgetControl instance can + * be used to generate additional widgets by passing it to the + * widget constructor + * + * @param hNxServer Handle to the NX server. + * @param widgetControl Controlling widget for this window. + */ + + CNxWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl); + + /** + * Destructor. + */ + + ~CNxWindow(void); + + /** + * Creates a new window. Window creation is separate from + * object instantiation so that failures can be reported. + * + * @return True if the window was successfully opened. + */ + + bool open(void); + + /** + * Request the position and size information of the window. The values + * will be returned asynchronously through the client callback method. + * The GetPosition() method may than be called to obtain the positional + * data as provided by the callback. + * + * @return True on success, false on any failure. + */ + + bool requestPosition(void); + + /** + * Get the position of the window (as reported by the NX callback). + * + * @return The position. + */ + + bool getPosition(FAR struct nxgl_point_s *pPos); + + /** + * Get the size of the window (as reported by the NX callback). + * + * @return The size. + */ + + bool getSize(FAR struct nxgl_size_s *pSize); + + /** + * Set the position and size of the window. + * + * @param pPos The new position of the window. + * @return True on success, false on any failure. + */ + + bool setPosition(FAR const struct nxgl_point_s *pPos); + + /** + * Set the size of the selected window. + * + * @param pSize The new size of the window. + * @return True on success, false on any failure. + */ + + bool setSize(FAR const struct nxgl_size_s *pSize); + + /** + * Bring the window to the top of the display. + * + * @return True on success, false on any failure. + */ + + bool raise(void); + + /** + * Lower the window to the bottom of the display. + * + * @return True on success, false on any failure. + */ + + bool lower(void); + + /** + * Set an individual pixel in the window with the specified color. + * + * @param pPos The location of the pixel to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool setPixel(FAR const struct nxgl_point_s *pPos, + nxgl_mxpixel_t color); + + /** + * Fill the specified rectangle in the window with the specified color. + * + * @param pRect The location to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fill(FAR const struct nxgl_rect_s *pRect, + nxgl_mxpixel_t color); + + /** + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * @param rect The location to be copied + * @param dest - The describes the destination bitmap to receive the + * graphics data. + */ + + void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest); + + /** + * Fill the specified trapezoidal region in the window with the specified + * color. + * + * @param pClip Clipping rectangle relative to window (may be null). + * @param pTrap The trapezoidal region to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, + FAR const struct nxgl_trapezoid_s *pTrap, + nxgl_mxpixel_t color); + + /** + * Fill the specified line in the window with the specified color. + * + * @param vector - Describes the line to be drawn + * @param width - The width of the line + * @param color - The color to use to fill the line + * + * @return True on success; false on failure. + */ + + bool drawLine(FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color); + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color); + + /** + * Move a rectangular region within the window. + * + * @param pRect Describes the rectangular region to move. + * @param pOffset The offset to move the region. + * + * @return True on success; false on failure. + */ + + bool move(FAR const struct nxgl_rect_s *pRect, + FAR const struct nxgl_point_s *pOffset); + + /** + * Copy a rectangular region of a larger image into the rectangle in the + * specified window. + * + * @param pDest Describes the rectangular on the display that will receive + * the bitmap. + * @param pSrc The start of the source image. + * @param pOrigin the pOrigin of the upper, left-most corner of the full + * bitmap. Both pDest and pOrigin are in window coordinates, however, + * pOrigin may lie outside of the display. + * @param stride The width of the full source image in bytes. + * + * @return True on success; false on failure. + */ + + bool bitmap(FAR const struct nxgl_rect_s *pDest, + FAR const void *pSrc, + FAR const struct nxgl_point_s *pOrigin, + unsigned int stride); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CNXWINDOW_HXX + diff --git a/NxWidgets/libnxwidgets/include/cprogressbar.hxx b/NxWidgets/libnxwidgets/include/cprogressbar.hxx new file mode 100644 index 000000000..c75d1eee6 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cprogressbar.hxx @@ -0,0 +1,251 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cprogressbar.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CPROGRESSBAR_HXX +#define __INCLUDE_CPROGRESSBAR_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + + /** + * Widget providing a horizontal progress bar. + */ + + class CProgressBar : public CNxWidget + { + protected: + int16_t m_minimumValue; /**< Minimum value that the grip can represent. */ + int16_t m_maximumValue; /**< Maximum value that the grip can represent. */ + int16_t m_value; /**< Value of the progress bar. */ + bool m_showPercentageText; /**< If true, completion percentage is drawn + over the bar. */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CProgressBar(const CProgressBar &progressBar) : CNxWidget(progressBar) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the progress bar, relative to its parent. + * @param y The y coordinate of the progress bar, relative to its parent. + * @param width The width of the progress bar. + * @param height The height of the progress bar. + */ + + CProgressBar(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CProgressBar(void) { } + + /** + * Get the smallest value that the progress bar can represent. + * + * @return The smallest value. + */ + + inline const int16_t getMinimumValue(void) const + { + return m_minimumValue; + } + + /** + * Get the largest value that the progress bar can represent. + * + * @return The largest value. + */ + + inline const int16_t getMaximumValue(void) const + { + return m_maximumValue; + } + + /** + * Get the current value of the progress bar. + * return The current progress bar value. + */ + + inline const int16_t getValue(void) const + { + return m_value; + } + + /** + * Set the smallest value that the progress bar can represent. + * + * @param value The smallest value. + */ + + inline void setMinimumValue(const int16_t value) + { + m_minimumValue = value; + } + + /** + * Set the largest value that the progress bar can represent. + * + * @param value The largest value. + */ + + inline void setMaximumValue(const int16_t value) + { + m_maximumValue = value; + } + + /** + * Set the value that of the progress bar. + * + * @param value The new value. + */ + + void setValue(const int16_t value); + + /** + * Shows the percentage text over the bar. + */ + + inline void showPercentageText(void) + { + m_showPercentageText = true; + redraw(); + } + + /** + * Hides the percentage text over the bar. + */ + + inline void hidePercentageText(void) + { + m_showPercentageText = false; + redraw(); + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CPROGRESSBAR_HXX diff --git a/NxWidgets/libnxwidgets/include/cradiobutton.hxx b/NxWidgets/libnxwidgets/include/cradiobutton.hxx new file mode 100644 index 000000000..4186b8eea --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cradiobutton.hxx @@ -0,0 +1,207 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cradiobutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CRADIOBUTTON_HXX +#define __INCLUDE_CRADIOBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "cbutton.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + class CRadioButtonGroup; + + /** + * Represents a radio button. Radio buttons can only exist as part of a + * CRadioButtonGroup class, and should not be instantiated individually. + * Radio buttons are tri-state - off, on and "mu". + * The mu state cannot be enabled by a user - it can only be set by the + * developer. + */ + + class CRadioButton : public CButton + { + public: + + /** + * Enum listing all possible radio button states. + */ + + enum RadioButtonState + { + RADIO_BUTTON_STATE_OFF = 0, /**< Radio button is off */ + RADIO_BUTTON_STATE_ON = 1, /**< Radio button is on */ + RADIO_BUTTON_STATE_MU = 2 /**< Radio button is in the third state */ + }; + + protected: + + RadioButtonState m_state; /**< The state of the radio button */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Sets the radiobutton's state to "on". + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Destructor. + */ + + virtual inline ~CRadioButton() { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CRadioButton(const CRadioButton &radioButton) : CButton(radioButton) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display. + * @param x The x coordinate of the radio button, relative to its + * parent. + * @param y The y coordinate of the radio button, relative to its + * parent. + * @param width The width of the radio button. + * @param height The height of the radio button. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * defaultCWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CRadioButton(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Get the current state of the radio button. + * + * @return The state of the radio button. + */ + + virtual inline RadioButtonState getState(void) + { + return m_state; + } + + /** + * Set the state of the radio button. + * + * @param state The new radio button state. + */ + + virtual void setState(RadioButtonState state); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CRADIOBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/cradiobuttongroup.hxx b/NxWidgets/libnxwidgets/include/cradiobuttongroup.hxx new file mode 100644 index 000000000..c37630c61 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cradiobuttongroup.hxx @@ -0,0 +1,253 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cradiobuttongroup.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CRADIOBUTTONGROUP_HXX +#define __INCLUDE_CRADIOBUTTONGROUP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "cnxwidget.hxx" +#include "cbutton.hxx" +#include "cwidgetstyle.hxx" +#include "cwidgeteventhandler.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + class CRadioButton; + + /** + * Container class that holds radio button widgets and tracks their status. + * The group provides an easy way to determine which radio button is + * selected. Note that, in order to set the "mu" state for a radio button, + * it is necessary to set the state via the radio button, not the group. + */ + + class CRadioButtonGroup : public CNxWidget, public CWidgetEventHandler + { + protected: + CWidgetControl *m_pWidgetControl; /**< The controlling widget */ + CRadioButton *m_selectedWidget; /**< Pointer to the currently selected radio button */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort* port); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CRadioButtonGroup(const CRadioButtonGroup &radioButtonGroup) : CNxWidget(radioButtonGroup) { } + + public: + + /** + * Constructor. Note that the group determines its width and height + * from the position and dimensions of its children. + * + * @param pWidgetControl The controlling widget for the display. + * @param x The x coordinate of the group. + * @param y The y coordinate of the group. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CRadioButtonGroup(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + ~CRadioButtonGroup(void) { } + + /** + * Simple method for adding a new radio button to the group. + * This should be used in preference to the usual addWidget() method, + * as this method automatically resizes the group. + * + * @param x The x coordinate of the new button, relative to this + * widget. + * @param y The y coordinate of the new button, relative to this + * widget. + * @param width The width of the new button. + * @param height The height of the new button. + */ + + CRadioButton *newRadioButton(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Gets a pointer to the selected widget. + * + * @return Pointer to the selected widget. + */ + + virtual const CRadioButton *getSelectedWidget(void) const; + + /** + * Gets the index of the selected widget. + * + * @return The index of the selected widget. + */ + + virtual const int getSelectedIndex(void) const; + + /** + * Sets the selected radio button to the supplied widget. + * + * @param widget The radio button to select. + */ + + virtual void setSelectedWidget(CRadioButton *widget); + + /** + * Selects the widget at the specified index. + * + * @param index The index of the widget to select. + */ + + virtual void setSelectedIndex(int index); + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the + * widget's parent. Value is based on the length of the largest string + * in the set of options. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + + /** + * Handle a mouse click event. + * + * @param e The event data. + */ + + virtual void handleClickEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse double-click event. + * + * @param e The event data. + */ + + virtual void handleDoubleClickEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse button release event that occurred within the bounds of + * the source widget. + * @param e The event data. + */ + + virtual void handleReleaseEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse button release event that occurred outside the bounds of + * the source widget. + * + * @param e The event data. + */ + + virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CRADIOBUTTONGROUP_HXX diff --git a/NxWidgets/libnxwidgets/include/crect.hxx b/NxWidgets/libnxwidgets/include/crect.hxx new file mode 100644 index 000000000..e3a73a392 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/crect.hxx @@ -0,0 +1,424 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cbgwindow.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CRECT_HXX +#define __INCLUDE_CRECT_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class describing a rectangle. + */ + + class CRect + { + public: + struct nxgl_point_s m_pos; /**< The position of the rectangle in the window */ + struct nxgl_size_s m_size; /**< The size of the rectangle */ + + /** + * Constructor. + */ + + CRect(void); + + /** + * Constructor. + * + * @param x The x coordinate of the rect. + * @param y The y coordinate of the rect. + * @param width The width of the rect. + * @param height The height of the rect. + */ + + CRect(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Constructor. + * + * @param rect Pointer to an NX rectangle + */ + + CRect(FAR const nxgl_rect_s *rect); + + /** + * Copy constructor. + * + * @param rect CRect to copy. + */ + + CRect(const CRect& rect); + + /** + * Create a rect object from the supplied coordinates. + * + * @param x1 The x coordinate of the rect's top-left corner. + * @param y1 The y coordinate of the rect's top-left corner. + * @param x2 The x coordinate of the rect's bottom-right corner. + * @param y2 The y coordinate of the rect's bottom-right corner. + * @return A new rect. + */ + + static CRect fromCoordinates(nxgl_coord_t x1, nxgl_coord_t y1, + nxgl_coord_t x2, nxgl_coord_t y2); + + /** + * Get the rectangle's left x coordinate. + * + * @return The rectangle's x coordinate. + */ + + inline nxgl_coord_t getX(void) const + { + return m_pos.x; + } + + /** + * Get the rectangle's top y coordinate. + * @return The rectangle's y coordinate. + */ + + inline nxgl_coord_t getY(void) const + { + return m_pos.y; + } + + /** + * Get the rectangle's width. + * + * @return The rectangle's width. + */ + + inline nxgl_coord_t getWidth(void) const + { + return m_size.w; + } + + /** + * Get the rectangle's height. + * + * @return The rectangle's height. + */ + + inline nxgl_coord_t getHeight(void) const + { + return m_size.h; + } + + /** + * Get the NX rectangle representation + * + * @param rect Pointer to NX rectangle + */ + + inline void getNxRect(FAR struct nxgl_rect_s *rect) const + { + rect->pt1.x = m_pos.x; + rect->pt1.y = m_pos.y; + rect->pt2.x = m_pos.x + m_size.w - 1; + rect->pt2.y = m_pos.y + m_size.h - 1; + } + + /** + * Set the rectangle's left x coordinate. + * + * @param x The new x coordinate. + */ + + inline void setX(nxgl_coord_t x) + { + m_pos.x = x; + } + + /** + * Set the rectangle's top y coordinate. + * + * @param y The new y coordinate. + */ + + inline void setY(nxgl_coord_t y) + { + m_pos.y = y; + } + + /** + * Set the rect's width. + * + * @param width The new width. + */ + inline void setWidth(nxgl_coord_t width) + { + m_size.w = width; + } + + /** + * Set the rect's height. + * + * @param height The new height. + */ + + inline void setHeight(nxgl_coord_t height) + { + m_size.h = height; + } + + /** + * Get the NX rectangle representation + * + * @param rect Pointer to NX rectangle + */ + + inline void setNxRect(FAR const struct nxgl_rect_s *rect) + { + m_pos.x = rect->pt1.x; + m_pos.y = rect->pt1.y; + m_size.w = rect->pt2.x - rect->pt1.x + 1; + m_size.h = rect->pt2.y - rect->pt1.y + 1; + } + + /** + * Set the x coordinate of the rect's bottom-right corner. If x2 is less + * than the rect's current x coordinate the method automatically adjusts + * the coordinates so that the rect's width is never negative. Changing this + * property will change the width of the rect. + * + * @param x2 The x coordinate of the rect's bottom-right corner. + */ + + void setX2(nxgl_coord_t x2); + + /** + * Set the y coordinate of the rect's bottom-right corner. If y2 is less + * than the rect's current y coordinate the method automatically adjusts + * the coordinates so that the rect's height is never negative. Changing this + * property will change the height of the rect. + * + * @param y2 The y coordinate of the rect's bottom-right corner. + */ + + void setY2(nxgl_coord_t y2); + + /** + * Get the x coordinate of the rectangle's right side. + * + * @return The x coordinate of the rectangle's right side. + */ + + inline nxgl_coord_t getX2(void) const + { + return m_pos.x + m_size.w - 1; + } + + /** + * Get the y coordinate of the rectangle's bottom side. + * + * @return The y coordinate of the rerectangle's bottom side. + */ + + inline nxgl_coord_t getY2(void) const + { + return m_pos.y + m_size.h - 1; + } + + /** + * Offset the rectangle position by the specified dx, dy values. + * + * @param dx X offset value + * @param dy Y offset value + */ + + inline void offset(nxgl_coord_t dx, nxgl_coord_t dy) + { + m_pos.x += dx; + m_pos.y += dy; + } + + /** + * Determines if the rectangle has two dimensions; in other words, does it + * have both height and width? Negative width or height is considered not to + * be valid. + * + * @return True if the rect has height and width; false if not. + */ + + inline bool hasDimensions(void) const + { + return m_size.w > 0 && m_size.h > 0; + } + + /** + * Populates dest with a rectangle representating the intersection + * of this rectangle and rect. + * + * @param rect The rectangle to intersect with this. + * @param dest The destination rectangle. + */ + + void getIntersect(const CRect& rect, CRect& dest) const; + + /** + * Populates dest with a rectangle representating the smallest + * rectangle that contains this rectangle and rect. + * + * @param rect The rectangle to add to this. + * @param dest The destination rectangle. + */ + + void getAddition(const CRect &rect, CRect &dest) const; + + /** + * Clips this rect to the region that intersects the supplied rect. + * + * @param rect CRect to intersect. + */ + + void clipToIntersect(const CRect &rect); + + /** + * Expands this rect so that it includes the area described by the supplied + * rect. + * + * @param rect CRect to include. + */ + + void expandToInclude(const CRect &rect); + + /** + * Check if the supplied rect intersects this. + * + * @param rect CRect to check for intersection with this. + * @return True if the rect intersects this; false if not. + */ + + bool intersects(const CRect &rect) const; + + /** + * Check if the rect contains the supplied point. + * + * @param x X coordinate of the point. + * @param y Y coordinate of the point. + * @return True if the rect contains the point; false if not. + */ + + bool contains(nxgl_coord_t x, nxgl_coord_t y) const; + + /** + * Copy the properties of this rect to the destination rect. + * + * @param dest Destination rect to copy to. + */ + + void copyTo(CRect &dest) const; + + /** + * Overloaded & operator. Returns the intersect of this rectangle and the + * rectangle passed as the "rect" argument". + * + * @param rect The rectangle to intersect with this. + */ + + CRect operator&(const CRect &rect); + + /** + * Overloaded + operator. Returns the smallest rectangle that can contain + * this rectangle and the rectangle passed as the "rect" argument". + * + * @param rect The rectangle to add to this. + */ + + CRect operator+(const CRect &rect); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CRECT_HXX diff --git a/NxWidgets/libnxwidgets/include/crectcache.hxx b/NxWidgets/libnxwidgets/include/crectcache.hxx new file mode 100644 index 000000000..f38c2313b --- /dev/null +++ b/NxWidgets/libnxwidgets/include/crectcache.hxx @@ -0,0 +1,222 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/crectcache.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CRECTCACHE_HXX +#define __INCLUDE_CRECTCACHE_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgetstyle.hxx" +#include "tnxarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Maintains a list of foreground (ie. above children) and background (with + * child overlapped-rects removed) rectangles representing the visible portions + * of a widget. + */ + + class CRectCache + { + private: + TNxArray m_foregroundRegions; /**< List of the widget's visible regions */ + TNxArray m_backgroundRegions; /**< List of the widget's visible regions with child rects removed */ + const CNxWidget *m_widget; /**< Owning widget */ + bool m_foregroundInvalid; /**< True if the foreground cache needs refreshing */ + bool m_backgroundInvalid; /**< True if the background cache needs refreshing */ + + /** + * Cache the foreground regions. + */ + + void cacheForegroundRegions(void); + + /** + * Cache the background regions. + */ + + void cacheBackgroundRegions(void); + + public: + + /** + * Constructor. + * + * @param widget Widget that contains the rect cache. + */ + + CRectCache(const CNxWidget *widget); + + /** + * Destructor. + */ + + inline ~CRectCache() { } + + /** + * Rebuild the cache if it is invalid. + */ + + void cache(void); + + /** + * Invalidates the cache. + */ + + inline void invalidate(void) + { + m_foregroundInvalid = true; + m_backgroundInvalid = true; + }; + + /** + * Return the list of background regions. These are regions that are not overlapped by + * child widgets. + * + * @return The list of background regions. + */ + + inline TNxArray *getBackgroundRegions(void) + { + return &m_backgroundRegions; + } + + /** + * Return the list of foreground regions. These are regions that represent the entire + * visible surface of the widget - that is, any regions not overlapped by ancestors or + * sublings of the widget - including any regions that are actually overlapped by + * child widgets. + * + * @return The list of foreground regions. + */ + + inline TNxArray *getForegroundRegions(void) + { + return &m_foregroundRegions; + } + + /** + * Works out which rectangles in the invalidRects list overlap this + * widget, then cuts the rectangles into smaller pieces. The overlapping + * pieces are pushed into validRects, and the non-overlapping pieces are + * pushed back into the invalidRects vector. + * + * @param invalidRects A vector of regions that need to be tested + * for collisions against this widget; they represent regions that need + * to be redrawn. + * @param validRects A vector of regions that represents areas of the + * display that do not need to be redrawn. + * @param sender Pointer to the widget that initiated the split. + */ + + void splitRectangles(TNxArray *invalidRects, + TNxArray *validRects, + FAR const CNxWidget *sender) const; + + /** + * Move any rectangles from the visibleRects list that overlap this widget + * into the invisibleRects list. Used during visible region calculations. + * + * @param visibleRects A vector of regions that are not overlapped. + * @param invisibleRects A vector of regions that are overlapped. + * @param widget The widget that requested the lists. + * @see splitRectangles() + */ + + void removeOverlappedRects(TNxArray *visibleRects, + TNxArray *invisibleRects, + FAR const CNxWidget* widget) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CRECTCACHE_HXX + diff --git a/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx b/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx new file mode 100644 index 000000000..2b1e4f065 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx @@ -0,0 +1,259 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + ****************************************************************************/ + +#ifndef __INCLUDE_CRLEPALETTBITMAP_HXX +#define __INCLUDE_CRLEPALETTBITMAP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nxconfig.hxx" +#include "ibitmap.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * One Run-Length Encoded (RLE) value + */ + + struct SRlePaletteBitmapEntry + { + uint8_t npixels; /**< Number of pixels */ + uint8_t lookup; /**< Pixel RGB lookup index */ + }; + + /** + * Run-Length Encoded (RLE), Paletted Bitmap Structure + */ + + struct SRlePaletteBitmap + { + uint8_t bpp; /**< Bits per pixel */ + uint8_t fmt; /**< Color format */ + uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */ + nxgl_coord_t width; /**< Width in pixels */ + nxgl_coord_t height; /**< Height in rows */ + FAR const void *lut; /**< Pointer to the beginning of the Look-Up Table (LUT) */ + + /** + * The pointer to the beginning of the RLE data + */ + + FAR const struct SRlePaletteBitmapEntry *data; + }; + + /** + * Class providing bitmap accessor for a bitmap represented by SRlePaletteBitmap. + */ + + class CRlePaletteBitmap : public IBitmap + { + protected: + /** + * The bitmap that is being managed + */ + + FAR const struct SRlePaletteBitmap *m_bitmap; /**< The bitmap that is being managed */ + + /** + * Accessor state data + */ + + nxgl_coord_t m_row; /**< Logical row number */ + nxgl_coord_t m_col; /**< Logical column number */ + uint8_t m_remaining; /**< Number of bytes remaining in current entry */ + FAR const struct SRlePaletteBitmapEntry *m_rle; /**< RLE entry being processed */ + + /** + * Reset to the beginning of the image + */ + + void startOfImage(void); + + /** + * Advance position data ahead. Called after npixels have + * have been consume. + * + * @param npixels The number of pixels to advance + * @return False if this goes beyond the end of the image + */ + + bool advancePosition(nxgl_coord_t npixels); + + /** + * Seek ahead the specific number of pixels -- discarding + * and advancing. + * + * @param npixels The number of pixels to skip + * @return False if this goes beyond the end of the image + */ + + bool skipPixels(nxgl_coord_t npixels); + + /** Seek to the beginning of the next row + * + * @return False if this was the last row of the image + */ + + bool nextRow(void); + + /** Seek to the beignning specific row + * + * @param row The row number to seek to + * @return False if this goes beyond the end of the image + */ + + bool seekRow(nxgl_coord_t row); + + /** Copy the pixels from the current RLE entry the specified number of times. + * + * @param npixels The number of pixels to copy. Must be less than or equal + * to m_remaining. + * @param data The memory location provided by the caller + * in which to return the data. This should be at least + * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length + * and properly aligned for the pixel color format. + */ + + void copyColor(nxgl_coord_t npixels, FAR void *data); + + /** Copy pixels from the current position + * + * @param npixels The number of pixels to copy + * @param data The memory location provided by the caller + * in which to return the data. This should be at least + * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length + * and properly aligned for the pixel color format. + * @return False if this goes beyond the end of the image + */ + + bool copyPixels(nxgl_coord_t npixels, FAR void *data); + + public: + + /** + * Constructor. + * + * @param bitmap The bitmap structure being wrapped. + */ + + CRlePaletteBitmap(const struct SRlePaletteBitmap *bitmap); + + /** + * Destructor. + */ + + inline ~CRlePaletteBitmap(void) {} + + /** + * Get the bitmap's color format. + * + * @return The bitmap's width. + */ + + const uint8_t getColorFormat(void) const; + + /** + * Get the bitmap's color format. + * + * @return The bitmap's color format. + */ + + const uint8_t getBitsPerPixel(void) const; + + /** + * Get the bitmap's width (in pixels/columns). + * + * @return The bitmap's pixel depth. + */ + + const nxgl_coord_t getWidth(void) const; + + /** + * Get the bitmap's height (in rows). + * + * @return The bitmap's height. + */ + + const nxgl_coord_t getHeight(void) const; + + /** + * Get the bitmap's width (in bytes). + * + * @return The bitmap's width. + */ + + const nxgl_coord_t getStride(void) const; + + /** + * Get one row from the bit map image. + * + * @param x The offset into the row to get + * @param y The row number to get + * @param width The number of pixels to get from the row + * @param data The memory location provided by the caller + * in which to return the data. This should be at least + * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length + * and properly aligned for the pixel color format. + * @param True if the run was returned successfully. + */ + + bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + FAR void *data); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CRLEPALETTBITMAP_HXX diff --git a/NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx b/NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx new file mode 100644 index 000000000..20ba149fa --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx @@ -0,0 +1,293 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollbarhorizontal.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLBARHORIZONTAL_HXX +#define __INCLUDE_CSCROLLBARHORIZONTAL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgeteventhandler.hxx" +#include "cwidgetstyle.hxx" +#include "islider.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CSliderHorizontal; + class CGlyphButton; + class CNxTimer; + + /** + * Container class that holds a slider widget and two arrow buttons. + * The interface is presents is virtually identical to the CSliderHorizontal + * widget, which means the two are easily interchangeable. All events + * raised by the internal slider widget are re-raised by this widget + * to this widget's event handler, meaning its events are also identical + * to the CSliderHorizontal's. + */ + + class CScrollbarHorizontal : public ISlider, public CNxWidget, public CWidgetEventHandler + { + protected: + CSliderHorizontal *m_slider; /**< Pointer to the slider widget */ + CGlyphButton *m_leftButton; /**< Pointer to the left button */ + CGlyphButton *m_rightButton; /**< Pointer to the right button */ + nxgl_coord_t m_buttonWidth; /**< Width of the buttons */ + uint8_t m_scrollTimeout; /**< Time until a button triggers + another grip movement */ + CNxTimer *m_timer; /**< Controls slider button repeats */ + + /** + * Resize the scrollbar to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScrollbarHorizontal(const CScrollbarHorizontal &scrollbarHorizontal) + : CNxWidget(scrollbarHorizontal) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control instance for the window. + * @param x The x coordinate of the slider, relative to its parent. + * @param y The y coordinate of the slider, relative to its parent. + * @param width The width of the slider. + * @param height The height of the slider. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScrollbarHorizontal(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CScrollbarHorizontal(void) { } + + /** + * Get the smallest value that the slider can represent. + * + * @return The smallest value. + */ + + const nxgl_coord_t getMinimumValue(void) const; + + /** + * Get the largest value that the slider can represent. + * + * @return The largest value. + */ + + const nxgl_coord_t getMaximumValue(void) const; + + /** + * Get the current value of the slider. + * + * @return The current slider value. + */ + + const nxgl_coord_t getValue(void) const; + + /** + * Get the value represented by the height of the grip. + * For sliders, this would typically be 1 (so each new + * grip position is worth 1). For scrollbars, this + * would be the height of the scrolling widget. + * + * @return The page size. + */ + + const nxgl_coord_t getPageSize(void) const; + + /** + * Set the smallest value that the slider can represent. + * + * @param value The smallest value. + */ + + void setMinimumValue(const nxgl_coord_t value); + + /** + * Set the largest value that the slider can represent. + * + * @param value The largest value. + */ + + void setMaximumValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition + * and redraw the grip. + * + * @param value The new value. + */ + + void setValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition and redraw + * the grip. The supplied value should be bitshifted left 16 places. + * This ensures greater accuracy than the standard setValue() method if + * the slider is being used as a scrollbar. + * + * @param value The new value. + */ + + void setValueWithBitshift(const int32_t value); + + /** + * Set the page size represented by the grip. + * + * @param pageSize The page size. + * @see getPageSize(). + */ + + void setPageSize(const nxgl_coord_t pageSize); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleActionEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleClickEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleReleaseEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleValueChangeEvent(const CWidgetEventArgs &e); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLBARHORIZONTAL_HXX + diff --git a/NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx b/NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx new file mode 100644 index 000000000..08bdb721c --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx @@ -0,0 +1,309 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollbarpanel.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLBARPANEL_HXX +#define __INCLUDE_CSCROLLBARPANEL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cscrollingpanel.hxx" +#include "cwidgetstyle.hxx" +#include "cscrollbarvertical.hxx" +#include "cscrollbarhorizontal.hxx" +#include "cwidgeteventhandler.hxx" +#include "iscrollable.hxx" +#include "cgraphicsport.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class containing a scrolling panel bordered by scrollbars. + */ + class CScollbarPanel : public CNxWidget, public IScrollable, + public CWidgetEventHandler + { + protected: + CWidgetControl *m_widgetControl; /**< Widget control instance */ + CScrollingPanel *m_panel; /**< Internal panel that + contains children. */ + CScrollbarHorizontal *m_scrollbarHorizontal; /**< Horizontal scrollbar. */ + CScrollbarVertical *m_scrollbarVertical; /**< Vertical scrollbar. */ + uint8_t m_scrollbarWidth; /**< Width of the vertical + scrollbar. */ + uint8_t m_scrollbarHeight; /**< Height of the horizontal + scrollbar. */ + bool m_hasVerticalScrollbar; /**< Indicates the presence of + a vertical scrollbar. */ + bool m_hasHorizontalScrollbar; /**< Indicates the presence of + a horizontal scrollbar. */ + + /** + * Creates the child widgets. + */ + + void buildUI(void); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Destructor. + */ + + virtual ~CScollbarPanel(void) { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScollbarPanel(const CScollbarPanel &scrollbarPanel) + : CNxWidget(scrollbarPanel) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + * @param flags The usual widget flags. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScollbarPanel(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + uint32_t flags, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Scroll the panel by the specified amounts. + * + * @param dx The horizontal distance to scroll. + * @param dy The vertical distance to scroll. + */ + + virtual void scroll(int32_t dx, int32_t dy); + + /** + * Reposition the panel's scrolling region to the specified coordinates. + * + * @param x The new x coordinate of the scrolling region. + * @param y The new y coordinate of the scrolling region. + */ + + virtual void jump(int32_t x, int32_t y); + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsVerticalScroll(bool allow); + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsHorizontalScroll(bool allow); + + /** + * Sets the width of the virtual canvas. + * + * @param width The width of the virtual canvas. + */ + + virtual void setCanvasWidth(const int32_t width); + + /** + * Sets the height of the virtual canvas. + * + * @param height The height of the virtual canvas. + */ + + virtual void setCanvasHeight(const int32_t height); + + /** + * Returns true if vertical scrolling is allowed. + * + * @return True if vertical scrolling is allowed. + */ + + virtual bool allowsVerticalScroll(void) const; + + /** + * Returns true if horizontal scrolling is allowed. + * + * @return True if horizontal scrolling is allowed. + */ + + virtual bool allowsHorizontalScroll(void) const; + + /** + * Gets the x coordinate of the virtual canvas. + * + * @return The x coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasX(void) const; + + /** + * Gets the y coordinate of the virtual canvas. + * + * @return The y coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasY(void) const; + + /** + * Gets the width of the virtual canvas. + * + * @return The width of the virtual canvas. + */ + + virtual const int32_t getCanvasWidth(void) const; + + /** + * Gets the height of the virtual canvas. + * + * @return The height of the virtual canvas. + */ + + virtual const int32_t getCanvasHeight(void) const; + + /** + * Handle a widget scroll event. + * + * @param e The event data. + */ + + void handleScrollEvent(const CWidgetEventArgs &e); + + /** + * Handle a widget value change event. + * + * @param e The event data. + */ + + void handleValueChangeEvent(const CWidgetEventArgs &e); + + /** + * Gets a pointer to the CScrollingPanel widget contained within + * this widget. + * + * @return A pointer to the CScrollingPanel widget. + */ + + inline CScrollingPanel *getPanel(void) + { + return m_panel; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLBARPANEL_HXX + diff --git a/NxWidgets/libnxwidgets/include/cscrollbarvertical.hxx b/NxWidgets/libnxwidgets/include/cscrollbarvertical.hxx new file mode 100644 index 000000000..974da3378 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollbarvertical.hxx @@ -0,0 +1,291 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollbarvertical.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLBARVERTICAL_HXX +#define __INCLUDE_CSCROLLBARVERTICAL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgeteventhandler.hxx" +#include "cwidgetstyle.hxx" +#include "islider.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CSliderVertical; + class CGlyphButton; + class CNxTimer; + + /** + * Container class that holds a slider widget and two arrow buttons. + * The interface is presents is virtually identical to the CSliderVertical + * widget, which means the two are easily interchangeable. All events + * raised by the internal slider widget are re-raised by this widget + * to this widget's event handler, meaning its events are also identical + * to the CSliderVertical's. + */ + class CScrollbarVertical : public ISlider, public CNxWidget, public CWidgetEventHandler { + + protected: + CSliderVertical *m_slider; /**< Pointer to the slider widget */ + CGlyphButton *m_upButton; /**< Pointer to the up button */ + CGlyphButton *m_downButton; /**< Pointer to the down button */ + nxgl_coord_t m_buttonHeight; /**< Height of the buttons */ + uint8_t m_scrollTimeout; /**< Time until a button triggers another grip + movement */ + CNxTimer *m_timer; /**< Controls slider button repeats */ + + /** + * Resize the scrollbar to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScrollbarVertical(const CScrollbarVertical& scrollbarVertical) + : CNxWidget(scrollbarVertical) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control instance for the window. + * @param x The x coordinate of the slider, relative to its parent. + * @param y The y coordinate of the slider, relative to its parent. + * @param width The width of the slider. + * @param height The height of the slider. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScrollbarVertical(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CScrollbarVertical(void) { } + + /** + * Get the smallest value that the slider can represent. + * + * @return The smallest value. + */ + + const nxgl_coord_t getMinimumValue(void) const; + + /** + * Get the largest value that the slider can represent. + * + * @return The largest value. + */ + + const nxgl_coord_t getMaximumValue(void) const; + + /** + * Get the current value of the slider. + * + * @return The current slider value. + */ + + const nxgl_coord_t getValue(void) const; + + /** + * Get the value represented by the height of the grip. + * For sliders, this would typically be 1 (so each new + * grip position is worth 1). For scrollbars, this + * would be the height of the scrolling widget. + * + * @return The page size. + */ + + const nxgl_coord_t getPageSize(void) const; + + /** + * Set the smallest value that the slider can represent. + * + * @param value The smallest value. + */ + + void setMinimumValue(const nxgl_coord_t value); + + /** + * Set the largest value that the slider can represent. + * + * @param value The largest value. + */ + + void setMaximumValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition + * and redraw the grip. + * + * @param value The new value. + */ + + void setValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition and redraw + * the grip. The supplied value should be bitshifted left 16 places. + * This ensures greater accuracy than the standard setValue() method if + * the slider is being used as a scrollbar. + * + * @param value The new value. + */ + + void setValueWithBitshift(const int32_t value); + + /** + * Set the page size represented by the grip. + * + * @param pageSize The page size. + * @see getPageSize(). + */ + + void setPageSize(const nxgl_coord_t pageSize); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleActionEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleClickEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleReleaseEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e); + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleValueChangeEvent(const CWidgetEventArgs &e); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLBARVERTICAL_HXX diff --git a/NxWidgets/libnxwidgets/include/cscrollinglistbox.hxx b/NxWidgets/libnxwidgets/include/cscrollinglistbox.hxx new file mode 100644 index 000000000..ba7090b4b --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollinglistbox.hxx @@ -0,0 +1,480 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollinglistbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLINGLISTBOX_HXX +#define __INCLUDE_CSCROLLINGLISTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "clistbox.hxx" +#include "cwidgeteventhandler.hxx" +#include "clistdata.hxx" +#include "clistboxdataitem.hxx" +#include "cwidgetstyle.hxx" +#include "ilistbox.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CScrollbarVertical; + class CWidgetControl; + + /** + * Widget containing a CListBox and a vertical scrollbar. Exposed + * methods are more or less identical to the methods exposed by the CListBox + * to ensure that the two are interchangeable. + */ + + class CScrollingListBox : public IListBox, public CNxWidget, + public CWidgetEventHandler + { + protected: + CListBox *m_listbox; /**< Pointer to the list box. */ + CScrollbarVertical *m_scrollbar; /**< Pointer to the scrollbar. */ + uint8_t m_scrollbarWidth; /**< Width of the scrollbar. */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Resize the listbox to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CScrollingListBox(void) { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScrollingListBox(const CScrollingListBox &scrollingListBox) + : CNxWidget(scrollingListBox) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScrollingListBox(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Add a new option to the widget using default colors. + * + * @param text Text to show in the option. + * @param value The value of the option. + */ + + virtual void addOption(const CNxString &text, const uint32_t value); + + /** + * Add an option to the widget. + * + * @param option The option to add. + */ + + virtual void addOption(CListBoxDataItem *option); + + /** + * Add a new option to the widget. + * + * @param text Text to show in the option. + * @param value The value of the option. + * @param normalTextColor Color to draw the text with when not selected. + * @param normalBackColor Color to draw the background with when not selected. + * @param selectedTextColor Color to draw the text with when selected. + * @param selectedBackColor Color to draw the background with when selected. + */ + + virtual void addOption(const CNxString &text, const uint32_t value, + const nxwidget_pixel_t normalTextColor, + const nxwidget_pixel_t normalBackColor, + const nxwidget_pixel_t selectedTextColor, + const nxwidget_pixel_t selectedBackColor); + + /** + * Remove an option from the widget by its index. + * + * @param index The index of the option to remove. + */ + + virtual void removeOption(const int index); + + /** + * Remove all options from the widget. + */ + + virtual void removeAllOptions(void); + + /** + * Select an option by its index. Does not deselect any other selected options. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual inline void selectOption(const int index) + { + m_listbox->selectOption(index); + } + + /** + * Select an option by its index. Does not deselect any other selected options. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual inline void deselectOption(const int index) + { + m_listbox->deselectOption(index); + } + + /** + * Select all options. Does nothing if the listbox does not allow multiple selections. + * Redraws the widget and raises a value changed event. + */ + + virtual inline void selectAllOptions(void) + { + m_listbox->selectAllOptions(); + } + + /** + * Deselect all options. + * Redraws the widget and raises a value changed event. + */ + + virtual inline void deselectAllOptions(void) + { + m_listbox->deselectAllOptions(); + } + + /** + * Get the selected index. Returns -1 if nothing is selected. If more than one + * option is selected, the index of the first selected option is returned. + * + * @return The selected index. + */ + + virtual inline const int getSelectedIndex(void) const + { + return m_listbox->getSelectedIndex(); + } + + /** + * Sets the selected index. Specify -1 to select nothing. Resets any + * other selected items to deselected. + * Redraws the widget and raises a value changed event. + * + * @param index The selected index. + */ + + virtual inline void setSelectedIndex(const int index) + { + m_listbox->setSelectedIndex(index); + } + + /** + * Get the selected option. Returns NULL if nothing is selected. + * + * @return The selected option. + */ + + virtual inline const CListBoxDataItem *getSelectedOption(void) const + { + return m_listbox->getSelectedOption(); + } + + /** + * Sets whether multiple selections are possible or not. + * + * @param allowMultipleSelections True to allow multiple selections. + */ + + virtual inline + void setAllowMultipleSelections(const bool allowMultipleSelections) + { + m_listbox->setAllowMultipleSelections(allowMultipleSelections); + } + + /** + * Sets whether multiple selections are possible or not. + * + * @return True if multiple selections are allowed. + */ + + virtual inline const bool allowsMultipleSelections(void) const + { + return m_listbox->allowsMultipleSelections(); + } + + /** + * Resize the scrolling canvas to encompass all options. + */ + + virtual inline void resizeCanvas(void) + { + m_listbox->resizeCanvas(); + } + + /** + * Get the specified option. + * + * @return The specified option. + */ + + virtual inline const CListBoxDataItem *getOption(const int index) + { + return m_listbox->getOption(index); + } + + /** + * Get the selected index. Returns -1 if nothing is selected. + * + * @return The selected index. + */ + + virtual inline const CListBoxDataItem *getOption(const int index) const + { + return m_listbox->getOption(index); + } + + /** + * Sort the options alphabetically by the text of the options. + */ + + virtual inline void sort(void) + { + m_listbox->sort(); + } + + /** + * Get the total number of options. + * + * @return The number of options. + */ + + virtual inline const int getOptionCount(void) const + { + return m_listbox->getOptionCount(); + } + + /** + * Get the height of a single option. + * + * @return The height of an option. + */ + + virtual inline const nxgl_coord_t getOptionHeight(void) const + { + return m_listbox->getOptionHeight(); + } + + /** + * Handles events raised by its sub-widgets. + * + * @param e Event arguments. + */ + + virtual void handleValueChangeEvent(const CWidgetEventArgs &e); + + /** + * Handle a widget action event. + * + * @param e The event data. + */ + + virtual void handleActionEvent(const CWidgetEventArgs &e); + + /** + * Handles events raised by its sub-widgets. + * + * @param e Event arguments. + */ + + virtual void handleScrollEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse button click event. + * + * @param e The event data. + */ + + virtual void handleClickEvent(const CWidgetEventArgs &e); + + /** + * Handles events raised by its sub-widgets. + * + * @param e Event arguments. + */ + + virtual void handleDoubleClickEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse button release event that occurred within the bounds of + * the source widget. + * + * @param e The event data. + */ + + virtual void handleReleaseEvent(const CWidgetEventArgs &e); + + /** + * Handle a mouse button release event that occurred outside the bounds of + * the source widget. + * + * @param e The event data. + */ + + virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e); + + /** + * Set the font used in the textbox. + * + * @param font Pointer to the new font. + */ + + virtual void setFont(CNxFont *font); + + /** + * Sets whether or not items added to the list are automatically + * sorted on insert or not. + * + * @param sortInsertedItems True to enable sort on insertion. + */ + + virtual inline void setSortInsertedItems(const bool sortInsertedItems) + { + m_listbox->setSortInsertedItems(sortInsertedItems); + } + + /** + * Insert the dimensions that this widget wants to have into the rect + * passed in as a parameter. All coordinates are relative to the widget's + * parent. Value is based on the length of the largest string in the + * set of options. + * + * @param rect Reference to a rect to populate with data. + */ + + virtual void getPreferredDimensions(CRect &rect) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLINGLISTBOX_HXX diff --git a/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx b/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx new file mode 100644 index 000000000..90dcc1ac9 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx @@ -0,0 +1,372 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollingpanel.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLINGPANEL_HXX +#define __INCLUDE_CSCROLLINGPANEL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "iscrollable.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Class containing a scrollable region. Responds to mouse movement. Can + * contain sub-widgets which will also be scrolled. + */ + + class CScrollingPanel : public CNxWidget, public IScrollable + { + protected: + CWidgetControl *m_widgetControl; /**< Widget control instance */ + int32_t m_canvasX; /**< X coordinate of the virtual + canvas. */ + int32_t m_canvasY; /**< Y coordinate of the virtual + canvas. */ + int32_t m_canvasWidth; /**< Width of the virtual canvas. */ + int32_t m_canvasHeight; /**< Height of the virtual canvas. */ + bool m_allowVerticalScroll; /**< True if vertical scrolling is + allowed. */ + bool m_allowHorizontalScroll; /**< True if horizontal scrolling is + allowed. */ + bool m_isContentScrolled; /**< True if the content drawn to the + panel is scrolled(ie. everything + drawn in the draw() method); + false if just child objects are scrolled. */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Scrolls the panel to match the drag. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + * @param vX The horizontal drag distance. + * @param vY The vertical drag distance. + */ + + virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Starts the dragging system. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Scroll all child widgets by the specified amounts. Actually uses + * the widget's moveTo() function to reposition them. + * + * @param dx The horizontal distance to scroll. + * @param dy The vertical distance to scroll. + */ + + void scrollChildren(int32_t dx, int32_t dy); + + /** + * Destructor. + */ + + virtual ~CScrollingPanel(void) { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScrollingPanel(const CScrollingPanel &scrollingPanel) + : CNxWidget(scrollingPanel) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + * @param flags The usual widget flags. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScrollingPanel(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + uint32_t flags, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Scroll the panel by the specified amounts. + * + * @param dx The horizontal distance to scroll. + * @param dy The vertical distance to scroll. + */ + + virtual void scroll(int32_t dx, int32_t dy); + + /** + * Reposition the panel's scrolling region to the specified coordinates. + * + * @param x The new x coordinate of the scrolling region. + * @param y The new y coordinate of the scrolling region. + */ + + virtual void jump(int32_t x, int32_t y); + + /** + * Returns true if vertical scrolling is allowed. + * + * @return True if vertical scrolling is allowed. + */ + + inline bool allowsVerticalScroll(void) const + { + return m_allowVerticalScroll; + } + + /** + * Returns true if horizontal scrolling is allowed. + * + * @return True if horizontal scrolling is allowed. + */ + + inline bool allowsHorizontalScroll(void) const + { + return m_allowHorizontalScroll; + } + + /** + * Gets the x coordinate of the virtual canvas. + * + * @return The x coordinate of the virtual canvas. + */ + + virtual inline const int32_t getCanvasX(void) const + { + return m_canvasX; + } + + /** + * Gets the y coordinate of the virtual canvas. + * + * @return The y coordinate of the virtual canvas. + */ + + virtual inline const int32_t getCanvasY(void) const + { + return m_canvasY; + } + + /** + * Gets the width of the virtual canvas. + * + * @return The width of the virtual canvas. + */ + + virtual inline const int32_t getCanvasWidth(void) const + { + return m_canvasWidth; + } + + /** + * Gets the height of the virtual canvas. + * + * @return The height of the virtual canvas. + */ + + virtual inline const int32_t getCanvasHeight(void) const + { + return m_canvasHeight; + } + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + inline void setAllowsVerticalScroll(bool allow) + { + m_allowVerticalScroll = allow; + } + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + inline void setAllowsHorizontalScroll(bool allow) + { + m_allowHorizontalScroll = allow; + } + + /** + * Set whether or not the content of the panel is scrolled. + * Content is anything drawn to the panel in the draw() method. + * This property is disabled by default, which will result in + * faster scrolling of child objects. + * If the panel contains no child objects, just draw() method + * content, consider using a SuperBitmap class instead. + * + * @param scrolled True to enable content scrolling; false to disable it. + */ + + inline void setContentScrolled(bool scrolled) + { + m_isContentScrolled = scrolled; + } + + /** + * Check if the content of the panel, drawn via the draw() method, + * is scrolled. + * + * @return True if the content is scrolled; false if not. + */ + + inline bool IsContentScrolled(void) + { + return m_isContentScrolled; + } + + /** + * Sets the width of the virtual canvas. + * + * @param width The width of the virtual canvas. + */ + + virtual inline void setCanvasWidth(const int32_t width) + { + m_canvasWidth = width; + } + + /** + * Sets the height of the virtual canvas. + * + * @param height The height of the virtual canvas. + */ + + virtual inline void setCanvasHeight(const int32_t height) + { + m_canvasHeight = height; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLINGPANEL_HXX + diff --git a/NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx b/NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx new file mode 100644 index 000000000..0d2a1a39d --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx @@ -0,0 +1,467 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSCROLLINGTEXTBOX_HXX +#define __INCLUDE_CSCROLLINGTEXTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cmultilinetextbox.hxx" +#include "cwidgeteventhandler.hxx" +#include "cwidgetstyle.hxx" +#include "cnxstring.hxx" +#include "iscrollable.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CScrollbarVertical; + class CNxFont; + + /** + * Widget containing a CMultiLineTextBox and a vertical scrollbar. Exposed + * methods are more or less identical to the methods exposed by the + * CMultiLineTextBox to ensure that the two are interchangeable. + */ + + class CScrollingTextBox : public ITextBox, public CNxWidget, + public IScrollable, public CWidgetEventHandler + { + protected: + CMultiLineTextBox *m_texbox; /**< Pointer to the textbox */ + CScrollbarVertical *m_scrollbar; /**< Pointer to the scrollbar */ + uint8_t m_scrollbarWidth; /**< Width of the scrollbar */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Resize the textbox to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CScrollingTextBox(void) { } + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CScrollingTextBox(const CScrollingTextBox& scrollingTextBox) + : CNxWidget(scrollingTextBox) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the text box, relative to its parent. + * @param y The y coordinate of the text box, relative to its parent. + * @param width The width of the textbox. + * @param height The height of the textbox. + * @param text Pointer to a string to display in the textbox. + * @param flags Standard widget flag options. + * @param maxRows The maximum number of rows the textbox can track. Adding + * text beyond this number will cause rows at the start of the text to be + * forgotten; text is essentially stored as a queue, and adding to the back + * of a full queue causes the front items to be popped off. Setting this to + * 0 will make the textbox track only the visible rows. + * @param style The style that the widget should use. If this is not + * specified, the widget will use the values stored in the global + * g_defaultWidgetStyle object. The widget will copy the properties of + * the style into its own internal style object. + */ + + CScrollingTextBox(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const CNxString &text, uint32_t flags, + nxgl_coord_t maxRows = 0, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Set the horizontal alignment of text within the textbox. + * + * @param alignment The horizontal position of the text. + */ + + virtual void setTextAlignmentHoriz(CMultiLineTextBox::TextAlignmentHoriz alignment); + + /** + * Set the vertical alignment of text within the textbox. + * + * @param alignment The vertical position of the text. + */ + + virtual void setTextAlignmentVert(CMultiLineTextBox::TextAlignmentVert alignment); + + /** + * Returns the number of "pages" that the text spans. A page + * is defined as the amount of text that can be displayed within + * the textbox at one time. + * + * @return The page count. + */ + + virtual const uint16_t getPageCount(void) const; + + /** + * Returns the current page. + * + * @return The current page. + * @see getPageCount(). + */ + + virtual const uint16_t getCurrentPage(void) const; + + /** + * Returns a pointer to the Text object that contains the + * wrapped text used in the textbox. It is used as the + * pre-processed data source for the textbox, and should + * not be altered. + * + * @return Pointer to the Text object. + */ + + virtual const CText *getText(void) const; + + /** + * Set the text displayed in the textbox. + * + * @param text String to display. + */ + + virtual void setText(const CNxString &text); + + /** + * Append new text to the end of the current text + * displayed in the textbox. + * + * @param text String to append. + */ + + virtual void appendText(const CNxString &text); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex Index to remove from. + */ + + virtual void removeText(const unsigned int startIndex); + + /** + * Remove specified number of characters from the string from the + * start index onwards. + * + * @param startIndex Index to remove from. + * @param count Number of characters to remove. + */ + + virtual void removeText(const unsigned int startIndex, const unsigned int count); + + /** + * Set the font used in the textbox. + * + * @param font Pointer to the new font. + */ + + virtual void setFont(CNxFont *font); + + /** + * Get the length of the text string. + * + * @return The length of the text string. + */ + + virtual const unsigned int getTextLength(void) const; + + /** + * Sets the cursor display mode. + * + * @param cursorMode Determines cursor display mode + */ + + virtual void showCursor(EShowCursor cursorMode); + + /** + * Shows the cursor in default mode (only when the TextBox has focus). + */ + + inline void showCursor(void) + { + showCursor(SHOW_CURSOR_ONFOCUS); + } + + /** + * Hides the cursor. + */ + + inline void hideCursor(void) + { + showCursor(SHOW_CURSOR_NEVER); + } + + /** + * Enables/disables cursor wrapping + * + * @param wrap True enables cursor wrapping + */ + + virtual void wrapCursor(bool wrap); + + /** + * Move the cursor to the text position specified. 0 indicates the start + * of the string. If position is greater than the length of the string, + * the cursor is moved to the end of the string. + * + * @param position The new cursor position. + */ + + virtual void moveCursorToPosition(const int32_t position); + + /** + * Get the cursor position. This is the index within the string that + * the cursor is currently positioned over. + * + * @return position The cursor position. + */ + + virtual const int32_t getCursorPosition(void) const; + + /** + * Insert text at the specified index. + * + * @param text The text to insert. + * @param index Index at which to insert the text. + */ + + virtual void insertText(const CNxString &text, const unsigned int index); + + /** + * Insert text at the current cursor position. + * + * @param text The text to insert. + */ + + virtual void insertTextAtCursor(const CNxString &text); + + /** + * Handles events raised by its sub-widgets. + * + * @param e Event arguments. + */ + + virtual void handleValueChangeEvent(const CWidgetEventArgs &e); + + /** + * Handles events raised by its sub-widgets. + * + * @param e Event arguments. + */ + + virtual void handleScrollEvent(const CWidgetEventArgs &e); + + /** + * Gets the x coordinate of the virtual canvas. + * + * @return The x coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasX(void) const; + + /** + * Gets the y coordinate of the virtual canvas. + * + * @return The y coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasY(void) const; + + /** + * Gets the width of the virtual canvas. + * + * @return The width of the virtual canvas. + */ + + virtual const int32_t getCanvasWidth(void) const; + + /** + * Gets the height of the virtual canvas. + * + * @return The height of the virtual canvas. + */ + + virtual const int32_t getCanvasHeight(void) const; + + /** + * Scroll the panel by the specified amounts. + * + * @param dx The horizontal distance to scroll. + * @param dy The vertical distance to scroll. + */ + + virtual void scroll(int32_t dx, int32_t dy); + + /** + * Reposition the panel's scrolling region to the specified coordinates. + * + * @param x The new x coordinate of the scrolling region. + * @param y The new y coordinate of the scrolling region. + */ + + virtual void jump(int32_t x, int32_t y); + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsVerticalScroll(bool allow); + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsHorizontalScroll(bool allow); + + /** + * Sets the width of the virtual canvas. + * + * @param width The width of the virtual canvas. + */ + + virtual void setCanvasWidth(const int32_t width); + + /** + * Sets the height of the virtual canvas. + * + * @param height The height of the virtual canvas. + */ + + virtual void setCanvasHeight(const int32_t height); + + /** + * Returns true if vertical scrolling is allowed. + * + * @return True if vertical scrolling is allowed. + */ + + virtual bool allowsVerticalScroll(void) const; + + /** + * Returns true if horizontal scrolling is allowed. + * + * @return True if horizontal scrolling is allowed. + */ + + virtual bool allowsHorizontalScroll(void) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSCROLLINGTEXTBOX_HXX + diff --git a/NxWidgets/libnxwidgets/include/csliderhorizontal.hxx b/NxWidgets/libnxwidgets/include/csliderhorizontal.hxx new file mode 100644 index 000000000..f732a1731 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/csliderhorizontal.hxx @@ -0,0 +1,344 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/csliderhorizontal.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSLIDERHORIZONTAL_HXX +#define __INCLUDE_CSLIDERHORIZONTAL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgeteventhandler.hxx" +#include "islider.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CSliderHorizontalGrip; + class CWidgetControl; + + /** + * Widget providing a sliding "grip" that can be moved left and + * right in the "gutter". Essentially a scrollbar, but more + * generic. + */ + + class CSliderHorizontal : public ISlider, public CNxWidget, public CWidgetEventHandler + { + protected: + CSliderHorizontalGrip *m_grip; /**< Pointer to the grip. */ + nxgl_coord_t m_minimumValue; /**< Minimum value that the grip can represent. */ + nxgl_coord_t m_maximumValue; /**< Maximum value that the grip can represent. */ + int32_t m_value; /**< Current value of the slider. */ + nxgl_coord_t m_minimumGripWidth; /**< Smallest width that the grip can become */ + nxgl_coord_t m_pageSize; /**< Value of a page of data, used when clicking + the gutter. */ + int32_t m_gutterWidth; /**< Width of the gutter, taking into account + any adjustments made to the width of the grip. */ + uint32_t m_contentSize; /**< Number of values in the min/max range. */ + + /** + * Get the maximum possible value that the slider can represent. Useful when + * using the slider as a scrollbar, as the height of the grip prevents the full + * range of values being accessed (intentionally). + * The returned value is bitshfted left 16 places for more accuracy in fixed-point + * calculations. + * + * @return The maximum possible value that the slider can represent. + */ + + int32_t getPhysicalMaximumValueWithBitshift(void) const; + + /** + * Get the value represented by the top of the grip. + * return The value represented by the top of the grip. + */ + + const int32_t getGripValue(void) const; + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Resize the slider to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Moves the grip towards the mouse. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CSliderHorizontal(const CSliderHorizontal& sliderHorizontal) + : CNxWidget(sliderHorizontal) { } + + /** + * Resize and redraw the grip. + */ + + void resizeGrip(void); + + public: + + /** + * Constructor. + * + * @param pWidgetControl The widget control instance for the window. + * @param x The x coordinate of the slider, relative to its parent. + * @param y The y coordinate of the slider, relative to its parent. + * @param width The width of the slider. + * @param height The height of the slider. + */ + + CSliderHorizontal(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CSliderHorizontal(void) { } + + /** + * Get the smallest value that the slider can represent. + * + * @return The smallest value. + */ + + inline const nxgl_coord_t getMinimumValue(void) const + { + return m_minimumValue; + } + + /** + * Get the largest value that the slider can represent. + * + * @return The largest value. + */ + + inline const nxgl_coord_t getMaximumValue(void) const + { + return m_maximumValue; + } + + /** + * Get the current value of the slider. + * + * return The current slider value. + */ + + inline const nxgl_coord_t getValue(void) const + { + return m_value >> 16; + } + + /** + * Get the value represented by the height of the grip. + * For sliders, this would typically be 1 (so each new + * grip position is worth 1). For scrollbars, this + * would be the height of the scrolling widget. + * + * @return The page size. + */ + + inline const nxgl_coord_t getPageSize(void) const + { + return m_pageSize; + } + + /** + * Set the smallest value that the slider can represent. + * + * @param value The smallest value. + */ + + inline void setMinimumValue(const nxgl_coord_t value) + { + m_minimumValue = value; + m_contentSize = m_maximumValue - m_minimumValue + 1; + resizeGrip(); + }; + + /** + * Set the largest value that the slider can represent. + * + * @param value The largest value. + */ + + inline void setMaximumValue(const nxgl_coord_t value) + { + m_maximumValue = value; + m_contentSize = m_maximumValue - m_minimumValue + 1; + resizeGrip(); + }; + + /** + * Set the value that of the slider. This will reposition + * and redraw the grip. + * + * @param value The new value. + */ + + void setValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition and redraw + * the grip. The supplied value should be bitshifted left 16 places. + * This ensures greater accuracy than the standard setValue() method if + * the slider is being used as a scrollbar. + * + * @param value The new value. + */ + + void setValueWithBitshift(const int32_t value); + + /** + * Set the page size represented by the grip. + * + * @param pageSize The page size. + * @see getPageSize(). + */ + + inline void setPageSize(const nxgl_coord_t pageSize) + { + m_pageSize = pageSize; + resizeGrip(); + }; + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleDragEvent(const CWidgetEventArgs &e); + + /** + * Get the smallest value that the slider can move through when + * dragged. + * + * @return The smallest value that the slider can move through when + * dragged. + */ + + nxgl_coord_t getMinimumStep(void) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSLIDERHORIZONTAL_HXX + diff --git a/NxWidgets/libnxwidgets/include/csliderhorizontalgrip.hxx b/NxWidgets/libnxwidgets/include/csliderhorizontalgrip.hxx new file mode 100644 index 000000000..71f10f62c --- /dev/null +++ b/NxWidgets/libnxwidgets/include/csliderhorizontalgrip.hxx @@ -0,0 +1,203 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/csliderhorizontalgrip.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSLIDERHORIZONTALGRIP_HXX +#define __INCLUDE_CSLIDERHORIZONTALGRIP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * Class representing the grip, or draggable button, with a horizontal + * slider. + */ + + class CSliderHorizontalGrip : public CNxWidget + { + protected: + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Starts dragging the grip and redraws it. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the grip. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the grip. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Moves the grip to follow the mouse. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + * @param vX The horizontal distance of the drag. + * @param vY The vertical distance of the drag. + */ + + virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CSliderHorizontalGrip(const CSliderHorizontalGrip &sliderHorizontalGrip) + : CNxWidget(sliderHorizontalGrip) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display + * @param x The x coordinate of the grip, relative to its parent. + * @param y The y coordinate of the grip, relative to its parent. + * @param width The width of the grip. + * @param height The height of the grip. + */ + + CSliderHorizontalGrip(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + + /** + * Destructor. + */ + + virtual inline ~CSliderHorizontalGrip(void) { } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSLIDERHORIZONTALGRIP_HXX + diff --git a/NxWidgets/libnxwidgets/include/cslidervertical.hxx b/NxWidgets/libnxwidgets/include/cslidervertical.hxx new file mode 100644 index 000000000..a1b8651f9 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cslidervertical.hxx @@ -0,0 +1,344 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cslidervertical.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSLIDERVERTICAL_HXX +#define __INCLUDE_CSLIDERVERTICAL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgeteventhandler.hxx" +#include "islider.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CSliderVerticalGrip; + class CWidgetControl; + + /** + * Widget providing a sliding "grip" that can be moved up and + * down the "gutter". Essentially a scrollbar, but more + * generic. + */ + + class CSliderVertical : public ISlider, public CNxWidget, public CWidgetEventHandler + { + protected: + CSliderVerticalGrip* m_grip; /**< Pointer to the grip. */ + nxgl_coord_t m_minimumValue; /**< Minimum value that the grip can represent. */ + nxgl_coord_t m_maximumValue; /**< Maximum value that the grip can represent. */ + int32_t m_value; /**< Current value of the slider. */ + nxgl_coord_t m_minimumGripHeight; /**< Smallest height that the grip can become. */ + nxgl_coord_t m_pageSize; /**< Value of a page of data, used when clicking + the gutter */ + int32_t m_gutterHeight; /**< Height of the gutter, taking into account + any adjustments made to the height of the grip. */ + uint32_t m_contentSize; /**< Number of values in the min/max range. */ + + /** + * Get the maximum possible value that the slider can represent. Useful when + * using the slider as a scrollbar, as the height of the grip prevents the full + * range of values being accessed (intentionally). + * The returned value is bitshfted left 16 places for more accuracy in fixed-point + * calculations. + * + * @return The maximum possible value that the slider can represent. + */ + + int32_t getPhysicalMaximumValueWithBitshift(void) const; + + /** + * Get the value represented by the top of the grip. The value is + * bitshifted left 16 places for accuracy. + * return The value represented by the top of the grip. + */ + + const int32_t getGripValue(void) const; + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Resize the slider to the new dimensions. + * + * @param width The new width. + * @param height The new height. + */ + + virtual void onResize(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Moves the grip towards the mouse. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CSliderVertical(const CSliderVertical &sliderVertical) + : CNxWidget(sliderVertical) { } + + /** + * Resize and redraw the grip. + */ + + void resizeGrip(); + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display + * @param x The x coordinate of the slider, relative to its parent. + * @param y The y coordinate of the slider, relative to its parent. + * @param width The width of the slider. + * @param height The height of the slider. + */ + + CSliderVertical(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CSliderVertical(void) { } + + /** + * Get the smallest value that the slider can represent. + * + * @return The smallest value. + */ + + inline const nxgl_coord_t getMinimumValue(void) const + { + return m_minimumValue; + } + + /** + * Get the largest value that the slider can represent. + * + * @return The largest value. + */ + + inline const nxgl_coord_t getMaximumValue(void) const + { + return m_maximumValue; + } + + /** + * Get the current value of the slider. + * return The current slider value. + */ + + inline const nxgl_coord_t getValue(void) const + { + return m_value >> 16; + } + + /** + * Get the value represented by the height of the grip. + * For sliders, this would typically be 1 (so each new + * grip position is worth 1). For scrollbars, this + * would be the height of the scrolling widget. + * + * @return The page size. + */ + + inline const nxgl_coord_t getPageSize(void) const + { + return m_pageSize; + } + + /** + * Set the smallest value that the slider can represent. + * + * @param value The smallest value. + */ + + inline void setMinimumValue(const nxgl_coord_t value) + { + m_minimumValue = value; + m_contentSize = m_maximumValue - m_minimumValue + 1; + resizeGrip(); + } + + /** + * Set the largest value that the slider can represent. + * + * @param value The largest value. + */ + + inline void setMaximumValue(const nxgl_coord_t value) + { + m_maximumValue = value; + m_contentSize = m_maximumValue - m_minimumValue + 1; + resizeGrip(); + } + + /** + * Set the value that of the slider. This will reposition + * and redraw the grip. + * + * @param value The new value. + */ + + void setValue(const nxgl_coord_t value); + + /** + * Set the value that of the slider. This will reposition and redraw + * the grip. The supplied value should be bitshifted left 16 places. + * This ensures greater accuracy than the standard setValue() method if + * the slider is being used as a scrollbar. + * + * @param value The new value. + */ + + void setValueWithBitshift(const int32_t value); + + /** + * Set the page size represented by the grip. + * + * @param pageSize The page size. + * @see getPageSize(). + */ + + inline void setPageSize(const nxgl_coord_t pageSize) + { + m_pageSize = pageSize; + resizeGrip(); + } + + /** + * Process events fired by the grip. + * + * @param e The event details. + */ + + virtual void handleDragEvent(const CWidgetEventArgs &e); + + /** + * Get the smallest value that the slider can move through when + * dragged. + * + * @return The smallest value that the slider can move through when + * dragged. + */ + + nxgl_coord_t getMinimumStep(void) const; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSLIDERVERTICAL_HXX + diff --git a/NxWidgets/libnxwidgets/include/csliderverticalgrip.hxx b/NxWidgets/libnxwidgets/include/csliderverticalgrip.hxx new file mode 100644 index 000000000..3ac7fb360 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/csliderverticalgrip.hxx @@ -0,0 +1,202 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cslidervertical.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSLIDERVERTICALGRIP_HXX +#define __INCLUDE_CSLIDERVERTICALGRIP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * Class representing the grip, or draggable button, with a vertical + * slider. + */ + + class CSliderVerticalGrip : public CNxWidget + { + protected: + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Starts dragging the grip and redraws it. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the grip. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Redraws the grip. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Moves the grip to follow the mouse. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + * @param vX The horizontal distance of the drag. + * @param vY The vertical distance of the drag. + */ + + virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CSliderVerticalGrip(const CSliderVerticalGrip &sliderVerticalGrip) + : CNxWidget(sliderVerticalGrip) { } + + public: + + /** + * Constructor. + * + * @param pWidgetControl The controlling widget for the display + * @param x The x coordinate of the grip, relative to its parent. + * @param y The y coordinate of the grip, relative to its parent. + * @param width The width of the grip. + * @param height The height of the grip. + */ + + CSliderVerticalGrip(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height); + + /** + * Destructor. + */ + + virtual inline ~CSliderVerticalGrip(void) { } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSLIDERVERTICALGRIP_HXX + diff --git a/NxWidgets/libnxwidgets/include/cstickybutton.hxx b/NxWidgets/libnxwidgets/include/cstickybutton.hxx new file mode 100644 index 000000000..c51976ec0 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cstickybutton.hxx @@ -0,0 +1,237 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cstickybutton.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSTICKYBUTTON_HXX +#define __INCLUDE_CSTICKYBUTTON_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cbutton.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CWidgetControl; + + /** + * CButton that sticks down when clicked. + */ + + class CStickyButton : public CButton + { + protected: + bool m_isStuckDown; /**< True if the key is stuck down */ + + /** + * Draws the outline of the button. + * + * @param port Graphics port to draw to. + */ + + virtual void drawOutline(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Don't redraw on button press events. The button display is + * completely controlled by the externally controlled stuck state. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y) {} + + /** + * Don't redraw on button release events. The button display is + * completely controlled by the externally controlled stuck state. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Don't redraw on button release events. The button display is + * completely controlled by the externally controlled stuck state. + * + * @param x The x coordinate of the mouse. + * @param y The y coordinate of the mouse. + */ + + virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) { } + + /** + * Copy constructor is protected to prevent usage. The button display is + * completely controlled by the externally controlled stuck state. + */ + + inline CStickyButton(const CStickyButton &button) : CButton(button) { } + + public: + + /** + * Constructor for buttons that display a string. + * + * @param pWidgetControl The controlling widget for the display. + * @param x The x coordinate of the button, relative to its parent. + * @param y The y coordinate of the button, relative to its parent. + * @param width The width of the button. + * @param height The height of the button. + * @param text The text for the button to display. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CStickyButton(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + const CNxString &text, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + virtual inline ~CStickyButton(void) { } + + /** + * Sets the key's stuck down state. If this is true, the key has a + * inwards-bevelled border when drawn. If it is false, the key has + * an outwards-bevelled border. + * + * @param stuckDown The new stuck down state. + */ + + void setStuckDown(bool stuckDown); + + /** + * Toggles the key's stuck down state. + */ + + inline void toggleStuckDown(void) + { + setStuckDown(!m_isStuckDown); + } + + /** + * Returns the stuck down state. + * + * @return True is the button is in the stuck down state. + */ + + inline const bool isStuckDown(void) const + { + return m_isStuckDown; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSTICKYBUTTON_HXX diff --git a/NxWidgets/libnxwidgets/include/cstickybuttonarray.hxx b/NxWidgets/libnxwidgets/include/cstickybuttonarray.hxx new file mode 100644 index 000000000..5854c51f0 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cstickybuttonarray.hxx @@ -0,0 +1,174 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cstickybuttonarray.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSTICKYBUTTONARRAY_HXX +#define __INCLUDE_CSTICKYBUTTONARRAY_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cbuttonarray.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CNxString; + + /** + * Manages a two-dimensional array of buttons as one widget. A two- + * dimensional array of buttons might also be called a "keyboard". + */ + + class CStickyButtonArray : public CButtonArray + { + protected: + bool m_isStuckDown; /**< True if one key in the array stuck down */ + bool m_stickDown; /**< True there is a change in a sticky button state */ + uint8_t m_stickyRow; /**< The row index of the stuck button */ + uint8_t m_stickyColumn; /**< The column index of the stuck button */ + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CStickyButtonArray(const CStickyButtonArray &button) : CButtonArray(button) { } + + public: + + /** + * Constructor for an array of sticky buttons. + * + * @param pWidgetControl The widget control for the display. + * @param x The x coordinate of the button array, relative to its parent. + * @param y The y coordinate of the button array, relative to its parent. + * @param buttonColumns The number of buttons in one row of the button array + * @param buttonRows The number of buttons in one column of the button array + * @param buttonWidth The width of one button + * @param buttonHeight The height of one button + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CStickyButtonArray(CWidgetControl *pWidgetControl, + nxgl_coord_t x, nxgl_coord_t y, + uint8_t buttonColumns, uint8_t buttonRows, + nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * CStickyButtonArray Destructor. + */ + + virtual inline ~CStickyButtonArray(void) { } + + /** + * Return the position of the last stuck down button (0,0 will be returned + * the no button has every been stuck down). The button at this position + * is currently stuck down then, in addition, return true. + * + * @param column The location to return the column index of the button + * of interest + * @param row The location to return the row index of the button of + * interest + * @return True if a button in the array is clicked + */ + + virtual bool isAnyButtonStuckDown(int &column, int &row) const; + + /** + * Check if this specific button in the array is stuck down + * + * @param column The column of the button to check. + * @param row The row of the button to check. + * @return True if this button is stuck down + */ + + virtual bool isThisButtonStuckDown(int column, int row) const; + + /** + * Force the button at this position into the stuck down state + * + * @param column The column containing the button to stick down + * @param row The rowtcontaining the button to stick down + * @return False(0) is returned if the indices are out of range. + */ + + virtual bool stickDown(int column, int row); + + /** + * Unstick all buttons + */ + + virtual void unstick(void); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSTICKYBUTTONARRAY_HXX diff --git a/NxWidgets/libnxwidgets/include/cstringiterator.hxx b/NxWidgets/libnxwidgets/include/cstringiterator.hxx new file mode 100644 index 000000000..648d12633 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cstringiterator.hxx @@ -0,0 +1,192 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cstringiterator.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CSTRINGITERATOR_HXX +#define __INCLUDE_CSTRINGITERATOR_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxString; + + /** + * Class used to efficiently iterate over the characters in a CNxString + * object. The CNxString is a Unicode string that uses the fixed-width + * 16-bit encoding to represent its characters. + */ + + class CStringIterator + { + private: + const CNxString *m_pString; /**< String being iterated over. */ + const nxwidget_char_t *m_pCurrentChar; /**< Pointer to the current position of the iterator. */ + int m_currentIndex; /**< Iterator's current index within the string. */ + + public: + + /** + * Constructor. Moves the iterator to the first character in the string. + * + * @param string Pointer to the string that will be iterated over. + */ + + CStringIterator(FAR const CNxString* string); + + /** + * Destructor. + */ + + inline ~CStringIterator(void) { } + + /** + * Moves the iterator to the first character in the string. + * + * @param Returns false if the string is empty + */ + + bool moveToFirst(void); + + /** + * Moves the iterator to the last character in the string. + * + * @param Returns false if the string is empty + */ + + bool moveToLast(void); + + /** + * Move the iterator to the next character in the string. + * + * @return True if the iterator moved; false if not (indicates end of string). + */ + + bool moveToNext(void); + + /** + * Move the iterator to the previous character in the string. + * + * @return True if the iterator moved; false if not (indicates start of string). + */ + + bool moveToPrevious(void); + + /** + * Move the iterator to the specified index. + * + * @param index The index to move to. + * @return True if the iterator moved; false if not (indicates end of string). + */ + + bool moveTo(int index); + + /** + * Get the current position of the iterator within the string. + * + * @return The current character index of the iterator. + */ + + inline int getIndex(void) const + { + return m_currentIndex; + } + + /** + * Get the letter in the string at the iterator's current point. + * + * @return The current character in the string. + */ + + inline nxwidget_char_t getChar(void) const + { + return *m_pCurrentChar; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CSTRINGITERATOR_HXX diff --git a/NxWidgets/libnxwidgets/include/ctext.hxx b/NxWidgets/libnxwidgets/include/ctext.hxx new file mode 100644 index 000000000..8f8ee5783 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ctext.hxx @@ -0,0 +1,386 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ctext.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CTEXT_HXX +#define __INCLUDE_CTEXT_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "nxconfig.hxx" +#include "cnxfont.hxx" +#include "tnxarray.hxx" +#include "cnxstring.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * This class functions as a wrapper around a char array offering + * more advanced functionality - it can wrap text, calculate its + * height in pixels, calculate the width of a row, etc. + */ + + class CText : public CNxString + { + private: + + /** + * Struct defining the position and length of a longest line within + * the m_linePositions array. + */ + + typedef struct + { + int index; + uint8_t width; + } LongestLine; + + CNxFont *m_font; /**< Font to be used for output */ + TNxArray m_linePositions; /**< Array containing start indexes + of each wrapped line */ + TNxArray m_longestLines; /**< Array containing data describing + successively longer wrapped + lines */ + uint8_t m_lineSpacing; /**< Spacing between lines of text */ + int32_t m_textPixelHeight; /**< Total height of the wrapped + text in pixels */ + uint8_t m_textPixelWidth; /**< Total width of the wrapped text + in pixels */ + nxgl_coord_t m_width; /**< Width in pixels available t + the text */ + + public: + + /** + * Constructor. + * + * @param font The font to use for this text object. + * @param text A string that this text object should wrap around. + * @param width The pixel width at which the text should wrap. + */ + + CText(CNxFont *font, const CNxString &text, nxgl_coord_t width); + + /** + * Set the text in the string. + * + * @param text Char array to use as the new data for this string. + */ + + virtual void setText(const CNxString &text); + + /** + * Set the text in the string. + * + * @param text Char array to use as the new data for this string. + */ + + virtual void setText(FAR const char *text); + + /** + * Set the text in the string. + * + * @param text Character to to use as the new data for this string. + */ + + virtual void setText(const nxwidget_char_t text); + + /** + * Append text to the end of the string. + * + * @param text String to append. + */ + + virtual void append(const CNxString &text); + + /** + * Insert text at the specified character index. + * + * @param text The text to insert. + * @param index The char index to insert at. + */ + + virtual void insert(const CNxString &text, const int index); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex The char index to start removing from. + */ + + virtual void remove(const int startIndex); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex The char index to start removing from. + * @param count The number of chars to remove. + */ + + virtual void remove(const int startIndex, const int count); + + /** + * Set the vertical spacing between rows of text. + * + * @param lineSpacing The line spacing. + */ + + void setLineSpacing(uint8_t lineSpacing); + + /** + * Sets the pixel width of the text; text wider than + * this will automatically wrap. + * + * @param width Maximum pixel width of the text. + */ + + void setWidth(nxgl_coord_t width); + + /** + * Set the font to use. + * + * @param font Pointer to the new font. + */ + + void setFont(CNxFont *font); + + /** + * Get the number of characters in the specified line number. + * + * @param lineNumber The line number to check. + * @return The number of characters in the line. + */ + + const int getLineLength(const int lineNumber) const; + + /** + * Get the number of characters in the specified line number, + * ignoring any trailing blank characters. + * + * @param lineNumber The line number to check. + * @return The number of characters in the line. + */ + + const int getLineTrimmedLength(const int lineNumber) const; + + /** + * Get the width in pixels of the specified line number. + * + * @param lineNumber The line number to check. + * @return The pixel width of the line. + */ + + const nxgl_coord_t getLinePixelLength(const int lineNumber) const; + + /** + * Get the width in pixels of the specified line number, + * ignoring any trailing blank characters. + * + * @param lineNumber The line number to check. + * @return The pixel width of the line. + */ + + const nxgl_coord_t getLineTrimmedPixelLength(const int lineNumber) const; + + /** + * Get the total height of the text in pixels. + * + * @return The total height of the text. + */ + + inline const int32_t getPixelHeight(void) const + { + return m_textPixelHeight; + } + + /** + * Get the width of the longest line in pixels. + * + * @return The width of the longest line. + */ + + inline const uint8_t getPixelWidth(void) const + { + return m_textPixelWidth; + } + + /** + * Get the pixel spacing between each line of text. + * + * @return The line spacing. + */ + + inline const uint8_t getLineSpacing(void) const + { + return m_lineSpacing; + } + + /** + * Get the height in pixels of a line, given as the + * height of the font plus the line spacing. + * + * @return The height of a line. + */ + + inline const uint8_t getLineHeight(void) const + { + return m_font->getHeight() + m_lineSpacing; + } + + /** + * Get the total number of lines in the text. + * + * @return The line count. + */ + + inline const int getLineCount(void) const + { + return m_linePositions.size() - 1; + } + + /** + * Get a pointer to the CText object's font. + * + * @return Pointer to the font. + */ + + CNxFont *getFont(void) const; + + /** + * Removes lines of text from the start of the text buffer. + * + * @param lines Number of lines to remove + */ + + void stripTopLines(const int lines); + + /** + * Wrap all of the text. + */ + + void wrap(void); + + /** + * Wrap the text from the line containing the specified char index onwards. + * + * @param charIndex The index of the char to start wrapping from; note + * that the wrapping function will re-wrap that entire line of text. + */ + + void wrap(int charIndex); + + /** + * Get the index of the line of text that contains the specified index + * within the raw char array. + * + * @param index The index to locate within the wrapped lines of text. + * @return The number of the line of wrapped text that contains the + * specified index. + */ + + const int getLineContainingCharIndex(const int index) const; + + /** + * Gets the index within the char array that represents the start of the line of + * text indicated by the line parameter. + * + * @param line The line number to locate within the char array. + * @return The index within the char array of the start of the supplied line. + */ + + const int getLineStartIndex(const int line) const + { + return m_linePositions[line]; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CTEXT_HXX + diff --git a/NxWidgets/libnxwidgets/include/ctextbox.hxx b/NxWidgets/libnxwidgets/include/ctextbox.hxx new file mode 100644 index 000000000..32a0ab69f --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ctextbox.hxx @@ -0,0 +1,375 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ctextbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CTEXTBOX_HXX +#define __INCLUDE_CTEXTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "clabel.hxx" +#include "cnxstring.hxx" +#include "cwidgetstyle.hxx" +#include "cwidgeteventargs.hxx" +#include "itextbox.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references. + */ + + class CWidgetControl; + class CNxTimer; + class CNxString; + + /** + * Single-line textbox widget. Can align text both vertically and + * horizontally in different ways. The widget gains this functionality by + * inheriting from the CLabel class. However, if the amount of text exceeds + * the dimensions of the widget, the widget will ignore its horizontal + * alignment settings and switch to left-aligned instead. This ensures that + * moving the cursor over the text will scroll through it correctly. + */ + + class CTextBox : public ITextBox, public CLabel, public CWidgetEventHandler + { + protected: + int m_cursorPos; /**< Position of the cursor within the string. */ + uint8_t m_showCursor; /**< Controls cursor visibility. */ + bool m_wrapCursor; /**< True wrap cursor at the ends of the text */ + + /** + * Redraws the widget + */ + + inline void onBlur(void); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawContents(CGraphicsPort *port); + + /** + * Moves the cursor without redrawing. + * + * @param position New cursor position. + * @return True if the cursor position changed + */ + + virtual bool repositionCursor(const int position); + + /** + * Move the cursor to the specified coordinates. The coordinates + * are expected to be the result of a click, and therefore in + * world-space rather than widget-space. + */ + + void moveCursorToClickLocation(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw() + */ + + virtual void drawBorder(CGraphicsPort *port); + + /** + * Moves the cursor to the clicked coordinates. + * + * @param x The x coordinates of the click. + * @param y The y coordinates of the click. + */ + + virtual void onClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Does nothing. + * + * @param x The x coordinates of the click. + * @param y The y coordinates of the click. + */ + + virtual void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Return true if the cursor is visible + */ + + virtual bool isCursorVisible(void) const; + + /** + * Get the x coordinate of the cursor in pixels relative + * to the left-hand edge of the client rect. + * + * @return The x coordinate of the cursor in pixels. + */ + + virtual const nxgl_coord_t getCursorXPos(void) const; + + /** + * Get the width of the cursor in pixels. + * + * @return The width of the cursor in pixels. + */ + + virtual nxgl_coord_t getCursorWidth(void) const; + + /** + * Calculate the horizontal position of the string based on its length + * and the alignment options. Alignment options are overridden if the + * width of the string exceeds the width of the textbox. + */ + + virtual void calculateTextPositionHorizontal(void); + + /** + * Copy constructor is protected to prevent usage. + */ + + inline CTextBox(const CTextBox& textbox) : CLabel(textbox) { }; + + public: + + /** + * Constructor for a textbox containing a string. + * + * @param pWidgetControl The controlling widget for the window + * @param x The x coordinate of the text box, relative to its parent. + * @param y The y coordinate of the text box, relative to its parent. + * @param width The width of the textbox. + * @param height The height of the textbox. + * @param text Pointer to a string to display in the textbox. + * @param style The style that the button should use. If this is not + * specified, the button will use the global default widget + * style. + */ + + CTextBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, + CWidgetStyle *style = (CWidgetStyle *)NULL); + + /** + * Sets the cursor display mode. + * + * @param cursorMode Determines cursor display mode + */ + + virtual void showCursor(EShowCursor cursorMode); + + /** + * Shows the cursor in default mode (only when the TextBox has focus). + */ + + virtual inline void showCursor(void) + { + showCursor(SHOW_CURSOR_ONFOCUS); + } + + /** + * Hides the cursor. + */ + + virtual inline void hideCursor(void) + { + showCursor(SHOW_CURSOR_NEVER); + } + + /** + * Enables/disables cursor wrapping + * + * @param wrap True enables cursor wrapping + */ + + virtual inline void wrapCursor(bool wrap) + { + m_wrapCursor = wrap; + } + + /** + * Set the text displayed in the label. + * + * @param text String to display. + */ + + virtual void setText(const CNxString &text); + + /** + * Append new text to the end of the current text displayed in the + * label. + * + * @param text String to append. + */ + + virtual void appendText(const CNxString &text); + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex Index to remove from. + */ + + virtual void removeText(const unsigned int startIndex); + + /** + * Remove specified number of characters from the string from the + * start index onwards. + * + * @param startIndex Index to remove from. + * @param count Number of characters to remove. + */ + + virtual void removeText(const unsigned int startIndex, const unsigned int count); + + /** + * Insert text at the specified index. + * + * @param text The text to insert. + * @param index Index at which to insert the text. + */ + + virtual void insertText(const CNxString &text, const unsigned int index); + + /** + * Insert text at the current cursor position. + * + * @param text The text to insert. + */ + + virtual void insertTextAtCursor(const CNxString &text); + + /** + * Move the cursor to the text position specified. 0 indicates the + * start of the string. If position is greater than the length of the + * string, the cursor is moved to the end of the string. + * + * @param position The new cursor position. + */ + + virtual void moveCursorToPosition(const int position); + + /** + * Get the cursor position. This is the index within the string that + * the cursor is currently positioned over. + * + * @return position The cursor position. + */ + + virtual inline const int getCursorPosition(void) const + { + return m_cursorPos; + } + + /** + * Handle a keyboard press event. Replaces CWidgetEventHandler method. + * + * @param e The event data. + */ + + void handleKeyPressEvent(const CWidgetEventArgs &e); + + /** + * Handle a cursor control event. Replaces CWidgetEventHandler method. + * + * @param e The event data. + */ + + void handleCursorControlEvent(const CWidgetEventArgs &e); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CTEXTBOX_HXX diff --git a/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx new file mode 100644 index 000000000..9fedd4618 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx @@ -0,0 +1,641 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CWIDGETCONTROLT_HXX +#define __INCLUDE_CWIDGETCONTROLT_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "nxconfig.hxx" +#include "cgraphicsport.hxx" +#include "cnxwidget.hxx" +#include "crect.hxx" +#include "cwidgetstyle.hxx" +#include "tnxarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class INxWindow; + class CNxWidget; + + /** + * Class providing a top-level widget and an interface to the CWidgetControl + * widget hierarchy. + * + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class CWidgetControl + { + protected: + /** + * Structure holding the status of the Mouse or Touchscreen. There must + * be one instance of this structure per window instance. The + * content of this structure is update by the CGraphicsPort on each + * NX mouse callback + */ + + struct SMouse + { +#if 0 // Center and right buttons are not used + uint16_t leftPressed : 1; /**< Left button pressed (or + touchscreen contact) */ + uint16_t centerPressed : 1; /**< Center button pressed (not + used with touchscreen) */ + uint16_t rightPressed : 1; /**< Right button pressed (not + used with touchscreen) */ + uint16_t leftHeld : 1; /**< Left button held down (or + touchscreen contact) */ + uint16_t centerHeld : 1; /**< Center button held down + (not used with touchscreen) */ + uint16_t rightHeld : 1; /**< Right button held down + (not used with touchscreen) */ + uint16_t leftDrag : 1; /**< Left button held down (or + touchscreen contact) */ + uint16_t centerDrag : 1; /**< Center button held down (or + touchscreen contact) */ + uint16_t rightDrag : 1; /**< Right button held down (or + touchscreen contact) */ + uint16_t leftReleased : 1; /**< Left button release (or + loss of touchscreen contact) */ + uint16_t centerReleased : 1; /**< Center button release (or + loss of touchscreen contact) */ + uint16_t rightReleased : 1; /**< Right button release (or + loss of touchscreen contact) */ + uint16_t doubleClick : 1; /**< Left button double click */ + uint16_t unused : 3; /**< Padding bits */ +#else + uint8_t leftPressed : 1; /**< Left button pressed (or + touchscreen contact) */ + uint8_t leftHeld : 1; /**< Left button held down (or + touchscreen contact) */ + uint8_t leftDrag : 1; /**< Left button held down (or + touchscreen contact) */ + uint8_t leftReleased : 1; /**< Left button release (or + loss of touchscreen contact) */ + uint8_t doubleClick : 1; /**< Left button double click */ + uint8_t unused : 3; /**< Padding bits */ +#endif + nxgl_coord_t x; /**< Current X coordinate of + the mouse/touch */ + nxgl_coord_t y; /**< Current Y coordinate of + the mouse/touch */ + nxgl_coord_t lastX; /**< X coordinate of the mouse + at the previous poll */ + nxgl_coord_t lastY; /**< Y coordinate of the mouse + at the previous poll */ + struct timespec leftPressTime; /**< Time the left button was + pressed */ + struct timespec leftReleaseTime; /**< Time the left button was + released */ + }; + + /** + * State data + */ + + CGraphicsPort *m_port; /**< The graphics port + that is used for + drawing on this window */ + TNxArray m_deleteQueue; /**< Array of widgets + awaiting deletion. */ + TNxArray m_widgets; /**< List of controlled + widgets. */ + bool m_modal; /**< True: in modal loop */ + sem_t m_modalsem; /**< Modal loops waits for + events on this semaphore */ + /** + * I/O + */ + + struct SMouse m_mouse; /**< Current pointer + device state */ + CNxWidget *m_clickedWidget; /**< Pointer to the widget + that is clicked. */ + CNxWidget *m_focusedWidget; /**< Pointer to the widget + that received keyboard + input. */ + uint8_t m_kbdbuf[CONFIG_NXWIDGETS_KBDBUFFER_SIZE]; + uint8_t m_nCh; /**< Number of buffered + keyboard characters */ + uint8_t m_controls[CONFIG_NXWIDGETS_CURSORCONTROL_SIZE]; + uint8_t m_nCc; /**< Number of buffered + cursor controls */ + /** + * The following were picked off from the position callback. + */ + + NXHANDLE m_hWindow; /**< Handle to the NX window */ + struct nxgl_size_s m_size; /**< Size of the window */ + struct nxgl_point_s m_pos; /**< Position in display space */ + struct nxgl_rect_s m_bounds; /**< Size of the display */ + + /** + * Style + */ + + CWidgetStyle m_style; /**< Default style used by all + widgets in the window. */ + + /** + * Copy a widget style + * + * @param dest The destination style + * @param src The source to use + */ + + void copyWidgetStyle(CWidgetStyle *dest, const CWidgetStyle *src); + + /** + * Return the elapsed time in millisconds + * + * @param startTime A time in the past from which to compute the elapsed time. + * @return The elapsed time since startTime + */ + + uint32_t elapsedTime(FAR const struct timespec *startTime); + + /** + * Pass clicks to the widget hierarchy. Closes the context menu if + * the clicked widget is not the context menu. If a single widget + * is supplied, only that widget is sent the click. That widget + * should be running modally. + * + * @param x Click xcoordinate. + * @param y Click ycoordinate. + * @param widget Pointer to a modally-running widget or NULL. + */ + + void handleLeftClick(nxgl_coord_t x, nxgl_coord_t y, CNxWidget* widget); + + /** + * Get the index of the specified controlled widget. + * + * @param widget The widget to get the index of. + * @return The index of the widget. -1 if the widget is not found. + */ + + const int getWidgetIndex(const CNxWidget *widget) const; + + /** + * Delete any widgets in the deletion queue. + */ + + void processDeleteQueue(void); + + /** + * Process mouse/touchscreen events and send throughout the hierarchy. + * + * @param widget to process, used for modal widgets; omit this parameter + * to run the whole system. + * @return True means a mouse event occurred + */ + + bool pollMouseEvents(CNxWidget* widget); + + /** + * Process keypad events and send throughout the hierarchy. + * + * @return True means a keyboard event occurred + */ + + bool pollKeyboardEvents(void); + + /** + * Process cursor control events and send throughout the hierarchy. + * + * @return True means a cursor control event was processes + */ + + bool pollCursorControlEvents(void); + + /** + * Wake up the modal loop + */ + + void wakeupModalLoop(void); + + /** + * Clear all mouse events + */ + + void clearMouseEvents(void); + + public: + + /** + * Constructor + * + * @param style The default style that all widgets on this display + * should use. If this is not specified, the widget will use the + * values stored in the defaultCWidgetStyle object. + */ + + CWidgetControl(FAR const CWidgetStyle *style = (const CWidgetStyle *)NULL); + + /** + * Destructor. + */ + + ~CWidgetControl(void); + + /** + * Run the widget modally. This will run the CWidgetControl + * application until stopModal() is called. + */ + + void goModal(void); + + /** + * Wait for an interesting modal event to occur (like a mouse or keyboard event) + */ + + void waitForModalEvent(void); + + /** + * Is the widget modal? Only true if the Widget singleton is also modal. + * + * @return True if the widget is modal. + */ + + inline const bool isModal(void) const + { + return m_modal; + } + + /** + * Stop the widget running modally. + */ + + void stopModal(void); + + /** + * Run all code that needs to take place on a periodic basis. + * This is normally called from and is the main body of goModal() + * with widget == NULL. + * + * @param widget Sub-widget to run, used for modal widgets; omit + * this parameter to run the whole system. + * @return True means some interesting event occurred + */ + + bool pollEvents(CNxWidget *widget = (CNxWidget *)NULL); + + /** + * Swaps the depth of the supplied widget. + * This function presumes that all child widgets are screens. + * + * @param widget The widget to be depth-swapped. + * @return True if the depth swap occurred. + */ + + bool swapWidgetDepth(CNxWidget *widget); + + /** + * Redraws any dirty regions within the supplied region. + * + * @param rect The region to redraw + */ + + void eraseRect(CRect rect); + + /** + * Add another widget to be managed by this control instance + * + * @param widget The widget to be controlled. + */ + + inline void addControlledWidget(CNxWidget* widget) + { + m_widgets.push_back(widget); + } + + /** + * Remove a controlled widget + * + * @param widget The widget to be removed + */ + + void removeControlledWidget(CNxWidget* widget); + + /** + * Get the number of controlled widgets. + * + * @return The number of child widgets belonging to this widget. + */ + + inline const int getControlledWidgetCount(void) const + { + return m_widgets.size(); + } + + /** + * Add a widget to the list of widgets to be deleted. + * Must never be called by anything other than the framework itself. + * + * @param widget The widget to add to the delete queue. + */ + + void addToDeleteQueue(CNxWidget *widget); + + /** + * Set the clicked widget pointer. Note that this should not be + * called by code other than within the CWidgetControl library itself. + * + * @param widget The new clicked widget. + */ + + void setClickedWidget(CNxWidget *widget); + + /** + * Get the clicked widget pointer. + * + * @return Pointer to the clicked widget. + */ + + inline CNxWidget *getClickedWidget(void) + { + return m_clickedWidget; + } + + /** + * Set the focused widget that will receive keyboard input. + * + * @param widget The new focused widget. + */ + + void setFocusedWidget(CNxWidget *widget); + + /** + * Reset the focused widget so that it will no longer receive keyboard input. + * + * @param widget The new focused widget. + */ + + void clearFocusedWidget(CNxWidget *widget) + { + if (widget == m_focusedWidget) + { + m_focusedWidget = (CNxWidget *)NULL; + } + } + + /** + * Get the focused widget pointer. + * + * @return Pointer to the focused widget. + */ + + inline CNxWidget *getFocusedWidget(void) + { + return m_focusedWidget; + } + + /** + * Check for the occurrence of a double click. + * + * @return Pointer to the clicked widget. + */ + + inline bool doubleClick(void) + { + return (bool)m_mouse.doubleClick; + } + + /** + * Get the default widget style for this window. + * + * @return Pointer to the clicked widget. + */ + + inline void getWidgetStyle(CWidgetStyle *style) + { + copyWidgetStyle(style, &m_style); + } + + /** + * These remaining methods are used by the CCallback instance to + * provide notifications of certain events. + */ + + /** + * This event will occur when the position or size of the underlying + * window occurs. + * + * @param hWindow The window handle that should be used to communicate + * with the window + * @param pos The position of the window in the physical device space. + * @param size The size of the window. + * @param bounds The size of the underlying display (pixels x rows) + */ + + void geometryEvent(NXHANDLE hWindow, + const struct nxgl_size_s *size, + const struct nxgl_point_s *pos, + const struct nxgl_rect_s *bounds); + + /** + * This event will occur when the a portion of the window that was + * previously obscured is now exposed. + * + * @param nxRect The region in the window that must be redrawn. + * @param more True means that more re-draw requests will follow + */ + + void redrawEvent(FAR const struct nxgl_rect_s *nxRect, bool more); + + /** + * This event means that new mouse data is available for the window. + * + * @param pPos The (x,y) position of the mouse. + * @param buttons See NX_MOUSE_* definitions. + */ + + void newMouseEvent(FAR const struct nxgl_point_s *pPos, uint8_t buttons); + + /** + * This event means that keyboard/keypad data is available for the window. + * + * @param nCh The number of characters that are available in pStr[]. + * @param pStr The array of characters. + */ + + void newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr); + + /** + * This event means that cursor control data is available for the window. + * + * @param cursorControl The cursor control code received. + */ + + void newCursorControlEvent(ECursorControl cursorControl); + + /** + * Get the window handle reported on the first position callback. + * + * @return This function returns the window handle. + */ + + inline NXHANDLE getWindowHandle(void) + { + return m_hWindow; + } + + /** + * Get the window bounding box in physical display coordinated. + * + * @return This function returns the window handle. + */ + + inline CRect getWindowBoundingBox(void) + { + return CRect(&m_bounds); + } + + /** + * Get the position of the window (as reported by the last NX callback). + * + * @return The position. + */ + + inline bool getWindowPosition(FAR struct nxgl_point_s *pPos) + { + pPos->x = m_pos.x; + pPos->x = m_pos.y; + return true; + } + + /** + * Get the size of the window (as reported by the last NX callback). + * + * @return The size. + */ + + inline bool getWindowSize(FAR struct nxgl_size_s *pSize) + { + pSize->h = m_size.h; + pSize->w = m_size.w; + return true; + } + + /** + * Get the width of the window (as reported by the last NX callback). + * + * @return The size. + */ + + inline nxgl_coord_t getWindowWidth(void) + { + return m_size.w; + } + + /** + * Get the height of the window (as reported by the last NX callback). + * + * @return The size. + */ + + inline nxgl_coord_t getWindowHeight(void) + { + return m_size.h; + } + + /** + * The creation sequence is: + * + * 1) Create a dumb CWigetControl instance + * 2) Pass the dumb CWidgetControl instance to the window constructor + * that inherits from INxWindow. + * 3) The call this method with the static_cast to INxWindow to, + * finally, create the CGraphicsPort for this window. + * 4) After that, the fully smartend CWidgetControl instance can + * be used to generate additional widgets. + * + * @param window The instance of INxWindow needed to construct the + * CGraphicsPort instance + */ + + inline bool createGraphicsPort(INxWindow *window) + { + m_port = new CGraphicsPort(window); + return m_port != (CGraphicsPort *)NULL; + } + + /** + * Get the CGraphicsPort instance for drawing on this window + */ + + inline CGraphicsPort *getGraphicsPort(void) + { + return m_port; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CWIDGETCONTROLT_HXX diff --git a/NxWidgets/libnxwidgets/include/cwidgeteventargs.hxx b/NxWidgets/libnxwidgets/include/cwidgeteventargs.hxx new file mode 100644 index 000000000..9aacafa74 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cwidgeteventargs.hxx @@ -0,0 +1,237 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cwidgeteventargs.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CWIDGETEVENTARGS_HXX +#define __INCLUDE_CWIDGETEVENTARGS_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nxconfig.hxx" +#include "teventargs.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Interesting Key events ***************************************************/ + +#define KEY_CODE_NONE ((nxwidget_char_t)0x00) /**< No key (NUL) */ +#define KEY_CODE_BACKSPACE ((nxwidget_char_t)0x08) /**< Backspace key */ +#define KEY_CODE_DELETE ((nxwidget_char_t)0x7f) /**< Delete key */ +#define KEY_CODE_ENTER ((nxwidget_char_t)0x0d) /**< Enter key (carriage return) */ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxWidget; + + /** + * Cursor control events + */ + + typedef enum + { + CURSOR_HOME = 1, // Set the cursor to the beginning + CURSOR_END, // Set the cursor to the end + CURSOR_UP, // Set the cursor up one row + CURSOR_DOWN, // Set the cursor down one row + CURSOR_LEFT, // Move the cursor left one column + CURSOR_RIGHT, // Move the cursor right one column + CURSOR_PAGEUP, // Move the cursor up one page + CURSOR_PAGEDOWN, // Move the cursor down one page + } ECursorControl; + + /** + * Event arguments passed to listeners when a CNxWidget object raises an event. + */ + + class CWidgetEventArgs : public TEventArgs + { + private: + nxgl_coord_t m_x; /**< X coordinateinate of the event. */ + nxgl_coord_t m_y; /**< Y coordinateinate of the event. */ + nxgl_coord_t m_vX; /**< X distance moved during event, for dragging. */ + nxgl_coord_t m_vY; /**< Y distance moved during event, for dragging. */ + nxwidget_char_t m_key; /**< The key code / cursor code that raised the event. */ + + public: + + /** + * Constructor. + * + * @param source Pointer to the CNxWidget object that raised the event. + * @param x The x coordinate of the event. + * @param y The y coordinate of the event. + * @param vX The x distance of the event. + * @param vY The y distance of the event. + * @param keyCode The keycode of the event. + */ + + 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) + : TEventArgs(source) + { + m_x = x; + m_y = y; + m_vX = vX; + m_vY = vY; + m_key = key; + } + + /** + * Get the x coordinate of the mouse event. Applies only to the following + * events: mouse click, mouse double click, mouse drag, mouse release + * + * @return The x coordinate of the event. + */ + + inline const nxgl_coord_t getX(void) const + { + return m_x; + } + + /** + * Get the y coordinate of the mouse event. Applies only to the following + * events: mouse click, mouse double click, mouse drag, mouse release + * + * @return The y coordinate of the event. + */ + + inline const nxgl_coord_t getY(void) const + { + return m_y; + } + + /** + * Get the x-axis mouse move distance of the mouse event. Applies + * only to the mouse drag event. + * + * @return The x-axis mouse move distance of the event. + */ + + inline const nxgl_coord_t getVX(void) const + { + return m_vX; + } + + /** + * Get the y-axis mouse move distance of the event. Applies + * only to the mouse drag event. + * + * @return The y-axis mouse move distance of the event. + */ + + inline const nxgl_coord_t getVY(void) const + { + return m_vY; + } + + /** + * Get the key press that generated the event. Applies only to + * the key press event. + * + * @return The key that generated the event. + */ + + inline const nxwidget_char_t getKey(void) const + { + return m_key; + } + + /** + * Get the cursor control that generated the event. Applies only + * to the curso control event. + * + * @return The cursor control that generated the event. + */ + + inline const ECursorControl getCursorControl(void) const + { + return (ECursorControl)m_key; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CWIDGETEVENTARGS_HXX diff --git a/NxWidgets/libnxwidgets/include/cwidgeteventhandler.hxx b/NxWidgets/libnxwidgets/include/cwidgeteventhandler.hxx new file mode 100644 index 000000000..965b29f0f --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cwidgeteventhandler.hxx @@ -0,0 +1,316 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cwidgeteventhandler.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CWIDGETEVENTHANDLER_HXX +#define __INCLUDE_CWIDGETEVENTHANDLER_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "cwidgeteventargs.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxWidget; + + /** + * Base CWidgetEventHandler class, intended to be subclassed. Any class that + * needs to listen for widget events should inherit from this class. + */ + + class CWidgetEventHandler + { + public: + /** + * Constructor. + */ + + inline CWidgetEventHandler() { } + + /** + * Destructor. + */ + + virtual inline ~CWidgetEventHandler() { } + + /** + * Handle a mouse button click event. + * + * @param e The event data. + */ + + virtual void handleClickEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a mouse button drag event. + * + * @param e The event data. + */ + + virtual void handleDragEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a drop event, triggered when the widget has been dragged-and-dropped. + * + * @param e The event data. + */ + + virtual void handleDropEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a mouse button release event that occurred within the bounds of + * the source widget. + * + * @param e The event data. + */ + + virtual void handleReleaseEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a mouse button release event that occurred outside the bounds of + * the source widget. + * + * @param e The event data. + */ + + virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a key press event. + * + * @param e The event data. + */ + + virtual void handleKeyPressEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a cursor control event. + * + * @param e The event data. + */ + + virtual void handleCursorControlEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a key repeat event. + * + * @param e The event data. + */ + + virtual void handleFocusEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget blur event. + * + * @param e The event data. + */ + + virtual void handleBlurEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget close event. + * + * @param e The event data. + */ + + virtual void handleCloseEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget hide event. + * + * @param e The event data. + */ + + virtual void handleHideEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget show event. + * + * @param e The event data. + */ + + virtual void handleShowEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget enable event. + * + * @param e The event data. + */ + + virtual void handleEnableEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget disable event. + * + * @param e The event data. + */ + + virtual void handleDisableEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget value change event. + * + * @param e The event data. + */ + + virtual void handleValueChangeEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget resize event. + * + * @param e The event data. + */ + + virtual void handleResizeEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget move event. + * + * @param e The event data. + */ + + virtual void handleMoveEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget scroll event. + * + * @param e The event data. + */ + + virtual void handleScrollEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget double-click event. + * + * @param e The event data. + */ + + virtual void handleDoubleClickEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget shelve event. + * + * @param e The event data. + */ + + virtual void handleShelveEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget unshelve event. + * + * @param e The event data. + */ + + virtual void handleUnshelveEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget action event. + * + * @param e The event data. + */ + + virtual void handleActionEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget move forward event. + * + * @param e The event data. + */ + + virtual void handleMoveForwardEvent(const CWidgetEventArgs &e) { } + + /** + * Handle a widget move backward event. + * + * @param e The event data. + */ + + virtual void handleMoveBackwardEvent(const CWidgetEventArgs &e) { } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CWIDGETEVENTHANDLER_HXX diff --git a/NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx b/NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx new file mode 100644 index 000000000..45e304554 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx @@ -0,0 +1,382 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cwidgeteventhandlerlist.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX +#define __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cwidgeteventhandler.hxx" +#include "tnxarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxWidget; + class CListDataItem; + + /** + * List of widget event handlers. + */ + class CWidgetEventHandlerList + { + protected: + TNxArray m_widgetEventHandlers; /**< List of event handlers */ + CNxWidget *m_widget; /**< Owning widget */ + bool m_isEnabled; /**< Indicates if events are active */ + + public: + + /** + * Constructor. + * + * @param widget The owning widget. + */ + + CWidgetEventHandlerList(CNxWidget *widget); + + /** + * Destructor. + */ + + ~CWidgetEventHandlerList(void) { } + + /** + * Check if the object raises events or not. + * + * @return True if events are enabled. + */ + + const bool isEnabled(void) const; + + /** + * Get the event handler at the specified index. + * + * @param index The index of the event handler. + * @return The event handler at the specified index. + */ + + inline CWidgetEventHandler *at(const int index) const + { + return m_widgetEventHandlers.at(index); + } + + /** + * Get the size of the array. + * + * @return The size of the array. + */ + + inline const nxgl_coord_t size(void) const + { + return m_widgetEventHandlers.size(); + } + + /** + * Adds a widget event handler. The event handler will receive + * all events raised by this object. + * @param eventHandler A pointer to the event handler. + */ + + void addWidgetEventHandler(CWidgetEventHandler *eventHandler); + + /** + * Remove a widget event handler. + * + * @param eventHandler A pointer to the event handler to remove. + */ + + void removeWidgetEventHandler(CWidgetEventHandler *eventHandler); + + /** + * Enables event raising. + */ + + inline void enable(void) + { + m_isEnabled = true; + } + + /** + * Disables event raising. + */ + + inline void disable(void) + { + m_isEnabled = false; + } + + /** + * Raise a click event to the event handler. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + void raiseClickEvent(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raise a double-click event to the event handler. + * + * @param x The x coordinate of the click. + * @param y The y coordinate of the click. + */ + + void raiseDoubleClickEvent(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raise a mouse release event to the event handler. + * + * @param x The x coordinate of the release. + * @param y The y coordinate of the release. + */ + + void raiseReleaseEvent(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raise a mouse release-outside event to the event handler. + * + * @param x The x coordinate of the release. + * @param y The y coordinate of the release. + */ + + void raiseReleaseOutsideEvent(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raise a mouse drag event to the event handler. + * + * @param x The x coordinate of the mouse when the drag started. + * @param y The y coordinate of the mouse when the drag started. + * @param vX The horizontal distance dragged. + * @param vY The vertical distance dragged. + */ + + void raiseDragEvent(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Raise a widget drop event to the event handler. + * + * @param x The x coordinate of the mouse when the drop occurred. + * @param y The y coordinate of the mouse when the drop occurred. + */ + + void raiseDropEvent(nxgl_coord_t x, nxgl_coord_t y); + + /** + * Raise a move forward event to the event handler. + */ + + void raiseMoveForwardEvent(void); + + /** + * Raise a move backward event to the event handler. + */ + + void raiseMoveBackwardEvent(void); + + /** + * Raise a key press event to the event handler. + * + * @param key The character code of the key that caused the event. + */ + + void raiseKeyPressEvent(nxwidget_char_t key); + + /** + * Raise a cursor control event to the event handler. + * + * @param cursorControl The cursor control code that caused the event. + */ + + void raiseCursorControlEvent(ECursorControl cursorControl); + + /** + * Raise a focus event to the event handler. + */ + + void raiseFocusEvent(void); + + /** + * Raise a blur event to the event handler. + */ + + void raiseBlurEvent(void); + + /** + * Raise a close event to the event handler. + */ + + void raiseCloseEvent(void); + + /** + * Raise a hide event to the event handler. + */ + + void raiseHideEvent(void); + + /** + * Raise a show event to the event handler. + */ + + void raiseShowEvent(void); + + /** + * Raise a shelve event to the event handler. + */ + + void raiseShelveEvent(void); + + /** + * Raise a unshelve event to the event handler. + */ + + void raiseUnshelveEvent(void); + + /** + * Raise an enable event to the event handler. + */ + + void raiseEnableEvent(void); + + /** + * Raise a disable event to the event handler. + */ + + void raiseDisableEvent(void); + + /** + * Raise a value change event to the event handler. + */ + + void raiseValueChangeEvent(void); + + /** + * Raise a resize event to the event handler. + * + * @param width The new width of the widget. + * @param height The new height of the widget. + */ + + void raiseResizeEvent(nxgl_coord_t width, nxgl_coord_t height); + + /** + * Raise a move event to the event handler. + * + * @param x The new x coordinate of the widget. + * @param y The new y coordinate of the widget. + * @param vX The horizontal distance moved. + * @param vY The vertical distance moved. + */ + + void raiseMoveEvent(nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t vX, nxgl_coord_t vY); + + /** + * Raise an action event to the event handler. This should be called + * when a widget's purpose has been fulfilled. For example, in the case + * of a button, this event is raised when the button is released within + * its boundaries. The button has produced a valid click, and thus + * fulfilled its purpose, so it needs to raise an "action" event. + */ + + void raiseActionEvent(void); + + /** + * Raises a scroll event. Fired when the panel scrolls. + * + * @param vX Horizontal distance scrolled. + * @param vY Vertical distance scrolled. + */ + + void raiseScrollEvent(nxgl_coord_t vX, nxgl_coord_t vY); + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CWIDGETEVENTHANDLERLIST_HXX diff --git a/NxWidgets/libnxwidgets/include/cwidgetstyle.hxx b/NxWidgets/libnxwidgets/include/cwidgetstyle.hxx new file mode 100644 index 000000000..8fe5e2c32 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/cwidgetstyle.hxx @@ -0,0 +1,135 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/cwidgetstyle.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CWIDGETSTYLE_HXX +#define __INCLUDE_CWIDGETSTYLE_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class CNxFont; + + /** + * Class containing all colors that a widget depends on. + */ + + class CWidgetColors + { + public: + nxgl_mxpixel_t background; /**< Color used for a normal background */ + nxgl_mxpixel_t selectedBackground; /**< Color used for a selected background */ + nxgl_mxpixel_t shineEdge; /**< Color used as light bevel edge */ + nxgl_mxpixel_t shadowEdge; /**< Color used as dark bevel edge */ + nxgl_mxpixel_t highlight; /**< Color used as highlighted elements */ + nxgl_mxpixel_t disabledText; /**< Color used for text in a disabled widget */ + nxgl_mxpixel_t enabledText; /**< Color used for text in a enabled widget */ + nxgl_mxpixel_t selectedText; /**< Color used for text in a clicked widget */ + }; + + /** + * Class providing the default colors and fonts for all widgets. This + * information is copied into the widgets when they are constructed, so you + * will need to change these values *before* creating any widgets if you + * want those widgets to use the altered colors. + * + * If the font objects are set, NXWidgets will use them in preference to the + * default system fonts. + */ + + class CWidgetStyle + { + public: + CWidgetColors colors; /**< Default widget colors */ + CNxFont *font; /**< Default font */ + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_CWIDGETSTYLE_HXX diff --git a/NxWidgets/libnxwidgets/include/glyphs.hxx b/NxWidgets/libnxwidgets/include/glyphs.hxx new file mode 100644 index 000000000..afd6cc7a0 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/glyphs.hxx @@ -0,0 +1,131 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/glyphs.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_GLYPHS_HXX +#define __INCLUDE_GLYPHS_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Bitmap Glyph References + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + struct SBitmap; + + // Global RLE Paletted Bitmaps + + extern const struct SRlePaletteBitmap g_nuttxBitmap; + + // Global Simple Bitmaps + + extern const struct SBitmap g_screenDepthUp; + extern const struct SBitmap g_screenDepthDown; + extern const struct SBitmap g_windowClose; + extern const struct SBitmap g_windowDepthUp; + extern const struct SBitmap g_windowDepthDown; + extern const struct SBitmap g_radioButtonOn; + extern const struct SBitmap g_radioButtonOff; + extern const struct SBitmap g_radioButtonMu; + extern const struct SBitmap g_checkBoxOff; + extern const struct SBitmap g_checkBoxOn; + extern const struct SBitmap g_checkBoxMu; + extern const struct SBitmap g_screenFlipUp; + extern const struct SBitmap g_screenFlipDown; + extern const struct SBitmap g_arrowUp; + extern const struct SBitmap g_arrowDown; + extern const struct SBitmap g_arrowLeft; + extern const struct SBitmap g_arrowRight; + extern const struct SBitmap g_cycle; + extern const struct SBitmap g_backspace; + extern const struct SBitmap g_return; + extern const struct SBitmap g_shift; + extern const struct SBitmap g_capslock; + extern const struct SBitmap g_control; +} + +#endif // __cplusplus + +#endif // __INCLUDE_GLYPHS_HXX diff --git a/NxWidgets/libnxwidgets/include/ibitmap.hxx b/NxWidgets/libnxwidgets/include/ibitmap.hxx new file mode 100644 index 000000000..c4bb3b5ac --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ibitmap.hxx @@ -0,0 +1,165 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ibitmap.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_IBITMAP_HXX +#define __INCLUDE_IBITMAP_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Abstract class defining the basic properties of a source bitmap. The + * primary intent of this class is two support a variety of sources of + * bitmap data with various kinds of compression. + */ + + class IBitmap + { + public: + /** + * Get the bitmap's color format. + * + * @return The bitmap's width. + */ + + virtual const uint8_t getColorFormat(void) const = 0; + + /** + * Get the bitmap's color format. + * + * @return The bitmap's color format. + */ + + virtual const uint8_t getBitsPerPixel(void) const = 0; + + /** + * Get the bitmap's width (in pixels/columns). + * + * @return The bitmap's pixel depth. + */ + + virtual const nxgl_coord_t getWidth(void) const = 0; + + /** + * Get the bitmap's height (in rows). + * + * @return The bitmap's height. + */ + + virtual const nxgl_coord_t getHeight(void) const = 0; + + /** + * Get the bitmap's width (in bytes). + * + * @return The bitmap's width. + */ + + virtual const nxgl_coord_t getStride(void) const = 0; + + /** + * Get one row from the bit map image. + * + * @param x The offset into the row to get + * @param y The row number to get + * @param width The number of pixels to get from the row + * @param data The memory location provided by the caller + * in which to return the data. This should be at least + * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length + * and properly aligned for the pixel color format. + * @param True if the run was returned successfully. + */ + + virtual bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, + FAR void *data) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_IBITMAP_HXX diff --git a/NxWidgets/libnxwidgets/include/ilistbox.hxx b/NxWidgets/libnxwidgets/include/ilistbox.hxx new file mode 100644 index 000000000..9184f23c8 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ilistbox.hxx @@ -0,0 +1,273 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ilistbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ILISTBOX_HXX +#define __INCLUDE_ILISTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "clistboxdataitem.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Abstract Base Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Defines the interface for ListBox classes. + */ + + class IListBox + { + public: + + /** + * Add a new option to the widget using default colors. + * + * @param text Text to show in the option. + * @param value The value of the option. + */ + + virtual void addOption(const CNxString &text, const uint32_t value) = 0; + + /** + * Add an option to the widget. + * + * @param option The option to add. + */ + + virtual void addOption(CListBoxDataItem *option) = 0; + + /** + * Remove an option from the widget by its index. + * + * @param index The index of the option to remove. + */ + + virtual void removeOption(const int index) = 0; + + /** + * Remove all options from the widget. + */ + + virtual void removeAllOptions(void) = 0; + + /** + * Add a new option to the widget. + * + * @param text Text to show in the option. + * @param value The value of the option. + * @param normalTextColor Color to draw the text with when not selected. + * @param normalBackColor Color to draw the background with when not selected. + * @param selectedTextColor Color to draw the text with when selected. + * @param selectedBackColor Color to draw the background with when selected. + */ + + virtual void addOption(const CNxString &text, const uint32_t value, + const nxwidget_pixel_t normalTextColor, + const nxwidget_pixel_t normalBackColor, + const nxwidget_pixel_t selectedTextColor, + const nxwidget_pixel_t selectedBackColor) = 0; + + /** + * Select an option by its index. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual void selectOption(const int index) = 0; + + /** + * Select an option by its index. + * Redraws the widget and raises a value changed event. + * + * @param index The index of the option to select. + */ + + virtual void deselectOption(const int index) = 0; + + /** + * Select all options. Does nothing if the listbox does not allow + * multiple selections. Redraws the widget and raises a value + * changed event. + */ + + virtual void selectAllOptions(void) = 0; + + /** + * Deselect all options. + * Redraws the widget and raises a value changed event. + */ + + virtual void deselectAllOptions(void) = 0; + + /** + * Get the selected index. Returns -1 if nothing is selected. If more than one + * option is selected, the index of the first selected option is returned. + * + * @return The selected index. + */ + + virtual const int getSelectedIndex(void) const = 0; + + /** + * Sets the selected index. Specify -1 to select nothing. Resets any + * other selected options to deselected. + * Redraws the widget and raises a value changed event. + * + * @param index The selected index. + */ + + virtual void setSelectedIndex(const int index) = 0; + + /** + * Get the selected option. Returns NULL if nothing is selected. + * + * @return The selected option. + */ + + virtual const CListBoxDataItem *getSelectedOption(void) const = 0; + + /** + * Sets whether multiple selections are possible or not. + * + * @param allowMultipleSelections True to allow multiple selections. + */ + + virtual void setAllowMultipleSelections(const bool allowMultipleSelections) = 0; + + /** + * Sets whether multiple selections are possible or not. + * + * @return True if multiple selections are allowed. + */ + + virtual const bool allowsMultipleSelections(void) const = 0; + + /** + * Get the specified option. + * + * @return The specified option. + */ + + virtual const CListBoxDataItem *getOption(const int index) = 0; + + /** + * Sort the options alphabetically by the text of the options. + */ + + virtual void sort(void) = 0; + + /** + * Get the total number of options. + * + * @return The number of options. + */ + + virtual const int getOptionCount(void) const = 0; + + /** + * Get the height of a single option. + * + * @return The height of an option. + */ + + virtual const nxgl_coord_t getOptionHeight(void) const = 0; + + /** + * Sets whether or not items added to the list are automatically sorted on insert or not. + * + * @param sortInsertedItems True to enable sort on insertion. + */ + + virtual void setSortInsertedItems(const bool sortInsertedItems) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_ILISTBOX_HXX + diff --git a/NxWidgets/libnxwidgets/include/ilistdataeventhandler.hxx b/NxWidgets/libnxwidgets/include/ilistdataeventhandler.hxx new file mode 100644 index 000000000..b6119a2ae --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ilistdataeventhandler.hxx @@ -0,0 +1,127 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ilistdataeventhandler.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ILISTDATAEVENTHANDLERR_HXX +#define __INCLUDE_ILISTDATAEVENTHANDLERR_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "clistdataeventargs.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Abstract Base Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + class ListData; + + /** + * Base IListDataEventHandler class, intended to be subclassed. Any class + * that needs to listen for CListData events should inherit from this class. + */ + + class IListDataEventHandler + { + public: + /** + * Handle data changes. + * + * @param e Event arguments. + */ + + virtual void handleListDataChangedEvent(const CListDataEventArgs &e) = 0; + + /** + * Handle data changes. + * + * @param e Event arguments. + */ + + virtual void + handleListDataSelectionChangedEvent(const CListDataEventArgs &e) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_ILISTDATAEVENTHANDLERR_HXX diff --git a/NxWidgets/libnxwidgets/include/inxwindow.hxx b/NxWidgets/libnxwidgets/include/inxwindow.hxx new file mode 100644 index 000000000..0c372ee0d --- /dev/null +++ b/NxWidgets/libnxwidgets/include/inxwindow.hxx @@ -0,0 +1,268 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/inxwindow.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_INXWINDOW_HXX +#define __INCLUDE_INXWINDOW_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Pure Virtual Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + struct SBitmap; + + /** + * This class defines common operations on a any NX window. + * There are three instances that represent an NX window from the + * perspective of NXWidgets. + * + * - There is one widget control instance per NX window, + * - One CCallback instance per window, + * - One window instance. + * + * There a various kinds of of window instances, but each inherits + * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow + * that describes the common window behavior. + */ + + class INxWindow + { + public: + + /** + * Creates a new window. Window creation is separate from + * object instantiation so that window creation failures can + * be properly reported. + * + * @return True if the window was successfully created. + */ + + virtual bool open(void) = 0; + + /** + * Request the position and size information of the window. The values + * will be returned asynchronously through the client callback method. + * The GetPosition() method may than be called to obtain the positional + * data as provided by the callback. + * + * @return OK on success; ERROR on failure with errno set appropriately. + */ + + virtual bool requestPosition(void) = 0; + + /** + * Get the position of the window (as reported by the NX callback). + * + * @return The position. + */ + + virtual bool getPosition(FAR struct nxgl_point_s *pPos) = 0; + + /** + * Get the size of the window (as reported by the NX callback). + * + * @return The size. + */ + + virtual bool getSize(FAR struct nxgl_size_s *pSize) = 0; + + /** + * Set the position and size of the window. + * + * @param pPos The new position of the window. + * @return True on success, false on failure. + */ + + virtual bool setPosition(FAR const struct nxgl_point_s *pPos) = 0; + + /** + * Set the size of the selected window. + * + * @param pSize The new size of the window. + * @return OK on success; ERROR on failure with errno set appropriately. + */ + + virtual bool setSize(FAR const struct nxgl_size_s *pSize) = 0; + + /** + * Bring the window to the top of the display. + * + * @return OK on success; ERROR on failure with errno set appropriately. + */ + + virtual bool raise(void) = 0; + + /** + * Lower the window to the bottom of the display. + * + * @return OK on success; ERROR on failure with errno set appropriately. + */ + + virtual bool lower(void) = 0; + + /** + * Set an individual pixel in the window with the specified color. + * + * @param pPos The location of the pixel to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + virtual bool setPixel(FAR const struct nxgl_point_s *pPos, + nxgl_mxpixel_t color) = 0; + + /** + * Fill the specified rectangle in the window with the specified color. + * + * @param pRect The location to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + virtual bool fill(FAR const struct nxgl_rect_s *pRect, + nxgl_mxpixel_t color) = 0; + + /** + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * @param rect The location to be copied + * @param dest - The describes the destination bitmap to receive the + * graphics data. + */ + + virtual void getRectangle(FAR const struct nxgl_rect_s *rect, + struct SBitmap *dest) = 0; + + /** + * Fill the specified trapezoidal region in the window with the specified + * color. + * + * @param pClip Clipping rectangle relative to window (may be null). + * @param pTrap The trapezoidal region to be filled. + * @param color The color to use in the fill. + * + * @return True on success; false on failure. + */ + + virtual bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, + FAR const struct nxgl_trapezoid_s *pTrap, + nxgl_mxpixel_t color) = 0; + + /** + * Fill the specified line in the window with the specified color. + * + * @param vector - Describes the line to be drawn + * @param width - The width of the line + * @param color - The color to use to fill the line + * + * @return True on success; false on failure. + */ + + virtual bool drawLine(FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color) = 0; + + /** + * Draw a filled circle at the specified position, size, and color. + * + * @param center The window-relative coordinates of the circle center. + * @param radius The radius of the rectangle in pixels. + * @param color The color of the rectangle. + */ + + virtual bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, + nxgl_mxpixel_t color) = 0; + + /** + * Move a rectangular region within the window. + * + * @param pRect Describes the rectangular region to move. + * @param pOffset The offset to move the region. + * + * @return True on success; false on failure. + */ + + virtual bool move(FAR const struct nxgl_rect_s *pRect, + FAR const struct nxgl_point_s *pOffset) = 0; + + /** + * Copy a rectangular region of a larger image into the rectangle in the + * specified window. The source image is treated as an opaque image. + * + * @param pDest Describes the rectangular on the display that will receive + * the bitmap. + * @param pSrc The start of the source image. + * @param pOrigin the pOrigin of the upper, left-most corner of the full + * bitmap. Both pDest and pOrigin are in window coordinates, however, + * pOrigin may lie outside of the display. + * @param stride The width of the full source image in bytes. + * + * @return True on success; false on failure. + */ + + virtual bool bitmap(FAR const struct nxgl_rect_s *pDest, + FAR const void *pSrc, + FAR const struct nxgl_point_s *pOrigin, + unsigned int stride) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_INXWINDOW_HXX + diff --git a/NxWidgets/libnxwidgets/include/iscrollable.hxx b/NxWidgets/libnxwidgets/include/iscrollable.hxx new file mode 100644 index 000000000..21a69e487 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/iscrollable.hxx @@ -0,0 +1,208 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/iscrollable.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ISCROLLABLE_HXX +#define __INCLUDE_ISCROLLABLE_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Abstract class defining basic functionality of scrolling widgets. + * Scrolling regions are modelled as a virtual "canvas", or rectangular + * region, with height/width dimensions and x/y coordinates. + */ + + class IScrollable + { + public: + /** + * Gets the x coordinate of the virtual canvas. + * + * @return The x coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasX(void) const = 0; + + /** + * Gets the y coordinate of the virtual canvas. + * + * @return The y coordinate of the virtual canvas. + */ + + virtual const int32_t getCanvasY(void) const = 0; + + /** + * Gets the width of the virtual canvas. + * + * @return The width of the virtual canvas. + */ + + virtual const int32_t getCanvasWidth(void) const = 0; + + /** + * Gets the height of the virtual canvas. + * + * @return The height of the virtual canvas. + */ + + virtual const int32_t getCanvasHeight(void) const = 0; + + /** + * Scrolls the virtual canvas by the specified amounts. + * + * @param dx Distance to scroll horizontally. + * @param dy Distance to scroll vertically. + */ + + virtual void scroll(int32_t dx, int32_t dy) = 0; + + /** + * Repositions the virtual canvas to the specified coordinates. + * + * @param x New x coordinate of the virtual canvas. + * @param y New y coordinate of the virtual canvas. + */ + + virtual void jump(int32_t x, int32_t y) = 0; + + /** + * Returns true if vertical scrolling is allowed. + * + * @return True if vertical scrolling is allowed. + */ + + virtual bool allowsVerticalScroll(void) const = 0; + + /** + * Returns true if horizontal scrolling is allowed. + * + * @return True if horizontal scrolling is allowed. + */ + + virtual bool allowsHorizontalScroll(void) const = 0; + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsVerticalScroll(bool allow) = 0; + + /** + * Set whether or not horizontal scrolling is allowed. + * + * @param allow True to allow horizontal scrolling; false to deny it. + */ + + virtual void setAllowsHorizontalScroll(bool allow) = 0; + + /** + * Sets the width of the virtual canvas. + * + * @param width The width of the virtual canvas. + */ + + virtual void setCanvasWidth(const int32_t width) = 0; + + /** + * Sets the height of the virtual canvas. + * + * @param height The height of the virtual canvas. + */ + + virtual void setCanvasHeight(const int32_t height) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_ISCROLLABLE_HXX + diff --git a/NxWidgets/libnxwidgets/include/islider.hxx b/NxWidgets/libnxwidgets/include/islider.hxx new file mode 100644 index 000000000..5ea821e42 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/islider.hxx @@ -0,0 +1,188 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/islider.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ISLIDER_HXX +#define __INCLUDE_ISLIDER_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Abstract Base Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Defines the interface for slider widgets. + */ + class ISlider + { + public: + + /** + * Get the smallest value that the slider can represent. + * + * @return The smallest value. + */ + + virtual const nxgl_coord_t getMinimumValue(void) const = 0; + + /** + * Get the largest value that the slider can represent. + * + * @return The largest value. + */ + + virtual const nxgl_coord_t getMaximumValue(void) const = 0; + + /** + * Get the current value of the slider. + * + * return The current slider value. + */ + + virtual const nxgl_coord_t getValue(void) const = 0; + + /** + * Get the value represented by the height of the grip. + * For sliders, this would typically be 1 (so each new + * grip position is worth 1). For scrollbars, this + * would be the height of the scrolling widget. + * + * @return The page size. + */ + + virtual const nxgl_coord_t getPageSize(void) const = 0; + + /** + * Set the smallest value that the slider can represent. + * + * @param value The smallest value. + */ + + virtual void setMinimumValue(const nxgl_coord_t value) = 0; + + /** + * Set the largest value that the slider can represent. + * + * @param value The largest value. + */ + + virtual void setMaximumValue(const nxgl_coord_t value) = 0; + + /** + * Set the value that of the slider. This will reposition + * and redraw the grip. + * + * @param value The new value. + */ + + virtual void setValue(const nxgl_coord_t value) = 0; + + /** + * Set the value that of the slider. This will reposition and redraw + * the grip. The supplied value should be bitshifted left 16 places. + * This ensures greater accuracy than the standard setValue() method if + * the slider is being used as a scrollbar. + * + * @param value The new value. + */ + + virtual void setValueWithBitshift(const int32_t value) = 0; + + /** + * Set the page size represented by the grip. + * + * @param pageSize The page size. + * @see getPageSize(). + */ + + virtual void setPageSize(const nxgl_coord_t pageSize) = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_ISLIDER_HXX + diff --git a/NxWidgets/libnxwidgets/include/itextbox.hxx b/NxWidgets/libnxwidgets/include/itextbox.hxx new file mode 100644 index 000000000..78de7e502 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/itextbox.hxx @@ -0,0 +1,209 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/itextbox.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ITEXTBOX_HXX +#define __INCLUDE_ITEXTBOX_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxstring.hxx" +#include "cwidgetstyle.hxx" +#include "cwidgeteventargs.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Abstract Base Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Cursor display options. + */ + + typedef enum + { + SHOW_CURSOR_ONFOCUS = 0, /**< Show the cursor only if the widget has focus */ + SHOW_CURSOR_NEVER, /**< The cursor is never displayed */ + SHOW_CURSOR_ALWAYS /**< Always show the cursor */ + } EShowCursor; + + /** + * Defines the interface that textbox-like classes should implement. + */ + + class ITextBox + { + public: + + /** + * Sets the cursor display mode. + * + *@param cursorMode Determines cursor display mode + */ + + virtual void showCursor(EShowCursor cursorMode) = 0; + + /** + * Enables/disables cursor wrapping + * + * @param wrap True enables cursor wrapping + */ + + virtual void wrapCursor(bool wrap) = 0; + + /** + * Set the text displayed in the label. + * + * @param text String to display. + */ + + virtual void setText(const CNxString &text) = 0; + + /** + * Append new text to the end of the current text displayed in the + * label. + * + * @param text String to append. + */ + + virtual void appendText(const CNxString &text) = 0; + + /** + * Remove all characters from the string from the start index onwards. + * + * @param startIndex Index to remove from. + */ + + virtual void removeText(const unsigned int startIndex) = 0; + + /** + * Remove specified number of characters from the string from the + * start index onwards. + * + * @param startIndex Index to remove from. + * @param count Number of characters to remove. + */ + + virtual void removeText(const unsigned int startIndex, const unsigned int count) = 0; + + /** + * Insert text at the specified index. + * + * @param text The text to insert. + * @param index Index at which to insert the text. + */ + + virtual void insertText(const CNxString &text, const unsigned int index) = 0; + + /** + * Insert text at the current cursor position. + * + * @param text The text to insert. + */ + + virtual void insertTextAtCursor(const CNxString &text) = 0; + + /** + * Move the cursor to the text position specified. 0 indicates the + * start of the string. If position is greater than the length of the + * string, the cursor is moved to the end of the string. + * + * @param position The new cursor position. + */ + + virtual void moveCursorToPosition(const int position) = 0; + + /** + * Get the cursor position. This is the index within the string that + * the cursor is currently positioned over. + * @return position The cursor position. + */ + + virtual const int getCursorPosition(void) const = 0; + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_ITEXTBOX_HXX diff --git a/NxWidgets/libnxwidgets/include/nxconfig.hxx b/NxWidgets/libnxwidgets/include/nxconfig.hxx new file mode 100644 index 000000000..2f38c7c26 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/nxconfig.hxx @@ -0,0 +1,444 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/nxconfig.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NXCONFIG_HXX +#define __INCLUDE_NXCONFIG_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* NX Configuration *********************************************************/ + +/** + * Required to enabled NX graphics support + */ + +#ifndef CONFIG_NX +# error "NX mouse/touchscreen support is required (CONFIG_NX_MOUSE)" +#endif + +/** + * Required to enabled NX mouse/touchscreen support + */ + +#ifndef CONFIG_NX_MOUSE +# warning "NX mouse/touchscreen support is required (CONFIG_NX_MOUSE)" +#endif + +/** + * Required to enabled NX keyboard support + */ + +#ifndef CONFIG_NX_KBD +# warning "NX keyboard support is required (CONFIG_NX_KBD)" +#endif + +/** + * Only a single video plane is supported + */ + +#ifndef CONFIG_NX_NPLANES +# define CONFIG_NX_NPLANES 1 +#endif + +#if CONFIG_NX_NPLANES != 1 +# error "Only a single color plane is supported (CONFIG_NX_NPLANES)" +#endif + +/* NX Server/Device Configuration *******************************************/ + +/** + * LCD device number (in case there are more than one LCDs connected) + */ + +#ifndef CONFIG_NXWIDGETS_DEVNO +# define CONFIG_NXWIDGETS_DEVNO 0 +#endif + +/** + * Only a single video plane is supported + */ + +#ifndef CONFIG_NXWIDGETS_VPLANE +# define CONFIG_NXWIDGETS_VPLANE 0 +#endif + +/** + * Priority of the NX server (in multi-user mode) + */ + +#ifndef CONFIG_NXWIDGETS_SERVERPRIO +# define CONFIG_NXWIDGETS_SERVERPRIO 50 +#endif + +/** + * Priority of the NX event listener thread (in multi-user mode) + */ + +#ifndef CONFIG_NXWIDGETS_LISTENERPRIO +# define CONFIG_NXWIDGETS_LISTENERPRIO 50 +#endif + +/** + * NX server/listener thread stack size (in multi-user mode) + */ + +#ifndef CONFIG_NXWIDGETS_STACKSIZE +# define CONFIG_NXWIDGETS_STACKSIZE 4096 +#endif + +/* NXWidget Configuration ***************************************************/ +/* NX Server/Device Configuration + * + * CONFIG_NXWIDGETS_DEVNO - LCD device number (in case there are more than + * one LCDs connected. Default: 0 + * CONFIG_NXWIDGETS_VPLANE - Only a single video plane is supported. Default: 0 + * CONFIG_NXWIDGETS_SERVERPRIO - Priority of the NX server (in multi-user mode). + * Default: 50 + * CONFIG_NXWIDGETS_SERVERPRIO + * CONFIG_NXWIDGETS_LISTENERPRIO - Priority of the NX event listener thread (in + * multi-user mode). Default: 50 + * CONFIG_NXWIDGETS_STACKSIZE - Priority of the NX server/listener thread + * stack size (in multi-user mode). Default: 4096 + * + * NXWidget Configuration + * + * CONFIG_NXWIDGETS_BPP - Supported bits-per-pixel {8, 16, 24, 32}. Default: + * The smallest BPP configuration supported by NX. + * CONFIG_NXWIDGETS_SIZEOFCHAR - Size of character {1 or 2 bytes}. Default + * Determined by CONFIG_NXWIDGETS_SIZEOFCHAR + * + * NXWidget Default Values + * + * CONFIG_NXWIDGETS_DEFAULT_FONTID - Default font ID. Default: NXFONT_DEFAULT + * CONFIG_NXWIDGETS_TNXARRAY_INITIALSIZE, CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT - + * Default dynamic array parameters. Default: 16, 8 + * + * CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR - Normal background color. Default: + * MKRGB(160,160,160) + * CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR - Default selected background + * color. Default: MKRGB(120,192,192) + * CONFIG_NXWIDGETS_DEFAULT_SHINEEDGECOLOR - Shiny side boarder color. Default + * MKRGB(248,248,248) + * CONFIG_NXWIDGETS_DEFAULT_SHADOWEDGECOLOR - Shadowed side border color. + * Default: MKRGB(0,0,0) + * CONFIG_NXWIDGETS_DEFAULT_HIGHLIGHTCOLOR - Highlight color. Default: + * MKRGB(192,192,192) + * CONFIG_NXWIDGETS_DEFAULT_DISABLEDTEXTCOLOR - Text color on a disabled widget: + * Default: MKRGB(192,192,192) + * CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR - Text color on a enabled widget: + * Default: MKRGB(248,248,248) + * CONFIG_NXWIDGETS_DEFAULT_DISABLEDTEXTCOLOR - Text color on a selected widget: + * Default: MKRGB(0,0,0) + * CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR - Default font color: Default: + * MKRGB(255,255,255) + * CONFIG_NXWIDGETS_TRANSPARENT_COLOR - Transparent color: Default: MKRGB(0,0,0) + * + * Keypad behavior + * + * CONFIG_NXWIDGETS_FIRST_REPEAT_TIME - Time taken before a key starts + * repeating (in milliseconds). Default: 500 + * CONFIG_NXWIDGETS_CONTINUE_REPEAT_TIME - Time taken before a repeating key + * repeats again (in milliseconds). Default: 200 + * CONFIG_NXWIDGETS_DOUBLECLICK_TIME - Left button release-press time for + * double click (in milliseconds). Default: 350 + * CONFIG_NXWIDGETS_KBDBUFFER_SIZE - Size of incoming character buffer, i.e., + * the maximum number of characters that can be entered between NX polling + * cycles without losing data. + * CONFIG_NXWIDGETS_CURSORCONTROL_SIZE - Size of incoming cursor control + * buffer, i.e., the maximum number of cursor controls that can between + * entered by NX polling cycles without losing data. Default: 4 + */ + +/** + * Bits per pixel + */ + +#ifndef CONFIG_NXWIDGETS_BPP +# if !defined(CONFIG_NX_DISABLE_8BPP) +# warning "Assuming 8-bits per pixel, RGB 3:3:2" +# define CONFIG_NXWIDGETS_BPP 8 +# elif !defined(CONFIG_NX_DISABLE_16BPP) +# warning "Assuming 16-bits per pixel, RGB 5:6:5" +# define CONFIG_NXWIDGETS_BPP 16 +# elif !defined(CONFIG_NX_DISABLE_24BPP) +# warning "Assuming 24-bits per pixel, RGB 8:8:8" +# define CONFIG_NXWIDGETS_BPP 24 +# elif !defined(CONFIG_NX_DISABLE_32BPP) +# warning "Assuming 32-bits per pixel, RGB 8:8:8" +# define CONFIG_NXWIDGETS_BPP 32 +# else +# error "No supported pixel depth is enabled" +# endif +#endif + +#if CONFIG_NXWIDGETS_BPP == 8 +# ifdef CONFIG_NX_DISABLE_8BPP +# error "NX 8-bit support is disabled (CONFIG_NX_DISABLE_8BPP)" +# endif +# define CONFIG_NXWIDGETS_FMT FB_FMT_RGB8_332 +# define MKRGB RGBTO8 +# define RGB2RED RBG8RED +# define RGB2GREEN RBG8GREEN +# define RGB2BLUE RBG8BLUE +# define FONT_RENDERER nxf_convert_8bpp +#elif CONFIG_NXWIDGETS_BPP == 16 +# ifdef CONFIG_NX_DISABLE_16BPP +# error "NX 16-bit support is disabled (CONFIG_NX_DISABLE_16BPP)" +# endif +# define CONFIG_NXWIDGETS_FMT FB_FMT_RGB16_565 +# define MKRGB RGBTO16 +# define RGB2RED RBG16RED +# define RGB2GREEN RBG16GREEN +# define RGB2BLUE RBG16BLUE +# define FONT_RENDERER nxf_convert_16bpp +#elif CONFIG_NXWIDGETS_BPP == 24 +# ifdef CONFIG_NX_DISABLE_24BPP +# error "NX 24-bit support is disabled (CONFIG_NX_DISABLE_24BPP)" +# endif +# define CONFIG_NXWIDGETS_FMT FB_FMT_RGB24 +# define MKRGB RGBTO24 +# define RGB2RED RBG24RED +# define RGB2GREEN RBG24GREEN +# define RGB2BLUE RBG24BLUE +# define FONT_RENDERER nxf_convert_24bpp +#elif CONFIG_NXWIDGETS_BPP == 32 +# ifdef CONFIG_NX_DISABLE_32BPP +# error "NX 32-bit support is disabled (CONFIG_NX_DISABLE_32BPP)" +# endif +# define CONFIG_NXWIDGETS_FMT FB_FMT_RGB32 +# define MKRGB RGBTO24 +# define RGB2RED RBG24RED +# define RGB2GREEN RBG24GREEN +# define RGB2BLUE RBG24BLUE +# define FONT_RENDERER nxf_convert_32bpp +#else +# error "Pixel depth not supported (CONFIG_NXWIDGETS_BPP)" +#endif + +/* Size of a character */ + +#ifndef CONFIG_NXWIDGETS_SIZEOFCHAR +# if CONFIG_NXFONTS_CHARBITS <= 8 +# define CONFIG_NXWIDGETS_SIZEOFCHAR 1 +# else +# define CONFIG_NXWIDGETS_SIZEOFCHAR 2 +# endif +#endif + +#if CONFIG_NXWIDGETS_SIZEOFCHAR != 1 && CONFIG_NXWIDGETS_SIZEOFCHAR != 2 +# error "Unsupported character width (CONFIG_NXWIDGETS_SIZEOFCHAR)" +#endif + +/* NXWidget Default Values **************************************************/ + +/** + * Default font ID + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_FONTID +# define CONFIG_NXWIDGETS_DEFAULT_FONTID NXFONT_DEFAULT +#endif + +/** + * Default dynamic array parameters + */ + +#ifndef CONFIG_NXWIDGETS_TNXARRAY_INITIALSIZE +# define CONFIG_NXWIDGETS_TNXARRAY_INITIALSIZE 16 +#endif + +#ifndef CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT +# define CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT 8 +#endif + +/** + * Normal background color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR MKRGB(160,160,160) +#endif + +/** + * Default selected background color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR MKRGB(120,192,192) +#endif + +/** + * Shiny side border color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_SHINEEDGECOLOR +# define CONFIG_NXWIDGETS_DEFAULT_SHINEEDGECOLOR MKRGB(248,248,248) +#endif + +/** + * Shadowed side border color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_SHADOWEDGECOLOR +# define CONFIG_NXWIDGETS_DEFAULT_SHADOWEDGECOLOR MKRGB(0,0,0) +#endif + +/** + * Highlight color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_HIGHLIGHTCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_HIGHLIGHTCOLOR MKRGB(192,192,192) +#endif + +/* Text colors */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_DISABLEDTEXTCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_DISABLEDTEXTCOLOR MKRGB(192,192,192) +#endif + +#ifndef CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR MKRGB(248,248,248) +#endif + +#ifndef CONFIG_NXWIDGETS_DEFAULT_SELECTEDTEXTCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_SELECTEDTEXTCOLOR MKRGB(0,0,0) +#endif + +/** + * Default font color + */ + +#ifndef CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR +# define CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR MKRGB(255,255,255) +#endif + +/** + * Transparent color + */ + +#ifndef CONFIG_NXWIDGETS_TRANSPARENT_COLOR +# define CONFIG_NXWIDGETS_TRANSPARENT_COLOR MKRGB(0,0,0) +#endif + +/* Keypad behavior **********************************************************/ + +/** + * Time taken before a key starts repeating (in milliseconds). + */ + +#ifndef CONFIG_NXWIDGETS_FIRST_REPEAT_TIME +# define CONFIG_NXWIDGETS_FIRST_REPEAT_TIME 500 +#endif + +/** + * Time taken before a repeating key repeats again (in milliseconds). + */ + +#ifndef CONFIG_NXWIDGETS_CONTINUE_REPEAT_TIME +# define CONFIG_NXWIDGETS_CONTINUE_REPEAT_TIME 200 +#endif + +/** + * Left button release-press time for double click (in milliseconds). + */ + +#ifndef CONFIG_NXWIDGETS_DOUBLECLICK_TIME +# define CONFIG_NXWIDGETS_DOUBLECLICK_TIME 350 +#endif + +/** + * Size of incoming character buffer, i.e., the maximum number of characters + * that can be entered between NX polling cycles without losing data. + */ + +#ifndef CONFIG_NXWIDGETS_KBDBUFFER_SIZE +# define CONFIG_NXWIDGETS_KBDBUFFER_SIZE 8 +#endif + +/** + * Size of incoming cursor control buffer, i.e., the maximum number of cursor + * controls that can between entered by NX polling cycles without losing data. + */ + +#ifndef CONFIG_NXWIDGETS_CURSORCONTROL_SIZE +# define CONFIG_NXWIDGETS_CURSORCONTROL_SIZE 4 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +namespace NXWidgets +{ +#if CONFIG_NXWIDGETS_BPP == 8 + typedef uint8_t nxwidget_pixel_t; +#elif CONFIG_NXWIDGETS_BPP == 16 + typedef uint16_t nxwidget_pixel_t; +#elif CONFIG_NXWIDGETS_BPP == 24 + typedef uint32_t nxwidget_pixel_t; +#elif CONFIG_NXWIDGETS_BPP == 32 + typedef uint32_t nxwidget_pixel_t; +#else +# error "Pixel depth is unknown" +#endif + +#if CONFIG_NXWIDGETS_SIZEOFCHAR == 2 + typedef uint16_t nxwidget_char_t; +#elif CONFIG_NXWIDGETS_SIZEOFCHAR == 1 + typedef uint8_t nxwidget_char_t; +#else +# error "Character width is unknown" +#endif +} + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#endif // __INCLUDE_NXCONFIG_HXX diff --git a/NxWidgets/libnxwidgets/include/singletons.hxx b/NxWidgets/libnxwidgets/include/singletons.hxx new file mode 100644 index 000000000..094808939 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/singletons.hxx @@ -0,0 +1,136 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/singletons.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SINGLETONS_HXX +#define __INCLUDE_SINGLETONS_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward References + */ + + class CWidgetStyle; + class CNxString; + + /** + * Global singleton instances + */ + + extern CWidgetStyle *g_defaultWidgetStyle; /**< The default widget style */ + extern CNxString *g_nullString; /**< The reusable empty string */ + extern TNxArray *g_nxTimers; /**< An array of all timers */ + + /** + * Setup misc singleton instances. + * + * Q: Why is there here? + * A: Because it needs to be done one time before any widgets are created. + * Q: So why isn't it just the default style just a statically constructed class? + * A: Because not all platforms will support static class constructions. + * Q: Why isn't it part of CNxServer? + * A: Because the singletons may be needed before the server is started. + */ + + void instantiateSingletons(void); + + /** + * Free the singleton instances when the last NX server is destroyed. + * + * Q: Why is there here is it is only called as part of the CNxServer destructor? + * A: Just for symmetry with instantiateSingletons(). + */ + + void freeSingletons(void); +} + +#endif // __cplusplus + +#endif // __INCLUDE_SINGLETONS_HXX diff --git a/NxWidgets/libnxwidgets/include/teventargs.hxx b/NxWidgets/libnxwidgets/include/teventargs.hxx new file mode 100644 index 000000000..c1371be92 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/teventargs.hxx @@ -0,0 +1,136 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/teventargs.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_TEVENTARGS_HXX +#define __INCLUDE_TEVENTARGS_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Base template class for all events within the NxWidgets system. + * All event types should inherit from this class. + */ + + template + class TEventArgs + { + private: + T m_source; /**< The object that raised the event */ + + public: + + /** + * Constructor. + * @param source The object that raised the event. + */ + + inline TEventArgs(const T& source) + { + m_source = source; + } + + /** + * Destructor. + */ + + virtual inline ~TEventArgs() { } + + /** + * Get the source object that raised the event. + */ + + inline const T& getSource(void) const + { + return m_source; + } + }; +} + +#endif // __cplusplus + +#endif // __INCLUDE_TEVENTARGS_HXX diff --git a/NxWidgets/libnxwidgets/include/tnxarray.hxx b/NxWidgets/libnxwidgets/include/tnxarray.hxx new file mode 100644 index 000000000..44cb537ad --- /dev/null +++ b/NxWidgets/libnxwidgets/include/tnxarray.hxx @@ -0,0 +1,437 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/tnxarray.hxx + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Portions of this package derive from Woopsi (http://woopsi.org/) and + * portions are original efforts. It is difficult to determine at this + * point what parts are original efforts and which parts derive from Woopsi. + * However, in any event, the work of Antony Dzeryn will be acknowledged + * in most NxWidget files. Thanks Antony! + * + * Copyright (c) 2007-2011, Antony Dzeryn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the names "Woopsi", "Simian Zombie" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_TNXARRAY_HXX +#define __INCLUDE_TNXARRAY_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "nxconfig.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +/** + * Class providing a dynamic array; that is, an array that will automatically + * grow to accommodate new data. It provides a fast way to randomly access + * a list of data. Essentially, it provides the most important functionality + * of the STL vector class without any of the overhead of including an STL + * class. + * + * If the data to be stored will store a lot of data that will predominantly + * be read sequentially, consider using the LinkedList class instead. Resizing + * the list is an expensive operation that will occur frequently when filling + * the array with large amounts of data. Adding new data to the linked list is + * very inexpensive. + */ + +template +class TNxArray +{ +private: + T *m_data; /**< Internal array of data items */ + int m_size; /**< Number of items in the array */ + int m_reservedSize; /**< Total size of the array including unpopulated slots */ + + /** + * Re-allocate the array to this size; + */ + + void reallocate(const int newSize); + + /** + * Resize the array if it is full. + */ + + void resize(void); + +public: + + /** + * Constructor. Creates an un-allocated array. The array will + * be allocated when items are added to it or when preallocate() + * is called. + */ + + inline TNxArray(); + + /** + * Constructor. Creates an allocated array. + * + *@param initialSize The initial size of the array. + */ + + inline TNxArray(int initialSize); + + /** + * Destructor. + */ + + inline ~TNxArray(); + + /** + * Set the initial size of the array. Normally, the array is + * unallocated until the first data is pushed into the array. + * That works great for stacks and lists. But if you want a + * array of unitialized elements, then this method will + * preallocate the array for you. + * + * @return The size of the array. + */ + + void preallocate(void); + + /** + * Get the size of the array. + * + * @return The size of the array. + */ + + inline const int size(void) const; + + /** + * Add a value to the end of the array. + * + * @param value The value to add to the array. + */ + + void push_back(const T &value); + + /** + * Insert a value into the array. + * + * @param index The index to insert into. + * @param value The value to insert. + */ + + void insert(const int index, const T &value); + + /** + * Remove the last element from the array. + */ + + void pop_back(void); + + /** + * Erase a single value at the specified index + */ + + void erase(const int index); + + /** + * Get a value at the specified location. Does not perform bounds checking. + * @param index The index of the desired value. + * @return The value at the specified index. + */ + + inline T &at(const int index) const; + + /** + * Check if the array has any data. + * @return True if the array is empty. + */ + + inline bool empty(void) const; + + /** + * Remove all data. + */ + + void clear(); + + /** + * Overload the [] operator to allow array-style access. + * @param index The index to retrieve. + * @return The value at the specified index. + */ + + T& operator[](const int index) const; +}; + +template +TNxArray::TNxArray() +{ + // Don't allocate anything until the first data is added to + // the array + + m_size = 0; // Number of data items in use + m_reservedSize = 0; // Number of data items allocated + m_data = (T *)0; // Allocated memory for data items +} + +template +TNxArray::TNxArray(int initialSize) +{ + m_size = 0; // Number of data items in use + m_reservedSize = 0; // Number of data items allocated + m_data = (T *)0; // Allocated memory for data items + preallocate(initialSize); // Allocate the initial array +} + +template +TNxArray::~TNxArray() +{ + if (m_data) + { + delete [] m_data; + } +} + +template +const int TNxArray::size(void) const +{ + return m_size; +} + +template +void TNxArray::push_back(const T &value) +{ + // Ensure the array is large enough to hold one more data item + + resize(); + + // Add data to array + + m_data[m_size] = value; + + // Remember we've filled a slot + + m_size++; +} + +template +void TNxArray::pop_back(void) +{ + if (m_size >= 1) + { + // We can just reduce the used size of the array, as the value + // will get overwritten automatically + + m_size--; + } +} + +template +void TNxArray::insert(const int index, const T &value) +{ + // Bounds check + + if ((index >= m_size) || (m_size == 0)) + { + push_back(value); + return; + } + + // Ensure the array is large enough to hold one more data item + + resize(); + + // Shift all of the data back one place to make a space for the new data + + for (int i = m_size; i > index; i--) + { + m_data[i] = m_data[i - 1]; + } + + // Add data to array + + m_data[index] = value; + + // Remember we've filled a slot + + m_size++; +} + +template +void TNxArray::erase(const int index) +{ + // Bounds check + + if (index >= m_size) + { + return; + } + + // Shift all of the data back one place and overwrite the value + + for (int i = index; i < m_size - 1; i++) + { + m_data[i] = m_data[i + 1]; + } + + // Remember we've removed a slot + + m_size--; +} + +template +void TNxArray::reallocate(const int newSize) +{ + // Do we need to redim the array? + + if (m_reservedSize < newSize) + { + // Create the new array + + T *newData = new T[newSize]; + + // Copy old array contents to new the new array + + for (int i = 0; i < m_reservedSize; i++) + { + newData[i] = m_data[i]; + } + + // Delete the old array (if there was one) + + if (m_data) + { + delete [] m_data; + } + + // Update values + + m_data = newData; + m_reservedSize = newSize; + } +} + +template +void TNxArray::resize(void) +{ + // Do we need to redim the array in order to add one more entry? + + if (m_reservedSize == m_size) + { + // We have filled the array, so resize it + + int newSize = m_reservedSize; +#if CONFIG_NXWIDGETS_TNXARRAY_INITIALSIZE != CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT + newSize += m_reservedSize ? + CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT : + CONFIG_NXWIDGETS_TNXARRAY_INITIALSIZE; +#else + newSize += CONFIG_NXWIDGETS_TNXARRAY_SIZEINCREMENT; +#endif + + // Re-allocate the array + + reallocate(newSize); + } +} + +template +T& TNxArray::at(const int index) const +{ + // What if this is called with index > m_reservedSize? What if + // this is called before m_data is allocated? Don't do that! + + return m_data[index]; +} + +template +bool TNxArray::empty() const +{ + return (m_size == 0); +} + +template +T& TNxArray::operator[](const int index) const +{ + // What if this is called with index > m_reservedSize? What if + // this is called before m_data is allocated? Don't do that! + + return m_data[index]; +} + +template +void TNxArray::clear() +{ + // All we need to do is reset the size value + + m_size = 0; +} + +#endif // __cplusplus + +#endif // __INCLUDE_TNXARRAY_HXX -- cgit v1.2.3