]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/combobox.h
use a single wxBookCtrlEvent class for all wxBookCtrlBase-derived controls (#9667)
[wxWidgets.git] / interface / wx / combobox.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: combobox.h
e54c96f1 3// Purpose: interface of wxComboBox
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxComboBox
7c913512 11
bd0812fe
BP
12 A combobox is like a combination of an edit control and a listbox. It can
13 be displayed as static list with editable or read-only text field; or a
14 drop-down list with text field; or a drop-down list without a text field.
7c913512 15
bd0812fe
BP
16 A combobox permits a single selection only. Combobox items are numbered
17 from zero.
7c913512 18
bd0812fe
BP
19 If you need a customized combobox, have a look at wxComboCtrl,
20 wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.
7c913512 21
23324ae1 22 @beginStyleTable
8c6791e4 23 @style{wxCB_SIMPLE}
23324ae1 24 Creates a combobox with a permanently displayed list. Windows only.
8c6791e4 25 @style{wxCB_DROPDOWN}
23324ae1 26 Creates a combobox with a drop-down list.
8c6791e4 27 @style{wxCB_READONLY}
bd0812fe
BP
28 Same as wxCB_DROPDOWN but only the strings specified as the combobox
29 choices can be selected, it is impossible to select (even from a
30 program) a string which is not in the choices list.
8c6791e4 31 @style{wxCB_SORT}
23324ae1 32 Sorts the entries in the list alphabetically.
8c6791e4 33 @style{wxTE_PROCESS_ENTER}
23324ae1
FM
34 The control will generate the event wxEVT_COMMAND_TEXT_ENTER
35 (otherwise pressing Enter key is either processed internally by the
36 control or used for navigation between dialog controls). Windows
37 only.
38 @endStyleTable
7c913512 39
1f1d2182 40 @beginEventTable{wxCommandEvent}
8c6791e4 41 @event{EVT_COMBOBOX(id, func)}
23324ae1 42 Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on
bd0812fe 43 the list is selected. Note that calling GetValue() returns the new
23324ae1 44 value of selection.
8c6791e4 45 @event{EVT_TEXT(id, func)}
23324ae1
FM
46 Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text
47 changes.
8c6791e4 48 @event{EVT_TEXT_ENTER(id, func)}
23324ae1
FM
49 Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
50 the combobox (notice that the combobox must have been created with
51 wxTE_PROCESS_ENTER style to receive this event).
52 @endEventTable
7c913512 53
23324ae1
FM
54 @library{wxcore}
55 @category{ctrl}
bd0812fe 56 <!-- @appearance{combobox.png} -->
7c913512 57
e54c96f1 58 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
23324ae1 59*/
bf84f3e2 60class wxComboBox : public wxControl, public wxItemContainer
23324ae1
FM
61{
62public:
bd0812fe
BP
63 /**
64 Default constructor.
65 */
66 wxComboBox();
67
23324ae1
FM
68 //@{
69 /**
70 Constructor, creating and showing a combobox.
3c4f71cc 71
7c913512 72 @param parent
4cc4bfaf 73 Parent window. Must not be @NULL.
7c913512 74 @param id
4cc4bfaf 75 Window identifier. The value wxID_ANY indicates a default value.
7c913512 76 @param value
4cc4bfaf 77 Initial selection string. An empty string indicates no selection.
7c913512 78 @param pos
4cc4bfaf 79 Window position.
7c913512 80 @param size
bd0812fe 81 Window size. If wxDefaultSize is specified then the window is sized
4cc4bfaf 82 appropriately.
7c913512 83 @param n
4cc4bfaf 84 Number of strings with which to initialise the control.
7c913512 85 @param choices
4cc4bfaf 86 An array of strings with which to initialise the control.
7c913512 87 @param style
4cc4bfaf 88 Window style. See wxComboBox.
7c913512 89 @param validator
4cc4bfaf 90 Window validator.
7c913512 91 @param name
4cc4bfaf 92 Window name.
3c4f71cc 93
bd0812fe
BP
94 @beginWxPythonOnly
95 The wxComboBox constructor in wxPython reduces the @a n and @a choices
96 arguments are to a single argument, which is a list of strings.
97 @endWxPythonOnly
98
4cc4bfaf 99 @see Create(), wxValidator
23324ae1 100 */
7c913512
FM
101 wxComboBox(wxWindow* parent, wxWindowID id,
102 const wxString& value = "",
103 const wxPoint& pos = wxDefaultPosition,
104 const wxSize& size = wxDefaultSize,
105 int n = 0,
4cc4bfaf 106 const wxString choices[] = NULL,
7c913512
FM
107 long style = 0,
108 const wxValidator& validator = wxDefaultValidator,
109 const wxString& name = "comboBox");
110 wxComboBox(wxWindow* parent, wxWindowID id,
111 const wxString& value,
112 const wxPoint& pos,
113 const wxSize& size,
114 const wxArrayString& choices,
115 long style = 0,
116 const wxValidator& validator = wxDefaultValidator,
117 const wxString& name = "comboBox");
23324ae1
FM
118 //@}
119
120 /**
121 Destructor, destroying the combobox.
122 */
123 ~wxComboBox();
124
bd0812fe 125 //@{
23324ae1 126 /**
bd0812fe
BP
127 Creates the combobox for two-step construction. Derived classes should
128 call or replace this function. See wxComboBox() for further details.
129 */
130 bool Create(wxWindow* parent, wxWindowID id,
131 const wxString& value = "",
132 const wxPoint& pos = wxDefaultPosition,
133 const wxSize& size = wxDefaultSize,
134 int n, const wxString choices[],
135 long style = 0,
136 const wxValidator& validator = wxDefaultValidator,
137 const wxString& name = "comboBox");
138 bool Create(wxWindow* parent, wxWindowID id,
139 const wxString& value,
140 const wxPoint& pos,
141 const wxSize& size,
142 const wxArrayString& choices,
143 long style = 0,
144 const wxValidator& validator = wxDefaultValidator,
145 const wxString& name = "comboBox");
146 //@}
147
148 /**
149 Returns @true if the combobox is editable and there is a text selection
150 to copy to the clipboard. Only available on Windows.
23324ae1 151 */
328f5751 152 bool CanCopy() const;
23324ae1
FM
153
154 /**
bd0812fe
BP
155 Returns @true if the combobox is editable and there is a text selection
156 to copy to the clipboard. Only available on Windows.
23324ae1 157 */
328f5751 158 bool CanCut() const;
23324ae1
FM
159
160 /**
bd0812fe
BP
161 Returns @true if the combobox is editable and there is text on the
162 clipboard that can be pasted into the text field. Only available on
163 Windows.
23324ae1 164 */
328f5751 165 bool CanPaste() const;
23324ae1
FM
166
167 /**
bd0812fe
BP
168 Returns @true if the combobox is editable and the last undo can be
169 redone. Only available on Windows.
23324ae1 170 */
328f5751 171 bool CanRedo() const;
23324ae1
FM
172
173 /**
bd0812fe
BP
174 Returns @true if the combobox is editable and the last edit can be
175 undone. Only available on Windows.
23324ae1 176 */
328f5751 177 bool CanUndo() const;
23324ae1
FM
178
179 /**
180 Copies the selected text to the clipboard.
181 */
182 void Copy();
183
23324ae1
FM
184 /**
185 Copies the selected text to the clipboard and removes the selection.
186 */
4cc4bfaf 187 void Cut();
23324ae1
FM
188
189 /**
bd0812fe
BP
190 This function does the same things as wxChoice::GetCurrentSelection()
191 and returns the item currently selected in the dropdown list if it's
192 open or the same thing as wxControlWithItems::GetSelection() otherwise.
23324ae1 193 */
328f5751 194 int GetCurrentSelection() const;
23324ae1
FM
195
196 /**
197 Returns the insertion point for the combobox's text field.
bd0812fe 198
cdbcf4c2 199 @note Under wxMSW, this function always returns 0 if the combobox
bd0812fe 200 doesn't have the focus.
23324ae1 201 */
328f5751 202 long GetInsertionPoint() const;
23324ae1
FM
203
204 /**
205 Returns the last position in the combobox text field.
206 */
328f5751 207 virtual wxTextPos GetLastPosition() const;
23324ae1
FM
208
209 /**
bd0812fe
BP
210 This is the same as wxTextCtrl::GetSelection() for the text control
211 which is part of the combobox. Notice that this is a different method
212 from wxControlWithItems::GetSelection().
213
23324ae1
FM
214 Currently this method is only implemented in wxMSW and wxGTK.
215 */
328f5751 216 void GetSelection(long* from, long* to) const;
23324ae1
FM
217
218 /**
219 Returns the current value in the combobox text field.
220 */
328f5751 221 wxString GetValue() const;
23324ae1
FM
222
223 /**
224 Pastes text from the clipboard to the text field.
225 */
226 void Paste();
227
228 /**
229 Redoes the last undo in the text field. Windows only.
230 */
231 void Redo();
232
233 /**
234 Removes the text between the two positions in the combobox text field.
3c4f71cc 235
7c913512 236 @param from
4cc4bfaf 237 The first position.
7c913512 238 @param to
4cc4bfaf 239 The last position.
23324ae1
FM
240 */
241 void Remove(long from, long to);
242
243 /**
bd0812fe
BP
244 Replaces the text between two positions with the given text, in the
245 combobox text field.
3c4f71cc 246
7c913512 247 @param from
4cc4bfaf 248 The first position.
7c913512 249 @param to
4cc4bfaf 250 The second position.
7c913512 251 @param text
4cc4bfaf 252 The text to insert.
23324ae1
FM
253 */
254 void Replace(long from, long to, const wxString& text);
255
256 /**
257 Sets the insertion point in the combobox text field.
3c4f71cc 258
7c913512 259 @param pos
4cc4bfaf 260 The new insertion point.
23324ae1
FM
261 */
262 void SetInsertionPoint(long pos);
263
264 /**
265 Sets the insertion point at the end of the combobox text field.
266 */
267 void SetInsertionPointEnd();
268
269 /**
270 Selects the text between the two positions, in the combobox text field.
3c4f71cc 271
7c913512 272 @param from
4cc4bfaf 273 The first position.
7c913512 274 @param to
4cc4bfaf 275 The second position.
bd0812fe
BP
276
277 @beginWxPythonOnly
278 This method is called SetMark() in wxPython, "SetSelection" is kept for
279 wxControlWithItems::SetSelection().
280 @endWxPythonOnly
23324ae1
FM
281 */
282 void SetSelection(long from, long to);
283
284 /**
285 Sets the text for the combobox text field.
1f1d2182
FM
286
287 @note For a combobox with @c wxCB_READONLY style the string must be in
bd0812fe
BP
288 the combobox choices list, otherwise the call to SetValue() is
289 ignored.
3c4f71cc 290
7c913512 291 @param text
4cc4bfaf 292 The text to set.
23324ae1
FM
293 */
294 void SetValue(const wxString& text);
295
296 /**
297 Undoes the last edit in the text field. Windows only.
298 */
299 void Undo();
300};
e54c96f1 301