NXWidgets  1.19
cnumericedit.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cnumericedit.hxx
3  *
4  * Copyright (C) 2012 Gregory Nutt. All rights reserved.
5  * Author: Gregory Nutt <gnutt@nuttx.org>
6  * Petteri Aimonen <jpa@kapsi.fi>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
19  * me be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  ****************************************************************************
36  *
37  * Portions of this package derive from Woopsi (http://woopsi.org/) and
38  * portions are original efforts. It is difficult to determine at this
39  * point what parts are original efforts and which parts derive from Woopsi.
40  * However, in any event, the work of Antony Dzeryn will be acknowledged
41  * in all NxWidget files. Thanks Antony!
42  *
43  * Copyright (c) 2007-2011, Antony Dzeryn
44  * All rights reserved.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions are met:
48  *
49  * * Redistributions of source code must retain the above copyright
50  * notice, this list of conditions and the following disclaimer.
51  * * Redistributions in binary form must reproduce the above copyright
52  * notice, this list of conditions and the following disclaimer in the
53  * documentation and/or other materials provided with the distribution.
54  * * Neither the names "Woopsi", "Simian Zombie" nor the
55  * names of its contributors may be used to endorse or promote products
56  * derived from this software without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
59  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61  * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
62  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
65  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
67  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68  *
69  ****************************************************************************/
70 
71 #ifndef __INCLUDE_CNUMERICEDIT_HXX
72 #define __INCLUDE_CNUMERICEDIT_HXX
73 
74 /****************************************************************************
75  * Included Files
76  ****************************************************************************/
77 
78 #include <nuttx/config.h>
79 
80 #include <stdint.h>
81 #include <stdbool.h>
82 
83 #include <nuttx/nx/nxglib.h>
84 
85 #include "cnxwidget.hxx"
86 #include "cwidgetstyle.hxx"
87 #include "cnxstring.hxx"
88 
89 /****************************************************************************
90  * Pre-Processor Definitions
91  ****************************************************************************/
92 
93 /****************************************************************************
94  * Implementation Classes
95  ****************************************************************************/
96 
97 #if defined(__cplusplus)
98 
99 namespace NXWidgets
100 {
101  /**
102  * Forward references
103  */
104 
105  class CWidgetControl;
106  class CRect;
107  class CLabel;
108  class CButton;
109  class CNxTimer;
110 
111  /**
112  * Numeric edit control, with plus and minus buttons.
113  */
114 
116  {
117  protected:
122  int m_value;
127 
128  /**
129  * Resize the widget to the new dimensions.
130  *
131  * @param width The new width.
132  * @param height The new height.
133  */
134 
135  virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
136 
137  virtual void handleClickEvent(const CWidgetEventArgs &e);
138 
139  virtual void handleReleaseEvent(const CWidgetEventArgs &e);
140 
141  virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e);
142 
143  virtual void handleActionEvent(const CWidgetEventArgs &e);
144 
145  virtual void handleDragEvent(const CWidgetEventArgs &e);
146 
147  /**
148  * Copy constructor is protected to prevent usage.
149  */
150 
151  inline CNumericEdit(const CNumericEdit &num) : CNxWidget(num) { };
152 
153  public:
154 
155  /**
156  * Constructor for a numeric edit control.
157  *
158  * @param pWidgetControl The controlling widget for the display
159  * @param x The x coordinate of the text box, relative to its parent.
160  * @param y The y coordinate of the text box, relative to its parent.
161  * @param width The width of the textbox.
162  * @param height The height of the textbox.
163  * @param style The style that the button should use. If this is not
164  * specified, the button will use the global default widget
165  * style.
166  */
167 
168  CNumericEdit(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
169  nxgl_coord_t width, nxgl_coord_t height,
170  CWidgetStyle *style = (CWidgetStyle *)NULL);
171 
172  /**
173  * Destructor.
174  */
175 
176  virtual ~CNumericEdit();
177 
178  /**
179  * Insert the dimensions that this widget wants to have into the rect
180  * passed in as a parameter. All coordinates are relative to the
181  * widget's parent.
182  *
183  * @param rect Reference to a rect to populate with data.
184  */
185 
186  virtual void getPreferredDimensions(CRect &rect) const;
187 
188  /**
189  * Sets the font.
190  *
191  * @param font A pointer to the font to use.
192  */
193 
194  virtual void setFont(CNxFont *font);
195 
196  inline int getValue() const { return m_value; }
197  void setValue(int value);
198 
199  inline int getMaximum() const { return m_maximum; }
200  inline void setMaximum(int value) { m_maximum = value; setValue(m_value); }
201 
202  inline int getMinimum() const { return m_minimum; }
203  inline void setMinimum(int value) { m_minimum = value; setValue(m_value); }
204 
205  inline int getIncrement() const { return m_increment; }
206  inline void setIncrement(int value) { m_increment = value; setValue(m_value); }
207 
208  };
209 }
210 
211 #endif // __cplusplus
212 
213 #endif // __INCLUDE_CLABEL_HXX
virtual void handleActionEvent(const CWidgetEventArgs &e)
virtual void handleClickEvent(const CWidgetEventArgs &e)
void setIncrement(int value)
void setMinimum(int value)
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
virtual void setFont(CNxFont *font)
virtual void getPreferredDimensions(CRect &rect) const
void setMaximum(int value)
virtual void handleDragEvent(const CWidgetEventArgs &e)
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
void setValue(int value)
CNumericEdit(const CNumericEdit &num)