]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listbox.h | |
e54c96f1 | 3 | // Purpose: interface of wxListBox |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxListBox | |
7c913512 | 11 | |
320ab87c FM |
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 | |
23324ae1 FM |
17 | (clicking an item toggles the item on or off independently of other |
18 | selections). | |
7c913512 | 19 | |
320ab87c FM |
20 | List box elements are numbered from zero. |
21 | Their number may be limited under some platforms. | |
7c913512 | 22 | |
320ab87c FM |
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. | |
7c913512 | 25 | |
23324ae1 | 26 | @beginStyleTable |
8c6791e4 | 27 | @style{wxLB_SINGLE} |
23324ae1 | 28 | Single-selection list. |
8c6791e4 | 29 | @style{wxLB_MULTIPLE} |
320ab87c FM |
30 | Multiple-selection list: the user can toggle multiple items on and off. |
31 | This is the same as wxLB_EXTENDED in wxGTK2 port. | |
8c6791e4 | 32 | @style{wxLB_EXTENDED} |
b4de6e0d VZ |
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. | |
8c6791e4 | 36 | @style{wxLB_HSCROLL} |
23324ae1 | 37 | Create horizontal scrollbar if contents are too wide (Windows only). |
8c6791e4 | 38 | @style{wxLB_ALWAYS_SB} |
23324ae1 | 39 | Always show a vertical scrollbar. |
8c6791e4 | 40 | @style{wxLB_NEEDED_SB} |
23324ae1 | 41 | Only create a vertical scrollbar if needed. |
8c6791e4 | 42 | @style{wxLB_SORT} |
23324ae1 FM |
43 | The listbox contents are sorted in alphabetical order. |
44 | @endStyleTable | |
7c913512 | 45 | |
320ab87c FM |
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 | ||
1f1d2182 | 50 | @beginEventTable{wxCommandEvent} |
8c6791e4 | 51 | @event{EVT_LISTBOX(id, func)} |
23324ae1 FM |
52 | Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the |
53 | list is selected or the selection changes. | |
8c6791e4 | 54 | @event{EVT_LISTBOX_DCLICK(id, func)} |
320ab87c FM |
55 | Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the listbox |
56 | is double-clicked. | |
23324ae1 | 57 | @endEventTable |
7c913512 | 58 | |
23324ae1 FM |
59 | @library{wxcore} |
60 | @category{ctrl} | |
7e59b885 | 61 | @appearance{listbox.png} |
7c913512 | 62 | |
d23914f8 | 63 | @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent |
23324ae1 FM |
64 | */ |
65 | class wxListBox : public wxControlWithItems | |
66 | { | |
67 | public: | |
23324ae1 | 68 | /** |
021b6794 RR |
69 | Default constructor. |
70 | */ | |
71 | wxListBox(); | |
320ab87c | 72 | |
021b6794 | 73 | /** |
320ab87c | 74 | Constructor, creating and showing a list box. |
3c4f71cc | 75 | |
320ab87c FM |
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. | |
7c913512 | 85 | @param n |
4cc4bfaf | 86 | Number of strings with which to initialise the control. |
320ab87c FM |
87 | @param choices |
88 | The strings to use to initialize the control. | |
7c913512 | 89 | @param style |
4cc4bfaf | 90 | Window style. See wxListBox. |
320ab87c FM |
91 | @param validator |
92 | The validator for this control. | |
93 | @param name | |
94 | The name of this class. | |
23324ae1 | 95 | */ |
320ab87c | 96 | |
7c913512 FM |
97 | wxListBox(wxWindow* parent, wxWindowID id, |
98 | const wxPoint& pos = wxDefaultPosition, | |
99 | const wxSize& size = wxDefaultSize, | |
100 | int n = 0, | |
4cc4bfaf | 101 | const wxString choices[] = NULL, |
7c913512 FM |
102 | long style = 0, |
103 | const wxValidator& validator = wxDefaultValidator, | |
320ab87c FM |
104 | const wxString& name = wxListBoxNameStr); |
105 | ||
021b6794 | 106 | /** |
320ab87c | 107 | Constructor, creating and showing a list box. |
021b6794 | 108 | |
320ab87c FM |
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. | |
021b6794 | 112 | */ |
320ab87c | 113 | |
7c913512 FM |
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, | |
320ab87c | 120 | const wxString& name = wxListBoxNameStr); |
23324ae1 FM |
121 | |
122 | /** | |
123 | Destructor, destroying the list box. | |
124 | */ | |
adaaa686 | 125 | virtual ~wxListBox(); |
23324ae1 FM |
126 | |
127 | //@{ | |
128 | /** | |
320ab87c FM |
129 | Creates the listbox for two-step construction. |
130 | See wxListBox() for further details. | |
23324ae1 | 131 | */ |
57bf907d | 132 | bool Create(wxWindow *parent, wxWindowID id, |
23324ae1 FM |
133 | const wxPoint& pos = wxDefaultPosition, |
134 | const wxSize& size = wxDefaultSize, | |
57bf907d | 135 | int n = 0, const wxString choices[] = NULL, |
23324ae1 FM |
136 | long style = 0, |
137 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d FM |
138 | const wxString& name = wxListBoxNameStr); |
139 | bool Create(wxWindow *parent, wxWindowID id, | |
7c913512 FM |
140 | const wxPoint& pos, |
141 | const wxSize& size, | |
142 | const wxArrayString& choices, | |
143 | long style = 0, | |
144 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d | 145 | const wxString& name = wxListBoxNameStr); |
23324ae1 FM |
146 | //@} |
147 | ||
148 | /** | |
149 | Deselects an item in the list box. | |
3c4f71cc | 150 | |
7c913512 | 151 | @param n |
4cc4bfaf | 152 | The zero-based item to deselect. |
3c4f71cc | 153 | |
23324ae1 FM |
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. | |
3c4f71cc | 160 | |
7c913512 | 161 | @param selections |
4cc4bfaf | 162 | A reference to an wxArrayInt instance that is used to store the result of |
320ab87c | 163 | the query. |
3c4f71cc | 164 | |
d29a9a8a | 165 | @return The number of selections. |
3c4f71cc | 166 | |
23324ae1 | 167 | @remarks Use this with a multiple selection listbox. |
3c4f71cc | 168 | |
4cc4bfaf FM |
169 | @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection, |
170 | wxControlWithItems::SetSelection | |
23324ae1 | 171 | */ |
adaaa686 | 172 | virtual int GetSelections(wxArrayInt& selections) const; |
23324ae1 FM |
173 | |
174 | /** | |
320ab87c FM |
175 | Returns the item located at @a point, or @c wxNOT_FOUND if there |
176 | is no item located at @a point. | |
3c4f71cc | 177 | |
1e24c2af | 178 | It is currently implemented for wxMSW, wxMac and wxGTK2 ports. |
3c4f71cc | 179 | |
7c913512 | 180 | @param point |
4cc4bfaf | 181 | Point of item (in client coordinates) to obtain |
3c4f71cc | 182 | |
d29a9a8a | 183 | @return Item located at point, or wxNOT_FOUND if unimplemented or the |
320ab87c | 184 | item does not exist. |
1e24c2af VS |
185 | |
186 | @since 2.7.0 | |
23324ae1 | 187 | */ |
320ab87c | 188 | int HitTest(const wxPoint& point) const; |
d4624460 FM |
189 | |
190 | /** | |
191 | @overload | |
192 | */ | |
0a03dc7a | 193 | int HitTest(int x, int y) const; |
23324ae1 | 194 | |
23324ae1 FM |
195 | /** |
196 | Insert the given number of strings before the specified position. | |
3c4f71cc | 197 | |
7c913512 | 198 | @param nItems |
4cc4bfaf | 199 | Number of items in the array items |
7c913512 | 200 | @param items |
4cc4bfaf | 201 | Labels of items to be inserted |
7c913512 | 202 | @param pos |
021b6794 RR |
203 | Position before which to insert the items: if pos is 0 the |
204 | items will be inserted in the beginning of the listbox | |
23324ae1 | 205 | */ |
0a98423e | 206 | void InsertItems(unsigned int nItems, const wxString *items, |
23324ae1 | 207 | unsigned int pos); |
021b6794 RR |
208 | |
209 | /** | |
210 | Insert the given number of strings before the specified position. | |
211 | ||
212 | @param items | |
213 | Labels of items to be inserted | |
214 | @param pos | |
320ab87c | 215 | Position before which to insert the items: if pos is @c 0 the |
021b6794 RR |
216 | items will be inserted in the beginning of the listbox |
217 | */ | |
218 | void InsertItems(const wxArrayString& items, | |
7c913512 | 219 | unsigned int pos); |
23324ae1 FM |
220 | |
221 | /** | |
222 | Determines whether an item is selected. | |
3c4f71cc | 223 | |
7c913512 | 224 | @param n |
4cc4bfaf | 225 | The zero-based item index. |
3c4f71cc | 226 | |
d29a9a8a | 227 | @return @true if the given item is selected, @false otherwise. |
23324ae1 | 228 | */ |
adaaa686 | 229 | virtual bool IsSelected(int n) const; |
23324ae1 | 230 | |
23324ae1 FM |
231 | /** |
232 | Clears the list box and adds the given strings to it. | |
3c4f71cc | 233 | |
7c913512 | 234 | @param n |
4cc4bfaf | 235 | The number of strings to set. |
7c913512 | 236 | @param choices |
4cc4bfaf | 237 | An array of strings to set. |
7c913512 | 238 | @param clientData |
4cc4bfaf | 239 | Options array of client data pointers |
021b6794 | 240 | */ |
0a98423e | 241 | void Set(unsigned int n, const wxString* choices, void *clientData); |
3c4f71cc | 242 | |
021b6794 | 243 | /** |
320ab87c FM |
244 | Clears the list box and adds the given strings to it. |
245 | You may free the array from the calling program after this method | |
021b6794 RR |
246 | has been called. |
247 | ||
248 | @param choices | |
249 | An array of strings to set. | |
250 | @param clientData | |
251 | Options array of client data pointers | |
23324ae1 | 252 | */ |
0a98423e | 253 | void Set(const wxArrayString& choices, void *clientData); |
23324ae1 | 254 | |
23324ae1 FM |
255 | /** |
256 | Set the specified item to be the first visible item. | |
3c4f71cc | 257 | |
7c913512 | 258 | @param n |
021b6794 RR |
259 | The zero-based item index that should be visible. |
260 | */ | |
261 | void SetFirstItem(int n); | |
262 | ||
263 | /** | |
264 | Set the specified item to be the first visible item. | |
265 | ||
7c913512 | 266 | @param string |
4cc4bfaf | 267 | The string that should be visible. |
23324ae1 | 268 | */ |
7c913512 | 269 | void SetFirstItem(const wxString& string); |
23324ae1 | 270 | }; |
e54c96f1 | 271 |