]>
git.saurik.com Git - wxWidgets.git/blob - interface/combo.h
e007048c24363cf7d7c93ca4f6707c4a87ce4794
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.
53 Preferred height. May be -1 to indicate
56 Max height for window, as limited by
59 @remarks Called each time popup is about to be shown.
61 wxSize
GetAdjustedSize(int minWidth
, int prefHeight
,
65 The derived class must implement this to return pointer
66 to the associated control created in Create().
68 wxWindow
* GetControl();
71 The derived class must implement this to return
72 string representation of the value.
74 wxString
GetStringValue() const;
77 The derived class must implement this to initialize
78 its internal variables. This method is called immediately
79 after construction finishes. @ref mcombo() m_combo
80 member variable has been initialized before the call.
85 Utility method that returns @true if Create has been called.
86 Useful in conjunction with LazyCreate().
88 bool IsCreated() const;
91 The derived class may implement this to return
92 @true if it wants to delay call to Create()
93 until the popup is shown for the first time. It is more
94 efficient, but on the other hand it is often more convenient
95 to have the control created immediately.
97 @remarks Base implementation returns @false.
102 The derived class may implement this to do something
103 when the parent wxComboCtrl gets double-clicked.
105 void OnComboDoubleClick();
108 The derived class may implement this to receive
109 key events from the parent wxComboCtrl.
110 Events not handled should be skipped, as usual.
112 void OnComboKeyEvent(wxKeyEvent
& event
);
115 The derived class may implement this to do
116 special processing when popup is hidden.
121 The derived class may implement this to do
122 special processing when popup is shown.
127 The derived class may implement this to paint
128 the parent wxComboCtrl.
129 Default implementation draws value as string.
131 void PaintComboControl(wxDC
& dc
, const wxRect
& rect
);
134 The derived class must implement this to receive
135 string value changes from wxComboCtrl.
137 void SetStringValue(const wxString
& value
);
141 Parent wxComboCtrl. This is parameter has
142 been prepared before Init() is called.
151 A combo control is a generic combobox that allows totally
152 custom popup. In addition it has other customization features.
153 For instance, position and size of the dropdown button
157 @style{wxCB_READONLY}:
158 Text will not be editable.
160 Sorts the entries in the list alphabetically.
161 @style{wxTE_PROCESS_ENTER}:
162 The control will generate the event wxEVT_COMMAND_TEXT_ENTER
163 (otherwise pressing Enter key is either processed internally by the
164 control or used for navigation between dialog controls). Windows
166 @style{wxCC_SPECIAL_DCLICK}:
167 Double-clicking triggers a call to popup's OnComboDoubleClick.
168 Actual behaviour is defined by a derived class. For instance,
169 wxOwnerDrawnComboBox will cycle an item. This style only applies if
170 wxCB_READONLY is used as well.
171 @style{wxCC_STD_BUTTON}:
172 Drop button will behave more like a standard push button.
176 @event{EVT_TEXT(id, func)}:
177 Process a wxEVT_COMMAND_TEXT_UPDATED event, when the text changes.
178 @event{EVT_TEXT_ENTER(id, func)}:
179 Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
185 @appearance{comboctrl.png}
188 wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup, wxCommandEvent
190 class wxComboCtrl
: public wxControl
195 Constructor, creating and showing a combo control.
198 Parent window. Must not be @NULL.
200 Window identifier. The value wxID_ANY indicates a default value.
202 Initial selection string. An empty string indicates no selection.
206 Window size. If wxDefaultSize is specified then the window is
210 Window style. See wxComboCtrl.
216 @see Create(), wxValidator
219 wxComboCtrl(wxWindow
* parent
, wxWindowID id
,
220 const wxString
& value
= "",
221 const wxPoint
& pos
= wxDefaultPosition
,
222 const wxSize
& size
= wxDefaultSize
,
224 const wxValidator
& validator
= wxDefaultValidator
,
225 const wxString
& name
= "comboCtrl");
229 Destructor, destroying the combo control.
234 This member function is not normally called in application code.
235 Instead, it can be implemented in a derived class to create a
236 custom popup animation.
238 @returns @true if animation finishes before the function returns. @false
239 otherwise. In the latter case you need to manually call
240 DoShowPopup after the animation ends.
242 virtual bool AnimateShow(const wxRect
& rect
, int flags
);
245 Copies the selected text to the clipboard.
250 Creates the combo control for two-step construction. Derived classes
251 should call or replace this function. See wxComboCtrl()
254 bool Create(wxWindow
* parent
, wxWindowID id
,
255 const wxString
& value
= "",
256 const wxPoint
& pos
= wxDefaultPosition
,
257 const wxSize
& size
= wxDefaultSize
,
259 const wxValidator
& validator
= wxDefaultValidator
,
260 const wxString
& name
= "comboCtrl");
263 Copies the selected text to the clipboard and removes the selection.
268 This member function is not normally called in application code.
269 Instead, it can be implemented in a derived class to return
270 default wxComboPopup, incase @c popup is @NULL.
271 @b Note: If you have implemented OnButtonClick to do
272 something else than show the popup, then DoSetPopupControl
273 must always return @NULL.
275 void DoSetPopupControl(wxComboPopup
* popup
);
278 This member function is not normally called in application code.
279 Instead, it must be called in a derived class to make sure popup
280 is properly shown after a popup animation has finished (but only
281 if AnimateShow() did not finish
282 the animation within it's function scope).
285 Position to show the popup window at, in screen coordinates.
287 Combination of any of the following:
289 virtual void DoShowPopup(const wxRect
& rect
, int flags
);
292 Enables or disables popup animation, if any, depending on the value of
295 void EnablePopupAnimation(bool enable
= true);
298 Returns disabled button bitmap that has been set with
301 @returns A reference to the disabled state bitmap.
303 const wxBitmap
GetBitmapDisabled() const;
306 Returns button mouse hover bitmap that has been set with
309 @returns A reference to the mouse hover state bitmap.
311 const wxBitmap
GetBitmapHover() const;
314 Returns default button bitmap that has been set with
317 @returns A reference to the normal state bitmap.
319 const wxBitmap
GetBitmapNormal() const;
322 Returns depressed button bitmap that has been set with
325 @returns A reference to the depressed state bitmap.
327 const wxBitmap
GetBitmapPressed() const;
330 Returns current size of the dropdown button.
332 wxSize
GetButtonSize();
335 Returns custom painted area in control.
337 @see SetCustomPaintWidth().
339 int GetCustomPaintWidth() const;
342 Returns features supported by wxComboCtrl. If needed feature is missing,
343 you need to instead use wxGenericComboCtrl, which however may lack
344 native look and feel (but otherwise sports identical API).
346 @returns Value returned is a combination of following flags:
348 static int GetFeatures();
351 Returns the insertion point for the combo control's text field.
352 @b Note: Under wxMSW, this function always returns 0 if the combo control
353 doesn't have the focus.
355 long GetInsertionPoint() const;
358 Returns the last position in the combo control text field.
360 long GetLastPosition() const;
363 Returns current popup interface that has been set with SetPopupControl.
365 wxComboPopup
* GetPopupControl();
368 Returns popup window containing the popup control.
370 wxWindow
* GetPopupWindow() const;
373 Get the text control which is part of the combo control.
375 wxTextCtrl
* GetTextCtrl() const;
378 Returns actual indentation in pixels.
380 wxCoord
GetTextIndent() const;
383 Returns area covered by the text field (includes everything except
384 borders and the dropdown button).
386 const wxRect
GetTextRect() const;
389 Returns text representation of the current value. For writable
390 combo control it always returns the value in the text field.
392 wxString
GetValue() const;
395 Dismisses the popup window.
400 Returns @true if the popup is currently shown
402 bool IsPopupShown() const;
405 Returns @true if the popup window is in the given state.
410 Popup window is hidden.
414 Popup window is being shown, but the
415 popup animation has not yet finished.
419 Popup window is fully visible.
421 bool IsPopupWindowState(int state
) const;
424 Implement in a derived class to define what happens on
425 dropdown button click.
426 Default action is to show the popup.
427 @b Note: If you implement this to do something else than
428 show the popup, you must then also implement
429 DoSetPopupControl() to always
432 void OnButtonClick();
435 Pastes text from the clipboard to the text field.
440 Removes the text between the two positions in the combo control text field.
447 void Remove(long from
, long to
);
450 Replaces the text between two positions with the given text, in the combo
460 void Replace(long from
, long to
, const wxString
& value
);
463 Sets custom dropdown button graphics.
466 Default button image.
468 If @true, blank push button background is painted
471 Depressed button image.
473 Button image when mouse hovers above it. This
474 should be ignored on platforms and themes that do not generally draw
475 different kind of button on mouse hover.
477 Disabled button image.
479 void SetButtonBitmaps(const wxBitmap
& bmpNormal
,
480 bool pushButtonBg
= false,
481 const wxBitmap
& bmpPressed
= wxNullBitmap
,
482 const wxBitmap
& bmpHover
= wxNullBitmap
,
483 const wxBitmap
& bmpDisabled
= wxNullBitmap
);
486 Sets size and position of dropdown button.
489 Button width. Value = 0 specifies default.
491 Button height. Value = 0 specifies default.
493 Indicates which side the button will be placed.
494 Value can be wxLEFT or wxRIGHT.
496 Horizontal spacing around the button. Default is 0.
498 void SetButtonPosition(int width
= -1, int height
= -1,
503 Set width, in pixels, of custom painted area in control without @c wxCB_READONLY
504 style. In read-only wxOwnerDrawnComboBox, this is used
505 to indicate area that is not covered by the focus rectangle.
507 void SetCustomPaintWidth(int width
);
510 Sets the insertion point in the text field.
513 The new insertion point.
515 void SetInsertionPoint(long pos
);
518 Sets the insertion point at the end of the combo control text field.
520 void SetInsertionPointEnd();
523 Set side of the control to which the popup will align itself. Valid values are
524 @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that the most appropriate
525 side is used (which, currently, is always @c wxLEFT).
527 void SetPopupAnchor(int anchorSide
);
530 Set popup interface class derived from wxComboPopup.
531 This method should be called as soon as possible after the control
532 has been created, unless OnButtonClick()
535 void SetPopupControl(wxComboPopup
* popup
);
538 Extends popup size horizontally, relative to the edges of the combo control.
541 How many pixel to extend beyond the left edge of the
542 control. Default is 0.
544 How many pixel to extend beyond the right edge of the
545 control. Default is 0.
547 @remarks Popup minimum width may override arguments.
549 void SetPopupExtents(int extLeft
, int extRight
);
552 Sets preferred maximum height of the popup.
554 @remarks Value -1 indicates the default.
556 void SetPopupMaxHeight(int height
);
559 Sets minimum width of the popup. If wider than combo control, it will extend to
562 @remarks Value -1 indicates the default.
564 void SetPopupMinWidth(int width
);
567 Selects the text between the two positions, in the combo control text field.
574 void SetSelection(long from
, long to
);
577 Sets the text for the text field without affecting the
578 popup. Thus, unlike SetValue(), it works
579 equally well with combo control using @c wxCB_READONLY style.
581 void SetText(const wxString
& value
);
584 This will set the space in pixels between left edge of the control and the
585 text, regardless whether control is read-only or not. Value -1 can be
586 given to indicate platform default.
588 void SetTextIndent(int indent
);
591 Sets the text for the combo control text field.
592 @b NB: For a combo control with @c wxCB_READONLY style the
593 string must be accepted by the popup (for instance, exist in the dropdown
594 list), otherwise the call to SetValue() is ignored
596 void SetValue(const wxString
& value
);
599 Same as SetValue, but also sends wxCommandEvent of type
600 wxEVT_COMMAND_TEXT_UPDATED
601 if @c withEvent is @true.
603 void SetValueWithEvent(const wxString
& value
,
604 bool withEvent
= true);
612 Undoes the last edit in the text field. Windows only.
617 Enable or disable usage of an alternative popup window, which guarantees
618 ability to focus the popup control, and allows common native controls to
619 function normally. This alternative popup window is usually a wxDialog,
620 and as such, when it is shown, its parent top-level window will appear
621 as if the focus has been lost from it.
623 void UseAltPopupWindow(bool enable
= true);