]>
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 | |
11 | @wxheader{listbox.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | A listbox is used to select one or more of a list of strings. The |
14 | 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 | |
16 | is selected, the previous selection is removed) or multiple selection | |
17 | (clicking an item toggles the item on or off independently of other | |
18 | selections). | |
7c913512 | 19 | |
23324ae1 FM |
20 | List box elements are numbered from zero. Their number may be limited |
21 | under some platforms. | |
7c913512 | 22 | |
021b6794 RR |
23 | A listbox callback gets an event wxEVT_COMMAND_LISTBOX_SELECTED for |
24 | single clicks, and 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} |
23324ae1 FM |
30 | Multiple-selection list: the user can toggle multiple items on and |
31 | off. | |
8c6791e4 | 32 | @style{wxLB_EXTENDED} |
23324ae1 FM |
33 | Extended-selection list: the user can select multiple items using |
34 | the SHIFT key and the mouse or special key combinations. | |
8c6791e4 | 35 | @style{wxLB_HSCROLL} |
23324ae1 | 36 | Create horizontal scrollbar if contents are too wide (Windows only). |
8c6791e4 | 37 | @style{wxLB_ALWAYS_SB} |
23324ae1 | 38 | Always show a vertical scrollbar. |
8c6791e4 | 39 | @style{wxLB_NEEDED_SB} |
23324ae1 | 40 | Only create a vertical scrollbar if needed. |
8c6791e4 | 41 | @style{wxLB_SORT} |
23324ae1 FM |
42 | The listbox contents are sorted in alphabetical order. |
43 | @endStyleTable | |
7c913512 | 44 | |
1f1d2182 | 45 | @beginEventTable{wxCommandEvent} |
8c6791e4 | 46 | @event{EVT_LISTBOX(id, func)} |
23324ae1 FM |
47 | Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the |
48 | list is selected or the selection changes. | |
8c6791e4 | 49 | @event{EVT_LISTBOX_DCLICK(id, func)} |
5651b7aa | 50 | Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the |
23324ae1 FM |
51 | listbox is double-clicked. |
52 | @endEventTable | |
7c913512 | 53 | |
23324ae1 FM |
54 | @library{wxcore} |
55 | @category{ctrl} | |
0c7fe6f2 | 56 | <!-- @appearance{listbox.png} --> |
7c913512 | 57 | |
e54c96f1 | 58 | @see wxChoice, wxComboBox, wxListCtrl, wxCommandEvent |
23324ae1 FM |
59 | */ |
60 | class wxListBox : public wxControlWithItems | |
61 | { | |
62 | public: | |
23324ae1 | 63 | /** |
021b6794 RR |
64 | Default constructor. |
65 | */ | |
66 | wxListBox(); | |
67 | ||
68 | /** | |
69 | Constructor | |
3c4f71cc | 70 | |
7c913512 | 71 | @param n |
4cc4bfaf | 72 | Number of strings with which to initialise the control. |
7c913512 | 73 | @param style |
4cc4bfaf | 74 | Window style. See wxListBox. |
23324ae1 | 75 | */ |
021b6794 | 76 | |
7c913512 FM |
77 | wxListBox(wxWindow* parent, wxWindowID id, |
78 | const wxPoint& pos = wxDefaultPosition, | |
79 | const wxSize& size = wxDefaultSize, | |
80 | int n = 0, | |
4cc4bfaf | 81 | const wxString choices[] = NULL, |
7c913512 FM |
82 | long style = 0, |
83 | const wxValidator& validator = wxDefaultValidator, | |
84 | const wxString& name = "listBox"); | |
021b6794 RR |
85 | |
86 | /** | |
87 | Constructor | |
88 | ||
89 | @param choices | |
90 | An array of strings with which to initialise the control. | |
91 | @param style | |
92 | Window style. See wxListBox. | |
93 | */ | |
94 | ||
7c913512 FM |
95 | wxListBox(wxWindow* parent, wxWindowID id, |
96 | const wxPoint& pos, | |
97 | const wxSize& size, | |
98 | const wxArrayString& choices, | |
99 | long style = 0, | |
100 | const wxValidator& validator = wxDefaultValidator, | |
101 | const wxString& name = "listBox"); | |
23324ae1 FM |
102 | |
103 | /** | |
104 | Destructor, destroying the list box. | |
105 | */ | |
106 | ~wxListBox(); | |
107 | ||
108 | //@{ | |
109 | /** | |
110 | Creates the listbox for two-step construction. See wxListBox() | |
111 | for further details. | |
112 | */ | |
113 | bool Create(wxWindow* parent, wxWindowID id, | |
114 | const wxPoint& pos = wxDefaultPosition, | |
115 | const wxSize& size = wxDefaultSize, | |
116 | int n, | |
4cc4bfaf | 117 | const wxString choices[] = NULL, |
23324ae1 FM |
118 | long style = 0, |
119 | const wxValidator& validator = wxDefaultValidator, | |
120 | const wxString& name = "listBox"); | |
7c913512 FM |
121 | bool Create(wxWindow* parent, wxWindowID id, |
122 | const wxPoint& pos, | |
123 | const wxSize& size, | |
124 | const wxArrayString& choices, | |
125 | long style = 0, | |
126 | const wxValidator& validator = wxDefaultValidator, | |
127 | const wxString& name = "listBox"); | |
23324ae1 FM |
128 | //@} |
129 | ||
130 | /** | |
131 | Deselects an item in the list box. | |
3c4f71cc | 132 | |
7c913512 | 133 | @param n |
4cc4bfaf | 134 | The zero-based item to deselect. |
3c4f71cc | 135 | |
23324ae1 FM |
136 | @remarks This applies to multiple selection listboxes only. |
137 | */ | |
138 | void Deselect(int n); | |
139 | ||
140 | /** | |
141 | Fill an array of ints with the positions of the currently selected items. | |
3c4f71cc | 142 | |
7c913512 | 143 | @param selections |
4cc4bfaf FM |
144 | A reference to an wxArrayInt instance that is used to store the result of |
145 | the query. | |
3c4f71cc | 146 | |
d29a9a8a | 147 | @return The number of selections. |
3c4f71cc | 148 | |
23324ae1 | 149 | @remarks Use this with a multiple selection listbox. |
3c4f71cc | 150 | |
4cc4bfaf FM |
151 | @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection, |
152 | wxControlWithItems::SetSelection | |
23324ae1 | 153 | */ |
328f5751 | 154 | int GetSelections(wxArrayInt& selections) const; |
23324ae1 FM |
155 | |
156 | /** | |
157 | Returns the item located at @e point, or @c wxNOT_FOUND if there | |
158 | is no item located at @e point. | |
3c4f71cc | 159 | |
1e24c2af | 160 | It is currently implemented for wxMSW, wxMac and wxGTK2 ports. |
3c4f71cc | 161 | |
7c913512 | 162 | @param point |
4cc4bfaf | 163 | Point of item (in client coordinates) to obtain |
3c4f71cc | 164 | |
d29a9a8a | 165 | @return Item located at point, or wxNOT_FOUND if unimplemented or the |
4cc4bfaf | 166 | item does not exist. |
1e24c2af VS |
167 | |
168 | @since 2.7.0 | |
23324ae1 | 169 | */ |
328f5751 | 170 | int HitTest(const wxPoint point) const; |
23324ae1 | 171 | |
23324ae1 FM |
172 | /** |
173 | Insert the given number of strings before the specified position. | |
3c4f71cc | 174 | |
7c913512 | 175 | @param nItems |
4cc4bfaf | 176 | Number of items in the array items |
7c913512 | 177 | @param items |
4cc4bfaf | 178 | Labels of items to be inserted |
7c913512 | 179 | @param pos |
021b6794 RR |
180 | Position before which to insert the items: if pos is 0 the |
181 | items will be inserted in the beginning of the listbox | |
23324ae1 | 182 | */ |
021b6794 | 183 | void InsertItems(int nItems, const wxString *items, |
23324ae1 | 184 | unsigned int pos); |
021b6794 RR |
185 | |
186 | /** | |
187 | Insert the given number of strings before the specified position. | |
188 | ||
189 | @param items | |
190 | Labels of items to be inserted | |
191 | @param pos | |
192 | Position before which to insert the items: if pos is 0 the | |
193 | items will be inserted in the beginning of the listbox | |
194 | */ | |
195 | void InsertItems(const wxArrayString& items, | |
7c913512 | 196 | unsigned int pos); |
23324ae1 FM |
197 | |
198 | /** | |
199 | Determines whether an item is selected. | |
3c4f71cc | 200 | |
7c913512 | 201 | @param n |
4cc4bfaf | 202 | The zero-based item index. |
3c4f71cc | 203 | |
d29a9a8a | 204 | @return @true if the given item is selected, @false otherwise. |
23324ae1 | 205 | */ |
328f5751 | 206 | bool IsSelected(int n) const; |
23324ae1 | 207 | |
23324ae1 FM |
208 | /** |
209 | Clears the list box and adds the given strings to it. | |
3c4f71cc | 210 | |
7c913512 | 211 | @param n |
4cc4bfaf | 212 | The number of strings to set. |
7c913512 | 213 | @param choices |
4cc4bfaf | 214 | An array of strings to set. |
7c913512 | 215 | @param clientData |
4cc4bfaf | 216 | Options array of client data pointers |
021b6794 RR |
217 | */ |
218 | void Set(int n, const wxString* choices, void **clientData = NULL); | |
3c4f71cc | 219 | |
021b6794 RR |
220 | /** |
221 | Clears the list box and adds the given strings to it. You may | |
222 | free the array from the calling program after this method | |
223 | has been called. | |
224 | ||
225 | @param choices | |
226 | An array of strings to set. | |
227 | @param clientData | |
228 | Options array of client data pointers | |
23324ae1 | 229 | */ |
7c913512 | 230 | void Set(const wxArrayString& choices, |
021b6794 | 231 | void **clientData = NULL); |
23324ae1 | 232 | |
23324ae1 FM |
233 | /** |
234 | Set the specified item to be the first visible item. | |
3c4f71cc | 235 | |
7c913512 | 236 | @param n |
021b6794 RR |
237 | The zero-based item index that should be visible. |
238 | */ | |
239 | void SetFirstItem(int n); | |
240 | ||
241 | /** | |
242 | Set the specified item to be the first visible item. | |
243 | ||
7c913512 | 244 | @param string |
4cc4bfaf | 245 | The string that should be visible. |
23324ae1 | 246 | */ |
7c913512 | 247 | void SetFirstItem(const wxString& string); |
23324ae1 | 248 | }; |
e54c96f1 | 249 |