NXWidgets  1.19
cradiobuttongroup.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cradiobuttongroup.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 most 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_CRADIOBUTTONGROUP_HXX
71 #define __INCLUDE_CRADIOBUTTONGROUP_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 #include <nuttx/nx/nx.h>
84 
85 #include "cnxwidget.hxx"
86 #include "cbutton.hxx"
87 #include "cwidgetstyle.hxx"
88 #include "cwidgeteventhandler.hxx"
89 
90 /****************************************************************************
91  * Pre-Processor Definitions
92  ****************************************************************************/
93 
94 /****************************************************************************
95  * Implementation Classes
96  ****************************************************************************/
97 
98 #if defined(__cplusplus)
99 
100 namespace NXWidgets
101 {
102  class CWidgetControl;
103  class CRadioButton;
104 
105  /**
106  * Container class that holds radio button widgets and tracks their status.
107  * The group provides an easy way to determine which radio button is
108  * selected. Note that, in order to set the "mu" state for a radio button,
109  * it is necessary to set the state via the radio button, not the group.
110  */
111 
113  {
114  protected:
115  CWidgetControl *m_pWidgetControl; /**< The controlling widget */
116  CRadioButton *m_selectedWidget; /**< Pointer to the currently selected radio button */
117 
118  /**
119  * Draw the area of this widget that falls within the clipping region.
120  * Called by the redraw() function to draw all visible regions.
121  * @param port The CGraphicsPort to draw to.
122  * @see redraw()
123  */
124 
125  virtual void drawContents(CGraphicsPort* port);
126 
127  /**
128  * Copy constructor is protected to prevent usage.
129  */
130 
131  inline CRadioButtonGroup(const CRadioButtonGroup &radioButtonGroup) : CNxWidget(radioButtonGroup) { }
132 
133  public:
134 
135  /**
136  * Constructor. Note that the group determines its width and height
137  * from the position and dimensions of its children.
138  *
139  * @param pWidgetControl The controlling widget for the display.
140  * @param x The x coordinate of the group.
141  * @param y The y coordinate of the group.
142  * @param style The style that the button should use. If this is not
143  * specified, the button will use the global default widget
144  * style.
145  */
146 
147  CRadioButtonGroup(CWidgetControl *pWidgetControl,
148  nxgl_coord_t x, nxgl_coord_t y,
149  CWidgetStyle *style = (CWidgetStyle *)NULL);
150 
151  /**
152  * Destructor.
153  */
154 
156 
157  /**
158  * Simple method for adding a new radio button to the group.
159  * This should be used in preference to the usual addWidget() method,
160  * as this method automatically resizes the group.
161  *
162  * @param x The x coordinate of the new button, relative to this
163  * widget.
164  * @param y The y coordinate of the new button, relative to this
165  * widget.
166  * @param width The width of the new button.
167  * @param height The height of the new button.
168  */
169 
170  CRadioButton *newRadioButton(nxgl_coord_t x, nxgl_coord_t y,
171  nxgl_coord_t width, nxgl_coord_t height);
172 
173  /**
174  * Gets a pointer to the selected widget.
175  *
176  * @return Pointer to the selected widget.
177  */
178 
179  virtual const CRadioButton *getSelectedWidget(void) const;
180 
181  /**
182  * Gets the index of the selected widget.
183  *
184  * @return The index of the selected widget.
185  */
186 
187  virtual const int getSelectedIndex(void) const;
188 
189  /**
190  * Sets the selected radio button to the supplied widget.
191  *
192  * @param widget The radio button to select.
193  */
194 
195  virtual void setSelectedWidget(CRadioButton *widget);
196 
197  /**
198  * Selects the widget at the specified index.
199  *
200  * @param index The index of the widget to select.
201  */
202 
203  virtual void setSelectedIndex(int index);
204 
205  /**
206  * Insert the dimensions that this widget wants to have into the rect
207  * passed in as a parameter. All coordinates are relative to the
208  * widget's parent. Value is based on the length of the largest string
209  * in the set of options.
210  *
211  * @param rect Reference to a rect to populate with data.
212  */
213 
214  virtual void getPreferredDimensions(CRect &rect) const;
215 
216  /**
217  * Handle a mouse click event.
218  *
219  * @param e The event data.
220  */
221 
222  virtual void handleClickEvent(const CWidgetEventArgs &e);
223 
224  /**
225  * Handle a mouse double-click event.
226  *
227  * @param e The event data.
228  */
229 
230  virtual void handleDoubleClickEvent(const CWidgetEventArgs &e);
231 
232  /**
233  * Handle a mouse button release event that occurred within the bounds of
234  * the source widget.
235  * @param e The event data.
236  */
237 
238  virtual void handleReleaseEvent(const CWidgetEventArgs &e);
239 
240  /**
241  * Handle a mouse button release event that occurred outside the bounds of
242  * the source widget.
243  *
244  * @param e The event data.
245  */
246 
247  virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e);
248  };
249 }
250 
251 #endif // __cplusplus
252 
253 #endif // __INCLUDE_CRADIOBUTTONGROUP_HXX
CRadioButtonGroup(const CRadioButtonGroup &radioButtonGroup)
virtual void setSelectedIndex(int index)
virtual const int getSelectedIndex(void) const
CRadioButton * newRadioButton(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height)
virtual void getPreferredDimensions(CRect &rect) const
virtual void handleDoubleClickEvent(const CWidgetEventArgs &e)
virtual void setSelectedWidget(CRadioButton *widget)
virtual void drawContents(CGraphicsPort *port)
virtual const CRadioButton * getSelectedWidget(void) const
virtual void handleReleaseOutsideEvent(const CWidgetEventArgs &e)
virtual void handleReleaseEvent(const CWidgetEventArgs &e)
virtual void handleClickEvent(const CWidgetEventArgs &e)