]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: combo.h | |
968f15e2 | 3 | // Purpose: interface of wxComboCtrl and wxComboPopup |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxComboPopup | |
7c913512 | 11 | |
968f15e2 BP |
12 | In order to use a custom popup with wxComboCtrl, an interface class must be |
13 | derived from wxComboPopup. | |
1f1d2182 | 14 | |
968f15e2 | 15 | For more information on how to use it, see @ref comboctrl_custompopup. |
7c913512 | 16 | |
23324ae1 | 17 | @library{wxcore} |
968f15e2 | 18 | @category{ctrl} |
7c913512 | 19 | |
e54c96f1 | 20 | @see wxComboCtrl |
23324ae1 | 21 | */ |
7c913512 | 22 | class wxComboPopup |
23324ae1 FM |
23 | { |
24 | public: | |
25 | /** | |
968f15e2 BP |
26 | Default constructor. It is recommended that internal variables are |
27 | prepared in Init() instead (because m_combo is not valid in | |
28 | constructor). | |
23324ae1 FM |
29 | */ |
30 | wxComboPopup(); | |
31 | ||
32 | /** | |
33 | The derived class must implement this to create the popup control. | |
3c4f71cc | 34 | |
d29a9a8a | 35 | @return @true if the call succeeded, @false otherwise. |
23324ae1 | 36 | */ |
b91c4601 | 37 | virtual bool Create(wxWindow* parent) = 0; |
23324ae1 FM |
38 | |
39 | /** | |
40 | Utility function that hides the popup. | |
41 | */ | |
42 | void Dismiss(); | |
43 | ||
44 | /** | |
968f15e2 BP |
45 | The derived class may implement this to return adjusted size for the |
46 | popup control, according to the variables given. | |
3c4f71cc | 47 | |
7c913512 | 48 | @param minWidth |
4cc4bfaf | 49 | Preferred minimum width. |
7c913512 | 50 | @param prefHeight |
968f15e2 | 51 | Preferred height. May be -1 to indicate no preference. |
45a591fa | 52 | @param maxHeight |
968f15e2 | 53 | Max height for window, as limited by screen size. |
3c4f71cc | 54 | |
968f15e2 | 55 | @remarks This function is called each time popup is about to be shown. |
23324ae1 | 56 | */ |
968f15e2 | 57 | virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); |
23324ae1 | 58 | |
8c61a9ea JS |
59 | /** |
60 | Returns pointer to the associated parent wxComboCtrl. | |
61 | */ | |
62 | wxComboCtrl* GetComboCtrl() const; | |
63 | ||
23324ae1 | 64 | /** |
968f15e2 BP |
65 | The derived class must implement this to return pointer to the |
66 | associated control created in Create(). | |
23324ae1 | 67 | */ |
b91c4601 | 68 | virtual wxWindow* GetControl() = 0; |
23324ae1 FM |
69 | |
70 | /** | |
968f15e2 BP |
71 | The derived class must implement this to return string representation |
72 | of the value. | |
23324ae1 | 73 | */ |
b91c4601 | 74 | virtual wxString GetStringValue() const = 0; |
23324ae1 FM |
75 | |
76 | /** | |
968f15e2 BP |
77 | The derived class must implement this to initialize its internal |
78 | variables. This method is called immediately after construction | |
79 | finishes. m_combo member variable has been initialized before the call. | |
23324ae1 | 80 | */ |
968f15e2 | 81 | virtual void Init(); |
23324ae1 FM |
82 | |
83 | /** | |
84 | Utility method that returns @true if Create has been called. | |
968f15e2 | 85 | |
23324ae1 FM |
86 | Useful in conjunction with LazyCreate(). |
87 | */ | |
328f5751 | 88 | bool IsCreated() const; |
23324ae1 FM |
89 | |
90 | /** | |
968f15e2 BP |
91 | The derived class may implement this to return @true if it wants to |
92 | delay call to Create() until the popup is shown for the first time. It | |
93 | is more efficient, but on the other hand it is often more convenient to | |
94 | have the control created immediately. | |
3c4f71cc | 95 | |
23324ae1 FM |
96 | @remarks Base implementation returns @false. |
97 | */ | |
968f15e2 | 98 | virtual bool LazyCreate(); |
23324ae1 FM |
99 | |
100 | /** | |
968f15e2 BP |
101 | The derived class may implement this to do something when the parent |
102 | wxComboCtrl gets double-clicked. | |
23324ae1 | 103 | */ |
968f15e2 | 104 | virtual void OnComboDoubleClick(); |
23324ae1 FM |
105 | |
106 | /** | |
968f15e2 BP |
107 | The derived class may implement this to receive key events from the |
108 | parent wxComboCtrl. | |
109 | ||
23324ae1 FM |
110 | Events not handled should be skipped, as usual. |
111 | */ | |
968f15e2 | 112 | virtual void OnComboKeyEvent(wxKeyEvent& event); |
23324ae1 FM |
113 | |
114 | /** | |
968f15e2 BP |
115 | The derived class may implement this to do special processing when |
116 | popup is hidden. | |
23324ae1 | 117 | */ |
968f15e2 | 118 | virtual void OnDismiss(); |
23324ae1 FM |
119 | |
120 | /** | |
968f15e2 BP |
121 | The derived class may implement this to do special processing when |
122 | popup is shown. | |
23324ae1 | 123 | */ |
968f15e2 | 124 | virtual void OnPopup(); |
23324ae1 FM |
125 | |
126 | /** | |
968f15e2 BP |
127 | The derived class may implement this to paint the parent wxComboCtrl. |
128 | ||
23324ae1 FM |
129 | Default implementation draws value as string. |
130 | */ | |
968f15e2 | 131 | virtual void PaintComboControl(wxDC& dc, const wxRect& rect); |
23324ae1 FM |
132 | |
133 | /** | |
968f15e2 BP |
134 | The derived class must implement this to receive string value changes |
135 | from wxComboCtrl. | |
23324ae1 | 136 | */ |
968f15e2 | 137 | virtual void SetStringValue(const wxString& value); |
23324ae1 | 138 | |
1fc5f383 | 139 | protected: |
23324ae1 | 140 | /** |
1fc5f383 JS |
141 | Parent wxComboCtrl. This member variable is prepared automatically |
142 | before Init() is called. | |
23324ae1 | 143 | */ |
1fc5f383 | 144 | wxComboCtrl* m_combo; |
23324ae1 FM |
145 | }; |
146 | ||
147 | ||
e54c96f1 | 148 | |
968f15e2 BP |
149 | /** |
150 | Features enabled for wxComboCtrl. | |
151 | ||
152 | @see wxComboCtrl::GetFeatures() | |
153 | */ | |
154 | struct wxComboCtrlFeatures | |
155 | { | |
156 | enum | |
157 | { | |
158 | MovableButton = 0x0001, ///< Button can be on either side of control. | |
159 | BitmapButton = 0x0002, ///< Button may be replaced with bitmap. | |
160 | ButtonSpacing = 0x0004, ///< Button can have spacing from the edge | |
161 | ///< of the control. | |
0847e36e | 162 | TextIndent = 0x0008, ///< wxComboCtrl::SetMargins() can be used. |
968f15e2 BP |
163 | PaintControl = 0x0010, ///< Combo control itself can be custom painted. |
164 | PaintWritable = 0x0020, ///< A variable-width area in front of writable | |
165 | ///< combo control's textctrl can be custom | |
166 | ///< painted. | |
167 | Borderless = 0x0040, ///< wxNO_BORDER window style works. | |
168 | ||
169 | All = MovableButton | BitmapButton | ButtonSpacing | | |
170 | TextIndent | PaintControl | PaintWritable | | |
171 | Borderless ///< All features. | |
172 | }; | |
173 | }; | |
174 | ||
175 | ||
23324ae1 FM |
176 | /** |
177 | @class wxComboCtrl | |
7c913512 | 178 | |
968f15e2 BP |
179 | A combo control is a generic combobox that allows totally custom popup. In |
180 | addition it has other customization features. For instance, position and | |
181 | size of the dropdown button can be changed. | |
1f1d2182 | 182 | |
968f15e2 | 183 | @section comboctrl_custompopup Setting Custom Popup for wxComboCtrl |
1f1d2182 FM |
184 | |
185 | wxComboCtrl needs to be told somehow which control to use and this is done | |
968f15e2 BP |
186 | by SetPopupControl(). However, we need something more than just a wxControl |
187 | in this method as, for example, we need to call | |
188 | SetStringValue("initial text value") and wxControl doesn't have such | |
189 | method. So we also need a wxComboPopup which is an interface which must be | |
190 | implemented by a control to be usable as a popup. | |
1f1d2182 FM |
191 | |
192 | We couldn't derive wxComboPopup from wxControl as this would make it | |
193 | impossible to have a class deriving from a wxWidgets control and from it, | |
194 | so instead it is just a mix-in. | |
195 | ||
196 | Here's a minimal sample of wxListView popup: | |
197 | ||
198 | @code | |
199 | #include <wx/combo.h> | |
200 | #include <wx/listctrl.h> | |
201 | ||
968f15e2 | 202 | class wxListViewComboPopup : public wxListView, public wxComboPopup |
1f1d2182 FM |
203 | { |
204 | public: | |
1f1d2182 FM |
205 | // Initialize member variables |
206 | virtual void Init() | |
207 | { | |
208 | m_value = -1; | |
209 | } | |
210 | ||
211 | // Create popup control | |
212 | virtual bool Create(wxWindow* parent) | |
213 | { | |
214 | return wxListView::Create(parent,1,wxPoint(0,0),wxDefaultSize); | |
215 | } | |
216 | ||
217 | // Return pointer to the created control | |
218 | virtual wxWindow *GetControl() { return this; } | |
219 | ||
220 | // Translate string into a list selection | |
221 | virtual void SetStringValue(const wxString& s) | |
222 | { | |
223 | int n = wxListView::FindItem(-1,s); | |
224 | if ( n >= 0 && n < wxListView::GetItemCount() ) | |
225 | wxListView::Select(n); | |
226 | } | |
227 | ||
228 | // Get list selection as a string | |
229 | virtual wxString GetStringValue() const | |
230 | { | |
231 | if ( m_value >= 0 ) | |
968f15e2 | 232 | return wxListView::GetItemText(m_value); |
1f1d2182 FM |
233 | return wxEmptyString; |
234 | } | |
235 | ||
236 | // Do mouse hot-tracking (which is typical in list popups) | |
237 | void OnMouseMove(wxMouseEvent& event) | |
238 | { | |
239 | // TODO: Move selection to cursor | |
240 | } | |
241 | ||
242 | // On mouse left up, set the value and close the popup | |
243 | void OnMouseClick(wxMouseEvent& WXUNUSED(event)) | |
244 | { | |
245 | m_value = wxListView::GetFirstSelected(); | |
246 | ||
247 | // TODO: Send event as well | |
248 | ||
249 | Dismiss(); | |
250 | } | |
251 | ||
252 | protected: | |
968f15e2 BP |
253 | |
254 | int m_value; // current item index | |
1f1d2182 FM |
255 | |
256 | private: | |
a0e9a5df | 257 | wxDECLARE_EVENT_TABLE(); |
1f1d2182 FM |
258 | }; |
259 | ||
a0e9a5df | 260 | wxBEGIN_EVENT_TABLE(wxListViewComboPopup, wxListView) |
1f1d2182 FM |
261 | EVT_MOTION(wxListViewComboPopup::OnMouseMove) |
262 | EVT_LEFT_UP(wxListViewComboPopup::OnMouseClick) | |
a0e9a5df | 263 | wxEND_EVENT_TABLE() |
1f1d2182 FM |
264 | @endcode |
265 | ||
266 | Here's how you would create and populate it in a dialog constructor: | |
267 | ||
268 | @code | |
968f15e2 | 269 | wxComboCtrl* comboCtrl = new wxComboCtrl(this, wxID_ANY, wxEmptyString); |
1f1d2182 FM |
270 | |
271 | wxListViewComboPopup* popupCtrl = new wxListViewComboPopup(); | |
272 | ||
5bc244b8 | 273 | // It is important to call SetPopupControl() as soon as possible |
1f1d2182 FM |
274 | comboCtrl->SetPopupControl(popupCtrl); |
275 | ||
276 | // Populate using wxListView methods | |
968f15e2 BP |
277 | popupCtrl->InsertItem(popupCtrl->GetItemCount(), "First Item"); |
278 | popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Second Item"); | |
279 | popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Third Item"); | |
1f1d2182 | 280 | @endcode |
7c913512 | 281 | |
23324ae1 | 282 | @beginStyleTable |
8c6791e4 | 283 | @style{wxCB_READONLY} |
23324ae1 | 284 | Text will not be editable. |
8c6791e4 | 285 | @style{wxCB_SORT} |
23324ae1 | 286 | Sorts the entries in the list alphabetically. |
8c6791e4 | 287 | @style{wxTE_PROCESS_ENTER} |
23324ae1 FM |
288 | The control will generate the event wxEVT_COMMAND_TEXT_ENTER |
289 | (otherwise pressing Enter key is either processed internally by the | |
290 | control or used for navigation between dialog controls). Windows | |
291 | only. | |
8c6791e4 | 292 | @style{wxCC_SPECIAL_DCLICK} |
23324ae1 FM |
293 | Double-clicking triggers a call to popup's OnComboDoubleClick. |
294 | Actual behaviour is defined by a derived class. For instance, | |
295 | wxOwnerDrawnComboBox will cycle an item. This style only applies if | |
296 | wxCB_READONLY is used as well. | |
8c6791e4 | 297 | @style{wxCC_STD_BUTTON} |
23324ae1 FM |
298 | Drop button will behave more like a standard push button. |
299 | @endStyleTable | |
7c913512 | 300 | |
3051a44a | 301 | @beginEventEmissionTable{wxCommandEvent} |
8c6791e4 | 302 | @event{EVT_TEXT(id, func)} |
23324ae1 | 303 | Process a wxEVT_COMMAND_TEXT_UPDATED event, when the text changes. |
8c6791e4 | 304 | @event{EVT_TEXT_ENTER(id, func)} |
23324ae1 FM |
305 | Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in |
306 | the combo control. | |
23d74d89 | 307 | @event{EVT_COMBOBOX_DROPDOWN(id, func)} |
a1d5aa93 JS |
308 | Process a wxEVT_COMMAND_COMBOBOX_DROPDOWN event, which is generated |
309 | when the popup window is shown (drops down). | |
23d74d89 | 310 | @event{EVT_COMBOBOX_CLOSEUP(id, func)} |
a1d5aa93 JS |
311 | Process a wxEVT_COMMAND_COMBOBOX_CLOSEUP event, which is generated |
312 | when the popup window of the combo control disappears (closes up). | |
bb3400a8 | 313 | You should avoid adding or deleting items in this event. |
23324ae1 | 314 | @endEventTable |
7c913512 | 315 | |
23324ae1 FM |
316 | @library{wxbase} |
317 | @category{ctrl} | |
7e59b885 | 318 | @appearance{comboctrl.png} |
7c913512 | 319 | |
968f15e2 BP |
320 | @see wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup, |
321 | wxCommandEvent | |
23324ae1 | 322 | */ |
fda62793 JS |
323 | class wxComboCtrl : public wxControl, |
324 | public wxTextEntry | |
23324ae1 FM |
325 | { |
326 | public: | |
968f15e2 BP |
327 | /** |
328 | Default constructor. | |
329 | */ | |
330 | wxComboCtrl(); | |
331 | ||
23324ae1 FM |
332 | /** |
333 | Constructor, creating and showing a combo control. | |
3c4f71cc | 334 | |
7c913512 | 335 | @param parent |
4cc4bfaf | 336 | Parent window. Must not be @NULL. |
7c913512 | 337 | @param id |
4cc4bfaf | 338 | Window identifier. The value wxID_ANY indicates a default value. |
7c913512 | 339 | @param value |
4cc4bfaf | 340 | Initial selection string. An empty string indicates no selection. |
7c913512 | 341 | @param pos |
4cc4bfaf | 342 | Window position. |
dc1b07fd | 343 | If ::wxDefaultPosition is specified then a default position is chosen. |
7c913512 | 344 | @param size |
dc1b07fd FM |
345 | Window size. |
346 | If ::wxDefaultSize is specified then the window is sized appropriately. | |
7c913512 | 347 | @param style |
4cc4bfaf | 348 | Window style. See wxComboCtrl. |
7c913512 | 349 | @param validator |
4cc4bfaf | 350 | Window validator. |
7c913512 | 351 | @param name |
4cc4bfaf | 352 | Window name. |
3c4f71cc | 353 | |
4cc4bfaf | 354 | @see Create(), wxValidator |
23324ae1 | 355 | */ |
4707b84c FM |
356 | wxComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, |
357 | const wxString& value = wxEmptyString, | |
7c913512 FM |
358 | const wxPoint& pos = wxDefaultPosition, |
359 | const wxSize& size = wxDefaultSize, | |
360 | long style = 0, | |
361 | const wxValidator& validator = wxDefaultValidator, | |
9d9c1c24 | 362 | const wxString& name = wxComboBoxNameStr); |
23324ae1 FM |
363 | |
364 | /** | |
365 | Destructor, destroying the combo control. | |
366 | */ | |
968f15e2 | 367 | virtual ~wxComboCtrl(); |
23324ae1 | 368 | |
23324ae1 FM |
369 | /** |
370 | Copies the selected text to the clipboard. | |
371 | */ | |
968f15e2 | 372 | virtual void Copy(); |
23324ae1 FM |
373 | |
374 | /** | |
375 | Creates the combo control for two-step construction. Derived classes | |
968f15e2 BP |
376 | should call or replace this function. See wxComboCtrl() for further |
377 | details. | |
23324ae1 | 378 | */ |
4707b84c FM |
379 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, |
380 | const wxString& value = wxEmptyString, | |
23324ae1 FM |
381 | const wxPoint& pos = wxDefaultPosition, |
382 | const wxSize& size = wxDefaultSize, | |
383 | long style = 0, | |
384 | const wxValidator& validator = wxDefaultValidator, | |
9d9c1c24 | 385 | const wxString& name = wxComboBoxNameStr); |
23324ae1 FM |
386 | |
387 | /** | |
388 | Copies the selected text to the clipboard and removes the selection. | |
389 | */ | |
968f15e2 | 390 | virtual void Cut(); |
23324ae1 | 391 | |
ffb9247a JS |
392 | /** |
393 | Dismisses the popup window. | |
394 | ||
395 | Notice that calling this function will generate a | |
396 | wxEVT_COMMAND_COMBOBOX_CLOSEUP event. | |
397 | ||
398 | @since 2.9.2 | |
399 | */ | |
400 | virtual void Dismiss(); | |
401 | ||
402 | ||
23324ae1 FM |
403 | /** |
404 | Enables or disables popup animation, if any, depending on the value of | |
405 | the argument. | |
406 | */ | |
4cc4bfaf | 407 | void EnablePopupAnimation(bool enable = true); |
23324ae1 FM |
408 | |
409 | /** | |
410 | Returns disabled button bitmap that has been set with | |
411 | SetButtonBitmaps(). | |
3c4f71cc | 412 | |
d29a9a8a | 413 | @return A reference to the disabled state bitmap. |
23324ae1 | 414 | */ |
4707b84c | 415 | const wxBitmap& GetBitmapDisabled() const; |
23324ae1 FM |
416 | |
417 | /** | |
418 | Returns button mouse hover bitmap that has been set with | |
419 | SetButtonBitmaps(). | |
3c4f71cc | 420 | |
d29a9a8a | 421 | @return A reference to the mouse hover state bitmap. |
23324ae1 | 422 | */ |
4707b84c | 423 | const wxBitmap& GetBitmapHover() const; |
23324ae1 FM |
424 | |
425 | /** | |
426 | Returns default button bitmap that has been set with | |
427 | SetButtonBitmaps(). | |
3c4f71cc | 428 | |
d29a9a8a | 429 | @return A reference to the normal state bitmap. |
23324ae1 | 430 | */ |
4707b84c | 431 | const wxBitmap& GetBitmapNormal() const; |
23324ae1 FM |
432 | |
433 | /** | |
434 | Returns depressed button bitmap that has been set with | |
435 | SetButtonBitmaps(). | |
3c4f71cc | 436 | |
d29a9a8a | 437 | @return A reference to the depressed state bitmap. |
23324ae1 | 438 | */ |
4707b84c | 439 | const wxBitmap& GetBitmapPressed() const; |
23324ae1 FM |
440 | |
441 | /** | |
442 | Returns current size of the dropdown button. | |
443 | */ | |
444 | wxSize GetButtonSize(); | |
445 | ||
446 | /** | |
447 | Returns custom painted area in control. | |
3c4f71cc | 448 | |
4cc4bfaf | 449 | @see SetCustomPaintWidth(). |
23324ae1 | 450 | */ |
328f5751 | 451 | int GetCustomPaintWidth() const; |
23324ae1 FM |
452 | |
453 | /** | |
968f15e2 BP |
454 | Returns features supported by wxComboCtrl. If needed feature is |
455 | missing, you need to instead use wxGenericComboCtrl, which however may | |
456 | lack a native look and feel (but otherwise sports identical API). | |
3c4f71cc | 457 | |
d29a9a8a BP |
458 | @return Value returned is a combination of the flags defined in |
459 | wxComboCtrlFeatures. | |
23324ae1 FM |
460 | */ |
461 | static int GetFeatures(); | |
462 | ||
107defe3 JS |
463 | /** |
464 | Returns the current hint string. | |
465 | ||
466 | See SetHint() for more information about hints. | |
467 | ||
468 | @since 2.9.1 | |
469 | */ | |
470 | virtual wxString GetHint() const; | |
471 | ||
23324ae1 FM |
472 | /** |
473 | Returns the insertion point for the combo control's text field. | |
968f15e2 BP |
474 | |
475 | @note Under Windows, this function always returns 0 if the combo | |
476 | control doesn't have the focus. | |
23324ae1 | 477 | */ |
968f15e2 | 478 | virtual long GetInsertionPoint() const; |
23324ae1 FM |
479 | |
480 | /** | |
481 | Returns the last position in the combo control text field. | |
482 | */ | |
968f15e2 | 483 | virtual long GetLastPosition() const; |
23324ae1 | 484 | |
0847e36e JS |
485 | /** |
486 | Returns the margins used by the control. The @c x field of the returned | |
487 | point is the horizontal margin and the @c y field is the vertical one. | |
488 | ||
489 | @remarks If given margin cannot be accurately determined, its value | |
490 | will be set to -1. | |
491 | ||
492 | @see SetMargins() | |
493 | ||
494 | @since 2.9.1 | |
495 | */ | |
496 | wxPoint GetMargins() const; | |
497 | ||
23324ae1 | 498 | /** |
968f15e2 BP |
499 | Returns current popup interface that has been set with |
500 | SetPopupControl(). | |
23324ae1 FM |
501 | */ |
502 | wxComboPopup* GetPopupControl(); | |
503 | ||
504 | /** | |
505 | Returns popup window containing the popup control. | |
506 | */ | |
328f5751 | 507 | wxWindow* GetPopupWindow() const; |
23324ae1 FM |
508 | |
509 | /** | |
510 | Get the text control which is part of the combo control. | |
511 | */ | |
328f5751 | 512 | wxTextCtrl* GetTextCtrl() const; |
23324ae1 FM |
513 | |
514 | /** | |
515 | Returns actual indentation in pixels. | |
0847e36e JS |
516 | |
517 | @deprecated Use GetMargins() instead. | |
23324ae1 | 518 | */ |
328f5751 | 519 | wxCoord GetTextIndent() const; |
23324ae1 FM |
520 | |
521 | /** | |
522 | Returns area covered by the text field (includes everything except | |
523 | borders and the dropdown button). | |
524 | */ | |
4707b84c | 525 | const wxRect& GetTextRect() const; |
23324ae1 FM |
526 | |
527 | /** | |
968f15e2 BP |
528 | Returns text representation of the current value. For writable combo |
529 | control it always returns the value in the text field. | |
23324ae1 | 530 | */ |
968f15e2 | 531 | virtual wxString GetValue() const; |
23324ae1 FM |
532 | |
533 | /** | |
534 | Dismisses the popup window. | |
a1d5aa93 JS |
535 | |
536 | @param generateEvent | |
537 | Set this to @true in order to generate | |
538 | wxEVT_COMMAND_COMBOBOX_CLOSEUP event. | |
ffb9247a JS |
539 | |
540 | @deprecated Use Dismiss() instead. | |
23324ae1 | 541 | */ |
a1d5aa93 | 542 | virtual void HidePopup(bool generateEvent=false); |
23324ae1 FM |
543 | |
544 | /** | |
545 | Returns @true if the popup is currently shown | |
546 | */ | |
328f5751 | 547 | bool IsPopupShown() const; |
23324ae1 FM |
548 | |
549 | /** | |
968f15e2 BP |
550 | Returns @true if the popup window is in the given state. Possible |
551 | values are: | |
3c4f71cc | 552 | |
968f15e2 BP |
553 | @beginTable |
554 | @row2col{wxComboCtrl::Hidden, Popup window is hidden.} | |
555 | @row2col{wxComboCtrl::Animating, Popup window is being shown, but the | |
556 | popup animation has not yet finished.} | |
557 | @row2col{wxComboCtrl::Visible, Popup window is fully visible.} | |
558 | @endTable | |
23324ae1 | 559 | */ |
328f5751 | 560 | bool IsPopupWindowState(int state) const; |
23324ae1 FM |
561 | |
562 | /** | |
968f15e2 BP |
563 | Implement in a derived class to define what happens on dropdown button |
564 | click. Default action is to show the popup. | |
565 | ||
566 | @note If you implement this to do something else than show the popup, | |
567 | you must then also implement DoSetPopupControl() to always return | |
568 | @NULL. | |
23324ae1 | 569 | */ |
968f15e2 | 570 | virtual void OnButtonClick(); |
23324ae1 FM |
571 | |
572 | /** | |
573 | Pastes text from the clipboard to the text field. | |
574 | */ | |
968f15e2 | 575 | virtual void Paste(); |
23324ae1 | 576 | |
ffb9247a JS |
577 | /** |
578 | Shows the popup portion of the combo control. | |
579 | ||
580 | Notice that calling this function will generate a | |
581 | wxEVT_COMMAND_COMBOBOX_DROPDOWN event. | |
582 | ||
583 | @since 2.9.2 | |
584 | */ | |
585 | virtual void Popup(); | |
586 | ||
23324ae1 | 587 | /** |
968f15e2 BP |
588 | Removes the text between the two positions in the combo control text |
589 | field. | |
3c4f71cc | 590 | |
7c913512 | 591 | @param from |
4cc4bfaf | 592 | The first position. |
7c913512 | 593 | @param to |
4cc4bfaf | 594 | The last position. |
23324ae1 | 595 | */ |
968f15e2 | 596 | virtual void Remove(long from, long to); |
23324ae1 FM |
597 | |
598 | /** | |
968f15e2 BP |
599 | Replaces the text between two positions with the given text, in the |
600 | combo control text field. | |
3c4f71cc | 601 | |
7c913512 | 602 | @param from |
4cc4bfaf | 603 | The first position. |
7c913512 | 604 | @param to |
4cc4bfaf | 605 | The second position. |
7c913512 | 606 | @param text |
4cc4bfaf | 607 | The text to insert. |
23324ae1 | 608 | */ |
45a591fa | 609 | virtual void Replace(long from, long to, const wxString& text); |
23324ae1 FM |
610 | |
611 | /** | |
612 | Sets custom dropdown button graphics. | |
3c4f71cc | 613 | |
7c913512 | 614 | @param bmpNormal |
4cc4bfaf | 615 | Default button image. |
7c913512 | 616 | @param pushButtonBg |
968f15e2 | 617 | If @true, blank push button background is painted below the image. |
7c913512 | 618 | @param bmpPressed |
4cc4bfaf | 619 | Depressed button image. |
7c913512 | 620 | @param bmpHover |
968f15e2 BP |
621 | Button image when mouse hovers above it. This should be ignored on |
622 | platforms and themes that do not generally draw different kind of | |
623 | button on mouse hover. | |
7c913512 | 624 | @param bmpDisabled |
4cc4bfaf | 625 | Disabled button image. |
23324ae1 FM |
626 | */ |
627 | void SetButtonBitmaps(const wxBitmap& bmpNormal, | |
4cc4bfaf | 628 | bool pushButtonBg = false, |
23324ae1 FM |
629 | const wxBitmap& bmpPressed = wxNullBitmap, |
630 | const wxBitmap& bmpHover = wxNullBitmap, | |
631 | const wxBitmap& bmpDisabled = wxNullBitmap); | |
632 | ||
633 | /** | |
634 | Sets size and position of dropdown button. | |
3c4f71cc | 635 | |
7c913512 | 636 | @param width |
4cc4bfaf | 637 | Button width. Value = 0 specifies default. |
7c913512 | 638 | @param height |
4cc4bfaf | 639 | Button height. Value = 0 specifies default. |
7c913512 | 640 | @param side |
968f15e2 BP |
641 | Indicates which side the button will be placed. Value can be wxLEFT |
642 | or wxRIGHT. | |
7c913512 | 643 | @param spacingX |
4cc4bfaf | 644 | Horizontal spacing around the button. Default is 0. |
23324ae1 FM |
645 | */ |
646 | void SetButtonPosition(int width = -1, int height = -1, | |
968f15e2 | 647 | int side = wxRIGHT, int spacingX = 0); |
23324ae1 FM |
648 | |
649 | /** | |
968f15e2 BP |
650 | Set width, in pixels, of custom painted area in control without |
651 | @c wxCB_READONLY style. In read-only wxOwnerDrawnComboBox, this is used | |
23324ae1 FM |
652 | to indicate area that is not covered by the focus rectangle. |
653 | */ | |
654 | void SetCustomPaintWidth(int width); | |
655 | ||
107defe3 JS |
656 | /** |
657 | Sets a hint shown in an empty unfocused combo control. | |
658 | ||
659 | Notice that hints are known as <em>cue banners</em> under MSW or | |
660 | <em>placeholder strings</em> under OS X. | |
661 | ||
662 | @see wxTextEntry::SetHint() | |
663 | ||
664 | @since 2.9.1 | |
665 | */ | |
666 | virtual void SetHint(const wxString& hint); | |
667 | ||
23324ae1 FM |
668 | /** |
669 | Sets the insertion point in the text field. | |
3c4f71cc | 670 | |
7c913512 | 671 | @param pos |
4cc4bfaf | 672 | The new insertion point. |
23324ae1 | 673 | */ |
968f15e2 | 674 | virtual void SetInsertionPoint(long pos); |
23324ae1 FM |
675 | |
676 | /** | |
677 | Sets the insertion point at the end of the combo control text field. | |
678 | */ | |
968f15e2 | 679 | virtual void SetInsertionPointEnd(); |
23324ae1 | 680 | |
0847e36e JS |
681 | //@{ |
682 | /** | |
683 | Attempts to set the control margins. When margins are given as wxPoint, | |
684 | x indicates the left and y the top margin. Use -1 to indicate that | |
685 | an existing value should be used. | |
686 | ||
687 | @return | |
688 | @true if setting of all requested margins was successful. | |
689 | ||
690 | @since 2.9.1 | |
691 | */ | |
692 | bool SetMargins(const wxPoint& pt); | |
693 | bool SetMargins(wxCoord left, wxCoord top = -1); | |
694 | //@} | |
695 | ||
23324ae1 | 696 | /** |
968f15e2 BP |
697 | Set side of the control to which the popup will align itself. Valid |
698 | values are @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that | |
699 | the most appropriate side is used (which, currently, is always | |
700 | @c wxLEFT). | |
23324ae1 FM |
701 | */ |
702 | void SetPopupAnchor(int anchorSide); | |
703 | ||
704 | /** | |
968f15e2 BP |
705 | Set popup interface class derived from wxComboPopup. This method should |
706 | be called as soon as possible after the control has been created, | |
707 | unless OnButtonClick() has been overridden. | |
23324ae1 FM |
708 | */ |
709 | void SetPopupControl(wxComboPopup* popup); | |
710 | ||
711 | /** | |
968f15e2 BP |
712 | Extends popup size horizontally, relative to the edges of the combo |
713 | control. | |
3c4f71cc | 714 | |
7c913512 | 715 | @param extLeft |
968f15e2 BP |
716 | How many pixel to extend beyond the left edge of the control. |
717 | Default is 0. | |
7c913512 | 718 | @param extRight |
968f15e2 BP |
719 | How many pixel to extend beyond the right edge of the control. |
720 | Default is 0. | |
3c4f71cc | 721 | |
968f15e2 BP |
722 | @remarks Popup minimum width may override arguments. It is up to the |
723 | popup to fully take this into account. | |
23324ae1 FM |
724 | */ |
725 | void SetPopupExtents(int extLeft, int extRight); | |
726 | ||
727 | /** | |
728 | Sets preferred maximum height of the popup. | |
3c4f71cc | 729 | |
23324ae1 FM |
730 | @remarks Value -1 indicates the default. |
731 | */ | |
732 | void SetPopupMaxHeight(int height); | |
733 | ||
734 | /** | |
968f15e2 BP |
735 | Sets minimum width of the popup. If wider than combo control, it will |
736 | extend to the left. | |
3c4f71cc | 737 | |
968f15e2 BP |
738 | @remarks Value -1 indicates the default. Also, popup implementation may |
739 | choose to ignore this. | |
23324ae1 FM |
740 | */ |
741 | void SetPopupMinWidth(int width); | |
742 | ||
743 | /** | |
968f15e2 BP |
744 | Selects the text between the two positions, in the combo control text |
745 | field. | |
3c4f71cc | 746 | |
7c913512 | 747 | @param from |
4cc4bfaf | 748 | The first position. |
7c913512 | 749 | @param to |
4cc4bfaf | 750 | The second position. |
23324ae1 | 751 | */ |
968f15e2 | 752 | virtual void SetSelection(long from, long to); |
23324ae1 FM |
753 | |
754 | /** | |
968f15e2 BP |
755 | Sets the text for the text field without affecting the popup. Thus, |
756 | unlike SetValue(), it works equally well with combo control using | |
757 | @c wxCB_READONLY style. | |
23324ae1 FM |
758 | */ |
759 | void SetText(const wxString& value); | |
760 | ||
1ac5cfc7 JS |
761 | /** |
762 | Set a custom window style for the embedded wxTextCtrl. Usually you | |
763 | will need to use this during two-step creation, just before Create(). | |
764 | For example: | |
765 | ||
766 | @code | |
767 | wxComboCtrl* comboCtrl = new wxComboCtrl(); | |
768 | ||
769 | // Let's make the text right-aligned | |
770 | comboCtrl->SetTextCtrlStyle(wxTE_RIGHT); | |
771 | ||
772 | comboCtrl->Create(parent, wxID_ANY, wxEmptyString); | |
773 | @endcode | |
774 | */ | |
775 | void SetTextCtrlStyle( int style ); | |
776 | ||
23324ae1 | 777 | /** |
968f15e2 BP |
778 | This will set the space in pixels between left edge of the control and |
779 | the text, regardless whether control is read-only or not. Value -1 can | |
780 | be given to indicate platform default. | |
0847e36e JS |
781 | |
782 | @deprecated Use SetMargins() instead. | |
23324ae1 FM |
783 | */ |
784 | void SetTextIndent(int indent); | |
785 | ||
786 | /** | |
787 | Sets the text for the combo control text field. | |
968f15e2 BP |
788 | |
789 | @note For a combo control with @c wxCB_READONLY style the string must | |
790 | be accepted by the popup (for instance, exist in the dropdown | |
791 | list), otherwise the call to SetValue() is ignored. | |
23324ae1 | 792 | */ |
968f15e2 | 793 | virtual void SetValue(const wxString& value); |
23324ae1 FM |
794 | |
795 | /** | |
968f15e2 BP |
796 | Same as SetValue(), but also sends wxCommandEvent of type |
797 | wxEVT_COMMAND_TEXT_UPDATED if @a withEvent is @true. | |
23324ae1 | 798 | */ |
968f15e2 | 799 | void SetValueWithEvent(const wxString& value, bool withEvent = true); |
23324ae1 FM |
800 | |
801 | /** | |
802 | Show the popup. | |
ffb9247a JS |
803 | |
804 | @deprecated Use Popup() instead. | |
23324ae1 | 805 | */ |
968f15e2 | 806 | virtual void ShowPopup(); |
23324ae1 FM |
807 | |
808 | /** | |
809 | Undoes the last edit in the text field. Windows only. | |
810 | */ | |
968f15e2 | 811 | virtual void Undo(); |
23324ae1 FM |
812 | |
813 | /** | |
968f15e2 BP |
814 | Enable or disable usage of an alternative popup window, which |
815 | guarantees ability to focus the popup control, and allows common native | |
816 | controls to function normally. This alternative popup window is usually | |
817 | a wxDialog, and as such, when it is shown, its parent top-level window | |
818 | will appear as if the focus has been lost from it. | |
23324ae1 | 819 | */ |
4cc4bfaf | 820 | void UseAltPopupWindow(bool enable = true); |
b91c4601 FM |
821 | |
822 | protected: | |
823 | ||
824 | /** | |
825 | This member function is not normally called in application code. | |
826 | Instead, it can be implemented in a derived class to create a custom | |
827 | popup animation. | |
828 | ||
829 | The parameters are the same as those for DoShowPopup(). | |
830 | ||
831 | @return @true if animation finishes before the function returns, | |
832 | @false otherwise. In the latter case you need to manually call | |
833 | DoShowPopup() after the animation ends. | |
834 | */ | |
835 | virtual bool AnimateShow(const wxRect& rect, int flags); | |
836 | ||
837 | /** | |
838 | This member function is not normally called in application code. | |
839 | Instead, it can be implemented in a derived class to return default | |
840 | wxComboPopup, incase @a popup is @NULL. | |
841 | ||
842 | @note If you have implemented OnButtonClick() to do something else than | |
843 | show the popup, then DoSetPopupControl() must always set @a popup | |
844 | to @NULL. | |
845 | */ | |
846 | virtual void DoSetPopupControl(wxComboPopup* popup); | |
847 | ||
848 | /** | |
849 | This member function is not normally called in application code. | |
850 | Instead, it must be called in a derived class to make sure popup is | |
851 | properly shown after a popup animation has finished (but only if | |
852 | AnimateShow() did not finish the animation within its function scope). | |
853 | ||
854 | @param rect | |
855 | Position to show the popup window at, in screen coordinates. | |
856 | @param flags | |
857 | Combination of any of the following: | |
858 | @beginTable | |
859 | @row2col{wxComboCtrl::ShowAbove, | |
860 | Popup is shown above the control instead of below.} | |
861 | @row2col{wxComboCtrl::CanDeferShow, | |
862 | Showing the popup can be deferred to happen sometime after | |
863 | ShowPopup() has finished. In this case, AnimateShow() must | |
864 | return false.} | |
865 | @endTable | |
866 | */ | |
867 | virtual void DoShowPopup(const wxRect& rect, int flags); | |
23324ae1 | 868 | }; |
e54c96f1 | 869 |