]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/combobox.h
remove ancient defines left over from GTK1
[wxWidgets.git] / interface / wx / combobox.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: combobox.h
e54c96f1 3// Purpose: interface of wxComboBox
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
8/**
9 @class wxComboBox
7c913512 10
2e7789a9
VZ
11 A combobox is like a combination of an edit control and a listbox.
12
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
1db02a5e 15 field depending on the platform and presence of wxCB_READONLY style.
7c913512 16
bd0812fe
BP
17 A combobox permits a single selection only. Combobox items are numbered
18 from zero.
7c913512 19
bd0812fe
BP
20 If you need a customized combobox, have a look at wxComboCtrl,
21 wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.
7c913512 22
2e7789a9 23 Please refer to wxTextEntry documentation for the description of methods
1db02a5e 24 operating with the text entry part of the combobox and to wxItemContainer
32564189
VZ
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.
2e7789a9 29
23324ae1 30 @beginStyleTable
8c6791e4 31 @style{wxCB_SIMPLE}
23324ae1 32 Creates a combobox with a permanently displayed list. Windows only.
8c6791e4 33 @style{wxCB_DROPDOWN}
1db02a5e 34 Creates a combobox with a drop-down list. MSW and Motif only.
8c6791e4 35 @style{wxCB_READONLY}
1db02a5e
VZ
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.
8c6791e4 40 @style{wxCB_SORT}
23324ae1 41 Sorts the entries in the list alphabetically.
8c6791e4 42 @style{wxTE_PROCESS_ENTER}
ce7fe42e 43 The control will generate the event @c wxEVT_TEXT_ENTER
23324ae1 44 (otherwise pressing Enter key is either processed internally by the
2bc096a0 45 control or used for navigation between dialog controls).
23324ae1 46 @endStyleTable
7c913512 47
3051a44a 48 @beginEventEmissionTable{wxCommandEvent}
8c6791e4 49 @event{EVT_COMBOBOX(id, func)}
ce7fe42e 50 Process a @c wxEVT_COMBOBOX event, when an item on
bd0812fe 51 the list is selected. Note that calling GetValue() returns the new
23324ae1 52 value of selection.
8c6791e4 53 @event{EVT_TEXT(id, func)}
ce7fe42e 54 Process a @c wxEVT_TEXT event, when the combobox text
23324ae1 55 changes.
8c6791e4 56 @event{EVT_TEXT_ENTER(id, func)}
ce7fe42e 57 Process a @c wxEVT_TEXT_ENTER event, when RETURN is pressed in
23324ae1
FM
58 the combobox (notice that the combobox must have been created with
59 wxTE_PROCESS_ENTER style to receive this event).
23d74d89 60 @event{EVT_COMBOBOX_DROPDOWN(id, func)}
ce7fe42e 61 Process a @c wxEVT_COMBOBOX_DROPDOWN event, which is generated
8933fbc6
VZ
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.
23d74d89 65 @event{EVT_COMBOBOX_CLOSEUP(id, func)}
ce7fe42e 66 Process a @c wxEVT_COMBOBOX_CLOSEUP event, which is generated
8933fbc6
VZ
67 when the list box of the combo box disappears (closes up). This
68 event is only generated for the same platforms as
ce7fe42e 69 @c wxEVT_COMBOBOX_DROPDOWN above. Also note that only wxMSW
bb3400a8 70 supports adding or deleting items in this event.
23324ae1 71 @endEventTable
7c913512 72
23324ae1
FM
73 @library{wxcore}
74 @category{ctrl}
ce154616 75 @appearance{combobox}
7c913512 76
e54c96f1 77 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
23324ae1 78*/
2e7789a9
VZ
79class wxComboBox : public wxControl,
80 public wxItemContainer,
81 public wxTextEntry
23324ae1
FM
82{
83public:
bd0812fe
BP
84 /**
85 Default constructor.
86 */
87 wxComboBox();
88
23324ae1
FM
89 /**
90 Constructor, creating and showing a combobox.
3c4f71cc 91
7c913512 92 @param parent
4cc4bfaf 93 Parent window. Must not be @NULL.
7c913512 94 @param id
4cc4bfaf 95 Window identifier. The value wxID_ANY indicates a default value.
7c913512 96 @param value
4cc4bfaf 97 Initial selection string. An empty string indicates no selection.
a3281dbc
VZ
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.
7c913512 100 @param pos
4cc4bfaf 101 Window position.
dc1b07fd 102 If ::wxDefaultPosition is specified then a default position is chosen.
7c913512 103 @param size
dc1b07fd
FM
104 Window size.
105 If ::wxDefaultSize is specified then the window is sized appropriately.
7c913512 106 @param n
4cc4bfaf 107 Number of strings with which to initialise the control.
7c913512 108 @param choices
4cc4bfaf 109 An array of strings with which to initialise the control.
7c913512 110 @param style
4cc4bfaf 111 Window style. See wxComboBox.
7c913512 112 @param validator
4cc4bfaf 113 Window validator.
7c913512 114 @param name
4cc4bfaf 115 Window name.
3c4f71cc 116
1058f652
MB
117 @beginWxPerlOnly
118 Not supported by wxPerl.
119 @endWxPerlOnly
120
4cc4bfaf 121 @see Create(), wxValidator
23324ae1 122 */
7c913512 123 wxComboBox(wxWindow* parent, wxWindowID id,
e9c3992c 124 const wxString& value = wxEmptyString,
7c913512
FM
125 const wxPoint& pos = wxDefaultPosition,
126 const wxSize& size = wxDefaultSize,
127 int n = 0,
4cc4bfaf 128 const wxString choices[] = NULL,
7c913512
FM
129 long style = 0,
130 const wxValidator& validator = wxDefaultValidator,
882678eb 131 const wxString& name = wxComboBoxNameStr);
792255cc
VZ
132 /**
133 Constructor, creating and showing a combobox.
134
135 @param parent
136 Parent window. Must not be @NULL.
137 @param id
138 Window identifier. The value wxID_ANY indicates a default value.
139 @param value
140 Initial selection string. An empty string indicates no selection.
141 @param pos
142 Window position.
143 @param size
144 Window size. If wxDefaultSize is specified then the window is sized
145 appropriately.
146 @param choices
147 An array of strings with which to initialise the control.
148 @param style
149 Window style. See wxComboBox.
150 @param validator
151 Window validator.
152 @param name
153 Window name.
154
1058f652
MB
155 @beginWxPerlOnly
156 Use an array reference for the @a choices parameter.
157 @endWxPerlOnly
158
792255cc
VZ
159 @see Create(), wxValidator
160 */
7c913512
FM
161 wxComboBox(wxWindow* parent, wxWindowID id,
162 const wxString& value,
163 const wxPoint& pos,
164 const wxSize& size,
165 const wxArrayString& choices,
166 long style = 0,
167 const wxValidator& validator = wxDefaultValidator,
882678eb 168 const wxString& name = wxComboBoxNameStr);
23324ae1
FM
169
170 /**
171 Destructor, destroying the combobox.
172 */
b7e94bd7 173 virtual ~wxComboBox();
23324ae1 174
bd0812fe 175 //@{
23324ae1 176 /**
bd0812fe
BP
177 Creates the combobox for two-step construction. Derived classes should
178 call or replace this function. See wxComboBox() for further details.
179 */
57bf907d
FM
180 bool Create(wxWindow *parent, wxWindowID id,
181 const wxString& value = wxEmptyString,
bd0812fe
BP
182 const wxPoint& pos = wxDefaultPosition,
183 const wxSize& size = wxDefaultSize,
57bf907d 184 int n = 0, const wxString choices[] = (const wxString *) NULL,
bd0812fe
BP
185 long style = 0,
186 const wxValidator& validator = wxDefaultValidator,
57bf907d
FM
187 const wxString& name = wxComboBoxNameStr);
188 bool Create(wxWindow *parent, wxWindowID id,
bd0812fe
BP
189 const wxString& value,
190 const wxPoint& pos,
191 const wxSize& size,
192 const wxArrayString& choices,
193 long style = 0,
194 const wxValidator& validator = wxDefaultValidator,
57bf907d 195 const wxString& name = wxComboBoxNameStr);
bd0812fe
BP
196 //@}
197
198 /**
2e7789a9 199 Returns the item being selected right now.
23324ae1 200
bd0812fe
BP
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.
23324ae1 204 */
b7e94bd7 205 virtual int GetCurrentSelection() const;
23324ae1
FM
206
207 /**
2e7789a9 208 Same as wxTextEntry::GetInsertionPoint().
bd0812fe 209
cdbcf4c2 210 @note Under wxMSW, this function always returns 0 if the combobox
bd0812fe 211 doesn't have the focus.
23324ae1 212 */
0004982c 213 virtual long GetInsertionPoint() const;
23324ae1 214
36a96421
VZ
215 /**
216 IsEmpty() is not available in this class.
217
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.
221
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.
225 */
226 bool IsEmpty() const;
227
228 /**
229 Returns true if the list of combobox choices is empty.
230
231 Use this method instead of (not available in this class) IsEmpty() to
232 test if the list of items is empty.
233
234 @since 2.9.3
235 */
236 bool IsListEmpty() const;
237
238 /**
239 Returns true if the text of the combobox is empty.
240
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.
243
244 @since 2.9.3
245 */
246 bool IsTextEmpty() const;
247
23324ae1 248 /**
2e7789a9 249 Same as wxTextEntry::SetSelection().
23324ae1 250 */
b7e94bd7 251 virtual void SetSelection(long from, long to);
23324ae1
FM
252
253 /**
254 Sets the text for the combobox text field.
1f1d2182 255
ce7fe42e 256 Notice that this method will generate a @c wxEVT_TEXT
35b9a078
VZ
257 event, use wxTextEntry::ChangeValue() if this is undesirable.
258
1f1d2182 259 @note For a combobox with @c wxCB_READONLY style the string must be in
bd0812fe 260 the combobox choices list, otherwise the call to SetValue() is
232fdc63 261 ignored. This is case insensitive.
3c4f71cc 262
7c913512 263 @param text
4cc4bfaf 264 The text to set.
23324ae1 265 */
0004982c 266 virtual void SetValue(const wxString& text);
d1d1f817
VZ
267
268 /**
269 Shows the list box portion of the combo box.
270
ff8cb900 271 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
d1d1f817 272
73c997ba 273 Notice that calling this function will generate a
ce7fe42e 274 @c wxEVT_COMBOBOX_DROPDOWN event except under wxOSX where
ff8cb900 275 generation of this event is not supported at all.
73c997ba 276
d1d1f817
VZ
277 @since 2.9.1
278 */
279 virtual void Popup();
280
281 /**
282 Hides the list box portion of the combo box.
283
ff8cb900 284 Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.
d1d1f817 285
73c997ba 286 Notice that calling this function will generate a
ce7fe42e 287 @c wxEVT_COMBOBOX_CLOSEUP event except under wxOSX where
ff8cb900 288 generation of this event is not supported at all.
73c997ba 289
d1d1f817
VZ
290 @since 2.9.1
291 */
292 virtual void Dismiss();
ff8cb900 293
e9321277
RD
294 virtual int GetSelection() const;
295 virtual void GetSelection(long *from, long *to) const;
296 virtual void SetSelection(int n);
e9321277
RD
297 virtual int FindString(const wxString& s, bool bCase = false) const;
298 virtual wxString GetString(unsigned int n) const;
299 virtual wxString GetStringSelection() const;
a9ed8caa
VZ
300
301 /**
302 Changes the text of the specified combobox item.
303
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.
307 */
308 virtual void SetString(unsigned int n, const wxString& text);
e9321277
RD
309
310 virtual unsigned int GetCount() const;
23324ae1 311};
e54c96f1 312