]>
git.saurik.com Git - wxWidgets.git/blob - interface/combo.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxComboPopup class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 In order to use a custom popup with wxComboCtrl,
14 an interface class must be derived from wxComboPopup. For more information
15 how to use it, see @ref overview_wxcomboctrl "Setting Custom Popup for
28 Default constructor. It is recommended that internal variables
29 are prepared in Init() instead
30 (because @ref mcombo() m_combo is not valid in constructor).
35 The derived class must implement this to create the popup control.
37 @returns @true if the call succeeded, @false otherwise.
39 bool Create(wxWindow
* parent
);
42 Utility function that hides the popup.
47 The derived class may implement this to return adjusted size
48 for the popup control, according to the variables given.
51 Preferred minimum width.
54 Preferred height. May be -1 to indicate
58 Max height for window, as limited by
61 @remarks Called each time popup is about to be shown.
63 wxSize
GetAdjustedSize(int minWidth
, int prefHeight
,
67 The derived class must implement this to return pointer
68 to the associated control created in Create().
70 wxWindow
* GetControl();
73 The derived class must implement this to return
74 string representation of the value.
76 wxString
GetStringValue();
79 The derived class must implement this to initialize
80 its internal variables. This method is called immediately
81 after construction finishes. @ref mcombo() m_combo
82 member variable has been initialized before the call.
87 Utility method that returns @true if Create has been called.
89 Useful in conjunction with LazyCreate().
94 The derived class may implement this to return
95 @true if it wants to delay call to Create()
96 until the popup is shown for the first time. It is more
97 efficient, but on the other hand it is often more convenient
98 to have the control created immediately.
100 @remarks Base implementation returns @false.
105 The derived class may implement this to do something
106 when the parent wxComboCtrl gets double-clicked.
108 void OnComboDoubleClick();
111 The derived class may implement this to receive
112 key events from the parent wxComboCtrl.
114 Events not handled should be skipped, as usual.
116 void OnComboKeyEvent(wxKeyEvent
& event
);
119 The derived class may implement this to do
120 special processing when popup is hidden.
125 The derived class may implement this to do
126 special processing when popup is shown.
131 The derived class may implement this to paint
132 the parent wxComboCtrl.
134 Default implementation draws value as string.
136 void PaintComboControl(wxDC
& dc
, const wxRect
& rect
);
139 The derived class must implement this to receive
140 string value changes from wxComboCtrl.
142 void SetStringValue(const wxString
& value
);
147 Parent wxComboCtrl. This is parameter has
148 been prepared before Init() is called.
157 A combo control is a generic combobox that allows totally
158 custom popup. In addition it has other customization features.
159 For instance, position and size of the dropdown button
163 @style{wxCB_READONLY}:
164 Text will not be editable.
166 Sorts the entries in the list alphabetically.
167 @style{wxTE_PROCESS_ENTER}:
168 The control will generate the event wxEVT_COMMAND_TEXT_ENTER
169 (otherwise pressing Enter key is either processed internally by the
170 control or used for navigation between dialog controls). Windows
172 @style{wxCC_SPECIAL_DCLICK}:
173 Double-clicking triggers a call to popup's OnComboDoubleClick.
174 Actual behaviour is defined by a derived class. For instance,
175 wxOwnerDrawnComboBox will cycle an item. This style only applies if
176 wxCB_READONLY is used as well.
177 @style{wxCC_STD_BUTTON}:
178 Drop button will behave more like a standard push button.
182 @event{EVT_TEXT(id\, func)}:
183 Process a wxEVT_COMMAND_TEXT_UPDATED event, when the text changes.
184 @event{EVT_TEXT_ENTER(id\, func)}:
185 Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
191 @appearance{comboctrl.png}
194 wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup, wxCommandEvent
196 class wxComboCtrl
: public wxControl
201 Constructor, creating and showing a combo control.
204 Parent window. Must not be @NULL.
207 Window identifier. The value wxID_ANY indicates a default value.
210 Initial selection string. An empty string indicates no selection.
216 Window size. If wxDefaultSize is specified then the window is sized
220 Window style. See wxComboCtrl.
228 @sa Create(), wxValidator
231 wxComboCtrl(wxWindow
* parent
, wxWindowID id
,
232 const wxString
& value
= "",
233 const wxPoint
& pos
= wxDefaultPosition
,
234 const wxSize
& size
= wxDefaultSize
,
236 const wxValidator
& validator
= wxDefaultValidator
,
237 const wxString
& name
= "comboCtrl");
241 Destructor, destroying the combo control.
246 This member function is not normally called in application code.
247 Instead, it can be implemented in a derived class to create a
248 custom popup animation.
250 @returns @true if animation finishes before the function returns. @false
251 otherwise. In the latter case you need to manually
252 call DoShowPopup after the animation ends.
254 virtual bool AnimateShow(const wxRect
& rect
, int flags
);
257 Copies the selected text to the clipboard.
262 Creates the combo control for two-step construction. Derived classes
263 should call or replace this function. See wxComboCtrl()
266 bool Create(wxWindow
* parent
, wxWindowID id
,
267 const wxString
& value
= "",
268 const wxPoint
& pos
= wxDefaultPosition
,
269 const wxSize
& size
= wxDefaultSize
,
271 const wxValidator
& validator
= wxDefaultValidator
,
272 const wxString
& name
= "comboCtrl");
275 Copies the selected text to the clipboard and removes the selection.
277 #define void Cut() /* implementation is private */
280 This member function is not normally called in application code.
281 Instead, it can be implemented in a derived class to return
282 default wxComboPopup, incase @c popup is @NULL.
284 @b Note: If you have implemented OnButtonClick to do
285 something else than show the popup, then DoSetPopupControl
286 must always return @NULL.
288 void DoSetPopupControl(wxComboPopup
* popup
);
291 This member function is not normally called in application code.
292 Instead, it must be called in a derived class to make sure popup
293 is properly shown after a popup animation has finished (but only
294 if AnimateShow() did not finish
295 the animation within it's function scope).
298 Position to show the popup window at, in screen coordinates.
301 Combination of any of the following:
303 virtual void DoShowPopup(const wxRect
& rect
, int flags
);
306 Enables or disables popup animation, if any, depending on the value of
309 void EnablePopupAnimation(bool enable
= @
true);
312 Returns disabled button bitmap that has been set with
315 @returns A reference to the disabled state bitmap.
317 const wxBitmap
GetBitmapDisabled();
320 Returns button mouse hover bitmap that has been set with
323 @returns A reference to the mouse hover state bitmap.
325 const wxBitmap
GetBitmapHover();
328 Returns default button bitmap that has been set with
331 @returns A reference to the normal state bitmap.
333 const wxBitmap
GetBitmapNormal();
336 Returns depressed button bitmap that has been set with
339 @returns A reference to the depressed state bitmap.
341 const wxBitmap
GetBitmapPressed();
344 Returns current size of the dropdown button.
346 wxSize
GetButtonSize();
349 Returns custom painted area in control.
351 @sa SetCustomPaintWidth().
353 int GetCustomPaintWidth();
356 Returns features supported by wxComboCtrl. If needed feature is missing,
357 you need to instead use wxGenericComboCtrl, which however may lack
358 native look and feel (but otherwise sports identical API).
360 @returns Value returned is a combination of following flags:
362 static int GetFeatures();
365 Returns the insertion point for the combo control's text field.
367 @b Note: Under wxMSW, this function always returns 0 if the combo control
368 doesn't have the focus.
370 long GetInsertionPoint();
373 Returns the last position in the combo control text field.
375 long GetLastPosition();
378 Returns current popup interface that has been set with SetPopupControl.
380 wxComboPopup
* GetPopupControl();
383 Returns popup window containing the popup control.
385 wxWindow
* GetPopupWindow();
388 Get the text control which is part of the combo control.
390 wxTextCtrl
* GetTextCtrl();
393 Returns actual indentation in pixels.
395 wxCoord
GetTextIndent();
398 Returns area covered by the text field (includes everything except
399 borders and the dropdown button).
401 const wxRect
GetTextRect();
404 Returns text representation of the current value. For writable
405 combo control it always returns the value in the text field.
410 Dismisses the popup window.
415 Returns @true if the popup is currently shown
420 Returns @true if the popup window is in the given state.
427 Popup window is hidden.
432 Popup window is being shown, but the
433 popup animation has not yet finished.
438 Popup window is fully visible.
440 bool IsPopupWindowState(int state
);
443 Implement in a derived class to define what happens on
444 dropdown button click.
446 Default action is to show the popup.
448 @b Note: If you implement this to do something else than
449 show the popup, you must then also implement
450 DoSetPopupControl() to always
453 void OnButtonClick();
456 Pastes text from the clipboard to the text field.
461 Removes the text between the two positions in the combo control text field.
469 void Remove(long from
, long to
);
472 Replaces the text between two positions with the given text, in the combo
484 void Replace(long from
, long to
, const wxString
& value
);
487 Sets custom dropdown button graphics.
490 Default button image.
493 If @true, blank push button background is painted
497 Depressed button image.
500 Button image when mouse hovers above it. This
501 should be ignored on platforms and themes that do not generally draw
502 different kind of button on mouse hover.
505 Disabled button image.
507 void SetButtonBitmaps(const wxBitmap
& bmpNormal
,
508 bool pushButtonBg
= @
false,
509 const wxBitmap
& bmpPressed
= wxNullBitmap
,
510 const wxBitmap
& bmpHover
= wxNullBitmap
,
511 const wxBitmap
& bmpDisabled
= wxNullBitmap
);
514 Sets size and position of dropdown button.
517 Button width. Value = 0 specifies default.
520 Button height. Value = 0 specifies default.
523 Indicates which side the button will be placed.
524 Value can be wxLEFT or wxRIGHT.
527 Horizontal spacing around the button. Default is 0.
529 void SetButtonPosition(int width
= -1, int height
= -1,
534 Set width, in pixels, of custom painted area in control without @c wxCB_READONLY
535 style. In read-only wxOwnerDrawnComboBox, this is used
536 to indicate area that is not covered by the focus rectangle.
538 void SetCustomPaintWidth(int width
);
541 Sets the insertion point in the text field.
544 The new insertion point.
546 void SetInsertionPoint(long pos
);
549 Sets the insertion point at the end of the combo control text field.
551 void SetInsertionPointEnd();
554 Set side of the control to which the popup will align itself. Valid values are
555 @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that the most appropriate
556 side is used (which, currently, is always @c wxLEFT).
558 void SetPopupAnchor(int anchorSide
);
561 Set popup interface class derived from wxComboPopup.
562 This method should be called as soon as possible after the control
563 has been created, unless OnButtonClick()
566 void SetPopupControl(wxComboPopup
* popup
);
569 Extends popup size horizontally, relative to the edges of the combo control.
572 How many pixel to extend beyond the left edge of the
573 control. Default is 0.
576 How many pixel to extend beyond the right edge of the
577 control. Default is 0.
579 @remarks Popup minimum width may override arguments.
581 void SetPopupExtents(int extLeft
, int extRight
);
584 Sets preferred maximum height of the popup.
586 @remarks Value -1 indicates the default.
588 void SetPopupMaxHeight(int height
);
591 Sets minimum width of the popup. If wider than combo control, it will extend to
594 @remarks Value -1 indicates the default.
596 void SetPopupMinWidth(int width
);
599 Selects the text between the two positions, in the combo control text field.
607 void SetSelection(long from
, long to
);
610 Sets the text for the text field without affecting the
611 popup. Thus, unlike SetValue(), it works
612 equally well with combo control using @c wxCB_READONLY style.
614 void SetText(const wxString
& value
);
617 This will set the space in pixels between left edge of the control and the
618 text, regardless whether control is read-only or not. Value -1 can be
619 given to indicate platform default.
621 void SetTextIndent(int indent
);
624 Sets the text for the combo control text field.
626 @b NB: For a combo control with @c wxCB_READONLY style the
627 string must be accepted by the popup (for instance, exist in the dropdown
628 list), otherwise the call to SetValue() is ignored
630 void SetValue(const wxString
& value
);
633 Same as SetValue, but also sends wxCommandEvent of type
634 wxEVT_COMMAND_TEXT_UPDATED
635 if @c withEvent is @true.
637 void SetValueWithEvent(const wxString
& value
,
638 bool withEvent
= @
true);
646 Undoes the last edit in the text field. Windows only.
651 Enable or disable usage of an alternative popup window, which guarantees
652 ability to focus the popup control, and allows common native controls to
653 function normally. This alternative popup window is usually a wxDialog,
654 and as such, when it is shown, its parent top-level window will appear
655 as if the focus has been lost from it.
657 void UseAltPopupWindow(bool enable
= @
true);