]>
Commit | Line | Data |
---|---|---|
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 | @wxheader{combobox.h} | |
12 | ||
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. | |
17 | ||
18 | A combobox permits a single selection only. Combobox items are numbered from | |
19 | zero. | |
20 | ||
21 | If you need a customized combobox, have a look at wxComboCtrl, wxOwnerDrawnComboBox, | |
22 | wxComboPopup and the ready-to-use wxBitmapComboBox. | |
23 | ||
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 | |
41 | ||
42 | @beginEventTable{wxCommandEvent} | |
43 | @event{EVT_COMBOBOX(id, func)} | |
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. | |
47 | @event{EVT_TEXT(id, func)} | |
48 | Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text | |
49 | changes. | |
50 | @event{EVT_TEXT_ENTER(id, func)} | |
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 | |
55 | ||
56 | @library{wxcore} | |
57 | @category{ctrl} | |
58 | @appearance{combobox.png} | |
59 | ||
60 | @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent | |
61 | */ | |
62 | class wxComboBox : public wxControl, public wxItemContainer | |
63 | { | |
64 | public: | |
65 | //@{ | |
66 | /** | |
67 | Constructor, creating and showing a combobox. | |
68 | ||
69 | @param parent | |
70 | Parent window. Must not be @NULL. | |
71 | @param id | |
72 | Window identifier. The value wxID_ANY indicates a default value. | |
73 | @param value | |
74 | Initial selection string. An empty string indicates no selection. | |
75 | @param pos | |
76 | Window position. | |
77 | @param size | |
78 | Window size. If wxDefaultSize is specified then the window is | |
79 | sized | |
80 | appropriately. | |
81 | @param n | |
82 | Number of strings with which to initialise the control. | |
83 | @param choices | |
84 | An array of strings with which to initialise the control. | |
85 | @param style | |
86 | Window style. See wxComboBox. | |
87 | @param validator | |
88 | Window validator. | |
89 | @param name | |
90 | Window name. | |
91 | ||
92 | @see Create(), wxValidator | |
93 | */ | |
94 | wxComboBox(); | |
95 | wxComboBox(wxWindow* parent, wxWindowID id, | |
96 | const wxString& value = "", | |
97 | const wxPoint& pos = wxDefaultPosition, | |
98 | const wxSize& size = wxDefaultSize, | |
99 | int n = 0, | |
100 | const wxString choices[] = NULL, | |
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"); | |
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 | */ | |
124 | bool CanCopy() const; | |
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 | */ | |
131 | bool CanCut() const; | |
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 | */ | |
138 | bool CanPaste() const; | |
139 | ||
140 | /** | |
141 | Returns @true if the combobox is editable and the last undo can be redone. | |
142 | Only available on Windows. | |
143 | */ | |
144 | bool CanRedo() const; | |
145 | ||
146 | /** | |
147 | Returns @true if the combobox is editable and the last edit can be undone. | |
148 | Only available on Windows. | |
149 | */ | |
150 | bool CanUndo() const; | |
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"); | |
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"); | |
179 | //@} | |
180 | ||
181 | /** | |
182 | Copies the selected text to the clipboard and removes the selection. | |
183 | */ | |
184 | void Cut(); | |
185 | ||
186 | /** | |
187 | This function does the same things as | |
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 | */ | |
192 | int GetCurrentSelection() const; | |
193 | ||
194 | /** | |
195 | Returns the insertion point for the combobox's text field. | |
196 | @note Under wxMSW, this function always returns 0 if the combobox | |
197 | doesn't have the focus. | |
198 | */ | |
199 | long GetInsertionPoint() const; | |
200 | ||
201 | /** | |
202 | Returns the last position in the combobox text field. | |
203 | */ | |
204 | virtual wxTextPos GetLastPosition() const; | |
205 | ||
206 | /** | |
207 | This is the same as wxTextCtrl::GetSelection | |
208 | for the text control which is part of the combobox. Notice that this is a | |
209 | different method from wxControlWithItems::GetSelection. | |
210 | Currently this method is only implemented in wxMSW and wxGTK. | |
211 | */ | |
212 | void GetSelection(long* from, long* to) const; | |
213 | ||
214 | /** | |
215 | Returns the current value in the combobox text field. | |
216 | */ | |
217 | wxString GetValue() const; | |
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. | |
231 | ||
232 | @param from | |
233 | The first position. | |
234 | @param to | |
235 | The last position. | |
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. | |
242 | ||
243 | @param from | |
244 | The first position. | |
245 | @param to | |
246 | The second position. | |
247 | @param text | |
248 | The text to insert. | |
249 | */ | |
250 | void Replace(long from, long to, const wxString& text); | |
251 | ||
252 | /** | |
253 | Sets the insertion point in the combobox text field. | |
254 | ||
255 | @param pos | |
256 | The new insertion point. | |
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. | |
267 | ||
268 | @param from | |
269 | The first position. | |
270 | @param to | |
271 | The second position. | |
272 | */ | |
273 | void SetSelection(long from, long to); | |
274 | ||
275 | /** | |
276 | Sets the text for the combobox text field. | |
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. | |
280 | ||
281 | @param text | |
282 | The text to set. | |
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 | }; | |
291 |