1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboCtrl declaration
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_COMBOCONTROL_H_BASE_
12 #define _WX_COMBOCONTROL_H_BASE_
16 A few words about all the classes defined in this file are probably in
17 order: why do we need extra wxComboCtrl and wxComboPopup classes?
19 This is because a traditional combobox is a combination of a text control
20 (with a button allowing to open the pop down list) with a listbox and
21 wxComboBox class is exactly such control, however we want to also have other
22 combinations - in fact, we want to allow anything at all to be used as pop
23 down list, not just a wxListBox.
25 So we define a base wxComboCtrl which can use any control as pop down
26 list and wxComboBox deriving from it which implements the standard wxWidgets
27 combobox API. wxComboCtrl needs to be told somehow which control to use
28 and this is done by SetPopupControl(). However, we need something more than
29 just a wxControl in this method as, for example, we need to call
30 SetSelection("initial text value") and wxControl doesn't have such method.
31 So we also need a wxComboPopup which is just a very simple interface which
32 must be implemented by a control to be usable as a popup.
34 We couldn't derive wxComboPopup from wxControl as this would make it
35 impossible to have a class deriving from both wxListBx and from it, so
36 instead it is just a mix-in.
44 #include "wx/control.h"
45 #include "wx/renderer.h" // this is needed for wxCONTROL_XXX flags
46 #include "wx/bitmap.h" // wxBitmap used by-value
47 #include "wx/textentry.h"
49 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
50 class WXDLLIMPEXP_FWD_CORE wxComboPopup
;
53 // New window styles for wxComboCtrlBase
57 // Double-clicking a read-only combo triggers call to popup's OnComboPopup.
58 // In wxOwnerDrawnComboBox, for instance, it cycles item.
59 wxCC_SPECIAL_DCLICK
= 0x0100,
61 // Dropbutton acts like standard push button.
62 wxCC_STD_BUTTON
= 0x0200
66 // wxComboCtrl internal flags
69 // First those that can be passed to Customize.
70 // It is Windows style for all flags to be clear.
72 // Button is preferred outside the border (GTK style)
73 wxCC_BUTTON_OUTSIDE_BORDER
= 0x0001,
74 // Show popup on mouse up instead of mouse down (which is the Windows style)
75 wxCC_POPUP_ON_MOUSE_UP
= 0x0002,
76 // All text is not automatically selected on click
77 wxCC_NO_TEXT_AUTO_SELECT
= 0x0004,
78 // Drop-button stays down as long as popup is displayed.
79 wxCC_BUTTON_STAYS_DOWN
= 0x0008,
80 // Drop-button covers the entire control.
81 wxCC_FULL_BUTTON
= 0x0010,
82 // Drop-button goes over the custom-border (used under WinVista).
83 wxCC_BUTTON_COVERS_BORDER
= 0x0020,
85 // Internal use: signals creation is complete
86 wxCC_IFLAG_CREATED
= 0x0100,
87 // Internal use: really put button outside
88 wxCC_IFLAG_BUTTON_OUTSIDE
= 0x0200,
89 // Internal use: SetMargins has been successfully called
90 wxCC_IFLAG_LEFT_MARGIN_SET
= 0x0400,
91 // Internal use: Set wxTAB_TRAVERSAL to parent when popup is dismissed
92 wxCC_IFLAG_PARENT_TAB_TRAVERSAL
= 0x0800,
93 // Internal use: Secondary popup window type should be used (if available).
94 wxCC_IFLAG_USE_ALT_POPUP
= 0x1000,
95 // Internal use: Skip popup animation.
96 wxCC_IFLAG_DISABLE_POPUP_ANIM
= 0x2000,
97 // Internal use: Drop-button is a bitmap button or has non-default size
98 // (but can still be on either side of the control), regardless whether
99 // specified by the platform or the application.
100 wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
= 0x4000
104 // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
107 wxCC_MF_ON_BUTTON
= 0x0001, // cursor is on dropbutton area
108 wxCC_MF_ON_CLICK_AREA
= 0x0002 // cursor is on dropbutton or other area
109 // that can be clicked to show the popup.
113 // Namespace for wxComboCtrl feature flags
114 struct wxComboCtrlFeatures
118 MovableButton
= 0x0001, // Button can be on either side of control
119 BitmapButton
= 0x0002, // Button may be replaced with bitmap
120 ButtonSpacing
= 0x0004, // Button can have spacing from the edge
122 TextIndent
= 0x0008, // SetMargins can be used to control
124 PaintControl
= 0x0010, // Combo control itself can be custom painted
125 PaintWritable
= 0x0020, // A variable-width area in front of writable
126 // combo control's textctrl can be custom
128 Borderless
= 0x0040, // wxNO_BORDER window style works
130 // There are no feature flags for...
131 // PushButtonBitmapBackground - if its in wxRendererNative, then it should be
132 // not an issue to have it automatically under the bitmap.
134 All
= MovableButton
|BitmapButton
|
135 ButtonSpacing
|TextIndent
|
136 PaintControl
|PaintWritable
|
142 class WXDLLIMPEXP_CORE wxComboCtrlBase
: public wxControl
,
145 friend class wxComboPopup
;
146 friend class wxComboPopupEvtHandler
;
149 wxComboCtrlBase() : wxControl(), wxTextEntry() { Init(); }
151 bool Create(wxWindow
*parent
,
153 const wxString
& value
,
157 const wxValidator
& validator
,
158 const wxString
& name
);
160 virtual ~wxComboCtrlBase();
162 // Show/hide popup window (wxComboBox-compatible methods)
163 virtual void Popup();
164 virtual void Dismiss()
169 // Show/hide popup window.
170 // TODO: Maybe deprecate in favor of Popup()/Dismiss().
171 // However, these functions are still called internally
172 // so it is not straightforward.
173 virtual void ShowPopup();
174 virtual void HidePopup(bool generateEvent
=false);
176 // Override for totally custom combo action
177 virtual void OnButtonClick();
179 // return true if the popup is currently shown
180 bool IsPopupShown() const { return m_popupWinState
== Visible
; }
182 // set interface class instance derived from wxComboPopup
183 // NULL popup can be used to indicate default in a derived class
184 void SetPopupControl( wxComboPopup
* popup
)
186 DoSetPopupControl(popup
);
189 // get interface class instance derived from wxComboPopup
190 wxComboPopup
* GetPopupControl()
192 EnsurePopupControl();
193 return m_popupInterface
;
196 // get the popup window containing the popup control
197 wxWindow
*GetPopupWindow() const { return m_winPopup
; }
199 // Get the text control which is part of the combobox.
200 wxTextCtrl
*GetTextCtrl() const { return m_text
; }
202 // get the dropdown button which is part of the combobox
203 // note: its not necessarily a wxButton or wxBitmapButton
204 wxWindow
*GetButton() const { return m_btn
; }
206 // forward these methods to all subcontrols
207 virtual bool Enable(bool enable
= true);
208 virtual bool Show(bool show
= true);
209 virtual bool SetFont(const wxFont
& font
);
212 // wxTextEntry methods
214 // NB: We basically need to override all of them because there is
215 // no guarantee how platform-specific wxTextEntry is implemented.
217 virtual void SetValue(const wxString
& value
)
218 { wxTextEntryBase::SetValue(value
); }
219 virtual void ChangeValue(const wxString
& value
)
220 { wxTextEntryBase::ChangeValue(value
); }
222 virtual void WriteText(const wxString
& text
);
223 virtual void AppendText(const wxString
& text
)
224 { wxTextEntryBase::AppendText(text
); }
226 virtual wxString
GetValue() const
227 { return wxTextEntryBase::GetValue(); }
229 virtual wxString
GetRange(long from
, long to
) const
230 { return wxTextEntryBase::GetRange(from
, to
); }
232 // Replace() and DoSetValue() need to be fully re-implemented since
233 // EventSuppressor utility class does not work with the way
234 // wxComboCtrl is implemented.
235 virtual void Replace(long from
, long to
, const wxString
& value
);
237 virtual void Remove(long from
, long to
);
241 virtual void Paste();
245 virtual bool CanUndo() const;
246 virtual bool CanRedo() const;
248 virtual void SetInsertionPoint(long pos
);
249 virtual long GetInsertionPoint() const;
250 virtual long GetLastPosition() const;
252 virtual void SetSelection(long from
, long to
);
253 virtual void GetSelection(long *from
, long *to
) const;
255 virtual bool IsEditable() const;
256 virtual void SetEditable(bool editable
);
258 virtual bool SetHint(const wxString
& hint
);
259 virtual wxString
GetHint() const;
261 // This method sets the text without affecting list selection
262 // (ie. wxComboPopup::SetStringValue doesn't get called).
263 void SetText(const wxString
& value
);
265 // This method sets value and also optionally sends EVT_TEXT
266 // (needed by combo popups)
267 wxDEPRECATED( void SetValueWithEvent(const wxString
& value
,
268 bool withEvent
= true) );
270 // Changes value of the control as if user had done it by selecting an
271 // item from a combo box drop-down list. Needs to be public so that
272 // derived popup classes can call it.
273 void SetValueByUser(const wxString
& value
);
276 // Popup customization methods
279 // Sets minimum width of the popup. If wider than combo control, it will extend to the left.
281 // * Value -1 indicates the default.
282 // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not).
283 void SetPopupMinWidth( int width
)
285 m_widthMinPopup
= width
;
288 // Sets preferred maximum height of the popup.
290 // * Value -1 indicates the default.
291 // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not).
292 void SetPopupMaxHeight( int height
)
294 m_heightPopup
= height
;
297 // Extends popup size horizontally, relative to the edges of the combo control.
299 // * Popup minimum width may override extLeft (ie. it has higher precedence).
300 // * Values 0 indicate default.
301 // * Custom popup may not take this fully into account (wxOwnerDrawnComboBox takes).
302 void SetPopupExtents( int extLeft
, int extRight
)
305 m_extRight
= extRight
;
308 // Set width, in pixels, of custom paint area in writable combo.
309 // In read-only, used to indicate area that is not covered by the
310 // focus rectangle (which may or may not be drawn, depending on the
312 void SetCustomPaintWidth( int width
);
313 int GetCustomPaintWidth() const { return m_widthCustomPaint
; }
315 // Set side of the control to which the popup will align itself.
316 // Valid values are wxLEFT, wxRIGHT and 0. The default value 0 wmeans
317 // that the side of the button will be used.
318 void SetPopupAnchor( int anchorSide
)
320 m_anchorSide
= anchorSide
;
323 // Set position of dropdown button.
324 // width: button width. <= 0 for default.
325 // height: button height. <= 0 for default.
326 // side: wxLEFT or wxRIGHT, indicates on which side the button will be placed.
327 // spacingX: empty space on sides of the button. Default is 0.
329 // There is no spacingY - the button will be centered vertically.
330 void SetButtonPosition( int width
= -1,
335 // Returns current size of the dropdown button.
336 wxSize
GetButtonSize();
339 // Sets dropbutton to be drawn with custom bitmaps.
341 // bmpNormal: drawn when cursor is not on button
342 // pushButtonBg: Draw push button background below the image.
343 // NOTE! This is usually only properly supported on platforms with appropriate
344 // method in wxRendererNative.
345 // bmpPressed: drawn when button is depressed
346 // bmpHover: drawn when cursor hovers on button. This is ignored on platforms
347 // that do not generally display hover differently.
348 // bmpDisabled: drawn when combobox is disabled.
349 void SetButtonBitmaps( const wxBitmap
& bmpNormal
,
350 bool pushButtonBg
= false,
351 const wxBitmap
& bmpPressed
= wxNullBitmap
,
352 const wxBitmap
& bmpHover
= wxNullBitmap
,
353 const wxBitmap
& bmpDisabled
= wxNullBitmap
);
355 #if WXWIN_COMPATIBILITY_2_8
357 // This will set the space in pixels between left edge of the control and the
358 // text, regardless whether control is read-only (ie. no wxTextCtrl) or not.
359 // Platform-specific default can be set with value-1.
361 // * This method may do nothing on some native implementations.
362 wxDEPRECATED( void SetTextIndent( int indent
) );
364 // Returns actual indentation in pixels.
365 wxDEPRECATED( wxCoord
GetTextIndent() const );
368 // Returns area covered by the text field.
369 const wxRect
& GetTextRect() const
374 // Call with enable as true to use a type of popup window that guarantees ability
375 // to focus the popup control, and normal function of common native controls.
376 // This alternative popup window is usually a wxDialog, and as such it's parent
377 // frame will appear as if the focus has been lost from it.
378 void UseAltPopupWindow( bool enable
= true )
380 wxASSERT_MSG( !m_winPopup
,
381 wxT("call this only before SetPopupControl") );
384 m_iFlags
|= wxCC_IFLAG_USE_ALT_POPUP
;
386 m_iFlags
&= ~wxCC_IFLAG_USE_ALT_POPUP
;
389 // Call with false to disable popup animation, if any.
390 void EnablePopupAnimation( bool enable
= true )
393 m_iFlags
&= ~wxCC_IFLAG_DISABLE_POPUP_ANIM
;
395 m_iFlags
|= wxCC_IFLAG_DISABLE_POPUP_ANIM
;
399 // Utilies needed by the popups or native implementations
402 // Returns true if given key combination should toggle the popup.
403 // NB: This is a separate from other keyboard handling because:
404 // 1) Replaceability.
405 // 2) Centralized code (otherwise it'd be split up between
406 // wxComboCtrl key handler and wxVListBoxComboPopup's
408 virtual bool IsKeyPopupToggle(const wxKeyEvent
& event
) const = 0;
410 // Prepare background of combo control or an item in a dropdown list
411 // in a way typical on platform. This includes painting the focus/disabled
412 // background and setting the clipping region.
413 // Unless you plan to paint your own focus indicator, you should always call this
414 // in your wxComboPopup::PaintComboControl implementation.
415 // In addition, it sets pen and text colour to what looks good and proper
416 // against the background.
417 // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control
418 // wxCONTROL_SELECTED: list item is selected
419 // wxCONTROL_DISABLED: control/item is disabled
420 virtual void PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const;
422 // Returns true if focus indicator should be drawn in the control.
423 bool ShouldDrawFocus() const
425 const wxWindow
* curFocus
= FindFocus();
426 return ( IsPopupWindowState(Hidden
) &&
427 (curFocus
== m_mainCtrlWnd
|| (m_btn
&& curFocus
== m_btn
)) &&
428 (m_windowStyle
& wxCB_READONLY
) );
431 // These methods return references to appropriate dropbutton bitmaps
432 const wxBitmap
& GetBitmapNormal() const { return m_bmpNormal
; }
433 const wxBitmap
& GetBitmapPressed() const { return m_bmpPressed
; }
434 const wxBitmap
& GetBitmapHover() const { return m_bmpHover
; }
435 const wxBitmap
& GetBitmapDisabled() const { return m_bmpDisabled
; }
437 // Set custom style flags for embedded wxTextCtrl. Usually must be used
438 // with two-step creation, before Create() call.
439 void SetTextCtrlStyle( int style
);
441 // Return internal flags
442 wxUint32
GetInternalFlags() const { return m_iFlags
; }
444 // Return true if Create has finished
445 bool IsCreated() const { return m_iFlags
& wxCC_IFLAG_CREATED
? true : false; }
447 // Need to override to return text area background colour
448 wxColour
GetBackgroundColour() const;
450 // common code to be called on popup hide/dismiss
451 void OnPopupDismiss(bool generateEvent
);
462 bool IsPopupWindowState( int state
) const { return (state
== m_popupWinState
) ? true : false; }
464 wxByte
GetPopupWindowState() const { return m_popupWinState
; }
466 // Set value returned by GetMainWindowOfCompositeControl
467 void SetCtrlMainWnd( wxWindow
* wnd
) { m_mainCtrlWnd
= wnd
; }
469 // This is public so we can access it from wxComboCtrlTextCtrl
470 virtual wxWindow
*GetMainWindowOfCompositeControl()
471 { return m_mainCtrlWnd
; }
473 // also set the embedded wxTextCtrl colours
474 virtual bool SetForegroundColour(const wxColour
& colour
);
475 virtual bool SetBackgroundColour(const wxColour
& colour
);
479 // Returns true if hint text should be drawn in the control
480 bool ShouldUseHintText(int flags
= 0) const
483 !(flags
& wxCONTROL_ISSUBMENU
) &&
484 !m_valueString
.length() &&
485 m_hintText
.length() &&
486 !ShouldDrawFocus() );
490 // Override these for customization purposes
493 // called from wxSizeEvent handler
494 virtual void OnResize() = 0;
496 // Return native text identation
497 // (i.e. text margin, for pure text, not textctrl)
498 virtual wxCoord
GetNativeTextIndent() const;
500 // Called in syscolourchanged handler and base create
501 virtual void OnThemeChange();
503 // Creates wxTextCtrl.
504 // extraStyle: Extra style parameters
505 void CreateTextCtrl( int extraStyle
);
507 // Called when text was changed programmatically
508 // (e.g. from WriteText())
509 void OnSetValue(const wxString
& value
);
511 // Installs standard input handler to combo (and optionally to the textctrl)
512 void InstallInputHandlers();
514 // Flags for DrawButton
517 Button_PaintBackground
= 0x0001, // Paints control background below the button
518 Button_BitmapOnly
= 0x0002 // Only paints the bitmap
521 // Draws dropbutton. Using wxRenderer or bitmaps, as appropriate.
522 // Flags are defined above.
523 virtual void DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
= Button_PaintBackground
);
525 // Call if cursor is on button area or mouse is captured for the button.
526 //bool HandleButtonMouseEvent( wxMouseEvent& event, bool isInside );
527 bool HandleButtonMouseEvent( wxMouseEvent
& event
, int flags
);
529 // returns true if event was consumed or filtered (event type is also set to 0 in this case)
530 bool PreprocessMouseEvent( wxMouseEvent
& event
, int flags
);
533 // This will handle left_down and left_dclick events outside button in a Windows-like manner.
534 // If you need alternate behaviour, it is recommended you manipulate and filter events to it
535 // instead of building your own handling routine (for reference, on wxEVT_LEFT_DOWN it will
536 // toggle popup and on wxEVT_LEFT_DCLICK it will do the same or run the popup's dclick method,
537 // if defined - you should pass events of other types of it for common processing).
538 void HandleNormalMouseEvent( wxMouseEvent
& event
);
540 // Creates popup window, calls interface->Create(), etc
543 // Destroy popup window and all related constructs
546 // override the base class virtuals involved in geometry calculations
547 // The common version only sets a default width, so the derived classes
548 // should override it and set the height and change the width as needed.
549 virtual wxSize
DoGetBestSize() const;
550 virtual wxSize
DoGetSizeFromTextSize(int xlen
, int ylen
= -1) const;
552 // NULL popup can be used to indicate default in a derived class
553 virtual void DoSetPopupControl(wxComboPopup
* popup
);
555 // ensures there is atleast the default popup
556 void EnsurePopupControl();
558 // Recalculates button and textctrl areas. Called when size or button setup change.
559 // btnWidth: default/calculated width of the dropbutton. 0 means unchanged,
561 void CalculateAreas( int btnWidth
= 0 );
563 // Standard textctrl positioning routine. Just give it platform-dependant
564 // textctrl coordinate adjustment.
565 virtual void PositionTextCtrl( int textCtrlXAdjust
= 0,
566 int textCtrlYAdjust
= 0);
569 void OnSizeEvent( wxSizeEvent
& event
);
570 void OnFocusEvent(wxFocusEvent
& event
);
571 void OnIdleEvent(wxIdleEvent
& event
);
572 void OnTextCtrlEvent(wxCommandEvent
& event
);
573 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
574 void OnKeyEvent(wxKeyEvent
& event
);
575 void OnCharEvent(wxKeyEvent
& event
);
577 // Set customization flags (directs how wxComboCtrlBase helpers behave)
578 void Customize( wxUint32 flags
) { m_iFlags
|= flags
; }
580 // Dispatches size event and refreshes
581 void RecalcAndRefresh();
583 // Flags for DoShowPopup and AnimateShow
586 ShowBelow
= 0x0000, // Showing popup below the control
587 ShowAbove
= 0x0001, // Showing popup above the control
588 CanDeferShow
= 0x0002 // Can only return true from AnimateShow if this is set
591 // Shows and positions the popup.
592 virtual void DoShowPopup( const wxRect
& rect
, int flags
);
594 // Implement in derived class to create a drop-down animation.
595 // Return true if finished immediately. Otherwise popup is only
596 // shown when the derived class call DoShowPopup.
597 // Flags are same as for DoShowPopup.
598 virtual bool AnimateShow( const wxRect
& rect
, int flags
);
601 virtual void DoSetToolTip( wxToolTip
*tip
);
604 // protected wxTextEntry methods
605 virtual void DoSetValue(const wxString
& value
, int flags
);
606 virtual wxString
DoGetValue() const;
607 virtual wxWindow
*GetEditableWindow() { return this; }
610 virtual bool DoSetMargins(const wxPoint
& pt
);
611 virtual wxPoint
DoGetMargins() const;
613 // This is used when m_text is hidden (readonly).
614 wxString m_valueString
;
616 // This is used when control is unfocused and m_valueString is empty
619 // the text control and button we show all the time
623 // wxPopupWindow or similar containing the window managed by the interface.
624 wxWindow
* m_winPopup
;
626 // the popup control/panel
630 wxComboPopup
* m_popupInterface
;
632 // this is input etc. handler for the text control
633 wxEvtHandler
* m_textEvtHandler
;
635 // this is for the top level window
636 wxEvtHandler
* m_toplevEvtHandler
;
638 // this is for the control in popup
639 wxEvtHandler
* m_popupEvtHandler
;
641 // this is for the popup window
642 wxEvtHandler
* m_popupWinEvtHandler
;
644 // main (ie. topmost) window of a composite control (default = this)
645 wxWindow
* m_mainCtrlWnd
;
647 // used to prevent immediate re-popupping in case closed popup
648 // by clicking on the combo control (needed because of inconsistent
649 // transient implementation across platforms).
650 wxLongLong m_timeCanAcceptClick
;
652 // how much popup should expand to the left/right of the control
656 // minimum popup width
657 wxCoord m_widthMinPopup
;
659 // preferred popup height
660 wxCoord m_heightPopup
;
662 // how much of writable combo is custom-paint by callback?
663 // also used to indicate area that is not covered by "blue"
664 // selection indicator.
665 wxCoord m_widthCustomPaint
;
667 // left margin, in pixels
668 wxCoord m_marginLeft
;
670 // side on which the popup is aligned
673 // Width of the "fake" border
674 wxCoord m_widthCustomBorder
;
676 // The button and textctrl click/paint areas
680 // Colour of the text area, in case m_text is NULL
683 // current button state (uses renderer flags)
692 // last default button width
695 // custom dropbutton bitmaps
696 wxBitmap m_bmpNormal
;
697 wxBitmap m_bmpPressed
;
699 wxBitmap m_bmpDisabled
;
701 // area used by the button
704 // platform-dependant customization and other flags
707 // custom style for m_text
710 // draw blank button background under bitmap?
711 bool m_blankButtonBg
;
713 // is the popup window currenty shown?
714 wxByte m_popupWinState
;
716 // should the focus be reset to the textctrl in idle time?
719 // is the text-area background colour overridden?
725 wxByte m_ignoreEvtText
; // Number of next EVT_TEXTs to ignore
727 // Is popup window wxPopupTransientWindow, wxPopupWindow or wxDialog?
728 wxByte m_popupWinType
;
730 DECLARE_EVENT_TABLE()
732 DECLARE_ABSTRACT_CLASS(wxComboCtrlBase
)
736 // ----------------------------------------------------------------------------
737 // wxComboPopup is the interface which must be implemented by a control to be
738 // used as a popup by wxComboCtrl
739 // ----------------------------------------------------------------------------
742 // wxComboPopup internal flags
745 wxCP_IFLAG_CREATED
= 0x0001 // Set by wxComboCtrlBase after Create is called
748 class WXDLLIMPEXP_FWD_CORE wxComboCtrl
;
751 class WXDLLIMPEXP_CORE wxComboPopup
753 friend class wxComboCtrlBase
;
761 // This is called immediately after construction finishes. m_combo member
762 // variable has been initialized before the call.
763 // NOTE: It is not in constructor so the derived class doesn't need to redefine
764 // a default constructor of its own.
765 virtual void Init() { }
767 virtual ~wxComboPopup();
769 // Create the popup child control.
770 // Return true for success.
771 virtual bool Create(wxWindow
* parent
) = 0;
773 // Calls Destroy() for the popup control (i.e. one returned by
774 // GetControl()) and makes sure that 'this' is deleted at the end.
775 // Default implementation works for both cases where popup control
776 // class is multiple inherited or created on heap as a separate
778 virtual void DestroyPopup();
780 // We must have an associated control which is subclassed by the combobox.
781 virtual wxWindow
*GetControl() = 0;
783 // Called immediately after the popup is shown
784 virtual void OnPopup();
786 // Called when popup is dismissed
787 virtual void OnDismiss();
789 // Called just prior to displaying popup.
790 // Default implementation does nothing.
791 virtual void SetStringValue( const wxString
& value
);
793 // Gets displayed string representation of the value.
794 virtual wxString
GetStringValue() const = 0;
796 // Called to check if the popup - when an item container - actually
797 // has matching item. Case-sensitivity checking etc. is up to the
798 // implementation. If the found item matched the string, but is
799 // different, it should be written back to pItem. Default implementation
800 // always return true and does not alter trueItem.
801 virtual bool FindItem(const wxString
& item
, wxString
* trueItem
=NULL
);
803 // This is called to custom paint in the combo control itself (ie. not the popup).
804 // Default implementation draws value as string.
805 virtual void PaintComboControl( wxDC
& dc
, const wxRect
& rect
);
807 // Receives wxEVT_KEY_DOWN key events from the parent wxComboCtrl.
808 // Events not handled should be skipped, as usual.
809 virtual void OnComboKeyEvent( wxKeyEvent
& event
);
811 // Receives wxEVT_CHAR key events from the parent wxComboCtrl.
812 // Events not handled should be skipped, as usual.
813 virtual void OnComboCharEvent( wxKeyEvent
& event
);
815 // Implement if you need to support special action when user
816 // double-clicks on the parent wxComboCtrl.
817 virtual void OnComboDoubleClick();
819 // Return final size of popup. Called on every popup, just prior to OnShow.
820 // minWidth = preferred minimum width for window
821 // prefHeight = preferred height. Only applies if > 0,
822 // maxHeight = max height for window, as limited by screen size
823 // and should only be rounded down, if necessary.
824 virtual wxSize
GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
);
826 // Return true if you want delay call to Create until the popup is shown
827 // for the first time. It is more efficient, but note that it is often
828 // more convenient to have the control created immediately.
829 // Default returns false.
830 virtual bool LazyCreate();
839 // Returns true if Create has been called.
840 bool IsCreated() const
842 return (m_iFlags
& wxCP_IFLAG_CREATED
) ? true : false;
845 // Returns pointer to the associated parent wxComboCtrl.
846 wxComboCtrl
* GetComboCtrl() const;
848 // Default PaintComboControl behaviour
849 static void DefaultPaintComboControl( wxComboCtrlBase
* combo
,
851 const wxRect
& rect
);
854 wxComboCtrlBase
* m_combo
;
858 // Called in wxComboCtrlBase::SetPopupControl
859 void InitBase(wxComboCtrlBase
*combo
)
866 // ----------------------------------------------------------------------------
867 // include the platform-dependent header defining the real class
868 // ----------------------------------------------------------------------------
870 #if defined(__WXUNIVERSAL__)
871 // No native universal (but it must still be first in the list)
872 #elif defined(__WXMSW__)
873 #include "wx/msw/combo.h"
876 // Any ports may need generic as an alternative
877 #include "wx/generic/combo.h"
879 #endif // wxUSE_COMBOCTRL
882 // _WX_COMBOCONTROL_H_BASE_