]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/listbox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxListBox
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 A listbox is used to select one or more of a list of strings.
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
20 List box elements are numbered from zero.
21 Their number may be limited under some platforms.
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.
28 Single-selection list.
30 Multiple-selection list: the user can toggle multiple items on and off.
31 This is the same as wxLB_EXTENDED in wxGTK2 port.
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
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.
43 Don't create vertical scrollbar (wxMSW only).
45 The listbox contents are sorted in alphabetical order.
48 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
49 mutually exclusive and you can specify at most one of them (single selection
50 is the default). See also @ref overview_windowstyles.
52 @beginEventEmissionTable{wxCommandEvent}
53 @event{EVT_LISTBOX(id, func)}
54 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
55 list is selected or the selection changes.
56 @event{EVT_LISTBOX_DCLICK(id, func)}
57 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
63 @appearance{listbox.png}
65 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
67 class wxListBox
: public wxControlWithItems
76 Constructor, creating and showing a list box.
81 The ID of this control. A value of @c wxID_ANY indicates a default value.
84 If ::wxDefaultPosition is specified then a default position is chosen.
87 If ::wxDefaultSize is specified then the window is sized appropriately.
89 Number of strings with which to initialise the control.
91 The strings to use to initialize the control.
93 Window style. See wxListBox.
95 The validator for this control.
97 The name of this class.
100 Not supported by wxPerl.
104 wxListBox(wxWindow
* parent
, wxWindowID id
,
105 const wxPoint
& pos
= wxDefaultPosition
,
106 const wxSize
& size
= wxDefaultSize
,
108 const wxString choices
[] = NULL
,
110 const wxValidator
& validator
= wxDefaultValidator
,
111 const wxString
& name
= wxListBoxNameStr
);
114 Constructor, creating and showing a list box.
116 See the other wxListBox() constructor; the only difference is that
117 this overload takes a wxArrayString instead of a pointer to an array
121 Use an array reference for the @a choices parameter.
125 wxListBox(wxWindow
* parent
, wxWindowID id
,
128 const wxArrayString
& choices
,
130 const wxValidator
& validator
= wxDefaultValidator
,
131 const wxString
& name
= wxListBoxNameStr
);
134 Destructor, destroying the list box.
136 virtual ~wxListBox();
140 Creates the listbox for two-step construction.
141 See wxListBox() for further details.
143 bool Create(wxWindow
*parent
, wxWindowID id
,
144 const wxPoint
& pos
= wxDefaultPosition
,
145 const wxSize
& size
= wxDefaultSize
,
146 int n
= 0, const wxString choices
[] = NULL
,
148 const wxValidator
& validator
= wxDefaultValidator
,
149 const wxString
& name
= wxListBoxNameStr
);
150 bool Create(wxWindow
*parent
, wxWindowID id
,
153 const wxArrayString
& choices
,
155 const wxValidator
& validator
= wxDefaultValidator
,
156 const wxString
& name
= wxListBoxNameStr
);
160 Deselects an item in the list box.
163 The zero-based item to deselect.
165 @remarks This applies to multiple selection listboxes only.
167 void Deselect(int n
);
169 virtual void SetSelection(int n
);
171 virtual int GetSelection() const;
173 virtual bool SetStringSelection(const wxString
& s
, bool select
);
174 virtual bool SetStringSelection(const wxString
& s
);
177 Fill an array of ints with the positions of the currently selected items.
180 A reference to an wxArrayInt instance that is used to store the result of
183 @return The number of selections.
185 @remarks Use this with a multiple selection listbox.
188 In wxPerl this method takes no parameters and return the
189 selected items as a list.
192 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
193 wxControlWithItems::SetSelection
195 virtual int GetSelections(wxArrayInt
& selections
) const;
198 Returns the item located at @a point, or @c wxNOT_FOUND if there
199 is no item located at @a point.
201 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
204 Point of item (in client coordinates) to obtain
206 @return Item located at point, or wxNOT_FOUND if unimplemented or the
211 int HitTest(const wxPoint
& point
) const;
216 int HitTest(int x
, int y
) const;
219 Insert the given number of strings before the specified position.
222 Number of items in the array items
224 Labels of items to be inserted
226 Position before which to insert the items: if pos is 0 the
227 items will be inserted in the beginning of the listbox
230 Not supported by wxPerl.
233 void InsertItems(unsigned int nItems
, const wxString
*items
,
237 Insert the given number of strings before the specified position.
240 Labels of items to be inserted
242 Position before which to insert the items: if pos is @c 0 the
243 items will be inserted in the beginning of the listbox
246 Use an array reference for the @a items parameter.
249 void InsertItems(const wxArrayString
& items
,
253 Determines whether an item is selected.
256 The zero-based item index.
258 @return @true if the given item is selected, @false otherwise.
260 virtual bool IsSelected(int n
) const;
263 Set the specified item to be the first visible item.
266 The zero-based item index that should be visible.
268 void SetFirstItem(int n
);
271 Set the specified item to be the first visible item.
274 The string that should be visible.
276 void SetFirstItem(const wxString
& string
);
279 Ensure that the item with the given index is currently shown.
281 Scroll the listbox if necessary.
283 This method is currently only implemented in wxGTK and wxOSX and does
284 nothing in other ports.
288 virtual void EnsureVisible(int n
);
291 Return true if the listbox has ::wxLB_SORT style.
293 This method is mostly meant for internal use only.
295 virtual bool IsSorted() const;
298 // NOTE: Phoenix needs to see the implementation of pure virtuals so it
299 // knows that this class is not abstract.
300 virtual unsigned int GetCount() const;
301 virtual wxString
GetString(unsigned int n
) const;
302 virtual void SetString(unsigned int n
, const wxString
& s
);
303 virtual int FindString(const wxString
& s
, bool bCase
= false) const;