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