]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/combobox.h
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_TEXT_ENTER
45 (otherwise pressing Enter key is either processed internally by the
46 control or used for navigation between dialog controls).
49 @beginEventEmissionTable{wxCommandEvent}
50 @event{EVT_COMBOBOX(id, func)}
51 Process a @c wxEVT_COMBOBOX event, when an item on
52 the list is selected. Note that calling GetValue() returns the new
54 @event{EVT_TEXT(id, func)}
55 Process a @c wxEVT_TEXT event, when the combobox text
57 @event{EVT_TEXT_ENTER(id, func)}
58 Process a @c wxEVT_TEXT_ENTER event, when RETURN is pressed in
59 the combobox (notice that the combobox must have been created with
60 wxTE_PROCESS_ENTER style to receive this event).
61 @event{EVT_COMBOBOX_DROPDOWN(id, func)}
62 Process a @c wxEVT_COMBOBOX_DROPDOWN event, which is generated
63 when the list box part of the combo box is shown (drops down).
64 Notice that this event is currently only supported by wxMSW and
65 wxGTK with GTK+ 2.10 or later.
66 @event{EVT_COMBOBOX_CLOSEUP(id, func)}
67 Process a @c wxEVT_COMBOBOX_CLOSEUP event, which is generated
68 when the list box of the combo box disappears (closes up). This
69 event is only generated for the same platforms as
70 @c wxEVT_COMBOBOX_DROPDOWN above. Also note that only wxMSW
71 supports adding or deleting items in this event.
78 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
80 class wxComboBox
: public wxControl
,
81 public wxItemContainer
,
91 Constructor, creating and showing a combobox.
94 Parent window. Must not be @NULL.
96 Window identifier. The value wxID_ANY indicates a default value.
98 Initial selection string. An empty string indicates no selection.
99 Notice that for the controls with @c wxCB_READONLY style this
100 string must be one of the valid choices if it is not empty.
103 If ::wxDefaultPosition is specified then a default position is chosen.
106 If ::wxDefaultSize is specified then the window is sized appropriately.
108 Number of strings with which to initialise the control.
110 An array of strings with which to initialise the control.
112 Window style. See wxComboBox.
119 Not supported by wxPerl.
122 @see Create(), wxValidator
124 wxComboBox(wxWindow
* parent
, wxWindowID id
,
125 const wxString
& value
= wxEmptyString
,
126 const wxPoint
& pos
= wxDefaultPosition
,
127 const wxSize
& size
= wxDefaultSize
,
129 const wxString choices
[] = NULL
,
131 const wxValidator
& validator
= wxDefaultValidator
,
132 const wxString
& name
= wxComboBoxNameStr
);
134 Constructor, creating and showing a combobox.
137 Parent window. Must not be @NULL.
139 Window identifier. The value wxID_ANY indicates a default value.
141 Initial selection string. An empty string indicates no selection.
145 Window size. If wxDefaultSize is specified then the window is sized
148 An array of strings with which to initialise the control.
150 Window style. See wxComboBox.
157 Use an array reference for the @a choices parameter.
160 @see Create(), wxValidator
162 wxComboBox(wxWindow
* parent
, wxWindowID id
,
163 const wxString
& value
,
166 const wxArrayString
& choices
,
168 const wxValidator
& validator
= wxDefaultValidator
,
169 const wxString
& name
= wxComboBoxNameStr
);
172 Destructor, destroying the combobox.
174 virtual ~wxComboBox();
178 Creates the combobox for two-step construction. Derived classes should
179 call or replace this function. See wxComboBox() for further details.
181 bool Create(wxWindow
*parent
, wxWindowID id
,
182 const wxString
& value
= wxEmptyString
,
183 const wxPoint
& pos
= wxDefaultPosition
,
184 const wxSize
& size
= wxDefaultSize
,
185 int n
= 0, const wxString choices
[] = (const wxString
*) NULL
,
187 const wxValidator
& validator
= wxDefaultValidator
,
188 const wxString
& name
= wxComboBoxNameStr
);
189 bool Create(wxWindow
*parent
, wxWindowID id
,
190 const wxString
& value
,
193 const wxArrayString
& choices
,
195 const wxValidator
& validator
= wxDefaultValidator
,
196 const wxString
& name
= wxComboBoxNameStr
);
200 Returns the item being selected right now.
202 This function does the same things as wxChoice::GetCurrentSelection()
203 and returns the item currently selected in the dropdown list if it's
204 open or the same thing as wxControlWithItems::GetSelection() otherwise.
206 virtual int GetCurrentSelection() const;
209 Same as wxTextEntry::GetInsertionPoint().
211 @note Under wxMSW, this function always returns 0 if the combobox
212 doesn't have the focus.
214 virtual long GetInsertionPoint() const;
217 IsEmpty() is not available in this class.
219 This method is documented here only to notice that it can't be used
220 with this class because of the ambiguity between the methods with the
221 same name inherited from wxItemContainer and wxTextEntry base classes.
223 Because of this, any attempt to call it results in a compilation error
224 and you should use either IsListEmpty() or IsTextEmpty() depending on
225 what exactly do you want to test.
227 bool IsEmpty() const;
230 Returns true if the list of combobox choices is empty.
232 Use this method instead of (not available in this class) IsEmpty() to
233 test if the list of items is empty.
237 bool IsListEmpty() const;
240 Returns true if the text of the combobox is empty.
242 Use this method instead of (not available in this class) IsEmpty() to
243 test if the text currently entered into the combobox is empty.
247 bool IsTextEmpty() const;
250 Same as wxTextEntry::SetSelection().
252 virtual void SetSelection(long from
, long to
);
255 Sets the text for the combobox text field.
257 Notice that this method will generate a @c wxEVT_TEXT
258 event, use wxTextEntry::ChangeValue() if this is undesirable.
260 @note For a combobox with @c wxCB_READONLY style the string must be in
261 the combobox choices list, otherwise the call to SetValue() is
262 ignored. This is case insensitive.
267 virtual void SetValue(const wxString
& text
);
270 Shows the list box portion of the combo box.
272 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
274 Notice that calling this function will generate a
275 @c wxEVT_COMBOBOX_DROPDOWN event except under wxOSX where
276 generation of this event is not supported at all.
280 virtual void Popup();
283 Hides the list box portion of the combo box.
285 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
287 Notice that calling this function will generate a
288 @c wxEVT_COMBOBOX_CLOSEUP event except under wxOSX where
289 generation of this event is not supported at all.
293 virtual void Dismiss();
295 virtual int GetSelection() const;
296 virtual void GetSelection(long *from
, long *to
) const;
297 virtual void SetSelection(int n
);
298 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
299 virtual wxString
GetString(unsigned int n
) const;
300 virtual wxString
GetStringSelection() const;
303 Changes the text of the specified combobox item.
305 Notice that if the item is the currently selected one, i.e. if its text
306 is displayed in the text part of the combobox, then the text is also
307 replaced with the new @a text.
309 virtual void SetString(unsigned int n
, const wxString
& text
);
311 virtual unsigned int GetCount() const;