]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/combobox.h
aaf7894177e84390dfd9096d78106ca7d2e7dda4
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxComboBox
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 A combobox is like a combination of an edit control and a listbox.
14 It can be displayed as static list with editable or read-only text field;
15 or a drop-down list with text field; or a drop-down list without a text
16 field depending on the platform and presence of wxCB_READONLY style.
18 A combobox permits a single selection only. Combobox items are numbered
21 If you need a customized combobox, have a look at wxComboCtrl,
22 wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.
24 Please refer to wxTextEntry documentation for the description of methods
25 operating with the text entry part of the combobox and to wxItemContainer
26 for the methods operating with the list of strings. Notice that at least
27 under MSW wxComboBox doesn't behave correctly if it contains strings
28 differing in case only so portable programs should avoid adding such
29 strings to this control.
33 Creates a combobox with a permanently displayed list. Windows only.
35 Creates a combobox with a drop-down list. MSW and Motif only.
37 A combobox with this style behaves like a wxChoice (and may look in
38 the same way as well, although this is platform-dependent), i.e. it
39 allows the user to choose from the list of options but doesn't allow
40 to enter a value not present in the list.
42 Sorts the entries in the list alphabetically.
43 @style{wxTE_PROCESS_ENTER}
44 The control will generate the event @c wxEVT_COMMAND_TEXT_ENTER
45 (otherwise pressing Enter key is either processed internally by the
46 control or used for navigation between dialog controls). Windows
50 @beginEventEmissionTable{wxCommandEvent}
51 @event{EVT_COMBOBOX(id, func)}
52 Process a @c wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on
53 the list is selected. Note that calling GetValue() returns the new
55 @event{EVT_TEXT(id, func)}
56 Process a @c wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text
58 @event{EVT_TEXT_ENTER(id, func)}
59 Process a @c wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
60 the combobox (notice that the combobox must have been created with
61 wxTE_PROCESS_ENTER style to receive this event).
62 @event{EVT_COMBOBOX_DROPDOWN(id, func)}
63 Process a @c wxEVT_COMMAND_COMBOBOX_DROPDOWN event, which is generated
64 when the list box part of the combo box is shown (drops down).
65 Notice that this event is currently only supported by wxMSW and
66 wxGTK with GTK+ 2.10 or later.
67 @event{EVT_COMBOBOX_CLOSEUP(id, func)}
68 Process a @c wxEVT_COMMAND_COMBOBOX_CLOSEUP event, which is generated
69 when the list box of the combo box disappears (closes up). This
70 event is only generated for the same platforms as
71 @c wxEVT_COMMAND_COMBOBOX_DROPDOWN above. Also note that only wxMSW
72 supports adding or deleting items in this event.
79 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
81 class wxComboBox
: public wxControl
,
82 public wxItemContainer
,
92 Constructor, creating and showing a combobox.
95 Parent window. Must not be @NULL.
97 Window identifier. The value wxID_ANY indicates a default value.
99 Initial selection string. An empty string indicates no selection.
100 Notice that for the controls with @c wxCB_READONLY style this
101 string must be one of the valid choices if it is not empty.
104 If ::wxDefaultPosition is specified then a default position is chosen.
107 If ::wxDefaultSize is specified then the window is sized appropriately.
109 Number of strings with which to initialise the control.
111 An array of strings with which to initialise the control.
113 Window style. See wxComboBox.
120 Not supported by wxPerl.
123 @see Create(), wxValidator
125 wxComboBox(wxWindow
* parent
, wxWindowID id
,
126 const wxString
& value
= wxEmptyString
,
127 const wxPoint
& pos
= wxDefaultPosition
,
128 const wxSize
& size
= wxDefaultSize
,
130 const wxString choices
[] = NULL
,
132 const wxValidator
& validator
= wxDefaultValidator
,
133 const wxString
& name
= wxComboBoxNameStr
);
135 Constructor, creating and showing a combobox.
138 Parent window. Must not be @NULL.
140 Window identifier. The value wxID_ANY indicates a default value.
142 Initial selection string. An empty string indicates no selection.
146 Window size. If wxDefaultSize is specified then the window is sized
149 An array of strings with which to initialise the control.
151 Window style. See wxComboBox.
158 Use an array reference for the @a choices parameter.
161 @see Create(), wxValidator
163 wxComboBox(wxWindow
* parent
, wxWindowID id
,
164 const wxString
& value
,
167 const wxArrayString
& choices
,
169 const wxValidator
& validator
= wxDefaultValidator
,
170 const wxString
& name
= wxComboBoxNameStr
);
173 Destructor, destroying the combobox.
175 virtual ~wxComboBox();
179 Creates the combobox for two-step construction. Derived classes should
180 call or replace this function. See wxComboBox() for further details.
182 bool Create(wxWindow
*parent
, wxWindowID id
,
183 const wxString
& value
= wxEmptyString
,
184 const wxPoint
& pos
= wxDefaultPosition
,
185 const wxSize
& size
= wxDefaultSize
,
186 int n
= 0, const wxString choices
[] = (const wxString
*) NULL
,
188 const wxValidator
& validator
= wxDefaultValidator
,
189 const wxString
& name
= wxComboBoxNameStr
);
190 bool Create(wxWindow
*parent
, wxWindowID id
,
191 const wxString
& value
,
194 const wxArrayString
& choices
,
196 const wxValidator
& validator
= wxDefaultValidator
,
197 const wxString
& name
= wxComboBoxNameStr
);
201 Returns the item being selected right now.
203 This function does the same things as wxChoice::GetCurrentSelection()
204 and returns the item currently selected in the dropdown list if it's
205 open or the same thing as wxControlWithItems::GetSelection() otherwise.
207 virtual int GetCurrentSelection() const;
210 Same as wxTextEntry::GetInsertionPoint().
212 @note Under wxMSW, this function always returns 0 if the combobox
213 doesn't have the focus.
215 virtual long GetInsertionPoint() const;
218 IsEmpty() is not available in this class.
220 This method is documented here only to notice that it can't be used
221 with this class because of the ambiguity between the methods with the
222 same name inherited from wxItemContainer and wxTextEntry base classes.
224 Because of this, any attempt to call it results in a compilation error
225 and you should use either IsListEmpty() or IsTextEmpty() depending on
226 what exactly do you want to test.
228 bool IsEmpty() const;
231 Returns true if the list of combobox choices is empty.
233 Use this method instead of (not available in this class) IsEmpty() to
234 test if the list of items is empty.
238 bool IsListEmpty() const;
241 Returns true if the text of the combobox is empty.
243 Use this method instead of (not available in this class) IsEmpty() to
244 test if the text currently entered into the combobox is empty.
248 bool IsTextEmpty() const;
251 Same as wxTextEntry::SetSelection().
253 virtual void SetSelection(long from
, long to
);
256 Sets the text for the combobox text field.
258 Notice that this method will generate a @c wxEVT_COMMAND_TEXT_UPDATED
259 event, use wxTextEntry::ChangeValue() if this is undesirable.
261 @note For a combobox with @c wxCB_READONLY style the string must be in
262 the combobox choices list, otherwise the call to SetValue() is
263 ignored. This is case insensitive.
268 virtual void SetValue(const wxString
& text
);
271 Shows the list box portion of the combo box.
273 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
275 Notice that calling this function will generate a
276 @c wxEVT_COMMAND_COMBOBOX_DROPDOWN event except under wxOSX where
277 generation of this event is not supported at all.
281 virtual void Popup();
284 Hides the list box portion of the combo box.
286 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
288 Notice that calling this function will generate a
289 @c wxEVT_COMMAND_COMBOBOX_CLOSEUP event except under wxOSX where
290 generation of this event is not supported at all.
294 virtual void Dismiss();
296 virtual int GetSelection() const;
297 virtual void GetSelection(long *from
, long *to
) const;
298 virtual void SetSelection(int n
);
299 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
300 virtual wxString
GetString(unsigned int n
) const;
301 virtual wxString
GetStringSelection() const;
304 Changes the text of the specified combobox item.
306 Notice that if the item is the currently selected one, i.e. if its text
307 is displayed in the text part of the combobox, then the text is also
308 replaced with the new @a text.
310 virtual void SetString(unsigned int n
, const wxString
& text
);
312 virtual unsigned int GetCount() const;