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