NXWidgets  1.19
ilistbox.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/ilistbox.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_ILISTBOX_HXX
71 #define __INCLUDE_ILISTBOX_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 "clistboxdataitem.hxx"
85 
86 /****************************************************************************
87  * Pre-Processor Definitions
88  ****************************************************************************/
89 
90 /****************************************************************************
91  * Abstract Base Classes
92  ****************************************************************************/
93 
94 #if defined(__cplusplus)
95 
96 namespace NXWidgets
97 {
98  /**
99  * Defines the interface for ListBox classes.
100  */
101 
102  class IListBox
103  {
104  public:
105  /**
106  * A virtual destructor is required in order to override the IListBox
107  * destructor. We do this because if we delete IListBox, we want the
108  * destructor of the class that inherits from IListBox to run, not this
109  * one.
110  */
111 
112  virtual ~IListBox(void) { }
113 
114  /**
115  * Add a new option to the widget using default colors.
116  *
117  * @param text Text to show in the option.
118  * @param value The value of the option.
119  */
120 
121  virtual void addOption(const CNxString &text, const uint32_t value) = 0;
122 
123  /**
124  * Add an option to the widget.
125  *
126  * @param option The option to add.
127  */
128 
129  virtual void addOption(CListBoxDataItem *option) = 0;
130 
131  /**
132  * Remove an option from the widget by its index.
133  *
134  * @param index The index of the option to remove.
135  */
136 
137  virtual void removeOption(const int index) = 0;
138 
139  /**
140  * Remove all options from the widget.
141  */
142 
143  virtual void removeAllOptions(void) = 0;
144 
145  /**
146  * Add a new option to the widget.
147  *
148  * @param text Text to show in the option.
149  * @param value The value of the option.
150  * @param normalTextColor Color to draw the text with when not selected.
151  * @param normalBackColor Color to draw the background with when not selected.
152  * @param selectedTextColor Color to draw the text with when selected.
153  * @param selectedBackColor Color to draw the background with when selected.
154  */
155 
156  virtual void addOption(const CNxString &text, const uint32_t value,
157  const nxwidget_pixel_t normalTextColor,
158  const nxwidget_pixel_t normalBackColor,
159  const nxwidget_pixel_t selectedTextColor,
160  const nxwidget_pixel_t selectedBackColor) = 0;
161 
162  /**
163  * Select an option by its index.
164  * Redraws the widget and raises a value changed event.
165  *
166  * @param index The index of the option to select.
167  */
168 
169  virtual void selectOption(const int index) = 0;
170 
171  /**
172  * Select an option by its index.
173  * Redraws the widget and raises a value changed event.
174  *
175  * @param index The index of the option to select.
176  */
177 
178  virtual void deselectOption(const int index) = 0;
179 
180  /**
181  * Select all options. Does nothing if the listbox does not allow
182  * multiple selections. Redraws the widget and raises a value
183  * changed event.
184  */
185 
186  virtual void selectAllOptions(void) = 0;
187 
188  /**
189  * Deselect all options.
190  * Redraws the widget and raises a value changed event.
191  */
192 
193  virtual void deselectAllOptions(void) = 0;
194 
195  /**
196  * Get the selected index. Returns -1 if nothing is selected. If more than one
197  * option is selected, the index of the first selected option is returned.
198  *
199  * @return The selected index.
200  */
201 
202  virtual const int getSelectedIndex(void) const = 0;
203 
204  /**
205  * Sets the selected index. Specify -1 to select nothing. Resets any
206  * other selected options to deselected.
207  * Redraws the widget and raises a value changed event.
208  *
209  * @param index The selected index.
210  */
211 
212  virtual void setSelectedIndex(const int index) = 0;
213 
214  /**
215  * Get the selected option. Returns NULL if nothing is selected.
216  *
217  * @return The selected option.
218  */
219 
220  virtual const CListBoxDataItem *getSelectedOption(void) const = 0;
221 
222  /**
223  * Sets whether multiple selections are possible or not.
224  *
225  * @param allowMultipleSelections True to allow multiple selections.
226  */
227 
228  virtual void setAllowMultipleSelections(const bool allowMultipleSelections) = 0;
229 
230  /**
231  * Sets whether multiple selections are possible or not.
232  *
233  * @return True if multiple selections are allowed.
234  */
235 
236  virtual const bool allowsMultipleSelections(void) const = 0;
237 
238  /**
239  * Get the specified option.
240  *
241  * @return The specified option.
242  */
243 
244  virtual const CListBoxDataItem *getOption(const int index) = 0;
245 
246  /**
247  * Sort the options alphabetically by the text of the options.
248  */
249 
250  virtual void sort(void) = 0;
251 
252  /**
253  * Get the total number of options.
254  *
255  * @return The number of options.
256  */
257 
258  virtual const int getOptionCount(void) const = 0;
259 
260  /**
261  * Get the height of a single option.
262  *
263  * @return The height of an option.
264  */
265 
266  virtual const nxgl_coord_t getOptionHeight(void) const = 0;
267 
268  /**
269  * Sets whether or not items added to the list are automatically sorted on insert or not.
270  *
271  * @param sortInsertedItems True to enable sort on insertion.
272  */
273 
274  virtual void setSortInsertedItems(const bool sortInsertedItems) = 0;
275  };
276 }
277 
278 #endif // __cplusplus
279 
280 #endif // __INCLUDE_ILISTBOX_HXX
281 
virtual void removeOption(const int index)=0
virtual void selectAllOptions(void)=0
virtual const int getOptionCount(void) const =0
virtual const CListBoxDataItem * getOption(const int index)=0
virtual void setAllowMultipleSelections(const bool allowMultipleSelections)=0
uint8_t nxwidget_pixel_t
Definition: nxconfig.hxx:442
virtual void deselectAllOptions(void)=0
virtual const nxgl_coord_t getOptionHeight(void) const =0
virtual void addOption(const CNxString &text, const uint32_t value)=0
virtual void deselectOption(const int index)=0
virtual const CListBoxDataItem * getSelectedOption(void) const =0
virtual void selectOption(const int index)=0
virtual void setSortInsertedItems(const bool sortInsertedItems)=0
virtual void removeAllOptions(void)=0
virtual void sort(void)=0
virtual void setSelectedIndex(const int index)=0
virtual const int getSelectedIndex(void) const =0
virtual ~IListBox(void)
Definition: ilistbox.hxx:112
virtual const bool allowsMultipleSelections(void) const =0