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