1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/combobox.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
36 #include "wx/textctrl.h"
39 #include "wx/tooltip.h"
46 // ----------------------------------------------------------------------------
48 #define DEFAULT_DROPBUTTON_WIDTH 19
50 #define BMP_BUTTON_MARGIN 4
52 #define DEFAULT_POPUP_HEIGHT 400
54 #define DEFAULT_TEXT_INDENT 3
56 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
59 #if defined(__WXMSW__)
61 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
63 #define wxCC_GENERIC_TLW_IS_FRAME
64 #define wxComboCtrlGenericTLW wxFrame
66 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
67 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
68 // native controls work on it like normal.
69 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
70 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
71 #define FOCUS_RING 0 // No focus ring on wxMSW
73 //#undef wxUSE_POPUPWIN
74 //#define wxUSE_POPUPWIN 0
76 #elif defined(__WXGTK__)
78 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
79 // this bug: If wxDialog is hidden, its position becomes corrupt
80 // between hide and next show, but without internal coordinates being
81 // reflected (or something like that - atleast commenting out ->Hide()
82 // seemed to eliminate the position change).
84 #include "wx/dialog.h"
85 #define wxCC_GENERIC_TLW_IS_DIALOG
86 #define wxComboCtrlGenericTLW wxDialog
88 #if defined(__WXGTK20__)
89 # include "wx/gtk/private.h"
91 # include "wx/gtk1/private.h"
94 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
95 // 'perfect' popup, as it can succesfully host child controls even in
96 // popups that are shown in modal dialogs.
98 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
99 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
100 // native controls work on it like normal.
101 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
102 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
103 #define FOCUS_RING 0 // No focus ring on wxGTK
105 #elif defined(__WXMAC__)
107 #include "wx/nonownedwnd.h"
108 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
109 #define wxComboCtrlGenericTLW wxNonOwnedWindow
111 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
112 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
113 // native controls work on it like normal.
114 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
115 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
116 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
118 #undef DEFAULT_DROPBUTTON_WIDTH
119 #define DEFAULT_DROPBUTTON_WIDTH 22
121 #define COMBO_MARGIN FOCUS_RING
125 #include "wx/dialog.h"
126 #define wxCC_GENERIC_TLW_IS_DIALOG
127 #define wxComboCtrlGenericTLW wxDialog
129 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
130 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
131 // native controls work on it like normal.
132 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
133 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
139 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
140 // what the wxUSE_POPUPWIN says.
141 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
142 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
143 #undef wxUSE_POPUPWIN
144 #define wxUSE_POPUPWIN 0
149 #include "wx/popupwin.h"
151 #undef USE_TRANSIENT_POPUP
152 #define USE_TRANSIENT_POPUP 0
156 // Define different types of popup windows
160 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
161 POPUPWIN_WXPOPUPWINDOW
= 2,
162 POPUPWIN_GENERICTLW
= 3
166 #if USE_TRANSIENT_POPUP
167 // wxPopupTransientWindow is implemented
169 #define wxComboPopupWindowBase wxPopupTransientWindow
170 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
171 #define USES_WXPOPUPTRANSIENTWINDOW 1
173 #if TRANSIENT_POPUPWIN_IS_PERFECT
175 #elif POPUPWIN_IS_PERFECT
176 #define wxComboPopupWindowBase2 wxPopupWindow
177 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
178 #define USES_WXPOPUPWINDOW 1
180 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
181 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
182 #define USES_GENERICTLW 1
186 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
188 #define wxComboPopupWindowBase wxPopupWindow
189 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
190 #define USES_WXPOPUPWINDOW 1
192 #if !POPUPWIN_IS_PERFECT
193 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
194 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
195 #define USES_GENERICTLW 1
199 // wxPopupWindow is not implemented
201 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
202 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
203 #define USES_GENERICTLW 1
208 #ifndef USES_WXPOPUPTRANSIENTWINDOW
209 #define USES_WXPOPUPTRANSIENTWINDOW 0
212 #ifndef USES_WXPOPUPWINDOW
213 #define USES_WXPOPUPWINDOW 0
216 #ifndef USES_GENERICTLW
217 #define USES_GENERICTLW 0
221 #if USES_WXPOPUPWINDOW
222 #define INSTALL_TOPLEV_HANDLER 1
224 #define INSTALL_TOPLEV_HANDLER 0
228 // Returns true if given popup window type can be classified as perfect
230 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
232 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
233 wxUnusedVar(popupWinType
);
236 return ( popupWinType
== POPUPWIN_GENERICTLW
237 #if POPUPWIN_IS_PERFECT
238 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
240 #if TRANSIENT_POPUPWIN_IS_PERFECT
241 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
250 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
254 // ----------------------------------------------------------------------------
255 // wxComboFrameEventHandler takes care of hiding the popup when events happen
256 // in its top level parent.
257 // ----------------------------------------------------------------------------
259 #if INSTALL_TOPLEV_HANDLER
262 // This will no longer be necessary after wxTransientPopupWindow
263 // works well on all platforms.
266 class wxComboFrameEventHandler
: public wxEvtHandler
269 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
270 virtual ~wxComboFrameEventHandler();
274 void OnIdle( wxIdleEvent
& event
);
275 void OnMouseEvent( wxMouseEvent
& event
);
276 void OnActivate( wxActivateEvent
& event
);
277 void OnResize( wxSizeEvent
& event
);
278 void OnMove( wxMoveEvent
& event
);
279 void OnMenuEvent( wxMenuEvent
& event
);
280 void OnClose( wxCloseEvent
& event
);
283 wxWindow
* m_focusStart
;
284 wxComboCtrlBase
* m_combo
;
287 DECLARE_EVENT_TABLE()
290 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
291 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
292 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
293 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
294 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
295 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
296 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
297 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
298 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
299 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
302 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
308 wxComboFrameEventHandler::~wxComboFrameEventHandler()
312 void wxComboFrameEventHandler::OnPopup()
314 m_focusStart
= ::wxWindow::FindFocus();
317 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
319 wxWindow
* winFocused
= ::wxWindow::FindFocus();
321 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
322 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
325 winFocused
!= m_focusStart
&&
326 winFocused
!= popup
&&
327 winFocused
->GetParent() != popup
&&
328 winFocused
!= winpopup
&&
329 winFocused
->GetParent() != winpopup
&&
330 winFocused
!= m_combo
&&
331 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
334 m_combo
->HidePopup(true);
340 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
342 m_combo
->HidePopup(true);
346 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
348 m_combo
->HidePopup(true);
352 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
354 m_combo
->HidePopup(true);
358 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
360 m_combo
->HidePopup(true);
364 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
366 m_combo
->HidePopup(true);
370 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
372 m_combo
->HidePopup(true);
376 #endif // INSTALL_TOPLEV_HANDLER
378 // ----------------------------------------------------------------------------
379 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
381 // ----------------------------------------------------------------------------
383 class wxComboPopupWindow
: public wxComboPopupWindowBase
387 wxComboPopupWindow( wxComboCtrlBase
*parent
,
389 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
390 : wxComboPopupWindowBase(parent
,style
)
392 : wxComboPopupWindowBase(parent
,
403 #if USES_WXPOPUPTRANSIENTWINDOW
404 virtual bool Show( bool show
);
405 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
407 virtual void OnDismiss();
415 #if USES_WXPOPUPTRANSIENTWINDOW
416 bool wxComboPopupWindow::Show( bool show
)
418 // Guard against recursion
420 return wxComboPopupWindowBase::Show(show
);
424 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
426 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
428 if ( show
!= ptw
->IsShown() )
431 // We used to do wxPopupTransientWindow::Popup here,
432 // but this would hide normal Show, which we are
433 // also going to need.
444 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
446 return wxPopupTransientWindow::ProcessLeftDown(event
);
449 // First thing that happens when a transient popup closes is that this method gets called.
450 void wxComboPopupWindow::OnDismiss()
452 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
453 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
454 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
456 combo
->OnPopupDismiss(true);
458 #endif // USES_WXPOPUPTRANSIENTWINDOW
461 // ----------------------------------------------------------------------------
462 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
463 // of a popup window. It is separate so we can have different types
465 // ----------------------------------------------------------------------------
467 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
471 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
476 void OnSizeEvent( wxSizeEvent
& event
);
477 void OnKeyEvent(wxKeyEvent
& event
);
479 void OnActivate( wxActivateEvent
& event
);
483 wxComboCtrlBase
* m_combo
;
485 DECLARE_EVENT_TABLE()
489 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
490 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
491 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
492 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
494 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
496 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
500 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
502 // Block the event so that the popup control does not get auto-resized.
505 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
507 // Relay keyboard event to the main child controls
508 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
509 wxWindowList::iterator node
= children
.begin();
510 wxWindow
* child
= (wxWindow
*)*node
;
511 child
->GetEventHandler()->ProcessEvent(event
);
515 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
517 if ( !event
.GetActive() )
519 // Tell combo control that we are dismissed.
520 m_combo
->HidePopup(true);
528 // ----------------------------------------------------------------------------
531 // ----------------------------------------------------------------------------
533 wxComboPopup::~wxComboPopup()
537 void wxComboPopup::OnPopup()
541 void wxComboPopup::OnDismiss()
545 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
547 return wxStaticCast(m_combo
, wxComboCtrl
);
550 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
552 int WXUNUSED(maxHeight
) )
554 return wxSize(minWidth
,prefHeight
);
557 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
558 wxDC
& dc
, const wxRect
& rect
)
560 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
562 combo
->PrepareBackground(dc
,rect
,0);
564 dc
.DrawText( combo
->GetValue(),
565 rect
.x
+ combo
->m_marginLeft
,
566 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
570 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
572 DefaultPaintComboControl(m_combo
,dc
,rect
);
575 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
580 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
585 void wxComboPopup::OnComboDoubleClick()
589 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
593 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
594 wxString
* WXUNUSED(trueItem
))
599 bool wxComboPopup::LazyCreate()
604 void wxComboPopup::Dismiss()
606 m_combo
->HidePopup(true);
609 // ----------------------------------------------------------------------------
611 // ----------------------------------------------------------------------------
614 // This is pushed to the event handler queue of the child textctrl.
616 class wxComboBoxExtraInputHandler
: public wxEvtHandler
620 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
625 virtual ~wxComboBoxExtraInputHandler() { }
626 void OnKey(wxKeyEvent
& event
);
627 void OnFocus(wxFocusEvent
& event
);
630 wxComboCtrlBase
* m_combo
;
633 DECLARE_EVENT_TABLE()
637 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
638 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
639 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
640 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
641 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
642 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
646 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
648 // Let the wxComboCtrl event handler have a go first.
649 wxComboCtrlBase
* combo
= m_combo
;
651 wxKeyEvent
redirectedEvent(event
);
652 redirectedEvent
.SetId(combo
->GetId());
653 redirectedEvent
.SetEventObject(combo
);
655 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
657 // Don't let TAB through to the text ctrl - looks ugly
658 if ( event
.GetKeyCode() != WXK_TAB
)
663 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
665 // FIXME: This code does run when control is clicked,
666 // yet on Windows it doesn't select all the text.
667 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
668 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
670 if ( m_combo
->GetTextCtrl() )
671 m_combo
->GetTextCtrl()->SelectAll();
673 m_combo
->SetSelection(-1,-1);
676 // Send focus indication to parent.
677 // NB: This is needed for cases where the textctrl gets focus
678 // instead of its parent. While this may trigger multiple
679 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
680 // from combo's focus event handler), they should be quite
682 wxFocusEvent
evt2(event
);
683 evt2
.SetId(m_combo
->GetId());
684 evt2
.SetEventObject(m_combo
);
685 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
692 // This is pushed to the event handler queue of the control in popup.
695 class wxComboPopupEvtHandler
: public wxEvtHandler
699 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
703 m_beenInside
= false;
705 // Let's make it so that the popup control will not receive mouse
706 // events until mouse left button has been up.
707 m_blockEventsToPopup
= true;
709 virtual ~wxComboPopupEvtHandler() { }
711 void OnMouseEvent( wxMouseEvent
& event
);
713 // Called from wxComboCtrlBase::OnPopupDismiss
714 void OnPopupDismiss()
716 m_beenInside
= false;
717 m_blockEventsToPopup
= true;
721 wxComboCtrlBase
* m_combo
;
724 bool m_blockEventsToPopup
;
727 DECLARE_EVENT_TABLE()
731 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
732 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
736 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
738 wxPoint pt
= event
.GetPosition();
739 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
740 int evtType
= event
.GetEventType();
741 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
742 bool relayToButton
= false;
746 if ( !isInside
|| !m_combo
->IsPopupShown() )
748 // Mouse is outside the popup or popup is not actually shown (yet)
750 if ( evtType
== wxEVT_MOTION
||
751 evtType
== wxEVT_LEFT_DOWN
||
752 evtType
== wxEVT_LEFT_UP
||
753 evtType
== wxEVT_RIGHT_DOWN
)
755 // Block motion and click events outside the popup
761 // Mouse is inside the popup, which is fully shown
765 // Do not let the popup control respond to mouse events until
766 // mouse press used to display the popup has been lifted. This
767 // is important for users with slower mouse fingers or mouse
768 // drivers. Note that we have some redundancy here, just in
769 // case the popup is some native control that does not emit all
770 // mouse event types.
771 if ( evtType
== wxEVT_MOTION
)
773 if ( m_blockEventsToPopup
)
775 if ( event
.LeftIsDown() )
778 m_blockEventsToPopup
= false;
781 else if ( evtType
== wxEVT_LEFT_DOWN
)
783 if ( m_blockEventsToPopup
)
784 m_blockEventsToPopup
= false;
786 else if ( evtType
== wxEVT_LEFT_UP
)
788 if ( m_blockEventsToPopup
)
790 // On first left up, stop blocking mouse events (but still
792 m_blockEventsToPopup
= false;
795 // Also, this button press was (probably) used to display
796 // the popup, so relay it back to the drop-down button
797 // (which supposedly originated it). This is necessary to
798 // refresh it properly.
799 relayToButton
= true;
802 else if ( m_blockEventsToPopup
)
809 // Some mouse events to popup that happen outside it, before cursor
810 // has been inside the popup, need to be ignored by it but relayed to
813 if ( evtType
== wxEVT_LEFT_UP
)
815 if ( !m_combo
->IsPopupShown() )
818 relayToButton
= true;
820 else if ( !isInside
&& !m_beenInside
)
822 // Popup is shown but the cursor is not inside, nor it has been
823 relayToButton
= true;
829 wxWindow
* btn
= m_combo
->GetButton();
831 btn
->GetEventHandler()->ProcessEvent(event
);
833 // Bypass the event handling mechanism. Using it would be
834 // confusing for the platform-specific wxComboCtrl
836 m_combo
->HandleButtonMouseEvent(event
, 0);
840 // ----------------------------------------------------------------------------
841 // wxComboCtrlTextCtrl
842 // ----------------------------------------------------------------------------
844 class wxComboCtrlTextCtrl
: public wxTextCtrl
847 wxComboCtrlTextCtrl() : wxTextCtrl() { }
848 virtual ~wxComboCtrlTextCtrl() { }
850 virtual wxWindow
*GetMainWindowOfCompositeControl()
852 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
854 // Returning this instead of just 'parent' lets FindFocus work
855 // correctly even when parent control is a child of a composite
856 // generic control (as is case with wxGenericDatePickerCtrl).
857 return combo
->GetMainWindowOfCompositeControl();
861 // ----------------------------------------------------------------------------
863 // ----------------------------------------------------------------------------
866 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
867 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
868 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
869 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
870 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
871 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
872 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
873 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
874 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
875 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
876 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
880 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
882 void wxComboCtrlBase::Init()
886 m_popupWinState
= Hidden
;
889 m_popupInterface
= NULL
;
891 m_popupEvtHandler
= NULL
;
892 m_textEvtHandler
= NULL
;
894 #if INSTALL_TOPLEV_HANDLER
895 m_toplevEvtHandler
= NULL
;
898 m_mainCtrlWnd
= this;
901 m_widthMinPopup
= -1;
903 m_widthCustomPaint
= 0;
904 m_widthCustomBorder
= 0;
908 m_blankButtonBg
= false;
910 m_popupWinType
= POPUPWIN_NONE
;
911 m_btnWid
= m_btnHei
= -1;
920 m_timeCanAcceptClick
= 0;
922 m_resetFocus
= false;
925 bool wxComboCtrlBase::Create(wxWindow
*parent
,
927 const wxString
& value
,
931 const wxValidator
& validator
,
932 const wxString
& name
)
934 if ( !wxControl::Create(parent
,
938 style
| wxWANTS_CHARS
,
943 m_valueString
= value
;
947 m_marginLeft
= GetNativeTextIndent();
949 m_iFlags
|= wxCC_IFLAG_CREATED
;
951 // If x and y indicate valid size, wxSizeEvent won't be
952 // emitted automatically, so we need to add artifical one.
953 if ( size
.x
> 0 && size
.y
> 0 )
955 wxSizeEvent
evt(size
,GetId());
956 GetEventHandler()->AddPendingEvent(evt
);
962 void wxComboCtrlBase::InstallInputHandlers()
966 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
967 m_text
->PushEventHandler(m_textEvtHandler
);
972 wxComboCtrlBase::CreateTextCtrl(int style
)
974 if ( !(m_windowStyle
& wxCB_READONLY
) )
979 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
980 // not used by the wxPropertyGrid and therefore the tab is processed by
981 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
982 // navigation event is then sent to the wrong window.
983 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
985 if ( HasFlag(wxTE_PROCESS_ENTER
) )
986 style
|= wxTE_PROCESS_ENTER
;
988 // Ignore EVT_TEXT generated by the constructor (but only
989 // if the event redirector already exists)
990 // NB: This must be " = 1" instead of "++";
991 if ( m_textEvtHandler
)
996 m_text
= new wxComboCtrlTextCtrl();
997 m_text
->Create(this, wxID_ANY
, m_valueString
,
998 wxDefaultPosition
, wxSize(10,-1),
1000 m_text
->SetHint(m_hintText
);
1004 void wxComboCtrlBase::OnThemeChange()
1006 // Leave the default bg on the Mac so the area used by the focus ring will
1007 // be the correct colour and themed brush. Instead we'll use
1008 // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
1010 #if defined(__WXMSW__) || defined(__WXGTK__)
1011 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1013 wxVisualAttributes vattrs
;
1014 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1015 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1018 // Only change the colours if application has not specified
1022 SetOwnForegroundColour(vattrs
.colFg
);
1027 SetOwnBackgroundColour(vattrs
.colBg
);
1030 #endif // !__WXMAC__
1033 wxComboCtrlBase::~wxComboCtrlBase()
1038 #if INSTALL_TOPLEV_HANDLER
1039 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1040 m_toplevEvtHandler
= NULL
;
1046 m_text
->RemoveEventHandler(m_textEvtHandler
);
1048 delete m_textEvtHandler
;
1052 // ----------------------------------------------------------------------------
1054 // ----------------------------------------------------------------------------
1056 // Recalculates button and textctrl areas
1057 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1059 wxSize sz
= GetClientSize();
1060 int customBorder
= m_widthCustomBorder
;
1061 int btnBorder
; // border for button only
1063 // check if button should really be outside the border: we'll do it it if
1064 // its platform default or bitmap+pushbutton background is used, but not if
1065 // there is vertical size adjustment or horizontal spacing.
1066 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1067 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
1068 m_btnSpacingX
== 0 &&
1071 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1074 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1075 m_btnSpacingX
== 0 && !m_bmpNormal
.Ok() )
1077 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1082 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1083 btnBorder
= customBorder
;
1086 // Defaul indentation
1087 if ( m_marginLeft
< 0 )
1088 m_marginLeft
= GetNativeTextIndent();
1090 int butWidth
= btnWidth
;
1092 if ( butWidth
<= 0 )
1093 butWidth
= m_btnWidDefault
;
1095 m_btnWidDefault
= butWidth
;
1097 if ( butWidth
<= 0 )
1100 int butHeight
= sz
.y
- btnBorder
*2;
1102 // Adjust button width
1104 butWidth
= m_btnWid
;
1107 // Adjust button width to match aspect ratio
1108 // (but only if control is smaller than best size).
1109 int bestHeight
= GetBestSize().y
;
1110 int height
= GetSize().y
;
1112 if ( height
< bestHeight
)
1114 // Make very small buttons square, as it makes
1115 // them accommodate arrow image better and still
1118 butWidth
= (height
*butWidth
)/bestHeight
;
1120 butWidth
= butHeight
;
1124 // Adjust button height
1126 butHeight
= m_btnHei
;
1128 // Use size of normal bitmap if...
1131 // button width is set to default and blank button bg is not drawn
1132 if ( m_bmpNormal
.Ok() )
1134 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1135 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1137 // If drawing blank button background, we need to add some margin.
1138 if ( m_blankButtonBg
)
1140 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1141 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1144 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1145 butWidth
= bmpReqWidth
;
1146 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1147 butHeight
= bmpReqHeight
;
1149 // Need to fix height?
1150 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1152 int newY
= butHeight
+(customBorder
*2);
1153 SetClientSize(wxDefaultCoord
,newY
);
1154 if ( m_bmpNormal
.Ok() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1155 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1157 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1163 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1165 m_btnSize
.x
= butWidth
;
1166 m_btnSize
.y
= butHeight
;
1168 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1169 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1170 m_btnArea
.width
= butAreaWid
;
1171 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1173 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1174 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1175 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1176 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1181 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1182 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1187 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1192 wxSize sz
= GetClientSize();
1194 int customBorder
= m_widthCustomBorder
;
1195 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1199 if ( !m_widthCustomPaint
)
1201 // No special custom paint area - we can use 0 left margin
1203 if ( m_text
->SetMargins(0) )
1204 textCtrlXAdjust
= 0;
1205 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1209 // There is special custom paint area - it is better to
1210 // use some margin with the wxTextCtrl.
1211 m_text
->SetMargins(m_marginLeft
);
1212 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1213 m_marginLeft
+ textCtrlXAdjust
;
1216 // Centre textctrl vertically, if needed
1217 #if !TEXTCTRL_TEXT_CENTERED
1218 int tcSizeY
= m_text
->GetBestSize().y
;
1219 int diff0
= sz
.y
- tcSizeY
;
1220 int y
= textCtrlYAdjust
+ (diff0
/2);
1222 wxUnusedVar(textCtrlYAdjust
);
1226 if ( y
< customBorder
)
1231 m_tcArea
.width
- m_tcArea
.x
- x
,
1234 // Make sure textctrl doesn't exceed the bottom custom border
1235 wxSize tsz
= m_text
->GetSize();
1236 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1239 tsz
.y
= tsz
.y
- diff1
- 1;
1240 m_text
->SetSize(tsz
);
1245 // If it has border, have textctrl fill the entire text field.
1246 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1248 m_tcArea
.width
- m_widthCustomPaint
,
1253 wxSize
wxComboCtrlBase::DoGetBestSize() const
1255 wxSize
sizeText(150,0);
1258 sizeText
= m_text
->GetBestSize();
1260 // TODO: Better method to calculate close-to-native control height.
1264 fhei
= (m_font
.GetPointSize()*2) + 5;
1265 else if ( wxNORMAL_FONT
->Ok() )
1266 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1268 fhei
= sizeText
.y
+ 4;
1270 // Need to force height to accomodate bitmap?
1271 int btnSizeY
= m_btnSize
.y
;
1272 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1275 // Control height doesn't depend on border
1278 int border = m_windowStyle & wxBORDER_MASK;
1279 if ( border == wxSIMPLE_BORDER )
1281 else if ( border == wxNO_BORDER )
1282 fhei += (m_widthCustomBorder*2);
1288 // Final adjustments
1294 // these are the numbers from the HIG:
1295 switch ( m_windowVariant
)
1297 case wxWINDOW_VARIANT_NORMAL
:
1301 case wxWINDOW_VARIANT_SMALL
:
1304 case wxWINDOW_VARIANT_MINI
:
1310 fhei
+= 2 * FOCUS_RING
;
1311 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1313 wxSize
ret(width
, fhei
);
1318 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1323 // defined by actual wxComboCtrls
1329 // ----------------------------------------------------------------------------
1330 // standard operations
1331 // ----------------------------------------------------------------------------
1333 bool wxComboCtrlBase::Enable(bool enable
)
1335 if ( !wxControl::Enable(enable
) )
1339 m_btn
->Enable(enable
);
1341 m_text
->Enable(enable
);
1348 bool wxComboCtrlBase::Show(bool show
)
1350 if ( !wxControl::Show(show
) )
1362 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1364 if ( !wxControl::SetFont(font
) )
1369 // Without hiding the wxTextCtrl there would be some
1370 // visible 'flicker' (at least on Windows XP).
1372 m_text
->SetFont(font
);
1381 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1383 wxControl::DoSetToolTip(tooltip
);
1385 // Set tool tip for button and text box
1388 const wxString
&tip
= tooltip
->GetTip();
1389 if ( m_text
) m_text
->SetToolTip(tip
);
1390 if ( m_btn
) m_btn
->SetToolTip(tip
);
1394 if ( m_text
) m_text
->SetToolTip( NULL
);
1395 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1398 #endif // wxUSE_TOOLTIPS
1400 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1402 if ( wxControl::SetForegroundColour(colour
) )
1405 m_text
->SetForegroundColour(colour
);
1411 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1413 if ( wxControl::SetBackgroundColour(colour
) )
1416 m_text
->SetBackgroundColour(colour
);
1421 // ----------------------------------------------------------------------------
1423 // ----------------------------------------------------------------------------
1425 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1426 // prepare combo box background on area in a way typical on platform
1427 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1429 wxSize sz
= GetClientSize();
1431 bool doDrawFocusRect
; // also selected
1433 // For smaller size control (and for disabled background) use less spacing
1437 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1440 isEnabled
= IsEnabled();
1441 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1443 // Windows-style: for smaller size control (and for disabled background) use less spacing
1444 focusSpacingX
= isEnabled
? 2 : 1;
1445 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1449 // Drawing a list item
1450 isEnabled
= true; // they are never disabled
1451 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1457 // Set the background sub-rectangle for selection, disabled etc
1458 wxRect
selRect(rect
);
1459 selRect
.y
+= focusSpacingY
;
1460 selRect
.height
-= (focusSpacingY
*2);
1464 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1465 wcp
+= m_widthCustomPaint
;
1467 selRect
.x
+= wcp
+ focusSpacingX
;
1468 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1473 bool doDrawSelRect
= true;
1475 // Determine foreground colour
1478 if ( doDrawFocusRect
)
1480 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1482 else if ( m_hasFgCol
)
1484 // Honour the custom foreground colour
1485 fgCol
= GetForegroundColour();
1489 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1494 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1497 // Determine background colour
1500 if ( doDrawFocusRect
)
1502 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1504 else if ( m_hasBgCol
)
1506 // Honour the custom background colour
1507 bgCol
= GetBackgroundColour();
1511 #ifndef __WXMAC__ // see note in OnThemeChange
1512 doDrawSelRect
= false;
1513 bgCol
= GetBackgroundColour();
1515 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1521 #ifndef __WXMAC__ // see note in OnThemeChange
1522 bgCol
= GetBackgroundColour();
1524 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1528 dc
.SetTextForeground( fgCol
);
1529 dc
.SetBrush( bgCol
);
1530 if ( doDrawSelRect
)
1533 dc
.DrawRectangle( selRect
);
1536 // Don't clip exactly to the selection rectangle so we can draw
1537 // to the non-selected area in front of it.
1538 wxRect
clipRect(rect
.x
,rect
.y
,
1539 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1540 dc
.SetClippingRegion(clipRect
);
1543 // Save the library size a bit for platforms that re-implement this.
1544 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1549 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1551 int drawState
= m_btnState
;
1553 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1554 GetPopupWindowState() >= Animating
)
1555 drawState
|= wxCONTROL_PRESSED
;
1557 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1558 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1562 // Make sure area is not larger than the control
1563 if ( drawRect
.y
< rect
.y
)
1564 drawRect
.y
= rect
.y
;
1565 if ( drawRect
.height
> rect
.height
)
1566 drawRect
.height
= rect
.height
;
1568 bool enabled
= IsEnabled();
1571 drawState
|= wxCONTROL_DISABLED
;
1573 if ( !m_bmpNormal
.Ok() )
1575 if ( flags
& Button_BitmapOnly
)
1578 // Need to clear button background even if m_btn is present
1579 if ( flags
& Button_PaintBackground
)
1583 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1584 bgCol
= GetParent()->GetBackgroundColour();
1586 bgCol
= GetBackgroundColour();
1590 dc
.DrawRectangle(rect
);
1593 // Draw standard button
1594 wxRendererNative::Get().DrawComboBoxDropButton(this,
1606 pBmp
= &m_bmpDisabled
;
1607 else if ( m_btnState
& wxCONTROL_PRESSED
)
1608 pBmp
= &m_bmpPressed
;
1609 else if ( m_btnState
& wxCONTROL_CURRENT
)
1612 pBmp
= &m_bmpNormal
;
1614 if ( m_blankButtonBg
)
1616 // If using blank button background, we need to clear its background
1617 // with button face colour instead of colour for rest of the control.
1618 if ( flags
& Button_PaintBackground
)
1620 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1621 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1624 dc
.DrawRectangle(rect
);
1627 if ( !(flags
& Button_BitmapOnly
) )
1629 wxRendererNative::Get().DrawPushButton(this,
1638 // Need to clear button background even if m_btn is present
1639 // (assume non-button background was cleared just before this call so brushes are good)
1640 if ( flags
& Button_PaintBackground
)
1641 dc
.DrawRectangle(rect
);
1644 // Draw bitmap centered in drawRect
1645 dc
.DrawBitmap(*pBmp
,
1646 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1647 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1652 void wxComboCtrlBase::RecalcAndRefresh()
1656 wxSizeEvent
evt(GetSize(),GetId());
1657 GetEventHandler()->ProcessEvent(evt
);
1662 // ----------------------------------------------------------------------------
1663 // miscellaneous event handlers
1664 // ----------------------------------------------------------------------------
1666 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1668 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1670 if ( m_ignoreEvtText
> 0 )
1677 // Change event id, object and string before relaying it forward
1678 event
.SetId(GetId());
1679 wxString s
= event
.GetString();
1680 event
.SetEventObject(this);
1685 // call if cursor is on button area or mouse is captured for the button
1686 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1689 int type
= event
.GetEventType();
1691 if ( type
== wxEVT_MOTION
)
1693 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1694 IsPopupWindowState(Hidden
) )
1696 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1698 // Mouse hover begins
1699 m_btnState
|= wxCONTROL_CURRENT
;
1700 if ( HasCapture() ) // Retain pressed state.
1701 m_btnState
|= wxCONTROL_PRESSED
;
1705 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1708 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1712 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1714 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1716 m_btnState
|= wxCONTROL_PRESSED
;
1719 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1722 // If showing popup now, do not capture mouse or there will be interference
1726 else if ( type
== wxEVT_LEFT_UP
)
1729 // Only accept event if mouse was left-press was previously accepted
1733 if ( m_btnState
& wxCONTROL_PRESSED
)
1735 // If mouse was inside, fire the click event.
1736 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1738 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1742 m_btnState
&= ~(wxCONTROL_PRESSED
);
1746 else if ( type
== wxEVT_LEAVE_WINDOW
)
1748 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1750 m_btnState
&= ~(wxCONTROL_CURRENT
);
1753 if ( IsPopupWindowState(Hidden
) )
1755 m_btnState
&= ~(wxCONTROL_PRESSED
);
1763 // Never have 'hot' state when popup is being shown
1764 // (this is mostly needed because of the animation).
1765 if ( !IsPopupWindowState(Hidden
) )
1766 m_btnState
&= ~wxCONTROL_CURRENT
;
1771 // returns true if event was consumed or filtered
1772 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1773 int WXUNUSED(flags
) )
1775 wxLongLong t
= ::wxGetLocalTimeMillis();
1776 int evtType
= event
.GetEventType();
1778 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1779 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1781 if ( IsPopupWindowState(Visible
) &&
1782 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1790 // Filter out clicks on button immediately after popup dismiss
1791 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1793 event
.SetEventType(0);
1800 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1802 int evtType
= event
.GetEventType();
1804 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1805 (m_windowStyle
& wxCB_READONLY
) )
1807 if ( GetPopupWindowState() >= Animating
)
1809 #if USES_WXPOPUPWINDOW
1810 // Click here always hides the popup.
1811 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1817 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1819 // In read-only mode, clicking the text is the
1820 // same as clicking the button.
1823 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1825 //if ( m_popupInterface->CycleValue() )
1827 if ( m_popupInterface
)
1828 m_popupInterface
->OnComboDoubleClick();
1832 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1834 if ( IsPopupShown() )
1836 // relay (some) mouse events to the popup
1837 m_popup
->GetEventHandler()->ProcessEvent(event
);
1839 else if ( event
.GetWheelAxis() == 0 &&
1840 event
.GetWheelRotation() != 0 &&
1841 event
.GetModifiers() == 0 )
1843 // Translate mousewheel actions into key up/down. This is
1844 // the simplest way of getting native behaviour: scrolling the
1845 // wheel moves selection up/down by one item.
1846 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1847 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1850 GetEventHandler()->ProcessEvent(kevent
);
1863 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1865 if ( IsPopupShown() )
1867 // pass it to the popped up control
1868 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1872 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1874 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1876 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1880 if ( IsKeyPopupToggle(event
) )
1886 int comboStyle
= GetWindowStyle();
1887 wxComboPopup
* popupInterface
= GetPopupControl();
1889 if ( !popupInterface
)
1895 int keycode
= event
.GetKeyCode();
1897 if ( (comboStyle
& wxCB_READONLY
) ||
1898 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1900 popupInterface
->OnComboKeyEvent(event
);
1907 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
1909 if ( IsPopupShown() )
1911 // pass it to the popped up control
1912 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1916 wxComboPopup
* popupInterface
= GetPopupControl();
1917 if ( popupInterface
)
1919 popupInterface
->OnComboCharEvent(event
);
1928 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1930 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1932 wxWindow
* tc
= GetTextCtrl();
1933 if ( tc
&& tc
!= DoFindFocus() )
1942 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
1946 m_resetFocus
= false;
1947 wxWindow
* tc
= GetTextCtrl();
1953 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1956 // left margin may also have changed
1957 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
1958 m_marginLeft
= GetNativeTextIndent();
1962 // ----------------------------------------------------------------------------
1964 // ----------------------------------------------------------------------------
1966 // Create popup window and the child control
1967 void wxComboCtrlBase::CreatePopup()
1969 wxComboPopup
* popupInterface
= m_popupInterface
;
1974 #ifdef wxComboPopupWindowBase2
1975 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
1977 #if !USES_GENERICTLW
1978 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
1980 int tlwFlags
= wxNO_BORDER
;
1981 #ifdef wxCC_GENERIC_TLW_IS_FRAME
1982 tlwFlags
|= wxFRAME_NO_TASKBAR
;
1985 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
1986 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
1987 wxPoint(-21,-21), wxSize(20, 20),
1990 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
1991 wxPoint(-21,-21), wxSize(20, 20),
1995 m_popupWinType
= SECONDARY_POPUP_TYPE
;
1998 #endif // wxComboPopupWindowBase2
2000 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2001 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2003 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2004 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2007 popupInterface
->Create(m_winPopup
);
2008 m_popup
= popup
= popupInterface
->GetControl();
2010 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2011 popup
->PushEventHandler( m_popupEvtHandler
);
2013 // This may be helpful on some platforms
2014 // (eg. it bypasses a wxGTK popupwindow bug where
2015 // window is not initially hidden when it should be)
2018 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2021 // Destroy popup window and the child control
2022 void wxComboCtrlBase::DestroyPopup()
2027 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2029 wxDELETE(m_popupEvtHandler
);
2031 wxDELETE(m_popupInterface
);
2035 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2036 wxDELETE(m_popupWinEvtHandler
);
2037 m_winPopup
->Destroy();
2044 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2046 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2050 iface
->InitBase(this);
2053 m_popupInterface
= iface
;
2055 if ( !iface
->LazyCreate() )
2064 // This must be done after creation
2065 if ( m_valueString
.length() )
2067 iface
->SetStringValue(m_valueString
);
2072 // Ensures there is atleast the default popup
2073 void wxComboCtrlBase::EnsurePopupControl()
2075 if ( !m_popupInterface
)
2076 SetPopupControl(NULL
);
2079 void wxComboCtrlBase::OnButtonClick()
2081 // Derived classes can override this method for totally custom
2083 switch ( GetPopupWindowState() )
2100 void wxComboCtrlBase::Popup()
2102 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2103 event
.SetEventObject(this);
2104 HandleWindowEvent(event
);
2109 void wxComboCtrlBase::ShowPopup()
2111 EnsurePopupControl();
2112 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2114 if ( IsPopupWindowState(Animating
) )
2119 // Space above and below
2125 wxSize ctrlSz
= GetSize();
2127 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2128 scrPos
= GetParent()->ClientToScreen(GetPosition());
2130 spaceAbove
= scrPos
.y
;
2131 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2133 maxHeightPopup
= spaceBelow
;
2134 if ( spaceAbove
> spaceBelow
)
2135 maxHeightPopup
= spaceAbove
;
2138 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2140 if ( widthPopup
< m_widthMinPopup
)
2141 widthPopup
= m_widthMinPopup
;
2143 wxWindow
* winPopup
= m_winPopup
;
2146 // Need to disable tab traversal of parent
2148 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2149 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2150 // that if transient popup is open, then tab traversal is to be ignored.
2151 // However, I think this code would still be needed for cases where
2152 // transient popup doesn't work yet (wxWinCE?).
2153 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2154 wxWindow
* parent
= mainCtrl
->GetParent();
2155 int parentFlags
= parent
->GetWindowStyle();
2156 if ( parentFlags
& wxTAB_TRAVERSAL
)
2158 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2159 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2165 winPopup
= m_winPopup
;
2175 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2177 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2178 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2181 popup
->SetSize(adjustedSize
);
2183 m_popupInterface
->OnPopup();
2186 // Reposition and resize popup window
2189 wxSize szp
= popup
->GetSize();
2192 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2194 // Default anchor is wxLEFT
2195 int anchorSide
= m_anchorSide
;
2197 anchorSide
= wxLEFT
;
2199 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2200 int leftX
= scrPos
.x
- m_extLeft
;
2202 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2205 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2207 // If there is not enough horizontal space, anchor on the other side.
2208 // If there is no space even then, place the popup at x 0.
2209 if ( anchorSide
== wxRIGHT
)
2213 if ( (leftX
+szp
.x
) < screenWidth
)
2214 anchorSide
= wxLEFT
;
2221 if ( (leftX
+szp
.x
) >= screenWidth
)
2224 anchorSide
= wxRIGHT
;
2230 // Select x coordinate according to the anchor side
2231 if ( anchorSide
== wxRIGHT
)
2233 else if ( anchorSide
== wxLEFT
)
2238 int showFlags
= CanDeferShow
;
2240 if ( spaceBelow
< szp
.y
)
2242 popupY
= scrPos
.y
- szp
.y
;
2243 showFlags
|= ShowAbove
;
2246 #if INSTALL_TOPLEV_HANDLER
2247 // Put top level window event handler into place
2248 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2250 if ( !m_toplevEvtHandler
)
2251 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2253 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2255 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2256 toplev
->PushEventHandler( m_toplevEvtHandler
);
2260 // Set string selection (must be this way instead of SetStringSelection)
2263 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2264 m_text
->SelectAll();
2266 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2270 // This is neede since focus/selection indication may change when popup is shown
2274 // This must be after SetStringValue
2275 m_popupWinState
= Animating
;
2277 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2280 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2281 AnimateShow( popupWinRect
, showFlags
) )
2283 DoShowPopup( popupWinRect
, showFlags
);
2287 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2292 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2294 wxWindow
* winPopup
= m_winPopup
;
2296 if ( IsPopupWindowState(Animating
) )
2298 // Make sure the popup window is shown in the right position.
2299 // Should not matter even if animation already did this.
2301 // Some platforms (GTK) may like SetSize and Move to be separate
2302 // (though the bug was probably fixed).
2303 winPopup
->SetSize( rect
);
2305 #if USES_WXPOPUPTRANSIENTWINDOW
2306 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2307 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2312 m_popupWinState
= Visible
;
2314 // If popup window was a generic top-level window, or the
2315 // wxPopupWindow implemenation on this platform is classified as
2316 // perfect, then we should be able to safely set focus to the popup
2318 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2319 m_popup
->SetFocus();
2321 else if ( IsPopupWindowState(Hidden
) )
2323 // Animation was aborted
2325 wxASSERT( !winPopup
->IsShown() );
2327 m_popupWinState
= Hidden
;
2333 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2335 // Just in case, avoid double dismiss
2336 if ( IsPopupWindowState(Hidden
) )
2339 // This must be set before focus - otherwise there will be recursive
2340 // OnPopupDismisses.
2341 m_popupWinState
= Hidden
;
2344 m_winPopup
->Disable();
2346 // Inform popup control itself
2347 m_popupInterface
->OnDismiss();
2349 if ( m_popupEvtHandler
)
2350 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2352 #if INSTALL_TOPLEV_HANDLER
2353 // Remove top level window event handler
2354 if ( m_toplevEvtHandler
)
2356 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2358 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2362 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2364 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2365 m_timeCanAcceptClick
+= 150;
2367 // If cursor not on dropdown button, then clear its state
2368 // (technically not required by all ports, but do it for all just in case)
2369 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2372 // Return parent's tab traversal flag.
2373 // See ShowPopup for notes.
2374 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2376 wxWindow
* parent
= GetParent();
2377 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2378 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2381 // refresh control (necessary even if m_text)
2386 if ( generateEvent
)
2388 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2389 event
.SetEventObject(this);
2390 HandleWindowEvent(event
);
2394 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2396 // Should be able to call this without popup interface
2397 if ( IsPopupWindowState(Hidden
) )
2400 // transfer value and show it in textctrl, if any
2401 if ( !IsPopupWindowState(Animating
) )
2402 SetValueByUser( m_popupInterface
->GetStringValue() );
2406 OnPopupDismiss(generateEvent
);
2409 // ----------------------------------------------------------------------------
2410 // customization methods
2411 // ----------------------------------------------------------------------------
2413 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2414 int side
, int spacingX
)
2419 m_btnSpacingX
= spacingX
;
2421 if ( width
> 0 || height
> 0 || spacingX
)
2422 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2427 wxSize
wxComboCtrlBase::GetButtonSize()
2429 if ( m_btnSize
.x
> 0 )
2432 wxSize
retSize(m_btnWid
,m_btnHei
);
2434 // Need to call CalculateAreas now if button size is
2435 // is not explicitly specified.
2436 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2440 retSize
= m_btnSize
;
2446 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2448 const wxBitmap
& bmpPressed
,
2449 const wxBitmap
& bmpHover
,
2450 const wxBitmap
& bmpDisabled
)
2452 m_bmpNormal
= bmpNormal
;
2453 m_blankButtonBg
= blankButtonBg
;
2455 if ( bmpPressed
.Ok() )
2456 m_bmpPressed
= bmpPressed
;
2458 m_bmpPressed
= bmpNormal
;
2460 if ( bmpHover
.Ok() )
2461 m_bmpHover
= bmpHover
;
2463 m_bmpHover
= bmpNormal
;
2465 if ( bmpDisabled
.Ok() )
2466 m_bmpDisabled
= bmpDisabled
;
2468 m_bmpDisabled
= bmpNormal
;
2473 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2477 // move textctrl accordingly
2478 wxRect r
= m_text
->GetRect();
2479 int inc
= width
- m_widthCustomPaint
;
2482 m_text
->SetSize( r
);
2485 m_widthCustomPaint
= width
;
2490 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2492 // For general sanity's sake, we ignore top margin. Instead
2493 // we will always try to center the text vertically.
2496 if ( margins
.x
!= -1 )
2498 m_marginLeft
= margins
.x
;
2499 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2503 m_marginLeft
= GetNativeTextIndent();
2504 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2507 if ( margins
.y
!= -1 )
2517 wxPoint
wxComboCtrlBase::DoGetMargins() const
2519 return wxPoint(m_marginLeft
, -1);
2522 #if WXWIN_COMPATIBILITY_2_8
2523 void wxComboCtrlBase::SetTextIndent( int indent
)
2527 m_marginLeft
= GetNativeTextIndent();
2528 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2532 m_marginLeft
= indent
;
2533 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2539 wxCoord
wxComboCtrlBase::GetTextIndent() const
2541 return m_marginLeft
;
2545 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2547 return DEFAULT_TEXT_INDENT
;
2550 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2552 m_textCtrlStyle
= style
;
2555 m_text
->SetWindowStyle(style
);
2558 // ----------------------------------------------------------------------------
2559 // wxTextEntry interface
2560 // ----------------------------------------------------------------------------
2562 wxString
wxComboCtrlBase::DoGetValue() const
2565 return m_text
->GetValue();
2566 return m_valueString
;
2569 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2572 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2575 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2577 // Note: before wxComboCtrl inherited from wxTextEntry,
2578 // this code used to be in SetValueWithEvent().
2580 // Since wxComboPopup may want to paint the combo as well, we need
2581 // to set the string value here (as well as sometimes in ShowPopup).
2582 if ( m_valueString
!= value
)
2585 wxString trueValue
= value
;
2587 // Conform to wxComboBox behavior: read-only control can only accept
2588 // valid list items and empty string
2589 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2591 found
= m_popupInterface
->FindItem(value
,
2597 m_valueString
= trueValue
;
2599 EnsurePopupControl();
2601 if ( m_popupInterface
)
2602 m_popupInterface
->SetStringValue(trueValue
);
2609 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2611 // NB: Order of function calls is important here. Otherwise
2612 // the SelectAll() may not work.
2616 m_text
->SetValue(value
);
2618 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2619 m_text
->SelectAll();
2625 // In this SetValue variant wxComboPopup::SetStringValue is not called
2626 void wxComboCtrlBase::SetText(const wxString
& value
)
2628 // Unlike in SetValue(), this must be called here or
2629 // the behaviour will no be consistent in readonlys.
2630 EnsurePopupControl();
2632 m_valueString
= value
;
2637 m_text
->SetValue( value
);
2643 void wxComboCtrlBase::Copy()
2649 void wxComboCtrlBase::Cut()
2655 void wxComboCtrlBase::Paste()
2661 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2664 m_text
->SetInsertionPoint(pos
);
2667 long wxComboCtrlBase::GetInsertionPoint() const
2670 return m_text
->GetInsertionPoint();
2675 long wxComboCtrlBase::GetLastPosition() const
2678 return m_text
->GetLastPosition();
2683 void wxComboCtrlBase::WriteText(const wxString
& text
)
2687 m_text
->WriteText(text
);
2688 OnSetValue(m_text
->GetValue());
2696 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2700 if ( flags
& SetValue_SendEvent
)
2701 m_text
->SetValue(value
);
2703 m_text
->ChangeValue(value
);
2709 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2713 m_text
->Replace(from
, to
, value
);
2714 OnSetValue(m_text
->GetValue());
2718 void wxComboCtrlBase::Remove(long from
, long to
)
2722 m_text
->Remove(from
, to
);
2723 OnSetValue(m_text
->GetValue());
2727 void wxComboCtrlBase::SetSelection(long from
, long to
)
2730 m_text
->SetSelection(from
, to
);
2733 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2737 m_text
->GetSelection(from
, to
);
2746 bool wxComboCtrlBase::IsEditable() const
2749 return m_text
->IsEditable();
2753 void wxComboCtrlBase::SetEditable(bool editable
)
2756 m_text
->SetEditable(editable
);
2759 void wxComboCtrlBase::Undo()
2765 void wxComboCtrlBase::Redo()
2771 bool wxComboCtrlBase::CanUndo() const
2774 return m_text
->CanUndo();
2779 bool wxComboCtrlBase::CanRedo() const
2782 return m_text
->CanRedo();
2787 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2792 res
= m_text
->SetHint(hint
);
2797 wxString
wxComboCtrlBase::GetHint() const
2802 #endif // wxUSE_COMBOCTRL