]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/listbox.h
small reorganization; no real change
[wxWidgets.git] / interface / wx / listbox.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.h
3 // Purpose: interface of wxListBox
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxListBox
11
12 A listbox is used to select one or more of a list of strings.
13
14 The strings are displayed in a scrolling box, with the selected string(s)
15 marked in reverse video. A listbox can be single selection (if an item is
16 selected, the previous selection is removed) or multiple selection
17 (clicking an item toggles the item on or off independently of other
18 selections).
19
20 List box elements are numbered from zero.
21 Their number may be limited under some platforms.
22
23 A listbox callback gets an event @c wxEVT_COMMAND_LISTBOX_SELECTED for
24 single clicks, and @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for double clicks.
25
26 @beginStyleTable
27 @style{wxLB_SINGLE}
28 Single-selection list.
29 @style{wxLB_MULTIPLE}
30 Multiple-selection list: the user can toggle multiple items on and off.
31 This is the same as wxLB_EXTENDED in wxGTK2 port.
32 @style{wxLB_EXTENDED}
33 Extended-selection list: the user can extend the selection by using
34 @c SHIFT or @c CTRL keys together with the cursor movement keys or
35 the mouse.
36 @style{wxLB_HSCROLL}
37 Create horizontal scrollbar if contents are too wide (Windows only).
38 @style{wxLB_ALWAYS_SB}
39 Always show a vertical scrollbar.
40 @style{wxLB_NEEDED_SB}
41 Only create a vertical scrollbar if needed.
42 @style{wxLB_SORT}
43 The listbox contents are sorted in alphabetical order.
44 @endStyleTable
45
46 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
47 mutually exclusive and you can specify at most one of them (single selection
48 is the default). See also @ref overview_windowstyles.
49
50 @beginEventTable{wxCommandEvent}
51 @event{EVT_LISTBOX(id, func)}
52 Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
53 list is selected or the selection changes.
54 @event{EVT_LISTBOX_DCLICK(id, func)}
55 Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the listbox
56 is double-clicked.
57 @endEventTable
58
59 @library{wxcore}
60 @category{ctrl}
61 @appearance{listbox.png}
62
63 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
64 */
65 class wxListBox : public wxControlWithItems
66 {
67 public:
68 /**
69 Default constructor.
70 */
71 wxListBox();
72
73 /**
74 Constructor, creating and showing a list box.
75
76 @param parent
77 The parent window.
78 @param id
79 The ID of this control. A value of @c wxID_ANY indicates a default value.
80 @param pos
81 The initial position.
82 @param size
83 The initial size.
84 If wxDefaultSize is specified then the window is sized appropriately.
85 @param n
86 Number of strings with which to initialise the control.
87 @param choices
88 The strings to use to initialize the control.
89 @param style
90 Window style. See wxListBox.
91 @param validator
92 The validator for this control.
93 @param name
94 The name of this class.
95 */
96
97 wxListBox(wxWindow* parent, wxWindowID id,
98 const wxPoint& pos = wxDefaultPosition,
99 const wxSize& size = wxDefaultSize,
100 int n = 0,
101 const wxString choices[] = NULL,
102 long style = 0,
103 const wxValidator& validator = wxDefaultValidator,
104 const wxString& name = wxListBoxNameStr);
105
106 /**
107 Constructor, creating and showing a list box.
108
109 See the other wxListBox() constructor; the only difference is that
110 this overload takes a wxArrayString instead of a pointer to an array
111 of wxString.
112 */
113
114 wxListBox(wxWindow* parent, wxWindowID id,
115 const wxPoint& pos,
116 const wxSize& size,
117 const wxArrayString& choices,
118 long style = 0,
119 const wxValidator& validator = wxDefaultValidator,
120 const wxString& name = wxListBoxNameStr);
121
122 /**
123 Destructor, destroying the list box.
124 */
125 virtual ~wxListBox();
126
127 //@{
128 /**
129 Creates the listbox for two-step construction.
130 See wxListBox() for further details.
131 */
132 bool Create(wxWindow *parent, wxWindowID id,
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
135 int n = 0, const wxString choices[] = NULL,
136 long style = 0,
137 const wxValidator& validator = wxDefaultValidator,
138 const wxString& name = wxListBoxNameStr);
139 bool Create(wxWindow *parent, wxWindowID id,
140 const wxPoint& pos,
141 const wxSize& size,
142 const wxArrayString& choices,
143 long style = 0,
144 const wxValidator& validator = wxDefaultValidator,
145 const wxString& name = wxListBoxNameStr);
146 //@}
147
148 /**
149 Deselects an item in the list box.
150
151 @param n
152 The zero-based item to deselect.
153
154 @remarks This applies to multiple selection listboxes only.
155 */
156 void Deselect(int n);
157
158 /**
159 Fill an array of ints with the positions of the currently selected items.
160
161 @param selections
162 A reference to an wxArrayInt instance that is used to store the result of
163 the query.
164
165 @return The number of selections.
166
167 @remarks Use this with a multiple selection listbox.
168
169 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
170 wxControlWithItems::SetSelection
171 */
172 virtual int GetSelections(wxArrayInt& selections) const;
173
174 //@{
175 /**
176 Returns the item located at @a point, or @c wxNOT_FOUND if there
177 is no item located at @a point.
178
179 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
180
181 @param point
182 Point of item (in client coordinates) to obtain
183
184 @return Item located at point, or wxNOT_FOUND if unimplemented or the
185 item does not exist.
186
187 @since 2.7.0
188 */
189 int HitTest(const wxPoint& point) const;
190 int HitTest(int x, int y) const;
191 //@}
192
193 /**
194 Insert the given number of strings before the specified position.
195
196 @param nItems
197 Number of items in the array items
198 @param items
199 Labels of items to be inserted
200 @param pos
201 Position before which to insert the items: if pos is 0 the
202 items will be inserted in the beginning of the listbox
203 */
204 void InsertItems(unsigned int nItems, const wxString *items,
205 unsigned int pos);
206
207 /**
208 Insert the given number of strings before the specified position.
209
210 @param items
211 Labels of items to be inserted
212 @param pos
213 Position before which to insert the items: if pos is @c 0 the
214 items will be inserted in the beginning of the listbox
215 */
216 void InsertItems(const wxArrayString& items,
217 unsigned int pos);
218
219 /**
220 Determines whether an item is selected.
221
222 @param n
223 The zero-based item index.
224
225 @return @true if the given item is selected, @false otherwise.
226 */
227 virtual bool IsSelected(int n) const;
228
229 /**
230 Clears the list box and adds the given strings to it.
231
232 @param n
233 The number of strings to set.
234 @param choices
235 An array of strings to set.
236 @param clientData
237 Options array of client data pointers
238 */
239 void Set(unsigned int n, const wxString* choices, void *clientData);
240
241 /**
242 Clears the list box and adds the given strings to it.
243 You may free the array from the calling program after this method
244 has been called.
245
246 @param choices
247 An array of strings to set.
248 @param clientData
249 Options array of client data pointers
250 */
251 void Set(const wxArrayString& choices, void *clientData);
252
253 /**
254 Set the specified item to be the first visible item.
255
256 @param n
257 The zero-based item index that should be visible.
258 */
259 void SetFirstItem(int n);
260
261 /**
262 Set the specified item to be the first visible item.
263
264 @param string
265 The string that should be visible.
266 */
267 void SetFirstItem(const wxString& string);
268 };
269