]>
git.saurik.com Git - wxWidgets.git/blob - interface/combo.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxComboPopup
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
27 Default constructor. It is recommended that internal variables
28 are prepared in Init() instead
29 (because @ref mcombo() m_combo is not valid in constructor).
34 The derived class must implement this to create the popup control.
36 @returns @true if the call succeeded, @false otherwise.
38 bool Create(wxWindow
* parent
);
41 Utility function that hides the popup.
46 The derived class may implement this to return adjusted size
47 for the popup control, according to the variables given.
50 Preferred minimum width.
52 Preferred height. May be -1 to indicate
55 Max height for window, as limited by
58 @remarks Called each time popup is about to be shown.
60 wxSize
GetAdjustedSize(int minWidth
, int prefHeight
,
64 The derived class must implement this to return pointer
65 to the associated control created in Create().
67 wxWindow
* GetControl();
70 The derived class must implement this to return
71 string representation of the value.
73 wxString
GetStringValue() const;
76 The derived class must implement this to initialize
77 its internal variables. This method is called immediately
78 after construction finishes. @ref mcombo() m_combo
79 member variable has been initialized before the call.
84 Utility method that returns @true if Create has been called.
85 Useful in conjunction with LazyCreate().
87 bool IsCreated() const;
90 The derived class may implement this to return
91 @true if it wants to delay call to Create()
92 until the popup is shown for the first time. It is more
93 efficient, but on the other hand it is often more convenient
94 to have the control created immediately.
96 @remarks Base implementation returns @false.
101 The derived class may implement this to do something
102 when the parent wxComboCtrl gets double-clicked.
104 void OnComboDoubleClick();
107 The derived class may implement this to receive
108 key events from the parent wxComboCtrl.
109 Events not handled should be skipped, as usual.
111 void OnComboKeyEvent(wxKeyEvent
& event
);
114 The derived class may implement this to do
115 special processing when popup is hidden.
120 The derived class may implement this to do
121 special processing when popup is shown.
126 The derived class may implement this to paint
127 the parent wxComboCtrl.
128 Default implementation draws value as string.
130 void PaintComboControl(wxDC
& dc
, const wxRect
& rect
);
133 The derived class must implement this to receive
134 string value changes from wxComboCtrl.
136 void SetStringValue(const wxString
& value
);
140 Parent wxComboCtrl. This is parameter has
141 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}
187 @see wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup, wxCommandEvent
189 class wxComboCtrl
: public wxControl
194 Constructor, creating and showing a combo control.
197 Parent window. Must not be @NULL.
199 Window identifier. The value wxID_ANY indicates a default value.
201 Initial selection string. An empty string indicates no selection.
205 Window size. If wxDefaultSize is specified then the window is
209 Window style. See wxComboCtrl.
215 @see Create(), wxValidator
218 wxComboCtrl(wxWindow
* parent
, wxWindowID id
,
219 const wxString
& value
= "",
220 const wxPoint
& pos
= wxDefaultPosition
,
221 const wxSize
& size
= wxDefaultSize
,
223 const wxValidator
& validator
= wxDefaultValidator
,
224 const wxString
& name
= "comboCtrl");
228 Destructor, destroying the combo control.
233 This member function is not normally called in application code.
234 Instead, it can be implemented in a derived class to create a
235 custom popup animation.
237 @returns @true if animation finishes before the function returns. @false
238 otherwise. In the latter case you need to manually call
239 DoShowPopup after the animation ends.
241 virtual bool AnimateShow(const wxRect
& rect
, int flags
);
244 Copies the selected text to the clipboard.
249 Creates the combo control for two-step construction. Derived classes
250 should call or replace this function. See wxComboCtrl()
253 bool Create(wxWindow
* parent
, wxWindowID id
,
254 const wxString
& value
= "",
255 const wxPoint
& pos
= wxDefaultPosition
,
256 const wxSize
& size
= wxDefaultSize
,
258 const wxValidator
& validator
= wxDefaultValidator
,
259 const wxString
& name
= "comboCtrl");
262 Copies the selected text to the clipboard and removes the selection.
267 This member function is not normally called in application code.
268 Instead, it can be implemented in a derived class to return
269 default wxComboPopup, incase @c popup is @NULL.
270 @b Note: If you have implemented OnButtonClick to do
271 something else than show the popup, then DoSetPopupControl
272 must always return @NULL.
274 void DoSetPopupControl(wxComboPopup
* popup
);
277 This member function is not normally called in application code.
278 Instead, it must be called in a derived class to make sure popup
279 is properly shown after a popup animation has finished (but only
280 if AnimateShow() did not finish
281 the animation within it's function scope).
284 Position to show the popup window at, in screen coordinates.
286 Combination of any of the following:
288 virtual void DoShowPopup(const wxRect
& rect
, int flags
);
291 Enables or disables popup animation, if any, depending on the value of
294 void EnablePopupAnimation(bool enable
= true);
297 Returns disabled button bitmap that has been set with
300 @returns A reference to the disabled state bitmap.
302 const wxBitmap
GetBitmapDisabled() const;
305 Returns button mouse hover bitmap that has been set with
308 @returns A reference to the mouse hover state bitmap.
310 const wxBitmap
GetBitmapHover() const;
313 Returns default button bitmap that has been set with
316 @returns A reference to the normal state bitmap.
318 const wxBitmap
GetBitmapNormal() const;
321 Returns depressed button bitmap that has been set with
324 @returns A reference to the depressed state bitmap.
326 const wxBitmap
GetBitmapPressed() const;
329 Returns current size of the dropdown button.
331 wxSize
GetButtonSize();
334 Returns custom painted area in control.
336 @see SetCustomPaintWidth().
338 int GetCustomPaintWidth() const;
341 Returns features supported by wxComboCtrl. If needed feature is missing,
342 you need to instead use wxGenericComboCtrl, which however may lack
343 native look and feel (but otherwise sports identical API).
345 @returns Value returned is a combination of following flags:
347 static int GetFeatures();
350 Returns the insertion point for the combo control's text field.
351 @b Note: Under wxMSW, this function always returns 0 if the combo control
352 doesn't have the focus.
354 long GetInsertionPoint() const;
357 Returns the last position in the combo control text field.
359 long GetLastPosition() const;
362 Returns current popup interface that has been set with SetPopupControl.
364 wxComboPopup
* GetPopupControl();
367 Returns popup window containing the popup control.
369 wxWindow
* GetPopupWindow() const;
372 Get the text control which is part of the combo control.
374 wxTextCtrl
* GetTextCtrl() const;
377 Returns actual indentation in pixels.
379 wxCoord
GetTextIndent() const;
382 Returns area covered by the text field (includes everything except
383 borders and the dropdown button).
385 const wxRect
GetTextRect() const;
388 Returns text representation of the current value. For writable
389 combo control it always returns the value in the text field.
391 wxString
GetValue() const;
394 Dismisses the popup window.
399 Returns @true if the popup is currently shown
401 bool IsPopupShown() const;
404 Returns @true if the popup window is in the given state.
409 Popup window is hidden.
413 Popup window is being shown, but the
414 popup animation has not yet finished.
418 Popup window is fully visible.
420 bool IsPopupWindowState(int state
) const;
423 Implement in a derived class to define what happens on
424 dropdown button click.
425 Default action is to show the popup.
426 @b Note: If you implement this to do something else than
427 show the popup, you must then also implement
428 DoSetPopupControl() to always
431 void OnButtonClick();
434 Pastes text from the clipboard to the text field.
439 Removes the text between the two positions in the combo control text field.
446 void Remove(long from
, long to
);
449 Replaces the text between two positions with the given text, in the combo
459 void Replace(long from
, long to
, const wxString
& value
);
462 Sets custom dropdown button graphics.
465 Default button image.
467 If @true, blank push button background is painted
470 Depressed button image.
472 Button image when mouse hovers above it. This
473 should be ignored on platforms and themes that do not generally draw
474 different kind of button on mouse hover.
476 Disabled button image.
478 void SetButtonBitmaps(const wxBitmap
& bmpNormal
,
479 bool pushButtonBg
= false,
480 const wxBitmap
& bmpPressed
= wxNullBitmap
,
481 const wxBitmap
& bmpHover
= wxNullBitmap
,
482 const wxBitmap
& bmpDisabled
= wxNullBitmap
);
485 Sets size and position of dropdown button.
488 Button width. Value = 0 specifies default.
490 Button height. Value = 0 specifies default.
492 Indicates which side the button will be placed.
493 Value can be wxLEFT or wxRIGHT.
495 Horizontal spacing around the button. Default is 0.
497 void SetButtonPosition(int width
= -1, int height
= -1,
502 Set width, in pixels, of custom painted area in control without @c wxCB_READONLY
503 style. In read-only wxOwnerDrawnComboBox, this is used
504 to indicate area that is not covered by the focus rectangle.
506 void SetCustomPaintWidth(int width
);
509 Sets the insertion point in the text field.
512 The new insertion point.
514 void SetInsertionPoint(long pos
);
517 Sets the insertion point at the end of the combo control text field.
519 void SetInsertionPointEnd();
522 Set side of the control to which the popup will align itself. Valid values are
523 @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that the most appropriate
524 side is used (which, currently, is always @c wxLEFT).
526 void SetPopupAnchor(int anchorSide
);
529 Set popup interface class derived from wxComboPopup.
530 This method should be called as soon as possible after the control
531 has been created, unless OnButtonClick()
534 void SetPopupControl(wxComboPopup
* popup
);
537 Extends popup size horizontally, relative to the edges of the combo control.
540 How many pixel to extend beyond the left edge of the
541 control. Default is 0.
543 How many pixel to extend beyond the right edge of the
544 control. Default is 0.
546 @remarks Popup minimum width may override arguments.
548 void SetPopupExtents(int extLeft
, int extRight
);
551 Sets preferred maximum height of the popup.
553 @remarks Value -1 indicates the default.
555 void SetPopupMaxHeight(int height
);
558 Sets minimum width of the popup. If wider than combo control, it will extend to
561 @remarks Value -1 indicates the default.
563 void SetPopupMinWidth(int width
);
566 Selects the text between the two positions, in the combo control text field.
573 void SetSelection(long from
, long to
);
576 Sets the text for the text field without affecting the
577 popup. Thus, unlike SetValue(), it works
578 equally well with combo control using @c wxCB_READONLY style.
580 void SetText(const wxString
& value
);
583 This will set the space in pixels between left edge of the control and the
584 text, regardless whether control is read-only or not. Value -1 can be
585 given to indicate platform default.
587 void SetTextIndent(int indent
);
590 Sets the text for the combo control text field.
591 @b NB: For a combo control with @c wxCB_READONLY style the
592 string must be accepted by the popup (for instance, exist in the dropdown
593 list), otherwise the call to SetValue() is ignored
595 void SetValue(const wxString
& value
);
598 Same as SetValue, but also sends wxCommandEvent of type
599 wxEVT_COMMAND_TEXT_UPDATED
600 if @c withEvent is @true.
602 void SetValueWithEvent(const wxString
& value
,
603 bool withEvent
= true);
611 Undoes the last edit in the text field. Windows only.
616 Enable or disable usage of an alternative popup window, which guarantees
617 ability to focus the popup control, and allows common native controls to
618 function normally. This alternative popup window is usually a wxDialog,
619 and as such, when it is shown, its parent top-level window will appear
620 as if the focus has been lost from it.
622 void UseAltPopupWindow(bool enable
= true);