NXWidgets  1.19
ccheckbox.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/ccheckbox.hxx
3  *
4  * Copyright (C) 2012 Gregory Nutt. All rights reserved.
5  * Author: Gregory Nutt <gnutt@nuttx.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18  * me be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************
35  *
36  * Portions of this package derive from Woopsi (http://woopsi.org/) and
37  * portions are original efforts. It is difficult to determine at this
38  * point what parts are original efforts and which parts derive from Woopsi.
39  * However, in any event, the work of Antony Dzeryn will be acknowledged
40  * in all NxWidget files. Thanks Antony!
41  *
42  * Copyright (c) 2007-2011, Antony Dzeryn
43  * All rights reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions are met:
47  *
48  * * Redistributions of source code must retain the above copyright
49  * notice, this list of conditions and the following disclaimer.
50  * * Redistributions in binary form must reproduce the above copyright
51  * notice, this list of conditions and the following disclaimer in the
52  * documentation and/or other materials provided with the distribution.
53  * * Neither the names "Woopsi", "Simian Zombie" nor the
54  * names of its contributors may be used to endorse or promote products
55  * derived from this software without specific prior written permission.
56  *
57  * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60  * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  ****************************************************************************/
69 
70 #ifndef __INCLUDE_CCHECKBOX_HXX
71 #define __INCLUDE_CCHECKBOX_HXX
72 
73 /****************************************************************************
74  * Included Files
75  ****************************************************************************/
76 
77 #include <nuttx/config.h>
78 
79 #include <stdint.h>
80 #include <stdbool.h>
81 
82 #include <nuttx/nx/nxglib.h>
83 
84 #include "cbutton.hxx"
85 #include "cwidgetstyle.hxx"
86 
87 /****************************************************************************
88  * Pre-Processor Definitions
89  ****************************************************************************/
90 
91 /****************************************************************************
92  * Implementation Classes
93  ****************************************************************************/
94 
95 #if defined(__cplusplus)
96 
97 namespace NXWidgets
98 {
99  class CWidgetControl;
100 
101  /**
102  * Class representing a checkbox. Like radio buttons, checkboxes
103  * are tri-state - off, on and "mu". The mu state cannot be enabled by
104  * a user - it can only be set by the developer.
105  */
106 
107  class CCheckBox : public CButton
108  {
109  public:
110 
111  /**
112  * Enum listing all possible checkbox states.
113  */
114 
116  {
117  CHECK_BOX_STATE_OFF = 0, /**< Checkbox is unticked */
118  CHECK_BOX_STATE_ON = 1, /**< Checkbox is ticked */
119  CHECK_BOX_STATE_MU = 2 /**< Checkbox is in the third state */
120  };
121 
122  protected:
123  CheckBoxState m_state; /**< The state of the checkbox */
124 
125  /**
126  * Draw the area of this widget that falls within the clipping region.
127  * Called by the redraw() function to draw all visible regions.
128  *
129  * @param port The CGraphicsPort to draw to.
130  * @see redraw()
131  */
132 
133  virtual void drawContents(CGraphicsPort *port);
134 
135  /**
136  * Draw the area of this widget that falls within the clipping region.
137  * Called by the redraw() function to draw all visible regions.
138  *
139  * @param port The CGraphicsPort to draw to.
140  * @see redraw()
141  */
142 
143  virtual void drawBorder(CGraphicsPort *port);
144 
145  /**
146  * Toggles the state of the checkbox.
147  *
148  * @param x The x coordinate of the click.
149  * @param y The y coordinate of the click.
150  */
151 
152  virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
153 
154  /**
155  * Copy constructor is protected to prevent usage.
156  */
157 
158  inline CCheckBox(const CCheckBox &checkBox) : CButton(checkBox) { }
159 
160  public:
161 
162  /**
163  * Constructor.
164  *
165  * @param pWidgetControl The widget control for the display.
166  * @param x The x coordinate of the checkbox, relative to its parent.
167  * @param y The y coordinate of the checkbox, relative to its parent.
168  * @param width The width of the checkbox.
169  * @param height The height of the checkbox.
170  * @param style The style that the widget should use. If this is not
171  * specified, the widget will use the values stored in the global
172  * g_defaultWidgetStyle object. The widget will copy the properties of
173  * the style into its own internal style object.
174  */
175 
176  CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
177  nxgl_coord_t width, nxgl_coord_t height,
178  CWidgetStyle *style = (CWidgetStyle *)NULL);
179 
180  /**
181  * Destructor.
182  */
183 
184  virtual inline ~CCheckBox(void) { }
185 
186  /**
187  * Get the current state of the checkbox.
188  *
189  * @return The state of the checkbox.
190  */
191 
192  virtual inline const CheckBoxState getState(void) const
193  {
194  return m_state;
195  }
196 
197  /**
198  * Set the state of the checkbox.
199  *
200  * @param state The new checkbox state.
201  */
202 
203  virtual void setState(CheckBoxState state);
204  };
205 }
206 
207 #endif // __cplusplus
208 
209 #endif // __INCLUDE_CCHECKBOX_HXX
210 
virtual void drawContents(CGraphicsPort *port)
Definition: ccheckbox.cxx:152
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
Definition: ccheckbox.cxx:255
CCheckBox(const CCheckBox &checkBox)
Definition: ccheckbox.hxx:158
virtual void setState(CheckBoxState state)
Definition: ccheckbox.cxx:134
virtual void drawBorder(CGraphicsPort *port)
Definition: ccheckbox.cxx:219
virtual ~CCheckBox(void)
Definition: ccheckbox.hxx:184
CheckBoxState m_state
Definition: ccheckbox.hxx:123
virtual const CheckBoxState getState(void) const
Definition: ccheckbox.hxx:192