]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/combobox.h
Only show the default close button in wxInfoBar if there are no others.
[wxWidgets.git] / interface / wx / combobox.h
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.
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.
17
18 A combobox permits a single selection only. Combobox items are numbered
19 from zero.
20
21 If you need a customized combobox, have a look at wxComboCtrl,
22 wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.
23
24 Please refer to wxTextEntry documentation for the description of methods
25 operating with the text entry part of the combobox.
26
27 @beginStyleTable
28 @style{wxCB_SIMPLE}
29 Creates a combobox with a permanently displayed list. Windows only.
30 @style{wxCB_DROPDOWN}
31 Creates a combobox with a drop-down list.
32 @style{wxCB_READONLY}
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.
36 @style{wxCB_SORT}
37 Sorts the entries in the list alphabetically.
38 @style{wxTE_PROCESS_ENTER}
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
44
45 @beginEventEmissionTable{wxCommandEvent}
46 @event{EVT_COMBOBOX(id, func)}
47 Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on
48 the list is selected. Note that calling GetValue() returns the new
49 value of selection.
50 @event{EVT_TEXT(id, func)}
51 Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text
52 changes.
53 @event{EVT_TEXT_ENTER(id, func)}
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).
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. Also note that only wxMSW
67 supports adding or deleting items in this event.
68 @endEventTable
69
70 @library{wxcore}
71 @category{ctrl}
72 @appearance{combobox.png}
73
74 @see wxListBox, wxTextCtrl, wxChoice, wxCommandEvent
75 */
76 class wxComboBox : public wxControl,
77 public wxItemContainer,
78 public wxTextEntry
79 {
80 public:
81 /**
82 Default constructor.
83 */
84 wxComboBox();
85
86 //@{
87 /**
88 Constructor, creating and showing a combobox.
89
90 @param parent
91 Parent window. Must not be @NULL.
92 @param id
93 Window identifier. The value wxID_ANY indicates a default value.
94 @param value
95 Initial selection string. An empty string indicates no selection.
96 Notice that for the controls with @c wxCB_READONLY style this
97 string must be one of the valid choices if it is not empty.
98 @param pos
99 Window position.
100 If ::wxDefaultPosition is specified then a default position is chosen.
101 @param size
102 Window size.
103 If ::wxDefaultSize is specified then the window is sized appropriately.
104 @param n
105 Number of strings with which to initialise the control.
106 @param choices
107 An array of strings with which to initialise the control.
108 @param style
109 Window style. See wxComboBox.
110 @param validator
111 Window validator.
112 @param name
113 Window name.
114
115 @beginWxPythonOnly
116 The wxComboBox constructor in wxPython reduces the @a n and @a choices
117 arguments are to a single argument, which is a list of strings.
118 @endWxPythonOnly
119
120 @see Create(), wxValidator
121 */
122 wxComboBox(wxWindow* parent, wxWindowID id,
123 const wxString& value = wxEmptyString,
124 const wxPoint& pos = wxDefaultPosition,
125 const wxSize& size = wxDefaultSize,
126 int n = 0,
127 const wxString choices[] = NULL,
128 long style = 0,
129 const wxValidator& validator = wxDefaultValidator,
130 const wxString& name = wxComboBoxNameStr);
131 /**
132 Constructor, creating and showing a combobox.
133
134 @param parent
135 Parent window. Must not be @NULL.
136 @param id
137 Window identifier. The value wxID_ANY indicates a default value.
138 @param value
139 Initial selection string. An empty string indicates no selection.
140 @param pos
141 Window position.
142 @param size
143 Window size. If wxDefaultSize is specified then the window is sized
144 appropriately.
145 @param choices
146 An array of strings with which to initialise the control.
147 @param style
148 Window style. See wxComboBox.
149 @param validator
150 Window validator.
151 @param name
152 Window name.
153
154 @beginWxPythonOnly
155 The wxComboBox constructor in wxPython reduces the @a n and @a choices
156 arguments are to a single argument, which is a list of strings.
157 @endWxPythonOnly
158
159 @see Create(), wxValidator
160 */
161 wxComboBox(wxWindow* parent, wxWindowID id,
162 const wxString& value,
163 const wxPoint& pos,
164 const wxSize& size,
165 const wxArrayString& choices,
166 long style = 0,
167 const wxValidator& validator = wxDefaultValidator,
168 const wxString& name = wxComboBoxNameStr);
169 //@}
170
171 /**
172 Destructor, destroying the combobox.
173 */
174 virtual ~wxComboBox();
175
176 //@{
177 /**
178 Creates the combobox for two-step construction. Derived classes should
179 call or replace this function. See wxComboBox() for further details.
180 */
181 bool Create(wxWindow *parent, wxWindowID id,
182 const wxString& value = wxEmptyString,
183 const wxPoint& pos = wxDefaultPosition,
184 const wxSize& size = wxDefaultSize,
185 int n = 0, const wxString choices[] = (const wxString *) NULL,
186 long style = 0,
187 const wxValidator& validator = wxDefaultValidator,
188 const wxString& name = wxComboBoxNameStr);
189 bool Create(wxWindow *parent, wxWindowID id,
190 const wxString& value,
191 const wxPoint& pos,
192 const wxSize& size,
193 const wxArrayString& choices,
194 long style = 0,
195 const wxValidator& validator = wxDefaultValidator,
196 const wxString& name = wxComboBoxNameStr);
197 //@}
198
199 /**
200 Returns the item being selected right now.
201
202 This function does the same things as wxChoice::GetCurrentSelection()
203 and returns the item currently selected in the dropdown list if it's
204 open or the same thing as wxControlWithItems::GetSelection() otherwise.
205 */
206 virtual int GetCurrentSelection() const;
207
208 /**
209 Same as wxTextEntry::GetInsertionPoint().
210
211 @note Under wxMSW, this function always returns 0 if the combobox
212 doesn't have the focus.
213 */
214 virtual long GetInsertionPoint() const;
215
216 /**
217 Same as wxTextEntry::SetSelection().
218
219 @beginWxPythonOnly
220 This method is called SetMark() in wxPython, "SetSelection" is kept for
221 wxControlWithItems::SetSelection().
222 @endWxPythonOnly
223 */
224 virtual void SetSelection(long from, long to);
225
226 /**
227 Sets the text for the combobox text field.
228
229 Notice that this method will generate a wxEVT_COMMAND_TEXT_UPDATED
230 event, use wxTextEntry::ChangeValue() if this is undesirable.
231
232 @note For a combobox with @c wxCB_READONLY style the string must be in
233 the combobox choices list, otherwise the call to SetValue() is
234 ignored.
235
236 @param text
237 The text to set.
238 */
239 virtual void SetValue(const wxString& text);
240 };
241