]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/combobox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxComboBox
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
11 A combobox is like a combination of an edit control and a listbox.
13 It can be displayed as static list with editable or read-only text field;
14 or a drop-down list with text field; or a drop-down list without a text
15 field depending on the platform and presence of wxCB_READONLY style.
17 A combobox permits a single selection only. Combobox items are numbered
20 If you need a customized combobox, have a look at wxComboCtrl,
21 wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.
23 Please refer to wxTextEntry documentation for the description of methods
24 operating with the text entry part of the combobox and to wxItemContainer
25 for the methods operating with the list of strings. Notice that at least
26 under MSW wxComboBox doesn't behave correctly if it contains strings
27 differing in case only so portable programs should avoid adding such
28 strings to this control.
32 Creates a combobox with a permanently displayed list. Windows only.
34 Creates a combobox with a drop-down list. MSW and Motif only.
36 A combobox with this style behaves like a wxChoice (and may look in
37 the same way as well, although this is platform-dependent), i.e. it
38 allows the user to choose from the list of options but doesn't allow
39 to enter a value not present in the list.
41 Sorts the entries in the list alphabetically.
42 @style{wxTE_PROCESS_ENTER}
43 The control will generate the event @c wxEVT_TEXT_ENTER
44 (otherwise pressing Enter key is either processed internally by the
45 control or used for navigation between dialog controls).
48 @beginEventEmissionTable{wxCommandEvent}
49 @event{EVT_COMBOBOX(id, func)}
50 Process a @c wxEVT_COMBOBOX event, when an item on
51 the list is selected. Note that calling GetValue() returns the new
53 @event{EVT_TEXT(id, func)}
54 Process a @c wxEVT_TEXT event, when the combobox text
56 @event{EVT_TEXT_ENTER(id, func)}
57 Process a @c wxEVT_TEXT_ENTER event, when RETURN is pressed in
58 the combobox (notice that the combobox must have been created with
59 wxTE_PROCESS_ENTER style to receive this event).
60 @event{EVT_COMBOBOX_DROPDOWN(id, func)}
61 Process a @c wxEVT_COMBOBOX_DROPDOWN event, which is generated
62 when the list box part of the combo box is shown (drops down).
63 Notice that this event is currently only supported by wxMSW and
64 wxGTK with GTK+ 2.10 or later.
65 @event{EVT_COMBOBOX_CLOSEUP(id, func)}
66 Process a @c wxEVT_COMBOBOX_CLOSEUP event, which is generated
67 when the list box of the combo box disappears (closes up). This
68 event is only generated for the same platforms as
69 @c wxEVT_COMBOBOX_DROPDOWN above. Also note that only wxMSW
70 supports adding or deleting items in this event.
77 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
79 class wxComboBox
: public wxControl
,
80 public wxItemContainer
,
90 Constructor, creating and showing a combobox.
93 Parent window. Must not be @NULL.
95 Window identifier. The value wxID_ANY indicates a default value.
97 Initial selection string. An empty string indicates no selection.
98 Notice that for the controls with @c wxCB_READONLY style this
99 string must be one of the valid choices if it is not empty.
102 If ::wxDefaultPosition is specified then a default position is chosen.
105 If ::wxDefaultSize is specified then the window is sized appropriately.
107 Number of strings with which to initialise the control.
109 An array of strings with which to initialise the control.
111 Window style. See wxComboBox.
118 Not supported by wxPerl.
121 @see Create(), wxValidator
123 wxComboBox(wxWindow
* parent
, wxWindowID id
,
124 const wxString
& value
= wxEmptyString
,
125 const wxPoint
& pos
= wxDefaultPosition
,
126 const wxSize
& size
= wxDefaultSize
,
128 const wxString choices
[] = NULL
,
130 const wxValidator
& validator
= wxDefaultValidator
,
131 const wxString
& name
= wxComboBoxNameStr
);
133 Constructor, creating and showing a combobox.
136 Parent window. Must not be @NULL.
138 Window identifier. The value wxID_ANY indicates a default value.
140 Initial selection string. An empty string indicates no selection.
144 Window size. If wxDefaultSize is specified then the window is sized
147 An array of strings with which to initialise the control.
149 Window style. See wxComboBox.
156 Use an array reference for the @a choices parameter.
159 @see Create(), wxValidator
161 wxComboBox(wxWindow
* parent
, wxWindowID id
,
162 const wxString
& value
,
165 const wxArrayString
& choices
,
167 const wxValidator
& validator
= wxDefaultValidator
,
168 const wxString
& name
= wxComboBoxNameStr
);
171 Destructor, destroying the combobox.
173 virtual ~wxComboBox();
177 Creates the combobox for two-step construction. Derived classes should
178 call or replace this function. See wxComboBox() for further details.
180 bool Create(wxWindow
*parent
, wxWindowID id
,
181 const wxString
& value
= wxEmptyString
,
182 const wxPoint
& pos
= wxDefaultPosition
,
183 const wxSize
& size
= wxDefaultSize
,
184 int n
= 0, const wxString choices
[] = (const wxString
*) NULL
,
186 const wxValidator
& validator
= wxDefaultValidator
,
187 const wxString
& name
= wxComboBoxNameStr
);
188 bool Create(wxWindow
*parent
, wxWindowID id
,
189 const wxString
& value
,
192 const wxArrayString
& choices
,
194 const wxValidator
& validator
= wxDefaultValidator
,
195 const wxString
& name
= wxComboBoxNameStr
);
199 Returns the item being selected right now.
201 This function does the same things as wxChoice::GetCurrentSelection()
202 and returns the item currently selected in the dropdown list if it's
203 open or the same thing as wxControlWithItems::GetSelection() otherwise.
205 virtual int GetCurrentSelection() const;
208 Same as wxTextEntry::GetInsertionPoint().
210 @note Under wxMSW, this function always returns 0 if the combobox
211 doesn't have the focus.
213 virtual long GetInsertionPoint() const;
216 IsEmpty() is not available in this class.
218 This method is documented here only to notice that it can't be used
219 with this class because of the ambiguity between the methods with the
220 same name inherited from wxItemContainer and wxTextEntry base classes.
222 Because of this, any attempt to call it results in a compilation error
223 and you should use either IsListEmpty() or IsTextEmpty() depending on
224 what exactly do you want to test.
226 bool IsEmpty() const;
229 Returns true if the list of combobox choices is empty.
231 Use this method instead of (not available in this class) IsEmpty() to
232 test if the list of items is empty.
236 bool IsListEmpty() const;
239 Returns true if the text of the combobox is empty.
241 Use this method instead of (not available in this class) IsEmpty() to
242 test if the text currently entered into the combobox is empty.
246 bool IsTextEmpty() const;
249 Same as wxTextEntry::SetSelection().
251 virtual void SetSelection(long from
, long to
);
254 Sets the text for the combobox text field.
256 Notice that this method will generate a @c wxEVT_TEXT
257 event, use wxTextEntry::ChangeValue() if this is undesirable.
259 @note For a combobox with @c wxCB_READONLY style the string must be in
260 the combobox choices list, otherwise the call to SetValue() is
261 ignored. This is case insensitive.
266 virtual void SetValue(const wxString
& text
);
269 Shows the list box portion of the combo box.
271 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
273 Notice that calling this function will generate a
274 @c wxEVT_COMBOBOX_DROPDOWN event except under wxOSX where
275 generation of this event is not supported at all.
279 virtual void Popup();
282 Hides the list box portion of the combo box.
284 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
286 Notice that calling this function will generate a
287 @c wxEVT_COMBOBOX_CLOSEUP event except under wxOSX where
288 generation of this event is not supported at all.
292 virtual void Dismiss();
294 virtual int GetSelection() const;
295 virtual void GetSelection(long *from
, long *to
) const;
296 virtual void SetSelection(int n
);
297 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
298 virtual wxString
GetString(unsigned int n
) const;
299 virtual wxString
GetStringSelection() const;
302 Changes the text of the specified combobox item.
304 Notice that if the item is the currently selected one, i.e. if its text
305 is displayed in the text part of the combobox, then the text is also
306 replaced with the new @a text.
308 virtual void SetString(unsigned int n
, const wxString
& text
);
310 virtual unsigned int GetCount() const;