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.
30 Creates a combobox with a permanently displayed list. Windows only.
32 Creates a combobox with a drop-down list. MSW and Motif only.
34 A combobox with this style behaves like a wxChoice (and may look in
35 the same way as well, although this is platform-dependent), i.e. it
36 allows the user to choose from the list of options but doesn't allow
37 to enter a value not present in the list.
39 Sorts the entries in the list alphabetically.
40 @style{wxTE_PROCESS_ENTER}
41 The control will generate the event wxEVT_COMMAND_TEXT_ENTER
42 (otherwise pressing Enter key is either processed internally by the
43 control or used for navigation between dialog controls). Windows
47 @beginEventEmissionTable{wxCommandEvent}
48 @event{EVT_COMBOBOX(id, func)}
49 Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on
50 the list is selected. Note that calling GetValue() returns the new
52 @event{EVT_TEXT(id, func)}
53 Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text
55 @event{EVT_TEXT_ENTER(id, func)}
56 Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
57 the combobox (notice that the combobox must have been created with
58 wxTE_PROCESS_ENTER style to receive this event).
59 @event{EVT_COMBOBOX_DROPDOWN(id, func)}
60 Process a wxEVT_COMMAND_COMBOBOX_DROPDOWN event, which is generated
61 when the list box part of the combo box is shown (drops down).
62 Notice that this event is currently only supported by wxMSW and
63 wxGTK with GTK+ 2.10 or later.
64 @event{EVT_COMBOBOX_CLOSEUP(id, func)}
65 Process a wxEVT_COMMAND_COMBOBOX_CLOSEUP event, which is generated
66 when the list box of the combo box disappears (closes up). This
67 event is only generated for the same platforms as
68 wxEVT_COMMAND_COMBOBOX_DROPDOWN above. Also note that only wxMSW
69 supports adding or deleting items in this event.
74 @appearance{combobox.png}
76 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
78 class wxComboBox
: public wxControl
,
79 public wxItemContainer
,
89 Constructor, creating and showing a combobox.
92 Parent window. Must not be @NULL.
94 Window identifier. The value wxID_ANY indicates a default value.
96 Initial selection string. An empty string indicates no selection.
97 Notice that for the controls with @c wxCB_READONLY style this
98 string must be one of the valid choices if it is not empty.
101 If ::wxDefaultPosition is specified then a default position is chosen.
104 If ::wxDefaultSize is specified then the window is sized appropriately.
106 Number of strings with which to initialise the control.
108 An array of strings with which to initialise the control.
110 Window style. See wxComboBox.
117 The wxComboBox constructor in wxPython reduces the @a n and @a choices
118 arguments are to a single argument, which is a list of strings.
122 Not supported by wxPerl.
125 @see Create(), wxValidator
127 wxComboBox(wxWindow
* parent
, wxWindowID id
,
128 const wxString
& value
= wxEmptyString
,
129 const wxPoint
& pos
= wxDefaultPosition
,
130 const wxSize
& size
= wxDefaultSize
,
132 const wxString choices
[] = NULL
,
134 const wxValidator
& validator
= wxDefaultValidator
,
135 const wxString
& name
= wxComboBoxNameStr
);
137 Constructor, creating and showing a combobox.
140 Parent window. Must not be @NULL.
142 Window identifier. The value wxID_ANY indicates a default value.
144 Initial selection string. An empty string indicates no selection.
148 Window size. If wxDefaultSize is specified then the window is sized
151 An array of strings with which to initialise the control.
153 Window style. See wxComboBox.
160 The wxComboBox constructor in wxPython reduces the @a n and @a choices
161 arguments are to a single argument, which is a list of strings.
165 Use an array reference for the @a choices parameter.
168 @see Create(), wxValidator
170 wxComboBox(wxWindow
* parent
, wxWindowID id
,
171 const wxString
& value
,
174 const wxArrayString
& choices
,
176 const wxValidator
& validator
= wxDefaultValidator
,
177 const wxString
& name
= wxComboBoxNameStr
);
180 Destructor, destroying the combobox.
182 virtual ~wxComboBox();
186 Creates the combobox for two-step construction. Derived classes should
187 call or replace this function. See wxComboBox() for further details.
189 bool Create(wxWindow
*parent
, wxWindowID id
,
190 const wxString
& value
= wxEmptyString
,
191 const wxPoint
& pos
= wxDefaultPosition
,
192 const wxSize
& size
= wxDefaultSize
,
193 int n
= 0, const wxString choices
[] = (const wxString
*) NULL
,
195 const wxValidator
& validator
= wxDefaultValidator
,
196 const wxString
& name
= wxComboBoxNameStr
);
197 bool Create(wxWindow
*parent
, wxWindowID id
,
198 const wxString
& value
,
201 const wxArrayString
& choices
,
203 const wxValidator
& validator
= wxDefaultValidator
,
204 const wxString
& name
= wxComboBoxNameStr
);
208 Returns the item being selected right now.
210 This function does the same things as wxChoice::GetCurrentSelection()
211 and returns the item currently selected in the dropdown list if it's
212 open or the same thing as wxControlWithItems::GetSelection() otherwise.
214 virtual int GetCurrentSelection() const;
217 Same as wxTextEntry::GetInsertionPoint().
219 @note Under wxMSW, this function always returns 0 if the combobox
220 doesn't have the focus.
222 virtual long GetInsertionPoint() const;
225 Same as wxTextEntry::SetSelection().
228 This method is called SetMark() in wxPython, "SetSelection" is kept for
229 wxControlWithItems::SetSelection().
232 virtual void SetSelection(long from
, long to
);
235 Sets the text for the combobox text field.
237 Notice that this method will generate a wxEVT_COMMAND_TEXT_UPDATED
238 event, use wxTextEntry::ChangeValue() if this is undesirable.
240 @note For a combobox with @c wxCB_READONLY style the string must be in
241 the combobox choices list, otherwise the call to SetValue() is
242 ignored. This is case insensitive.
247 virtual void SetValue(const wxString
& text
);
250 Shows the list box portion of the combo box.
252 Currently only implemented in wxMSW and wxGTK.
254 Notice that calling this function will generate a
255 wxEVT_COMMAND_COMBOBOX_DROPDOWN event.
259 virtual void Popup();
262 Hides the list box portion of the combo box.
264 Currently only implemented in wxMSW and wxGTK.
266 Notice that calling this function will generate a
267 wxEVT_COMMAND_COMBOBOX_CLOSEUP event.
271 virtual void Dismiss();