NXWidgets: cnumericedit.hxx Source File

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
115 class CNumericEdit : public CNxWidget, public CWidgetEventHandler
116 {
117 protected:
118 CLabel *m_label;
119 CButton *m_button_minus;
120 CButton *m_button_plus;
121 CNxTimer *m_timer;
122 int m_value;
123 int m_minimum;
124 int m_maximum;
125 int m_increment;
126 int m_timercount;
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
NXWidgets::CNumericEdit::getValue
int getValue() const
Definition: cnumericedit.hxx:196
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CNumericEdit::~CNumericEdit
virtual ~CNumericEdit()
Definition: cnumericedit.cxx:159
NXWidgets::CNumericEdit::handleActionEvent
virtual void handleActionEvent(const CWidgetEventArgs &e)
Definition: cnumericedit.cxx:213
NXWidgets::CWidgetStyle
Definition: cwidgetstyle.hxx:125
NXWidgets::CWidgetEventHandler
Definition: cwidgeteventhandler.hxx:103
NXWidgets::CNumericEdit::getMaximum
int getMaximum() const
Definition: cnumericedit.hxx:199
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CNumericEdit::handleClickEvent
virtual void handleClickEvent(const CWidgetEventArgs &e)
Definition: cnumericedit.cxx:181
NXWidgets::CNumericEdit::getMinimum
int getMinimum() const
Definition: cnumericedit.hxx:202
NXWidgets::CNumericEdit::setIncrement
void setIncrement(int value)
Definition: cnumericedit.hxx:206
NXWidgets::CNumericEdit::m_timercount
int m_timercount
Definition: cnumericedit.hxx:126
cwidgetstyle.hxx
NXWidgets::CNumericEdit
Definition: cnumericedit.hxx:115
NXWidgets::CNumericEdit::setMinimum
void setMinimum(int value)
Definition: cnumericedit.hxx:203
NXWidgets::CNumericEdit::getIncrement
int getIncrement() const
Definition: cnumericedit.hxx:205
NXWidgets::CNumericEdit::handleReleaseOutsideEvent
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
Definition: cnumericedit.cxx:205
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNumericEdit::m_minimum
int m_minimum
Definition: cnumericedit.hxx:123
NXWidgets::CNxTimer
Definition: cnxtimer.hxx:110
NXWidgets::CNxFont
Definition: cnxfont.hxx:70
NXWidgets::CNumericEdit::setFont
virtual void setFont(CNxFont *font)
Definition: cnumericedit.cxx:172
NXWidgets::CNumericEdit::getPreferredDimensions
virtual void getPreferredDimensions(CRect &rect) const
Definition: cnumericedit.cxx:168
NXWidgets::CNumericEdit::setMaximum
void setMaximum(int value)
Definition: cnumericedit.hxx:200
NXWidgets::CNumericEdit::handleDragEvent
virtual void handleDragEvent(const CWidgetEventArgs &e)
Definition: cnumericedit.cxx:248
NXWidgets::CNumericEdit::onResize
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cnumericedit.cxx:177
NXWidgets::CNumericEdit::m_increment
int m_increment
Definition: cnumericedit.hxx:125
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
NXWidgets::CRect
Definition: crect.hxx:101
NXWidgets::CNumericEdit::m_button_minus
CButton * m_button_minus
Definition: cnumericedit.hxx:119
NXWidgets::CNumericEdit::handleReleaseEvent
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
Definition: cnumericedit.cxx:197
NXWidgets::CNumericEdit::setValue
void setValue(int value)
Definition: cnumericedit.cxx:256
NXWidgets::CNumericEdit::m_button_plus
CButton * m_button_plus
Definition: cnumericedit.hxx:120
NXWidgets::CLabel
Definition: clabel.hxx:112
NXWidgets::CNumericEdit::m_label
CLabel * m_label
Definition: cnumericedit.hxx:118
NXWidgets::CNumericEdit::m_maximum
int m_maximum
Definition: cnumericedit.hxx:124
NXWidgets::CNumericEdit::CNumericEdit
CNumericEdit(const CNumericEdit &num)
Definition: cnumericedit.hxx:151
cnxwidget.hxx
cnxstring.hxx
NXWidgets::CButton
Definition: cbutton.hxx:109
NXWidgets::CNumericEdit::m_timer
CNxTimer * m_timer
Definition: cnumericedit.hxx:121
NXWidgets::CNumericEdit::m_value
int m_value
Definition: cnumericedit.hxx:122