]>
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 | |
7c913512 | 11 | |
2e7789a9 VZ |
12 | A combobox is like a combination of an edit control and a listbox. |
13 | ||
14 | It can be displayed as static list with editable or read-only text field; | |
15 | or a drop-down list with text field; or a drop-down list without a text | |
16 | field. | |
7c913512 | 17 | |
bd0812fe BP |
18 | A combobox permits a single selection only. Combobox items are numbered |
19 | from zero. | |
7c913512 | 20 | |
bd0812fe BP |
21 | If you need a customized combobox, have a look at wxComboCtrl, |
22 | wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox. | |
7c913512 | 23 | |
2e7789a9 VZ |
24 | Please refer to wxTextEntry documentation for the description of methods |
25 | operating with the text entry part of the combobox. | |
26 | ||
23324ae1 | 27 | @beginStyleTable |
8c6791e4 | 28 | @style{wxCB_SIMPLE} |
23324ae1 | 29 | Creates a combobox with a permanently displayed list. Windows only. |
8c6791e4 | 30 | @style{wxCB_DROPDOWN} |
23324ae1 | 31 | Creates a combobox with a drop-down list. |
8c6791e4 | 32 | @style{wxCB_READONLY} |
bd0812fe BP |
33 | Same as wxCB_DROPDOWN but only the strings specified as the combobox |
34 | choices can be selected, it is impossible to select (even from a | |
35 | program) a string which is not in the choices list. | |
8c6791e4 | 36 | @style{wxCB_SORT} |
23324ae1 | 37 | Sorts the entries in the list alphabetically. |
8c6791e4 | 38 | @style{wxTE_PROCESS_ENTER} |
23324ae1 FM |
39 | The control will generate the event wxEVT_COMMAND_TEXT_ENTER |
40 | (otherwise pressing Enter key is either processed internally by the | |
41 | control or used for navigation between dialog controls). Windows | |
42 | only. | |
43 | @endStyleTable | |
7c913512 | 44 | |
3051a44a | 45 | @beginEventEmissionTable{wxCommandEvent} |
8c6791e4 | 46 | @event{EVT_COMBOBOX(id, func)} |
23324ae1 | 47 | Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on |
bd0812fe | 48 | the list is selected. Note that calling GetValue() returns the new |
23324ae1 | 49 | value of selection. |
8c6791e4 | 50 | @event{EVT_TEXT(id, func)} |
23324ae1 FM |
51 | Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text |
52 | changes. | |
8c6791e4 | 53 | @event{EVT_TEXT_ENTER(id, func)} |
23324ae1 FM |
54 | Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in |
55 | the combobox (notice that the combobox must have been created with | |
56 | wxTE_PROCESS_ENTER style to receive this event). | |
8933fbc6 VZ |
57 | @event{EVT_COMBOX_DROPDOWN(id, func)} |
58 | Process a wxEVT_COMMAND_COMBOBOX_DROPDOWN event, which is generated | |
59 | when the list box part of the combo box is shown (drops down). | |
60 | Notice that this event is currently only supported by wxMSW and | |
61 | wxGTK with GTK+ 2.10 or later. | |
62 | @event{EVT_COMBOX_CLOSEUP(id, func)} | |
63 | Process a wxEVT_COMMAND_COMBOBOX_CLOSEUP event, which is generated | |
64 | when the list box of the combo box disappears (closes up). This | |
65 | event is only generated for the same platforms as | |
66 | wxEVT_COMMAND_COMBOBOX_DROPDOWN above. | |
23324ae1 | 67 | @endEventTable |
7c913512 | 68 | |
23324ae1 FM |
69 | @library{wxcore} |
70 | @category{ctrl} | |
7e59b885 | 71 | @appearance{combobox.png} |
7c913512 | 72 | |
e54c96f1 | 73 | @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent |
23324ae1 | 74 | */ |
2e7789a9 VZ |
75 | class wxComboBox : public wxControl, |
76 | public wxItemContainer, | |
77 | public wxTextEntry | |
23324ae1 FM |
78 | { |
79 | public: | |
bd0812fe BP |
80 | /** |
81 | Default constructor. | |
82 | */ | |
83 | wxComboBox(); | |
84 | ||
23324ae1 FM |
85 | //@{ |
86 | /** | |
87 | Constructor, creating and showing a combobox. | |
3c4f71cc | 88 | |
7c913512 | 89 | @param parent |
4cc4bfaf | 90 | Parent window. Must not be @NULL. |
7c913512 | 91 | @param id |
4cc4bfaf | 92 | Window identifier. The value wxID_ANY indicates a default value. |
7c913512 | 93 | @param value |
4cc4bfaf | 94 | Initial selection string. An empty string indicates no selection. |
a3281dbc VZ |
95 | Notice that for the controls with @c wxCB_READONLY style this |
96 | string must be one of the valid choices if it is not empty. | |
7c913512 | 97 | @param pos |
4cc4bfaf | 98 | Window position. |
7c913512 | 99 | @param size |
bd0812fe | 100 | Window size. If wxDefaultSize is specified then the window is sized |
4cc4bfaf | 101 | appropriately. |
7c913512 | 102 | @param n |
4cc4bfaf | 103 | Number of strings with which to initialise the control. |
7c913512 | 104 | @param choices |
4cc4bfaf | 105 | An array of strings with which to initialise the control. |
7c913512 | 106 | @param style |
4cc4bfaf | 107 | Window style. See wxComboBox. |
7c913512 | 108 | @param validator |
4cc4bfaf | 109 | Window validator. |
7c913512 | 110 | @param name |
4cc4bfaf | 111 | Window name. |
3c4f71cc | 112 | |
bd0812fe BP |
113 | @beginWxPythonOnly |
114 | The wxComboBox constructor in wxPython reduces the @a n and @a choices | |
115 | arguments are to a single argument, which is a list of strings. | |
116 | @endWxPythonOnly | |
117 | ||
4cc4bfaf | 118 | @see Create(), wxValidator |
23324ae1 | 119 | */ |
7c913512 | 120 | wxComboBox(wxWindow* parent, wxWindowID id, |
e9c3992c | 121 | const wxString& value = wxEmptyString, |
7c913512 FM |
122 | const wxPoint& pos = wxDefaultPosition, |
123 | const wxSize& size = wxDefaultSize, | |
124 | int n = 0, | |
4cc4bfaf | 125 | const wxString choices[] = NULL, |
7c913512 FM |
126 | long style = 0, |
127 | const wxValidator& validator = wxDefaultValidator, | |
882678eb | 128 | const wxString& name = wxComboBoxNameStr); |
792255cc VZ |
129 | /** |
130 | Constructor, creating and showing a combobox. | |
131 | ||
132 | @param parent | |
133 | Parent window. Must not be @NULL. | |
134 | @param id | |
135 | Window identifier. The value wxID_ANY indicates a default value. | |
136 | @param value | |
137 | Initial selection string. An empty string indicates no selection. | |
138 | @param pos | |
139 | Window position. | |
140 | @param size | |
141 | Window size. If wxDefaultSize is specified then the window is sized | |
142 | appropriately. | |
143 | @param choices | |
144 | An array of strings with which to initialise the control. | |
145 | @param style | |
146 | Window style. See wxComboBox. | |
147 | @param validator | |
148 | Window validator. | |
149 | @param name | |
150 | Window name. | |
151 | ||
152 | @beginWxPythonOnly | |
153 | The wxComboBox constructor in wxPython reduces the @a n and @a choices | |
154 | arguments are to a single argument, which is a list of strings. | |
155 | @endWxPythonOnly | |
156 | ||
157 | @see Create(), wxValidator | |
158 | */ | |
7c913512 FM |
159 | wxComboBox(wxWindow* parent, wxWindowID id, |
160 | const wxString& value, | |
161 | const wxPoint& pos, | |
162 | const wxSize& size, | |
163 | const wxArrayString& choices, | |
164 | long style = 0, | |
165 | const wxValidator& validator = wxDefaultValidator, | |
882678eb | 166 | const wxString& name = wxComboBoxNameStr); |
23324ae1 FM |
167 | //@} |
168 | ||
169 | /** | |
170 | Destructor, destroying the combobox. | |
171 | */ | |
b7e94bd7 | 172 | virtual ~wxComboBox(); |
23324ae1 | 173 | |
bd0812fe | 174 | //@{ |
23324ae1 | 175 | /** |
bd0812fe BP |
176 | Creates the combobox for two-step construction. Derived classes should |
177 | call or replace this function. See wxComboBox() for further details. | |
178 | */ | |
57bf907d FM |
179 | bool Create(wxWindow *parent, wxWindowID id, |
180 | const wxString& value = wxEmptyString, | |
bd0812fe BP |
181 | const wxPoint& pos = wxDefaultPosition, |
182 | const wxSize& size = wxDefaultSize, | |
57bf907d | 183 | int n = 0, const wxString choices[] = (const wxString *) NULL, |
bd0812fe BP |
184 | long style = 0, |
185 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d FM |
186 | const wxString& name = wxComboBoxNameStr); |
187 | bool Create(wxWindow *parent, wxWindowID id, | |
bd0812fe BP |
188 | const wxString& value, |
189 | const wxPoint& pos, | |
190 | const wxSize& size, | |
191 | const wxArrayString& choices, | |
192 | long style = 0, | |
193 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d | 194 | const wxString& name = wxComboBoxNameStr); |
bd0812fe BP |
195 | //@} |
196 | ||
197 | /** | |
2e7789a9 | 198 | Returns the item being selected right now. |
23324ae1 | 199 | |
bd0812fe BP |
200 | This function does the same things as wxChoice::GetCurrentSelection() |
201 | and returns the item currently selected in the dropdown list if it's | |
202 | open or the same thing as wxControlWithItems::GetSelection() otherwise. | |
23324ae1 | 203 | */ |
b7e94bd7 | 204 | virtual int GetCurrentSelection() const; |
23324ae1 FM |
205 | |
206 | /** | |
2e7789a9 | 207 | Same as wxTextEntry::GetInsertionPoint(). |
bd0812fe | 208 | |
cdbcf4c2 | 209 | @note Under wxMSW, this function always returns 0 if the combobox |
bd0812fe | 210 | doesn't have the focus. |
23324ae1 | 211 | */ |
0004982c | 212 | virtual long GetInsertionPoint() const; |
23324ae1 FM |
213 | |
214 | /** | |
2e7789a9 | 215 | Same as wxTextEntry::SetSelection(). |
bd0812fe BP |
216 | |
217 | @beginWxPythonOnly | |
218 | This method is called SetMark() in wxPython, "SetSelection" is kept for | |
219 | wxControlWithItems::SetSelection(). | |
220 | @endWxPythonOnly | |
23324ae1 | 221 | */ |
b7e94bd7 | 222 | virtual void SetSelection(long from, long to); |
23324ae1 FM |
223 | |
224 | /** | |
225 | Sets the text for the combobox text field. | |
1f1d2182 | 226 | |
35b9a078 VZ |
227 | Notice that this method will generate a wxEVT_COMMAND_TEXT_UPDATED |
228 | event, use wxTextEntry::ChangeValue() if this is undesirable. | |
229 | ||
1f1d2182 | 230 | @note For a combobox with @c wxCB_READONLY style the string must be in |
bd0812fe BP |
231 | the combobox choices list, otherwise the call to SetValue() is |
232 | ignored. | |
3c4f71cc | 233 | |
7c913512 | 234 | @param text |
4cc4bfaf | 235 | The text to set. |
23324ae1 | 236 | */ |
0004982c | 237 | virtual void SetValue(const wxString& text); |
23324ae1 | 238 | }; |
e54c96f1 | 239 |