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